uvd-x402-sdk 2.59.0 → 2.60.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.
package/dist/index.js CHANGED
@@ -1590,6 +1590,15 @@ function sellerDigestFor(paymentId2, contentHash2, payee, network) {
1590
1590
  }
1591
1591
  return anchorDigest(paymentId2, contentHash2, "", ZERO_ADDRESS, 0);
1592
1592
  }
1593
+ var ANCHOR_MAX_REQUEST_BYTES = 64 * 1024;
1594
+ function toBase64(bytes) {
1595
+ let out = "";
1596
+ const CHUNK = 32768;
1597
+ for (let i = 0; i < bytes.length; i += CHUNK) {
1598
+ out += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
1599
+ }
1600
+ return btoa(out);
1601
+ }
1593
1602
  async function anchorEvidence(body, opts) {
1594
1603
  try {
1595
1604
  const recipients = [
@@ -1606,7 +1615,7 @@ async function anchorEvidence(body, opts) {
1606
1615
  txHash: opts.txHash,
1607
1616
  payer: opts.payer,
1608
1617
  payee: opts.payee,
1609
- sealed: btoa(String.fromCharCode(...blob)),
1618
+ sealed: toBase64(blob),
1610
1619
  backend: "s3",
1611
1620
  contentHash: hash,
1612
1621
  keyAlg: opts.payerKey.length === 32 ? "ECIES-X25519" : "ECIES-secp256k1",
@@ -1618,6 +1627,10 @@ async function anchorEvidence(body, opts) {
1618
1627
  sellerDigestFor(opts.paymentId, hash, opts.payee, opts.network)
1619
1628
  );
1620
1629
  }
1630
+ const wire = JSON.stringify(payload);
1631
+ if (new TextEncoder().encode(wire).length > ANCHOR_MAX_REQUEST_BYTES) {
1632
+ return { v: 1, skipped: "too_large" };
1633
+ }
1621
1634
  const base = (opts.facilitator ?? "https://facilitator.ultravioletadao.xyz").replace(
1622
1635
  /\/+$/,
1623
1636
  ""
@@ -1626,9 +1639,16 @@ async function anchorEvidence(body, opts) {
1626
1639
  const res = await doFetch(`${base}/dx402/anchor`, {
1627
1640
  method: "POST",
1628
1641
  headers: { "content-type": "application/json" },
1629
- body: JSON.stringify(payload)
1642
+ body: wire
1630
1643
  });
1631
- if (!res.ok) return { v: 1, skipped: "anchor_failed" };
1644
+ if (!res.ok) {
1645
+ let error;
1646
+ try {
1647
+ error = (await res.json()).error;
1648
+ } catch {
1649
+ }
1650
+ return { v: 1, skipped: "anchor_failed", status: res.status, error };
1651
+ }
1632
1652
  return await res.json();
1633
1653
  } catch {
1634
1654
  return { v: 1, skipped: "anchor_failed" };