Skip to main content

nectar_primitives/bmt/
mod.rs

1//! Binary Merkle Tree (BMT) implementation
2//!
3//! This module provides an optimized implementation of a Binary Merkle Tree
4//! for hashing data in parallel and generating proofs of inclusion.
5//!
6//! ## Key Components
7//!
8//! - **Hasher**: Core BMT hashing functionality with span support
9//! - **Proof**: Inclusion proofs for efficient verification
10//! - **Prover**: Interface for generating and verifying proofs
11//!
12//! ## Example Usage
13//!
14//! ```
15//! use nectar_primitives::bmt::{Hasher, Prover};
16//!
17//! // Create a hasher and update with data
18//! let data = b"hello world";
19//! let mut hasher = Hasher::new();
20//! hasher.set_span(data.len() as u64);
21//! hasher.update(data);
22//!
23//! // Get the hash
24//! let hash = hasher.sum();
25//!
26//! // Generate a proof for the first segment
27//! let proof = hasher.generate_proof(data, 0).unwrap();
28//!
29//! // Verify the proof
30//! assert!(Hasher::verify_proof(&proof, hash.as_slice()).unwrap());
31//! ```
32
33mod constants;
34pub(crate) mod error;
35mod hasher;
36mod proof;
37
38pub use constants::{BRANCHES, DEFAULT_BODY_SIZE, HASH_SIZE, SPAN_SIZE};
39pub use hasher::{Hasher, HasherFactory};
40pub use proof::{Proof, Prover};
41
42// Re-export for convenience
43pub use crate::error::{PrimitivesError, Result};
44
45#[cfg(target_arch = "wasm32")]
46pub mod wasm;
47
48#[cfg(test)]
49mod tests;