Struct celestia_types::nmt::NamespaceProof
source · pub struct NamespaceProof(/* private fields */);Expand description
Merkle proof of inclusion or absence of some data in the Nmt.
§Example
use nmt_rs::NamespaceMerkleHasher;
use celestia_types::nmt::{Namespace, Nmt, NamespacedSha2Hasher, EMPTY_LEAVES};
let ns1 = Namespace::new_v0(&[1]).unwrap();
let ns2 = Namespace::new_v0(&[2]).unwrap();
let ns3 = Namespace::new_v0(&[3]).unwrap();
let ns4 = Namespace::new_v0(&[4]).unwrap();
let leaves = [
(ns1, b"leaf0"),
(ns2, b"leaf1"),
(ns2, b"leaf2"),
(ns4, b"leaf3"),
];
// create the nmt and feed it with data
let mut nmt = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true));
for (namespace, data) in leaves {
nmt.push_leaf(data, *namespace);
}
// create and verify the proof of inclusion of namespace 2 data
let root = nmt.root();
let proof = nmt.get_namespace_proof(*ns2);
assert!(proof.is_of_presence());
assert!(
proof.verify_complete_namespace(&root, &["leaf1", "leaf2"], *ns2).is_ok()
);
// create and verify the proof of absence of namespace 3 data
let proof = nmt.get_namespace_proof(*ns3);
assert!(proof.is_of_absence());
assert!(
proof.verify_complete_namespace(&root, EMPTY_LEAVES, *ns3).is_ok()
);Implementations§
source§impl NamespaceProof
impl NamespaceProof
sourcepub fn into_inner(self) -> NamespaceProof<NamespacedSha2Hasher, NS_SIZE>
pub fn into_inner(self) -> NamespaceProof<NamespacedSha2Hasher, NS_SIZE>
Convert the proof to the underlying nmt_rs equivalent.
sourcepub fn leaf(&self) -> Option<&NamespacedHash>
pub fn leaf(&self) -> Option<&NamespacedHash>
Get the hash of the leaf following the Namespace which absence is being proven.
If the tree had contained the proven namespace, it should be in the tree right before the leaf returned by this function.
This function returns None if the proof isn’t an AbsenceProof or the
proven Namespace is not in the range of the tree root NamespacedHash.
sourcepub fn max_ns_ignored(&self) -> bool
pub fn max_ns_ignored(&self) -> bool
Returns true if the proof ignores all the leaves inserted with
Namespace::PARITY_SHARE.
Methods from Deref<Target = NamespaceProof<NamespacedSha2Hasher, NS_SIZE>>§
sourcepub fn verify_complete_namespace(
&self,
root: &NamespacedHash<NS_ID_SIZE>,
raw_leaves: &[impl AsRef<[u8]>],
namespace: NamespaceId<NS_ID_SIZE>,
) -> Result<(), RangeProofError>
pub fn verify_complete_namespace( &self, root: &NamespacedHash<NS_ID_SIZE>, raw_leaves: &[impl AsRef<[u8]>], namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<(), RangeProofError>
Verify that the provided raw leaves are a complete namespace. This may be a proof of presence or absence.
sourcepub fn verify_range(
&self,
root: &NamespacedHash<NS_ID_SIZE>,
raw_leaves: &[impl AsRef<[u8]>],
leaf_namespace: NamespaceId<NS_ID_SIZE>,
) -> Result<(), RangeProofError>
pub fn verify_range( &self, root: &NamespacedHash<NS_ID_SIZE>, raw_leaves: &[impl AsRef<[u8]>], leaf_namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<(), RangeProofError>
Verify a that the provided raw leaves are a (1) present and (2) form a contiguous subset of some namespace
sourcepub fn convert_to_absence_proof(&mut self, leaf: NamespacedHash<NS_ID_SIZE>)
pub fn convert_to_absence_proof(&mut self, leaf: NamespacedHash<NS_ID_SIZE>)
Convert a proof of the presence of some leaf to the proof of the absence of another leaf
sourcepub fn siblings(&self) -> &[NamespacedHash<NS_ID_SIZE>]
pub fn siblings(&self) -> &[NamespacedHash<NS_ID_SIZE>]
Returns the siblings provided as part of the proof
sourcepub fn leftmost_right_sibling(&self) -> Option<&NamespacedHash<NS_ID_SIZE>>
pub fn leftmost_right_sibling(&self) -> Option<&NamespacedHash<NS_ID_SIZE>>
Returns the leftmost node to the right of the proven range, if one exists
sourcepub fn rightmost_left_sibling(&self) -> Option<&NamespacedHash<NS_ID_SIZE>>
pub fn rightmost_left_sibling(&self) -> Option<&NamespacedHash<NS_ID_SIZE>>
Returns the rightmost node to the left of the proven range, if one exists
sourcepub fn is_of_absence(&self) -> bool
pub fn is_of_absence(&self) -> bool
Returns true if the proof is an absence proof
sourcepub fn is_of_presence(&self) -> bool
pub fn is_of_presence(&self) -> bool
Returns true if the proof is a presence proof
Trait Implementations§
source§impl Clone for NamespaceProof
impl Clone for NamespaceProof
source§fn clone(&self) -> NamespaceProof
fn clone(&self) -> NamespaceProof
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for NamespaceProof
impl Debug for NamespaceProof
source§impl Deref for NamespaceProof
impl Deref for NamespaceProof
§type Target = NamespaceProof<NamespacedSha2Hasher<NS_SIZE>, NS_SIZE>
type Target = NamespaceProof<NamespacedSha2Hasher<NS_SIZE>, NS_SIZE>
source§impl DerefMut for NamespaceProof
impl DerefMut for NamespaceProof
source§impl<'de> Deserialize<'de> for NamespaceProof
impl<'de> Deserialize<'de> for NamespaceProof
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<NamespaceProof<NamespacedSha2Hasher<NS_SIZE>, NS_SIZE>> for NamespaceProof
impl From<NamespaceProof<NamespacedSha2Hasher<NS_SIZE>, NS_SIZE>> for NamespaceProof
source§fn from(value: NamespaceProof<NamespacedSha2Hasher, NS_SIZE>) -> NamespaceProof
fn from(value: NamespaceProof<NamespacedSha2Hasher, NS_SIZE>) -> NamespaceProof
source§impl From<NamespaceProof> for NamespaceProof<NamespacedSha2Hasher, NS_SIZE>
impl From<NamespaceProof> for NamespaceProof<NamespacedSha2Hasher, NS_SIZE>
source§fn from(value: NamespaceProof) -> NamespaceProof<NamespacedSha2Hasher, NS_SIZE>
fn from(value: NamespaceProof) -> NamespaceProof<NamespacedSha2Hasher, NS_SIZE>
source§impl From<NamespaceProof> for Proof
impl From<NamespaceProof> for Proof
source§fn from(value: NamespaceProof) -> Self
fn from(value: NamespaceProof) -> Self
source§impl PartialEq for NamespaceProof
impl PartialEq for NamespaceProof
source§impl Protobuf<Proof> for NamespaceProof
impl Protobuf<Proof> for NamespaceProof
source§fn encode<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
source§fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
source§fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
source§fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
source§fn encode_vec(&self) -> Result<Vec<u8>, Infallible>
fn encode_vec(&self) -> Result<Vec<u8>, Infallible>
Vec<u8>.source§fn decode_vec(v: &[u8]) -> Result<Self, Error>
fn decode_vec(v: &[u8]) -> Result<Self, Error>
Vec<u8> (or equivalent).source§fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>
fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>
Vec<u8> Protobuf-encoded message.source§impl Serialize for NamespaceProof
impl Serialize for NamespaceProof
source§impl TryFrom<Proof> for NamespaceProof
impl TryFrom<Proof> for NamespaceProof
impl StructuralPartialEq for NamespaceProof
Auto Trait Implementations§
impl Freeze for NamespaceProof
impl RefUnwindSafe for NamespaceProof
impl Send for NamespaceProof
impl Sync for NamespaceProof
impl Unpin for NamespaceProof
impl UnwindSafe for NamespaceProof
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)