Skip to content

feat: add Rust SDK with full x402 payment support#63

Open
kmjones1979 wants to merge 4 commits intoedgeandnode:mainfrom
kmjones1979:feat/rust-sdk
Open

feat: add Rust SDK with full x402 payment support#63
kmjones1979 wants to merge 4 commits intoedgeandnode:mainfrom
kmjones1979:feat/rust-sdk

Conversation

@kmjones1979
Copy link
Copy Markdown

Summary

  • Adds a complete Rust SDK (rust/ampersend-sdk/) with feature parity to the TypeScript SDK
  • Core x402 traits (X402Treasurer, X402Wallet), wallet implementations (EOA + Smart Account with ERC-3009/ERC-1271), and treasurer implementations (NaiveTreasurer + AmpersendTreasurer with SIWE auth)
  • MCP integration: client with payment retry, proxy server (axum), FastMCP server middleware
  • HTTP adapter with automatic 402 handling and v1/v2 protocol conversion
  • CLI binary (ampersend-proxy) with environment-based configuration
  • CI/CD workflows for Rust (build, clippy, fmt, test + crates.io release)
  • CLAUDE.md updated with Rust setup, testing, linting, and architecture docs

What's included

Component Description
x402/ Core traits and types (Treasurer, Wallet, PaymentRequirements, PaymentPayload)
x402/wallets/ AccountWallet (EOA), SmartAccountWallet (ERC-3009 + ERC-1271)
x402/treasurers/ NaiveTreasurer (auto-approve for testing)
smart_account/ ERC-3009 signing with OwnableValidator
ampersend/ API client (SIWE auth), AmpersendTreasurer, ManagementClient
mcp/client/ MCP client with automatic x402 payment retry
mcp/proxy/ HTTP proxy server (axum) with x402 bridge middleware
mcp/server/ FastMCP server middleware for payment requirements
http/ x402-aware HTTP client, v1/v2 protocol adapter
bin/ ampersend-proxy CLI

Test plan

  • cargo build --all-features — clean build, zero warnings
  • cargo clippy --all-features -- -D warnings — zero clippy warnings
  • cargo fmt --check — properly formatted
  • cargo test — 114 unit tests pass across 13 test files:
    • Types & serde (16), Wallets (9), Treasurers (8), Management API (4)
    • MCP client middleware (10), MCP types (9), FastMCP server (4)
    • HTTP adapter (9), V2 protocol adapter (18), URL validation (16)
    • ERC-1271/ERC-3009 signing (4), Proxy env config (5), Doc tests (2)
  • cargo test --test integration_test -- --ignored — 5 integration tests pass against live Ampersend API (SIWE auth, payment authorization, full lifecycle, rejection/error reporting)

🤖 Generated with Claude Code

kmjones1979 and others added 4 commits March 16, 2026 17:33
Adds a Rust implementation of the ampersend SDK with feature parity to the
TypeScript SDK, including:

- Core x402 traits (X402Treasurer, X402Wallet) and types
- Wallet implementations (AccountWallet for EOA, SmartAccountWallet with ERC-3009/ERC-1271)
- Treasurer implementations (NaiveTreasurer, AmpersendTreasurer with SIWE auth)
- Ampersend API client (SIWE authentication, payment authorization, event reporting)
- Ampersend Management client (agent deployment and listing)
- MCP client with automatic x402 payment retry
- MCP proxy server (axum) with x402 bridge middleware
- FastMCP server middleware for payment requirements
- HTTP adapter with automatic 402 handling
- v1/v2 protocol adapter (CAIP-2 network conversion)
- CLI binary (ampersend-proxy) with environment-based config
- 91 unit tests + 5 integration tests against live Ampersend API
- CI workflow (build, clippy, fmt, test)
- Release workflow (crates.io publish on rs-v* tags)
- README with quick start examples for all entry points
- CLAUDE.md updated with Rust setup, testing, and architecture docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fills test coverage gaps identified against the TypeScript and Python SDKs:

- MCP client middleware: 402 detection, payment retry with _meta, treasurer
  decline/approve, status lifecycle (sending→accepted/rejected), no-retry
  when payment already present, non-402 passthrough
- HTTP adapter: 402→retry with X-PAYMENT header, treasurer decline, rejected
  retry (second 402), error on 500 retry, non-JSON/non-x402 402 handling,
  request body preservation, base64 header encoding
- ERC-3009 signing: signature structure (85 bytes = 20 validator + 65 EOA),
  validator address prefix, v value validation, nonce uniqueness, invalid
  key rejection

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Apply cargo fmt to test files (http_adapter, mcp_client, signing)
- Replace server_url unwrap() with expect() in MCP client connect flow
- Add test job to rust-release workflow; publish depends on verify-version + test

Made-with: Cursor
- Add wallet_creates_payment_from_env: create payment from env config (EOA or smart account), assert payload shape
- Add management_list_agents: optional test when AMPERSEND_API_KEY is set
- Update module doc to describe treasurer, wallet, and management coverage

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant