nectar_postage/lib.rs
1//! Postage stamp primitives for Ethereum Swarm.
2//!
3//! This crate provides the core types and traits for postage stamps in the Swarm network.
4//! It is optimized for verification use cases (such as `vertex` nodes).
5//!
6//! For stamp issuing and signing, use the
7//! [`nectar-postage-issuer`](https://docs.rs/nectar-postage-issuer) crate.
8//!
9//! # Core Types
10//!
11//! - [`Batch`]: A postage batch representing prepaid storage
12//! - [`Stamp`]: A postage stamp proving payment for chunk storage
13//! - [`StampIndex`]: The bucket and position index within a stamp
14//! - [`StampDigest`]: The data to be signed when creating a stamp
15//! - [`PostageContext`]: Context for batch expiry calculations
16//! - [`BatchEvent`]: Events emitted by the postage stamp contract (requires `std`)
17//!
18//! # Traits
19//!
20//! - [`StampValidator`]: Validate stamps against batches
21//! - [`BatchStore`]: Persist and retrieve batches (requires `std`)
22//! - [`BatchEventHandler`]: Handle batch events from the blockchain (requires `std`)
23//!
24//! # Features
25//!
26//! - `std` (default): Enable standard library support, BatchStore, events
27//! - `serde`: Enable serde serialization/deserialization
28//! - `parallel`: Enable parallel verification with rayon
29
30#![cfg_attr(not(test), warn(unused_crate_dependencies))]
31#![cfg_attr(not(feature = "std"), no_std)]
32#![cfg_attr(docsrs, feature(doc_cfg))]
33
34// k256 is a dependency only to enable the precomputed-tables feature for faster ECDSA
35#[cfg(not(test))]
36use k256 as _;
37
38mod batch;
39mod error;
40mod stamp;
41mod util;
42mod validation;
43
44// Storage and events (std only)
45#[cfg(feature = "std")]
46mod events;
47#[cfg(feature = "std")]
48mod store;
49
50// Parallel verification (requires rayon)
51#[cfg(feature = "parallel")]
52pub mod parallel;
53
54// Core types
55pub use batch::{Batch, BatchId, BatchParams};
56pub use error::StampError;
57pub use stamp::{STAMP_SIZE, Stamp, StampBytes, StampDigest, StampIndex};
58pub use util::{PostageContext, calculate_bucket, current_timestamp};
59pub use validation::StampValidator;
60#[cfg(feature = "std")]
61pub use validation::StoreValidator;
62
63// Storage and events (std only)
64#[cfg(feature = "std")]
65pub use events::{BatchEvent, BatchEventHandler};
66#[cfg(feature = "std")]
67pub use store::{BatchStore, BatchStoreError, BatchStoreExt};
68
69// Re-export VerifyingKey for cached pubkey verification optimization
70pub use alloy_signer::k256::ecdsa::VerifyingKey;