From 1abc5c49abb013f66663b39ac07fe4d530fa6eb5 Mon Sep 17 00:00:00 2001 From: srihar5ha Date: Thu, 8 Jun 2023 04:58:15 +0530 Subject: [PATCH] hard coded root. verify successfull. --- client/index.js | 18 ++++++++++++++---- package-lock.json | 16 ---------------- server/index.js | 10 ++++++++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/client/index.js b/client/index.js index 28980e4..192b131 100644 --- a/client/index.js +++ b/client/index.js @@ -5,12 +5,22 @@ const MerkleTree = require('../utils/MerkleTree'); const serverUrl = 'http://localhost:1225'; async function main() { - // TODO: how do we prove to the server we're on the nice list? +const MERKLE_ROOT = new MerkleTree(niceList); +const root = MERKLE_ROOT.getRoot(); +//console.log("root is ",root); + +const name = 'Norman Block'; +const index = niceList.findIndex(n => n === name); +const proof = MERKLE_ROOT.getProof(index); - const { data: gift } = await axios.post(`${serverUrl}/gift`, { - // TODO: add request body parameters here! - }); +const requestBody = { + proof: proof, + name : name +}; + // TODO: how do we prove to the server we're on the nice list? + const { data: gift } = await axios.post(`${serverUrl}/gift`, requestBody); + console.log("req sent from client"); 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..4610a63 100644 --- a/server/index.js +++ b/server/index.js @@ -1,5 +1,6 @@ const express = require('express'); const verifyProof = require('../utils/verifyProof'); +const MerkleTree = require('../utils/MerkleTree'); const port = 1225; @@ -8,14 +9,19 @@ 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 root='ddd59a2ffccddd60ff47993312821cd57cf30f7f14fb82937ebe2c4dc78375aa'; + app.post('/gift', (req, res) => { // grab the parameters from the front-end here const body = req.body; + const proof = body.proof; + const name = body.name; + + //console.log("server side, params ",proof,index) // TODO: prove that a name is in the list - const isInTheList = false; + const isInTheList = verifyProof(proof, name, root); if(isInTheList) { res.send("You got a toy robot!"); }