uvd-x402-sdk 2.104.2 → 2.104.3

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.
@@ -1543,8 +1543,124 @@ function assertTypedDataIntegersExact(doc, where = "typed data", code = "INVALID
1543
1543
  }
1544
1544
  assertNoInexactNumber(message, `${where} message`, code);
1545
1545
  }
1546
+ var MIN_EXACT_DIGITS = 22;
1547
+ var MAX_EXACT_DIGITS = 78;
1548
+ var MAX_DOUBLE_DIGITS = 17;
1549
+ function doubleShaped(literal) {
1550
+ const significant = literal.replace(/^-/, "").replace(/0+$/, "");
1551
+ return significant.length <= MAX_DOUBLE_DIGITS || BigInt(literal) === BigInt(Number(literal));
1552
+ }
1553
+ var JSON_NUMBER = /-?(?:0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/y;
1554
+ var JSON_SPACE = /[ \t\n\r]*/y;
1555
+ function dataDescriptor(value) {
1556
+ const descriptor = /* @__PURE__ */ Object.create(null);
1557
+ descriptor.value = value;
1558
+ descriptor.writable = true;
1559
+ descriptor.enumerable = true;
1560
+ descriptor.configurable = true;
1561
+ return descriptor;
1562
+ }
1563
+ function parseJsonExact(input) {
1564
+ const text = String(input);
1565
+ let pos = 0;
1566
+ let wide = false;
1567
+ const fail = (what) => {
1568
+ throw new SyntaxError(`${what} in JSON at position ${pos}`);
1569
+ };
1570
+ const space = () => {
1571
+ JSON_SPACE.lastIndex = pos;
1572
+ if (JSON_SPACE.exec(text)) pos = JSON_SPACE.lastIndex;
1573
+ };
1574
+ const string = () => {
1575
+ if (text[pos] !== '"') fail("Expected a string");
1576
+ let end = pos + 1;
1577
+ while (end < text.length && text[end] !== '"') end += text[end] === "\\" ? 2 : 1;
1578
+ if (end >= text.length) fail("Unterminated string");
1579
+ const value = JSON.parse(text.slice(pos, end + 1));
1580
+ pos = end + 1;
1581
+ return value;
1582
+ };
1583
+ const key = () => {
1584
+ const name = string();
1585
+ space();
1586
+ if (text[pos] !== ":") fail("Expected ':'");
1587
+ pos += 1;
1588
+ space();
1589
+ return name;
1590
+ };
1591
+ const scalar = () => {
1592
+ if (text[pos] === '"') return string();
1593
+ for (const [word, value] of [["true", true], ["false", false], ["null", null]]) {
1594
+ if (text.startsWith(word, pos)) {
1595
+ pos += word.length;
1596
+ return value;
1597
+ }
1598
+ }
1599
+ JSON_NUMBER.lastIndex = pos;
1600
+ const match = JSON_NUMBER.exec(text);
1601
+ if (!match) return fail("Unexpected token");
1602
+ pos = JSON_NUMBER.lastIndex;
1603
+ const literal = match[0];
1604
+ const digits = literal.length - (literal.startsWith("-") ? 1 : 0);
1605
+ if (match[1] === void 0 && match[2] === void 0 && digits >= MIN_EXACT_DIGITS && digits <= MAX_EXACT_DIGITS && !doubleShaped(literal)) {
1606
+ wide = true;
1607
+ return BigInt(literal);
1608
+ }
1609
+ return Number(literal);
1610
+ };
1611
+ const stack = [];
1612
+ space();
1613
+ for (; ; ) {
1614
+ let value;
1615
+ if (text[pos] === "[") {
1616
+ pos += 1;
1617
+ space();
1618
+ if (text[pos] !== "]") {
1619
+ stack.push({ kind: "array", items: [] });
1620
+ continue;
1621
+ }
1622
+ pos += 1;
1623
+ value = [];
1624
+ } else if (text[pos] === "{") {
1625
+ pos += 1;
1626
+ space();
1627
+ if (text[pos] !== "}") {
1628
+ stack.push({ kind: "object", object: {}, key: key() });
1629
+ continue;
1630
+ }
1631
+ pos += 1;
1632
+ value = {};
1633
+ } else {
1634
+ value = scalar();
1635
+ }
1636
+ for (; ; ) {
1637
+ space();
1638
+ const top = stack[stack.length - 1];
1639
+ if (top === void 0) {
1640
+ if (pos !== text.length) fail("Unexpected non-whitespace character after JSON");
1641
+ return wide ? value : JSON.parse(text);
1642
+ }
1643
+ const close = top.kind === "array" ? "]" : "}";
1644
+ if (top.kind === "array") {
1645
+ top.items.push(value);
1646
+ } else {
1647
+ Object.defineProperty(top.object, top.key, dataDescriptor(value));
1648
+ }
1649
+ if (text[pos] === ",") {
1650
+ pos += 1;
1651
+ space();
1652
+ if (top.kind === "object") top.key = key();
1653
+ break;
1654
+ }
1655
+ if (text[pos] !== close) fail(`Expected ',' or '${close}'`);
1656
+ pos += 1;
1657
+ stack.pop();
1658
+ value = top.kind === "array" ? top.items : top.object;
1659
+ }
1660
+ }
1661
+ }
1546
1662
  function parseTypedDataJson(text, where = "typed data", code = "INVALID_CONFIG") {
1547
- const doc = JSON.parse(text);
1663
+ const doc = parseJsonExact(text);
1548
1664
  assertTypedDataIntegersExact(doc, where, code);
1549
1665
  return doc;
1550
1666
  }
@@ -1587,11 +1703,18 @@ var EnvKeyAdapter = class {
1587
1703
  /**
1588
1704
  * Sign EIP-712 typed structured data.
1589
1705
  *
1706
+ * An integer of 22 to 78 digits written as a JSON number (a 32-byte salt)
1707
+ * is read with every digit, as Python's `json` reads it, not rounded the
1708
+ * way `JSON.parse` rounds it.
1709
+ *
1590
1710
  * @param typedData - JSON string with `domain`, `types`, `primaryType`, and `message` fields
1591
1711
  * @returns Object with signature and v/r/s components
1592
1712
  * @throws {X402Error} `INVALID_CONFIG` when an integer field of `message`
1593
- * (or `domain.chainId`) is a JSON number above 2**53 - 1: `JSON.parse`
1594
- * rounded it, so it is refused instead of signed. Write uints as strings.
1713
+ * (or `domain.chainId`) is a JSON number above 2**53 - 1 of up to 21
1714
+ * digits (a JavaScript hop may have rounded it and written it back in
1715
+ * digits) or written with an exponent or a fraction (`7.76e+76`): it is
1716
+ * refused instead of signed. Write uints as strings. An integer out of
1717
+ * its field's range is refused by ethers (`value out-of-bounds`).
1595
1718
  */
1596
1719
  async signTypedData(typedData) {
1597
1720
  const parsed = parseTypedDataJson(typedData);
@@ -1854,7 +1977,14 @@ function prepareTypedData(input) {
1854
1977
  EIP712Domain: EIP712_DOMAIN_FIELDS.filter(([name]) => domain[name] != null).map(
1855
1978
  ([name, type]) => ({ name, type })
1856
1979
  ),
1857
- ...structs
1980
+ // Each field as ethers hashes it, name and type: any other key (a wide
1981
+ // number in it is a bigint) never reaches OWS or JSON.stringify.
1982
+ ...Object.fromEntries(
1983
+ Object.entries(structs).map(([struct, fields]) => [
1984
+ struct,
1985
+ fields.map(({ name, type }) => ({ name, type }))
1986
+ ])
1987
+ )
1858
1988
  };
1859
1989
  const owsDomain = owsValue("EIP712Domain", domain, all, "domain");
1860
1990
  const owsMessage = owsValue(root, message, all, "message");
@@ -1986,7 +2116,7 @@ var OWSWalletAdapter = class {
1986
2116
  async signTypedData(typedData) {
1987
2117
  let parsed;
1988
2118
  try {
1989
- parsed = JSON.parse(typedData);
2119
+ parsed = parseJsonExact(typedData);
1990
2120
  } catch {
1991
2121
  throw refuse("typedData is not a JSON string");
1992
2122
  }