remitmd/lib.rs
1//! # remitmd — Rust SDK for the remit.md universal AI payment protocol
2//!
3//! remit.md enables AI agents to send and receive USDC payments on Base (EVM L2)
4//! with support for direct payments, escrow, streaming, payment channels (tabs),
5//! bounties, and security deposits.
6//!
7//! ## Quick start
8//!
9//! ```rust,no_run
10//! use remitmd::Wallet;
11//! use rust_decimal_macros::dec;
12//!
13//! #[tokio::main]
14//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
15//! // From environment: export REMITMD_KEY=0x...
16//! let wallet = Wallet::from_env()?;
17//!
18//! // Direct payment
19//! let tx = wallet.pay("0xRecipient...", dec!(1.50)).await?;
20//! println!("paid {:?} USDC in {}", tx.amount, tx.tx_hash);
21//!
22//! // Escrow for high-value work
23//! let escrow = wallet.create_escrow("0xAgent...", dec!(100.00)).await?;
24//! // ... agent completes work ...
25//! wallet.release_escrow(&escrow.id, None).await?;
26//! Ok(())
27//! }
28//! ```
29//!
30//! ## Testing
31//!
32//! Use `MockRemit` for unit tests — zero network, zero latency, deterministic:
33//!
34//! ```rust
35//! use remitmd::MockRemit;
36//! use rust_decimal_macros::dec;
37//!
38//! #[tokio::test]
39//! async fn agent_pays_for_service() {
40//! let mock = MockRemit::new();
41//! let wallet = mock.wallet();
42//!
43//! wallet.pay("0xService000000000000000000000000000000001", dec!(0.003)).await.unwrap();
44//!
45//! assert!(mock.was_paid("0xService000000000000000000000000000000001", dec!(0.003)).await);
46//! }
47//! ```
48//!
49//! ## Error handling
50//!
51//! All SDK methods return `Result<T, RemitError>`. Errors are structured with a
52//! stable machine-readable code, an actionable message, and a documentation link.
53//!
54//! ```rust,ignore
55//! use remitmd::error::codes;
56//!
57//! match wallet.pay(addr, amount).await {
58//! Ok(tx) => println!("paid: {}", tx.tx_hash),
59//! Err(e) if e.code == codes::INVALID_ADDRESS => {
60//! eprintln!("fix the address: {}", e.message);
61//! }
62//! Err(e) if e.code == codes::INSUFFICIENT_BALANCE => {
63//! eprintln!("top up your wallet: {}", e.message);
64//! }
65//! Err(e) => eprintln!("payment error: {e}"),
66//! }
67//! ```
68
69#![deny(warnings)]
70
71pub mod a2a;
72mod compliance;
73pub mod error;
74mod http;
75mod mock;
76mod models;
77mod signer;
78mod wallet;
79pub mod x402;
80
81// ─── Public API ───────────────────────────────────────────────────────────────
82
83pub use error::RemitError;
84pub use mock::MockRemit;
85pub use models::{
86 Balance, Bounty, BountyStatus, BountySubmission, Budget, ChainId, ContractAddresses, Deposit,
87 DepositStatus, Escrow, EscrowStatus, Intent, Milestone, MintResponse, PermitSignature,
88 Reputation, SpendingSummary, Split, Stream, StreamStatus, Tab, TabCharge, TabDebit, TabStatus,
89 TopRecipient, Transaction, TransactionList, WalletStatus,
90};
91pub use signer::{PrivateKeySigner, Signer};
92pub use wallet::{Wallet, WalletBuilder, WithKey, WithSigner};