uvd-x402-sdk 2.104.0 → 2.104.2

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 (97) hide show
  1. package/README.md +88 -1
  2. package/dist/adapters/index.d.mts +1 -1
  3. package/dist/adapters/index.d.ts +1 -1
  4. package/dist/adapters/index.js +3 -0
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/index.mjs +3 -0
  7. package/dist/adapters/index.mjs.map +1 -1
  8. package/dist/backend/index.d.mts +3 -3
  9. package/dist/backend/index.d.ts +3 -3
  10. package/dist/backend/index.js +764 -25
  11. package/dist/backend/index.js.map +1 -1
  12. package/dist/backend/index.mjs +764 -27
  13. package/dist/backend/index.mjs.map +1 -1
  14. package/dist/{escrow-contracts-C59jszp3.d.ts → escrow-contracts-Bf3PU_Ub.d.ts} +496 -4
  15. package/dist/{escrow-contracts-Dgcyu7Fh.d.mts → escrow-contracts-amyDktMD.d.mts} +496 -4
  16. package/dist/{index-QswKm6BF.d.ts → index-CZHgEr58.d.ts} +2 -2
  17. package/dist/{index-DagQ74ZQ.d.ts → index-DARXHuQl.d.mts} +1 -1
  18. package/dist/{index-DagQ74ZQ.d.mts → index-DARXHuQl.d.ts} +1 -1
  19. package/dist/{index-CS4qStqy.d.mts → index-jNJd8jEb.d.mts} +2 -2
  20. package/dist/index.d.mts +41 -434
  21. package/dist/index.d.ts +41 -434
  22. package/dist/index.js +541 -39
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +539 -40
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/providers/algorand/index.d.mts +1 -1
  27. package/dist/providers/algorand/index.d.ts +1 -1
  28. package/dist/providers/algorand/index.js +3 -0
  29. package/dist/providers/algorand/index.js.map +1 -1
  30. package/dist/providers/algorand/index.mjs +3 -0
  31. package/dist/providers/algorand/index.mjs.map +1 -1
  32. package/dist/providers/evm/index.d.mts +1 -1
  33. package/dist/providers/evm/index.d.ts +1 -1
  34. package/dist/providers/evm/index.js +3 -0
  35. package/dist/providers/evm/index.js.map +1 -1
  36. package/dist/providers/evm/index.mjs +3 -0
  37. package/dist/providers/evm/index.mjs.map +1 -1
  38. package/dist/providers/hedera/index.d.mts +1 -1
  39. package/dist/providers/hedera/index.d.ts +1 -1
  40. package/dist/providers/near/index.d.mts +1 -1
  41. package/dist/providers/near/index.d.ts +1 -1
  42. package/dist/providers/near/index.js +3 -0
  43. package/dist/providers/near/index.js.map +1 -1
  44. package/dist/providers/near/index.mjs +3 -0
  45. package/dist/providers/near/index.mjs.map +1 -1
  46. package/dist/providers/solana/index.d.mts +1 -1
  47. package/dist/providers/solana/index.d.ts +1 -1
  48. package/dist/providers/solana/index.js +3 -0
  49. package/dist/providers/solana/index.js.map +1 -1
  50. package/dist/providers/solana/index.mjs +3 -0
  51. package/dist/providers/solana/index.mjs.map +1 -1
  52. package/dist/providers/stellar/index.d.mts +1 -1
  53. package/dist/providers/stellar/index.d.ts +1 -1
  54. package/dist/providers/stellar/index.js +3 -0
  55. package/dist/providers/stellar/index.js.map +1 -1
  56. package/dist/providers/stellar/index.mjs +3 -0
  57. package/dist/providers/stellar/index.mjs.map +1 -1
  58. package/dist/providers/sui/index.d.mts +1 -1
  59. package/dist/providers/sui/index.d.ts +1 -1
  60. package/dist/providers/sui/index.js +3 -0
  61. package/dist/providers/sui/index.js.map +1 -1
  62. package/dist/providers/sui/index.mjs +3 -0
  63. package/dist/providers/sui/index.mjs.map +1 -1
  64. package/dist/providers/xrpl/index.d.mts +1 -1
  65. package/dist/providers/xrpl/index.d.ts +1 -1
  66. package/dist/providers/xrpl/index.js +3 -0
  67. package/dist/providers/xrpl/index.js.map +1 -1
  68. package/dist/providers/xrpl/index.mjs +3 -0
  69. package/dist/providers/xrpl/index.mjs.map +1 -1
  70. package/dist/react/index.d.mts +4 -4
  71. package/dist/react/index.d.ts +4 -4
  72. package/dist/react/index.js +3 -0
  73. package/dist/react/index.js.map +1 -1
  74. package/dist/react/index.mjs +3 -0
  75. package/dist/react/index.mjs.map +1 -1
  76. package/dist/react/picker/index.d.mts +1 -1
  77. package/dist/react/picker/index.d.ts +1 -1
  78. package/dist/react/picker/index.js.map +1 -1
  79. package/dist/react/picker/index.mjs.map +1 -1
  80. package/dist/{receipts-8XsMeo1y.d.ts → receipts-CMuWVtO0.d.ts} +1 -1
  81. package/dist/{receipts-COPJ_BY9.d.mts → receipts-DsOSK0yB.d.mts} +1 -1
  82. package/dist/utils/index.d.mts +2 -2
  83. package/dist/utils/index.d.ts +2 -2
  84. package/dist/utils/index.js +3 -0
  85. package/dist/utils/index.js.map +1 -1
  86. package/dist/utils/index.mjs +3 -0
  87. package/dist/utils/index.mjs.map +1 -1
  88. package/dist/{validity-BpwXbfdj.d.ts → validity-BshzF_Ga.d.ts} +1 -1
  89. package/dist/{validity-eGGXxzpi.d.mts → validity-y_M1oNCt.d.mts} +1 -1
  90. package/package.json +1 -1
  91. package/src/backend/durable.ts +582 -0
  92. package/src/backend/index.ts +149 -5
  93. package/src/chains/index.ts +4 -1
  94. package/src/escrow-contracts.ts +1 -1
  95. package/src/escrow-preauth.ts +99 -58
  96. package/src/fixtures/escrow-operator-snapshot.json +3 -2
  97. package/src/index.ts +8 -0
package/README.md CHANGED
@@ -684,7 +684,7 @@ const paymentAuth = await buildEscrowPreAuth(new EnvKeyAdapter(), {
684
684
  // Send as the X-Payment-Auth header (raw JSON, NOT base64).
685
685
  ```
686
686
 
687
- Any `SigningWalletAdapter` works as the signer (only `signTypedData` is used); browser wallets can pass a minimal `{ signTypedData }` wrapper. Validation fails loud instead of falling back: incomplete network config, unknown tier, bounty outside the on-chain deposit limit ($100), or a `maxFeeBps` below the operator's 1300 bps all throw before anything is signed. What the config asserts is also checked against the SDK's own tables before signing, as in the Python SDK: the `chain_id` against the `network` you name (a registry name or `eip155:<id>`), the escrow, token collector and USDC against `ESCROW_CONTRACTS`, the operator against `ESCROW_OPERATORS`, and `maxFeeBps` against the chain's ceiling in `ESCROW_MAX_FEE_BPS`. A contradiction throws `INVALID_CONFIG`, and so do a `network` the SDK does not register and a chain without a row in each of the three tables, with or without `network`; name the network you expect to pay on, from your own code, never one read from the config. A server-published tier window must be an integer from 0 to its `ESCROW_TIER_WINDOW_MAX`, and `authorizationExpiry` at most `ESCROW_MAX_AUTHORIZATION_SEC` after now: past either, the SDK refuses, it never clamps. `computeEscrowNonce` is exported to reproduce `AuthCaptureEscrow.getHash` externally.
687
+ Any `SigningWalletAdapter` works as the signer (only `signTypedData` is used); browser wallets can pass a minimal `{ signTypedData }` wrapper. Validation fails loud instead of falling back: incomplete network config, unknown tier, bounty outside the on-chain deposit limit ($100), or a `maxFeeBps` below the operator's 1300 bps all throw before anything is signed. What the config asserts is also checked against the SDK's own tables before signing, as in the Python SDK: the `chain_id` against the `network` you name (a registry name or `eip155:<id>`), the escrow, token collector and USDC against `ESCROW_CONTRACTS`, the operator against `ESCROW_OPERATORS`, `maxFeeBps` against the chain's ceiling in `ESCROW_MAX_FEE_BPS`, and the USDC EIP-712 domain (`usdc_domain_name` / `usdc_domain_version`) against the token's on-chain domain in `VERIFIED_USDC_DOMAINS`. A contradiction throws `INVALID_CONFIG`, and so do a `network` the SDK does not register and a chain without a row in each of the four tables, with or without `network`; name the network you expect to pay on, from your own code, never one read from the config. A server-published tier window must be an integer from 0 to its `ESCROW_TIER_WINDOW_MAX`, and `authorizationExpiry` at most `ESCROW_MAX_AUTHORIZATION_SEC` after now: past either, the SDK refuses, it never clamps. `computeEscrowNonce` is exported to reproduce `AuthCaptureEscrow.getHash` externally.
688
688
 
689
689
  ## Multi-Stablecoin (EVM)
690
690
 
@@ -889,6 +889,8 @@ app.post('/api/premium', async (req, res) => {
889
889
  });
890
890
  ```
891
891
 
892
+ To be listed in the facilitator's Bazaar after a paid call, flag the accepts as discoverable: `discoverable: true` in the options of `createHonoMiddleware()` or `createFetchPaywall()` writes `extra.discoverable: true` on every accept, in the 402 and in the requirements sent to `/verify` and `/settle`; the other `extra` fields (`name`, `version`) stay. `false` writes `discoverable: false`, overriding a hand-written `true`, as the Python SDK's `False` does (for the facilitator, `false` and no flag both mean "not listed"); without the option the accepts go out as given. Native Hedera accepts go out as given with either value: the facilitator allows only `feePayer` in their `extra`, so a Hedera settle is never listed. For one accept, or for `create402Response`, use `withDiscoverable(accept)` (`withDiscoverable(accept, false)` to opt out); it throws for a native Hedera accept. Neither modifies the object it is given. A `discoverable` that is not a boolean and an `extra` that is not a plain object throw when the paywall is built, before any request.
893
+
892
894
  `createPaymentMiddleware()`, `createHonoMiddleware()` and `createFetchPaywall()` verify and settle automatically by default (`before-handler`). Use `settlementStrategy: 'manual'` if you need to control when settlement happens (e.g., settle only after confirming you can fulfill the request).
893
895
 
894
896
  A buyer in a browser on another origin reads the terms of a v2 402, in the `PAYMENT-REQUIRED` header, only if the app's CORS exposes that header: list it in `Access-Control-Expose-Headers` (with `hono/cors`, `exposeHeaders: ['PAYMENT-REQUIRED']`) and send `Access-Control-Allow-Origin`. The 402 of `createHonoMiddleware` and `createFetchPaywall` sets no CORS header of its own; `create402Response` lists the header in its `headers` but sets no `Access-Control-Allow-Origin` (spread `getCorsHeaders(origin)` too).
@@ -2050,6 +2052,91 @@ const result = await anchorEvidence(body, {
2050
2052
  res.setHeader('X-Durable-Evidence', evidenceHeader(result));
2051
2053
  ```
2052
2054
 
2055
+ ### Seller: from the paywall itself (`durable`)
2056
+
2057
+ `createFetchPaywall`, `createHonoMiddleware` and `createPaymentMiddleware`
2058
+ (Express) take an opt-in `durable`. With it, a paid `2xx` answer that the
2059
+ handler did not anchor itself is captured once, sealed and anchored through
2060
+ `anchorEvidence`, and goes out with `X-Durable-Evidence`:
2061
+
2062
+ ```ts
2063
+ import { TypedDataEncoder, getBytes } from 'ethers';
2064
+ import { createFetchPaywall, type DurableEvidenceContext } from 'uvd-x402-sdk/backend';
2065
+ import { caip2ToChain, getChainByName, payerKeyFromEvmSignature } from 'uvd-x402-sdk';
2066
+
2067
+ const TRANSFER_WITH_AUTHORIZATION = {
2068
+ TransferWithAuthorization: [
2069
+ { name: 'from', type: 'address' }, { name: 'to', type: 'address' },
2070
+ { name: 'value', type: 'uint256' }, { name: 'validAfter', type: 'uint256' },
2071
+ { name: 'validBefore', type: 'uint256' }, { name: 'nonce', type: 'bytes32' },
2072
+ ],
2073
+ };
2074
+
2075
+ // The key behind an EIP-3009 USDC payment: recovered from the signature over the
2076
+ // digest the buyer signed, with the token domain of the chain registry.
2077
+ const evmPayerKey = ({ payment }: DurableEvidenceContext) => {
2078
+ const payload = payment.payment.payload;
2079
+ if (!('authorization' in payload)) return undefined; // not an EVM payment: skipped
2080
+ const network = payment.requirements.network;
2081
+ const chain = getChainByName(caip2ToChain(network) ?? network);
2082
+ if (!chain) return undefined;
2083
+ const digest = TypedDataEncoder.hash(
2084
+ { name: chain.usdc.name, version: chain.usdc.version, chainId: chain.chainId, verifyingContract: payment.requirements.asset },
2085
+ TRANSFER_WITH_AUTHORIZATION,
2086
+ payload.authorization,
2087
+ );
2088
+ return payerKeyFromEvmSignature(payload.signature, getBytes(digest));
2089
+ };
2090
+
2091
+ const paywall = createFetchPaywall({
2092
+ accepts,
2093
+ durable: {
2094
+ payerKey: evmPayerKey, // Solana: ({ payment }) => payerKeyFromSolanaAddress(payment.verifyResult.payer!)
2095
+ maxBodyBytes: 64 * 1024, // default ANCHOR_MAX_REQUEST_BYTES
2096
+ timeoutMs: 5000, // default DURABLE_DEFAULT_TIMEOUT_MS
2097
+ },
2098
+ });
2099
+ ```
2100
+
2101
+ A wrong digest does not throw: it recovers another valid key, and the evidence
2102
+ would be sealed to it. `src/backend/durable-evidence.test.ts` checks this
2103
+ derivation against a signature made with a synthetic key.
2104
+
2105
+ Without `durable` nothing changes and nothing is anchored. It anchors only a
2106
+ payment this request settled with a transaction hash (`'manual'`: once
2107
+ `x402.settle()` resolved successfully before the answer); a replayed settle, or
2108
+ one whose receipt is `pending`, `unknown` or `rejected`, is not anchored. The body is read once
2109
+ and held at most `maxBodyBytes`; past that, past `timeoutMs`, for an event
2110
+ stream, for a body already locked or read, or when the handler's own stream
2111
+ fails, the response goes out whole and unchanged except for a skip notice in
2112
+ the header, and nothing is anchored. A failed anchor is a skip notice too: the
2113
+ response and the payment stand. A `HEAD`, a non-`2xx` answer and a response that
2114
+ already has `X-Durable-Evidence` are left alone. Every field of `durable` but
2115
+ `payerKey`, `maxBodyBytes` and `timeoutMs` is the `anchorEvidence` option of the
2116
+ same name; `facilitator` defaults to the paywall's facilitator.
2117
+
2118
+ The skip notices the paywall adds, besides those of `anchorEvidence`:
2119
+
2120
+ | `skipped` | When |
2121
+ |---|---|
2122
+ | `no_payer_key` | `payerKey` returned `undefined` or an empty key, or threw |
2123
+ | `too_large` | the body is over `maxBodyBytes` (declared or read) |
2124
+ | `not_capturable` | an event stream, a body already sent, a chunk that is not bytes, or a handler stream that failed |
2125
+ | `timeout` | capture, `payerKey`, upload or anchor did not finish within `timeoutMs` |
2126
+ | `anchor_failed` | the anchor failed |
2127
+
2128
+ In Express, the answer is held from the handler's `end()` until the anchor
2129
+ returns (at most `timeoutMs`). In that window `res.headersSent` and
2130
+ `res.writableEnded` are `true`, a further `write()` is refused as a write after
2131
+ end, a further `end()` only queues its callback, and headers can no longer be
2132
+ set: the paid answer goes out as the handler ended it. A close the server asks
2133
+ for in that window without an error (`res.destroy()` or `req.socket.destroy()`,
2134
+ which is what Express's final handler does on an error once headers are sent)
2135
+ waits until the body is written and then closes the connection. A close with an
2136
+ error, or one once the connection can no longer write, is not held. A client
2137
+ that hangs up its side during the window does not get the body: the window
2138
+ lengthens (up to `timeoutMs`) the time in which that happens.
2139
+
2053
2140
  **It never throws.** Every failure resolves to `result.skipped`, because
2054
2141
  evidence is an addition to the payment path and must never be a gate in front of
2055
2142
  it. An unreachable facilitator costs the receipt, never the sale.
@@ -1,4 +1,4 @@
1
- import { X as X402Version, a as PaymentResult } from '../index-DagQ74ZQ.mjs';
1
+ import { X as X402Version, a as PaymentResult } from '../index-DARXHuQl.mjs';
2
2
  export { E as EnvKeyAdapter, O as OWSAccountInfo, a as OWSCore, b as OWSSignResult, c as OWSWallet, d as OWSWalletAdapter, e as OWSWalletAdapterOptions } from '../ows-DazT4KQH.mjs';
3
3
  import '../wallet-T0NFUUkT.mjs';
4
4
  import 'ethers';
@@ -1,4 +1,4 @@
1
- import { X as X402Version, a as PaymentResult } from '../index-DagQ74ZQ.js';
1
+ import { X as X402Version, a as PaymentResult } from '../index-DARXHuQl.js';
2
2
  export { E as EnvKeyAdapter, O as OWSAccountInfo, a as OWSCore, b as OWSSignResult, c as OWSWallet, d as OWSWalletAdapter, e as OWSWalletAdapterOptions } from '../ows-BB6Sgj0W.js';
3
3
  import '../wallet-T0NFUUkT.js';
4
4
  import 'ethers';
@@ -1126,6 +1126,9 @@ var SUPPORTED_CHAINS = {
1126
1126
  var CHAIN_ALIASES = {
1127
1127
  hedera: "hedera:mainnet",
1128
1128
  "hedera-testnet": "hedera:testnet",
1129
+ // Execution Market's and Karmakadabra's keys for SKALE Base.
1130
+ skale: "skale-base",
1131
+ "skale-testnet": "skale-base-sepolia",
1129
1132
  // Renamed in 2.85.0: the facilitator advertises the mainnet as `xrpl`.
1130
1133
  "xrpl-mainnet": "xrpl"
1131
1134
  };