Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Dec 13, 2023
1 parent 0f25dba commit 5a2aeba
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 157 deletions.
54 changes: 44 additions & 10 deletions packages/hardhat/contracts/Nostr3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,50 @@ contract Nostr3 {

uint256 public fees;

uint256 public FEE = 1 wei;

uint256 constant MAX_FEE = 1000 wei;
uint256 public FEE = 10; // 10 / 10000 =

struct Nostr3Account {
bytes publicKey;
address evmAddres;
}

Nostr3Account[] public accounts;

constructor() {
owner = msg.sender;
}

function changeFEE(uint256 newFee) public {
require(msg.sender == owner, "NOT_ALLOWED");
require(newFee <= MAX_FEE, "FEE_TO_HIGH");
FEE = newFee;

function join(bytes memory publicKey,address evmAddress) public {
Nostr3Account memory account;
account.publicKey = publicKey;
account.evmAddres = evmAddress;
accounts.push(account);
}

function change(bytes memory publicKey, address newEvmAddress) public {
bool isFound = false;
for (uint i = 0; i < accounts.length; i++) {
if (keccak256(accounts[i].publicKey) == keccak256(publicKey)) {
require(msg.sender == accounts[i].evmAddres, "NOT_ALLOWED");
accounts[i].evmAddres = newEvmAddress;
isFound = true;
break;
}
}
require(isFound, "PUBLIC_KEY_NOT_FOUND");
}


function changeOwner(address _newOwner) public {
require(msg.sender == owner, "NOT_ALLOWED");
owner = _newOwner;
}

function deposit(bytes32 encryptedHash) public payable {
uint256 depositAmount = msg.value - FEE;
fees += FEE;

uint256 feeAmount = msg.value * FEE / 10000;
uint256 depositAmount = msg.value - feeAmount;
fees += feeAmount;
encryptedDeposits[encryptedHash] = depositAmount;
}

Expand All @@ -46,4 +67,17 @@ contract Nostr3 {
fees = 0;
payable(msg.sender).transfer(amountToSend);
}

function getAccounts() public view returns (bytes[] memory, address[] memory) {
bytes[] memory publicKeys = new bytes[](accounts.length);
address[] memory evmAddresses = new address[](accounts.length);

for (uint i = 0; i < accounts.length; i++) {
publicKeys[i] = accounts[i].publicKey;
evmAddresses[i] = accounts[i].evmAddres;
}

return (publicKeys, evmAddresses);
}

}
1 change: 0 additions & 1 deletion packages/nextjs/cids.json

This file was deleted.

53 changes: 50 additions & 3 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
const deployedContracts = {
10: {
Nostr3: {
address: "0x21f5C4f2a0898Aa3EaFfdcb644dFeF30e95cC359",
address: "0x432AF68A2CED9891dEf8Caf7140574b7452Fa479",
abi: [
{
inputs: [],
Expand All @@ -31,11 +31,40 @@ const deployedContracts = {
inputs: [
{
internalType: "uint256",
name: "newFee",
name: "",
type: "uint256",
},
],
name: "changeFEE",
name: "accounts",
outputs: [
{
internalType: "bytes",
name: "publicKey",
type: "bytes",
},
{
internalType: "address",
name: "evmAddres",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "bytes",
name: "publicKey",
type: "bytes",
},
{
internalType: "address",
name: "newEvmAddress",
type: "address",
},
],
name: "change",
outputs: [],
stateMutability: "nonpayable",
type: "function",
Expand Down Expand Up @@ -98,6 +127,24 @@ const deployedContracts = {
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "bytes",
name: "publicKey",
type: "bytes",
},
{
internalType: "address",
name: "evmAddress",
type: "address",
},
],
name: "join",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "owner",
Expand Down
47 changes: 0 additions & 47 deletions packages/nextjs/events.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@noble/secp256k1": "^2.0.0",
"@rainbow-me/rainbowkit": "1.1.2",
"@scobru/crypto-ipfs": "^1.1.11",
"@scobru/mogu": "^1.2.7",
"@scobru/mogu": "^1.2.8",
"@scobru/nostr3": "^1.1.5",
"@types/fs-extra": "^11.0.4",
"@uniswap/sdk-core": "^4.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/pages/api/[pubkey].ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default async function handler(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
);

const pubkey = req.query.pubkey;
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/pages/api/cids.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"Qmaxaxmhzux47opqBK1NTAKZoyV89BzU28dcQunKXCchkg"
"QmXWRpMZ4GdKCVKtP1qHHkT9rfH9eTmJUdPmNFiWPFqorH"
2 changes: 2 additions & 0 deletions packages/nextjs/pages/api/getAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default async function handler(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
);

let cid;
Expand All @@ -29,6 +30,7 @@ export default async function handler(
if (fse.existsSync(cidFilePath)) {
const rawData = fse.readFileSync(cidFilePath, "utf8");
cid = JSON.parse(rawData);
console.log(cid)
} else {
throw new Error("CID file not found.");
}
Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/pages/api/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const mogu = new Mogu(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
);

export default async function handler(
Expand Down Expand Up @@ -131,6 +132,7 @@ export default async function handler(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
);

const { evmAddress } = req.query;
Expand Down
115 changes: 77 additions & 38 deletions packages/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,91 @@
import Image from "next/image";
import "daisyui/dist/full.css";
import type { NextPage } from "next";
import { MetaHeader } from "~~/components/MetaHeader";

// Importa lo stile completo di DaisyUI

const Home: NextPage = () => {
return (
<div className="flex flex-col items-center justify-center min-h-screen py-10 w-full sm:w-4/5 md:w-3/4 lg:w-3/6 mx-auto">
<div className="flex flex-col items-center justify-center min-h-screen py-10 w-full sm:w-4/5 md:w-3/4 lg:w-3/6 mx-auto ">
<MetaHeader />
<div className="w-full">
<Image className="mb-5 mx-auto" src="/assets/nostr3.png" width={400} height={400} alt="nostr3" />
{/* <Image className="mb-5 mx-auto" src="/assets/nostr3.png" width={400} height={400} alt="nostr3" /> */}
<div className="m-5 mx-auto w-5/6">
<h1 className="text-4xl w-2/4 justify-center items-centert text-center mb-5 mx-auto">
Generate Keys for <strong> NOSTR </strong> Protocol with Your <strong>EVM</strong> Address
<h1 className="text-4xl text-center mb-5">
Welcome to <strong>Nostr3</strong> : Enhancing the Nostr Protocol with Web3 Interoperability
</h1>
{/* <p className="text-xl">
<strong>Nostr3</strong> is here to make your life easier when dealing with the Nostr protocol! It cleverly generates private keys
right from your EVM address, taking the hassle out of key storage. Need your keys? Just a quick interaction
with Nostr3, and you are all set. What&apos;s more, it links your Nostr accounts to your EVM accounts,
making tipping a breeze for all Nostr accounts set up through Nostr3. For the best Nostr experience, we
suggest pairing it with open-source clients. Happy Nostring!
<p className="text-xl mb-4 text-center">
Effortlessly generate Nostr keys with your EVM address and engage in seamless tipping transactions.
</p>
<div className="my-10" />
<h2 className="text-3xl text-left mb-3 font-semibold ">Core Features</h2>
<ul className="list-disc list-inside mb-5 text-md">
<li>Signature Signing & Keypair Generation</li>
<li>Database Registration of EVM Addresses</li>
<li>Quick and Efficient Tipping through URL Links</li>
<li>Enabling Interoperability and Easy Transactions</li>
</ul>
<div className="my-10" />
<h2 className="text-3xl text-left mb-3 font-bold">How to Send a Tip</h2>
<ul className="list-disc list-inside mb-5">
<li>
<strong>Visit the Tipping URL:</strong> Navigate to the URL provided by the content creator or user. For
example,{" "}
<a href="https://nostr3.vercel.app/tip/npub1abcd1234/note12345abcd" className="text-blue-600 break-all">
nostr3.vercel.app/tip/npub1abcd1234/note12345abcd
</a>
.
</li>
<li>
<strong>Connect Your Wallet:</strong> On the tipping page, connect your Web3 wallet.
</li>
<li>
<strong>Enter Tip Amount:</strong> Choose the amount you wish to tip.
</li>
<li>
<strong>Confirm the Transaction:</strong> Approve the transaction to send your tip directly to the
recipient’s EVM address.
</li>
<li>
<strong>Recipient Without Linked Address:</strong> If the recipient’s public key is not linked to an EVM
address, you can send them a private message with a unique password.
</li>
<li>
<strong>Recipient Claims Tip:</strong> The recipient can later claim the tip from the smart contract by
entering this password.
</li>
</ul>
<div className="my-10" />

<h2 className="text-3xl text-left mb-3 font-bold">How to Claim a Tip</h2>
<ul className="list-disc list-inside mb-5">
<li>
<strong>Link EVM Address:</strong> Ensure your Nostr public key is linked to an EVM address. Tips are
directly sent to the linked wallet.
</li>
<li>
<strong>No Linked Address:</strong> If your public key isn’t linked to an EVM address, the tip sender will
send you a private message containing a unique key.
</li>
<li>
<strong>Access Claim Page:</strong> Visit{" "}
<a href="https://nostr3.vercel.app/claim" className="text-blue-600">
nostr3.vercel.app/claim
</a>{" "}
and connect your Web3 wallet.
</li>
<li>
<strong>Enter the Unique Key:</strong> If you received a private message, input the provided key in the
designated field.
</li>
<li>
<strong>Confirm the Transaction:</strong> Approve the transaction in your wallet to receive the tip.
</li>
</ul>

<div className="bg-success text-success-content rounded-md my-8 p-6">
<h2 className="text-2xl mb-4">🎉 Updates</h2>
<ul className="list-disc space-y-2">
<li className="text-lg font-medium">
<span className="font-bold">Nostr3 Tipping URL Routing</span>: Facilitate direct tipping to authors on a blog platform via Nostr3 tipping URLs. Each blog post can feature a unique link, allowing readers to tip the author seamlessly. For instance, a URL like `https://nostr3.vercel.app/tip/npub1abcd1234/note12345abcd` directly routes a tip to the author's public key (`npub1abcd1234`) and associates it with a specific note or content item (`note12345abcd`). This feature simplifies the process of showing appreciation, making it more interactive and user-friendly.
</li>
<li className="text-lg font-medium">
<span className="font-bold">Secret Tip Feature</span>: This function allows users to send tips anonymously and securely. A random key is generated for each tip, which is then encrypted. The receiver gets a private message with this key to claim their tip. The tip is stored in a smart contract, ensuring safety and privacy. Users can opt for this feature whether they are using the extension or not, facilitating both convenience and security in transactions.
</li>
<li className="text-lg font-medium">
<span className="font-bold">NIP-111</span>: Implementation of NIP-111, which allows for the association
of an EVM address with a Nostr3 public key. This allows for the easy transfer of tips between EVM and
Nostr3 accounts.
</li>
<li className="text-lg font-medium">
<span className="font-bold">Nos2x Extension Compatibility</span>: Log in seamlessly using the nos2x
extension for a smoother experience.
</li>
<li className="text-lg font-medium">
<span className="font-bold">List Address Box Feature</span>: Keep track of all pubkey associated with
corresponding EVM addresses with our new feature.
</li>
</ul>
</div> */}
<p className="text-center my-4">
Learn more about NIP-111:{" "}
<a href="https://github.com/nostr-protocol/nips/pull/268" className="text-blue-600">
NIP-111 on GitHub
</a>
</p>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 5a2aeba

Please sign in to comment.