merkle-lite

CI License Cargo Documentation

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

Examples

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;

// Composes a MerkleTree for the 50,000 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 particular leaves. let leafindices = [12, 0, 1, 1201, 13903, 980]; let leafhashes: Vec<_> = leafindices .iter().map(|index| (index, tree.leaves().nth(index).expect("leaf"))) .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.