Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
/ sp4r53 Public archive

A sparse Merkle tree implementation that only recomputes its branches’ hashes when asked

License

Notifications You must be signed in to change notification settings

an0nym0u51y/sp4r53

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sparse Merkle tree

img img img

A sparse Merkle tree implementation that only recomputes its branches’ hashes when asked.

Example

use sp4r53::{blake3, Proof, Tree};

let foo = blake3::hash(b"foo");
let bar = blake3::hash(b"bar");
let baz = blake3::hash(b"baz");

let mut tree = Tree::new();

tree.insert(foo);
tree.insert(bar);
tree.insert(baz);
assert_eq!(tree.is_valid(), false);

let root = tree.flush();
assert_eq!(tree.is_valid(), true);
assert_eq!(tree.root(), Some(root));

let proof = tree.proove(&[foo, baz]).unwrap();
assert_eq!(proof.verify(root), true);

let encoded = proof.as_bytes();
let decoded = Proof::from_bytes(&encoded).unwrap();
assert_eq!(decoded, proof);

tree.remove(bar);

let root = tree.flush();
assert_eq!(proof.verify(root), false);

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

About

A sparse Merkle tree implementation that only recomputes its branches’ hashes when asked

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages