uvd-x402-sdk 2.89.0 → 2.91.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 (77) hide show
  1. package/README.md +32 -0
  2. package/dist/adapters/index.d.mts +1 -1
  3. package/dist/adapters/index.d.ts +1 -1
  4. package/dist/adapters/index.js.map +1 -1
  5. package/dist/adapters/index.mjs.map +1 -1
  6. package/dist/backend/index.d.mts +2 -2
  7. package/dist/backend/index.d.ts +2 -2
  8. package/dist/backend/index.js.map +1 -1
  9. package/dist/backend/index.mjs.map +1 -1
  10. package/dist/erc8128/index.js.map +1 -1
  11. package/dist/erc8128/index.mjs.map +1 -1
  12. package/dist/{index-13ZUDF7c.d.mts → index-DAC3DRdT.d.mts} +1 -1
  13. package/dist/{index-B5B9EK3x.d.ts → index-DRSEcZ36.d.ts} +1 -1
  14. package/dist/{index-CAJg-_cr.d.mts → index-DRk6i654.d.mts} +1 -1
  15. package/dist/{index-BWN0Haa0.d.mts → index-DbauIMV2.d.mts} +41 -0
  16. package/dist/{index-BWN0Haa0.d.ts → index-DbauIMV2.d.ts} +41 -0
  17. package/dist/{index-Cd1Mpznb.d.ts → index-s6ot_Mu-.d.ts} +1 -1
  18. package/dist/index.d.mts +4 -4
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +43 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +42 -3
  23. package/dist/index.mjs.map +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/algorand/index.js.map +1 -1
  27. package/dist/providers/algorand/index.mjs.map +1 -1
  28. package/dist/providers/evm/index.d.mts +1 -1
  29. package/dist/providers/evm/index.d.ts +1 -1
  30. package/dist/providers/evm/index.js +23 -1
  31. package/dist/providers/evm/index.js.map +1 -1
  32. package/dist/providers/evm/index.mjs +23 -1
  33. package/dist/providers/evm/index.mjs.map +1 -1
  34. package/dist/providers/near/index.d.mts +1 -1
  35. package/dist/providers/near/index.d.ts +1 -1
  36. package/dist/providers/near/index.js.map +1 -1
  37. package/dist/providers/near/index.mjs.map +1 -1
  38. package/dist/providers/solana/index.d.mts +1 -1
  39. package/dist/providers/solana/index.d.ts +1 -1
  40. package/dist/providers/solana/index.js.map +1 -1
  41. package/dist/providers/solana/index.mjs.map +1 -1
  42. package/dist/providers/stellar/index.d.mts +1 -1
  43. package/dist/providers/stellar/index.d.ts +1 -1
  44. package/dist/providers/stellar/index.js.map +1 -1
  45. package/dist/providers/stellar/index.mjs.map +1 -1
  46. package/dist/providers/sui/index.d.mts +1 -1
  47. package/dist/providers/sui/index.d.ts +1 -1
  48. package/dist/providers/sui/index.js.map +1 -1
  49. package/dist/providers/sui/index.mjs.map +1 -1
  50. package/dist/providers/xrpl/index.d.mts +1 -1
  51. package/dist/providers/xrpl/index.d.ts +1 -1
  52. package/dist/providers/xrpl/index.js.map +1 -1
  53. package/dist/providers/xrpl/index.mjs.map +1 -1
  54. package/dist/react/index.d.mts +3 -3
  55. package/dist/react/index.d.ts +3 -3
  56. package/dist/react/index.js +44 -5
  57. package/dist/react/index.js.map +1 -1
  58. package/dist/react/index.mjs +44 -5
  59. package/dist/react/index.mjs.map +1 -1
  60. package/dist/react/picker/index.d.mts +1 -1
  61. package/dist/react/picker/index.d.ts +1 -1
  62. package/dist/utils/index.d.mts +2 -2
  63. package/dist/utils/index.d.ts +2 -2
  64. package/dist/utils/index.js +29 -0
  65. package/dist/utils/index.js.map +1 -1
  66. package/dist/utils/index.mjs +26 -1
  67. package/dist/utils/index.mjs.map +1 -1
  68. package/dist/{validation-B95g0MqC.d.mts → validity-BTMBMmuj.d.mts} +101 -2
  69. package/dist/{validation-_Tcjm2gu.d.ts → validity-C0z0GqH6.d.ts} +101 -2
  70. package/package.json +1 -1
  71. package/src/client/X402Client.ts +32 -2
  72. package/src/index.ts +5 -0
  73. package/src/providers/evm/index.ts +4 -2
  74. package/src/react/index.tsx +8 -3
  75. package/src/types/index.ts +41 -0
  76. package/src/utils/index.ts +7 -0
  77. package/src/utils/validity.ts +135 -0
@@ -1,8 +1,8 @@
1
- import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-BWN0Haa0.mjs';
2
- export { d as WalletState } from '../index-BWN0Haa0.mjs';
1
+ import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-DbauIMV2.mjs';
2
+ export { d as WalletState } from '../index-DbauIMV2.mjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
- import { g as getChainByName, X as X402Client } from '../index-13ZUDF7c.mjs';
5
+ import { g as getChainByName, X as X402Client } from '../index-DAC3DRdT.mjs';
6
6
  export { FAMILY_LABEL, NetworkOption, NetworkPicker, NetworkPickerProps, SIGNABLE_IN_BROWSER, buildNetworkOptions, resolveChain } from './picker/index.mjs';
7
7
 
8
8
  /** One entry of the `accepts` array of a 402 response. */
@@ -1,8 +1,8 @@
1
- import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-BWN0Haa0.js';
2
- export { d as WalletState } from '../index-BWN0Haa0.js';
1
+ import { P as PaymentInfo, a as PaymentResult, N as NetworkType, b as X402ClientConfig, C as ChainConfig, c as NetworkBalance } from '../index-DbauIMV2.js';
2
+ export { d as WalletState } from '../index-DbauIMV2.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
- import { g as getChainByName, X as X402Client } from '../index-B5B9EK3x.js';
5
+ import { g as getChainByName, X as X402Client } from '../index-DRSEcZ36.js';
6
6
  export { FAMILY_LABEL, NetworkOption, NetworkPicker, NetworkPickerProps, SIGNABLE_IN_BROWSER, buildNetworkOptions, resolveChain } from './picker/index.js';
7
7
 
8
8
  /** One entry of the `accepts` array of a 402 response. */
@@ -1273,6 +1273,37 @@ var init_personal_sign = __esm({
1273
1273
  }
1274
1274
  });
1275
1275
 
1276
+ // src/utils/validity.ts
1277
+ function resolveValiditySeconds(perPayment, clientDefault) {
1278
+ const chosen = perPayment ?? clientDefault ?? DEFAULT_VALIDITY_SECONDS;
1279
+ if (!Number.isInteger(chosen) || chosen <= 0) {
1280
+ throw new X402Error(
1281
+ `validitySeconds must be a positive whole number of seconds, got ${String(chosen)}`,
1282
+ "INVALID_CONFIG",
1283
+ { validitySeconds: chosen }
1284
+ );
1285
+ }
1286
+ if (chosen > MAX_VALIDITY_SECONDS) {
1287
+ throw new X402Error(
1288
+ `validitySeconds must be at most ${MAX_VALIDITY_SECONDS} seconds, got ${String(chosen)}. A longer window is a standing claim on the payer: it can be settled long after the payer gave the payment up for expired.`,
1289
+ "INVALID_CONFIG",
1290
+ { validitySeconds: chosen, max: MAX_VALIDITY_SECONDS }
1291
+ );
1292
+ }
1293
+ return chosen;
1294
+ }
1295
+ function clampValiditySeconds(maxTimeoutSeconds) {
1296
+ return Math.min(MAX_VALIDITY_SECONDS, Math.max(1, Math.floor(maxTimeoutSeconds)));
1297
+ }
1298
+ var DEFAULT_VALIDITY_SECONDS, MAX_VALIDITY_SECONDS;
1299
+ var init_validity = __esm({
1300
+ "src/utils/validity.ts"() {
1301
+ init_types();
1302
+ DEFAULT_VALIDITY_SECONDS = 300;
1303
+ MAX_VALIDITY_SECONDS = 3600;
1304
+ }
1305
+ });
1306
+
1276
1307
  // src/utils/index.ts
1277
1308
  var init_utils = __esm({
1278
1309
  "src/utils/index.ts"() {
@@ -1281,6 +1312,7 @@ var init_utils = __esm({
1281
1312
  init_base64();
1282
1313
  init_validation();
1283
1314
  init_personal_sign();
1315
+ init_validity();
1284
1316
  }
1285
1317
  });
1286
1318
 
@@ -2022,6 +2054,7 @@ var X402Client = class _X402Client {
2022
2054
  */
2023
2055
  purchasePolicy;
2024
2056
  constructor(config = {}) {
2057
+ resolveValiditySeconds(void 0, config.validitySeconds);
2025
2058
  this.config = {
2026
2059
  ...DEFAULT_CONFIG,
2027
2060
  ...config
@@ -2349,7 +2382,8 @@ var X402Client = class _X402Client {
2349
2382
  amount: ethers.ethers.formatUnits(chosen.amount, chosen.decimals),
2350
2383
  tokenType,
2351
2384
  network: chosen.chainName,
2352
- x402Version: version
2385
+ x402Version: version,
2386
+ validitySeconds: chosen.maxTimeoutSeconds !== void 0 ? clampValiditySeconds(chosen.maxTimeoutSeconds) : void 0
2353
2387
  });
2354
2388
  const paidHeaders = {
2355
2389
  ..._X402Client.headersToRecord(options.init?.headers),
@@ -2423,6 +2457,7 @@ var X402Client = class _X402Client {
2423
2457
  continue;
2424
2458
  }
2425
2459
  const chainName = getChainByName(network) ? network : caip2ToChain(network);
2460
+ const declaredTimeout = typeof accept.maxTimeoutSeconds === "number" && Number.isFinite(accept.maxTimeoutSeconds) ? accept.maxTimeoutSeconds : void 0;
2426
2461
  offers.push({
2427
2462
  network,
2428
2463
  chainName,
@@ -2430,6 +2465,7 @@ var X402Client = class _X402Client {
2430
2465
  amount: String(amount),
2431
2466
  decimals: _X402Client.offerDecimals(chainName, tokenType),
2432
2467
  payTo,
2468
+ ...declaredTimeout !== void 0 ? { maxTimeoutSeconds: declaredTimeout } : {},
2433
2469
  raw: accept
2434
2470
  });
2435
2471
  }
@@ -2729,7 +2765,10 @@ var X402Client = class _X402Client {
2729
2765
  }
2730
2766
  const nonce = ethers.ethers.hexlify(nonceBytes);
2731
2767
  const validAfter = 0;
2732
- const validityWindowSeconds = chain.name === "base" ? 300 : 60;
2768
+ const validityWindowSeconds = resolveValiditySeconds(
2769
+ paymentInfo.validitySeconds,
2770
+ this.config.validitySeconds
2771
+ );
2733
2772
  const validBefore = Math.floor(Date.now() / 1e3) + validityWindowSeconds;
2734
2773
  const domain = {
2735
2774
  name: token.name,
@@ -3251,13 +3290,13 @@ function useBalance() {
3251
3290
  };
3252
3291
  }
3253
3292
  function usePayment() {
3254
- const { client, isConnected } = useX402();
3293
+ const { client } = useX402();
3255
3294
  const [isPaying, setIsPaying] = react.useState(false);
3256
3295
  const [error, setError] = react.useState(null);
3257
3296
  const [lastResult, setLastResult] = react.useState(null);
3258
3297
  const pay = react.useCallback(
3259
3298
  async (paymentInfo) => {
3260
- if (!isConnected) {
3299
+ if (!client.getState().connected) {
3261
3300
  throw new Error("Wallet not connected");
3262
3301
  }
3263
3302
  setIsPaying(true);
@@ -3274,7 +3313,7 @@ function usePayment() {
3274
3313
  setIsPaying(false);
3275
3314
  }
3276
3315
  },
3277
- [client, isConnected]
3316
+ [client]
3278
3317
  );
3279
3318
  const reset = react.useCallback(() => {
3280
3319
  setError(null);