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

final #4

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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1 point - briefly describe how you achieved the goals of the project (in the README.md)
1 point - project compiles and run
2 points - create a Merkle tree from the “nice” list
3 points - generate Merkle proof from the name in the “nice” list
3 points - verify name exists on the nice list on the server

Run the scripts to obtain the merkle root and add to the server. In the client add request body paramaters and server too. Import verify proof into server to check names on list.
# Gift List

To get started with the repository, clone it and then run `npm install` in the top-level directory to install the depedencies.
Expand Down
22 changes: 22 additions & 0 deletions client/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
const axios = require('axios');
const niceList = require('../utils/niceList.json');
const MerkleTree = require('../utils/MerkleTree');
// verify proof?
//root
const root = 'ddd59a2ffccddd60ff47993312821cd57cf30f7f14fb82937ebe2c4dc78375aa';

const verifyProof = require('../utils/verifyProof');

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

async function main() {
// TODO: how do we prove to the server we're on the nice list?
const name = 'Norman Block'
console.log('name', name)
// find index in the nice list
const index = niceList.findIndex(_name => _name === name );
console.log('index', index)
// get proof

const merkleTree = new MerkleTree(niceList)
//console.log('merkletree', merkleTree)
const proof = merkleTree.getProof(index)
//console.log('proof', proof)
//const inList = verifyProof(proof, name, root)


const { data: gift } = await axios.post(`${serverUrl}/gift`, {
// TODO: add request body parameters here!
// verify proof is on the server
// surround with own object
proof: proof,
name: name
});

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.

13 changes: 10 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ 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;
// axios destructuring object to input variables from client
//const {variables } = req.body
// not const proof = req.proof et`
const {proof, name} = req.body;

// TODO: prove that a name is in the list
const isInTheList = false;

let isInTheList = false;

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