Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thewawar/exclusion-merkle-cbt

Complete Binary Merkle Tree for verify exclusion
https://github.com/thewawar/exclusion-merkle-cbt

blacklist exclusion merkle tree

Last synced: about 1 month ago
JSON representation

Complete Binary Merkle Tree for verify exclusion

Awesome Lists containing this project

README

        

# Exclusion Complete Binary Merkle Tree
A merkle tree based on Nervos [Complete Binary Merkle Tree](https://github.com/nervosnetwork/merkle-tree) to support verifiing a leaf is not on a certain tree.

## Example Usage
```rust
type StrKey = &'static str;
type StrLeaf = SimpleLeaf;
type StrRangeLeaf = SimpleRangeLeaf;
// A helper to compute root and build proof
type StrExCBMT = SimpleExclusionCBMT;

// Can be seen as a black list
let all_leaves: Vec = vec!["b", "e", "g", "x"]
.into_iter()
.map(StrLeaf::new_with_key)
.collect();
let root = StrExCBMT::compute_root(&all_leaves);
// The keys not in the black list
let excluded_keys = vec!["f", "y", "z", "a"];
let proof = StrExCBMT::build_proof(&all_leaves, &excluded_keys).unwrap();
assert_eq!(
proof
.range_leaves()
.iter()
.map(|l| (*l.key(), *l.next_key()))
.collect::>(),
vec![("e", "g"), ("x", "b")]
);
assert!(proof
.verify_exclusion(&root, &excluded_keys)
.is_ok());
```