Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

week 2 project #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
main();
9 changes: 5 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const verifyProof = require('../utils/verifyProof');
const { keccak256 } = require('ethereum-cryptography/keccak');

const port = 1225;

Expand All @@ -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!");
}
Expand Down