Skip to main content

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//! - [`SnapshotStore`]: Cache recovered issuer snapshot state by batch id (requires `std`)
23//! - [`BatchEventHandler`]: Handle batch events from the blockchain (requires `std`)
24//!
25//! # Features
26//!
27//! - `std` (default): Enable standard library support, BatchStore, events
28//! - `serde`: Enable serde serialization/deserialization
29//! - `parallel`: Enable parallel verification with rayon
30
31#![cfg_attr(not(test), warn(unused_crate_dependencies))]
32#![cfg_attr(not(feature = "std"), no_std)]
33#![cfg_attr(docsrs, feature(doc_cfg))]
34
35// k256 is a dependency only to enable the precomputed-tables feature for faster ECDSA
36#[cfg(not(test))]
37use k256 as _;
38
39mod batch;
40mod error;
41mod stamp;
42mod util;
43mod validation;
44
45// Storage and events (std only)
46#[cfg(feature = "std")]
47mod events;
48#[cfg(feature = "std")]
49mod snapshot_store;
50#[cfg(feature = "std")]
51mod store;
52
53// Parallel verification (requires rayon)
54#[cfg(feature = "parallel")]
55pub mod parallel;
56
57// Core types
58pub use batch::{Batch, BatchId, BatchParams};
59pub use error::StampError;
60pub use stamp::{STAMP_SIZE, Stamp, StampBytes, StampDigest, StampIndex};
61pub use util::{PostageContext, calculate_bucket, current_timestamp};
62pub use validation::StampValidator;
63#[cfg(feature = "std")]
64pub use validation::StoreValidator;
65
66// Storage and events (std only)
67#[cfg(feature = "std")]
68pub use events::{BatchEvent, BatchEventHandler};
69#[cfg(feature = "std")]
70pub use snapshot_store::SnapshotStore;
71#[cfg(feature = "std")]
72pub use store::{BatchStore, BatchStoreError, BatchStoreExt};
73
74// Re-export VerifyingKey for cached pubkey verification optimization
75pub use alloy_signer::k256::ecdsa::VerifyingKey;