uvd-x402-sdk 2.101.0 → 2.102.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 (49) hide show
  1. package/dist/adapters/index.d.mts +1 -1
  2. package/dist/adapters/index.d.ts +1 -1
  3. package/dist/adapters/index.js +117 -9
  4. package/dist/adapters/index.js.map +1 -1
  5. package/dist/adapters/index.mjs +117 -9
  6. package/dist/adapters/index.mjs.map +1 -1
  7. package/dist/backend/index.d.mts +1 -1
  8. package/dist/backend/index.d.ts +1 -1
  9. package/dist/backend/index.js +182 -57
  10. package/dist/backend/index.js.map +1 -1
  11. package/dist/backend/index.mjs +182 -57
  12. package/dist/backend/index.mjs.map +1 -1
  13. package/dist/{index-Bc91DzIt.d.mts → index-DKUUBqZO.d.mts} +8 -3
  14. package/dist/{index-49h53dGB.d.ts → index-Di8sCYHx.d.ts} +8 -3
  15. package/dist/index.d.mts +8 -3
  16. package/dist/index.d.ts +8 -3
  17. package/dist/index.js +202 -56
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +202 -56
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/{ows-Tt33WE0s.d.ts → ows-BB6Sgj0W.d.ts} +3 -0
  22. package/dist/{ows-9uNT7ZSZ.d.mts → ows-DazT4KQH.d.mts} +3 -0
  23. package/dist/providers/evm/index.js +31 -1
  24. package/dist/providers/evm/index.js.map +1 -1
  25. package/dist/providers/evm/index.mjs +31 -1
  26. package/dist/providers/evm/index.mjs.map +1 -1
  27. package/dist/providers/stellar/index.js +28 -0
  28. package/dist/providers/stellar/index.js.map +1 -1
  29. package/dist/providers/stellar/index.mjs +28 -0
  30. package/dist/providers/stellar/index.mjs.map +1 -1
  31. package/dist/providers/sui/index.js +27 -0
  32. package/dist/providers/sui/index.js.map +1 -1
  33. package/dist/providers/sui/index.mjs +27 -0
  34. package/dist/providers/sui/index.mjs.map +1 -1
  35. package/dist/react/index.js +49 -4
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/react/index.mjs +49 -4
  38. package/dist/react/index.mjs.map +1 -1
  39. package/package.json +1 -1
  40. package/src/adapters/env-key.ts +5 -1
  41. package/src/adapters/ows.ts +3 -0
  42. package/src/backend/index.ts +36 -8
  43. package/src/client/X402Client.ts +23 -3
  44. package/src/escrow-preauth.ts +32 -4
  45. package/src/lifecycle-auth.ts +37 -31
  46. package/src/providers/evm/index.ts +9 -1
  47. package/src/providers/stellar/index.ts +5 -0
  48. package/src/providers/sui/index.ts +4 -0
  49. package/src/utils/uint.ts +252 -0
@@ -1,5 +1,5 @@
1
1
  import { X as X402Version, a as PaymentResult } from '../index-DagQ74ZQ.mjs';
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-9uNT7ZSZ.mjs';
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';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { X as X402Version, a as PaymentResult } from '../index-DagQ74ZQ.js';
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-Tt33WE0s.js';
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';
5
5
 
@@ -1443,6 +1443,110 @@ function useX402Wagmi(walletClient) {
1443
1443
  createPaymentFull
1444
1444
  };
1445
1445
  }
1446
+ var INTEGER_TYPE = /^u?int\d*$/;
1447
+ function isRecord(value) {
1448
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1449
+ }
1450
+ function inexactNumberMessage(field, value) {
1451
+ return `${field} is the JSON number ${String(value)}, larger in magnitude than Number.MAX_SAFE_INTEGER (2**53 - 1): JSON.parse has already rounded it, and signing it would sign a different integer than the one that was written. Send uints as decimal or 0x-hex strings (or a bigint)`;
1452
+ }
1453
+ function numberRefusal(path, value, code) {
1454
+ return new X402Error(
1455
+ Number.isInteger(value) ? inexactNumberMessage(path, value) : `${path} must be an integer, got the JSON number ${String(value)}`,
1456
+ code
1457
+ );
1458
+ }
1459
+ function findInexactNumber(value, path, seen = /* @__PURE__ */ new Set()) {
1460
+ if (typeof value === "number") {
1461
+ return Number.isSafeInteger(value) ? null : { path, value };
1462
+ }
1463
+ if (typeof value !== "object" || value === null || seen.has(value)) return null;
1464
+ seen.add(value);
1465
+ const entries = Array.isArray(value) ? value.map((item, i) => [`${path}[${i}]`, item]) : Object.entries(value).map(([key, item]) => [`${path}.${key}`, item]);
1466
+ for (const [itemPath, item] of entries) {
1467
+ const hit = findInexactNumber(item, itemPath, seen);
1468
+ if (hit) return hit;
1469
+ }
1470
+ return null;
1471
+ }
1472
+ function assertNoInexactNumber(value, path, code = "INVALID_CONFIG") {
1473
+ const hit = findInexactNumber(value, path);
1474
+ if (hit) throw numberRefusal(hit.path, hit.value, code);
1475
+ }
1476
+ function rootStruct(structs, primaryType) {
1477
+ try {
1478
+ return ethers.ethers.TypedDataEncoder.from(
1479
+ structs
1480
+ ).primaryType;
1481
+ } catch {
1482
+ return typeof primaryType === "string" && Array.isArray(structs[primaryType]) ? primaryType : null;
1483
+ }
1484
+ }
1485
+ function checkTyped(type, value, path, structs, code, ancestors = /* @__PURE__ */ new Set()) {
1486
+ if (typeof value === "object" && value !== null) {
1487
+ if (ancestors.has(value)) return;
1488
+ ancestors.add(value);
1489
+ }
1490
+ try {
1491
+ const array = /^(.*)\[(\d*)\]$/.exec(type);
1492
+ if (array) {
1493
+ if (Array.isArray(value)) {
1494
+ value.forEach(
1495
+ (item, i) => checkTyped(array[1], item, `${path}[${i}]`, structs, code, ancestors)
1496
+ );
1497
+ }
1498
+ return;
1499
+ }
1500
+ const struct = structs[type];
1501
+ if (Array.isArray(struct)) {
1502
+ if (!isRecord(value)) return;
1503
+ for (const field of struct) {
1504
+ if (typeof field?.name === "string" && typeof field.type === "string") {
1505
+ checkTyped(
1506
+ field.type,
1507
+ value[field.name],
1508
+ `${path}.${field.name}`,
1509
+ structs,
1510
+ code,
1511
+ ancestors
1512
+ );
1513
+ }
1514
+ }
1515
+ return;
1516
+ }
1517
+ if (INTEGER_TYPE.test(type) && typeof value === "number" && !Number.isSafeInteger(value)) {
1518
+ throw numberRefusal(path, value, code);
1519
+ }
1520
+ } finally {
1521
+ if (typeof value === "object" && value !== null) ancestors.delete(value);
1522
+ }
1523
+ }
1524
+ function assertTypedDataIntegersExact(doc, where = "typed data", code = "INVALID_CONFIG") {
1525
+ if (!isRecord(doc)) return;
1526
+ const { domain, types, message, primaryType } = doc;
1527
+ if (isRecord(domain) && typeof domain.chainId === "number" && !Number.isSafeInteger(domain.chainId)) {
1528
+ throw numberRefusal(`${where} domain.chainId`, domain.chainId, code);
1529
+ }
1530
+ if (!isRecord(message)) return;
1531
+ const structs = isRecord(types) ? { ...types } : {};
1532
+ delete structs["EIP712Domain"];
1533
+ const root = rootStruct(structs, primaryType);
1534
+ if (root) {
1535
+ checkTyped(root, message, `${where} message`, structs, code);
1536
+ if (typeof primaryType === "string" && primaryType !== root && Array.isArray(structs[primaryType])) {
1537
+ checkTyped(primaryType, message, `${where} message`, structs, code);
1538
+ }
1539
+ return;
1540
+ }
1541
+ assertNoInexactNumber(message, `${where} message`, code);
1542
+ }
1543
+ function parseTypedDataJson(text, where = "typed data", code = "INVALID_CONFIG") {
1544
+ const doc = JSON.parse(text);
1545
+ assertTypedDataIntegersExact(doc, where, code);
1546
+ return doc;
1547
+ }
1548
+
1549
+ // src/adapters/env-key.ts
1446
1550
  var EnvKeyAdapter = class {
1447
1551
  wallet;
1448
1552
  /**
@@ -1482,9 +1586,12 @@ var EnvKeyAdapter = class {
1482
1586
  *
1483
1587
  * @param typedData - JSON string with `domain`, `types`, `primaryType`, and `message` fields
1484
1588
  * @returns Object with signature and v/r/s components
1589
+ * @throws {X402Error} `INVALID_CONFIG` when an integer field of `message`
1590
+ * (or `domain.chainId`) is a JSON number above 2**53 - 1: `JSON.parse`
1591
+ * rounded it, so it is refused instead of signed. Write uints as strings.
1485
1592
  */
1486
1593
  async signTypedData(typedData) {
1487
- const parsed = JSON.parse(typedData);
1594
+ const parsed = parseTypedDataJson(typedData);
1488
1595
  const { domain, types, message } = parsed;
1489
1596
  const cleanTypes = { ...types };
1490
1597
  delete cleanTypes["EIP712Domain"];
@@ -1618,7 +1725,7 @@ var ETHERS_NAME_OF = { input: "data", gas: "gasLimit" };
1618
1725
  var TWO_127 = 1n << 127n;
1619
1726
  var TWO_128 = 1n << 128n;
1620
1727
  var TWO_256 = 1n << 256n;
1621
- function isRecord(value) {
1728
+ function isRecord2(value) {
1622
1729
  return typeof value === "object" && value !== null && !Array.isArray(value);
1623
1730
  }
1624
1731
  function shown(value) {
@@ -1635,6 +1742,7 @@ function refuse(message) {
1635
1742
  function toInteger(value, where) {
1636
1743
  if (typeof value === "bigint") return value;
1637
1744
  if (typeof value === "number" && Number.isSafeInteger(value)) return BigInt(value);
1745
+ if (typeof value === "number" && Number.isInteger(value)) throw refuse(inexactNumberMessage(where, value));
1638
1746
  if (typeof value === "string" && /^-?(0[xX][0-9a-fA-F]+|[0-9]+)$/.test(value)) {
1639
1747
  return value.startsWith("-") ? -BigInt(value.slice(1)) : BigInt(value);
1640
1748
  }
@@ -1662,7 +1770,7 @@ function owsValue(kind, value, types, where) {
1662
1770
  }
1663
1771
  const struct = types[kind];
1664
1772
  if (struct) {
1665
- if (!isRecord(value)) throw refuse(`${where}: ${kind} needs an object, got ${shown(value)}`);
1773
+ if (!isRecord2(value)) throw refuse(`${where}: ${kind} needs an object, got ${shown(value)}`);
1666
1774
  const out = {};
1667
1775
  for (const field of struct) {
1668
1776
  if (value[field.name] === void 0) throw refuse(`${where}: ${kind} lacks ${field.name}`);
@@ -1716,11 +1824,11 @@ function owsValue(kind, value, types, where) {
1716
1824
  throw refuse(`${where}: unsupported EIP-712 type ${kind}`);
1717
1825
  }
1718
1826
  function prepareTypedData(input) {
1719
- if (!isRecord(input)) throw refuse("typed data must be an object with domain, types and message");
1827
+ if (!isRecord2(input)) throw refuse("typed data must be an object with domain, types and message");
1720
1828
  const { domain, types, message, primaryType } = input;
1721
- if (!isRecord(domain)) throw refuse("typed data needs a domain object");
1722
- if (!isRecord(types)) throw refuse("typed data needs a types object");
1723
- if (!isRecord(message)) throw refuse("typed data needs a message object");
1829
+ if (!isRecord2(domain)) throw refuse("typed data needs a domain object");
1830
+ if (!isRecord2(types)) throw refuse("typed data needs a types object");
1831
+ if (!isRecord2(message)) throw refuse("typed data needs a message object");
1724
1832
  const structs = { ...types };
1725
1833
  delete structs["EIP712Domain"];
1726
1834
  let root;
@@ -1798,7 +1906,7 @@ var OWSWalletAdapter = class {
1798
1906
  #chain;
1799
1907
  #address;
1800
1908
  constructor(ows, options) {
1801
- if (isRecord(ows) && "accounts" in ows && (options === void 0 || typeof options === "number")) {
1909
+ if (isRecord2(ows) && "accounts" in ows && (options === void 0 || typeof options === "number")) {
1802
1910
  throw new X402Error(
1803
1911
  `OWSWalletAdapter no longer takes a wallet object with accounts (the deprecated OWSWallet shape, which never worked with @open-wallet-standard/core 1.x); ${MIGRATION}. Nothing was signed.`,
1804
1912
  "INVALID_CONFIG"
@@ -1813,7 +1921,7 @@ var OWSWalletAdapter = class {
1813
1921
  "INVALID_CONFIG"
1814
1922
  );
1815
1923
  }
1816
- const opts = isRecord(options) ? options : {};
1924
+ const opts = isRecord2(options) ? options : {};
1817
1925
  if (typeof opts.wallet !== "string" || opts.wallet === "") {
1818
1926
  throw new X402Error("OWSWalletAdapter needs options.wallet: the name or id of a wallet in the vault", "INVALID_CONFIG");
1819
1927
  }