uvd-x402-sdk 2.79.0 → 2.81.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 (63) hide show
  1. package/README.md +63 -0
  2. package/dist/adapters/index.d.mts +3 -3
  3. package/dist/adapters/index.d.ts +3 -3
  4. package/dist/backend/index.d.mts +118 -4
  5. package/dist/backend/index.d.ts +118 -4
  6. package/dist/backend/index.js +98 -26
  7. package/dist/backend/index.js.map +1 -1
  8. package/dist/backend/index.mjs +96 -27
  9. package/dist/backend/index.mjs.map +1 -1
  10. package/dist/erc8128/index.d.mts +1 -1
  11. package/dist/erc8128/index.d.ts +1 -1
  12. package/dist/{index-CiRbsqXe.d.mts → index-BbveI6RT.d.mts} +2 -2
  13. package/dist/{index-DTXTOEby.d.ts → index-CmIus8r3.d.ts} +2 -2
  14. package/dist/{index-ZH10otHE.d.mts → index-D5uN1cIM.d.mts} +1 -1
  15. package/dist/{index-ZH10otHE.d.ts → index-D5uN1cIM.d.ts} +1 -1
  16. package/dist/index.d.mts +7 -7
  17. package/dist/index.d.ts +7 -7
  18. package/dist/index.js +67 -17
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +65 -18
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/{ows-DTDixPzO.d.ts → ows-C-KmORG9.d.ts} +1 -1
  23. package/dist/{ows-CYIVd4xO.d.mts → ows-Z9v4GxOZ.d.mts} +1 -1
  24. package/dist/providers/algorand/index.d.mts +1 -1
  25. package/dist/providers/algorand/index.d.ts +1 -1
  26. package/dist/providers/evm/index.d.mts +1 -1
  27. package/dist/providers/evm/index.d.ts +1 -1
  28. package/dist/providers/near/index.d.mts +1 -1
  29. package/dist/providers/near/index.d.ts +1 -1
  30. package/dist/providers/solana/index.d.mts +1 -1
  31. package/dist/providers/solana/index.d.ts +1 -1
  32. package/dist/providers/stellar/index.d.mts +1 -1
  33. package/dist/providers/stellar/index.d.ts +1 -1
  34. package/dist/providers/sui/index.d.mts +1 -1
  35. package/dist/providers/sui/index.d.ts +1 -1
  36. package/dist/providers/xrpl/index.d.mts +1 -1
  37. package/dist/providers/xrpl/index.d.ts +1 -1
  38. package/dist/react/index.d.mts +30 -4
  39. package/dist/react/index.d.ts +30 -4
  40. package/dist/react/index.js +215 -0
  41. package/dist/react/index.js.map +1 -1
  42. package/dist/react/index.mjs +212 -3
  43. package/dist/react/index.mjs.map +1 -1
  44. package/dist/react/picker/index.d.mts +77 -0
  45. package/dist/react/picker/index.d.ts +77 -0
  46. package/dist/react/picker/index.js +1152 -0
  47. package/dist/react/picker/index.js.map +1 -0
  48. package/dist/react/picker/index.mjs +1145 -0
  49. package/dist/react/picker/index.mjs.map +1 -0
  50. package/dist/utils/index.d.mts +2 -2
  51. package/dist/utils/index.d.ts +2 -2
  52. package/dist/{validation-DsbfDAtV.d.ts → validation-Cjew3uCN.d.ts} +1 -1
  53. package/dist/{validation-De3bessL.d.mts → validation-GwdW_4v4.d.mts} +1 -1
  54. package/dist/{wallet-0cX9Pw2F.d.mts → wallet-w7BnImDG.d.mts} +1 -1
  55. package/dist/{wallet-0cX9Pw2F.d.ts → wallet-w7BnImDG.d.ts} +1 -1
  56. package/package.json +6 -1
  57. package/src/backend/facilitator-error.ts +201 -11
  58. package/src/backend/index.ts +79 -18
  59. package/src/index.ts +6 -0
  60. package/src/react/NetworkPicker.tsx +322 -0
  61. package/src/react/PaymentMethodPicker.tsx +110 -0
  62. package/src/react/index.tsx +10 -0
  63. package/src/react/picker.ts +38 -0
package/README.md CHANGED
@@ -877,6 +877,8 @@ try {
877
877
  |---|---|---|
878
878
  | **402** | the payment was **rejected** | sign a **new** authorization |
879
879
  | **503** | **no verdict was reached** | resend the **same** credential |
880
+ | **502** `upstream_rpc_unavailable` | the node never answered; nothing was broadcast | resend the **same** credential |
881
+ | **502** `settlement_unconfirmed` | broadcast, **and it may be mined** | **send nothing** — look up the hash |
880
882
 
881
883
  Charging a `503` as a `402` makes the buyer sign and broadcast a second payment
882
884
  for money that was never refused — and the first authorization is still
@@ -893,6 +895,11 @@ if (!result.success) {
893
895
  // result.reason -> 'holder_unknown' | 'forward_failed' | ...
894
896
  // result.retryAfterSeconds -> already clamped, never an hour
895
897
  // result.safeToReplay -> true only if the facilitator proved nothing ran
898
+ } else if (isSettlementUnconfirmed(result)) {
899
+ // NOT a refusal: the transfer was broadcast and may already be mined.
900
+ // Reconcile — never re-send.
901
+ // result.transaction -> the hash, in that chain's own encoding
902
+ // result.paymentId -> the same id a successful settle would have printed
896
903
  } else {
897
904
  // A real refusal. result.errorReason says why.
898
905
  }
@@ -935,12 +942,68 @@ new FacilitatorClient({ retries: 0 }); // never replay; default is 2 extra att
935
942
  misconfigured facilitator answering `Retry-After: 3600` would otherwise hang the
936
943
  request for an hour.
937
944
 
945
+ ### The two `502`s mean opposite things — branch on the body, not the status
946
+
947
+ `POST /settle` answers `502` for two situations that call for opposite moves:
948
+
949
+ | body `error` | `Retry-After` | did the money move? | retry? |
950
+ |---|---|---|---|
951
+ | `upstream_rpc_unavailable` | `30` | no, nothing was broadcast | **yes** |
952
+ | `settlement_unconfirmed` | **absent** | **maybe — it may be mined** | **never** |
953
+
954
+ `settlement_unconfirmed` is emitted when the transaction went out and no receipt
955
+ ever came back. Retrying it re-signs a **new** authorization with a **fresh
956
+ nonce**, which the chain accepts as a second, perfectly valid payment for the
957
+ same purchase — the buyer pays twice, in exactly the case the facilitator emits
958
+ this error to prevent. `authorizationState` does not stop it: the second
959
+ authorization is genuinely new.
960
+
961
+ So the status alone cannot decide. This SDK reads the body:
962
+
963
+ ```typescript
964
+ import { isSettlementUnconfirmed, SETTLEMENT_UNCONFIRMED } from 'uvd-x402-sdk';
965
+
966
+ const result = await client.settle(payment, requirements);
967
+
968
+ if (!result.success && isSettlementUnconfirmed(result)) {
969
+ // result.retryable -> false. Do not resend, and do not ask for a signature.
970
+ // result.transaction -> what to look up on chain
971
+ // result.paymentId -> matches the id a successful settle prints, so a
972
+ // payment later found confirmed reconciles cleanly
973
+ await reconcileOnChain(result.transaction);
974
+ }
975
+ ```
976
+
977
+ `result.transaction` is **not always `0x`-prefixed** — Algorand prints base32 and
978
+ Solana base58. Pass it through verbatim; reformatting it makes it unpasteable in
979
+ an explorer, and pasting it is the entire remedy on offer.
980
+
981
+ The same reading applies to `Erc8004LookupError` (`POST /register` goes through
982
+ the same EVM path, so a mint can come back unconfirmed too) and to every gasless
983
+ escrow call. An explicit `retryable: false` in a facilitator body always wins
984
+ over the status — but only ever **downgrades**: a body claiming `retryable: true`
985
+ on a `402` will not make this SDK resend a genuinely refused credential.
986
+
987
+ Three independent signals stop a retry, because the cost of missing one is a
988
+ second payment: the explicit `retryable: false`, the named
989
+ `settlement_unconfirmed`, and — the general rule — **any 5xx body carrying a
990
+ transaction hash at all**, under any of `transaction`, `transaction.hash`,
991
+ `txHash`, `tx_hash` or `transaction_hash`. A hash in a *failure* means the
992
+ facilitator got as far as broadcasting, whatever it called the error, so that
993
+ last rule holds for codes that do not exist yet. It is the Python SDK's
994
+ anti-double-settle guard, adopted here.
995
+
938
996
  ### Middleware
939
997
 
940
998
  `createPaymentMiddleware` and `createHonoMiddleware` answer **503 with a
941
999
  `Retry-After` header** — not `402`, not `500` — whenever the facilitator reached
942
1000
  no verdict, and keep answering `402` for genuine rejections.
943
1001
 
1002
+ An unconfirmed settlement is the one 5xx that goes out as **`500`, with no
1003
+ `Retry-After`**: "stop" is the correct instruction when the transfer may already
1004
+ be mining. The body carries `transaction`, `paymentId` and `retryable: false`, so
1005
+ the buyer's client can reconcile instead of paying again.
1006
+
944
1007
  ## ERC-8004 Trustless Agents
945
1008
 
946
1009
  Build verifiable on-chain reputation for AI agents and services. Supports **21 networks** (19 EVM + 2 Solana).
@@ -1,6 +1,6 @@
1
- import { Q as X402Version, k as PaymentResult } from '../index-ZH10otHE.mjs';
2
- export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-CYIVd4xO.mjs';
3
- import '../wallet-0cX9Pw2F.mjs';
1
+ import { X as X402Version, a as PaymentResult } from '../index-D5uN1cIM.mjs';
2
+ export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-Z9v4GxOZ.mjs';
3
+ import '../wallet-w7BnImDG.mjs';
4
4
 
5
5
  /**
6
6
  * uvd-x402-sdk - Wagmi/Viem Adapter
@@ -1,6 +1,6 @@
1
- import { Q as X402Version, k as PaymentResult } from '../index-ZH10otHE.js';
2
- export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-DTDixPzO.js';
3
- import '../wallet-0cX9Pw2F.js';
1
+ import { X as X402Version, a as PaymentResult } from '../index-D5uN1cIM.js';
2
+ export { E as EnvKeyAdapter, O as OWSWallet, a as OWSWalletAdapter } from '../ows-C-KmORG9.js';
3
+ import '../wallet-w7BnImDG.js';
4
4
 
5
5
  /**
6
6
  * uvd-x402-sdk - Wagmi/Viem Adapter
@@ -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, h as X402Header, i as X402PayloadData } from '../index-D5uN1cIM.mjs';
3
3
 
4
4
  /**
5
5
  * Reading a facilitator refusal as DATA instead of prose.
@@ -45,8 +45,34 @@ import { Q as X402Version, x as X402Header, G as X402PayloadData } from '../inde
45
45
  * sequence that once minted five duplicate agents — reconcile with
46
46
  * `GET /identity/{network}/owner/{recipient}` or `getRegisterStatus` instead.
47
47
  *
48
+ * # The two `502`s of `/settle`, which mean opposite things
49
+ *
50
+ * | body `error` | `Retry-After` | did the money move? | retry? |
51
+ * |----------------------------|---------------|---------------------|-----------|
52
+ * | `upstream_rpc_unavailable` | `30` | no, never broadcast | **yes** |
53
+ * | `settlement_unconfirmed` | **absent** | **maybe — mined?** | **NEVER** |
54
+ *
55
+ * `settlement_unconfirmed` is answered after the transaction was broadcast and
56
+ * no receipt ever arrived, so it MAY be mined. Retrying re-signs a new
57
+ * authorization with a fresh nonce, which the chain accepts as a second,
58
+ * perfectly valid payment for the same purchase — the buyer pays twice, in
59
+ * exactly the case the facilitator emits it to prevent. The `transaction` hash
60
+ * and `paymentId` travel in the body so the caller can LOOK AT THE CHAIN; they
61
+ * are not an invitation to send it again.
62
+ *
63
+ * The status cannot tell the two apart, which is why this file used to get it
64
+ * wrong: every `502` was retryable, and until `settlement_unconfirmed` existed
65
+ * that was correct. **Branch on the body.**
66
+ *
67
+ * The general form of that rule — **a 5xx whose body carries a transaction hash
68
+ * was broadcast, whatever the error is called** — is adopted from the Python
69
+ * SDK, which has carried it as its anti-double-settle guard
70
+ * (`uvd_x402_sdk/client.py`, `_is_retryable_settle_error`) while this one had
71
+ * only the status to go on.
72
+ *
48
73
  * Source of the shape: x402-rs `src/handlers.rs` `writer_lease_unavailable()`
49
- * and `require_writer_lease()`.
74
+ * and `require_writer_lease()`; `SettlementUnconfirmedResponse` in
75
+ * `src/types.rs`, built in the `IntoResponse` of `FacilitatorLocalError`.
50
76
  */
51
77
  /**
52
78
  * A `reason` the facilitator attaches to a writer-lease 503.
@@ -72,6 +98,13 @@ declare const REPLAYABLE_LEASE_REASONS: readonly WriterLeaseReason[];
72
98
  * automatically. Resolve it by reading state, not by re-POSTing.
73
99
  */
74
100
  declare const AMBIGUOUS_LEASE_REASONS: readonly WriterLeaseReason[];
101
+ /**
102
+ * The facilitator's `error` code for a settle it broadcast and could not confirm.
103
+ *
104
+ * The transaction may be mined. This is the one upstream failure that must
105
+ * never be retried; reconcile with `transaction` / `paymentId` instead.
106
+ */
107
+ declare const SETTLEMENT_UNCONFIRMED = "settlement_unconfirmed";
75
108
  /**
76
109
  * Ceiling, in seconds, on how long an automatic retry will wait.
77
110
  *
@@ -98,6 +131,24 @@ interface FacilitatorErrorInfo {
98
131
  status: number;
99
132
  /** The facilitator's own `reason`, when the body carried one. */
100
133
  reason?: string;
134
+ /**
135
+ * The facilitator's machine-readable `error` code, verbatim.
136
+ *
137
+ * Some codes carry a `(ref: <uuid>)` suffix, so compare with care —
138
+ * {@link SETTLEMENT_UNCONFIRMED} is emitted bare. Branch on this rather than
139
+ * on the status: `/settle` has two `502`s that mean opposite things.
140
+ */
141
+ errorCode?: string;
142
+ /**
143
+ * The hash of a transaction that WAS broadcast, in that chain's own encoding.
144
+ *
145
+ * Present on {@link SETTLEMENT_UNCONFIRMED}. Not always `0x`-prefixed:
146
+ * Algorand prints base32 and Solana base58, and reformatting it makes it
147
+ * unpasteable in an explorer — which is the entire remedy on offer.
148
+ */
149
+ transaction?: string;
150
+ /** `keccak256(caip2 ‖ txHash)`, the same id a successful settle would print. */
151
+ paymentId?: string;
101
152
  /**
102
153
  * Seconds to wait before retrying, already clamped to
103
154
  * {@link MAX_RETRY_AFTER_SECONDS}. Absent when the answer is not retryable.
@@ -126,6 +177,15 @@ interface FacilitatorFailureFields {
126
177
  status?: number;
127
178
  /** The facilitator's `reason` for the refusal (see {@link WriterLeaseReason}). */
128
179
  reason?: string;
180
+ /** The facilitator's machine-readable `error` code (see {@link FacilitatorErrorInfo.errorCode}). */
181
+ errorCode?: string;
182
+ /**
183
+ * A transaction that WAS broadcast and could not be confirmed. Look it up on
184
+ * chain; do NOT send the payment again. See {@link SETTLEMENT_UNCONFIRMED}.
185
+ */
186
+ transaction?: string;
187
+ /** The payment id for that transaction, identical to the one a settle prints. */
188
+ paymentId?: string;
129
189
  /** True when the same request may be sent again without re-signing anything. */
130
190
  retryable?: boolean;
131
191
  /** Seconds to wait before retrying, clamped to {@link MAX_RETRY_AFTER_SECONDS}. */
@@ -149,6 +209,41 @@ declare function parseRetryAfterSeconds(response: {
149
209
  get?: (name: string) => string | null;
150
210
  };
151
211
  }): number | undefined;
212
+ /** Everything this SDK reads out of a facilitator error body. */
213
+ interface ParsedFacilitatorErrorBody {
214
+ /** The `error` code, verbatim. */
215
+ errorCode?: string;
216
+ /** The writer-lease `reason`. */
217
+ reason?: string;
218
+ /** A broadcast transaction hash, in its own chain's encoding. */
219
+ transaction?: string;
220
+ /** The payment id for that hash. */
221
+ paymentId?: string;
222
+ /**
223
+ * The facilitator's OWN retry verdict, when it stated one.
224
+ *
225
+ * `undefined` on every body that does not carry the field — which is most of
226
+ * them, so absence means "the facilitator did not say", never "no".
227
+ */
228
+ retryable?: boolean;
229
+ }
230
+ /**
231
+ * Read a JSON error body, tolerating anything that is not one.
232
+ *
233
+ * Exported so {@link FacilitatorErrorInfo} and `Erc8004LookupError` read the
234
+ * SAME fields the same way. Two subtly different parses of the same body is how
235
+ * one code path stops honouring a `retryable: false` the other one honours.
236
+ */
237
+ declare function parseFacilitatorErrorBody(body: string): ParsedFacilitatorErrorBody;
238
+ /**
239
+ * This refusal reports a transaction that may already be mined.
240
+ *
241
+ * The caller's move is to look up `transaction` / `paymentId` on chain. Sending
242
+ * the payment again is the double-charge.
243
+ */
244
+ declare function isSettlementUnconfirmed(failure: {
245
+ errorCode?: string;
246
+ }): boolean;
152
247
  /**
153
248
  * Turn a non-2xx facilitator response into {@link FacilitatorErrorInfo}.
154
249
  *
@@ -2118,6 +2213,13 @@ declare class Erc8004LookupError extends Error {
2118
2213
  * `502` and `504` join `503` and `429` here: a gateway that answered on the
2119
2214
  * facilitator's behalf is exactly as silent about the agent's existence, and
2120
2215
  * reading either as absence has the same consequence -- a duplicate mint.
2216
+ *
2217
+ * **Except when the body says otherwise.** `POST /register` goes through the
2218
+ * same EVM `send_transaction_from` as a settle, so it can answer
2219
+ * `settlement_unconfirmed`: the mint was broadcast and may be mined. That is
2220
+ * a `502` where retrying is precisely the thing that mints the duplicate this
2221
+ * class exists to prevent, so an explicit `retryable: false` wins over the
2222
+ * status. See {@link SETTLEMENT_UNCONFIRMED}.
2121
2223
  */
2122
2224
  get retryable(): boolean;
2123
2225
  /**
@@ -2127,6 +2229,18 @@ declare class Erc8004LookupError extends Error {
2127
2229
  * request may be re-sent; see {@link isReplayableLeaseReason}.
2128
2230
  */
2129
2231
  get reason(): string | undefined;
2232
+ /** The facilitator's machine-readable `error` code, when the body carried one. */
2233
+ get errorCode(): string | undefined;
2234
+ /**
2235
+ * A transaction that WAS broadcast and could not be confirmed.
2236
+ *
2237
+ * Present on `settlement_unconfirmed`. This is what to do INSTEAD of
2238
+ * retrying: look it up on chain. An error that carries "do not retry" and no
2239
+ * hash leaves the caller with nothing to act on.
2240
+ */
2241
+ get transaction(): string | undefined;
2242
+ /** The payment id for {@link transaction}, identical to a successful settle's. */
2243
+ get paymentId(): string | undefined;
2130
2244
  /**
2131
2245
  * The facilitator NAMED a reason proving it executed nothing.
2132
2246
  *
@@ -3261,4 +3375,4 @@ declare class AdvancedEscrowClient {
3261
3375
  private sendViaAdapter;
3262
3376
  }
3263
3377
 
3264
- 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 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, 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, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
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 };
@@ -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, h as X402Header, i as X402PayloadData } from '../index-D5uN1cIM.js';
3
3
 
4
4
  /**
5
5
  * Reading a facilitator refusal as DATA instead of prose.
@@ -45,8 +45,34 @@ import { Q as X402Version, x as X402Header, G as X402PayloadData } from '../inde
45
45
  * sequence that once minted five duplicate agents — reconcile with
46
46
  * `GET /identity/{network}/owner/{recipient}` or `getRegisterStatus` instead.
47
47
  *
48
+ * # The two `502`s of `/settle`, which mean opposite things
49
+ *
50
+ * | body `error` | `Retry-After` | did the money move? | retry? |
51
+ * |----------------------------|---------------|---------------------|-----------|
52
+ * | `upstream_rpc_unavailable` | `30` | no, never broadcast | **yes** |
53
+ * | `settlement_unconfirmed` | **absent** | **maybe — mined?** | **NEVER** |
54
+ *
55
+ * `settlement_unconfirmed` is answered after the transaction was broadcast and
56
+ * no receipt ever arrived, so it MAY be mined. Retrying re-signs a new
57
+ * authorization with a fresh nonce, which the chain accepts as a second,
58
+ * perfectly valid payment for the same purchase — the buyer pays twice, in
59
+ * exactly the case the facilitator emits it to prevent. The `transaction` hash
60
+ * and `paymentId` travel in the body so the caller can LOOK AT THE CHAIN; they
61
+ * are not an invitation to send it again.
62
+ *
63
+ * The status cannot tell the two apart, which is why this file used to get it
64
+ * wrong: every `502` was retryable, and until `settlement_unconfirmed` existed
65
+ * that was correct. **Branch on the body.**
66
+ *
67
+ * The general form of that rule — **a 5xx whose body carries a transaction hash
68
+ * was broadcast, whatever the error is called** — is adopted from the Python
69
+ * SDK, which has carried it as its anti-double-settle guard
70
+ * (`uvd_x402_sdk/client.py`, `_is_retryable_settle_error`) while this one had
71
+ * only the status to go on.
72
+ *
48
73
  * Source of the shape: x402-rs `src/handlers.rs` `writer_lease_unavailable()`
49
- * and `require_writer_lease()`.
74
+ * and `require_writer_lease()`; `SettlementUnconfirmedResponse` in
75
+ * `src/types.rs`, built in the `IntoResponse` of `FacilitatorLocalError`.
50
76
  */
51
77
  /**
52
78
  * A `reason` the facilitator attaches to a writer-lease 503.
@@ -72,6 +98,13 @@ declare const REPLAYABLE_LEASE_REASONS: readonly WriterLeaseReason[];
72
98
  * automatically. Resolve it by reading state, not by re-POSTing.
73
99
  */
74
100
  declare const AMBIGUOUS_LEASE_REASONS: readonly WriterLeaseReason[];
101
+ /**
102
+ * The facilitator's `error` code for a settle it broadcast and could not confirm.
103
+ *
104
+ * The transaction may be mined. This is the one upstream failure that must
105
+ * never be retried; reconcile with `transaction` / `paymentId` instead.
106
+ */
107
+ declare const SETTLEMENT_UNCONFIRMED = "settlement_unconfirmed";
75
108
  /**
76
109
  * Ceiling, in seconds, on how long an automatic retry will wait.
77
110
  *
@@ -98,6 +131,24 @@ interface FacilitatorErrorInfo {
98
131
  status: number;
99
132
  /** The facilitator's own `reason`, when the body carried one. */
100
133
  reason?: string;
134
+ /**
135
+ * The facilitator's machine-readable `error` code, verbatim.
136
+ *
137
+ * Some codes carry a `(ref: <uuid>)` suffix, so compare with care —
138
+ * {@link SETTLEMENT_UNCONFIRMED} is emitted bare. Branch on this rather than
139
+ * on the status: `/settle` has two `502`s that mean opposite things.
140
+ */
141
+ errorCode?: string;
142
+ /**
143
+ * The hash of a transaction that WAS broadcast, in that chain's own encoding.
144
+ *
145
+ * Present on {@link SETTLEMENT_UNCONFIRMED}. Not always `0x`-prefixed:
146
+ * Algorand prints base32 and Solana base58, and reformatting it makes it
147
+ * unpasteable in an explorer — which is the entire remedy on offer.
148
+ */
149
+ transaction?: string;
150
+ /** `keccak256(caip2 ‖ txHash)`, the same id a successful settle would print. */
151
+ paymentId?: string;
101
152
  /**
102
153
  * Seconds to wait before retrying, already clamped to
103
154
  * {@link MAX_RETRY_AFTER_SECONDS}. Absent when the answer is not retryable.
@@ -126,6 +177,15 @@ interface FacilitatorFailureFields {
126
177
  status?: number;
127
178
  /** The facilitator's `reason` for the refusal (see {@link WriterLeaseReason}). */
128
179
  reason?: string;
180
+ /** The facilitator's machine-readable `error` code (see {@link FacilitatorErrorInfo.errorCode}). */
181
+ errorCode?: string;
182
+ /**
183
+ * A transaction that WAS broadcast and could not be confirmed. Look it up on
184
+ * chain; do NOT send the payment again. See {@link SETTLEMENT_UNCONFIRMED}.
185
+ */
186
+ transaction?: string;
187
+ /** The payment id for that transaction, identical to the one a settle prints. */
188
+ paymentId?: string;
129
189
  /** True when the same request may be sent again without re-signing anything. */
130
190
  retryable?: boolean;
131
191
  /** Seconds to wait before retrying, clamped to {@link MAX_RETRY_AFTER_SECONDS}. */
@@ -149,6 +209,41 @@ declare function parseRetryAfterSeconds(response: {
149
209
  get?: (name: string) => string | null;
150
210
  };
151
211
  }): number | undefined;
212
+ /** Everything this SDK reads out of a facilitator error body. */
213
+ interface ParsedFacilitatorErrorBody {
214
+ /** The `error` code, verbatim. */
215
+ errorCode?: string;
216
+ /** The writer-lease `reason`. */
217
+ reason?: string;
218
+ /** A broadcast transaction hash, in its own chain's encoding. */
219
+ transaction?: string;
220
+ /** The payment id for that hash. */
221
+ paymentId?: string;
222
+ /**
223
+ * The facilitator's OWN retry verdict, when it stated one.
224
+ *
225
+ * `undefined` on every body that does not carry the field — which is most of
226
+ * them, so absence means "the facilitator did not say", never "no".
227
+ */
228
+ retryable?: boolean;
229
+ }
230
+ /**
231
+ * Read a JSON error body, tolerating anything that is not one.
232
+ *
233
+ * Exported so {@link FacilitatorErrorInfo} and `Erc8004LookupError` read the
234
+ * SAME fields the same way. Two subtly different parses of the same body is how
235
+ * one code path stops honouring a `retryable: false` the other one honours.
236
+ */
237
+ declare function parseFacilitatorErrorBody(body: string): ParsedFacilitatorErrorBody;
238
+ /**
239
+ * This refusal reports a transaction that may already be mined.
240
+ *
241
+ * The caller's move is to look up `transaction` / `paymentId` on chain. Sending
242
+ * the payment again is the double-charge.
243
+ */
244
+ declare function isSettlementUnconfirmed(failure: {
245
+ errorCode?: string;
246
+ }): boolean;
152
247
  /**
153
248
  * Turn a non-2xx facilitator response into {@link FacilitatorErrorInfo}.
154
249
  *
@@ -2118,6 +2213,13 @@ declare class Erc8004LookupError extends Error {
2118
2213
  * `502` and `504` join `503` and `429` here: a gateway that answered on the
2119
2214
  * facilitator's behalf is exactly as silent about the agent's existence, and
2120
2215
  * reading either as absence has the same consequence -- a duplicate mint.
2216
+ *
2217
+ * **Except when the body says otherwise.** `POST /register` goes through the
2218
+ * same EVM `send_transaction_from` as a settle, so it can answer
2219
+ * `settlement_unconfirmed`: the mint was broadcast and may be mined. That is
2220
+ * a `502` where retrying is precisely the thing that mints the duplicate this
2221
+ * class exists to prevent, so an explicit `retryable: false` wins over the
2222
+ * status. See {@link SETTLEMENT_UNCONFIRMED}.
2121
2223
  */
2122
2224
  get retryable(): boolean;
2123
2225
  /**
@@ -2127,6 +2229,18 @@ declare class Erc8004LookupError extends Error {
2127
2229
  * request may be re-sent; see {@link isReplayableLeaseReason}.
2128
2230
  */
2129
2231
  get reason(): string | undefined;
2232
+ /** The facilitator's machine-readable `error` code, when the body carried one. */
2233
+ get errorCode(): string | undefined;
2234
+ /**
2235
+ * A transaction that WAS broadcast and could not be confirmed.
2236
+ *
2237
+ * Present on `settlement_unconfirmed`. This is what to do INSTEAD of
2238
+ * retrying: look it up on chain. An error that carries "do not retry" and no
2239
+ * hash leaves the caller with nothing to act on.
2240
+ */
2241
+ get transaction(): string | undefined;
2242
+ /** The payment id for {@link transaction}, identical to a successful settle's. */
2243
+ get paymentId(): string | undefined;
2130
2244
  /**
2131
2245
  * The facilitator NAMED a reason proving it executed nothing.
2132
2246
  *
@@ -3261,4 +3375,4 @@ declare class AdvancedEscrowClient {
3261
3375
  private sendViaAdapter;
3262
3376
  }
3263
3377
 
3264
- 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 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, 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, parsePaymentHeader, parseRetryAfterSeconds, readFacilitatorError, resolveEnvelopeVersion, supportsRelayedFeedback, toPaymentRequirementsV2, toResourceInfoV2, wireNetwork };
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 };