This repository contains a simple implementation of a Merkle Tree in JavaScript using the merkletreejs
library. The code creates a Merkle Tree from a list of Ethereum wallet addresses and provides a function to verify the authenticity of a given address within the constructed Merkle Tree. The SHA256 hashing algorithm is used to hash the addresses and build the Merkle Tree.
-
Address List:
- A predefined array (
addresses
) contains Ethereum wallet addresses.
- A predefined array (
-
Hashing Addresses:
- Each address is hashed using the SHA256 algorithm, resulting in an array of hashed addresses (
leaves
).
- Each address is hashed using the SHA256 algorithm, resulting in an array of hashed addresses (
-
Building the Merkle Tree:
- The Merkle Tree is constructed using the
merkletreejs
library, with the hashed addresses as leaves and the SHA256 hash function.
- The Merkle Tree is constructed using the
-
Computing the Root:
- The root of the Merkle Tree is computed and converted to a hexadecimal string.
-
Verification Function (
verify
):- The
verify
function takes an Ethereum wallet address as input. - It hashes the address to obtain the corresponding leaf in the Merkle Tree.
- The proof of inclusion for the leaf is retrieved from the tree.
- The function checks if the leaf, proof, and root match to determine the authenticity of the address.
- The
-
Example Usage:
- The provided example code demonstrates how to use the Merkle Tree and the verification function.
-
Installation:
- Install the required dependencies using
npm install merkletreejs crypto-js
.
- Install the required dependencies using
-
Run the Script:
- Copy the code from
merkle-tree-verification.js
into a JavaScript file. - Execute the script with Node.js:
node your-script-name.js
.
- Copy the code from
-
Customization:
- Modify the
addresses
array or integrate the code into your project as needed.
- Modify the
Feel free to explore and use this Merkle Tree implementation for secure verification of Ethereum wallet addresses.