-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (29 loc) · 874 Bytes
/
Copy pathindex.js
File metadata and controls
34 lines (29 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { MerkleTree } from "merkletreejs";
import keccak256 from "keccak256";
const eligibleAirdropParticipants = [
"Musab",
"Scoutan",
"Node",
"Dolapo",
"Gogo",
];
const leaves = eligibleAirdropParticipants.map((name) => keccak256(name));
const tree = new MerkleTree(leaves, keccak256);
const root = tree.getHexRoot();
//Proof verification function for any leaf
function checkIfNameIsValid(name) {
const nameHash = keccak256(name).toString("hex");
const nameProof = tree.getProof(nameHash);
const isNameValid = tree.verify(nameProof, nameHash, root);
if (isNameValid == true) {
console.log(`${name} is valid`);
} else {
console.log(`${name} is invalid`);
}
}
checkIfNameIsValid("Musab");
checkIfNameIsValid("Scoutan");
checkIfNameIsValid("Node");
checkIfNameIsValid("Dolapo");
checkIfNameIsValid("Gogo");
checkIfNameIsValid("Augustine");