From db13836e8bbe5770bccc29a2d35e57bd75b06269 Mon Sep 17 00:00:00 2001 From: Bradley DAmato Date: Wed, 2 Aug 2023 18:20:49 -0400 Subject: [PATCH] finished --- client/index.js | 8 ++++++++ package-lock.json | 16 ---------------- server/index.js | 6 ++++-- utils/example.js | 1 + 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/client/index.js b/client/index.js index 28980e4..8fcb3b4 100644 --- a/client/index.js +++ b/client/index.js @@ -6,9 +6,17 @@ const serverUrl = 'http://localhost:1225'; async function main() { // TODO: how do we prove to the server we're on the nice list? + // get merkle hash of the whole nice list + const merkleTree = new MerkleTree(niceList); + + const name = 'Norman Block'; + const index = niceList.findIndex(n => n === name); + const proof = merkleTree.getProof(index); const { data: gift } = await axios.post(`${serverUrl}/gift`, { // TODO: add request body parameters here! + 'name': name, + 'proof': proof }); console.log({ gift }); diff --git a/package-lock.json b/package-lock.json index 70a452c..29fc2e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,22 +6,11 @@ "": { "name": "holiday-gift-list", "dependencies": { - "@faker-js/faker": "^7.6.0", "axios": "^1.2.0", - "body-parser": "^1.20.1", "ethereum-cryptography": "^1.1.2", "express": "^4.18.2" } }, - "node_modules/@faker-js/faker": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-7.6.0.tgz", - "integrity": "sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==", - "engines": { - "node": ">=14.0.0", - "npm": ">=6.0.0" - } - }, "node_modules/@noble/hashes": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", @@ -785,11 +774,6 @@ } }, "dependencies": { - "@faker-js/faker": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-7.6.0.tgz", - "integrity": "sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==" - }, "@noble/hashes": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", diff --git a/server/index.js b/server/index.js index cc302ca..94b6e31 100644 --- a/server/index.js +++ b/server/index.js @@ -8,14 +8,16 @@ app.use(express.json()); // TODO: hardcode a merkle root here representing the whole nice list // paste the hex string in here, without the 0x prefix -const MERKLE_ROOT = ''; +const MERKLE_ROOT = 'ddd59a2ffccddd60ff47993312821cd57cf30f7f14fb82937ebe2c4dc78375aa'; app.post('/gift', (req, res) => { // grab the parameters from the front-end here const body = req.body; + const name = body.name; + const proof = body.proof; // TODO: prove that a name is in the list - const isInTheList = false; + const isInTheList = verifyProof(proof, name, MERKLE_ROOT); if(isInTheList) { res.send("You got a toy robot!"); } diff --git a/utils/example.js b/utils/example.js index 7dcf6ff..5bfa669 100644 --- a/utils/example.js +++ b/utils/example.js @@ -7,6 +7,7 @@ const merkleTree = new MerkleTree(niceList); // get the root const root = merkleTree.getRoot(); +console.log(root) // find the proof that norman block is in the list const name = 'Norman Block';