erc8128/lib.rs
1//! # erc8128 — Signed HTTP Requests with Ethereum
2//!
3//! Rust implementation of [ERC-8128]: authenticate HTTP requests using
4//! HTTP Message Signatures ([RFC 9421]) with Ethereum accounts.
5//!
6//! Two core operations:
7//! - [`sign_request`] — sign an outgoing HTTP request
8//! - [`verify_request`] — verify an incoming signed HTTP request
9//!
10//! Chain-specific signature verification (EOA / ERC-1271) is pluggable
11//! via the [`Verifier`] trait.
12//!
13//! # Examples
14//!
15//! ```no_run
16//! use erc8128::{Request, SignOptions, sign_request};
17//!
18//! # async fn example(signer: impl erc8128::Signer) -> Result<(), erc8128::Erc8128Error> {
19//! let request = Request {
20//! method: "GET",
21//! url: "https://api.example.com/resource",
22//! headers: &[],
23//! body: None,
24//! };
25//! let signed = sign_request(&request, &signer, &SignOptions::default()).await?;
26//! # Ok(())
27//! # }
28//! ```
29//!
30//! [ERC-8128]: https://erc8128.org
31//! [RFC 9421]: https://www.rfc-editor.org/rfc/rfc9421
32
33mod error;
34/// `KeyID` formatting and parsing (`erc8128:<chainId>:<address>`).
35pub mod keyid;
36/// Cryptographically secure nonce generation.
37pub mod nonce;
38pub(crate) mod sf;
39pub(crate) mod sign;
40pub(crate) mod traits;
41pub(crate) mod types;
42pub(crate) mod verify;
43
44/// EOA signer and verifier using pure `k256` ECDSA.
45#[cfg(feature = "k256")]
46pub mod eoa;
47
48/// Adapter for [`alloy_signer::Signer`] implementations.
49#[cfg(feature = "alloy")]
50pub mod alloy;
51
52/// Axum middleware for ERC-8128 signature verification.
53#[cfg(feature = "axum")]
54pub mod middleware;
55
56/// Reqwest client helpers for ERC-8128 signed requests.
57#[cfg(feature = "reqwest")]
58pub mod client;
59
60pub use error::Erc8128Error;
61pub use sign::sign_request;
62pub use traits::{
63 MemoryNonceStore, NoNonceStore, NonceStore, RejectReplayable, ReplayablePolicy, Signer,
64 Verifier,
65};
66pub use types::{
67 Address, Binding, ContentDigest, Replay, ReplayableInfo, Request, SignOptions, SignatureParams,
68 SignedHeaders, VerifyPolicy, VerifySuccess,
69};
70pub use verify::verify_request;