-
Notifications
You must be signed in to change notification settings - Fork 1
Port the x402 v2 wire types #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca79e6a
becddb7
e917b5a
dbb1d62
ed65c71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ name = "public_api" | |
| required-features = ["btc", "evm", "solana", "tron", "keccak"] | ||
|
|
||
| [features] | ||
| default = ["btc", "evm", "solana", "tron", "keccak", "net", "key", "asset", "client", "tx"] | ||
| default = ["btc", "evm", "solana", "tron", "keccak", "net", "key", "asset", "client", "tx", "x402"] | ||
| # Bitcoin address parsing and validation. | ||
| btc = ["dep:bitcoin"] | ||
| # EVM (Ethereum and compatible chains) address validation. Dependency-free: | ||
|
|
@@ -106,6 +106,7 @@ asset = ["btc", "evm", "solana", "tron"] | |
| client = ["net", "asset", "tx", "serde/derive"] | ||
| # Transaction building and signing (`tinywallet::tx`). Needs secp256k1 | ||
| # recoverable signing (via `bitcoin`) and Keccak-256 (via `keccak`). | ||
| x402 = ["dep:serde", "dep:serde_json", "serde/derive"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an explanatory comment for the x402 feature The repository rules require commenting why each crate is needed, but the new A descriptive comment should be added, consistent with the other feature definitions in this file. [RULE] Comment why each crate is needed · |
||
| tx = ["btc", "evm", "keccak", "solana", "tron", "key", "dep:ed25519-dalek", "dep:bs58", "dep:sha2", "dep:hex"] | ||
| # Deterministic key derivation from a BIP-39 mnemonic (`tinywallet::key`). | ||
| # Needs every chain gate it derives for; `keccak` covers the EVM/Tron address | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //! The x402 machine-payment protocol (v2). | ||
| //! | ||
| //! x402 revives HTTP's long-unused `402 Payment Required`. A server answers a | ||
| //! request with a 402 and a `PAYMENT-REQUIRED` header describing what it will | ||
| //! accept; the client pays, retries with a `PAYMENT-SIGNATURE` header carrying | ||
| //! the proof, and the server settles it through a facilitator and answers with | ||
| //! `PAYMENT-RESPONSE`. | ||
| //! | ||
| //! This module owns the **wire types** — the header payloads and the rules for | ||
| //! reading them. Every header payload is standard-base64-encoded JSON, and | ||
| //! networks are named in [CAIP-2] form (`solana:…`, `eip155:8453`). | ||
| //! | ||
| //! ## Amounts are strings, and that is not laziness | ||
| //! | ||
| //! [`PaymentRequirements::amount`] is a `String` of atomic units, not a number. | ||
| //! JSON numbers are IEEE 754 doubles in most parsers, which cannot represent | ||
| //! every `u64` exactly — and a token amount that survives a round trip through | ||
| //! a JavaScript facilitator only approximately is a payment for the wrong sum. | ||
| //! The protocol carries them as decimal strings for that reason, and so does | ||
| //! this module. | ||
| //! | ||
| //! ## The client signs an authorisation; the facilitator broadcasts | ||
| //! | ||
| //! In both supported schemes the payer never broadcasts. On Solana it hands | ||
| //! over a partially-signed transaction that the facilitator co-signs as fee | ||
| //! payer; on EVM it signs an EIP-3009 `transferWithAuthorization` the | ||
| //! facilitator submits. So a payment proof is a *capability someone else will | ||
| //! exercise* — which is why [`EvmAuthorization`] carries `valid_after`, | ||
| //! `valid_before` and a `nonce`: without them an authorisation would be | ||
| //! replayable indefinitely. | ||
| //! | ||
| //! [CAIP-2]: https://chainagnostic.org/CAIPs/caip-2 | ||
|
|
||
| mod types; | ||
|
|
||
| pub use types::{ | ||
| BASE_MAINNET_CAIP2, BASE_SEPOLIA_CAIP2, COMPUTE_BUDGET_PROGRAM, ETHEREUM_MAINNET_CAIP2, | ||
| EvmAuthorization, EvmPaymentProof, HEADER_PAYMENT_REQUIRED, HEADER_PAYMENT_REQUIRED_V1, | ||
| HEADER_PAYMENT_RESPONSE, HEADER_PAYMENT_SIGNATURE, HEADER_PAYMENT_SIGNATURE_V1, PaymentChain, | ||
| PaymentExtra, PaymentPayload, PaymentProof, PaymentRequired, PaymentRequirements, ResourceInfo, | ||
| SOLANA_DEVNET_CAIP2, SOLANA_MAINNET_CAIP2, SPL_MEMO_PROGRAM, SPL_TOKEN_PROGRAM, | ||
| SettlementResponse, SolanaPaymentProof, USDC_BASE_MAINNET, USDC_BASE_SEPOLIA, | ||
| USDC_ETHEREUM_MAINNET, USDC_MINT_DEVNET, USDC_MINT_MAINNET, X402_VERSION, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move x402 below tx so the tx comment stays attached
The new
x402feature is inserted between the comment block that describestxand thetxline itself, so thetxcomment is now visually attached tox402:The
txfeature loses its explanatory comment andx402gains a misleading one. Thex402feature should be placed elsewhere (e.g., below thetxline or in its own commented section).[RULE] Comment why each crate is needed ·