1 unstable release
0.1.0 | Oct 22, 2020 |
---|
#2127 in Cryptography
18KB
367 lines
use mrklt::{compute_root, create_proof, Merge, verify_proof};
struct MyHash;
impl Merge for MyHash {
type Hash = [u8; 32];
fn leaf(leaf: &[u8; 32]) -> [u8; 32] {
hash(&[leaf])
}
fn merge(left: &[u8; 32], right: &[u8; 32]) -> [u8; 32] {
hash(&[left, right])
}
}
let leaves = [[1u8; 32], [2u8; 32], [1u8; 32], [3u8; 32]];
let root = compute_root::<MyHash>(&leaves);
let proof = create_proof::<MyHash>(1, &leaves);
assert_eq!(root, verify_proof::<MyHash>(&leaves[1], &proof));
Dependencies
~165KB