pub struct MerkleTree<T: Serialize> { /* private fields */ }Expand description
A Merkle tree.
§Examples
use hash_based_signatures::merkle_tree::MerkleTree;
let elements: Vec<u8> = (0..128).collect();
let tree = MerkleTree::new(&elements);
let proof = tree.get_proof(17);
assert!(proof.verify(*tree.get_root_hash(), &17));Implementations§
Source§impl<T: Serialize + Debug> MerkleTree<T>
impl<T: Serialize + Debug> MerkleTree<T>
Sourcepub fn new(elements: &[T]) -> MerkleTree<T>
pub fn new(elements: &[T]) -> MerkleTree<T>
Construct a new Merkle tree from a list of elements.
A single element is of type Vec<u8>, so any complex data structure has
to be serialized to a variable-length byte array.
The tree owns the values.
§Panics
Panics if the number of elements is not a power of two or if the provided data can’t be serialized.
Sourcepub fn get_root_hash(&self) -> &[u8; 32]
pub fn get_root_hash(&self) -> &[u8; 32]
Get the root hash of the tree.
Sourcepub fn get_proof(&self, i: usize) -> MerkleProof<T>
pub fn get_proof(&self, i: usize) -> MerkleProof<T>
Get a Merkle proof for a given index i.
Trait Implementations§
Source§impl<T: Clone + Serialize> Clone for MerkleTree<T>
impl<T: Clone + Serialize> Clone for MerkleTree<T>
Source§fn clone(&self) -> MerkleTree<T>
fn clone(&self) -> MerkleTree<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for MerkleTree<T>
impl<T> RefUnwindSafe for MerkleTree<T>where
T: RefUnwindSafe,
impl<T> Send for MerkleTree<T>where
T: Send,
impl<T> Sync for MerkleTree<T>where
T: Sync,
impl<T> Unpin for MerkleTree<T>where
T: Unpin,
impl<T> UnwindSafe for MerkleTree<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more