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 narrow_range<L>(
&self,
left_extra_raw_leaves: &[L],
right_extra_raw_leaves: &[L],
leaf_namespace: NamespaceId<NS_ID_SIZE>,
) -> Result<NamespaceProof<M, NS_ID_SIZE>, RangeProofError>
pub fn narrow_range<L>( &self, left_extra_raw_leaves: &[L], right_extra_raw_leaves: &[L], leaf_namespace: NamespaceId<NS_ID_SIZE>, ) -> Result<NamespaceProof<M, NS_ID_SIZE>, RangeProofError>
Narrows the proof range: uses an existing proof to create a new proof for a subrange of the original proof’s range
§Arguments
- left_extra_raw_leaves: The data for the leaves that will narrow the range from the left side (i.e. all the leaves from the left edge of the currently proven range, to the left edge of the new desired shrunk range)
- right_extra_raw_leaves: Analogously, data for all the leaves between the right edge of the desired shrunken range, and the right edge of the current proof’s range
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
Source§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 NmtProof
impl From<NamespaceProof> for NmtProof
Source§fn from(value: NamespaceProof) -> Self
fn from(value: NamespaceProof) -> Self
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 decode_vec(v: &[u8]) -> Result<Self, Error>
fn decode_vec(v: &[u8]) -> Result<Self, Error>
Vec<u8> (or equivalent).Source§impl Serialize for NamespaceProof
impl Serialize for NamespaceProof
Source§impl TryFrom<NmtProof> for NamespaceProof
impl TryFrom<NmtProof> 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§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.