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

Create the merkle tree, proof and verify #1

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.DS_Store

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
14 changes: 13 additions & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ const MerkleTree = require('../utils/MerkleTree');

const serverUrl = 'http://localhost:1225';

const index = niceList.findIndex(n => n === process.argv[2]);
if (!index || index < 0 || index > niceList.length || !process.argv[2]) {
console.log('Name not found in nice list!');
process.exit(1);
}

const leaf = process.argv[3];
const merkleTree = new MerkleTree(niceList);
const proof = merkleTree.getProof(index);


async function main() {
// TODO: how do we prove to the server we're on the nice list?

const { data: gift } = await axios.post(`${serverUrl}/gift`, {
// TODO: add request body parameters here!
leaf,
proof,
});

console.log({ gift });
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3"

services:
node-server:
tty: true
build:
context: .
dockerfile: docker/nodejs/Dockerfile
ports:
- 1225:1225
restart: unless-stopped
volumes:
- ./:/app
5 changes: 5 additions & 0 deletions docker/nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:18.12
LABEL name="Fazal-E-Rabbi" email="[email protected]"

WORKDIR /app
EXPOSE 1225
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.

12 changes: 10 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ 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 niceList = require('../utils/niceList.json');
// const MerkleTree = require('../utils/MerkleTree');
// const merkleTree = new MerkleTree(niceList);

// const root = merkleTree.getRoot();
// console.log(root);

const MERKLE_ROOT = 'ddd59a2ffccddd60ff47993312821cd57cf30f7f14fb82937ebe2c4dc78375aa';

app.post('/gift', (req, res) => {
// grab the parameters from the front-end here
const body = req.body;

// TODO: prove that a name is in the list
const isInTheList = false;
const isInTheList = verifyProof(body.proof, body.leaf, MERKLE_ROOT);
if(isInTheList) {
res.send("You got a toy robot!");
}
Expand Down