A simple, fast, and composable binary [Merkle tree and proof] for [Rust Crypto] hash functions.
Here is how to create MerkleTree
and MerkleProof
for the ordered array of cryptographic hashes:
```
use randcore::RngCore;
use sha3::Sha3256;
use merkle_lite::MerkleTree;
// 100 random leaves. let leaves: Vec<_> = std::iter::repeat([0u8; 32]) .map(|mut leaf| { randcore::OsRng.fillbytes(&mut leaf); leaf }) .take(100) .collect();
// A Merkle tree composed from the leaves.
let tree: MerkleTree
// A proof of inclusion for an arbitrary number of leaves // specified by the 0-indexed ordered indices. let proof = tree.proof(&[12, 98]).unwrap();
// verify the merkle proof of inclusion by comparing the // result to the Merkle root. let inclusion = vec![(98, &leaves[98]), (12, &leaves[12])]; asserteq!( proof.verify(&inclusion).unwrap().asref(), tree.root(), ); ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.