diff --git a/client/package-lock.json b/client/package-lock.json
index 3cf61093..bc4ee11e 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -9,6 +9,7 @@
"version": "0.0.0",
"dependencies": {
"axios": "^0.27.2",
+ "ethereum-cryptography": "^1.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
@@ -517,6 +518,70 @@
"@jridgewell/sourcemap-codec": "^1.4.10"
}
},
+ "node_modules/@noble/hashes": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz",
+ "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ]
+ },
+ "node_modules/@noble/secp256k1": {
+ "version": "1.7.1",
+ "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz",
+ "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ]
+ },
+ "node_modules/@scure/base": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz",
+ "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ]
+ },
+ "node_modules/@scure/bip32": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.5.tgz",
+ "integrity": "sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ],
+ "dependencies": {
+ "@noble/hashes": "~1.2.0",
+ "@noble/secp256k1": "~1.7.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
+ "node_modules/@scure/bip39": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz",
+ "integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ],
+ "dependencies": {
+ "@noble/hashes": "~1.2.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
"node_modules/@types/prop-types": {
"version": "15.7.5",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz",
@@ -1178,6 +1243,17 @@
"node": ">=0.8.0"
}
},
+ "node_modules/ethereum-cryptography": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz",
+ "integrity": "sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw==",
+ "dependencies": {
+ "@noble/hashes": "1.2.0",
+ "@noble/secp256k1": "1.7.1",
+ "@scure/bip32": "1.1.5",
+ "@scure/bip39": "1.1.1"
+ }
+ },
"node_modules/fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
@@ -2107,6 +2183,40 @@
"@jridgewell/sourcemap-codec": "^1.4.10"
}
},
+ "@noble/hashes": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz",
+ "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ=="
+ },
+ "@noble/secp256k1": {
+ "version": "1.7.1",
+ "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz",
+ "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw=="
+ },
+ "@scure/base": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz",
+ "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA=="
+ },
+ "@scure/bip32": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.5.tgz",
+ "integrity": "sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==",
+ "requires": {
+ "@noble/hashes": "~1.2.0",
+ "@noble/secp256k1": "~1.7.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
+ "@scure/bip39": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz",
+ "integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==",
+ "requires": {
+ "@noble/hashes": "~1.2.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
"@types/prop-types": {
"version": "15.7.5",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz",
@@ -2497,6 +2607,17 @@
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true
},
+ "ethereum-cryptography": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz",
+ "integrity": "sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw==",
+ "requires": {
+ "@noble/hashes": "1.2.0",
+ "@noble/secp256k1": "1.7.1",
+ "@scure/bip32": "1.1.5",
+ "@scure/bip39": "1.1.1"
+ }
+ },
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
diff --git a/client/package.json b/client/package.json
index f662261b..493079cb 100644
--- a/client/package.json
+++ b/client/package.json
@@ -10,6 +10,7 @@
},
"dependencies": {
"axios": "^0.27.2",
+ "ethereum-cryptography": "^1.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 7254c1fa..243df05d 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -6,11 +6,14 @@ import { useState } from "react";
function App() {
const [balance, setBalance] = useState(0);
const [address, setAddress] = useState("");
+ const [privateKey, setPrivateKey] = useState("");
return (
);
diff --git a/server/index.js b/server/index.js
index 3dbd053b..c8b3b178 100644
--- a/server/index.js
+++ b/server/index.js
@@ -1,5 +1,6 @@
const express = require("express");
const app = express();
+const generate=require("./generate")
const cors = require("cors");
const port = 3042;
@@ -7,9 +8,9 @@ app.use(cors());
app.use(express.json());
const balances = {
- "0x1": 100,
- "0x2": 50,
- "0x3": 75,
+ "0477d6d89efe313dcc63599dbe0aff9f7a84129fcd00c8c952b4eba35da41547e25d69132809fe620cbdccf5fcb3f2f053842a302fbf660635c4e45f693732fd8c": 100,
+ "041e7b0cec9217b3e2604f752f3805f52f10935aa51d8d4e0b1bce953f5cc95768ca298942265994e45695122c8421fb2b24f857cd4a9091f8c2fd75544cdf6dfa": 50,
+ "048e2bd0844c517a2cf8877c7aa05a737ebfda87581f198e6d84e3e7feb766ca6ccace598e16192081960b4e4cc5ce5a95bdc5bad61a5cd6efdc7550e619f66cab": 75,
};
app.get("/balance/:address", (req, res) => {
@@ -19,7 +20,10 @@ app.get("/balance/:address", (req, res) => {
});
app.post("/send", (req, res) => {
- const { sender, recipient, amount } = req.body;
+ const { message, signature } = req.body;
+ const { recipient, amount } = message;
+ const pk=generate.signatureToPk(message,signature);
+ const sender=generate.pktoAddress(pk);
setInitialBalance(sender);
setInitialBalance(recipient);
diff --git a/server/package-lock.json b/server/package-lock.json
index 612c6e2d..7e16965a 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -10,9 +10,74 @@
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
+ "ethereum-cryptography": "^1.2.0",
"express": "^4.18.1"
}
},
+ "node_modules/@noble/hashes": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz",
+ "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ]
+ },
+ "node_modules/@noble/secp256k1": {
+ "version": "1.7.1",
+ "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz",
+ "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ]
+ },
+ "node_modules/@scure/base": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz",
+ "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ]
+ },
+ "node_modules/@scure/bip32": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.5.tgz",
+ "integrity": "sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ],
+ "dependencies": {
+ "@noble/hashes": "~1.2.0",
+ "@noble/secp256k1": "~1.7.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
+ "node_modules/@scure/bip39": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz",
+ "integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==",
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://paulmillr.com/funding/"
+ }
+ ],
+ "dependencies": {
+ "@noble/hashes": "~1.2.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@@ -168,6 +233,17 @@
"node": ">= 0.6"
}
},
+ "node_modules/ethereum-cryptography": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz",
+ "integrity": "sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw==",
+ "dependencies": {
+ "@noble/hashes": "1.2.0",
+ "@noble/secp256k1": "1.7.1",
+ "@scure/bip32": "1.1.5",
+ "@scure/bip39": "1.1.1"
+ }
+ },
"node_modules/express": {
"version": "4.18.1",
"resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz",
@@ -611,6 +687,40 @@
}
},
"dependencies": {
+ "@noble/hashes": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz",
+ "integrity": "sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ=="
+ },
+ "@noble/secp256k1": {
+ "version": "1.7.1",
+ "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz",
+ "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw=="
+ },
+ "@scure/base": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz",
+ "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA=="
+ },
+ "@scure/bip32": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.1.5.tgz",
+ "integrity": "sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw==",
+ "requires": {
+ "@noble/hashes": "~1.2.0",
+ "@noble/secp256k1": "~1.7.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
+ "@scure/bip39": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.1.1.tgz",
+ "integrity": "sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg==",
+ "requires": {
+ "@noble/hashes": "~1.2.0",
+ "@scure/base": "~1.1.0"
+ }
+ },
"accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@@ -728,6 +838,17 @@
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="
},
+ "ethereum-cryptography": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz",
+ "integrity": "sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw==",
+ "requires": {
+ "@noble/hashes": "1.2.0",
+ "@noble/secp256k1": "1.7.1",
+ "@scure/bip32": "1.1.5",
+ "@scure/bip39": "1.1.1"
+ }
+ },
"express": {
"version": "4.18.1",
"resolved": "https://registry.npmjs.org/express/-/express-4.18.1.tgz",
diff --git a/server/package.json b/server/package.json
index c03b40a9..a24cb654 100644
--- a/server/package.json
+++ b/server/package.json
@@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
+ "ethereum-cryptography": "^1.2.0",
"express": "^4.18.1"
}
}
diff --git a/server/scripts/generate.js b/server/scripts/generate.js
new file mode 100644
index 00000000..eb4d73ae
--- /dev/null
+++ b/server/scripts/generate.js
@@ -0,0 +1,6 @@
+const secp=require("ethereum-cryptography/secp256k1")
+const {toHex}=require("ethereum-cryptography/utils")
+const privateKey=secp.utils.randomPrivateKey();
+console.log("private key:",toHex(privateKey));
+const publicKey=secp.getPublicKey(privateKey);
+console.log('public key:',toHex(publicKey))
\ No newline at end of file