| Crates.io | agentic-payments |
| lib.rs | agentic-payments |
| version | 0.1.0 |
| created_at | 2025-09-30 02:50:22.74568+00 |
| updated_at | 2025-09-30 02:50:22.74568+00 |
| description | Autonomous multi-agent Ed25519 signature verification with Byzantine fault tolerance |
| homepage | |
| repository | https://github.com/agentic-catalog/agentic-payments |
| max_upload_size | |
| id | 1860503 |
| size | 1,326,456 |
Dual-protocol payment infrastructure for autonomous AI commerce Supports AP2 (Agent Payments Protocol) and ACP (Agentic Commerce Protocol) with cryptographic security, Byzantine fault tolerance, and WASM compatibility.
The hottest thing in AI right now is agentic commerce specs. Two protocols have emerged almost back-to-back: the Agentic Commerce Protocol (ACP) from OpenAI and Stripe, and the Agent Payments Protocol (AP2) from Google and its partners. Each represents a different philosophy about how agents should buy and sell on our behalf.
ACP (Agentic Commerce Protocol) is the practical framework. It extends Stripe's trusted infrastructure with AI-native features - shared payment tokens that let your grocery bot see your payment methods without accessing the actual card numbers, instant checkout sessions that let your travel agent book flights without manual approval, and webhook events that keep your agents informed about payment status. OpenAI and Stripe designed it for immediate merchant adoption, which means millions of businesses can accept AI payments tomorrow.
AP2 (Agent Payments Protocol) comes from Google's vision of cryptographic trust for agents. Instead of API keys and webhook secrets, AP2 uses W3C Decentralized Identifiers (DIDs) and Verifiable Credentials - the same technology securing diplomatic communications. When your shopping agent commits to a purchase, it's not just sending JSON over HTTPS; it's creating a cryptographically signed mandate that proves authorization without revealing your identity. AP2 is about agent autonomy at scale: multi-signature approvals, Byzantine fault tolerance, and trust networks that work even if some participants are malicious.
The real insight is that these protocols complement rather than compete. ACP excels at merchant integration and instant checkout, while AP2 provides the authorization layer that lets you trust your agent's decisions. A travel bot might use AP2 to prove it's authorized to book flights on your behalf, then execute the actual payment through ACP's Stripe-compatible checkout. This library implements both protocols with shared cryptographic infrastructure (Ed25519 signatures, Byzantine fault tolerance, multi-agent consensus), giving you the flexibility to use each protocol where it shines.
Created by rUv - Dual-protocol infrastructure for the agentic commerce revolution
| Protocol | Philosophy | Best For | Key Features |
|---|---|---|---|
| ACP (Agentic Commerce Protocol) | Practical merchant adoption | Instant checkout, Stripe compatibility | REST API, Webhooks, Shared tokens |
| AP2 (Agent Payments Protocol) | Cryptographic trust & authorization | DID-based mandates, Agent autonomy | W3C DIDs, Verifiable Credentials, BFT consensus |
Both protocols share the same cryptographic infrastructure (Ed25519, BFT consensus, multi-agent verification) for maximum security.
[dependencies]
# Base library (AP2 only)
agentic-payments = "0.1.0"
# With ACP support
agentic-payments = { version = "0.1.0", features = ["acp"] }
# Full features (AP2 + ACP + metrics + DID)
agentic-payments = { version = "0.1.0", features = ["full"] }
# WASM for browser/Node.js
agentic-payments = { version = "0.1.0", features = ["wasm"] }
use agentic_payments::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// 1. Create AI shopping agent with DID
let shopping_agent = AgentIdentity::generate()?;
println!("Agent DID: {}", shopping_agent.did());
// 2. User authorizes weekly grocery shopping
let mut mandate = IntentMandate::new(
"did:user:alice".to_string(),
shopping_agent.did().to_string(),
"Weekly groceries with price comparison".to_string()
);
mandate.add_permission(Permission {
action: "purchase".to_string(),
resource: "groceries".to_string(),
conditions: vec!["max_amount:200".to_string()],
});
mandate.add_constraint("max_amount".to_string(), json!(200.00));
// 3. Build shopping cart
let items = vec![
CartItem::new("bananas".to_string(), "Organic Bananas".to_string(), 2, 399),
CartItem::new("milk".to_string(), "Almond Milk".to_string(), 1, 549),
];
let cart = CartMandate::new(
shopping_agent.did().to_string(),
items,
948, // $9.48
"USD".to_string()
);
// 4. Multi-agent consensus validates purchase
let system = AgenticVerificationSystem::builder()
.pool_size(5)
.consensus_threshold(0.67)
.build()
.await?;
let verification = system.verify_shopping_cart_consensus(
&mandate,
signature,
&cart,
user_key
).await?;
if verification.is_valid() {
println!("โ
Purchase approved by {}/{} agents",
verification.votes_for, verification.total_votes);
}
Ok(())
}
use agentic_payments::acp::prelude::*;
#[tokio::main]
async fn main() {
// 1. Start ACP REST server
let app = create_router();
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
tokio::spawn(async move {
axum::serve(listener, app).await.unwrap();
});
// 2. Create checkout session
let client = reqwest::Client::new();
let response = client
.post("http://localhost:3000/checkout_sessions")
.json(&serde_json::json!({
"items": [
{
"id": "item_123",
"name": "Laptop",
"quantity": 1,
"unit_price": 129900
}
]
}))
.send()
.await
.unwrap();
let session: CheckoutSession = response.json().await.unwrap();
println!("Checkout session created: {}", session.id);
// 3. Complete checkout
client
.post(&format!("http://localhost:3000/checkout_sessions/{}/complete", session.id))
.send()
.await
.unwrap();
println!("โ
Order completed!");
}
use agentic_payments::acp::{WebhookDelivery, WebhookEvent};
#[tokio::main]
async fn main() {
// 1. Initialize webhook system
let delivery = WebhookDelivery::new(b"your_hmac_secret".to_vec())
.with_max_retries(5);
// 2. Create event
let event = WebhookEvent {
event_type: "order.completed".to_string(),
checkout_session_id: "cs_123".to_string(),
data: serde_json::json!({
"amount": 129900,
"currency": "USD"
}),
timestamp: chrono::Utc::now().timestamp(),
};
// 3. Deliver with exponential backoff (10ms โ 8s)
match delivery.deliver("https://merchant.com/webhooks", event).await {
Ok(_) => println!("โ
Webhook delivered"),
Err(e) => println!("โ Delivery failed: {}", e),
}
}
use agentic_payments::acp::bridge::*;
// Convert AP2 CartMandate to ACP CheckoutSession
let cart = CartMandate::new(...);
let checkout = cart_mandate_to_checkout(&cart)?;
println!("Converted to ACP: {}", checkout.id);
// Convert back to AP2
let cart2 = checkout_to_cart_mandate(&checkout, "did:user:alice")?;
assert_eq!(cart.total_amount, cart2.total_amount);
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Protocol Router โ
โ (Automatic AP2/ACP Detection & Routing) โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโผโโโโโโโโโ โโโโโโโโโโผโโโโโโโโโโโ
โ AP2 Flow โ โ ACP Flow โ
โ (DID + VCs) โโโโโโโโโโโบโ (REST + SPT) โ
โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโผโโโโโโโโโโโ
โ Shared Core โ
โ - Ed25519 Crypto โ
โ - BFT Consensus โ
โ - Multi-Agent โ
โ - Self-Healing โ
โโโโโโโโโโโโโโโโโโโโโโ
[Verifier-1] โโโ [Verifier-2] โโโ [Verifier-3]
โ โ โ
[Merchant-1] โโโ [Merchant-2] โโโ [Merchant-3]
โ โ โ
[Fraud-Det] โโโ [Identity] โโโ [Recovery]
Byzantine Fault Tolerant Consensus:
Tolerates up to f malicious agents in 2f+1 pools
Based on Google's Agent Payments Protocol
Features:
Use Cases:
Based on OpenAI/Stripe's Agentic Commerce Protocol
REST Endpoints:
POST /checkout_sessions - Create sessionGET /checkout_sessions/:id - Retrieve sessionPOST /checkout_sessions/:id - Update sessionPOST /checkout_sessions/:id/complete - Complete checkoutPOST /checkout_sessions/:id/cancel - Cancel sessionPOST /agentic_commerce/delegate_payment - Tokenize paymentFeatures:
Use Cases:
Automatic routing based on:
/checkout_sessions โ ACPAuthorization: DID โ AP2checkout_session โ ACP, VerifiableCredential โ AP2| Metric | AP2 | ACP | Configuration |
|---|---|---|---|
| Throughput | 10,000+ tx/sec | 5,000+ sessions/sec | 100-agent pool |
| Latency | <50ms p99 | <50ms p99 | 5-agent consensus |
| Recovery | <2 seconds | <2 seconds | CRDT state sync |
| Verification | <1ms single | <0.05ms routing | Ed25519 + cache |
| Webhook Delivery | N/A | 10,000+/sec | Async + retry |
import init, { AgentIdentity, verify } from './pkg/agentic_payments.js';
await init();
// Create agent in browser
const agent = AgentIdentity.generate();
const signature = agent.sign("Purchase: Coffee Maker - $89.99");
const valid = await verify(signature, "Purchase: Coffee Maker - $89.99", agent.publicKey());
console.log("โ
Transaction approved:", valid);
# Browser target
wasm-pack build --target web --features wasm
# Node.js target
wasm-pack build --target nodejs --features wasm
# Deno/Bun target
wasm-pack build --target web --features wasm
# Run all tests (AP2 only)
cargo test --lib
# Run with ACP features
cargo test --features acp
# Run all features
cargo test --all-features
# Run WASM tests
wasm-pack test --node --features wasm
# Run benchmarks
cargo bench --features acp
# Run specific test suite
cargo test --features acp acp::hmac::tests
cargo test --features acp acp::webhook::tests
cargo test --features acp tests::acp_integration_test
| Module | Tests | Coverage | Status |
|---|---|---|---|
| Core Crypto | 5 | 100% | โ |
| BFT Consensus | 45 | 100% | โ |
| Multi-Agent | 8 | 100% | โ |
| AP2 Library | 112 | 100% | โ |
| ACP HMAC | 11 | 100% | โ |
| ACP Webhooks | 10 | 100% | โ |
| ACP Router | 26 | 100% | โ |
| ACP Bridge | 13 | 100% | โ |
| Integration | 150 | 95%+ | โ |
| WASM | 10 | 95%+ | โ |
| Total | 227+ | 98%+ | โ |
unsafe code in production paths# Clone repository
git clone https://github.com/agentic-catalog/agentic-payments
cd agentic-payments
# Install Rust toolchain
rustup install stable
# Run tests
cargo test --all-features
# Run linter
cargo clippy --all-features
# Format code
cargo fmt
# Build documentation
cargo doc --all-features --open
crates/agentic-payments/
โโโ src/
โ โโโ crypto/ # Ed25519, HMAC, key management
โ โโโ consensus/ # BFT consensus engine
โ โโโ agents/ # Multi-agent verification
โ โโโ ap2/ # Agent Payments Protocol
โ โโโ acp/ # Agentic Commerce Protocol
โ โ โโโ hmac.rs # HMAC-SHA256 signatures
โ โ โโโ webhook.rs # Async delivery + retry
โ โ โโโ handlers.rs # REST API handlers
โ โ โโโ router.rs # Protocol detection
โ โ โโโ bridge.rs # AP2 โ ACP conversion
โ โ โโโ models.rs # Data structures
โ โโโ lib.rs
โโโ tests/ # Integration tests
โโโ examples/ # Usage examples
โโโ benches/ # Performance benchmarks
โโโ docs/ # Documentation
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
ed25519-dalek - Fast and secure Ed25519 signaturesaxum - Production web framework for REST APItokio - Async runtime for high-performance I/Oserde - Serialization frameworkwasm-bindgen - WebAssembly JavaScript bindingsBuilt with โค๏ธ by rUv.
Ready to build the future of autonomous commerce? ๐
cargo add agentic-payments --features full