x402 (HTTP 402 Payment Required; Coinbase -> Linux Foundation, Visa/
Stripe/Circle) is where agentic-commerce momentum is, and OpenPay had no
agentic acceptance path despite being built to ride it. New op-rails-x402
crate adds the protocol surface:
- PaymentRequirements::for_charge(&Money, ...) -> the 402 challenge from an
OpenPay charge (minor units -> atomic maxAmountRequired; the fiat Money
preserved in `extra.fiat` so the merchant ledger keeps its truth) +
to_402_body() (the x402Version/accepts response).
- PaymentPayload encode/decode for the X-PAYMENT header (base64 of JSON) +
matches() guard (scheme/network).
- SettleResult + X-PAYMENT-RESPONSE; accept(req, header, settler) reference
flow.
- Settler trait = the on-chain edge (signature verify + settlement against
a chain RPC), host-implemented per OpenPay's swappable-driver doctrine —
keeps this crate network- and dependency-free.
Validated standalone (3 tests green: challenge-from-Money, X-PAYMENT
round-trip, accept+settle+mismatch). No new deps (op-core + serde).
NOTE: the openpay workspace does NOT currently resolve due to a
PRE-EXISTING issue in op-vault (`rand_core ^0.10` requested with the
`getrandom` feature that rand_core 0.10 no longer has) — unrelated to this
crate; `cargo build -p op-core` fails the same way. op-rails-x402 was
validated against op-core in isolation. op-vault's rand_core pin needs
fixing for the full workspace to build again.
Co-Authored-By: Claude Opus 4.8 <[email protected]>