mpay
Rust SDK for the Machine Payments Protocol (MPP) - an implementation of the "Payment" HTTP Authentication Scheme.
Design Principles
- Protocol-first — Core types (
Challenge,Credential,Receipt) map directly to HTTP headers - Zero-copy parsing — Efficient header parsing without unnecessary allocations
- Pluggable methods — Payment networks are feature-gated (Tempo included by default)
- Minimal dependencies — Core has minimal deps; features add what you need
- Designed for extension —
MethodandIntentare traits. Implement them for custom payment methods.
Quick Start
Parse a Challenge (Server → Client)
use Challenge;
let header = r#"Payment realm="api.example.com", id="abc123", method="tempo", intent="charge", request="eyJhbW91bnQiOiIxMDAwIn0""#;
let challenge = from_www_authenticate?;
println!;
println!;
Create a Credential (Client → Server)
use Credential;
let credential = Credential ;
let auth_header = credential.to_authorization;
Parse a Receipt (Server → Client)
use Receipt;
let receipt = from_payment_receipt?;
assert_eq!;
API Reference
Core
Challenge
A parsed payment challenge from a WWW-Authenticate header.
use Challenge;
let challenge = Challenge ;
let header = challenge.to_www_authenticate;
let parsed = from_www_authenticate?;
Credential
The credential sent in the Authorization header.
use Credential;
let credential = Credential ;
let header = credential.to_authorization;
let parsed = from_authorization?;
Receipt
Payment receipt returned after successful verification.
use Receipt;
let receipt = Receipt ;
let header = receipt.to_payment_receipt;
let parsed = from_payment_receipt?;
Install
[]
= "0.1"
Feature Flags
| Feature | Description |
|---|---|
tempo |
Tempo blockchain support (default, includes evm) |
evm |
Shared EVM utilities (Address, U256, parsing) |
utils |
Encoding utilities (hex, base64) |
What's NOT Included
Network registries, currency formatting, keystore management, HTTP clients, and middleware are out of scope for this library.
Examples
See the examples/ directory for integration patterns with common HTTP libraries:
Development
License
MIT OR Apache-2.0