chrono_merkle/
lib.rs

1//! # ChronoMerkle Tree
2//!
3//! A time-aware Merkle tree implementation with delta-based updates, programmable nodes,
4//! and sparse timestamp indexing. Designed for blockchain and distributed systems.
5//!
6//! ## Features
7//!
8//! - **Time-aware**: Each leaf includes a timestamp for efficient time-based queries
9//! - **Delta-based updates**: Only affected branches are recomputed on insert
10//! - **Programmable nodes**: Custom validation logic at internal nodes
11//! - **Sparse indexing**: Fast timestamp-based lookups and range queries
12//! - **Generic**: Works with any hash function and hash size
13//!
14//! ## Example
15//!
16//! ```rust
17//! use chrono_merkle::{ChronoMerkleTree, Blake3Hasher};
18//!
19//! let mut tree: ChronoMerkleTree = ChronoMerkleTree::new(Blake3Hasher::default());
20//! tree.insert(b"data1", 1000).unwrap();
21//! tree.insert(b"data2", 1001).unwrap();
22//!
23//! let proof = tree.generate_proof(0).unwrap();
24//! assert!(tree.verify_proof(&proof).unwrap());
25//! ```
26
27#![cfg_attr(feature = "no-std", no_std)]
28
29#[cfg(feature = "no-std")]
30extern crate alloc;
31
32pub mod config;
33pub mod constructors;
34pub mod delta;
35pub mod error;
36pub mod hash;
37pub mod node;
38pub mod operations;
39pub mod proof;
40pub mod proofs;
41pub mod rebuild;
42pub mod security;
43pub mod sparse_index;
44pub mod storage;
45pub mod tree;
46pub mod traits;
47pub mod validation;
48pub mod visualization;
49
50// Re-export tree configuration and types
51
52#[cfg(feature = "serde")]
53pub mod serde_impl;
54
55#[cfg(feature = "clockhash")]
56pub mod clockhash;
57
58#[cfg(feature = "clockhash")]
59pub use clockhash::ClockHashAdapter;
60
61// Re-exports
62pub use error::ChronoMerkleError;
63#[cfg(feature = "blake3-hash")]
64pub use hash::Blake3Hasher;
65pub use hash::HashFunction;
66pub use node::{Node, NodeType};
67pub use proof::{ChronoProof, ProofStep};
68pub use security::{SecurityEvent, SecurityEventType, SecurityLevel, SecurityLogger, NoOpLogger};
69#[cfg(feature = "std")]
70pub use security::StdErrLogger;
71pub use sparse_index::SparseIndex;
72#[cfg(feature = "storage")]
73pub use storage::MemoryStorage;
74#[cfg(all(feature = "storage", feature = "std", not(feature = "no-std")))]
75pub use storage::FileStorage;
76pub use tree::{ChronoMerkleTree, TreeConfig};
77
78/// Type alias for the most common ChronoMerkleTree configuration.
79///
80/// This uses Blake3 hashing with 32-byte outputs and a no-op security logger.
81/// Suitable for most applications requiring time-aware Merkle trees.
82pub type DefaultChronoMerkleTree = ChronoMerkleTree<[u8; 32], Blake3Hasher, NoOpLogger>;
83
84// Conditionally re-export DefaultHasher based on features
85#[cfg(any(feature = "sha2-hash", not(any(feature = "sha2-hash", feature = "blake3-hash"))))]
86pub use hash::DefaultHasher;
87
88#[cfg(test)]
89mod tests;