uvd-x402-sdk 2.80.0 → 2.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/adapters/index.d.mts +3 -3
  2. package/dist/adapters/index.d.ts +3 -3
  3. package/dist/adapters/index.js.map +1 -1
  4. package/dist/adapters/index.mjs.map +1 -1
  5. package/dist/backend/index.d.mts +99 -3
  6. package/dist/backend/index.d.ts +99 -3
  7. package/dist/backend/index.js +39 -25
  8. package/dist/backend/index.js.map +1 -1
  9. package/dist/backend/index.mjs +39 -26
  10. package/dist/backend/index.mjs.map +1 -1
  11. package/dist/erc8128/index.d.mts +1 -1
  12. package/dist/erc8128/index.d.ts +1 -1
  13. package/dist/erc8128/index.js.map +1 -1
  14. package/dist/erc8128/index.mjs.map +1 -1
  15. package/dist/{index-CiRbsqXe.d.mts → index-A0HMziCN.d.ts} +76 -2
  16. package/dist/{index-ZH10otHE.d.mts → index-CkR8p1sT.d.mts} +57 -2
  17. package/dist/{index-ZH10otHE.d.ts → index-CkR8p1sT.d.ts} +57 -2
  18. package/dist/{index-DTXTOEby.d.ts → index-DNzmQvh7.d.mts} +76 -2
  19. package/dist/index.d.mts +62 -8
  20. package/dist/index.d.ts +62 -8
  21. package/dist/index.js +2214 -1517
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +2574 -1871
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/{ows-DTDixPzO.d.ts → ows-C-KmORG9.d.ts} +1 -1
  26. package/dist/{ows-CYIVd4xO.d.mts → ows-Z9v4GxOZ.d.mts} +1 -1
  27. package/dist/providers/algorand/index.d.mts +1 -1
  28. package/dist/providers/algorand/index.d.ts +1 -1
  29. package/dist/providers/algorand/index.js.map +1 -1
  30. package/dist/providers/algorand/index.mjs.map +1 -1
  31. package/dist/providers/evm/index.d.mts +1 -1
  32. package/dist/providers/evm/index.d.ts +1 -1
  33. package/dist/providers/evm/index.js.map +1 -1
  34. package/dist/providers/evm/index.mjs.map +1 -1
  35. package/dist/providers/near/index.d.mts +1 -1
  36. package/dist/providers/near/index.d.ts +1 -1
  37. package/dist/providers/near/index.js.map +1 -1
  38. package/dist/providers/near/index.mjs.map +1 -1
  39. package/dist/providers/solana/index.d.mts +1 -1
  40. package/dist/providers/solana/index.d.ts +1 -1
  41. package/dist/providers/solana/index.js.map +1 -1
  42. package/dist/providers/solana/index.mjs.map +1 -1
  43. package/dist/providers/stellar/index.d.mts +1 -1
  44. package/dist/providers/stellar/index.d.ts +1 -1
  45. package/dist/providers/stellar/index.js.map +1 -1
  46. package/dist/providers/stellar/index.mjs.map +1 -1
  47. package/dist/providers/sui/index.d.mts +1 -1
  48. package/dist/providers/sui/index.d.ts +1 -1
  49. package/dist/providers/sui/index.js.map +1 -1
  50. package/dist/providers/sui/index.mjs.map +1 -1
  51. package/dist/providers/xrpl/index.d.mts +1 -1
  52. package/dist/providers/xrpl/index.d.ts +1 -1
  53. package/dist/providers/xrpl/index.js.map +1 -1
  54. package/dist/providers/xrpl/index.mjs.map +1 -1
  55. package/dist/react/index.d.mts +30 -4
  56. package/dist/react/index.d.ts +30 -4
  57. package/dist/react/index.js +1965 -1051
  58. package/dist/react/index.js.map +1 -1
  59. package/dist/react/index.mjs +1961 -1053
  60. package/dist/react/index.mjs.map +1 -1
  61. package/dist/react/picker/index.d.mts +77 -0
  62. package/dist/react/picker/index.d.ts +77 -0
  63. package/dist/react/picker/index.js +1152 -0
  64. package/dist/react/picker/index.js.map +1 -0
  65. package/dist/react/picker/index.mjs +1145 -0
  66. package/dist/react/picker/index.mjs.map +1 -0
  67. package/dist/utils/index.d.mts +2 -2
  68. package/dist/utils/index.d.ts +2 -2
  69. package/dist/utils/index.js +30 -12
  70. package/dist/utils/index.js.map +1 -1
  71. package/dist/utils/index.mjs +30 -12
  72. package/dist/utils/index.mjs.map +1 -1
  73. package/dist/{validation-De3bessL.d.mts → validation-BoqlgHUL.d.ts} +28 -3
  74. package/dist/{validation-DsbfDAtV.d.ts → validation-Cp4arAWl.d.mts} +28 -3
  75. package/dist/{wallet-0cX9Pw2F.d.mts → wallet-w7BnImDG.d.mts} +1 -1
  76. package/dist/{wallet-0cX9Pw2F.d.ts → wallet-w7BnImDG.d.ts} +1 -1
  77. package/package.json +6 -1
  78. package/src/backend/index.ts +159 -28
  79. package/src/client/X402Client.ts +352 -10
  80. package/src/escrow-preauth.ts +56 -4
  81. package/src/index.ts +5 -0
  82. package/src/react/NetworkPicker.tsx +322 -0
  83. package/src/react/PaymentMethodPicker.tsx +110 -0
  84. package/src/react/index.tsx +10 -0
  85. package/src/react/picker.ts +38 -0
  86. package/src/types/index.ts +59 -0
  87. package/src/utils/x402.ts +48 -12
@@ -1,5 +1,5 @@
1
- import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.mjs';
2
- import { Q as X402Version, x as X402Header, G as X402PayloadData } from '../index-ZH10otHE.mjs';
1
+ import { S as SigningWalletAdapter } from '../wallet-w7BnImDG.mjs';
2
+ import { X as X402Version, i as X402Header, j as X402PayloadData } from '../index-CkR8p1sT.mjs';
3
3
 
4
4
  /**
5
5
  * Reading a facilitator refusal as DATA instead of prose.
@@ -1044,6 +1044,69 @@ declare function create402Response(requirements: PaymentRequirementsOptions, opt
1044
1044
  headers: Record<string, string>;
1045
1045
  body: Record<string, unknown>;
1046
1046
  };
1047
+ /** The body of a no-verdict refusal. See {@link buildUnavailableResponse}. */
1048
+ interface UnavailableBody {
1049
+ /** Human-readable summary. Never says the payment was rejected. */
1050
+ error: string;
1051
+ /** The facilitator's own reason, under whichever field it populated. */
1052
+ reason?: string;
1053
+ /** Always `true` — this response exists to say "no verdict", not "refused". */
1054
+ retryable: true;
1055
+ /** Whole seconds to wait, mirroring the `Retry-After` header. */
1056
+ retryAfterSeconds: number;
1057
+ /**
1058
+ * `false` for `forward_failed` and for a bare timeout: the write may already
1059
+ * have landed, so the caller must reconcile before resending.
1060
+ */
1061
+ safeToReplay: boolean;
1062
+ }
1063
+ /** A framework-agnostic HTTP response. See {@link buildUnavailableResponse}. */
1064
+ interface UnavailableResponse {
1065
+ /** Always 503. */
1066
+ status: 503;
1067
+ /** `Retry-After`, ready to spread onto any framework's header setter. */
1068
+ headers: Record<string, string>;
1069
+ body: UnavailableBody;
1070
+ /** Same value as the header, already clamped to a whole second >= 1. */
1071
+ retryAfterSeconds: number;
1072
+ }
1073
+ /**
1074
+ * Build the answer to a facilitator refusal that reached NO VERDICT.
1075
+ *
1076
+ * `verify` returns invalid for two different things: a payment that was
1077
+ * REJECTED, and a facilitator that never reached a verdict (`retryable`).
1078
+ * Answering `402` in the second case tells the buyer to sign a NEW
1079
+ * authorization while the first one is still live and still spendable by the
1080
+ * facilitator — so the buyer pays twice. The correct answer is `503` plus
1081
+ * `Retry-After`, which asks for the SAME credential again.
1082
+ *
1083
+ * This returns plain data — status, headers, body — so a handler written
1084
+ * without Express (Lambda, Hono, a Next route, Fastify, a bare `Response`) can
1085
+ * answer correctly without re-deriving the rule. The Express and Hono
1086
+ * middlewares in this SDK both build their reply from it.
1087
+ *
1088
+ * @param message - Summary for the `error` field, e.g. `'Payment verification unavailable'`
1089
+ * @param failure - The facilitator result. Only its failure fields are read.
1090
+ *
1091
+ * @example Lambda / any framework
1092
+ * ```ts
1093
+ * const verifyResult = await client.verify(payment, requirements);
1094
+ * if (!verifyResult.isValid && verifyResult.retryable) {
1095
+ * const r = buildUnavailableResponse('Payment verification unavailable', verifyResult);
1096
+ * return { statusCode: r.status, headers: r.headers, body: JSON.stringify(r.body) };
1097
+ * }
1098
+ * ```
1099
+ *
1100
+ * @example Web `Response`
1101
+ * ```ts
1102
+ * const r = buildUnavailableResponse('Payment settlement unavailable', settleResult);
1103
+ * return Response.json(r.body, { status: r.status, headers: r.headers });
1104
+ * ```
1105
+ */
1106
+ declare function buildUnavailableResponse(message: string, failure: FacilitatorFailureFields & {
1107
+ error?: string;
1108
+ invalidReason?: string;
1109
+ }): UnavailableResponse;
1047
1110
  /**
1048
1111
  * Create an Express-compatible middleware for x402 payments
1049
1112
  *
@@ -2902,6 +2965,15 @@ declare const DEPOSIT_LIMIT_USDC = "100000000";
2902
2965
  * Default facilitator request timeout per chain in milliseconds.
2903
2966
  * Ethereum L1 (~12s blocks) needs much longer than L2s (~2s blocks).
2904
2967
  * Timeout chain: Client > SDK > Facilitator. The facilitator uses 900s for Ethereum L1.
2968
+ *
2969
+ * These are correct, and they are also a PRODUCT constraint worth reading before
2970
+ * you offer a network in a checkout: Ethereum L1 is 960s against 90s for every
2971
+ * L2 here. A buyer waiting in a browser will not wait sixteen minutes, so a
2972
+ * human-facing flow should offer the L2s and leave L1 to agent-to-agent or
2973
+ * batch callers that can tolerate the wait. Do not shorten this to make a
2974
+ * checkout feel faster — the value tracks L1 block time and the facilitator's
2975
+ * own 900s TxWatcher, and cutting it just times out a payment that was going
2976
+ * to land.
2905
2977
  */
2906
2978
  declare const ESCROW_TIMEOUT_MS: Record<number, number>;
2907
2979
  /**
@@ -2914,6 +2986,21 @@ declare const USDC_DOMAIN_NAME: Record<number, string>;
2914
2986
  * Multi-chain escrow contract addresses for the Advanced Escrow system.
2915
2987
  * Keyed by EVM chain ID. Source: x402r-sdk A1igator/multichain-config deployment.
2916
2988
  */
2989
+ /**
2990
+ * Per-chain escrow contract addresses.
2991
+ *
2992
+ * KNOWN GAP, measured 2026-09-05: the `operator` entries are
2993
+ * PaymentOperatorFactory addresses, not deployed PaymentOperator instances.
2994
+ * Verified on Base mainnet, Base Sepolia and Arbitrum — they answer
2995
+ * `ESCROW()` and `operators(bytes32)` and revert on `FEE_CALCULATOR()`,
2996
+ * `FEE_RECIPIENT()` and `release(...)` — and x402-rs
2997
+ * `docs/X402R_MULTICHAIN_DEPLOYMENT.md` labels the same addresses
2998
+ * "PaymentOperatorFactory". A factory has no `release`/`charge`, so the direct
2999
+ * on-chain paths below cannot execute against these addresses as written;
3000
+ * resolve the real operator from the marketplace's own escrow config
3001
+ * ({@link EscrowNetworkConfig}) and pass it via `options.contracts`.
3002
+ * See {@link OPERATOR_FEE_BPS} for the commands.
3003
+ */
2917
3004
  declare const ESCROW_CONTRACTS: Record<number, AdvancedEscrowContracts>;
2918
3005
  /**
2919
3006
  * Base Mainnet contract addresses for the Advanced Escrow system.
@@ -3194,6 +3281,15 @@ declare class AdvancedEscrowClient {
3194
3281
  buildPaymentInfo(receiver: string, amount: string, tier?: AdvancedEscrowTaskTier, salt?: string, opts?: {
3195
3282
  deadline?: number;
3196
3283
  reviewWindowSec?: number;
3284
+ /**
3285
+ * Fee bounds to sign, in basis points. Default
3286
+ * {@link DEFAULT_MIN_FEE_BPS} / {@link DEFAULT_MAX_FEE_BPS}. Override
3287
+ * only against an operator whose fee you have actually read on-chain —
3288
+ * `maxFeeBps` is a CEILING, so a value under the operator's own fee does
3289
+ * not shave the fee, it reverts the deposit.
3290
+ */
3291
+ minFeeBps?: number;
3292
+ maxFeeBps?: number;
3197
3293
  }): AdvancedPaymentInfo;
3198
3294
  /**
3199
3295
  * Compute the correct nonce (with PAYMENT_INFO_TYPEHASH).
@@ -3375,4 +3471,4 @@ declare class AdvancedEscrowClient {
3375
3471
  private sendViaAdapter;
3376
3472
  }
3377
3473
 
3378
- export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type ParsedFacilitatorErrorBody, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, SETTLEMENT_UNCONFIRMED, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, isSettlementUnconfirmed, parseFacilitatorErrorBody, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
3474
+ export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type ParsedFacilitatorErrorBody, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, SETTLEMENT_UNCONFIRMED, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type UnavailableBody, type UnavailableResponse, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildUnavailableResponse, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, isSettlementUnconfirmed, parseFacilitatorErrorBody, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
@@ -1,5 +1,5 @@
1
- import { S as SigningWalletAdapter } from '../wallet-0cX9Pw2F.js';
2
- import { Q as X402Version, x as X402Header, G as X402PayloadData } from '../index-ZH10otHE.js';
1
+ import { S as SigningWalletAdapter } from '../wallet-w7BnImDG.js';
2
+ import { X as X402Version, i as X402Header, j as X402PayloadData } from '../index-CkR8p1sT.js';
3
3
 
4
4
  /**
5
5
  * Reading a facilitator refusal as DATA instead of prose.
@@ -1044,6 +1044,69 @@ declare function create402Response(requirements: PaymentRequirementsOptions, opt
1044
1044
  headers: Record<string, string>;
1045
1045
  body: Record<string, unknown>;
1046
1046
  };
1047
+ /** The body of a no-verdict refusal. See {@link buildUnavailableResponse}. */
1048
+ interface UnavailableBody {
1049
+ /** Human-readable summary. Never says the payment was rejected. */
1050
+ error: string;
1051
+ /** The facilitator's own reason, under whichever field it populated. */
1052
+ reason?: string;
1053
+ /** Always `true` — this response exists to say "no verdict", not "refused". */
1054
+ retryable: true;
1055
+ /** Whole seconds to wait, mirroring the `Retry-After` header. */
1056
+ retryAfterSeconds: number;
1057
+ /**
1058
+ * `false` for `forward_failed` and for a bare timeout: the write may already
1059
+ * have landed, so the caller must reconcile before resending.
1060
+ */
1061
+ safeToReplay: boolean;
1062
+ }
1063
+ /** A framework-agnostic HTTP response. See {@link buildUnavailableResponse}. */
1064
+ interface UnavailableResponse {
1065
+ /** Always 503. */
1066
+ status: 503;
1067
+ /** `Retry-After`, ready to spread onto any framework's header setter. */
1068
+ headers: Record<string, string>;
1069
+ body: UnavailableBody;
1070
+ /** Same value as the header, already clamped to a whole second >= 1. */
1071
+ retryAfterSeconds: number;
1072
+ }
1073
+ /**
1074
+ * Build the answer to a facilitator refusal that reached NO VERDICT.
1075
+ *
1076
+ * `verify` returns invalid for two different things: a payment that was
1077
+ * REJECTED, and a facilitator that never reached a verdict (`retryable`).
1078
+ * Answering `402` in the second case tells the buyer to sign a NEW
1079
+ * authorization while the first one is still live and still spendable by the
1080
+ * facilitator — so the buyer pays twice. The correct answer is `503` plus
1081
+ * `Retry-After`, which asks for the SAME credential again.
1082
+ *
1083
+ * This returns plain data — status, headers, body — so a handler written
1084
+ * without Express (Lambda, Hono, a Next route, Fastify, a bare `Response`) can
1085
+ * answer correctly without re-deriving the rule. The Express and Hono
1086
+ * middlewares in this SDK both build their reply from it.
1087
+ *
1088
+ * @param message - Summary for the `error` field, e.g. `'Payment verification unavailable'`
1089
+ * @param failure - The facilitator result. Only its failure fields are read.
1090
+ *
1091
+ * @example Lambda / any framework
1092
+ * ```ts
1093
+ * const verifyResult = await client.verify(payment, requirements);
1094
+ * if (!verifyResult.isValid && verifyResult.retryable) {
1095
+ * const r = buildUnavailableResponse('Payment verification unavailable', verifyResult);
1096
+ * return { statusCode: r.status, headers: r.headers, body: JSON.stringify(r.body) };
1097
+ * }
1098
+ * ```
1099
+ *
1100
+ * @example Web `Response`
1101
+ * ```ts
1102
+ * const r = buildUnavailableResponse('Payment settlement unavailable', settleResult);
1103
+ * return Response.json(r.body, { status: r.status, headers: r.headers });
1104
+ * ```
1105
+ */
1106
+ declare function buildUnavailableResponse(message: string, failure: FacilitatorFailureFields & {
1107
+ error?: string;
1108
+ invalidReason?: string;
1109
+ }): UnavailableResponse;
1047
1110
  /**
1048
1111
  * Create an Express-compatible middleware for x402 payments
1049
1112
  *
@@ -2902,6 +2965,15 @@ declare const DEPOSIT_LIMIT_USDC = "100000000";
2902
2965
  * Default facilitator request timeout per chain in milliseconds.
2903
2966
  * Ethereum L1 (~12s blocks) needs much longer than L2s (~2s blocks).
2904
2967
  * Timeout chain: Client > SDK > Facilitator. The facilitator uses 900s for Ethereum L1.
2968
+ *
2969
+ * These are correct, and they are also a PRODUCT constraint worth reading before
2970
+ * you offer a network in a checkout: Ethereum L1 is 960s against 90s for every
2971
+ * L2 here. A buyer waiting in a browser will not wait sixteen minutes, so a
2972
+ * human-facing flow should offer the L2s and leave L1 to agent-to-agent or
2973
+ * batch callers that can tolerate the wait. Do not shorten this to make a
2974
+ * checkout feel faster — the value tracks L1 block time and the facilitator's
2975
+ * own 900s TxWatcher, and cutting it just times out a payment that was going
2976
+ * to land.
2905
2977
  */
2906
2978
  declare const ESCROW_TIMEOUT_MS: Record<number, number>;
2907
2979
  /**
@@ -2914,6 +2986,21 @@ declare const USDC_DOMAIN_NAME: Record<number, string>;
2914
2986
  * Multi-chain escrow contract addresses for the Advanced Escrow system.
2915
2987
  * Keyed by EVM chain ID. Source: x402r-sdk A1igator/multichain-config deployment.
2916
2988
  */
2989
+ /**
2990
+ * Per-chain escrow contract addresses.
2991
+ *
2992
+ * KNOWN GAP, measured 2026-09-05: the `operator` entries are
2993
+ * PaymentOperatorFactory addresses, not deployed PaymentOperator instances.
2994
+ * Verified on Base mainnet, Base Sepolia and Arbitrum — they answer
2995
+ * `ESCROW()` and `operators(bytes32)` and revert on `FEE_CALCULATOR()`,
2996
+ * `FEE_RECIPIENT()` and `release(...)` — and x402-rs
2997
+ * `docs/X402R_MULTICHAIN_DEPLOYMENT.md` labels the same addresses
2998
+ * "PaymentOperatorFactory". A factory has no `release`/`charge`, so the direct
2999
+ * on-chain paths below cannot execute against these addresses as written;
3000
+ * resolve the real operator from the marketplace's own escrow config
3001
+ * ({@link EscrowNetworkConfig}) and pass it via `options.contracts`.
3002
+ * See {@link OPERATOR_FEE_BPS} for the commands.
3003
+ */
2917
3004
  declare const ESCROW_CONTRACTS: Record<number, AdvancedEscrowContracts>;
2918
3005
  /**
2919
3006
  * Base Mainnet contract addresses for the Advanced Escrow system.
@@ -3194,6 +3281,15 @@ declare class AdvancedEscrowClient {
3194
3281
  buildPaymentInfo(receiver: string, amount: string, tier?: AdvancedEscrowTaskTier, salt?: string, opts?: {
3195
3282
  deadline?: number;
3196
3283
  reviewWindowSec?: number;
3284
+ /**
3285
+ * Fee bounds to sign, in basis points. Default
3286
+ * {@link DEFAULT_MIN_FEE_BPS} / {@link DEFAULT_MAX_FEE_BPS}. Override
3287
+ * only against an operator whose fee you have actually read on-chain —
3288
+ * `maxFeeBps` is a CEILING, so a value under the operator's own fee does
3289
+ * not shave the fee, it reverts the deposit.
3290
+ */
3291
+ minFeeBps?: number;
3292
+ maxFeeBps?: number;
3197
3293
  }): AdvancedPaymentInfo;
3198
3294
  /**
3199
3295
  * Compute the correct nonce (with PAYMENT_INFO_TYPEHASH).
@@ -3375,4 +3471,4 @@ declare class AdvancedEscrowClient {
3375
3471
  private sendViaAdapter;
3376
3472
  }
3377
3473
 
3378
- export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type ParsedFacilitatorErrorBody, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, SETTLEMENT_UNCONFIRMED, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, isSettlementUnconfirmed, parseFacilitatorErrorBody, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
3474
+ export { AMBIGUOUS_LEASE_REASONS, type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentId, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, type AtomStats, BASE_MAINNET_CONTRACTS, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarRegisterOptions, type BazaarResource, type CreateEscrowOptions, DEFAULT_FACILITATOR_RETRIES, DEFAULT_RETRY_AFTER_SECONDS, DEPOSIT_LIMIT_USDC, type DiscoveryAccepts, type DiscoveryCuration, type DiscoveryHealth, type DiscoveryHealthStatus, type DiscoveryListOptions, type DiscoveryPagination, type DiscoveryRegisterOptions, type DiscoveryResource, type DiscoveryResponse, type DiscoverySource, type DiscoveryStats, type DiscoveryTier, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, ESCROW_TIMEOUT_MS, Erc8004Client, type Erc8004ClientOptions, Erc8004LookupError, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FacilitatorErrorInfo, type FacilitatorFailureFields, type FacilitatorFetchOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, HEALTH_FILTERS, type HonoMiddlewareOptions, type IdentityByOwnerResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, MAX_RETRY_AFTER_SECONDS, MAX_SEARCH_LEN, type MetadataEntryParam, OPERATOR_ABI, OPERATOR_ABI_CREATE3, PAYMENT_INFO_TYPEHASH, type ParsedFacilitatorErrorBody, type PaymentAcceptance, type PaymentMiddlewareOptions, type PaymentPayloadV2, type PaymentRequirementResolver, type PaymentRequirements, type PaymentRequirementsOptions, type PaymentRequirementsV2, type PrepareRelayFeedbackRequest, type PrepareRelayFeedbackResponse, type PrepareRelayResponseRequest, type ProofOfPayment, RELAYED_FEEDBACK_NETWORKS, REPLAYABLE_LEASE_REASONS, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterJobResponse, type RegisterJobStatus, RegistrationPendingError, type RelayAuthorizationParams, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type ResourceInfoV2, SETTLEMENT_UNCONFIRMED, type SettleRequest, type SettleRequestV2, type SettleResponse, type SettleResponseWithProof, type SubmitRelayFeedbackRequest, type SubmitRelayResponseRequest, TIER_FILTERS, TIER_TIMINGS, USDC_DOMAIN_NAME, type UnavailableBody, type UnavailableResponse, type VerifiedPaymentState, type VerifyRequest, type VerifyRequestV2, type VerifyResponse, WRITER_LEASE_REASONS, type WriterLeaseReason, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildSettleRequestForVersion, buildSettleRequestV2, buildUnavailableResponse, buildVerifyRequest, buildVerifyRequestForVersion, buildVerifyRequestV2, canRefundEscrow, canReleaseEscrow, carryFailureFields, create402Response, createHonoMiddleware, createPaymentMiddleware, epochToDate, escrowTimeRemaining, extractPaymentFromHeaders, facilitatorFetch, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isAlive, isAmbiguousLeaseReason, isEscrowExpired, isEscrowSupportedOnChain, isRegisterJobTerminal, isReplayableLeaseReason, isSettlementUnconfirmed, parseFacilitatorErrorBody, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
@@ -1090,6 +1090,10 @@ function decodeX402Header(encoded) {
1090
1090
  const json = decodeBase64Utf8(encoded);
1091
1091
  return JSON.parse(json);
1092
1092
  }
1093
+ var OPERATOR_FEE_BPS = 1300;
1094
+ var MAX_PROTOCOL_FEE_BPS = 500;
1095
+ var DEFAULT_MIN_FEE_BPS = 0;
1096
+ var DEFAULT_MAX_FEE_BPS = OPERATOR_FEE_BPS + MAX_PROTOCOL_FEE_BPS;
1093
1097
  var REVIEW_WINDOW_SEC = 7 * 24 * 3600;
1094
1098
  var REFUND_WINDOW_SEC = 7 * 24 * 3600;
1095
1099
 
@@ -2006,20 +2010,26 @@ function createVerifiedPaymentState(client, payment, requirements, verifyResult)
2006
2010
  }
2007
2011
  };
2008
2012
  }
2009
- function respondUnavailable(res, message, failure) {
2013
+ function buildUnavailableResponse(message, failure) {
2010
2014
  const seconds = Math.max(1, Math.ceil(failure.retryAfterSeconds ?? DEFAULT_RETRY_AFTER_SECONDS));
2011
- const body = {
2012
- error: message,
2013
- reason: failure.reason ?? failure.invalidReason ?? failure.error,
2014
- retryable: true,
2015
- retryAfterSeconds: seconds,
2016
- // False for `forward_failed` and for a bare timeout: the write may already
2017
- // have landed, so the caller must reconcile before resending.
2018
- safeToReplay: failure.safeToReplay === true
2015
+ return {
2016
+ status: 503,
2017
+ headers: { "Retry-After": String(seconds) },
2018
+ body: {
2019
+ error: message,
2020
+ reason: failure.reason ?? failure.invalidReason ?? failure.error,
2021
+ retryable: true,
2022
+ retryAfterSeconds: seconds,
2023
+ safeToReplay: failure.safeToReplay === true
2024
+ },
2025
+ retryAfterSeconds: seconds
2019
2026
  };
2020
- const staged = res.status(503);
2027
+ }
2028
+ function respondUnavailable(res, message, failure) {
2029
+ const { status, headers, body } = buildUnavailableResponse(message, failure);
2030
+ const staged = res.status(status);
2021
2031
  if (typeof staged.set === "function") {
2022
- staged.set({ "Retry-After": String(seconds) }).json(body);
2032
+ staged.set(headers).json(body);
2023
2033
  return;
2024
2034
  }
2025
2035
  staged.json(body);
@@ -2079,18 +2089,11 @@ function settlementFailureBody(failure, fallbackReason) {
2079
2089
  };
2080
2090
  }
2081
2091
  function honoUnavailable(c, message, failure) {
2082
- const seconds = Math.max(1, Math.ceil(failure.retryAfterSeconds ?? DEFAULT_RETRY_AFTER_SECONDS));
2083
- c.header?.("Retry-After", String(seconds));
2084
- return c.json(
2085
- {
2086
- error: message,
2087
- reason: failure.reason ?? failure.invalidReason ?? failure.error,
2088
- retryable: true,
2089
- retryAfterSeconds: seconds,
2090
- safeToReplay: failure.safeToReplay === true
2091
- },
2092
- 503
2093
- );
2092
+ const { status, headers, body } = buildUnavailableResponse(message, failure);
2093
+ for (const [name, value] of Object.entries(headers)) {
2094
+ c.header?.(name, value);
2095
+ }
2096
+ return c.json(body, status);
2094
2097
  }
2095
2098
  function createHonoMiddleware(options) {
2096
2099
  const client = new FacilitatorClient({
@@ -4150,6 +4153,16 @@ var AdvancedEscrowClient = class {
4150
4153
  }
4151
4154
  generatedSalt = "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
4152
4155
  }
4156
+ const minFeeBps = opts?.minFeeBps ?? DEFAULT_MIN_FEE_BPS;
4157
+ const maxFeeBps = opts?.maxFeeBps ?? DEFAULT_MAX_FEE_BPS;
4158
+ if (maxFeeBps < minFeeBps) {
4159
+ throw new Error(`maxFeeBps=${maxFeeBps} is below minFeeBps=${minFeeBps}`);
4160
+ }
4161
+ if (maxFeeBps < OPERATOR_FEE_BPS) {
4162
+ throw new Error(
4163
+ `maxFeeBps=${maxFeeBps} cannot cover the operator's ${OPERATOR_FEE_BPS} bps fee \u2014 the on-chain authorize would revert with FeeBoundsIncompatible. Read the fee off your operator before overriding it.`
4164
+ );
4165
+ }
4153
4166
  return {
4154
4167
  operator: this.contracts.operator,
4155
4168
  receiver,
@@ -4158,8 +4171,8 @@ var AdvancedEscrowClient = class {
4158
4171
  preApprovalExpiry: now + t.pre,
4159
4172
  authorizationExpiry,
4160
4173
  refundExpiry,
4161
- minFeeBps: 0,
4162
- maxFeeBps: 800,
4174
+ minFeeBps,
4175
+ maxFeeBps,
4163
4176
  feeReceiver: this.contracts.operator,
4164
4177
  salt: generatedSalt
4165
4178
  };
@@ -4879,6 +4892,7 @@ exports.buildPaymentRequirements = buildPaymentRequirements;
4879
4892
  exports.buildSettleRequest = buildSettleRequest;
4880
4893
  exports.buildSettleRequestForVersion = buildSettleRequestForVersion;
4881
4894
  exports.buildSettleRequestV2 = buildSettleRequestV2;
4895
+ exports.buildUnavailableResponse = buildUnavailableResponse;
4882
4896
  exports.buildVerifyRequest = buildVerifyRequest;
4883
4897
  exports.buildVerifyRequestForVersion = buildVerifyRequestForVersion;
4884
4898
  exports.buildVerifyRequestV2 = buildVerifyRequestV2;