From 027269c14338754bb5b0f8eb931245f81bf7c203 Mon Sep 17 00:00:00 2001 From: sanemi07 <130812101+sanemi07@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:37:02 +0530 Subject: [PATCH 1/2] Update index.js --- client/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/index.js b/client/index.js index 28980e4..75ce34e 100644 --- a/client/index.js +++ b/client/index.js @@ -6,12 +6,20 @@ const serverUrl = 'http://localhost:1225'; async function main() { // TODO: how do we prove to the server we're on the nice list? + const tree=new MerkleTree(niceList); + const name ="Joel Raynor"; + const root = tree.getRoot(); + const index=niceList.findIndex(n => n === name); + const proof=tree.getProof(index); const { data: gift } = await axios.post(`${serverUrl}/gift`, { // TODO: add request body parameters here! - }); + name:name, + proof:proof, + }); +console.log("sending to the server",{name,proof}); console.log({ gift }); } -main(); \ No newline at end of file +main(); From 9c8d5e1c52aa6cb89a5b8dcb66a42c7af8f5e629 Mon Sep 17 00:00:00 2001 From: sanemi07 <130812101+sanemi07@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:37:40 +0530 Subject: [PATCH 2/2] Update index.js --- server/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/index.js b/server/index.js index cc302ca..30e9c35 100644 --- a/server/index.js +++ b/server/index.js @@ -1,5 +1,6 @@ const express = require('express'); const verifyProof = require('../utils/verifyProof'); +const { keccak256 } = require('ethereum-cryptography/keccak'); const port = 1225; @@ -8,14 +9,14 @@ 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 = '4cdf89e56895bbcabd3551d431b8ba74239d026cfac7af5fcb1c15934a4eaf34'; app.post('/gift', (req, res) => { - // grab the parameters from the front-end here - const body = req.body; + const {name,proof}=req.body; + const lea=keccak256(Buffer.from(name)).toString('hex'); // TODO: prove that a name is in the list - const isInTheList = false; + const isInTheList = tree.verifyProof(lea,proof,MERKLE_ROOT); if(isInTheList) { res.send("You got a toy robot!"); }