Skip to main content

mpp_br/
lib.rs

1//! mpp - Machine Payment Protocol for Rust
2//!
3//! A Rust library implementing the Web Payment Auth protocol.
4//!
5//! # Quick Start
6//!
7//! ```no_run
8//! use mpp_br::{PaymentChallenge, PaymentCredential, Receipt, ChargeRequest};
9//! use mpp_br::{parse_www_authenticate, format_authorization};
10//! # fn main() {}
11//! ```
12//!
13//! # Signer Integration
14//!
15#![cfg_attr(feature = "evm", doc = "```no_run")]
16#![cfg_attr(not(feature = "evm"), doc = "```ignore")]
17//! use mpp_br::{Signer, PrivateKeySigner};
18//! # fn main() {}
19//! ```
20//!
21//! Consumers provide their own signer. The library does not manage keystores.
22
23pub const VERSION: &str = env!("CARGO_PKG_VERSION");
24
25// ==================== Internal Modules ====================
26
27pub mod body_digest;
28pub mod error;
29pub mod expires;
30pub mod mcp;
31pub mod protocol;
32pub mod proxy;
33pub mod store;
34
35#[cfg(feature = "evm")]
36pub mod evm;
37
38#[cfg(feature = "client")]
39pub mod client;
40
41#[cfg(feature = "server")]
42pub mod server;
43
44#[cfg(feature = "tempo")]
45pub mod tempo;
46
47// ==================== Flat Re-exports ====================
48
49// Error types
50pub use error::{MppError, Result};
51
52// RFC 9457 Problem Details
53pub use error::{
54    PaymentError, PaymentErrorDetails, CORE_PROBLEM_TYPE_BASE, SESSION_PROBLEM_TYPE_BASE,
55};
56
57// Deprecated: remove in next major version.
58#[allow(deprecated)]
59pub use error::STREAM_PROBLEM_TYPE_BASE;
60
61// Core protocol types
62pub use protocol::core::{
63    compute_challenge_id, ChallengeEcho, PaymentChallenge, PaymentCredential, PaymentPayload,
64    Receipt, ReceiptStatus,
65};
66
67// Header parsing/formatting
68pub use protocol::core::{
69    format_authorization, format_receipt, format_www_authenticate, format_www_authenticate_many,
70    parse_authorization, parse_receipt, parse_www_authenticate, parse_www_authenticate_all,
71};
72
73// Schema types
74pub use protocol::core::{
75    base64url_decode, base64url_encode, Base64UrlJson, IntentName, MethodName, PayloadType,
76    PaymentProtocol, AUTHORIZATION_HEADER, PAYMENT_RECEIPT_HEADER, PAYMENT_SCHEME,
77    WWW_AUTHENTICATE_HEADER,
78};
79
80// Store types
81pub use store::{FileStore, MemoryStore, Store, StoreError};
82
83#[cfg(all(feature = "server", feature = "tempo"))]
84pub use store::ChannelStoreAdapter;
85
86// Intent types
87pub use protocol::intents::{
88    deserialize_request, deserialize_request_typed, parse_units, request_from_challenge,
89    request_from_challenge_typed, serialize_request, ChargeRequest, Request as PaymentRequest,
90    SessionRequest,
91};
92
93// ==================== Alloy Re-exports ====================
94
95#[cfg(feature = "evm")]
96pub use alloy::signers::Signer;
97
98#[cfg(feature = "evm")]
99pub use alloy::signers::local::PrivateKeySigner;
100
101#[cfg(feature = "evm")]
102pub use alloy::primitives::{Address, U256};
103
104#[cfg(feature = "tempo")]
105pub use alloy::providers::{ProviderBuilder, RootProvider};