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`). The trait is
22//! synchronous and, having an associated `Error` and no generic methods, is
23//! naturally object-safe; drive it from an async edge (a gRPC service, an FFI
24//! boundary) where async is genuinely needed, rather than colouring the core.
25//! - [`SnapshotStore`]: Cache recovered issuer snapshot state by batch id (requires `std`)
26//! - [`BatchEventHandler`]: Handle batch events from the blockchain (requires `std`)
27//!
28//! # Features
29//!
30//! - `std` (default): Enable standard library support, BatchStore, events
31//! - `serde`: Enable serde serialization/deserialization
32//! - `parallel`: Enable parallel verification with rayon
33
34#![cfg_attr(not(test), warn(unused_crate_dependencies))]
35#![cfg_attr(not(feature = "std"), no_std)]
36#![cfg_attr(docsrs, feature(doc_cfg))]
37
38// k256 is a dependency only to enable the precomputed-tables feature for faster ECDSA
39#[cfg(not(test))]
40use k256 as _;
41
42// `alloc` is required by the stamped-chunk codec (`Vec`). `nectar-primitives`,
43// a hard dependency, also already requires an allocator, so this adds no new
44// constraint to the `no_std` build.
45extern crate alloc;
46
47mod batch;
48mod error;
49mod stamp;
50mod stamped;
51mod util;
52mod validation;
53
54// Storage and events (std only)
55#[cfg(feature = "std")]
56mod events;
57#[cfg(feature = "std")]
58mod snapshot_store;
59#[cfg(feature = "std")]
60mod store;
61
62// Parallel verification (requires rayon)
63#[cfg(feature = "parallel")]
64pub mod parallel;
65
66// Core types
67pub use batch::{Batch, BatchId, BatchParams};
68pub use error::StampError;
69pub use stamp::{STAMP_SIZE, Stamp, StampBytes, StampDigest, StampIndex};
70pub use stamped::StampedChunk;
71pub use util::{PostageContext, calculate_bucket, current_timestamp};
72pub use validation::StampValidator;
73#[cfg(feature = "std")]
74pub use validation::StoreValidator;
75
76// Storage and events (std only)
77#[cfg(feature = "std")]
78pub use events::{BatchEvent, BatchEventHandler};
79#[cfg(feature = "std")]
80pub use snapshot_store::SnapshotStore;
81#[cfg(feature = "std")]
82pub use store::{BatchStore, BatchStoreError, BatchStoreExt};
83
84// Re-export VerifyingKey for cached pubkey verification optimization
85pub use alloy_signer::k256::ecdsa::VerifyingKey;