merkle-lite

CI License Cargo Documentation

A simple, fast, and composable binary [Merkle tree and proof] for [Rust Crypto] hash functions.

Examples

It's super simple to compose MerkleTree from the ordered array of hashes and verify the proof of inclusion with MerkleProof:

``` use merklelite::MerkleTree; use randcore::RngCore;

// Composes MerkleTree from the 50,000 random hashes. let tree: MerkleTree = std::iter::repeat([0u8; 32]) .map(|mut leaf| { randcore::OsRng.fillbytes(&mut leaf); leaf }) .take(50_000) .collect();

// Verifies the proof of inclusion for the arbitrary leaves. let treeleaves = tree.getleaves(); let leafindices = [12, 0, 1, 1201, 13903, 980]; let leafhashes: Vec<_> = leafindices .iter() .map(|index| (index, tree_leaves[index])) .collect(); asserteq!( tree.proof(&leafindices) .expect("proof") .verify(&leafhashes) .expect("verify") .asref(), tree.root().expect("root"), ); ```

License

Licensed under either of

at your option.

Contribution

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.