arnaucube
arnaucube/merkletree-rsPublic Self-hosted repository
merkletree-rs/README.md
README.mdRaw
 1# merkletree-rs [![Build Status](https://travis-ci.org/arnaucube/merkletree-rs.svg?branch=master)](https://travis-ci.org/arnaucube/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
 6Compatible with the Go version: https://github.com/arnaucube/go-merkletree
 7
 8
 9## Usage
10Create new tree:
11```rust
12let mut mt: MerkleTree = new(140);
13```
14
15Add value to leaf:
16```rust
17let val = TestValue {
18  bytes: "this is a test leaf".as_bytes().to_vec(),
19  index_length: 15,
20};
21mt.add(&val);
22```
23
24Get proof:
25```rust
26let mp = mt.generate_proof(val.hi());
27```
28
29Verify proof:
30```rust
31// check if the value exist
32let v = verify_proof(mt.root, mp, val.hi(), val.ht(), mt.num_levels);
33
34// check if the don't value exist
35let v = verify_proof(mt.root, mp, val.hi(), EMPTYNODEVALUE, mt.num_levels);
36```