pub struct MerkleProof { /* private fields */ }unstable only.Expand description
An inclusion proof for a leaf in a MerkleTree.
The path lists each sibling hash on the way from the leaf up to the root.
Implementations§
Source§impl MerkleProof
impl MerkleProof
Sourcepub fn new(path: Vec<Node>) -> Self
pub fn new(path: Vec<Node>) -> Self
Construct a proof directly from a sibling path. Mostly useful for
tests and for callers reconstructing a proof from out-of-band data;
most users obtain proofs via MerkleTree::get_proof.
Sourcepub fn path(&self) -> &[Node]
pub fn path(&self) -> &[Node]
The sibling hashes on the path from the leaf to the root, leaf-side first.
Sourcepub fn verify_proof_with_leaf_bytes(
&self,
root: &Node,
leaf_bytes: &[u8],
leaf_index: usize,
) -> Result<(), MerkleError>
pub fn verify_proof_with_leaf_bytes( &self, root: &Node, leaf_bytes: &[u8], leaf_index: usize, ) -> Result<(), MerkleError>
Verify that the leaf identified by the given canonical bytes at
position leaf_index is included in the tree whose root is root.
leaf_bytes must be the same byte representation that was hashed
into the tree when it was built — for trees built via
MerkleTree::build_from_unserialized that is the leaf’s BCS
encoding. Most callers that already have the leaf in its structured
form should use verify_proof instead, which performs that BCS
step internally.
Sourcepub fn verify_proof<L: Serialize>(
&self,
root: &Node,
leaf: &L,
leaf_index: usize,
) -> Result<(), MerkleError>
pub fn verify_proof<L: Serialize>( &self, root: &Node, leaf: &L, leaf_index: usize, ) -> Result<(), MerkleError>
Verify that leaf at position leaf_index is included in the tree
whose root is root.
The leaf is BCS-encoded internally to obtain the canonical byte
representation that the tree commits to. Use
verify_proof_with_leaf_bytes when the caller already has those
bytes.
Sourcepub fn compute_root(&self, leaf: &[u8], leaf_index: usize) -> Option<Node>
pub fn compute_root(&self, leaf: &[u8], leaf_index: usize) -> Option<Node>
Recompute the root from the proof and leaf at leaf_index.
Returns None if leaf_index cannot fit in a tree of
self.path.len() levels (which would imply the proof was tampered
with or never matched this index).
Sourcepub fn is_right_most(&self, leaf_index: usize) -> bool
pub fn is_right_most(&self, leaf_index: usize) -> bool
Whether this proof identifies the right-most leaf in its tree.
A right-most proof has the property that every step where the leaf is
a left child carries an Empty sibling — the only way to be on the
extreme right of a padded power-of-two tree.
Trait Implementations§
Source§impl Clone for MerkleProof
impl Clone for MerkleProof
Source§fn clone(&self) -> MerkleProof
fn clone(&self) -> MerkleProof
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MerkleProof
impl Debug for MerkleProof
Source§impl PartialEq for MerkleProof
impl PartialEq for MerkleProof
impl Eq for MerkleProof
impl StructuralPartialEq for MerkleProof
Auto Trait Implementations§
impl Freeze for MerkleProof
impl RefUnwindSafe for MerkleProof
impl Send for MerkleProof
impl Sync for MerkleProof
impl Unpin for MerkleProof
impl UnsafeUnpin for MerkleProof
impl UnwindSafe for MerkleProof
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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
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>
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>
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