#merkle-tree #proof #tree-root #hash #u8 #merge #compute

mrklt

简单的Merkle树库,用于:计算根、生成证明和验证证明

1个不稳定版本

0.1.0 2020年10月22日

#1997 in 加密学

MIT/Apache

18KB
367

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));

依赖项

~170KB