You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

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