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 MerkleTree from the 100 random leaves. let tree: MerkleTree = std::iter::repeat([0u8; 32]) .map(|mut leaf| { randcore::OsRng.fillbytes(&mut leaf); leaf }) .take(100) .collect();

// Verifies the proof of inclusion, 12th and 98th leaves. asserteq!( tree.proof(&[12, 98]) .unwrap() .verify(&[ (98, tree.leaves().nth(98).unwrap()), (12, tree.leaves().nth(12).unwrap()), ]) .unwrap() .asref(), tree.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.