Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e6900d4
docs(tinywallet-x402): add wire fixtures for siwx and upto challenges
senamakel Nov 12, 2026
2a33447
test(x402): add passthrough wire type tests
senamakel Nov 12, 2026
d1a3344
feat(x402): preserve unmodelled fields when echoing payment requirements
senamakel Nov 12, 2026
ce3f9bf
feat(wire): parse the upto asset transfer method and facilitator address
senamakel Nov 12, 2026
549e7c8
test(x402): add new extra fields to test fixtures
senamakel Nov 12, 2026
694a68b
test(x402): add tests for payment requirement selection
senamakel Nov 12, 2026
a5da22a
feat(x402): add network pinning to payment requirement selection
senamakel Nov 12, 2026
678b46d
feat(x402): rank payment options and honour network pins
senamakel Nov 12, 2026
5c55480
fix(x402): mention EVM upto in no-payment-option error
senamakel Nov 12, 2026
8bf5884
test(x402): add network protocol tests
senamakel Nov 12, 2026
7481aa7
feat(x402): add network-pinned 402 payment handling
senamakel Nov 12, 2026
b557c9c
test(eip712): add permit2 signature tests
senamakel Nov 12, 2026
eb93e63
feat(x402): add permit2 eip712 module
senamakel Nov 12, 2026
b4272c1
feat(eip712): re-export permit2 types and helpers
senamakel Nov 12, 2026
1d0dbce
feat(abi): add erc20 read call encoding and reply decoding
senamakel Nov 12, 2026
6e79a58
feat(eip712): add u256_to_decimal to format 256-bit values as decimal
senamakel Nov 12, 2026
622d10c
feat(wire): add permit2 upto payment proof types
senamakel Nov 12, 2026
edc261d
feat(x402): add authorization deadline accessor to payment proofs
senamakel Nov 12, 2026
d6b93a2
style: apply rustfmt formatting to x402 crate
senamakel Nov 12, 2026
dc3a98d
chore(tinywallet-x402): drop unused imports and improve test panic me…
senamakel Nov 12, 2026
f1bf715
test(x402): add tests for upto payment crypto
senamakel Nov 12, 2026
baddd38
feat(crypto): add upto payment module
senamakel Nov 12, 2026
02a0d79
feat(x402): route upto scheme payments through the Permit2 builder
senamakel Nov 12, 2026
467f9c3
test(ledger): register upto tests module
senamakel Nov 12, 2026
41c0870
test(x402): add scheme field to payment record fixtures
senamakel Nov 12, 2026
ad9c1b6
feat(ledger): record the x402 scheme on payment records
senamakel Nov 12, 2026
3a6be4c
test(x402): cover upto settlement at the charged amount
senamakel Nov 12, 2026
80efc48
feat(x402): expose payment scheme and settle upto payments at charged…
senamakel Nov 12, 2026
78f3004
feat(x402): settle upto payments at the amount charged
senamakel Nov 12, 2026
1cd76ed
feat(x402): add optional network filter to payment preparation
senamakel Nov 12, 2026
67ec169
test(x402): move network pin coverage into prepare tests
senamakel Nov 12, 2026
4e6e2ce
test(x402): align fixture broker task handle with tinybus result type
senamakel Nov 12, 2026
9ef84e9
test(x402): keep bus connections alive in prepare fixture
senamakel Nov 12, 2026
6e4ef56
refactor(tinywallet-x402): extract settlement receipt parsing into a …
senamakel Nov 12, 2026
d955e38
refactor(tinywallet-x402): simplify receipt handling and test helpers
senamakel Nov 12, 2026
f97556b
refactor(x402): extract pending payment record construction
senamakel Nov 12, 2026
709d9cf
test(siwx): add unit tests for siwx signature verification
senamakel Nov 12, 2026
85b312c
feat(x402): add sign-in-with-x challenge support
senamakel Nov 12, 2026
ad92523
feat(x402): add sign-in-with-x challenge signing on evm
senamakel Nov 12, 2026
21c84b1
feat(crypto): export sign-in-with-x proof types from the crypto module
senamakel Nov 12, 2026
e2d745a
test(siwx): drop unused base64 engine import
senamakel Nov 12, 2026
8b1d14d
test(x402): add sign-in test module
senamakel Nov 12, 2026
56c79e0
feat(x402): add sign-in-with-x challenge signing
senamakel Nov 12, 2026
b5660d4
test(siwx): split refusal cases into origin and field helpers
senamakel Nov 12, 2026
a3b6695
fix(siwx): reject control characters and recheck expiry after signing
senamakel Nov 12, 2026
6799aaa
test(x402): cover builder rejection of non-permit2 transfer methods
senamakel Nov 12, 2026
17d5872
fix(x402): reject non-permit2 asset transfer methods in upto terms
senamakel Nov 12, 2026
816619c
test(x402): assert upto scheme is recorded on approval
senamakel Nov 12, 2026
669a4eb
feat(x402): carry the payment scheme on authorization requests
senamakel Nov 12, 2026
b56da6f
feat(x402): settle payments from receipts under the ledger lock
senamakel Nov 12, 2026
803fde6
test(x402): cover sign-in and upto payment failure paths
senamakel Nov 12, 2026
03c9060
test: cover non-json status replies and short bip32 seeds
senamakel Nov 12, 2026
3df4420
refactor(tinywallet-module): destructure record request before settling
senamakel Nov 12, 2026
085dcb4
test(x402): cover unconfigured payment prep and settlement rule
senamakel Nov 12, 2026
5097ede
test(x402): assert the specific error for unconfigured payments
senamakel Nov 12, 2026
ff94ad9
refactor(key): extract shared derivation error mapping helper
senamakel Nov 12, 2026
b6851ac
test(key): import derivation_failed in key tests
senamakel Nov 12, 2026
5191982
test(tinywallet-module): cover bus error naming and failure messages
senamakel Nov 12, 2026
03cde61
test(tinywallet-module): qualify failure variants with super path
senamakel Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/tinywallet-bus/src/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn network_request_keeps_legacy_json_and_omits_unset_endpoint_url() {

#[test]
fn the_contract_accepts_its_own_version_and_newer_minors() {
assert_eq!(CONTRACT_VERSION, (1, 15));
assert_eq!(CONTRACT_VERSION, (1, 16));
assert!(is_compatible(CONTRACT_VERSION));
assert!(is_compatible((CONTRACT_VERSION.0, CONTRACT_VERSION.1 + 1)));
assert!(!is_compatible((CONTRACT_VERSION.0 + 1, 0)));
Expand Down Expand Up @@ -146,7 +146,7 @@ fn the_method_list_is_sorted_complete_and_free_of_duplicates() {
METHODS,
"sorted dispatch order, no repeats"
);
assert_eq!(METHODS.len(), 39);
assert_eq!(METHODS.len(), 40);
for member in [
names::methods::ATTACH_SIGNATURE,
names::methods::BUILD_UNSIGNED,
Expand Down Expand Up @@ -188,6 +188,7 @@ fn the_method_list_is_sorted_complete_and_free_of_duplicates() {
names::methods::X402_UPDATE_BUDGET,
names::methods::X402_CLOSE,
names::methods::X402_CONFIGURE,
names::methods::X402_SIGN_IN,
] {
assert!(
METHODS.contains(&member),
Expand Down Expand Up @@ -292,7 +293,7 @@ fn native_wallet_members_are_additive_and_use_one_typed_argument() {
methods::NATIVE_WALLET_TX_RECEIPT,
methods::NATIVE_WALLET_LOOKUP_TX,
];
assert_eq!(METHODS.len(), 39);
assert_eq!(METHODS.len(), 40);
assert!(native_members.iter().all(|member| METHODS.contains(member)));
assert_eq!(HOST_METHODS.len(), 6);
assert!(HOST_METHODS.contains(&host_methods::AUTHORIZE_NATIVE_WALLET_EXECUTION));
Expand Down Expand Up @@ -443,3 +444,9 @@ fn token_balance_rows_serialize_in_camel_case_with_the_mint() {
row
);
}

#[test]
fn signing_in_with_x_is_confidential() {
// It carries the EVM recovery phrase into the module, like a payment.
assert!(CONFIDENTIAL_METHODS.contains(&names::methods::X402_SIGN_IN));
}
5 changes: 5 additions & 0 deletions crates/tinywallet-bus/src/names/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ pub mod methods {
pub const ENCODE_ERC20_TRANSFER: &str = "EncodeErc20Transfer";
/// Records a retry result and commits or releases its module reservation.
pub const X402_RECORD_PAYMENT: &str = "X402RecordPayment";
/// Signs an x402 `sign-in-with-x` challenge for the requested host with
/// the EVM account. Contract 1.16.
pub const X402_SIGN_IN: &str = "X402SignIn";
/// Reports ledger totals and spending limits.
pub const X402_SPENDING_SUMMARY: &str = "X402SpendingSummary";
/// Reports ledger totals, counts and spending limits for host projection.
Expand Down Expand Up @@ -163,6 +166,7 @@ pub const METHODS: &[&str] = &[
methods::X402_LIST_PAYMENTS,
methods::X402_PREPARE_PAYMENT,
methods::X402_RECORD_PAYMENT,
methods::X402_SIGN_IN,
methods::X402_SPENDING_SUMMARY,
methods::X402_SPENDING_SUMMARY_DETAILED,
methods::X402_UPDATE_BUDGET,
Expand All @@ -184,4 +188,5 @@ pub const CONFIDENTIAL_METHODS: &[&str] = &[
methods::SIGN_TRANSACTION,
methods::WEB3_EXECUTE,
methods::X402_PREPARE_PAYMENT,
methods::X402_SIGN_IN,
];
3 changes: 3 additions & 0 deletions crates/tinywallet-bus/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub struct StoredPaymentRecord {
/// The conversation thread, if any.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub thread_id: Option<String>,
/// The x402 scheme the payment was signed under. Absent means `exact`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scheme: Option<String>,
/// The budget hold this entry committed, if any.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub committed_hold: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion crates/tinywallet-bus/src/version/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The `TinyWallet` `TinyBus` contract version and its binding rule.

/// The wire contract version this crate defines.
pub const CONTRACT_VERSION: (u32, u32) = (1, 15);
pub const CONTRACT_VERSION: (u32, u32) = (1, 16);

/// Returns whether a host using [`CONTRACT_VERSION`] can bind to `module`.
///
Expand Down
46 changes: 45 additions & 1 deletion crates/tinywallet-bus/src/wire/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,20 @@ pub struct AuthorizeX402PaymentRequest {
pub asset: String,
/// Payment recipient.
pub recipient: String,
/// Exact amount in token atomic units.
/// Amount in token atomic units that the signed authorization allows: the
/// exact price for `exact`, the most that can be charged for `upto`. A
/// host cap compares against this value.
pub amount_atomic: u64,
/// Conversation owner used to route approval to the initiating client.
/// Older hosts omit this field and retain their existing approval flow.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub owner: Option<QuoteOwner>,
/// The x402 scheme the payment is signed under: `"exact"`, or `"upto"`,
/// where `amount_atomic` is a ceiling and the server charges what it
/// used, from zero up to it. Absent from older modules, which sign only
/// `exact`. Contract 1.16.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scheme: Option<String>,
}

/// Request module-owned parsing and signing for a 402 challenge.
Expand All @@ -388,6 +396,13 @@ pub struct X402PreparePaymentRequest {
/// Older hosts omit this field and keep sending only `secret`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub additional_secrets: Vec<SecretMaterial>,
/// Pay only on this network. A CAIP-2 chain id (`eip155:8453`) must equal
/// the option's network; a CAIP-2 namespace without a colon (`eip155`,
/// `solana`) matches every chain in it. When no option matches, the
/// request is refused before anything is reserved or signed. `None`, and
/// older hosts that omit the field, keep the module's own preference.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub network: Option<String>,
}

/// Payment proof and pending-ledger handle returned to the host for retry.
Expand All @@ -408,6 +423,35 @@ pub struct X402PreparePaymentResponse {
pub network: String,
}

/// Sign an x402 `sign-in-with-x` challenge with the wallet's EVM account.
///
/// The module signs only an EIP-4361 sign-in built from the challenge, and
/// only when its `domain` is the host of `url`, its `uri` and `resources` are
/// HTTPS on that origin, and its `expirationTime` is still ahead. It is not a
/// way to sign other text.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct X402SignInRequest {
/// The URL whose 402 response carried the challenge.
pub url: String,
/// Raw `PAYMENT-REQUIRED` header value (base64 JSON) of that response.
pub payment_required: String,
/// The EVM wallet material, consumed only inside the confidential call.
pub secret: SecretMaterial,
}

/// The signed sign-in for the host's retry.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct X402SignInResponse {
/// Value for the `SIGN-IN-WITH-X` request header.
pub header: String,
/// The account that signed in, EIP-55 checksummed.
pub address: String,
/// The CAIP-2 chain the sign-in names, such as `eip155:8453`.
pub chain_id: String,
}

/// Record the outcome after the host retries with the module-built proof.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
4 changes: 2 additions & 2 deletions crates/tinywallet-bus/src/wire/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub use host::{
Web3ServiceHandle, X402CloseRequest, X402ConfigResponse, X402ConfigureRequest,
X402DetailedSpendingSummary, X402ListPaymentsRequest, X402ListPaymentsResponse,
X402PaymentRecord, X402PaymentStatus, X402PreparePaymentRequest, X402PreparePaymentResponse,
X402RecordPaymentRequest, X402ServiceHandle, X402SpendingSummary, X402SummaryRequest,
X402UpdateBudgetRequest,
X402RecordPaymentRequest, X402ServiceHandle, X402SignInRequest, X402SignInResponse,
X402SpendingSummary, X402SummaryRequest, X402UpdateBudgetRequest,
};
pub use wallet::{
BalanceInfo, ChainStatus, DeriveMnemonicSeedRequest, DeriveMnemonicSeedResponse,
Expand Down
36 changes: 36 additions & 0 deletions crates/tinywallet-bus/src/wire/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,39 @@ fn x402_chain_secret_extension_preserves_legacy_serialization() {
let request: super::X402PreparePaymentRequest = serde_json::from_value(legacy.clone()).unwrap();
assert_eq!(serde_json::to_value(request).unwrap(), legacy);
}

#[test]
fn an_x402_authorization_names_its_scheme_and_older_hosts_still_parse_it() {
let request = super::AuthorizeX402PaymentRequest {
url: "https://twitr.sh/api/tools/x_search".into(),
network: "eip155:8453".into(),
asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913".into(),
recipient: "0xb5194A98DbDBb7028B585Db26B972e7F0F3f826A".into(),
amount_atomic: 3600,
owner: None,
scheme: Some("upto".into()),
};
let encoded = serde_json::to_value(&request).unwrap();
assert_eq!(encoded["scheme"], "upto");
assert_eq!(
serde_json::from_value::<super::AuthorizeX402PaymentRequest>(encoded).unwrap(),
request
);

let legacy = json!({
"url": "https://x", "network": "eip155:8453", "asset": "a",
"recipient": "r", "amount_atomic": 1
});
let parsed: super::AuthorizeX402PaymentRequest = serde_json::from_value(legacy).unwrap();
assert_eq!(parsed.scheme, None);
let unnamed = super::AuthorizeX402PaymentRequest {
scheme: None,
..parsed
};
assert!(
serde_json::to_value(&unnamed)
.unwrap()
.get("scheme")
.is_none()
);
}
12 changes: 12 additions & 0 deletions crates/tinywallet-module/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ impl Wallet {
x402.prepare(request).await.map_err(x402_operation_failed)
}

/// Sign an x402 `sign-in-with-x` challenge with the EVM secret. Only a
/// sign-in for the requested host is signed; anything else is refused
/// before the key is used.
#[tinybus(confidential)]
async fn x402_sign_in(
&self,
request: tinywallet_bus::wire::X402SignInRequest,
) -> BusResult<tinywallet_bus::wire::X402SignInResponse> {
x402::sign_in(request).await.map_err(x402_operation_failed)
}

/// Open or replace the active Web3 quote service after the host establishes
/// the account context. Replacing it waits for in-flight executions and
/// discards every quote tied to the previous credentials.
Expand Down Expand Up @@ -1571,6 +1582,7 @@ mod exports {
"X402UpdateBudget",
"X402Configure",
"X402Close",
"X402SignIn",
],
signals = [],
requires = [],
Expand Down
47 changes: 47 additions & 0 deletions crates/tinywallet-module/src/service/mod_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,7 @@ async fn user_scoped_operations_fail_closed_before_configuration() {
owner: None,
additional_secrets: Vec::new(),
secret: secret(Chain::Evm, "m/44'/60'/0'/0/0"),
network: None,
})
.await
.is_err()
Expand Down Expand Up @@ -1660,3 +1661,49 @@ async fn user_scoped_operations_fail_closed_before_configuration() {
.is_err()
);
}

/// Every bus error the service raises names its own error, so a host can
/// tell a refused approval from an unreachable host or a bad input, and
/// carries the message it was given.
#[test]
fn each_bus_error_names_its_kind_and_keeps_its_message() {
let named = |error: super::BusError| match error {
super::BusError::MethodFailed { name, message } => (name, message),
other => panic!("not a method failure: {other:?}"),
};
let (name, _) = named(super::host_unavailable());
assert_eq!(name, "ai.tinyhumans.tinywallet.Error.HostUnavailable");
for (error, kind) in [
(super::host_call_failed("m".into()), "HostCallFailed"),
(super::invalid_input("m".into()), "InvalidInput"),
(
super::web3_operation_failed("m".into()),
"Web3OperationFailed",
),
(
super::x402_operation_failed("m".into()),
"X402OperationFailed",
),
(
super::native_wallet_operation_failed("m".into()),
"NativeWalletOperationFailed",
),
(super::host_build_failed("m".into()), "BuildFailed"),
] {
let (name, message) = named(error);
assert!(name.ends_with(kind), "{name} is not {kind}");
assert_eq!(message, "m");
}
}

#[test]
fn a_failure_reads_as_its_message() {
assert_eq!(
super::failure_message(super::Failure::InvalidInput("bad".into())),
"bad"
);
assert_eq!(
super::failure_message(super::Failure::BuildFailed("broke".into())),
"broke"
);
}
Loading
Loading