@piprail/sdk 2.13.0 → 2.14.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 (30) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/{algorand-AA3WXKW4.js → algorand-6J3IABVF.js} +12 -11
  3. package/dist/{algorand-FCEECDG6.cjs → algorand-QU6G2DQZ.cjs} +43 -42
  4. package/dist/{aptos-LY67Q6QF.js → aptos-DHOMTBLZ.js} +11 -10
  5. package/dist/{aptos-GHJPO6JJ.cjs → aptos-LFTQGBBK.cjs} +41 -40
  6. package/dist/{chunk-MWBT7MCE.cjs → chunk-GYM46G5L.cjs} +22 -4
  7. package/dist/{chunk-SC2ZYDHD.js → chunk-PAMKCWVW.js} +22 -4
  8. package/dist/index.cjs +505 -234
  9. package/dist/index.d.cts +281 -12
  10. package/dist/index.d.ts +281 -12
  11. package/dist/index.js +302 -31
  12. package/dist/{ledger-mF_SoiDB.d.ts → ledger-uFtXlIHY.d.cts} +31 -1
  13. package/dist/{ledger-mF_SoiDB.d.cts → ledger-uFtXlIHY.d.ts} +31 -1
  14. package/dist/{near-FZBUICCS.js → near-5PXTVQ47.js} +14 -5
  15. package/dist/{near-6KAQVVG2.cjs → near-YNNK7RW7.cjs} +39 -30
  16. package/dist/node.d.cts +2 -2
  17. package/dist/node.d.ts +2 -2
  18. package/dist/{solana-ELUWO6N5.js → solana-HITVI3HF.js} +22 -7
  19. package/dist/{solana-MYF4HBO4.cjs → solana-N3UCNCYE.cjs} +54 -39
  20. package/dist/{stellar-ASP2THL2.js → stellar-2QT6YYKN.js} +4 -4
  21. package/dist/{stellar-CRWBSX4E.cjs → stellar-Y3SQN7S5.cjs} +23 -23
  22. package/dist/{sui-Y4RLKKE2.cjs → sui-4AL4E6XU.cjs} +35 -27
  23. package/dist/{sui-FZIKZNVI.js → sui-FV5L6WF5.js} +20 -12
  24. package/dist/{ton-7GKCTC5H.js → ton-5FWDQ4QR.js} +18 -7
  25. package/dist/{ton-AOR3EURW.cjs → ton-5HDVOTMR.cjs} +33 -22
  26. package/dist/{tron-BMCWN5SS.js → tron-AZDY7BMQ.js} +10 -10
  27. package/dist/{tron-OMXB6EW2.cjs → tron-TX2B4N2A.cjs} +39 -39
  28. package/dist/{xrpl-Y6SQNYLC.cjs → xrpl-5TYDLQFS.cjs} +31 -31
  29. package/dist/{xrpl-DD7TJL5L.js → xrpl-UJL5J7CY.js} +13 -13
  30. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -31,7 +31,7 @@ var _chunkCQQI5IJXcjs = require('./chunk-CQQI5IJX.cjs');
31
31
 
32
32
 
33
33
 
34
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
34
+ var _chunkGYM46G5Lcjs = require('./chunk-GYM46G5L.cjs');
35
35
 
36
36
  // src/drivers/registry.ts
37
37
  var byFamily = /* @__PURE__ */ new Map();
@@ -60,13 +60,13 @@ function resolveNetwork(opts) {
60
60
  const family = familyForChain(opts.chain);
61
61
  const driver = byFamily.get(family);
62
62
  if (!driver) {
63
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedNetworkError)(
63
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedNetworkError)(
64
64
  `No driver registered for the "${family}" family \u2014 it may not be mounted yet (use the async resolveNetwork()).`
65
65
  );
66
66
  }
67
67
  const net = driver.resolve(opts);
68
68
  if (!net) {
69
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedNetworkError)(
69
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedNetworkError)(
70
70
  `The ${family} driver didn't recognise this chain input.`
71
71
  );
72
72
  }
@@ -331,12 +331,12 @@ function resolveChain(input, rpcUrlOverride) {
331
331
 
332
332
  var _accounts = require('viem/accounts');
333
333
  function createWalletAdapter(config, resolved) {
334
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, config, "EVM");
334
+ _chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, config, "EVM");
335
335
  if ("key" in config) {
336
336
  const key = config.key;
337
337
  if (typeof key !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(key)) {
338
338
  const hint = typeof key === "string" && !key.startsWith("0x") ? " (got a non-0x string \u2014 a base58/seed key belongs to another family; pass { key } as the EVM chain's 0x\u2026 hex secret)." : " (expected 0x followed by 64 hex characters).";
339
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
339
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
340
340
  `chain is EVM; the wallet { key } is not a valid 0x\u2026 32-byte hex private key${hint}`
341
341
  );
342
342
  }
@@ -344,7 +344,7 @@ function createWalletAdapter(config, resolved) {
344
344
  try {
345
345
  account = _accounts.privateKeyToAccount.call(void 0, key);
346
346
  } catch (err) {
347
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
347
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
348
348
  `chain is EVM; the wallet { key } is not a valid 0x\u2026 32-byte hex private key: ${err instanceof Error ? err.message : String(err)}.`
349
349
  );
350
350
  }
@@ -354,12 +354,12 @@ function createWalletAdapter(config, resolved) {
354
354
  }
355
355
  const wc = config.walletClient;
356
356
  if (!wc.account) {
357
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
357
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
358
358
  "chain is EVM; the provided walletClient has no attached account. Use `createWalletClient({ account, chain, transport })`, or pass { key }."
359
359
  );
360
360
  }
361
361
  if (wc.chain && wc.chain.id !== resolved.chainId) {
362
- throw new (0, _chunkMWBT7MCEcjs.WrongChainError)(
362
+ throw new (0, _chunkGYM46G5Lcjs.WrongChainError)(
363
363
  `PipRailClient: walletClient is on chain ${wc.chain.id} but the SDK was configured with chain ${resolved.chainId}. They must match.`
364
364
  );
365
365
  }
@@ -689,7 +689,7 @@ async function payExactEvm(input) {
689
689
  code = void 0;
690
690
  }
691
691
  if (code && code !== "0x") {
692
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
692
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
693
693
  `exact buyer rail requires an EOA signer; ${account.address} is a contract / EIP-1271 / EIP-7702-delegated account (no recoverable ECDSA signature). Pay via onchain-proof.`
694
694
  );
695
695
  }
@@ -699,13 +699,13 @@ async function payExactEvm(input) {
699
699
  domain = await readExactDomain(publicClient, accept.asset);
700
700
  }
701
701
  if (!domain) {
702
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
702
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
703
703
  `exact: couldn't derive the EIP-712 domain for ${accept.asset} on ${accept.network}. Either it isn't an EIP-3009 token (USDT needs Permit2; native/plain ERC-20 aren't exact-payable) \u2014 pay via onchain-proof \u2014 OR your RPC couldn't read it (transient): if the gate advertised eip3009, pass a reliable rpcUrl and retry.`
704
704
  );
705
705
  }
706
706
  const g = globalThis.crypto;
707
707
  if (!_optionalChain([g, 'optionalAccess', _5 => _5.getRandomValues])) {
708
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
708
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
709
709
  "this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the exact rail needs a CSPRNG nonce."
710
710
  );
711
711
  }
@@ -962,7 +962,7 @@ async function verifyAndSettleExactEvm(input) {
962
962
  args: writeArgs
963
963
  });
964
964
  } catch (err) {
965
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
965
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
966
966
  `exact settle: the merchant relayer failed to broadcast transferWithAuthorization (${shorten(err instanceof Error ? err.message : String(err))}). The payer's authorization is still valid and unused \u2014 fund/fix the relayer and the payer can retry.`,
967
967
  { cause: err }
968
968
  );
@@ -974,7 +974,7 @@ async function verifyAndSettleExactEvm(input) {
974
974
  return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
975
975
  }
976
976
  } catch (err) {
977
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
977
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
978
978
  `exact settle: broadcast ${txHash} but couldn't confirm it (${shorten(err instanceof Error ? err.message : String(err))}).`,
979
979
  { cause: err }
980
980
  );
@@ -1105,7 +1105,7 @@ function shorten2(msg) {
1105
1105
  function randomPermit2Nonce() {
1106
1106
  const g = globalThis.crypto;
1107
1107
  if (!_optionalChain([g, 'optionalAccess', _8 => _8.getRandomValues])) {
1108
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
1108
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
1109
1109
  "this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the permit2 rail needs a CSPRNG nonce."
1110
1110
  );
1111
1111
  }
@@ -1124,7 +1124,7 @@ async function ensurePermit2Allowance(input) {
1124
1124
  args: [account.address, PERMIT2_ADDRESS]
1125
1125
  });
1126
1126
  } catch (err) {
1127
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
1127
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
1128
1128
  `permit2: couldn't read the Permit2 allowance for ${token} (${shorten2(err instanceof Error ? err.message : String(err))}).`
1129
1129
  );
1130
1130
  }
@@ -1141,7 +1141,7 @@ async function ensurePermit2Allowance(input) {
1141
1141
  await publicClient.waitForTransactionReceipt({ hash, confirmations: 1 });
1142
1142
  return hash;
1143
1143
  } catch (err) {
1144
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( new (0, _chunkMWBT7MCEcjs.SettlementError)(
1144
+ throw _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( new (0, _chunkGYM46G5Lcjs.SettlementError)(
1145
1145
  `permit2: the one-time Permit2 approval for ${token} failed to broadcast (${shorten2(err instanceof Error ? err.message : String(err))}).`,
1146
1146
  { cause: err }
1147
1147
  )));
@@ -1156,7 +1156,7 @@ async function payPermit2Evm(input) {
1156
1156
  code = void 0;
1157
1157
  }
1158
1158
  if (code && code !== "0x") {
1159
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
1159
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
1160
1160
  `permit2 buyer rail requires an EOA signer; ${account.address} is a contract / EIP-1271 / EIP-7702-delegated account. Pay via onchain-proof.`
1161
1161
  );
1162
1162
  }
@@ -1331,7 +1331,7 @@ async function verifyAndSettlePermit2Evm(input) {
1331
1331
  args: settleArgs
1332
1332
  });
1333
1333
  } catch (err) {
1334
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
1334
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
1335
1335
  `permit2 settle: the merchant relayer failed to broadcast the proxy settle (${shorten2(err instanceof Error ? err.message : String(err))}). The payer's signature is still valid and its nonce unused \u2014 fund/fix the relayer and the payer can retry.`,
1336
1336
  { cause: err }
1337
1337
  );
@@ -1343,7 +1343,7 @@ async function verifyAndSettlePermit2Evm(input) {
1343
1343
  return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
1344
1344
  }
1345
1345
  } catch (err) {
1346
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
1346
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
1347
1347
  `permit2 settle: broadcast ${txHash} but couldn't confirm it (${shorten2(err instanceof Error ? err.message : String(err))}).`,
1348
1348
  { cause: err }
1349
1349
  );
@@ -1441,7 +1441,7 @@ function shorten3(msg) {
1441
1441
  function randomPermit2Nonce2() {
1442
1442
  const g = globalThis.crypto;
1443
1443
  if (!_optionalChain([g, 'optionalAccess', _9 => _9.getRandomValues])) {
1444
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
1444
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
1445
1445
  "this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the upto rail needs a CSPRNG nonce."
1446
1446
  );
1447
1447
  }
@@ -1458,13 +1458,13 @@ async function payUptoEvm(input) {
1458
1458
  code = void 0;
1459
1459
  }
1460
1460
  if (code && code !== "0x") {
1461
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
1461
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
1462
1462
  `upto buyer rail requires an EOA signer; ${account.address} is a contract / EIP-1271 / EIP-7702-delegated account. Pay via onchain-proof.`
1463
1463
  );
1464
1464
  }
1465
1465
  const facilitatorAddress = _optionalChain([accept, 'access', _10 => _10.extra, 'optionalAccess', _11 => _11.facilitatorAddress]);
1466
1466
  if (typeof facilitatorAddress !== "string" || facilitatorAddress.length === 0) {
1467
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
1467
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
1468
1468
  `upto: the rail carries no extra.facilitatorAddress to bind into witness.facilitator \u2014 refusing to sign.`
1469
1469
  );
1470
1470
  }
@@ -1685,7 +1685,7 @@ async function verifyAndSettleUptoEvm(input) {
1685
1685
  args: settleArgs
1686
1686
  });
1687
1687
  } catch (err) {
1688
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
1688
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
1689
1689
  `upto settle: the merchant relayer failed to broadcast the proxy settle (${shorten3(err instanceof Error ? err.message : String(err))}). The payer's signature is still valid and its nonce unused \u2014 fund/fix the relayer and the payer can retry.`,
1690
1690
  { cause: err }
1691
1691
  );
@@ -1697,7 +1697,7 @@ async function verifyAndSettleUptoEvm(input) {
1697
1697
  return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
1698
1698
  }
1699
1699
  } catch (err) {
1700
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
1700
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
1701
1701
  `upto settle: broadcast ${txHash} but couldn't confirm it (${shorten3(err instanceof Error ? err.message : String(err))}).`,
1702
1702
  { cause: err }
1703
1703
  );
@@ -1780,6 +1780,37 @@ function buildReceiptExtension(bundle) {
1780
1780
  if (bundle.attestation) info.receipt = bundle.attestation;
1781
1781
  return { [EXT_OFFER_RECEIPT]: { info } };
1782
1782
  }
1783
+ var EXT_PAYMENT_IDENTIFIER = "payment-identifier";
1784
+ var PAYMENT_ID_MIN = 16;
1785
+ var PAYMENT_ID_MAX = 128;
1786
+ var PAYMENT_ID_RE = /^[A-Za-z0-9_-]+$/;
1787
+ function buildPaymentIdentifierAdvertisement() {
1788
+ return {
1789
+ [EXT_PAYMENT_IDENTIFIER]: {
1790
+ info: { required: false },
1791
+ schema: { properties: { id: { type: "string", minLength: PAYMENT_ID_MIN, maxLength: PAYMENT_ID_MAX } } }
1792
+ }
1793
+ };
1794
+ }
1795
+ function readPaymentIdentifier(payload) {
1796
+ if (typeof payload !== "object" || payload === null) return null;
1797
+ const ext = payload.extensions;
1798
+ if (typeof ext !== "object" || ext === null) return null;
1799
+ const block = ext[EXT_PAYMENT_IDENTIFIER];
1800
+ if (typeof block !== "object" || block === null) return null;
1801
+ const info = block.info;
1802
+ if (typeof info !== "object" || info === null) return null;
1803
+ const id = info.id;
1804
+ if (id === void 0) return null;
1805
+ if (typeof id !== "string") return { invalid: "payment-identifier id must be a string" };
1806
+ if (id.length < PAYMENT_ID_MIN || id.length > PAYMENT_ID_MAX) {
1807
+ return { invalid: `payment-identifier id must be ${PAYMENT_ID_MIN}\u2013${PAYMENT_ID_MAX} chars (got ${id.length})` };
1808
+ }
1809
+ if (!PAYMENT_ID_RE.test(id)) {
1810
+ return { invalid: "payment-identifier id must match [A-Za-z0-9_-]" };
1811
+ }
1812
+ return id;
1813
+ }
1783
1814
  function buildSignatureHeader(signature) {
1784
1815
  return toBase64Json(signature);
1785
1816
  }
@@ -1806,7 +1837,10 @@ function parseReceipt(response) {
1806
1837
  const headerValue = _nullishCoalesce(response.headers.get(HEADER_RESPONSE), () => ( response.headers.get(HEADER_RESPONSE_V1)));
1807
1838
  if (!headerValue) return null;
1808
1839
  const parsed = fromBase64Json(headerValue);
1809
- return isValidReceipt(parsed) ? parsed : null;
1840
+ if (!isValidReceipt(parsed)) return null;
1841
+ const r = parsed;
1842
+ if (typeof r.transaction !== "string" && typeof r.txHash === "string") r.transaction = r.txHash;
1843
+ return r;
1810
1844
  }
1811
1845
  function parseReceiptExtension(response) {
1812
1846
  const headerValue = _nullishCoalesce(response.headers.get(HEADER_RESPONSE), () => ( response.headers.get(HEADER_RESPONSE_V1)));
@@ -1836,7 +1870,8 @@ function parseSettleResponse(response) {
1836
1870
  if (!parsed || typeof parsed !== "object" || typeof parsed.success !== "boolean") return null;
1837
1871
  return {
1838
1872
  success: parsed.success,
1839
- ...typeof parsed.transaction === "string" ? { transaction: parsed.transaction } : {},
1873
+ // Tolerate the legacy v1 `txHash` alias for `transaction` (mirrors isValidReceipt/parseReceipt).
1874
+ ...typeof parsed.transaction === "string" ? { transaction: parsed.transaction } : typeof parsed.txHash === "string" ? { transaction: parsed.txHash } : {},
1840
1875
  ...typeof parsed.network === "string" ? { network: parsed.network } : {},
1841
1876
  ...typeof parsed.payer === "string" ? { payer: parsed.payer } : {},
1842
1877
  ...typeof parsed.errorReason === "string" ? { errorReason: parsed.errorReason } : {},
@@ -1855,6 +1890,14 @@ function parseSignatureObject(parsed) {
1855
1890
  if (!payload || typeof payload.txHash !== "string" || typeof payload.nonce !== "string") {
1856
1891
  return null;
1857
1892
  }
1893
+ if (!accepted) {
1894
+ const synthesized = {
1895
+ scheme: "onchain-proof",
1896
+ ...typeof v.network === "string" ? { network: v.network } : {},
1897
+ ...typeof v.asset === "string" ? { asset: v.asset } : {}
1898
+ };
1899
+ return { ...v, accepted: synthesized, payload };
1900
+ }
1858
1901
  return parsed;
1859
1902
  }
1860
1903
  function parseSignatureHeader(value) {
@@ -1994,7 +2037,11 @@ var evmDriver = {
1994
2037
  resolve(opts) {
1995
2038
  if (typeof opts.chain === "string" && /^(solana|ton|stellar)/.test(opts.chain)) return null;
1996
2039
  if (typeof opts.chain === "string") {
1997
- return makeEvmNetwork(resolveChain(opts.chain, opts.rpcUrl));
2040
+ try {
2041
+ return makeEvmNetwork(resolveChain(opts.chain, opts.rpcUrl));
2042
+ } catch (err) {
2043
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedNetworkError)(err instanceof Error ? err.message : String(err), { cause: err });
2044
+ }
1998
2045
  }
1999
2046
  let resolved;
2000
2047
  try {
@@ -2027,20 +2074,25 @@ function makeEvmNetwork(resolved) {
2027
2074
  const info = resolved.tokens[token.toUpperCase()];
2028
2075
  if (!info) {
2029
2076
  const known = Object.keys(resolved.tokens).join(", ") || "(none built in)";
2030
- throw new (0, _chunkMWBT7MCEcjs.UnknownTokenError)(
2077
+ throw new (0, _chunkGYM46G5Lcjs.UnknownTokenError)(
2031
2078
  `token "${token}" isn't built in for ${resolved.chain.name} (known: ${known}). Pass { address, decimals } instead, or use 'native'.`
2032
2079
  );
2033
2080
  }
2034
2081
  return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
2035
2082
  }
2036
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "evm", network);
2083
+ _chunkGYM46G5Lcjs.rejectForeignToken.call(void 0, token, "evm", network);
2037
2084
  if (!("address" in token)) {
2038
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
2085
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
2039
2086
  `chain ${network} is EVM; a custom token must be { address, decimals }.`
2040
2087
  );
2041
2088
  }
2089
+ if (!_viem.isAddress.call(void 0, token.address)) {
2090
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
2091
+ `chain ${network} is EVM, but token address "${token.address}" is not a valid 0x address.`
2092
+ );
2093
+ }
2042
2094
  return {
2043
- asset: token.address,
2095
+ asset: _viem.getAddress.call(void 0, token.address),
2044
2096
  decimals: token.decimals,
2045
2097
  ...token.symbol ? { symbol: token.symbol } : {}
2046
2098
  };
@@ -2067,20 +2119,20 @@ function makeEvmNetwork(resolved) {
2067
2119
  },
2068
2120
  assertValidPayTo(payTo) {
2069
2121
  if (!_viem.isAddress.call(void 0, payTo)) {
2070
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
2122
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
2071
2123
  `chain ${network} is EVM, but payTo "${payTo}" is not a valid 0x address.`
2072
2124
  );
2073
2125
  }
2074
2126
  },
2075
2127
  bindWallet(wallet) {
2076
2128
  if (typeof wallet !== "object" || wallet === null) {
2077
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
2129
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
2078
2130
  `chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
2079
2131
  );
2080
2132
  }
2081
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "EVM");
2133
+ _chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, wallet, "EVM");
2082
2134
  if (!("key" in wallet) && !("walletClient" in wallet)) {
2083
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
2135
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
2084
2136
  `chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
2085
2137
  );
2086
2138
  }
@@ -2097,12 +2149,12 @@ function makeEvmNetwork(resolved) {
2097
2149
  });
2098
2150
  } catch (err) {
2099
2151
  if (isViemInsufficientFunds(err)) {
2100
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
2152
+ throw new (0, _chunkGYM46G5Lcjs.InsufficientFundsError)(
2101
2153
  err instanceof Error ? err.message : "Insufficient funds for payment.",
2102
2154
  { cause: err }
2103
2155
  );
2104
2156
  }
2105
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
2157
+ throw _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
2106
2158
  }
2107
2159
  },
2108
2160
  async confirm(ref, minConfirmations) {
@@ -2113,7 +2165,7 @@ function makeEvmNetwork(resolved) {
2113
2165
  });
2114
2166
  return { height: receipt.blockNumber.toString() };
2115
2167
  } catch (err) {
2116
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(
2168
+ throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(
2117
2169
  `EVM tx ${ref} did not reach ${minConfirmations} confirmation(s) in time.`,
2118
2170
  { cause: err }
2119
2171
  );
@@ -2121,10 +2173,10 @@ function makeEvmNetwork(resolved) {
2121
2173
  },
2122
2174
  async estimateCost(accept) {
2123
2175
  const { decimals, symbol } = resolved.chain.nativeCurrency;
2124
- if (accept.scheme === "exact") {
2125
- const m = accept.extra.assetTransferMethod;
2126
- const permit2 = m === "permit2" || m === "permit2-exact";
2127
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
2176
+ if (accept.scheme === "exact" || accept.scheme === "upto") {
2177
+ const m = _optionalChain([accept, 'access', _19 => _19.extra, 'optionalAccess', _20 => _20.assetTransferMethod]);
2178
+ const permit2 = m === "permit2" || m === "permit2-exact" || m === "permit2-upto";
2179
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
2128
2180
  symbol,
2129
2181
  decimals,
2130
2182
  fee: 0n,
@@ -2135,7 +2187,7 @@ function makeEvmNetwork(resolved) {
2135
2187
  const gasLimit = accept.asset === "native" ? 21000n : 65000n;
2136
2188
  try {
2137
2189
  const gasPrice = await publicClient.getGasPrice();
2138
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
2190
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
2139
2191
  symbol,
2140
2192
  decimals,
2141
2193
  fee: gasPrice * gasLimit,
@@ -2144,7 +2196,7 @@ function makeEvmNetwork(resolved) {
2144
2196
  });
2145
2197
  } catch (e23) {
2146
2198
  const gasPrice = 5000000000n;
2147
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
2199
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
2148
2200
  symbol,
2149
2201
  decimals,
2150
2202
  fee: gasPrice * gasLimit,
@@ -2329,9 +2381,9 @@ var loaders = {
2329
2381
  solana: async () => {
2330
2382
  let mod;
2331
2383
  try {
2332
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./solana-MYF4HBO4.cjs")));
2384
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./solana-N3UCNCYE.cjs")));
2333
2385
  } catch (cause) {
2334
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2386
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2335
2387
  `Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
2336
2388
  { cause }
2337
2389
  );
@@ -2341,9 +2393,9 @@ var loaders = {
2341
2393
  ton: async () => {
2342
2394
  let mod;
2343
2395
  try {
2344
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./ton-AOR3EURW.cjs")));
2396
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./ton-5HDVOTMR.cjs")));
2345
2397
  } catch (cause) {
2346
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2398
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2347
2399
  `TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
2348
2400
  { cause }
2349
2401
  );
@@ -2353,9 +2405,9 @@ var loaders = {
2353
2405
  stellar: async () => {
2354
2406
  let mod;
2355
2407
  try {
2356
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./stellar-CRWBSX4E.cjs")));
2408
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./stellar-Y3SQN7S5.cjs")));
2357
2409
  } catch (cause) {
2358
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2410
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2359
2411
  `Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
2360
2412
  { cause }
2361
2413
  );
@@ -2365,9 +2417,9 @@ var loaders = {
2365
2417
  xrpl: async () => {
2366
2418
  let mod;
2367
2419
  try {
2368
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./xrpl-Y6SQNYLC.cjs")));
2420
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./xrpl-5TYDLQFS.cjs")));
2369
2421
  } catch (cause) {
2370
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2422
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2371
2423
  `XRPL selected, but its package isn't installed. Run: npm install xrpl`,
2372
2424
  { cause }
2373
2425
  );
@@ -2377,9 +2429,9 @@ var loaders = {
2377
2429
  tron: async () => {
2378
2430
  let mod;
2379
2431
  try {
2380
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./tron-OMXB6EW2.cjs")));
2432
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./tron-TX2B4N2A.cjs")));
2381
2433
  } catch (cause) {
2382
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2434
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2383
2435
  `Tron selected, but its package isn't installed. Run: npm install tronweb`,
2384
2436
  { cause }
2385
2437
  );
@@ -2389,9 +2441,9 @@ var loaders = {
2389
2441
  sui: async () => {
2390
2442
  let mod;
2391
2443
  try {
2392
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./sui-Y4RLKKE2.cjs")));
2444
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./sui-4AL4E6XU.cjs")));
2393
2445
  } catch (cause) {
2394
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2446
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2395
2447
  `Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
2396
2448
  { cause }
2397
2449
  );
@@ -2401,9 +2453,9 @@ var loaders = {
2401
2453
  near: async () => {
2402
2454
  let mod;
2403
2455
  try {
2404
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./near-6KAQVVG2.cjs")));
2456
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./near-YNNK7RW7.cjs")));
2405
2457
  } catch (cause) {
2406
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2458
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2407
2459
  `NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
2408
2460
  { cause }
2409
2461
  );
@@ -2413,9 +2465,9 @@ var loaders = {
2413
2465
  aptos: async () => {
2414
2466
  let mod;
2415
2467
  try {
2416
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./aptos-GHJPO6JJ.cjs")));
2468
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./aptos-LFTQGBBK.cjs")));
2417
2469
  } catch (cause) {
2418
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2470
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2419
2471
  `Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
2420
2472
  { cause }
2421
2473
  );
@@ -2425,9 +2477,9 @@ var loaders = {
2425
2477
  algorand: async () => {
2426
2478
  let mod;
2427
2479
  try {
2428
- mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./algorand-FCEECDG6.cjs")));
2480
+ mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./algorand-QU6G2DQZ.cjs")));
2429
2481
  } catch (cause) {
2430
- throw new (0, _chunkMWBT7MCEcjs.MissingDriverError)(
2482
+ throw new (0, _chunkGYM46G5Lcjs.MissingDriverError)(
2431
2483
  `Algorand selected, but its package isn't installed. Run: npm install algosdk`,
2432
2484
  { cause }
2433
2485
  );
@@ -2788,7 +2840,7 @@ async function register402Index(input) {
2788
2840
  if (res.ok) {
2789
2841
  const body = await res.json().catch(() => ({}));
2790
2842
  const msg = typeof body.message === "string" && body.message.length > 0 ? body.message : void 0;
2791
- const live = _optionalChain([body, 'access', _19 => _19.service, 'optionalAccess', _20 => _20.status]) === "active";
2843
+ const live = _optionalChain([body, 'access', _21 => _21.service, 'optionalAccess', _22 => _22.status]) === "active";
2792
2844
  return {
2793
2845
  source: "402index",
2794
2846
  ok: true,
@@ -2925,11 +2977,11 @@ async function readSiwxInfo(res) {
2925
2977
  try {
2926
2978
  const body = await res.json();
2927
2979
  const ext = body.extensions;
2928
- const siwx = _optionalChain([ext, 'optionalAccess', _21 => _21["sign-in-with-x"]]);
2929
- const info = _nullishCoalesce(_optionalChain([siwx, 'optionalAccess', _22 => _22.info]), () => ( siwx));
2930
- if (info && info.chainId == null && Array.isArray(_optionalChain([siwx, 'optionalAccess', _23 => _23.supportedChains]))) {
2980
+ const siwx = _optionalChain([ext, 'optionalAccess', _23 => _23["sign-in-with-x"]]);
2981
+ const info = _nullishCoalesce(_optionalChain([siwx, 'optionalAccess', _24 => _24.info]), () => ( siwx));
2982
+ if (info && info.chainId == null && Array.isArray(_optionalChain([siwx, 'optionalAccess', _25 => _25.supportedChains]))) {
2931
2983
  const evm = siwx.supportedChains.find(
2932
- (c) => typeof _optionalChain([c, 'optionalAccess', _24 => _24.chainId]) === "string" && c.chainId.startsWith("eip155:")
2984
+ (c) => typeof _optionalChain([c, 'optionalAccess', _26 => _26.chainId]) === "string" && c.chainId.startsWith("eip155:")
2933
2985
  );
2934
2986
  if (evm && typeof evm.chainId === "string") info.chainId = evm.chainId;
2935
2987
  }
@@ -3071,7 +3123,7 @@ function encodeBase642(str) {
3071
3123
  }
3072
3124
 
3073
3125
  // src/policy.ts
3074
- var DENOM_PRECISION = _chunkMWBT7MCEcjs.MAX_DECIMALS;
3126
+ var DENOM_PRECISION = _chunkGYM46G5Lcjs.MAX_DECIMALS;
3075
3127
  var BUILTIN_DENOMS = {
3076
3128
  USDC: "USD",
3077
3129
  USDT: "USD",
@@ -3085,7 +3137,7 @@ var BUILTIN_DENOMS = {
3085
3137
  function denomOf(symbol, asset, policy) {
3086
3138
  if (asset === "native") return void 0;
3087
3139
  const norm = (v) => typeof v === "string" && v.trim() !== "" ? v.trim().toUpperCase() : void 0;
3088
- const override = _optionalChain([policy, 'optionalAccess', _25 => _25.denomFor]);
3140
+ const override = _optionalChain([policy, 'optionalAccess', _27 => _27.denomFor]);
3089
3141
  if (override && typeof override === "object") {
3090
3142
  if (asset && asset in override) {
3091
3143
  const d = norm(override[asset]);
@@ -3186,7 +3238,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
3186
3238
  }
3187
3239
  }
3188
3240
  if (policy.maxAmount !== void 0) {
3189
- const cap = _chunkMWBT7MCEcjs.floorUnits.call(void 0, policy.maxAmount, intent.decimals);
3241
+ const cap = _chunkGYM46G5Lcjs.floorUnits.call(void 0, policy.maxAmount, intent.decimals);
3190
3242
  if (intent.amountBase > cap) {
3191
3243
  return deny(
3192
3244
  "MAX_AMOUNT",
@@ -3195,7 +3247,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
3195
3247
  }
3196
3248
  }
3197
3249
  if (policy.maxTotal !== void 0) {
3198
- const cap = _chunkMWBT7MCEcjs.floorUnits.call(void 0, policy.maxTotal, intent.decimals);
3250
+ const cap = _chunkGYM46G5Lcjs.floorUnits.call(void 0, policy.maxTotal, intent.decimals);
3199
3251
  if (spentForAssetBase + intent.amountBase > cap) {
3200
3252
  return deny(
3201
3253
  "MAX_TOTAL",
@@ -3214,7 +3266,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
3214
3266
  `token for ${denom} has more than ${DENOM_PRECISION} decimals \u2014 refusing to count it toward policy.maxTotalPerDenom.${denom} on trust (it can't be summed safely).`
3215
3267
  );
3216
3268
  }
3217
- const capScaled = _chunkMWBT7MCEcjs.floorUnits.call(void 0, capStr, DENOM_PRECISION);
3269
+ const capScaled = _chunkGYM46G5Lcjs.floorUnits.call(void 0, capStr, DENOM_PRECISION);
3218
3270
  if ((_nullishCoalesce(ctx.spentInDenomScaled, () => ( 0n))) + thisScaled > capScaled) {
3219
3271
  return deny(
3220
3272
  "MAX_TOTAL_DENOM",
@@ -3232,7 +3284,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
3232
3284
  }
3233
3285
  }
3234
3286
  if (ctx && policy.windowTotal !== void 0 && policy.windowSeconds !== void 0) {
3235
- const cap = _chunkMWBT7MCEcjs.floorUnits.call(void 0, policy.windowTotal, intent.decimals);
3287
+ const cap = _chunkGYM46G5Lcjs.floorUnits.call(void 0, policy.windowTotal, intent.decimals);
3236
3288
  if (ctx.spentInWindowBase + intent.amountBase > cap) {
3237
3289
  return deny(
3238
3290
  "WINDOW_TOTAL",
@@ -3286,7 +3338,7 @@ var SpendLedger = (_class = class {
3286
3338
  } catch (e30) {
3287
3339
  seed = [];
3288
3340
  }
3289
- for (const r of seed) this.ingest(r, _nullishCoalesce(_optionalChain([r, 'optionalAccess', _26 => _26.decimals]), () => ( 0)), _optionalChain([r, 'optionalAccess', _27 => _27.denom]));
3341
+ for (const r of seed) this.ingest(r, _nullishCoalesce(_optionalChain([r, 'optionalAccess', _28 => _28.decimals]), () => ( 0)), _optionalChain([r, 'optionalAccess', _29 => _29.denom]));
3290
3342
  }
3291
3343
  }
3292
3344
  /**
@@ -3298,7 +3350,7 @@ var SpendLedger = (_class = class {
3298
3350
  * read or the constructor.
3299
3351
  */
3300
3352
  isTallyable(r, decimals) {
3301
- return !!r && typeof r.amountBase === "string" && /^\d+$/.test(r.amountBase) && Number.isInteger(decimals) && decimals >= 0 && decimals <= _chunkMWBT7MCEcjs.MAX_DECIMALS;
3353
+ return !!r && typeof r.amountBase === "string" && /^\d+$/.test(r.amountBase) && Number.isInteger(decimals) && decimals >= 0 && decimals <= _chunkGYM46G5Lcjs.MAX_DECIMALS;
3302
3354
  }
3303
3355
  /** Apply a record to the in-memory tallies (records + per-asset bucket + denom total).
3304
3356
  * Shared by {@link record} and constructor hydration; does NOT persist. Returns the
@@ -3348,7 +3400,7 @@ var SpendLedger = (_class = class {
3348
3400
  }
3349
3401
  /** Running total (base units) already spent on this (network, asset). */
3350
3402
  totalFor(network, asset) {
3351
- return _nullishCoalesce(_optionalChain([this, 'access', _28 => _28.buckets, 'access', _29 => _29.get, 'call', _30 => _30(keyFor(network, asset)), 'optionalAccess', _31 => _31.total]), () => ( 0n));
3403
+ return _nullishCoalesce(_optionalChain([this, 'access', _30 => _30.buckets, 'access', _31 => _31.get, 'call', _32 => _32(keyFor(network, asset)), 'optionalAccess', _33 => _33.total]), () => ( 0n));
3352
3404
  }
3353
3405
  /**
3354
3406
  * Running grand total for a DENOMINATION, scaled to {@link DENOM_PRECISION} (so
@@ -3435,20 +3487,38 @@ var SpendLedger = (_class = class {
3435
3487
  symbol: b.symbol,
3436
3488
  decimals: b.decimals,
3437
3489
  totalBase: b.total.toString(),
3438
- totalFormatted: _chunkMWBT7MCEcjs.formatUnits.call(void 0, b.total, b.decimals),
3490
+ totalFormatted: _chunkGYM46G5Lcjs.formatUnits.call(void 0, b.total, b.decimals),
3439
3491
  count: b.count
3440
3492
  })),
3441
3493
  byDenom: [...this.denomTotals.entries()].map(([denom, scaled]) => ({
3442
3494
  denom,
3443
3495
  totalScaled: scaled.toString(),
3444
- totalFormatted: _chunkMWBT7MCEcjs.formatUnits.call(void 0, scaled, DENOM_PRECISION),
3445
- count: this.records.filter((r) => _optionalChain([r, 'access', _32 => _32.denom, 'optionalAccess', _33 => _33.toUpperCase, 'call', _34 => _34()]) === denom).length
3496
+ totalFormatted: _chunkGYM46G5Lcjs.formatUnits.call(void 0, scaled, DENOM_PRECISION),
3497
+ count: this.records.filter((r) => _optionalChain([r, 'access', _34 => _34.denom, 'optionalAccess', _35 => _35.toUpperCase, 'call', _36 => _36()]) === denom).length
3446
3498
  })),
3447
3499
  records: [...this.records]
3448
3500
  };
3449
3501
  }
3450
3502
  }, _class);
3451
3503
 
3504
+ // src/util/exactRecovery.ts
3505
+ function exactSettleCheckHint(family, payerFrom, nonce) {
3506
+ switch (family) {
3507
+ case "evm":
3508
+ return `the EIP-3009 \`authorizationState(${payerFrom}, ${nonce})\` (or, on the Permit2 method, the Permit2 nonce bitmap)`;
3509
+ case "solana":
3510
+ return `the buyer's transaction signature (a duplicate signature is the chain's own replay guard; plus the SPL-Memo nonce when present)`;
3511
+ case "algorand":
3512
+ return `the atomic group / transaction id`;
3513
+ case "aptos":
3514
+ return `the sender's account sequence number`;
3515
+ case "near":
3516
+ return `the access-key nonce (\`${nonce}\`)`;
3517
+ default:
3518
+ return `the single-use marker (\`ref=${nonce}\`)`;
3519
+ }
3520
+ }
3521
+
3452
3522
  // src/client.ts
3453
3523
  var DEFAULT_SCHEMES = ["onchain-proof"];
3454
3524
  var RECIPIENT_FIX = {
@@ -3660,17 +3730,17 @@ var PipRailClient = (_class2 = class {
3660
3730
  * {@link ReceiptVerification}).
3661
3731
  */
3662
3732
  static async verifyReceipt(receipt, opts) {
3663
- const r = _optionalChain([receipt, 'optionalAccess', _35 => _35.receipt]);
3733
+ const r = _optionalChain([receipt, 'optionalAccess', _37 => _37.receipt]);
3664
3734
  if (!r || typeof r !== "object") {
3665
3735
  return { ok: false, onChain: { payTo: "", asset: "", amount: "", payer: "" }, matchesClaims: false, ageSeconds: 0, error: "tx_not_found" };
3666
3736
  }
3667
3737
  const claimed = { payTo: _nullishCoalesce(r.payTo, () => ( "")), asset: _nullishCoalesce(r.asset, () => ( "")), amount: _nullishCoalesce(r.amount, () => ( "")), payer: _nullishCoalesce(r.payer, () => ( "")) };
3668
3738
  const ageSeconds = receiptAgeSeconds(r.verifiedAt);
3669
3739
  try {
3670
- const chain = chainSelectorForNetwork(r.network, _optionalChain([opts, 'optionalAccess', _36 => _36.rpcUrl]));
3740
+ const chain = chainSelectorForNetwork(r.network, _optionalChain([opts, 'optionalAccess', _38 => _38.rpcUrl]));
3671
3741
  const net = await resolveNetwork2({
3672
3742
  chain,
3673
- ..._optionalChain([opts, 'optionalAccess', _37 => _37.rpcUrl]) ? { rpcUrl: opts.rpcUrl } : {}
3743
+ ..._optionalChain([opts, 'optionalAccess', _39 => _39.rpcUrl]) ? { rpcUrl: opts.rpcUrl } : {}
3674
3744
  });
3675
3745
  const accept = {
3676
3746
  scheme: "onchain-proof",
@@ -3717,7 +3787,7 @@ var PipRailClient = (_class2 = class {
3717
3787
  * no chain libs. The JWS format defers to R3 (`{ ok:false, reason:'jws-not-loaded' }`).
3718
3788
  */
3719
3789
  static async verifyAttestation(receipt) {
3720
- const att = _optionalChain([receipt, 'optionalAccess', _38 => _38.attestation]);
3790
+ const att = _optionalChain([receipt, 'optionalAccess', _40 => _40.attestation]);
3721
3791
  if (!att || typeof att !== "object" || typeof att.signature !== "string") {
3722
3792
  return { ok: false, reason: "no-attestation" };
3723
3793
  }
@@ -3728,7 +3798,7 @@ var PipRailClient = (_class2 = class {
3728
3798
  if (!r || typeof r !== "object") return { ok: false, reason: "no-receipt" };
3729
3799
  const payload = _nullishCoalesce(att.payload, () => ( {}));
3730
3800
  const network = typeof payload.network === "string" ? payload.network : r.network;
3731
- const resourceUrl = typeof payload.resourceUrl === "string" ? payload.resourceUrl : _nullishCoalesce(_optionalChain([receipt, 'access', _39 => _39.resource, 'optionalAccess', _40 => _40.url]), () => ( ""));
3801
+ const resourceUrl = typeof payload.resourceUrl === "string" ? payload.resourceUrl : _nullishCoalesce(_optionalChain([receipt, 'access', _41 => _41.resource, 'optionalAccess', _42 => _42.url]), () => ( ""));
3732
3802
  const payer = typeof payload.payer === "string" ? payload.payer : r.payer;
3733
3803
  const issuedAt = typeof payload.issuedAt === "number" ? payload.issuedAt : receiptIssuedAtSeconds(r.verifiedAt);
3734
3804
  const transaction = typeof payload.transaction === "string" ? payload.transaction : _nullishCoalesce(r.transaction, () => ( ""));
@@ -3774,7 +3844,7 @@ var PipRailClient = (_class2 = class {
3774
3844
  * as-is) or a plain object (serialised as JSON).
3775
3845
  */
3776
3846
  post(url, body, init) {
3777
- const headers = new Headers(_optionalChain([init, 'optionalAccess', _41 => _41.headers]));
3847
+ const headers = new Headers(_optionalChain([init, 'optionalAccess', _43 => _43.headers]));
3778
3848
  let payload;
3779
3849
  if (body === void 0 || body === null) {
3780
3850
  payload = void 0;
@@ -3805,7 +3875,7 @@ var PipRailClient = (_class2 = class {
3805
3875
  * "0.05 USDC on Base, within budget → pay it." No funds move.
3806
3876
  */
3807
3877
  async quote(url, init) {
3808
- const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), method: _nullishCoalesce(_optionalChain([init, 'optionalAccess', _42 => _42.method]), () => ( "GET")) });
3878
+ const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), method: _nullishCoalesce(_optionalChain([init, 'optionalAccess', _44 => _44.method]), () => ( "GET")) });
3809
3879
  if (res.status !== 402) return null;
3810
3880
  const { quote } = await this.resolveChallenge(url, res, this.resolveSchemes());
3811
3881
  return quote;
@@ -3824,14 +3894,14 @@ var PipRailClient = (_class2 = class {
3824
3894
  * on Tron, where a USD₮ transfer can cost real TRX.
3825
3895
  */
3826
3896
  async estimateCost(url, init) {
3827
- const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), method: _nullishCoalesce(_optionalChain([init, 'optionalAccess', _43 => _43.method]), () => ( "GET")) });
3897
+ const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), method: _nullishCoalesce(_optionalChain([init, 'optionalAccess', _45 => _45.method]), () => ( "GET")) });
3828
3898
  if (res.status !== 402) return null;
3829
3899
  try {
3830
3900
  const { net, accept, quote } = await this.resolveChallenge(url, res, this.resolveSchemes());
3831
3901
  const cost = await net.estimateCost(accept);
3832
3902
  return { quote, cost };
3833
3903
  } catch (err) {
3834
- if (err instanceof _chunkMWBT7MCEcjs.InvalidEnvelopeError) return null;
3904
+ if (err instanceof _chunkGYM46G5Lcjs.InvalidEnvelopeError) return null;
3835
3905
  throw err;
3836
3906
  }
3837
3907
  }
@@ -3862,8 +3932,8 @@ var PipRailClient = (_class2 = class {
3862
3932
  return {
3863
3933
  session: {
3864
3934
  start,
3865
- expiresAt: _optionalChain([view, 'optionalAccess', _44 => _44.expiresAt]) != null ? new Date(view.expiresAt).toISOString() : null,
3866
- secondsRemaining: _nullishCoalesce(_optionalChain([view, 'optionalAccess', _45 => _45.secondsRemaining]), () => ( null))
3935
+ expiresAt: _optionalChain([view, 'optionalAccess', _46 => _46.expiresAt]) != null ? new Date(view.expiresAt).toISOString() : null,
3936
+ secondsRemaining: _nullishCoalesce(_optionalChain([view, 'optionalAccess', _47 => _47.secondsRemaining]), () => ( null))
3867
3937
  },
3868
3938
  byAsset: this.remaining(),
3869
3939
  byDenom: this.denomRemaining(),
@@ -3878,19 +3948,19 @@ var PipRailClient = (_class2 = class {
3878
3948
  * price-converted figure (tokens grouped as one unit, each 1:1).
3879
3949
  */
3880
3950
  denomRemaining() {
3881
- const caps = _optionalChain([this, 'access', _46 => _46.opts, 'access', _47 => _47.policy, 'optionalAccess', _48 => _48.maxTotalPerDenom]);
3951
+ const caps = _optionalChain([this, 'access', _48 => _48.opts, 'access', _49 => _49.policy, 'optionalAccess', _50 => _50.maxTotalPerDenom]);
3882
3952
  if (!caps) return [];
3883
3953
  return Object.entries(caps).map(([rawDenom, capStr]) => {
3884
3954
  const denom = rawDenom.toUpperCase();
3885
3955
  const spentScaled = this.ledger.totalForDenom(denom);
3886
- const capScaled = _chunkMWBT7MCEcjs.floorUnits.call(void 0, capStr, DENOM_PRECISION);
3956
+ const capScaled = _chunkGYM46G5Lcjs.floorUnits.call(void 0, capStr, DENOM_PRECISION);
3887
3957
  const remainingScaled = capScaled > spentScaled ? capScaled - spentScaled : 0n;
3888
3958
  const fraction = capScaled === 0n ? spentScaled > 0n ? 1 : 0 : Number(spentScaled * 1000000n / capScaled) / 1e6;
3889
3959
  return {
3890
3960
  denom,
3891
- spentFormatted: _chunkMWBT7MCEcjs.formatUnits.call(void 0, spentScaled, DENOM_PRECISION),
3892
- capFormatted: _chunkMWBT7MCEcjs.formatUnits.call(void 0, capScaled, DENOM_PRECISION),
3893
- remainingFormatted: _chunkMWBT7MCEcjs.formatUnits.call(void 0, remainingScaled, DENOM_PRECISION),
3961
+ spentFormatted: _chunkGYM46G5Lcjs.formatUnits.call(void 0, spentScaled, DENOM_PRECISION),
3962
+ capFormatted: _chunkGYM46G5Lcjs.formatUnits.call(void 0, capScaled, DENOM_PRECISION),
3963
+ remainingFormatted: _chunkGYM46G5Lcjs.formatUnits.call(void 0, remainingScaled, DENOM_PRECISION),
3894
3964
  fraction
3895
3965
  };
3896
3966
  });
@@ -3901,11 +3971,11 @@ var PipRailClient = (_class2 = class {
3901
3971
  const policy = this.opts.policy;
3902
3972
  const settled = this.ledger.count();
3903
3973
  const out = { settled };
3904
- if (_optionalChain([policy, 'optionalAccess', _49 => _49.maxPayments]) !== void 0) {
3974
+ if (_optionalChain([policy, 'optionalAccess', _51 => _51.maxPayments]) !== void 0) {
3905
3975
  out.lifetimeCap = policy.maxPayments;
3906
3976
  out.lifetimeRemaining = Math.max(0, policy.maxPayments - settled);
3907
3977
  }
3908
- if (_optionalChain([policy, 'optionalAccess', _50 => _50.maxPaymentsPerWindow]) !== void 0 && policy.windowSeconds !== void 0) {
3978
+ if (_optionalChain([policy, 'optionalAccess', _52 => _52.maxPaymentsPerWindow]) !== void 0 && policy.windowSeconds !== void 0) {
3909
3979
  const windowSettled = this.ledger.countSince(Date.now() - policy.windowSeconds * 1e3);
3910
3980
  out.windowCap = policy.maxPaymentsPerWindow;
3911
3981
  out.windowSettled = windowSettled;
@@ -3921,7 +3991,7 @@ var PipRailClient = (_class2 = class {
3921
3991
  * never throws, never sums across tokens (no price oracle). PROCESS-SCOPED.
3922
3992
  */
3923
3993
  remaining() {
3924
- const maxTotal = _optionalChain([this, 'access', _51 => _51.opts, 'access', _52 => _52.policy, 'optionalAccess', _53 => _53.maxTotal]);
3994
+ const maxTotal = _optionalChain([this, 'access', _53 => _53.opts, 'access', _54 => _54.policy, 'optionalAccess', _55 => _55.maxTotal]);
3925
3995
  return this.ledger.assetBuckets().map((b) => {
3926
3996
  const base2 = {
3927
3997
  network: b.network,
@@ -3931,13 +4001,13 @@ var PipRailClient = (_class2 = class {
3931
4001
  spentBase: b.totalBase.toString()
3932
4002
  };
3933
4003
  if (maxTotal === void 0) return base2;
3934
- const capBase = _chunkMWBT7MCEcjs.floorUnits.call(void 0, maxTotal, b.decimals);
4004
+ const capBase = _chunkGYM46G5Lcjs.floorUnits.call(void 0, maxTotal, b.decimals);
3935
4005
  const remainingBase = capBase > b.totalBase ? capBase - b.totalBase : 0n;
3936
4006
  return {
3937
4007
  ...base2,
3938
4008
  capBase: capBase.toString(),
3939
4009
  remainingBase: remainingBase.toString(),
3940
- remainingFormatted: _chunkMWBT7MCEcjs.formatUnits.call(void 0, remainingBase, b.decimals)
4010
+ remainingFormatted: _chunkGYM46G5Lcjs.formatUnits.call(void 0, remainingBase, b.decimals)
3941
4011
  };
3942
4012
  });
3943
4013
  }
@@ -3973,15 +4043,15 @@ var PipRailClient = (_class2 = class {
3973
4043
  * the plan yourself. No funds move.
3974
4044
  */
3975
4045
  async planPayment(url, init) {
3976
- const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), method: _nullishCoalesce(_optionalChain([init, 'optionalAccess', _54 => _54.method]), () => ( "GET")) });
4046
+ const res = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), method: _nullishCoalesce(_optionalChain([init, 'optionalAccess', _56 => _56.method]), () => ( "GET")) });
3977
4047
  if (res.status !== 402) return null;
3978
4048
  const challenge = await parseChallenge(res);
3979
4049
  if (!challenge) {
3980
- throw new (0, _chunkMWBT7MCEcjs.InvalidEnvelopeError)("402 response did not include a parseable x402 challenge.");
4050
+ throw new (0, _chunkGYM46G5Lcjs.InvalidEnvelopeError)("402 response did not include a parseable x402 challenge.");
3981
4051
  }
3982
4052
  const { net, wallet } = await this.ensure();
3983
4053
  if (!wallet) {
3984
- throw new (0, _chunkMWBT7MCEcjs.WalletRequiredError)(
4054
+ throw new (0, _chunkGYM46G5Lcjs.WalletRequiredError)(
3985
4055
  "planPayment needs a wallet (it checks YOUR balance, gas, and recipient-readiness). This client is read-only \u2014 construct it with a `wallet` to plan or pay."
3986
4056
  );
3987
4057
  }
@@ -4014,7 +4084,8 @@ var PipRailClient = (_class2 = class {
4014
4084
  * before publishing, so retry with a brief backoff if a fresh listing is missing.
4015
4085
  * - Results are cross-scheme (mostly the mainstream `exact` scheme); `fetch()` pays
4016
4086
  * `onchain-proof` rails by default, and standard `exact` rails too once you opt in
4017
- * with `schemes: ['onchain-proof', 'exact']` (EVM EIP-3009/Permit2 + Solana SVM + Algorand).
4087
+ * with `schemes: ['onchain-proof', 'exact']` (EVM EIP-3009/Permit2 + Solana SVM + Algorand
4088
+ * + Aptos + NEAR).
4018
4089
  */
4019
4090
  async discover(opts = {}) {
4020
4091
  const found = await searchOpenIndexes({
@@ -4154,31 +4225,31 @@ var PipRailClient = (_class2 = class {
4154
4225
  * streams throw `NonReplayableBodyError`.
4155
4226
  */
4156
4227
  async fetch(url, init) {
4157
- const body = _optionalChain([init, 'optionalAccess', _55 => _55.body]);
4228
+ const body = _optionalChain([init, 'optionalAccess', _57 => _57.body]);
4158
4229
  if (body !== void 0 && body !== null && !isReplayableBodyInit(body)) {
4159
- throw new (0, _chunkMWBT7MCEcjs.NonReplayableBodyError)(
4230
+ throw new (0, _chunkGYM46G5Lcjs.NonReplayableBodyError)(
4160
4231
  "fetch(): init.body is not replayable. Pass a string, FormData, URLSearchParams, ArrayBuffer, or Blob \u2014 not a ReadableStream."
4161
4232
  );
4162
4233
  }
4163
4234
  const firstResponse = await fetch(url, init);
4164
4235
  if (firstResponse.status !== 402) return firstResponse;
4165
- const schemes = this.resolveSchemes(_optionalChain([init, 'optionalAccess', _56 => _56.schemes]));
4236
+ const schemes = this.resolveSchemes(_optionalChain([init, 'optionalAccess', _58 => _58.schemes]));
4166
4237
  const resolved = await this.resolveChallenge(url, firstResponse, schemes);
4167
4238
  const { net, wallet, challenge } = resolved;
4168
4239
  if (!wallet) {
4169
- throw new (0, _chunkMWBT7MCEcjs.WalletRequiredError)(
4240
+ throw new (0, _chunkGYM46G5Lcjs.WalletRequiredError)(
4170
4241
  "Paying a 402 needs a wallet to sign + settle. This client is read-only \u2014 construct it with a `wallet` to pay (quote/discover/register still work without one)."
4171
4242
  );
4172
4243
  }
4173
4244
  let accept = resolved.accept;
4174
4245
  let quote = resolved.quote;
4175
- const autoRoute = _nullishCoalesce(_nullishCoalesce(_optionalChain([init, 'optionalAccess', _57 => _57.autoRoute]), () => ( this.opts.autoRoute)), () => ( false));
4246
+ const autoRoute = _nullishCoalesce(_nullishCoalesce(_optionalChain([init, 'optionalAccess', _59 => _59.autoRoute]), () => ( this.opts.autoRoute)), () => ( false));
4176
4247
  if (autoRoute) {
4177
4248
  const plan = await this.planFromChallenge(net, wallet, challenge, url, schemes);
4178
4249
  if (!plan.best) {
4179
4250
  const reason = _nullishCoalesce(plan.fundingHint, () => ( "No rail is settleable for this payment."));
4180
4251
  this.safeEmit({ kind: "payment-failed", reason });
4181
- throw new (0, _chunkMWBT7MCEcjs.PaymentDeclinedError)(reason);
4252
+ throw new (0, _chunkGYM46G5Lcjs.PaymentDeclinedError)(reason);
4182
4253
  }
4183
4254
  accept = plan.best.accept;
4184
4255
  quote = plan.best.quote;
@@ -4192,7 +4263,7 @@ var PipRailClient = (_class2 = class {
4192
4263
  return this.payExactRail(net, wallet, accept, url, init, quote);
4193
4264
  }
4194
4265
  if (accept.scheme !== "onchain-proof") {
4195
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
4266
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
4196
4267
  `internal: unrouted accept scheme '${accept.scheme}' reached the onchain-proof pay path.`
4197
4268
  );
4198
4269
  }
@@ -4210,7 +4281,7 @@ var PipRailClient = (_class2 = class {
4210
4281
  async resolveChallenge(url, response, schemes) {
4211
4282
  const challenge = await parseChallenge(response);
4212
4283
  if (!challenge) {
4213
- throw new (0, _chunkMWBT7MCEcjs.InvalidEnvelopeError)(
4284
+ throw new (0, _chunkGYM46G5Lcjs.InvalidEnvelopeError)(
4214
4285
  "402 response did not include a parseable x402 challenge."
4215
4286
  );
4216
4287
  }
@@ -4221,8 +4292,8 @@ var PipRailClient = (_class2 = class {
4221
4292
  (a) => a.scheme === "exact" && this.supportsNetwork(net, a.network)
4222
4293
  );
4223
4294
  if (schemes.includes("exact") && exactOnNet && typeof net.payExact !== "function") {
4224
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
4225
- `This 402 offers a standard 'exact' rail on ${net.network}, but the ${net.family} family can't pay 'exact' (supported on EVM, Solana, Algorand + NEAR today), and no 'onchain-proof' rail was offered.`
4295
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
4296
+ `This 402 offers a standard 'exact' rail on ${net.network}, but the ${net.family} family can't pay 'exact' (supported on EVM, Solana, Algorand, Aptos + NEAR today), and no 'onchain-proof' rail was offered.`
4226
4297
  );
4227
4298
  }
4228
4299
  if (!schemes.includes("exact") && exactOnNet && typeof net.payExact === "function") {
@@ -4230,13 +4301,13 @@ var PipRailClient = (_class2 = class {
4230
4301
  (a) => a.scheme === "exact" && this.supportsNetwork(net, a.network) && net.describeAsset(a.asset) != null
4231
4302
  );
4232
4303
  if (payable) {
4233
- throw new (0, _chunkMWBT7MCEcjs.NoCompatibleAcceptError)(
4304
+ throw new (0, _chunkGYM46G5Lcjs.NoCompatibleAcceptError)(
4234
4305
  `This 402 is payable only via the standard 'exact' rail on ${net.network}, which is OFF by default. Enable it: new PipRailClient({ \u2026, schemes: ['onchain-proof', 'exact'] }) or per call fetch(url, { schemes: ['exact'] }) (MCP: PIPRAIL_SCHEMES=onchain-proof,exact).`
4235
4306
  );
4236
4307
  }
4237
4308
  }
4238
4309
  const networks = [...new Set(challenge.accepts.map((a) => a.network))].join(", ");
4239
- throw new (0, _chunkMWBT7MCEcjs.NoCompatibleAcceptError)(
4310
+ throw new (0, _chunkGYM46G5Lcjs.NoCompatibleAcceptError)(
4240
4311
  `No accepts[] entry payable by this client on ${net.network} (schemes: ${schemes.join(", ")}; challenge offered: ${networks || "none"}).`
4241
4312
  );
4242
4313
  }
@@ -4275,7 +4346,15 @@ var PipRailClient = (_class2 = class {
4275
4346
  if (schemes.includes("exact")) {
4276
4347
  out.push(
4277
4348
  ...challenge.accepts.filter(
4278
- (a) => a.scheme === "exact" && this.supportsNetwork(net, a.network) && typeof net.payExact === "function" && net.describeAsset(a.asset) != null && // a foreign rail's maxTimeoutSeconds must be a usable positive integer, or
4349
+ (a) => a.scheme === "exact" && this.supportsNetwork(net, a.network) && typeof net.payExact === "function" && // `native` is never `exact`-payable on ANY family (exact = an EIP-3009/Permit2-style
4350
+ // signed-authorization scheme a native coin can't support; every driver's payExact
4351
+ // throws/returns-null for it). describeAsset('native') IS non-null (onchain-proof needs
4352
+ // it), so without this guard a malformed 402 advertising a native `exact` rail would be
4353
+ // gathered, planned `payable`, even chosen by autoRoute — then throw at pay time.
4354
+ a.asset !== "native" && // the exact pay path (payExact → driver) reads `extra.assetTransferMethod`; a malformed
4355
+ // 402 offering an exact rail for a RECOGNISED token but omitting `extra` would otherwise
4356
+ // be planned payable then throw a raw TypeError mid-pay. Require it at gather time.
4357
+ typeof _optionalChain([a, 'access', _60 => _60.extra, 'optionalAccess', _61 => _61.assetTransferMethod]) === "string" && net.describeAsset(a.asset) != null && // a foreign rail's maxTimeoutSeconds must be a usable positive integer, or
4279
4358
  // signing it would build a NaN/garbage validBefore — drop it silently
4280
4359
  // (symmetric with an unrecognised token) rather than leak a raw SyntaxError.
4281
4360
  Number.isInteger(a.maxTimeoutSeconds) && a.maxTimeoutSeconds > 0
@@ -4285,7 +4364,8 @@ var PipRailClient = (_class2 = class {
4285
4364
  if (schemes.includes("upto")) {
4286
4365
  out.push(
4287
4366
  ...challenge.accepts.filter(
4288
- (a) => a.scheme === "upto" && this.supportsNetwork(net, a.network) && typeof net.payUpto === "function" && net.describeAsset(a.asset) != null && typeof _optionalChain([a, 'access', _58 => _58.extra, 'optionalAccess', _59 => _59.facilitatorAddress]) === "string" && a.extra.facilitatorAddress.length > 0 && Number.isInteger(a.maxTimeoutSeconds) && a.maxTimeoutSeconds > 0
4367
+ (a) => a.scheme === "upto" && this.supportsNetwork(net, a.network) && typeof net.payUpto === "function" && a.asset !== "native" && // native is not upto-payable either (same reason as exact)
4368
+ net.describeAsset(a.asset) != null && typeof _optionalChain([a, 'access', _62 => _62.extra, 'optionalAccess', _63 => _63.facilitatorAddress]) === "string" && a.extra.facilitatorAddress.length > 0 && Number.isInteger(a.maxTimeoutSeconds) && a.maxTimeoutSeconds > 0
4289
4369
  )
4290
4370
  );
4291
4371
  }
@@ -4356,21 +4436,21 @@ var PipRailClient = (_class2 = class {
4356
4436
  if (isExact) {
4357
4437
  if (tokenKnown && bal.token < amount) {
4358
4438
  blockers.push("INSUFFICIENT_TOKEN");
4359
- shortfall.token = _chunkMWBT7MCEcjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
4439
+ shortfall.token = _chunkGYM46G5Lcjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
4360
4440
  }
4361
4441
  } else if (isNative) {
4362
4442
  if (nativeKnown && bal.native < amount + fee) {
4363
4443
  blockers.push("INSUFFICIENT_TOKEN");
4364
- shortfall.token = _chunkMWBT7MCEcjs.formatUnits.call(void 0, amount + fee - bal.native, quote.decimals);
4444
+ shortfall.token = _chunkGYM46G5Lcjs.formatUnits.call(void 0, amount + fee - bal.native, quote.decimals);
4365
4445
  }
4366
4446
  } else {
4367
4447
  if (tokenKnown && bal.token < amount) {
4368
4448
  blockers.push("INSUFFICIENT_TOKEN");
4369
- shortfall.token = _chunkMWBT7MCEcjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
4449
+ shortfall.token = _chunkGYM46G5Lcjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
4370
4450
  }
4371
4451
  if (nativeKnown && bal.native < fee) {
4372
4452
  blockers.push("INSUFFICIENT_GAS");
4373
- shortfall.native = _chunkMWBT7MCEcjs.formatUnits.call(void 0, fee - bal.native, cost.feeDecimals);
4453
+ shortfall.native = _chunkGYM46G5Lcjs.formatUnits.call(void 0, fee - bal.native, cost.feeDecimals);
4374
4454
  } else if (nativeKnown && fee > 0n && bal.native < fee * 3n / 2n) {
4375
4455
  warnings.push("THIN_GAS_MARGIN");
4376
4456
  }
@@ -4395,8 +4475,8 @@ var PipRailClient = (_class2 = class {
4395
4475
  blockers,
4396
4476
  warnings,
4397
4477
  balance: {
4398
- token: bal.token != null ? _chunkMWBT7MCEcjs.formatUnits.call(void 0, bal.token, quote.decimals) : null,
4399
- native: bal.native != null ? _chunkMWBT7MCEcjs.formatUnits.call(void 0, bal.native, cost.feeDecimals) : null
4478
+ token: bal.token != null ? _chunkGYM46G5Lcjs.formatUnits.call(void 0, bal.token, quote.decimals) : null,
4479
+ native: bal.native != null ? _chunkGYM46G5Lcjs.formatUnits.call(void 0, bal.native, cost.feeDecimals) : null
4400
4480
  },
4401
4481
  need: { token: quote.amountFormatted, native: cost.feeFormatted },
4402
4482
  ...shortfall.token || shortfall.native ? { shortfall } : {},
@@ -4407,30 +4487,30 @@ var PipRailClient = (_class2 = class {
4407
4487
  * driver's describeAsset) + the policy verdict + a symbol-mismatch flag. */
4408
4488
  buildQuote(net, accept, url, description) {
4409
4489
  if (typeof accept.amount !== "string" || !/^\d+$/.test(accept.amount)) {
4410
- throw new (0, _chunkMWBT7MCEcjs.InvalidEnvelopeError)(
4490
+ throw new (0, _chunkGYM46G5Lcjs.InvalidEnvelopeError)(
4411
4491
  `challenge amount "${String(accept.amount)}" is not a base-unit integer string.`
4412
4492
  );
4413
4493
  }
4414
4494
  if (typeof accept.asset !== "string" || accept.asset.length === 0) {
4415
- throw new (0, _chunkMWBT7MCEcjs.InvalidEnvelopeError)(
4495
+ throw new (0, _chunkGYM46G5Lcjs.InvalidEnvelopeError)(
4416
4496
  `challenge on ${accept.network} states no (string) asset \u2014 refusing to price it.`
4417
4497
  );
4418
4498
  }
4419
4499
  const amountBase = BigInt(accept.amount);
4420
4500
  const described = net.describeAsset(accept.asset);
4421
- const decimals = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _60 => _60.decimals]), () => ( _optionalChain([accept, 'access', _61 => _61.extra, 'optionalAccess', _62 => _62.decimals])));
4501
+ const decimals = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _64 => _64.decimals]), () => ( _optionalChain([accept, 'access', _65 => _65.extra, 'optionalAccess', _66 => _66.decimals])));
4422
4502
  if (typeof decimals !== "number" || !Number.isInteger(decimals) || decimals < 0) {
4423
- throw new (0, _chunkMWBT7MCEcjs.InvalidEnvelopeError)(
4503
+ throw new (0, _chunkGYM46G5Lcjs.InvalidEnvelopeError)(
4424
4504
  `challenge for ${accept.asset} on ${accept.network} states no valid decimals and the SDK doesn't recognise the token \u2014 refusing to price it.`
4425
4505
  );
4426
4506
  }
4427
- if (decimals > _chunkMWBT7MCEcjs.MAX_DECIMALS) {
4428
- throw new (0, _chunkMWBT7MCEcjs.InvalidEnvelopeError)(
4429
- `challenge for ${accept.asset} on ${accept.network} states ${decimals} decimals (> ${_chunkMWBT7MCEcjs.MAX_DECIMALS}) \u2014 refusing to price it (no real token is that deep).`
4507
+ if (decimals > _chunkGYM46G5Lcjs.MAX_DECIMALS) {
4508
+ throw new (0, _chunkGYM46G5Lcjs.InvalidEnvelopeError)(
4509
+ `challenge for ${accept.asset} on ${accept.network} states ${decimals} decimals (> ${_chunkGYM46G5Lcjs.MAX_DECIMALS}) \u2014 refusing to price it (no real token is that deep).`
4430
4510
  );
4431
4511
  }
4432
- const symbol = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _63 => _63.symbol]), () => ( _optionalChain([accept, 'access', _64 => _64.extra, 'optionalAccess', _65 => _65.symbol])));
4433
- const amountFormatted = _chunkMWBT7MCEcjs.formatUnits.call(void 0, amountBase, decimals);
4512
+ const symbol = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _67 => _67.symbol]), () => ( _optionalChain([accept, 'access', _68 => _68.extra, 'optionalAccess', _69 => _69.symbol])));
4513
+ const amountFormatted = _chunkGYM46G5Lcjs.formatUnits.call(void 0, amountBase, decimals);
4434
4514
  const intent = {
4435
4515
  host: hostOf2(url),
4436
4516
  chain: this.opts.chain,
@@ -4471,7 +4551,7 @@ var PipRailClient = (_class2 = class {
4471
4551
  this.ledger.totalFor(accept.network, accept.asset),
4472
4552
  ctx
4473
4553
  );
4474
- const serverSymbol = _optionalChain([accept, 'access', _66 => _66.extra, 'optionalAccess', _67 => _67.symbol]);
4554
+ const serverSymbol = _optionalChain([accept, 'access', _70 => _70.extra, 'optionalAccess', _71 => _71.symbol]);
4475
4555
  const symbolMismatch = intent.recognized && !!serverSymbol && !!symbol && serverSymbol.toUpperCase() !== symbol.toUpperCase();
4476
4556
  return {
4477
4557
  url,
@@ -4535,7 +4615,7 @@ var PipRailClient = (_class2 = class {
4535
4615
  ...opts.quote ? { quote: opts.quote } : {},
4536
4616
  budget: this.budget()
4537
4617
  });
4538
- throw new (0, _chunkMWBT7MCEcjs.PaymentDeclinedError)(reason, {
4618
+ throw new (0, _chunkGYM46G5Lcjs.PaymentDeclinedError)(reason, {
4539
4619
  ...opts.reasonCode ? { reasonCode: opts.reasonCode } : {},
4540
4620
  ...opts.cause !== void 0 ? { cause: opts.cause } : {}
4541
4621
  });
@@ -4567,7 +4647,7 @@ var PipRailClient = (_class2 = class {
4567
4647
  const max = BigInt(quote.amount);
4568
4648
  const shown = claimed < max ? claimed : max;
4569
4649
  settledBase = shown.toString();
4570
- settledFormatted = _chunkMWBT7MCEcjs.formatUnits.call(void 0, shown, quote.decimals);
4650
+ settledFormatted = _chunkGYM46G5Lcjs.formatUnits.call(void 0, shown, quote.decimals);
4571
4651
  } catch (e36) {
4572
4652
  }
4573
4653
  }
@@ -4603,7 +4683,7 @@ var PipRailClient = (_class2 = class {
4603
4683
  * `warnAtFraction` is set. Reads the just-computed {@link SessionBudget}; isolated (safeEmit).
4604
4684
  */
4605
4685
  emitThresholds(budget) {
4606
- const frac = _optionalChain([this, 'access', _68 => _68.opts, 'access', _69 => _69.policy, 'optionalAccess', _70 => _70.warnAtFraction]);
4686
+ const frac = _optionalChain([this, 'access', _72 => _72.opts, 'access', _73 => _73.policy, 'optionalAccess', _74 => _74.warnAtFraction]);
4607
4687
  if (frac === void 0) return;
4608
4688
  const fire = (scope, label, spentFormatted, capFormatted, fraction) => {
4609
4689
  if (fraction < frac) return;
@@ -4618,8 +4698,8 @@ var PipRailClient = (_class2 = class {
4618
4698
  fire(
4619
4699
  "asset",
4620
4700
  `${_nullishCoalesce(r.symbol, () => ( r.asset))} on ${r.network}`,
4621
- _chunkMWBT7MCEcjs.formatUnits.call(void 0, spent, r.decimals),
4622
- _chunkMWBT7MCEcjs.formatUnits.call(void 0, cap, r.decimals),
4701
+ _chunkGYM46G5Lcjs.formatUnits.call(void 0, spent, r.decimals),
4702
+ _chunkGYM46G5Lcjs.formatUnits.call(void 0, cap, r.decimals),
4623
4703
  fraction
4624
4704
  );
4625
4705
  }
@@ -4627,17 +4707,17 @@ var PipRailClient = (_class2 = class {
4627
4707
  fire("denom", d.denom, d.spentFormatted, d.capFormatted, d.fraction);
4628
4708
  }
4629
4709
  const policy = this.opts.policy;
4630
- if (_optionalChain([policy, 'optionalAccess', _71 => _71.windowTotal]) !== void 0 && policy.windowSeconds !== void 0) {
4710
+ if (_optionalChain([policy, 'optionalAccess', _75 => _75.windowTotal]) !== void 0 && policy.windowSeconds !== void 0) {
4631
4711
  const since = Date.now() - policy.windowSeconds * 1e3;
4632
4712
  for (const r of budget.byAsset) {
4633
- const cap = _chunkMWBT7MCEcjs.floorUnits.call(void 0, policy.windowTotal, r.decimals);
4713
+ const cap = _chunkGYM46G5Lcjs.floorUnits.call(void 0, policy.windowTotal, r.decimals);
4634
4714
  const spent = this.ledger.totalSince(r.network, r.asset, since);
4635
4715
  const fraction = cap === 0n ? spent > 0n ? 1 : 0 : Number(spent * 1000000n / cap) / 1e6;
4636
4716
  fire(
4637
4717
  "window",
4638
4718
  `${_nullishCoalesce(r.symbol, () => ( r.asset))} on ${r.network}`,
4639
- _chunkMWBT7MCEcjs.formatUnits.call(void 0, spent, r.decimals),
4640
- _chunkMWBT7MCEcjs.formatUnits.call(void 0, cap, r.decimals),
4719
+ _chunkGYM46G5Lcjs.formatUnits.call(void 0, spent, r.decimals),
4720
+ _chunkGYM46G5Lcjs.formatUnits.call(void 0, cap, r.decimals),
4641
4721
  fraction
4642
4722
  );
4643
4723
  }
@@ -4658,14 +4738,14 @@ var PipRailClient = (_class2 = class {
4658
4738
  }
4659
4739
  async payAndConfirm(net, wallet, accept) {
4660
4740
  if (!this.supportsNetwork(net, accept.network)) {
4661
- throw new (0, _chunkMWBT7MCEcjs.WrongChainError)(
4741
+ throw new (0, _chunkGYM46G5Lcjs.WrongChainError)(
4662
4742
  `Challenge expects ${accept.network} but client is on ${net.network}.`
4663
4743
  );
4664
4744
  }
4665
4745
  const ref = await net.send(wallet, accept);
4666
4746
  this.safeEmit({ kind: "payment-broadcast", ref });
4667
4747
  try {
4668
- const { height } = await net.confirm(ref, _nullishCoalesce(_optionalChain([accept, 'access', _72 => _72.extra, 'optionalAccess', _73 => _73.minConfirmations]), () => ( 1)));
4748
+ const { height } = await net.confirm(ref, _nullishCoalesce(_optionalChain([accept, 'access', _76 => _76.extra, 'optionalAccess', _77 => _77.minConfirmations]), () => ( 1)));
4669
4749
  this.safeEmit({
4670
4750
  kind: "payment-confirmed",
4671
4751
  ref,
@@ -4685,9 +4765,9 @@ var PipRailClient = (_class2 = class {
4685
4765
  const signature = {
4686
4766
  x402Version: 2,
4687
4767
  accepted: accept,
4688
- payload: { nonce: _optionalChain([accept, 'access', _74 => _74.extra, 'optionalAccess', _75 => _75.nonce]), txHash: ref }
4768
+ payload: { nonce: _optionalChain([accept, 'access', _78 => _78.extra, 'optionalAccess', _79 => _79.nonce]), txHash: ref }
4689
4769
  };
4690
- const headers = new Headers(_optionalChain([originalInit, 'optionalAccess', _76 => _76.headers]));
4770
+ const headers = new Headers(_optionalChain([originalInit, 'optionalAccess', _80 => _80.headers]));
4691
4771
  headers.set(HEADER_SIGNATURE, buildSignatureHeader(signature));
4692
4772
  let lastResponse = null;
4693
4773
  let lastReason = null;
@@ -4702,7 +4782,7 @@ var PipRailClient = (_class2 = class {
4702
4782
  () => timeoutController.abort(),
4703
4783
  this.retryTimeoutMs
4704
4784
  );
4705
- const signal = _optionalChain([originalInit, 'optionalAccess', _77 => _77.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, originalInit.signal]) : timeoutController.signal;
4785
+ const signal = _optionalChain([originalInit, 'optionalAccess', _81 => _81.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, originalInit.signal]) : timeoutController.signal;
4706
4786
  try {
4707
4787
  lastResponse = await fetch(url, {
4708
4788
  ..._nullishCoalesce(originalInit, () => ( {})),
@@ -4711,7 +4791,7 @@ var PipRailClient = (_class2 = class {
4711
4791
  });
4712
4792
  } catch (err) {
4713
4793
  if (timeoutController.signal.aborted) {
4714
- throw new (0, _chunkMWBT7MCEcjs.PaymentTimeoutError)(
4794
+ throw new (0, _chunkGYM46G5Lcjs.PaymentTimeoutError)(
4715
4795
  `Server did not respond within ${this.retryTimeoutMs}ms after broadcasting payment ${ref}. Re-verify or re-submit ref=${ref} \u2014 do NOT re-pay.`,
4716
4796
  { cause: err, ref }
4717
4797
  );
@@ -4735,7 +4815,7 @@ var PipRailClient = (_class2 = class {
4735
4815
  reason: `server returned 402 after broadcasting payment ${ref}${unconfirmedNote} (${why})`,
4736
4816
  ...lastReason ? { code: lastReason.error, detail: lastReason.detail } : {}
4737
4817
  });
4738
- throw new (0, _chunkMWBT7MCEcjs.MaxRetriesExceededError)(
4818
+ throw new (0, _chunkGYM46G5Lcjs.MaxRetriesExceededError)(
4739
4819
  `Server still returned 402 after ${attempts} attempt(s) with on-chain proof ref=${ref}${unconfirmedNote}. Last server rejection: ${why}. Re-verify or re-submit ref=${ref} before retrying \u2014 never re-pay (it would double-spend).`,
4740
4820
  { ref }
4741
4821
  );
@@ -4759,17 +4839,17 @@ var PipRailClient = (_class2 = class {
4759
4839
  */
4760
4840
  async payExactRail(net, wallet, accept, url, init, quote) {
4761
4841
  if (!net.payExact) {
4762
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
4763
- `the ${net.family} family can't pay a standard 'exact' rail (supported on EVM, Solana, Algorand + NEAR today).`
4842
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
4843
+ `the ${net.family} family can't pay a standard 'exact' rail (supported on EVM, Solana, Algorand, Aptos + NEAR today).`
4764
4844
  );
4765
4845
  }
4766
- throwIfAborted(_optionalChain([init, 'optionalAccess', _78 => _78.signal]));
4846
+ throwIfAborted(_optionalChain([init, 'optionalAccess', _82 => _82.signal]));
4767
4847
  const { payload, accepted, payerFrom, nonce } = await net.payExact(wallet, accept);
4768
- const headers = new Headers(_optionalChain([init, 'optionalAccess', _79 => _79.headers]));
4848
+ const headers = new Headers(_optionalChain([init, 'optionalAccess', _83 => _83.headers]));
4769
4849
  headers.set(HEADER_SIGNATURE, buildExactSignatureHeader({ accepted, payload }));
4770
4850
  const rejectDefinitive = (why2) => {
4771
4851
  this.safeEmit({ kind: "payment-failed", reason: `exact: facilitator rejected nonce=${nonce} (${why2})`, code: why2 });
4772
- throw new (0, _chunkMWBT7MCEcjs.MaxRetriesExceededError)(
4852
+ throw new (0, _chunkGYM46G5Lcjs.MaxRetriesExceededError)(
4773
4853
  `exact: the facilitator rejected the payment (${why2}). Fix the cause, then re-present the SAME signed authorization (nonce=${nonce}) \u2014 do NOT re-sign a fresh nonce. ref=${nonce}.`,
4774
4854
  { ref: nonce }
4775
4855
  );
@@ -4782,18 +4862,18 @@ var PipRailClient = (_class2 = class {
4782
4862
  if (Date.now() >= deadline) break;
4783
4863
  await new Promise((r) => setTimeout(r, Math.min(2e3, 400 * 2 ** (attempt - 1))));
4784
4864
  }
4785
- throwIfAborted(_optionalChain([init, 'optionalAccess', _80 => _80.signal]));
4865
+ throwIfAborted(_optionalChain([init, 'optionalAccess', _84 => _84.signal]));
4786
4866
  const budget = Math.min(this.retryTimeoutMs, deadline - Date.now());
4787
4867
  if (budget <= 0) break;
4788
4868
  const timeoutController = new AbortController();
4789
4869
  const timeoutId = setTimeout(() => timeoutController.abort(), budget);
4790
- const signal = _optionalChain([init, 'optionalAccess', _81 => _81.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, init.signal]) : timeoutController.signal;
4870
+ const signal = _optionalChain([init, 'optionalAccess', _85 => _85.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, init.signal]) : timeoutController.signal;
4791
4871
  let response;
4792
4872
  try {
4793
4873
  response = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), headers, signal });
4794
4874
  } catch (err) {
4795
- throw new (0, _chunkMWBT7MCEcjs.PaymentTimeoutError)(
4796
- `exact: no response after submitting the authorization (nonce=${nonce}) to ${hostOf2(url)}. The facilitator may have already settled it \u2014 verify on-chain with authorizationState(${payerFrom}, ${nonce}) before re-presenting; do NOT re-pay.`,
4875
+ throw new (0, _chunkGYM46G5Lcjs.PaymentTimeoutError)(
4876
+ `exact: no response after submitting the authorization (nonce=${nonce}) to ${hostOf2(url)}. The facilitator may have already settled it \u2014 verify on-chain via ${exactSettleCheckHint(net.family, payerFrom, nonce)} before re-presenting the SAME signed authorization; do NOT re-pay.`,
4797
4877
  { cause: err, ref: nonce }
4798
4878
  );
4799
4879
  } finally {
@@ -4809,7 +4889,7 @@ var PipRailClient = (_class2 = class {
4809
4889
  const receipt = parseReceipt(response);
4810
4890
  this.captureReceipt(response, url);
4811
4891
  this.safeEmit({ kind: "payment-settled", receipt, ...settle ? { settle } : {} });
4812
- const ref = _optionalChain([settle, 'optionalAccess', _82 => _82.transaction]) || _optionalChain([receipt, 'optionalAccess', _83 => _83.transaction]) || `eip3009-nonce:${nonce}`;
4892
+ const ref = _optionalChain([settle, 'optionalAccess', _86 => _86.transaction]) || _optionalChain([receipt, 'optionalAccess', _87 => _87.transaction]) || `${net.family === "evm" ? "eip3009" : net.family}-nonce:${nonce}`;
4813
4893
  this.recordSpend(quote, ref);
4814
4894
  return response;
4815
4895
  }
@@ -4827,8 +4907,8 @@ var PipRailClient = (_class2 = class {
4827
4907
  reason: `exact: 402 after submitting authorization nonce=${nonce} (${why})`,
4828
4908
  ...lastReason ? { code: lastReason.error, detail: lastReason.detail } : {}
4829
4909
  });
4830
- throw new (0, _chunkMWBT7MCEcjs.MaxRetriesExceededError)(
4831
- `exact: server still returned 402 after submitting the signed authorization (nonce=${nonce}). Last rejection: ${why}. Re-present the SAME authorization \u2014 do NOT re-sign a fresh nonce; verify authorizationState(${payerFrom}, ${nonce}) first. ref=${nonce}.`,
4910
+ throw new (0, _chunkGYM46G5Lcjs.MaxRetriesExceededError)(
4911
+ `exact: server still returned 402 after submitting the signed authorization (nonce=${nonce}). Last rejection: ${why}. Re-present the SAME authorization \u2014 do NOT re-sign a fresh nonce; verify on-chain via ${exactSettleCheckHint(net.family, payerFrom, nonce)} first. ref=${nonce}.`,
4832
4912
  { ref: nonce }
4833
4913
  );
4834
4914
  }
@@ -4843,17 +4923,17 @@ var PipRailClient = (_class2 = class {
4843
4923
  */
4844
4924
  async payUptoRail(net, wallet, accept, url, init, quote) {
4845
4925
  if (!net.payUpto) {
4846
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
4926
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
4847
4927
  `the ${net.family} family can't pay a standard 'upto' rail (EVM-Permit2 only today).`
4848
4928
  );
4849
4929
  }
4850
- throwIfAborted(_optionalChain([init, 'optionalAccess', _84 => _84.signal]));
4930
+ throwIfAborted(_optionalChain([init, 'optionalAccess', _88 => _88.signal]));
4851
4931
  const { payload, accepted, payerFrom, nonce } = await net.payUpto(wallet, accept);
4852
- const headers = new Headers(_optionalChain([init, 'optionalAccess', _85 => _85.headers]));
4932
+ const headers = new Headers(_optionalChain([init, 'optionalAccess', _89 => _89.headers]));
4853
4933
  headers.set(HEADER_SIGNATURE, buildUptoSignatureHeader({ accepted, payload }));
4854
4934
  const rejectDefinitive = (why2) => {
4855
4935
  this.safeEmit({ kind: "payment-failed", reason: `upto: facilitator rejected nonce=${nonce} (${why2})`, code: why2 });
4856
- throw new (0, _chunkMWBT7MCEcjs.MaxRetriesExceededError)(
4936
+ throw new (0, _chunkGYM46G5Lcjs.MaxRetriesExceededError)(
4857
4937
  `upto: the server rejected the payment (${why2}). Fix the cause, then re-present the SAME signed authorization (nonce=${nonce}) \u2014 do NOT re-sign a fresh nonce. ref=${nonce}.`,
4858
4938
  { ref: nonce }
4859
4939
  );
@@ -4866,17 +4946,17 @@ var PipRailClient = (_class2 = class {
4866
4946
  if (Date.now() >= deadline) break;
4867
4947
  await new Promise((r) => setTimeout(r, Math.min(2e3, 400 * 2 ** (attempt - 1))));
4868
4948
  }
4869
- throwIfAborted(_optionalChain([init, 'optionalAccess', _86 => _86.signal]));
4949
+ throwIfAborted(_optionalChain([init, 'optionalAccess', _90 => _90.signal]));
4870
4950
  const budget = Math.min(this.retryTimeoutMs, deadline - Date.now());
4871
4951
  if (budget <= 0) break;
4872
4952
  const timeoutController = new AbortController();
4873
4953
  const timeoutId = setTimeout(() => timeoutController.abort(), budget);
4874
- const signal = _optionalChain([init, 'optionalAccess', _87 => _87.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, init.signal]) : timeoutController.signal;
4954
+ const signal = _optionalChain([init, 'optionalAccess', _91 => _91.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, init.signal]) : timeoutController.signal;
4875
4955
  let response;
4876
4956
  try {
4877
4957
  response = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), headers, signal });
4878
4958
  } catch (err) {
4879
- throw new (0, _chunkMWBT7MCEcjs.PaymentTimeoutError)(
4959
+ throw new (0, _chunkGYM46G5Lcjs.PaymentTimeoutError)(
4880
4960
  `upto: no response after submitting the authorization (nonce=${nonce}) to ${hostOf2(url)}. The merchant may have already settled it \u2014 verify on-chain before re-presenting; do NOT re-pay.`,
4881
4961
  { cause: err, ref: nonce }
4882
4962
  );
@@ -4893,8 +4973,8 @@ var PipRailClient = (_class2 = class {
4893
4973
  const receipt = parseReceipt(response);
4894
4974
  this.captureReceipt(response, url);
4895
4975
  this.safeEmit({ kind: "payment-settled", receipt, ...settle ? { settle } : {} });
4896
- const ref = _optionalChain([settle, 'optionalAccess', _88 => _88.transaction]) || _optionalChain([receipt, 'optionalAccess', _89 => _89.transaction]) || `upto-nonce:${nonce}`;
4897
- const settledAmount = _nullishCoalesce(_optionalChain([settle, 'optionalAccess', _90 => _90.amount]), () => ( _optionalChain([receipt, 'optionalAccess', _91 => _91.amount])));
4976
+ const ref = _optionalChain([settle, 'optionalAccess', _92 => _92.transaction]) || _optionalChain([receipt, 'optionalAccess', _93 => _93.transaction]) || `upto-nonce:${nonce}`;
4977
+ const settledAmount = _nullishCoalesce(_optionalChain([settle, 'optionalAccess', _94 => _94.amount]), () => ( _optionalChain([receipt, 'optionalAccess', _95 => _95.amount])));
4898
4978
  this.recordSpend(quote, ref, settledAmount);
4899
4979
  return response;
4900
4980
  }
@@ -4912,14 +4992,14 @@ var PipRailClient = (_class2 = class {
4912
4992
  reason: `upto: 402 after submitting authorization nonce=${nonce} (${why})`,
4913
4993
  ...lastReason ? { code: lastReason.error, detail: lastReason.detail } : {}
4914
4994
  });
4915
- throw new (0, _chunkMWBT7MCEcjs.MaxRetriesExceededError)(
4995
+ throw new (0, _chunkGYM46G5Lcjs.MaxRetriesExceededError)(
4916
4996
  `upto: server still returned 402 after submitting the signed authorization (nonce=${nonce}). Last rejection: ${why}. Re-present the SAME authorization \u2014 do NOT re-sign a fresh nonce. ref=${nonce}.`,
4917
4997
  { ref: nonce }
4918
4998
  );
4919
4999
  }
4920
5000
  }, _class2);
4921
5001
  function throwIfAborted(signal) {
4922
- if (_optionalChain([signal, 'optionalAccess', _92 => _92.aborted])) {
5002
+ if (_optionalChain([signal, 'optionalAccess', _96 => _96.aborted])) {
4923
5003
  throw _nullishCoalesce(signal.reason, () => ( new DOMException("This operation was aborted.", "AbortError")));
4924
5004
  }
4925
5005
  }
@@ -4989,10 +5069,10 @@ function buildFundingHint(options, chainLabel) {
4989
5069
  return `Couldn't fully read your wallet on ${chainLabel} (RPC throttled) \u2014 retry; you may already be able to pay ${target.quote.amountFormatted} ${sym}.`;
4990
5070
  }
4991
5071
  const parts = [];
4992
- if (target.blockers.includes("INSUFFICIENT_TOKEN") && _optionalChain([target, 'access', _93 => _93.shortfall, 'optionalAccess', _94 => _94.token])) {
5072
+ if (target.blockers.includes("INSUFFICIENT_TOKEN") && _optionalChain([target, 'access', _97 => _97.shortfall, 'optionalAccess', _98 => _98.token])) {
4993
5073
  parts.push(`top up ${target.shortfall.token} ${sym}`);
4994
5074
  }
4995
- if (target.blockers.includes("INSUFFICIENT_GAS") && _optionalChain([target, 'access', _95 => _95.shortfall, 'optionalAccess', _96 => _96.native])) {
5075
+ if (target.blockers.includes("INSUFFICIENT_GAS") && _optionalChain([target, 'access', _99 => _99.shortfall, 'optionalAccess', _100 => _100.native])) {
4996
5076
  parts.push(`add ~${target.shortfall.native} ${target.cost.feeSymbol} for gas`);
4997
5077
  }
4998
5078
  return parts.length ? `Can't settle on ${chainLabel}: ${parts.join(" and ")} (to pay ${target.quote.amountFormatted} ${sym}).` : `Can't settle on ${chainLabel} for ${target.quote.amountFormatted} ${sym}.`;
@@ -5006,7 +5086,7 @@ async function planAcross(clients, url, init) {
5006
5086
  const status = best ? "ready" : options.some((o) => o.state === "unknown") ? "unknown" : "blocked";
5007
5087
  return {
5008
5088
  url,
5009
- network: _nullishCoalesce(_optionalChain([best, 'optionalAccess', _97 => _97.accept, 'access', _98 => _98.network]), () => ( live[0].network)),
5089
+ network: _nullishCoalesce(_optionalChain([best, 'optionalAccess', _101 => _101.accept, 'access', _102 => _102.network]), () => ( live[0].network)),
5010
5090
  status,
5011
5091
  payable: best !== null,
5012
5092
  best,
@@ -5025,7 +5105,7 @@ async function fetchAcross(clients, url, init) {
5025
5105
  const best = rankAcross(live.map((p) => p.plan)).find((o) => o.state === "payable");
5026
5106
  if (!best) {
5027
5107
  const hint = mergeDeclineHint(live.map((p) => p.plan));
5028
- throw new (0, _chunkMWBT7MCEcjs.PaymentDeclinedError)(hint || "No funded chain can settle this payment right now.");
5108
+ throw new (0, _chunkGYM46G5Lcjs.PaymentDeclinedError)(hint || "No funded chain can settle this payment right now.");
5029
5109
  }
5030
5110
  const owner = live.find((p) => p.plan.options.includes(best)).client;
5031
5111
  return owner.fetch(url, { ..._nullishCoalesce(init, () => ( {})), autoRoute: true });
@@ -5071,8 +5151,8 @@ function isReplayableBodyInit(value) {
5071
5151
  async function readInvalidReason(response) {
5072
5152
  try {
5073
5153
  const body = await response.clone().json();
5074
- const ext = _optionalChain([body, 'optionalAccess', _99 => _99.extensions]);
5075
- const piprail = _optionalChain([ext, 'optionalAccess', _100 => _100.piprail]);
5154
+ const ext = _optionalChain([body, 'optionalAccess', _103 => _103.extensions]);
5155
+ const piprail = _optionalChain([ext, 'optionalAccess', _104 => _104.piprail]);
5076
5156
  if (piprail && typeof piprail.code === "string") {
5077
5157
  return {
5078
5158
  error: piprail.code,
@@ -5094,7 +5174,7 @@ async function readInvalidReason(response) {
5094
5174
  } catch (e40) {
5095
5175
  }
5096
5176
  const settle = parseSettleResponse(response);
5097
- if (_optionalChain([settle, 'optionalAccess', _101 => _101.errorReason])) return { error: settle.errorReason, detail: "" };
5177
+ if (_optionalChain([settle, 'optionalAccess', _105 => _105.errorReason])) return { error: settle.errorReason, detail: "" };
5098
5178
  return null;
5099
5179
  }
5100
5180
  var EVM_PRESET_FOR_CHAINID = {
@@ -5192,7 +5272,7 @@ var MultiChainPayer = class _MultiChainPayer {
5192
5272
  ledger,
5193
5273
  ...opts.policy ? { policy: opts.policy } : {},
5194
5274
  ...opts.schemes ? { schemes: opts.schemes } : {},
5195
- ..._optionalChain([opts, 'access', _102 => _102.rpcUrls, 'optionalAccess', _103 => _103[chain]]) ? { rpcUrl: opts.rpcUrls[chain] } : {},
5275
+ ..._optionalChain([opts, 'access', _106 => _106.rpcUrls, 'optionalAccess', _107 => _107[chain]]) ? { rpcUrl: opts.rpcUrls[chain] } : {},
5196
5276
  ...opts.onBeforePay ? { onBeforePay: opts.onBeforePay } : {},
5197
5277
  ...opts.onEvent ? { onEvent: opts.onEvent } : {},
5198
5278
  ...opts.maxPaymentRetries != null ? { maxPaymentRetries: opts.maxPaymentRetries } : {},
@@ -5250,7 +5330,7 @@ var MultiChainPayer = class _MultiChainPayer {
5250
5330
  * {@link PipRailClient.post}.
5251
5331
  */
5252
5332
  post(url, body, init) {
5253
- const headers = new Headers(_optionalChain([init, 'optionalAccess', _104 => _104.headers]));
5333
+ const headers = new Headers(_optionalChain([init, 'optionalAccess', _108 => _108.headers]));
5254
5334
  let payload;
5255
5335
  if (body === void 0 || body === null) {
5256
5336
  payload = void 0;
@@ -5400,14 +5480,14 @@ function buildSelfDescription(input) {
5400
5480
  }
5401
5481
  function buildEndpointInfo(input) {
5402
5482
  const d = input.descriptor;
5403
- const summary = _nullishCoalesce(_optionalChain([d, 'optionalAccess', _105 => _105.summary]), () => ( input.description));
5404
- const hasInput = _optionalChain([d, 'optionalAccess', _106 => _106.queryParams]) && Object.keys(d.queryParams).length > 0;
5483
+ const summary = _nullishCoalesce(_optionalChain([d, 'optionalAccess', _109 => _109.summary]), () => ( input.description));
5484
+ const hasInput = _optionalChain([d, 'optionalAccess', _110 => _110.queryParams]) && Object.keys(d.queryParams).length > 0;
5405
5485
  const endpoint = {
5406
5486
  ...summary ? { summary } : {},
5407
- ..._optionalChain([d, 'optionalAccess', _107 => _107.method]) ? { method: d.method.toUpperCase() } : {},
5487
+ ..._optionalChain([d, 'optionalAccess', _111 => _111.method]) ? { method: d.method.toUpperCase() } : {},
5408
5488
  ...input.mimeType ? { mimeType: input.mimeType } : {},
5409
5489
  ...hasInput ? { input: d.queryParams } : {},
5410
- ..._optionalChain([d, 'optionalAccess', _108 => _108.output]) ? { output: d.output } : {}
5490
+ ..._optionalChain([d, 'optionalAccess', _112 => _112.output]) ? { output: d.output } : {}
5411
5491
  };
5412
5492
  return Object.keys(endpoint).length > 0 ? endpoint : void 0;
5413
5493
  }
@@ -5425,7 +5505,7 @@ function summarizePlan(plan) {
5425
5505
  return `NOT payable: ${_nullishCoalesce(plan.fundingHint, () => ( `no settleable rail on ${plan.network}`))}`;
5426
5506
  }
5427
5507
  function explainDecline(err) {
5428
- if (!(err instanceof _chunkMWBT7MCEcjs.PipRailError)) {
5508
+ if (!(err instanceof _chunkGYM46G5Lcjs.PipRailError)) {
5429
5509
  return `Payment failed: ${err instanceof Error ? err.message : String(err)}`;
5430
5510
  }
5431
5511
  switch (err.code) {
@@ -5499,8 +5579,8 @@ A 402 may offer up to three rails; you don't choose per payment \u2014 the clien
5499
5579
  (the native coin \u2014 ETH/SOL/\u2026). Works on every chain.
5500
5580
  - exact (the ratified x402 rail, opt-in): you only SIGN; the server \u2014 or a facilitator it chose
5501
5581
  (e.g. PayAI) \u2014 broadcasts it, so you pay ZERO gas (you need only the token, no native coin). It
5502
- works on EVM, Solana + Algorand, and the on-chain method (EIP-3009 / Permit2 / SVM / Algorand
5503
- fee-pooled group) is picked automatically.
5582
+ works on EVM, Solana, Algorand, Aptos + NEAR, and the on-chain method (EIP-3009 / Permit2 / SVM /
5583
+ Algorand fee-pooled group / Aptos fee-payer / NEAR SignedDelegateAction) is picked automatically.
5504
5584
  - upto (the metered/variable x402 rail, opt-in, EVM): the amount you see is a MAXIMUM \u2014 you sign
5505
5585
  a ceiling, the server meters real usage and settles the ACTUAL (<= the max). BUDGET AGAINST THE MAX:
5506
5586
  the plan/policy treat the ceiling as the spend (a server may charge up to it), so a payable plan
@@ -5577,14 +5657,14 @@ async function readBody(res) {
5577
5657
  }
5578
5658
  }
5579
5659
  function toToolError(err) {
5580
- if (!(err instanceof _chunkMWBT7MCEcjs.PipRailError)) throw err;
5660
+ if (!(err instanceof _chunkGYM46G5Lcjs.PipRailError)) throw err;
5581
5661
  const out = {
5582
5662
  ok: false,
5583
5663
  code: err.code,
5584
5664
  reason: err.message,
5585
5665
  explain: explainDecline(err)
5586
5666
  };
5587
- if (err instanceof _chunkMWBT7MCEcjs.PaymentDeclinedError) {
5667
+ if (err instanceof _chunkGYM46G5Lcjs.PaymentDeclinedError) {
5588
5668
  out.declined = true;
5589
5669
  if (err.reasonCode) out.reasonCode = err.reasonCode;
5590
5670
  }
@@ -5800,14 +5880,14 @@ function paymentTools(client) {
5800
5880
  ...verifiable ? { verifiableReceipt: { ...verifiable, resource: { url } } } : {}
5801
5881
  };
5802
5882
  } catch (err) {
5803
- if (err instanceof _chunkMWBT7MCEcjs.PipRailError) {
5883
+ if (err instanceof _chunkGYM46G5Lcjs.PipRailError) {
5804
5884
  const out = {
5805
5885
  ok: false,
5806
5886
  code: err.code,
5807
5887
  reason: err.message,
5808
5888
  explain: explainDecline(err)
5809
5889
  };
5810
- if (err instanceof _chunkMWBT7MCEcjs.PaymentDeclinedError) {
5890
+ if (err instanceof _chunkGYM46G5Lcjs.PaymentDeclinedError) {
5811
5891
  out.declined = true;
5812
5892
  if (err.reasonCode) out.reasonCode = err.reasonCode;
5813
5893
  }
@@ -6045,6 +6125,23 @@ function buildWellKnownX402(input) {
6045
6125
  ...input.ownershipProofs && input.ownershipProofs.length > 0 ? { ownershipProofs: input.ownershipProofs } : {}
6046
6126
  };
6047
6127
  }
6128
+ function buildWellKnownX402Manifest(input) {
6129
+ return {
6130
+ x402Version: 2,
6131
+ lastUpdated: _nullishCoalesce(input.lastUpdated, () => ( Math.floor(Date.now() / 1e3))),
6132
+ items: input.resources.map((r) => ({
6133
+ resource: {
6134
+ url: r.url,
6135
+ ...r.description ? { description: r.description } : {},
6136
+ ...r.mimeType ? { mimeType: r.mimeType } : {}
6137
+ },
6138
+ type: "http",
6139
+ accepts: r.accepts,
6140
+ input: { method: (_nullishCoalesce(r.method, () => ( "GET"))).toUpperCase() },
6141
+ ...r.mimeType ? { output: { mimeType: r.mimeType } } : {}
6142
+ }))
6143
+ };
6144
+ }
6048
6145
  function buildX402DnsTxt(input) {
6049
6146
  const descriptor = input.descriptor ? `descriptor=${input.descriptor};` : "";
6050
6147
  return {
@@ -6114,10 +6211,10 @@ async function fetchFacilitatorFeePayer(url, network, timeoutMs = 8e3) {
6114
6211
  const res = await fetch(`${base2}/supported`, { signal: ctrl.signal });
6115
6212
  if (!res.ok) return void 0;
6116
6213
  const body = await res.json();
6117
- const kinds = Array.isArray(_optionalChain([body, 'optionalAccess', _109 => _109.kinds])) ? body.kinds : [];
6214
+ const kinds = Array.isArray(_optionalChain([body, 'optionalAccess', _113 => _113.kinds])) ? body.kinds : [];
6118
6215
  const want = normalizeNetwork(network);
6119
- const kind = kinds.find((k) => _optionalChain([k, 'optionalAccess', _110 => _110.scheme]) === "exact" && normalizeNetwork(String(_nullishCoalesce(_optionalChain([k, 'optionalAccess', _111 => _111.network]), () => ( "")))) === want);
6120
- const fp = _optionalChain([kind, 'optionalAccess', _112 => _112.extra, 'optionalAccess', _113 => _113.feePayer]);
6216
+ const kind = kinds.find((k) => _optionalChain([k, 'optionalAccess', _114 => _114.scheme]) === "exact" && normalizeNetwork(String(_nullishCoalesce(_optionalChain([k, 'optionalAccess', _115 => _115.network]), () => ( "")))) === want);
6217
+ const fp = _optionalChain([kind, 'optionalAccess', _116 => _116.extra, 'optionalAccess', _117 => _117.feePayer]);
6121
6218
  return typeof fp === "string" ? fp : void 0;
6122
6219
  } catch (e43) {
6123
6220
  return void 0;
@@ -6126,16 +6223,16 @@ async function fetchFacilitatorFeePayer(url, network, timeoutMs = 8e3) {
6126
6223
  }
6127
6224
  }
6128
6225
  function parseFacilitatorSupported(body) {
6129
- const kinds = _optionalChain([body, 'optionalAccess', _114 => _114.kinds]);
6226
+ const kinds = _optionalChain([body, 'optionalAccess', _118 => _118.kinds]);
6130
6227
  if (!Array.isArray(kinds)) return [];
6131
6228
  const out = [];
6132
6229
  for (const k of kinds) {
6133
6230
  if (!k || typeof k !== "object") continue;
6134
6231
  const o = k;
6135
6232
  if (typeof o.scheme !== "string" || typeof o.network !== "string") continue;
6136
- const fp = _optionalChain([o, 'access', _115 => _115.extra, 'optionalAccess', _116 => _116.feePayer]);
6233
+ const fp = _optionalChain([o, 'access', _119 => _119.extra, 'optionalAccess', _120 => _120.feePayer]);
6137
6234
  const ver = o.x402Version;
6138
- const method = _optionalChain([o, 'access', _117 => _117.extra, 'optionalAccess', _118 => _118.assetTransferMethod]);
6235
+ const method = _optionalChain([o, 'access', _121 => _121.extra, 'optionalAccess', _122 => _122.assetTransferMethod]);
6139
6236
  out.push({
6140
6237
  scheme: o.scheme,
6141
6238
  network: o.network,
@@ -6199,13 +6296,13 @@ async function settleViaFacilitator(input) {
6199
6296
  try {
6200
6297
  verify = await post(`${base2}/verify`, body, auth);
6201
6298
  } catch (err) {
6202
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
6299
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
6203
6300
  `exact settle (facilitator ${base2}): /verify request failed (${err instanceof Error ? err.message : String(err)}).`,
6204
6301
  { cause: err }
6205
6302
  );
6206
6303
  }
6207
6304
  if (verify.status !== 200) {
6208
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
6305
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
6209
6306
  `exact settle (facilitator ${base2}): /verify returned HTTP ${verify.status} (transport/auth error).`
6210
6307
  );
6211
6308
  }
@@ -6221,13 +6318,13 @@ async function settleViaFacilitator(input) {
6221
6318
  try {
6222
6319
  settle = await post(`${base2}/settle`, body, auth);
6223
6320
  } catch (err) {
6224
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
6321
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
6225
6322
  `exact settle (facilitator ${base2}): /settle request failed (${err instanceof Error ? err.message : String(err)}).`,
6226
6323
  { cause: err }
6227
6324
  );
6228
6325
  }
6229
6326
  if (settle.status !== 200) {
6230
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
6327
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
6231
6328
  `exact settle (facilitator ${base2}): /settle returned HTTP ${settle.status} (transport/auth error).`
6232
6329
  );
6233
6330
  }
@@ -6643,7 +6740,7 @@ function createPaymentGate(options) {
6643
6740
  }
6644
6741
  net.assertValidPayTo(payTo);
6645
6742
  const { asset, decimals, symbol } = net.resolveToken(a.token);
6646
- const amountBase = _chunkMWBT7MCEcjs.parseUnits.call(void 0, a.amount, decimals);
6743
+ const amountBase = _chunkGYM46G5Lcjs.parseUnits.call(void 0, a.amount, decimals);
6647
6744
  const spec = { net, asset, decimals, symbol, amountBase, amountFormatted: a.amount, payTo };
6648
6745
  if (exactOption) {
6649
6746
  const outcome = await resolveExactRail(net, asset);
@@ -6666,7 +6763,7 @@ function createPaymentGate(options) {
6666
6763
  if (exactOption && !specs.some((s) => s.exact)) {
6667
6764
  const why = exactSkips.length > 0 ? exactSkips.join(" ") : "The standard `exact` rail is EVM ERC-20 (EIP-3009 \u2014 USDC / EURC \u2014 or Permit2, e.g. Binance-Peg USDC on BNB) or a Solana SPL token (SVM) \u2014 NOT native coins, NOT families without a standard `exact` scheme.";
6668
6765
  if (exactOption.settle === "keyless") {
6669
- if (typeof process === "undefined" || !_optionalChain([process, 'optionalAccess', _119 => _119.env, 'optionalAccess', _120 => _120.PIPRAIL_NO_HINTS])) {
6766
+ if (typeof process === "undefined" || !_optionalChain([process, 'optionalAccess', _123 => _123.env, 'optionalAccess', _124 => _124.PIPRAIL_NO_HINTS])) {
6670
6767
  console.warn(
6671
6768
  `[piprail] exact: true \u2014 no offered chain has a gasless \`exact\` rail available, so this gate serves ONCHAIN-PROOF ONLY (buyers PAY GAS \u2014 the fallback when no facilitator can sponsor). ${why} To be gasless: pin \`exact: { settle: { facilitator } }\` or self-settle \`exact: { settle: 'self', relayer }\`. (Suppress with PIPRAIL_NO_HINTS=1.)`
6672
6769
  );
@@ -6694,7 +6791,7 @@ function createPaymentGate(options) {
6694
6791
  skipReason: `${net.network}: \`exact: true\` found no known keyless facilitator for this network. Pass \`exact: { settle: { facilitator } }\`, \`exact: { settle: 'self', relayer }\`, or see the coverage map (KNOWN_FACILITATORS / docs.piprail.com).`
6695
6792
  };
6696
6793
  }
6697
- if (typeof process === "undefined" || _optionalChain([process, 'optionalAccess', _121 => _121.env, 'optionalAccess', _122 => _122.NODE_ENV]) !== "production" && !_optionalChain([process, 'optionalAccess', _123 => _123.env, 'optionalAccess', _124 => _124.PIPRAIL_NO_HINTS])) {
6794
+ if (typeof process === "undefined" || _optionalChain([process, 'optionalAccess', _125 => _125.env, 'optionalAccess', _126 => _126.NODE_ENV]) !== "production" && !_optionalChain([process, 'optionalAccess', _127 => _127.env, 'optionalAccess', _128 => _128.PIPRAIL_NO_HINTS])) {
6698
6795
  console.warn(
6699
6796
  `[piprail] exact: keyless rail on ${net.network} auto-settles via ${picked.url} (zero-config; pin \`exact.settle.facilitator\` in production).`
6700
6797
  );
@@ -6775,7 +6872,7 @@ function createPaymentGate(options) {
6775
6872
  if (hasCustomStore) {
6776
6873
  return options.isUsed ? Boolean(await options.isUsed(ref)) : false;
6777
6874
  }
6778
- const key = ref.toLowerCase();
6875
+ const key = ref.startsWith("pid:") ? ref : ref.toLowerCase();
6779
6876
  const now = Date.now();
6780
6877
  pruneUsed(now);
6781
6878
  if (localUsed.has(key)) return true;
@@ -6787,7 +6884,7 @@ function createPaymentGate(options) {
6787
6884
  if (ok && options.markUsed) await options.markUsed(ref);
6788
6885
  return;
6789
6886
  }
6790
- if (!ok) localUsed.delete(ref.toLowerCase());
6887
+ if (!ok) localUsed.delete(ref.startsWith("pid:") ? ref : ref.toLowerCase());
6791
6888
  }
6792
6889
  function buildAccept(s, nonce) {
6793
6890
  return {
@@ -6838,7 +6935,7 @@ function createPaymentGate(options) {
6838
6935
  extra: {
6839
6936
  assetTransferMethod: "permit2-upto",
6840
6937
  // facilitatorAddress comes from rail.extra; the spread below carries it (+ name/version).
6841
- facilitatorAddress: _nullishCoalesce(_optionalChain([rail, 'access', _125 => _125.extra, 'optionalAccess', _126 => _126.facilitatorAddress]), () => ( "")),
6938
+ facilitatorAddress: _nullishCoalesce(_optionalChain([rail, 'access', _129 => _129.extra, 'optionalAccess', _130 => _130.facilitatorAddress]), () => ( "")),
6842
6939
  minConfirmations,
6843
6940
  decimals: s.decimals,
6844
6941
  amountFormatted: s.amountFormatted,
@@ -6860,6 +6957,7 @@ function createPaymentGate(options) {
6860
6957
  const specs = await ready();
6861
6958
  const nonce = genNonce();
6862
6959
  const bazaar = options.discovery ? { bazaar: buildBazaarExtension(options.discovery === true ? {} : options.discovery) } : void 0;
6960
+ const paymentIdAd = options.paymentIdentifier ? buildPaymentIdentifierAdvertisement() : void 0;
6863
6961
  const accepts = buildAccepts(specs, nonce);
6864
6962
  const endpointInfo = buildEndpointInfo({
6865
6963
  ...options.description ? { description: options.description } : {},
@@ -6872,16 +6970,18 @@ function createPaymentGate(options) {
6872
6970
  ...endpointInfo ? { endpoint: endpointInfo } : {},
6873
6971
  ...receiptsOn ? { verifiableReceipts: true } : {}
6874
6972
  });
6875
- const rejectionExt = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _127 => _127.extensions]), () => ( {}));
6973
+ const rejectionExt = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _131 => _131.extensions]), () => ( {}));
6876
6974
  const rejectionPiprail = _nullishCoalesce(rejectionExt.piprail, () => ( {}));
6877
6975
  const bodyPiprail = { ..._nullishCoalesce(selfDescribe, () => ( {})), ...rejectionPiprail };
6878
6976
  const bodyExtensions = {
6879
6977
  ...bazaar,
6978
+ ...paymentIdAd,
6880
6979
  ...rejectionExt,
6881
6980
  ...Object.keys(bodyPiprail).length > 0 ? { piprail: bodyPiprail } : {}
6882
6981
  };
6883
6982
  const headerExtensions = {
6884
6983
  ...bazaar,
6984
+ ...paymentIdAd,
6885
6985
  ...Object.keys(rejectionPiprail).length > 0 ? { piprail: rejectionPiprail } : {}
6886
6986
  };
6887
6987
  const challenge2 = {
@@ -6892,7 +6992,7 @@ function createPaymentGate(options) {
6892
6992
  ...options.mimeType ? { mimeType: options.mimeType } : {}
6893
6993
  },
6894
6994
  accepts,
6895
- ..._optionalChain([opts, 'optionalAccess', _128 => _128.error]) ? { error: opts.error } : {},
6995
+ ..._optionalChain([opts, 'optionalAccess', _132 => _132.error]) ? { error: opts.error } : {},
6896
6996
  ...Object.keys(bodyExtensions).length > 0 ? { extensions: bodyExtensions } : {}
6897
6997
  };
6898
6998
  const headerChallenge = {
@@ -6923,7 +7023,7 @@ function createPaymentGate(options) {
6923
7023
  function enrichReceipt(spec, receipt) {
6924
7024
  let amountFormatted = receipt.amount;
6925
7025
  try {
6926
- amountFormatted = _chunkMWBT7MCEcjs.formatUnits.call(void 0, BigInt(receipt.amount), spec.decimals);
7026
+ amountFormatted = _chunkGYM46G5Lcjs.formatUnits.call(void 0, BigInt(receipt.amount), spec.decimals);
6927
7027
  } catch (e47) {
6928
7028
  }
6929
7029
  return {
@@ -7091,7 +7191,17 @@ function createPaymentGate(options) {
7091
7191
  await settleTx(ref, false);
7092
7192
  return rejection(result.error, result.detail);
7093
7193
  }
7094
- await settleTx(ref, true);
7194
+ const verified = result.receipt.transaction;
7195
+ if (verified && verified !== ref) {
7196
+ if (await claimTx(verified)) {
7197
+ await settleTx(ref, false);
7198
+ return rejection("tx_already_used", `Payment ${verified} was already redeemed.`);
7199
+ }
7200
+ await settleTx(ref, false);
7201
+ await settleTx(verified, true);
7202
+ } else {
7203
+ await settleTx(ref, true);
7204
+ }
7095
7205
  await deliverOnPaid(spec, result.receipt);
7096
7206
  return await buildPaidResult(spec, result.receipt, sig.payload.nonce);
7097
7207
  }
@@ -7165,7 +7275,7 @@ function createPaymentGate(options) {
7165
7275
  const ftMethod = accept.extra.assetTransferMethod;
7166
7276
  const needsFeePayer = ftMethod === "svm" || ftMethod === "algorand" || ftMethod === "aptos" || ftMethod === "near";
7167
7277
  if (needsFeePayer && !accept.extra.feePayer) {
7168
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
7278
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
7169
7279
  `exact settle: the ${ftMethod} facilitator rail is missing extra.feePayer (the gas sponsor) \u2014 cannot settle.`
7170
7280
  );
7171
7281
  }
@@ -7213,15 +7323,15 @@ function createPaymentGate(options) {
7213
7323
  if (s.endsWith("%")) {
7214
7324
  const pct = s.slice(0, -1).trim();
7215
7325
  if (!/^\d+(\.\d+)?$/.test(pct)) return null;
7216
- const pctScaled = _chunkMWBT7MCEcjs.floorUnits.call(void 0, pct, 4);
7326
+ const pctScaled = _chunkGYM46G5Lcjs.floorUnits.call(void 0, pct, 4);
7217
7327
  return maxAmount * pctScaled / (100n * 10n ** 4n);
7218
7328
  }
7219
7329
  if (s.startsWith("$")) {
7220
7330
  const amt = s.slice(1).trim();
7221
- return _chunkMWBT7MCEcjs.floorUnits.call(void 0, amt, decimals);
7331
+ return _chunkGYM46G5Lcjs.floorUnits.call(void 0, amt, decimals);
7222
7332
  }
7223
7333
  if (/^\d+$/.test(s)) return BigInt(s);
7224
- return _chunkMWBT7MCEcjs.floorUnits.call(void 0, s, decimals);
7334
+ return _chunkGYM46G5Lcjs.floorUnits.call(void 0, s, decimals);
7225
7335
  } catch (e56) {
7226
7336
  return null;
7227
7337
  }
@@ -7272,7 +7382,7 @@ function createPaymentGate(options) {
7272
7382
  result = await spec.net.settleUptoSelf({ relayer, payload: upto.payload, accept, settleAmount });
7273
7383
  } catch (err) {
7274
7384
  await settleTx(nonce, false);
7275
- if (err instanceof _chunkMWBT7MCEcjs.SettlementError) throw err;
7385
+ if (err instanceof _chunkGYM46G5Lcjs.SettlementError) throw err;
7276
7386
  return rejection(
7277
7387
  "tx_reverted",
7278
7388
  `upto: metering/settle failed (${err instanceof Error ? err.message : String(err)}).`
@@ -7297,7 +7407,7 @@ function createPaymentGate(options) {
7297
7407
  if (result.kind === "invalid") await deliverOnFailed(result);
7298
7408
  return result;
7299
7409
  }
7300
- async function resolveVerdictObject(obj) {
7410
+ async function routeVerdictObject(obj) {
7301
7411
  if (obj === void 0 || obj === null) return asChallenge();
7302
7412
  const sig = parseSignatureObject(obj);
7303
7413
  if (sig && sig.accepted && typeof sig.accepted.network === "string" && typeof sig.accepted.asset === "string") {
@@ -7309,11 +7419,49 @@ function createPaymentGate(options) {
7309
7419
  if (exact) return verifyExact(exact);
7310
7420
  return asChallenge();
7311
7421
  }
7422
+ function echoPaymentIdentifier(result, id) {
7423
+ try {
7424
+ const decoded = decodeBase64Json(result.receiptHeader);
7425
+ if (!decoded) return result;
7426
+ const { extensions: existing, ...receiptOnly } = decoded;
7427
+ const merged = {
7428
+ ..._nullishCoalesce(existing, () => ( {})),
7429
+ [EXT_PAYMENT_IDENTIFIER]: { info: { required: false, id } }
7430
+ };
7431
+ return { ...result, receiptHeader: buildReceiptHeader(receiptOnly, merged) };
7432
+ } catch (e57) {
7433
+ return result;
7434
+ }
7435
+ }
7436
+ async function resolveVerdictObject(obj) {
7437
+ if (!options.paymentIdentifier) return routeVerdictObject(obj);
7438
+ const id = readPaymentIdentifier(obj);
7439
+ if (id !== null && typeof id === "object") {
7440
+ return rejection("signature_invalid", `payment-identifier: ${id.invalid}.`);
7441
+ }
7442
+ if (id === null) return routeVerdictObject(obj);
7443
+ const idKey = "pid:" + id;
7444
+ if (await claimTx(idKey)) {
7445
+ return rejection(
7446
+ "tx_already_used",
7447
+ `Idempotency id "${id}" is already bound to a settled payment; use a fresh id for a new payment.`
7448
+ );
7449
+ }
7450
+ let result;
7451
+ try {
7452
+ result = await routeVerdictObject(obj);
7453
+ } catch (err) {
7454
+ await settleTx(idKey, false);
7455
+ throw err;
7456
+ }
7457
+ await settleTx(idKey, result.kind === "paid");
7458
+ return result.kind === "paid" ? echoPaymentIdentifier(result, id) : result;
7459
+ }
7312
7460
  return { challenge, verify, verifyObject, describe, landingPage };
7313
7461
  }
7314
7462
  function requirePayment(options) {
7315
7463
  if (options.upto) {
7316
- throw new (_class3 = class extends _chunkMWBT7MCEcjs.PipRailError {constructor(...args2) { super(...args2); _class3.prototype.__init7.call(this); }
7464
+ throw new (_class3 = class extends _chunkGYM46G5Lcjs.PipRailError {constructor(...args2) { super(...args2); _class3.prototype.__init7.call(this); }
7317
7465
  __init7() {this.code = "UNSUPPORTED_SCHEME"}
7318
7466
  }, _class3)(
7319
7467
  "requirePayment: the 'upto' (metered) rail is unsupported through the Express middleware \u2014 it settles before the route handler serves, so metered usage is unknown at settle time. Call gate.verify() directly (createPaymentGate) and meter inside settleAmount; see docs/accepting-payments/upto-rail-seller.md."
@@ -7325,7 +7473,7 @@ function requirePayment(options) {
7325
7473
  try {
7326
7474
  result = await gate.verify(_nullishCoalesce(req.headers[HEADER_SIGNATURE], () => ( req.headers[HEADER_SIGNATURE_V1])));
7327
7475
  } catch (err) {
7328
- if (err instanceof _chunkMWBT7MCEcjs.SettlementError) {
7476
+ if (err instanceof _chunkGYM46G5Lcjs.SettlementError) {
7329
7477
  res.status(502);
7330
7478
  res.json({
7331
7479
  x402Version: 2,
@@ -7373,7 +7521,7 @@ function isRetryableStatus(status) {
7373
7521
  }
7374
7522
  var sleep = (ms) => ms > 0 ? new Promise((resolve) => setTimeout(resolve, ms)) : Promise.resolve();
7375
7523
  async function signBody(secret, body) {
7376
- const subtle = _optionalChain([globalThis, 'access', _129 => _129.crypto, 'optionalAccess', _130 => _130.subtle]);
7524
+ const subtle = _optionalChain([globalThis, 'access', _133 => _133.crypto, 'optionalAccess', _134 => _134.subtle]);
7377
7525
  if (!subtle) return null;
7378
7526
  try {
7379
7527
  const enc = new TextEncoder();
@@ -7383,7 +7531,7 @@ async function signBody(secret, body) {
7383
7531
  const sig = await subtle.sign("HMAC", key, enc.encode(body));
7384
7532
  const hex = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
7385
7533
  return `sha256=${hex}`;
7386
- } catch (e57) {
7534
+ } catch (e58) {
7387
7535
  return null;
7388
7536
  }
7389
7537
  }
@@ -7443,8 +7591,8 @@ async function deliverReceipt(receipt, options) {
7443
7591
  const retryable = status === void 0 ? true : isRetryableStatus(status);
7444
7592
  const willRetry = !ok && retryable && attempt < maxAttempts;
7445
7593
  try {
7446
- _optionalChain([onAttempt, 'optionalCall', _131 => _131({ attempt, ok, ...status !== void 0 ? { status } : {}, ...error ? { error } : {}, willRetry })]);
7447
- } catch (e58) {
7594
+ _optionalChain([onAttempt, 'optionalCall', _135 => _135({ attempt, ok, ...status !== void 0 ? { status } : {}, ...error ? { error } : {}, willRetry })]);
7595
+ } catch (e59) {
7448
7596
  }
7449
7597
  if (ok) return { delivered: true, attempts: attempt, status };
7450
7598
  if (!willRetry) {
@@ -7532,13 +7680,13 @@ function toA2APaymentFailed(code, detail, receipts = [], network) {
7532
7680
  };
7533
7681
  }
7534
7682
  function fromA2APaymentRequired(task) {
7535
- const meta = _optionalChain([task, 'access', _132 => _132.status, 'optionalAccess', _133 => _133.message, 'optionalAccess', _134 => _134.metadata]);
7536
- const required = _optionalChain([meta, 'optionalAccess', _135 => _135[A2A_REQUIRED_KEY]]);
7683
+ const meta = _optionalChain([task, 'access', _136 => _136.status, 'optionalAccess', _137 => _137.message, 'optionalAccess', _138 => _138.metadata]);
7684
+ const required = _optionalChain([meta, 'optionalAccess', _139 => _139[A2A_REQUIRED_KEY]]);
7537
7685
  if (!required || typeof required !== "object") return null;
7538
7686
  return required;
7539
7687
  }
7540
7688
  function fromA2APaymentPayload(message) {
7541
- const raw = _optionalChain([message, 'access', _136 => _136.metadata, 'optionalAccess', _137 => _137[A2A_PAYLOAD_KEY]]);
7689
+ const raw = _optionalChain([message, 'access', _140 => _140.metadata, 'optionalAccess', _141 => _141[A2A_PAYLOAD_KEY]]);
7542
7690
  if (raw === void 0 || raw === null) return null;
7543
7691
  return { raw, taskId: _nullishCoalesce(message.taskId, () => ( "")) };
7544
7692
  }
@@ -7571,7 +7719,7 @@ function createA2APaymentHandler(options) {
7571
7719
  const ttlMs = _nullishCoalesce(options.taskTtlMs, () => ( maxTimeoutSeconds * 1e3));
7572
7720
  const store = _nullishCoalesce(options.taskStore, () => ( defaultTaskStore()));
7573
7721
  function appendReceipt(taskId, entry) {
7574
- const prior = _nullishCoalesce(_optionalChain([store, 'access', _138 => _138.get, 'call', _139 => _139(taskId), 'optionalAccess', _140 => _140.receipts]), () => ( []));
7722
+ const prior = _nullishCoalesce(_optionalChain([store, 'access', _142 => _142.get, 'call', _143 => _143(taskId), 'optionalAccess', _144 => _144.receipts]), () => ( []));
7575
7723
  const isDup = "success" in entry && entry.success === true && entry.transaction !== "" && prior.some((r) => "transaction" in r && r.transaction === entry.transaction);
7576
7724
  const next = isDup ? prior : [...prior, entry];
7577
7725
  const receipts = next.length > MAX_TASK_RECEIPTS ? next.slice(-MAX_TASK_RECEIPTS) : next;
@@ -7647,7 +7795,7 @@ function createA2APaymentHandler(options) {
7647
7795
  try {
7648
7796
  result = await gate.verifyObject(inbound.raw);
7649
7797
  } catch (err) {
7650
- if (err instanceof _chunkMWBT7MCEcjs.SettlementError) {
7798
+ if (err instanceof _chunkGYM46G5Lcjs.SettlementError) {
7651
7799
  return failedTask(id, "settlement_failed", err.message, attempted);
7652
7800
  }
7653
7801
  const detail = err instanceof Error ? err.message : String(err);
@@ -7679,11 +7827,11 @@ function createA2APaymentHandler(options) {
7679
7827
  }
7680
7828
  }
7681
7829
  function agentCardExtension(opts) {
7682
- const uri = _optionalChain([opts, 'optionalAccess', _141 => _141.version]) === "v0.2" ? A2A_X402_EXTENSION_URI_V02 : A2A_X402_EXTENSION_URI_V01;
7830
+ const uri = _optionalChain([opts, 'optionalAccess', _145 => _145.version]) === "v0.2" ? A2A_X402_EXTENSION_URI_V02 : A2A_X402_EXTENSION_URI_V01;
7683
7831
  return {
7684
7832
  uri,
7685
7833
  description: "Supports payments using the x402 protocol for on-chain settlement.",
7686
- ..._optionalChain([opts, 'optionalAccess', _142 => _142.required]) ? { required: true } : {}
7834
+ ..._optionalChain([opts, 'optionalAccess', _146 => _146.required]) ? { required: true } : {}
7687
7835
  };
7688
7836
  }
7689
7837
  return { handleMessage, agentCardExtension, gate };
@@ -7694,7 +7842,7 @@ function singleNetworkOf(challenge) {
7694
7842
  }
7695
7843
  function networkFromPayload(raw) {
7696
7844
  const v = raw;
7697
- if (v && typeof _optionalChain([v, 'access', _143 => _143.accepted, 'optionalAccess', _144 => _144.network]) === "string") return v.accepted.network;
7845
+ if (v && typeof _optionalChain([v, 'access', _147 => _147.accepted, 'optionalAccess', _148 => _148.network]) === "string") return v.accepted.network;
7698
7846
  if (v && typeof v.network === "string") return v.network;
7699
7847
  return void 0;
7700
7848
  }
@@ -7709,6 +7857,129 @@ function resourceUrlFromMessage(message) {
7709
7857
  return "";
7710
7858
  }
7711
7859
 
7860
+ // src/transports/mcp-types.ts
7861
+ var MCP_PAYMENT_META_KEY = "x402/payment";
7862
+ var MCP_PAYMENT_RESPONSE_META_KEY = "x402/payment-response";
7863
+
7864
+ // src/transports/mcp.ts
7865
+ function toMcpPaymentRequired(challenge) {
7866
+ const text = JSON.stringify(challenge);
7867
+ return {
7868
+ isError: true,
7869
+ structuredContent: challenge,
7870
+ content: [{ type: "text", text }]
7871
+ };
7872
+ }
7873
+ function toMcpPaymentResponse(content, receipt) {
7874
+ return {
7875
+ content,
7876
+ _meta: {
7877
+ [MCP_PAYMENT_RESPONSE_META_KEY]: {
7878
+ success: true,
7879
+ transaction: receipt.transaction,
7880
+ network: receipt.network,
7881
+ payer: receipt.payer
7882
+ }
7883
+ }
7884
+ };
7885
+ }
7886
+ function fromMcpPayment(params) {
7887
+ const meta = _optionalChain([params, 'optionalAccess', _149 => _149._meta, 'optionalAccess', _150 => _150[MCP_PAYMENT_META_KEY]]);
7888
+ return meta == null ? null : meta;
7889
+ }
7890
+ function fromMcpPaymentRequired(result) {
7891
+ if (!result || result.isError !== true) return null;
7892
+ const sc = result.structuredContent;
7893
+ if (sc && typeof sc === "object" && typeof sc.x402Version === "number") {
7894
+ return sc;
7895
+ }
7896
+ const text = _optionalChain([result, 'access', _151 => _151.content, 'optionalAccess', _152 => _152[0], 'optionalAccess', _153 => _153.text]);
7897
+ if (typeof text === "string") {
7898
+ try {
7899
+ const parsed = JSON.parse(text);
7900
+ if (parsed && typeof parsed === "object" && typeof parsed.x402Version === "number") {
7901
+ return parsed;
7902
+ }
7903
+ } catch (e60) {
7904
+ }
7905
+ }
7906
+ return null;
7907
+ }
7908
+ function isMcpPaymentRequired(result) {
7909
+ return fromMcpPaymentRequired(result) != null;
7910
+ }
7911
+ function fromMcpPaymentResponse(result) {
7912
+ const meta = _optionalChain([result, 'optionalAccess', _154 => _154._meta, 'optionalAccess', _155 => _155[MCP_PAYMENT_RESPONSE_META_KEY]]);
7913
+ if (!meta || typeof meta !== "object") return null;
7914
+ return meta;
7915
+ }
7916
+ function buildMcpPaymentMeta(input) {
7917
+ return {
7918
+ [MCP_PAYMENT_META_KEY]: {
7919
+ x402Version: _nullishCoalesce(input.x402Version, () => ( 2)),
7920
+ ...input.resource ? { resource: input.resource } : {},
7921
+ accepted: input.accepted,
7922
+ payload: input.payload
7923
+ }
7924
+ };
7925
+ }
7926
+ function createMcpPaymentTool(options) {
7927
+ const gate = _nullishCoalesce(options.gate, () => ( createPaymentGate(options)));
7928
+ function settlementFailed(code, detail) {
7929
+ return {
7930
+ isError: true,
7931
+ content: [
7932
+ {
7933
+ type: "text",
7934
+ text: `x402 settlement failed (${toA2AErrorCode(code)}): ${detail}. The buyer can retry, or pay the onchain-proof rail directly.`
7935
+ }
7936
+ ]
7937
+ };
7938
+ }
7939
+ async function handleToolCall(params) {
7940
+ const raw = fromMcpPayment(params);
7941
+ if (raw == null) {
7942
+ const { challenge } = await gate.challenge(_nullishCoalesce(options.resourceUrl, () => ( "")));
7943
+ return toMcpPaymentRequired(challenge);
7944
+ }
7945
+ let result;
7946
+ try {
7947
+ result = await gate.verifyObject(raw);
7948
+ } catch (err) {
7949
+ if (err instanceof _chunkGYM46G5Lcjs.SettlementError) return settlementFailed("settlement_failed", err.message);
7950
+ throw err;
7951
+ }
7952
+ if (result.kind === "paid") {
7953
+ try {
7954
+ const content = await options.fulfill({ receipt: result.receipt, params });
7955
+ return toMcpPaymentResponse(content, result.receipt);
7956
+ } catch (err) {
7957
+ const detail = err instanceof Error ? err.message : String(err);
7958
+ return toMcpPaymentResponse(
7959
+ [{ type: "text", text: `Payment settled (tx ${result.receipt.transaction}), but serving the result failed: ${detail}` }],
7960
+ result.receipt
7961
+ );
7962
+ }
7963
+ }
7964
+ return toMcpPaymentRequired(result.challenge);
7965
+ }
7966
+ return { handleToolCall, gate };
7967
+ }
7968
+
7969
+
7970
+
7971
+
7972
+
7973
+
7974
+
7975
+
7976
+
7977
+
7978
+
7979
+
7980
+
7981
+
7982
+
7712
7983
 
7713
7984
 
7714
7985
 
@@ -7841,4 +8112,4 @@ function resourceUrlFromMessage(message) {
7841
8112
 
7842
8113
 
7843
8114
 
7844
- exports.A2A_ERROR_KEY = A2A_ERROR_KEY; exports.A2A_EXTENSIONS_HEADER = A2A_EXTENSIONS_HEADER; exports.A2A_PAYLOAD_KEY = A2A_PAYLOAD_KEY; exports.A2A_RECEIPTS_KEY = A2A_RECEIPTS_KEY; exports.A2A_REQUIRED_KEY = A2A_REQUIRED_KEY; exports.A2A_STATUS_KEY = A2A_STATUS_KEY; exports.A2A_X402_EXTENSION_URI_V01 = A2A_X402_EXTENSION_URI_V01; exports.A2A_X402_EXTENSION_URI_V02 = A2A_X402_EXTENSION_URI_V02; exports.BRAND = BRAND; exports.BUILTIN_DENOMS = BUILTIN_DENOMS; exports.CHAINS = CHAINS; exports.ConfirmationTimeoutError = _chunkMWBT7MCEcjs.ConfirmationTimeoutError; exports.DENOM_PRECISION = DENOM_PRECISION; exports.DIRECTORY_INFO = DIRECTORY_INFO; exports.EIP3009_TYPES = EIP3009_TYPES; exports.EXACT_NETWORK_SLUGS = EXACT_NETWORK_SLUGS; exports.EXT_OFFER_RECEIPT = EXT_OFFER_RECEIPT; exports.GENERATOR = GENERATOR; exports.HEADER_REQUIRED = HEADER_REQUIRED; exports.HEADER_RESPONSE = HEADER_RESPONSE; exports.HEADER_RESPONSE_V1 = HEADER_RESPONSE_V1; exports.HEADER_SIGNATURE = HEADER_SIGNATURE; exports.HEADER_SIGNATURE_V1 = HEADER_SIGNATURE_V1; exports.InsufficientFundsError = _chunkMWBT7MCEcjs.InsufficientFundsError; exports.InvalidEnvelopeError = _chunkMWBT7MCEcjs.InvalidEnvelopeError; exports.KNOWN_FACILITATORS = KNOWN_FACILITATORS; exports.MaxRetriesExceededError = _chunkMWBT7MCEcjs.MaxRetriesExceededError; exports.MissingDriverError = _chunkMWBT7MCEcjs.MissingDriverError; exports.MultiChainPayer = MultiChainPayer; exports.NoCompatibleAcceptError = _chunkMWBT7MCEcjs.NoCompatibleAcceptError; exports.NonReplayableBodyError = _chunkMWBT7MCEcjs.NonReplayableBodyError; exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS; exports.PERMIT2_PROXY_CHAIN_IDS = PERMIT2_PROXY_CHAIN_IDS; exports.PERMIT2_UPTO_WITNESS_TYPES = PERMIT2_UPTO_WITNESS_TYPES; exports.PERMIT2_WITNESS_TYPES = PERMIT2_WITNESS_TYPES; exports.PIPRAIL_AGENT_GUIDE = PIPRAIL_AGENT_GUIDE; exports.POWERED_BY = POWERED_BY; exports.PaymentDeclinedError = _chunkMWBT7MCEcjs.PaymentDeclinedError; exports.PaymentTimeoutError = _chunkMWBT7MCEcjs.PaymentTimeoutError; exports.PipRailClient = PipRailClient; exports.PipRailError = _chunkMWBT7MCEcjs.PipRailError; exports.REGISTER_ATTRIBUTION = REGISTER_ATTRIBUTION; exports.RecipientNotReadyError = _chunkMWBT7MCEcjs.RecipientNotReadyError; exports.SettlementError = _chunkMWBT7MCEcjs.SettlementError; exports.SpendLedger = SpendLedger; exports.UPTO_PROXY_CHAIN_IDS = UPTO_PROXY_CHAIN_IDS; exports.UnknownTokenError = _chunkMWBT7MCEcjs.UnknownTokenError; exports.UnsupportedNetworkError = _chunkMWBT7MCEcjs.UnsupportedNetworkError; exports.UnsupportedSchemeError = _chunkMWBT7MCEcjs.UnsupportedSchemeError; exports.VERIFY_CODE_TO_A2A_ERROR = VERIFY_CODE_TO_A2A_ERROR; exports.WalletRequiredError = _chunkMWBT7MCEcjs.WalletRequiredError; exports.WrongChainError = _chunkMWBT7MCEcjs.WrongChainError; exports.WrongFamilyError = _chunkMWBT7MCEcjs.WrongFamilyError; exports.X402_EXACT_PERMIT2_PROXY = X402_EXACT_PERMIT2_PROXY; exports.X402_UPTO_PERMIT2_PROXY = X402_UPTO_PERMIT2_PROXY; exports.agentGuide = agentGuide; exports.appendAttribution = appendAttribution; exports.appendKeywords = appendKeywords; exports.buildBazaarExtension = buildBazaarExtension; exports.buildChallengeHeader = buildChallengeHeader; exports.buildEndpointInfo = buildEndpointInfo; exports.buildExactAuthorization = buildExactAuthorization; exports.buildExactSignatureHeader = buildExactSignatureHeader; exports.buildOpenApi = buildOpenApi; exports.buildReceiptExtension = buildReceiptExtension; exports.buildReceiptHeader = buildReceiptHeader; exports.buildSelfDescription = buildSelfDescription; exports.buildSignatureHeader = buildSignatureHeader; exports.buildUptoSignatureHeader = buildUptoSignatureHeader; exports.buildWellKnownX402 = buildWellKnownX402; exports.buildX402DnsTxt = buildX402DnsTxt; exports.chainIdForExactNetwork = chainIdForExactNetwork; exports.claim402IndexDomain = claim402IndexDomain; exports.classifyChallenge = classifyChallenge; exports.createA2APaymentHandler = createA2APaymentHandler; exports.createPaymentGate = createPaymentGate; exports.decodeBase64Json = decodeBase64Json; exports.decorateOutcome = decorateOutcome; exports.deliverReceipt = deliverReceipt; exports.denomOf = denomOf; exports.describeChallenge = describeChallenge; exports.discoveryHeaders = discoveryHeaders; exports.eip3009Abi = eip3009Abi; exports.encodeXPaymentHeader = encodeXPaymentHeader; exports.evaluatePolicy = evaluatePolicy; exports.explainDecline = explainDecline; exports.facilitatorCoverage = facilitatorCoverage; exports.fetchAcross = fetchAcross; exports.firstKeylessFacilitator = firstKeylessFacilitator; exports.formatSpendReport = formatSpendReport; exports.fromA2APaymentPayload = fromA2APaymentPayload; exports.fromA2APaymentRequired = fromA2APaymentRequired; exports.getDirectoryInfo = getDirectoryInfo; exports.isPermit2ProxyChain = isPermit2ProxyChain; exports.isUptoProxyChain = isUptoProxyChain; exports.knownFacilitatorsFor = knownFacilitatorsFor; exports.memorySpendStore = _chunkO4UQOZ4Zcjs.memorySpendStore; exports.normalizeNetwork = normalizeNetwork; exports.parseChallenge = parseChallenge; exports.parseExactObject = parseExactObject; exports.parseExactPaymentHeader = parseExactPaymentHeader; exports.parseExactRequirements = parseExactRequirements; exports.parseFacilitatorSupported = parseFacilitatorSupported; exports.parseReceipt = parseReceipt; exports.parseReceiptExtension = parseReceiptExtension; exports.parseSettleResponse = parseSettleResponse; exports.parseSignatureHeader = parseSignatureHeader; exports.parseSignatureObject = parseSignatureObject; exports.parseUptoObject = parseUptoObject; exports.parseUptoPaymentHeader = parseUptoPaymentHeader; exports.paymentTools = paymentTools; exports.pickAccept = pickAccept; exports.planAcross = planAcross; exports.rankResources = rankResources; exports.readExactDomain = readExactDomain; exports.register402Index = register402Index; exports.registerDriver = registerDriver; exports.registerX402Scan = registerX402Scan; exports.renderLandingPage = renderLandingPage; exports.requirePayment = requirePayment; exports.resolveChain = resolveChain; exports.scoreResource = scoreResource; exports.searchOpenIndexes = searchOpenIndexes; exports.settleViaFacilitator = settleViaFacilitator; exports.summarizePlan = summarizePlan; exports.toA2AErrorCode = toA2AErrorCode; exports.toA2APaymentFailed = toA2APaymentFailed; exports.toA2APaymentReceipts = toA2APaymentReceipts; exports.toA2APaymentRequired = toA2APaymentRequired; exports.toInsufficientFundsError = _chunkMWBT7MCEcjs.toInsufficientFundsError; exports.toInvalidBody = toInvalidBody; exports.verify402IndexDomain = verify402IndexDomain;
8115
+ exports.A2A_ERROR_KEY = A2A_ERROR_KEY; exports.A2A_EXTENSIONS_HEADER = A2A_EXTENSIONS_HEADER; exports.A2A_PAYLOAD_KEY = A2A_PAYLOAD_KEY; exports.A2A_RECEIPTS_KEY = A2A_RECEIPTS_KEY; exports.A2A_REQUIRED_KEY = A2A_REQUIRED_KEY; exports.A2A_STATUS_KEY = A2A_STATUS_KEY; exports.A2A_X402_EXTENSION_URI_V01 = A2A_X402_EXTENSION_URI_V01; exports.A2A_X402_EXTENSION_URI_V02 = A2A_X402_EXTENSION_URI_V02; exports.BRAND = BRAND; exports.BUILTIN_DENOMS = BUILTIN_DENOMS; exports.CHAINS = CHAINS; exports.ConfirmationTimeoutError = _chunkGYM46G5Lcjs.ConfirmationTimeoutError; exports.DENOM_PRECISION = DENOM_PRECISION; exports.DIRECTORY_INFO = DIRECTORY_INFO; exports.EIP3009_TYPES = EIP3009_TYPES; exports.EXACT_NETWORK_SLUGS = EXACT_NETWORK_SLUGS; exports.EXT_OFFER_RECEIPT = EXT_OFFER_RECEIPT; exports.EXT_PAYMENT_IDENTIFIER = EXT_PAYMENT_IDENTIFIER; exports.GENERATOR = GENERATOR; exports.HEADER_REQUIRED = HEADER_REQUIRED; exports.HEADER_RESPONSE = HEADER_RESPONSE; exports.HEADER_RESPONSE_V1 = HEADER_RESPONSE_V1; exports.HEADER_SIGNATURE = HEADER_SIGNATURE; exports.HEADER_SIGNATURE_V1 = HEADER_SIGNATURE_V1; exports.InsufficientFundsError = _chunkGYM46G5Lcjs.InsufficientFundsError; exports.InvalidEnvelopeError = _chunkGYM46G5Lcjs.InvalidEnvelopeError; exports.KNOWN_FACILITATORS = KNOWN_FACILITATORS; exports.MCP_PAYMENT_META_KEY = MCP_PAYMENT_META_KEY; exports.MCP_PAYMENT_RESPONSE_META_KEY = MCP_PAYMENT_RESPONSE_META_KEY; exports.MaxRetriesExceededError = _chunkGYM46G5Lcjs.MaxRetriesExceededError; exports.MissingDriverError = _chunkGYM46G5Lcjs.MissingDriverError; exports.MultiChainPayer = MultiChainPayer; exports.NoCompatibleAcceptError = _chunkGYM46G5Lcjs.NoCompatibleAcceptError; exports.NonReplayableBodyError = _chunkGYM46G5Lcjs.NonReplayableBodyError; exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS; exports.PERMIT2_PROXY_CHAIN_IDS = PERMIT2_PROXY_CHAIN_IDS; exports.PERMIT2_UPTO_WITNESS_TYPES = PERMIT2_UPTO_WITNESS_TYPES; exports.PERMIT2_WITNESS_TYPES = PERMIT2_WITNESS_TYPES; exports.PIPRAIL_AGENT_GUIDE = PIPRAIL_AGENT_GUIDE; exports.POWERED_BY = POWERED_BY; exports.PaymentDeclinedError = _chunkGYM46G5Lcjs.PaymentDeclinedError; exports.PaymentTimeoutError = _chunkGYM46G5Lcjs.PaymentTimeoutError; exports.PipRailClient = PipRailClient; exports.PipRailError = _chunkGYM46G5Lcjs.PipRailError; exports.REGISTER_ATTRIBUTION = REGISTER_ATTRIBUTION; exports.RecipientNotReadyError = _chunkGYM46G5Lcjs.RecipientNotReadyError; exports.SettlementError = _chunkGYM46G5Lcjs.SettlementError; exports.SpendLedger = SpendLedger; exports.UPTO_PROXY_CHAIN_IDS = UPTO_PROXY_CHAIN_IDS; exports.UnknownTokenError = _chunkGYM46G5Lcjs.UnknownTokenError; exports.UnsupportedNetworkError = _chunkGYM46G5Lcjs.UnsupportedNetworkError; exports.UnsupportedSchemeError = _chunkGYM46G5Lcjs.UnsupportedSchemeError; exports.VERIFY_CODE_TO_A2A_ERROR = VERIFY_CODE_TO_A2A_ERROR; exports.WalletRequiredError = _chunkGYM46G5Lcjs.WalletRequiredError; exports.WrongChainError = _chunkGYM46G5Lcjs.WrongChainError; exports.WrongFamilyError = _chunkGYM46G5Lcjs.WrongFamilyError; exports.X402_EXACT_PERMIT2_PROXY = X402_EXACT_PERMIT2_PROXY; exports.X402_UPTO_PERMIT2_PROXY = X402_UPTO_PERMIT2_PROXY; exports.agentGuide = agentGuide; exports.appendAttribution = appendAttribution; exports.appendKeywords = appendKeywords; exports.buildBazaarExtension = buildBazaarExtension; exports.buildChallengeHeader = buildChallengeHeader; exports.buildEndpointInfo = buildEndpointInfo; exports.buildExactAuthorization = buildExactAuthorization; exports.buildExactSignatureHeader = buildExactSignatureHeader; exports.buildMcpPaymentMeta = buildMcpPaymentMeta; exports.buildOpenApi = buildOpenApi; exports.buildPaymentIdentifierAdvertisement = buildPaymentIdentifierAdvertisement; exports.buildReceiptExtension = buildReceiptExtension; exports.buildReceiptHeader = buildReceiptHeader; exports.buildSelfDescription = buildSelfDescription; exports.buildSignatureHeader = buildSignatureHeader; exports.buildUptoSignatureHeader = buildUptoSignatureHeader; exports.buildWellKnownX402 = buildWellKnownX402; exports.buildWellKnownX402Manifest = buildWellKnownX402Manifest; exports.buildX402DnsTxt = buildX402DnsTxt; exports.chainIdForExactNetwork = chainIdForExactNetwork; exports.claim402IndexDomain = claim402IndexDomain; exports.classifyChallenge = classifyChallenge; exports.createA2APaymentHandler = createA2APaymentHandler; exports.createMcpPaymentTool = createMcpPaymentTool; exports.createPaymentGate = createPaymentGate; exports.decodeBase64Json = decodeBase64Json; exports.decorateOutcome = decorateOutcome; exports.deliverReceipt = deliverReceipt; exports.denomOf = denomOf; exports.describeChallenge = describeChallenge; exports.discoveryHeaders = discoveryHeaders; exports.eip3009Abi = eip3009Abi; exports.encodeXPaymentHeader = encodeXPaymentHeader; exports.evaluatePolicy = evaluatePolicy; exports.explainDecline = explainDecline; exports.facilitatorCoverage = facilitatorCoverage; exports.fetchAcross = fetchAcross; exports.firstKeylessFacilitator = firstKeylessFacilitator; exports.formatSpendReport = formatSpendReport; exports.fromA2APaymentPayload = fromA2APaymentPayload; exports.fromA2APaymentRequired = fromA2APaymentRequired; exports.fromMcpPayment = fromMcpPayment; exports.fromMcpPaymentRequired = fromMcpPaymentRequired; exports.fromMcpPaymentResponse = fromMcpPaymentResponse; exports.getDirectoryInfo = getDirectoryInfo; exports.isMcpPaymentRequired = isMcpPaymentRequired; exports.isPermit2ProxyChain = isPermit2ProxyChain; exports.isUptoProxyChain = isUptoProxyChain; exports.knownFacilitatorsFor = knownFacilitatorsFor; exports.memorySpendStore = _chunkO4UQOZ4Zcjs.memorySpendStore; exports.normalizeNetwork = normalizeNetwork; exports.parseChallenge = parseChallenge; exports.parseExactObject = parseExactObject; exports.parseExactPaymentHeader = parseExactPaymentHeader; exports.parseExactRequirements = parseExactRequirements; exports.parseFacilitatorSupported = parseFacilitatorSupported; exports.parseReceipt = parseReceipt; exports.parseReceiptExtension = parseReceiptExtension; exports.parseSettleResponse = parseSettleResponse; exports.parseSignatureHeader = parseSignatureHeader; exports.parseSignatureObject = parseSignatureObject; exports.parseUptoObject = parseUptoObject; exports.parseUptoPaymentHeader = parseUptoPaymentHeader; exports.paymentTools = paymentTools; exports.pickAccept = pickAccept; exports.planAcross = planAcross; exports.rankResources = rankResources; exports.readExactDomain = readExactDomain; exports.readPaymentIdentifier = readPaymentIdentifier; exports.register402Index = register402Index; exports.registerDriver = registerDriver; exports.registerX402Scan = registerX402Scan; exports.renderLandingPage = renderLandingPage; exports.requirePayment = requirePayment; exports.resolveChain = resolveChain; exports.scoreResource = scoreResource; exports.searchOpenIndexes = searchOpenIndexes; exports.settleViaFacilitator = settleViaFacilitator; exports.summarizePlan = summarizePlan; exports.toA2AErrorCode = toA2AErrorCode; exports.toA2APaymentFailed = toA2APaymentFailed; exports.toA2APaymentReceipts = toA2APaymentReceipts; exports.toA2APaymentRequired = toA2APaymentRequired; exports.toInsufficientFundsError = _chunkGYM46G5Lcjs.toInsufficientFundsError; exports.toInvalidBody = toInvalidBody; exports.toMcpPaymentRequired = toMcpPaymentRequired; exports.toMcpPaymentResponse = toMcpPaymentResponse; exports.verify402IndexDomain = verify402IndexDomain;