arnaucube
arnaucube/merkletree-rsPublic Self-hosted repository
merkletree-rs/README.md
README.mdRaw
 1# merkletree-rs
 2Sparse MerkleTree implementation in Rust.
 3
 4The MerkleTree is optimized in the design and concepts, to have a faster and lighter MerkleTree, maintaining compatibility with a non optimized MerkleTree. In this way, the MerkleRoot of the optimized MerkleTree will be the same that the MerkleRoot of the non optimized MerkleTree.
 5
 6
 7## Usage
 8Create new tree:
 9```rust
10let mut mt: MerkleTree = new(140);
11```
12
13Add value to leaf:
14```rust
15let val = TestValue {
16  bytes: "this is a test leaf".as_bytes().to_vec(),
17  index_length: 15,
18};
19mt.add(&val);
20```
21
22Get proof:
23```rust
24let mp = mt.generate_proof(val.hi());
25```
26
27Verify proof:
28```rust
29// check if the value exist
30let v = verify_proof(mt.root, mp, val.hi(), val.ht(), mt.num_levels);
31
32// check if the don't value exist
33let v = verify_proof(mt.root, mp, val.hi(), EMPTYNODEVALUE, mt.num_levels);
34```