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

finished #10

Open
wants to merge 1 commit 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
8 changes: 8 additions & 0 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
1 change: 1 addition & 0 deletions utils/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down