@piprail/sdk 1.25.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +4 -4
- package/dist/{algorand-677ILBQS.js → algorand-GSFVZTBF.js} +10 -18
- package/dist/{algorand-ZJ53VCTN.cjs → algorand-HZS43N4P.cjs} +23 -31
- package/dist/{aptos-3TSKTI4D.js → aptos-RIL56C7L.js} +10 -18
- package/dist/{aptos-XIIHPAOO.cjs → aptos-TRCCJRZA.cjs} +22 -30
- package/dist/{chunk-L6WQRHEZ.js → chunk-7XK22JSQ.js} +14 -1
- package/dist/{chunk-U35MG4TF.cjs → chunk-JG6KRAW6.cjs} +15 -2
- package/dist/index.cjs +282 -197
- package/dist/index.d.cts +40 -32
- package/dist/index.d.ts +40 -32
- package/dist/index.js +176 -91
- package/dist/{near-MG256A3E.cjs → near-DI2I3MAV.cjs} +24 -32
- package/dist/{near-TWA4PYOD.js → near-MTYBCUYM.js} +10 -18
- package/dist/{solana-KWNRY5NR.js → solana-E4MD6JJ6.js} +20 -12
- package/dist/{solana-UEMHFQH5.cjs → solana-TLHL2KNY.cjs} +46 -38
- package/dist/{stellar-SCRRPCEA.cjs → stellar-FW6C6FBE.cjs} +28 -38
- package/dist/{stellar-YB7JXKK4.js → stellar-U5NCRIOJ.js} +12 -22
- package/dist/{sui-LFT65OGU.cjs → sui-47C2KEZI.cjs} +23 -31
- package/dist/{sui-IODKU2MA.js → sui-Y53M4GUM.js} +10 -18
- package/dist/{ton-QN5GTOCS.js → ton-5ZPT5PSP.js} +20 -13
- package/dist/{ton-RAYJFKJC.cjs → ton-MMPKWT6N.cjs} +30 -23
- package/dist/{tron-KX4VWS7V.cjs → tron-JOT4STIG.cjs} +33 -38
- package/dist/{tron-QSNCDYRB.js → tron-WYS4X2I5.js} +14 -19
- package/dist/{xrpl-ECHK3GIX.js → xrpl-2MZEOIFY.js} +11 -19
- package/dist/{xrpl-GXUFDXHU.cjs → xrpl-PECT4IMX.cjs} +27 -35
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
|
|
27
28
|
|
|
28
29
|
// src/drivers/registry.ts
|
|
29
30
|
var byFamily = /* @__PURE__ */ new Map();
|
|
@@ -52,13 +53,13 @@ function resolveNetwork(opts) {
|
|
|
52
53
|
const family = familyForChain(opts.chain);
|
|
53
54
|
const driver = byFamily.get(family);
|
|
54
55
|
if (!driver) {
|
|
55
|
-
throw new (0,
|
|
56
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedNetworkError)(
|
|
56
57
|
`No driver registered for the "${family}" family \u2014 it may not be mounted yet (use the async resolveNetwork()).`
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
60
|
const net = driver.resolve(opts);
|
|
60
61
|
if (!net) {
|
|
61
|
-
throw new (0,
|
|
62
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedNetworkError)(
|
|
62
63
|
`The ${family} driver didn't recognise this chain input.`
|
|
63
64
|
);
|
|
64
65
|
}
|
|
@@ -319,20 +320,35 @@ function resolveChain(input, rpcUrlOverride) {
|
|
|
319
320
|
|
|
320
321
|
var _accounts = require('viem/accounts');
|
|
321
322
|
function createWalletAdapter(config, resolved) {
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, config, "EVM");
|
|
324
|
+
if ("key" in config) {
|
|
325
|
+
const key = config.key;
|
|
326
|
+
if (typeof key !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(key)) {
|
|
327
|
+
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).";
|
|
328
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
329
|
+
`chain is EVM; the wallet { key } is not a valid 0x\u2026 32-byte hex private key${hint}`
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
let account;
|
|
333
|
+
try {
|
|
334
|
+
account = _accounts.privateKeyToAccount.call(void 0, key);
|
|
335
|
+
} catch (err) {
|
|
336
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
337
|
+
`chain is EVM; the wallet { key } is not a valid 0x\u2026 32-byte hex private key: ${err instanceof Error ? err.message : String(err)}.`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
324
340
|
const transport = _viem.http.call(void 0, resolved.rpcUrl);
|
|
325
341
|
const walletClient = _viem.createWalletClient.call(void 0, { account, chain: resolved.chain, transport });
|
|
326
342
|
return { account, walletClient };
|
|
327
343
|
}
|
|
328
344
|
const wc = config.walletClient;
|
|
329
345
|
if (!wc.account) {
|
|
330
|
-
throw new (0,
|
|
331
|
-
"chain is EVM; the provided walletClient has no attached account. Use `createWalletClient({ account, chain, transport })`, or pass {
|
|
346
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
347
|
+
"chain is EVM; the provided walletClient has no attached account. Use `createWalletClient({ account, chain, transport })`, or pass { key }."
|
|
332
348
|
);
|
|
333
349
|
}
|
|
334
350
|
if (wc.chain && wc.chain.id !== resolved.chainId) {
|
|
335
|
-
throw new (0,
|
|
351
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongChainError)(
|
|
336
352
|
`PipRailClient: walletClient is on chain ${wc.chain.id} but the SDK was configured with chain ${resolved.chainId}. They must match.`
|
|
337
353
|
);
|
|
338
354
|
}
|
|
@@ -662,7 +678,7 @@ async function payExactEvm(input) {
|
|
|
662
678
|
code = void 0;
|
|
663
679
|
}
|
|
664
680
|
if (code && code !== "0x") {
|
|
665
|
-
throw new (0,
|
|
681
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
666
682
|
`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.`
|
|
667
683
|
);
|
|
668
684
|
}
|
|
@@ -672,13 +688,13 @@ async function payExactEvm(input) {
|
|
|
672
688
|
domain = await readExactDomain(publicClient, accept.asset);
|
|
673
689
|
}
|
|
674
690
|
if (!domain) {
|
|
675
|
-
throw new (0,
|
|
691
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
676
692
|
`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.`
|
|
677
693
|
);
|
|
678
694
|
}
|
|
679
695
|
const g = globalThis.crypto;
|
|
680
696
|
if (!_optionalChain([g, 'optionalAccess', _5 => _5.getRandomValues])) {
|
|
681
|
-
throw new (0,
|
|
697
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
682
698
|
"this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the exact rail needs a CSPRNG nonce."
|
|
683
699
|
);
|
|
684
700
|
}
|
|
@@ -935,7 +951,7 @@ async function verifyAndSettleExactEvm(input) {
|
|
|
935
951
|
args: writeArgs
|
|
936
952
|
});
|
|
937
953
|
} catch (err) {
|
|
938
|
-
throw new (0,
|
|
954
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
939
955
|
`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.`,
|
|
940
956
|
{ cause: err }
|
|
941
957
|
);
|
|
@@ -947,7 +963,7 @@ async function verifyAndSettleExactEvm(input) {
|
|
|
947
963
|
return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
|
|
948
964
|
}
|
|
949
965
|
} catch (err) {
|
|
950
|
-
throw new (0,
|
|
966
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
951
967
|
`exact settle: broadcast ${txHash} but couldn't confirm it (${shorten(err instanceof Error ? err.message : String(err))}).`,
|
|
952
968
|
{ cause: err }
|
|
953
969
|
);
|
|
@@ -1078,7 +1094,7 @@ function shorten2(msg) {
|
|
|
1078
1094
|
function randomPermit2Nonce() {
|
|
1079
1095
|
const g = globalThis.crypto;
|
|
1080
1096
|
if (!_optionalChain([g, 'optionalAccess', _8 => _8.getRandomValues])) {
|
|
1081
|
-
throw new (0,
|
|
1097
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
1082
1098
|
"this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the permit2 rail needs a CSPRNG nonce."
|
|
1083
1099
|
);
|
|
1084
1100
|
}
|
|
@@ -1097,7 +1113,7 @@ async function ensurePermit2Allowance(input) {
|
|
|
1097
1113
|
args: [account.address, PERMIT2_ADDRESS]
|
|
1098
1114
|
});
|
|
1099
1115
|
} catch (err) {
|
|
1100
|
-
throw new (0,
|
|
1116
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
1101
1117
|
`permit2: couldn't read the Permit2 allowance for ${token} (${shorten2(err instanceof Error ? err.message : String(err))}).`
|
|
1102
1118
|
);
|
|
1103
1119
|
}
|
|
@@ -1114,7 +1130,7 @@ async function ensurePermit2Allowance(input) {
|
|
|
1114
1130
|
await publicClient.waitForTransactionReceipt({ hash, confirmations: 1 });
|
|
1115
1131
|
return hash;
|
|
1116
1132
|
} catch (err) {
|
|
1117
|
-
throw _nullishCoalesce(
|
|
1133
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
1118
1134
|
`permit2: the one-time Permit2 approval for ${token} failed to broadcast (${shorten2(err instanceof Error ? err.message : String(err))}).`,
|
|
1119
1135
|
{ cause: err }
|
|
1120
1136
|
)));
|
|
@@ -1129,7 +1145,7 @@ async function payPermit2Evm(input) {
|
|
|
1129
1145
|
code = void 0;
|
|
1130
1146
|
}
|
|
1131
1147
|
if (code && code !== "0x") {
|
|
1132
|
-
throw new (0,
|
|
1148
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
1133
1149
|
`permit2 buyer rail requires an EOA signer; ${account.address} is a contract / EIP-1271 / EIP-7702-delegated account. Pay via onchain-proof.`
|
|
1134
1150
|
);
|
|
1135
1151
|
}
|
|
@@ -1304,7 +1320,7 @@ async function verifyAndSettlePermit2Evm(input) {
|
|
|
1304
1320
|
args: settleArgs
|
|
1305
1321
|
});
|
|
1306
1322
|
} catch (err) {
|
|
1307
|
-
throw new (0,
|
|
1323
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
1308
1324
|
`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.`,
|
|
1309
1325
|
{ cause: err }
|
|
1310
1326
|
);
|
|
@@ -1316,7 +1332,7 @@ async function verifyAndSettlePermit2Evm(input) {
|
|
|
1316
1332
|
return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
|
|
1317
1333
|
}
|
|
1318
1334
|
} catch (err) {
|
|
1319
|
-
throw new (0,
|
|
1335
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
1320
1336
|
`permit2 settle: broadcast ${txHash} but couldn't confirm it (${shorten2(err instanceof Error ? err.message : String(err))}).`,
|
|
1321
1337
|
{ cause: err }
|
|
1322
1338
|
);
|
|
@@ -1492,6 +1508,7 @@ function isValidChallenge(value) {
|
|
|
1492
1508
|
const v = value;
|
|
1493
1509
|
if (v.x402Version !== 2) return false;
|
|
1494
1510
|
if (!Array.isArray(v.accepts) || v.accepts.length === 0) return false;
|
|
1511
|
+
if (!v.accepts.every((a) => a !== null && typeof a === "object")) return false;
|
|
1495
1512
|
if (!v.resource || typeof v.resource !== "object") return false;
|
|
1496
1513
|
return true;
|
|
1497
1514
|
}
|
|
@@ -1549,15 +1566,15 @@ function makeEvmNetwork(resolved) {
|
|
|
1549
1566
|
const info = resolved.tokens[token.toUpperCase()];
|
|
1550
1567
|
if (!info) {
|
|
1551
1568
|
const known = Object.keys(resolved.tokens).join(", ") || "(none built in)";
|
|
1552
|
-
throw new (0,
|
|
1569
|
+
throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
|
|
1553
1570
|
`token "${token}" isn't built in for ${resolved.chain.name} (known: ${known}). Pass { address, decimals } instead, or use 'native'.`
|
|
1554
1571
|
);
|
|
1555
1572
|
}
|
|
1556
1573
|
return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
|
|
1557
1574
|
}
|
|
1558
|
-
|
|
1575
|
+
_chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "evm", network);
|
|
1559
1576
|
if (!("address" in token)) {
|
|
1560
|
-
throw new (0,
|
|
1577
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1561
1578
|
`chain ${network} is EVM; a custom token must be { address, decimals }.`
|
|
1562
1579
|
);
|
|
1563
1580
|
}
|
|
@@ -1589,15 +1606,21 @@ function makeEvmNetwork(resolved) {
|
|
|
1589
1606
|
},
|
|
1590
1607
|
assertValidPayTo(payTo) {
|
|
1591
1608
|
if (!_viem.isAddress.call(void 0, payTo)) {
|
|
1592
|
-
throw new (0,
|
|
1609
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1593
1610
|
`chain ${network} is EVM, but payTo "${payTo}" is not a valid 0x address.`
|
|
1594
1611
|
);
|
|
1595
1612
|
}
|
|
1596
1613
|
},
|
|
1597
1614
|
bindWallet(wallet) {
|
|
1598
|
-
if (typeof wallet !== "object" || wallet === null
|
|
1599
|
-
throw new (0,
|
|
1600
|
-
`chain ${network} is EVM; wallet must be {
|
|
1615
|
+
if (typeof wallet !== "object" || wallet === null) {
|
|
1616
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1617
|
+
`chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
|
|
1618
|
+
);
|
|
1619
|
+
}
|
|
1620
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "EVM");
|
|
1621
|
+
if (!("key" in wallet) && !("walletClient" in wallet)) {
|
|
1622
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1623
|
+
`chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
|
|
1601
1624
|
);
|
|
1602
1625
|
}
|
|
1603
1626
|
return { _native: createWalletAdapter(wallet, resolved) };
|
|
@@ -1613,12 +1636,12 @@ function makeEvmNetwork(resolved) {
|
|
|
1613
1636
|
});
|
|
1614
1637
|
} catch (err) {
|
|
1615
1638
|
if (isViemInsufficientFunds(err)) {
|
|
1616
|
-
throw new (0,
|
|
1639
|
+
throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
|
|
1617
1640
|
err instanceof Error ? err.message : "Insufficient funds for payment.",
|
|
1618
1641
|
{ cause: err }
|
|
1619
1642
|
);
|
|
1620
1643
|
}
|
|
1621
|
-
throw _nullishCoalesce(
|
|
1644
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
1622
1645
|
}
|
|
1623
1646
|
},
|
|
1624
1647
|
async confirm(ref, minConfirmations) {
|
|
@@ -1629,7 +1652,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1629
1652
|
});
|
|
1630
1653
|
return { height: receipt.blockNumber.toString() };
|
|
1631
1654
|
} catch (err) {
|
|
1632
|
-
throw new (0,
|
|
1655
|
+
throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(
|
|
1633
1656
|
`EVM tx ${ref} did not reach ${minConfirmations} confirmation(s) in time.`,
|
|
1634
1657
|
{ cause: err }
|
|
1635
1658
|
);
|
|
@@ -1639,7 +1662,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1639
1662
|
const { decimals, symbol } = resolved.chain.nativeCurrency;
|
|
1640
1663
|
if (accept.scheme === "exact") {
|
|
1641
1664
|
const permit2 = accept.extra.assetTransferMethod === "permit2";
|
|
1642
|
-
return
|
|
1665
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
1643
1666
|
symbol,
|
|
1644
1667
|
decimals,
|
|
1645
1668
|
fee: 0n,
|
|
@@ -1650,7 +1673,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1650
1673
|
const gasLimit = accept.asset === "native" ? 21000n : 65000n;
|
|
1651
1674
|
try {
|
|
1652
1675
|
const gasPrice = await publicClient.getGasPrice();
|
|
1653
|
-
return
|
|
1676
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
1654
1677
|
symbol,
|
|
1655
1678
|
decimals,
|
|
1656
1679
|
fee: gasPrice * gasLimit,
|
|
@@ -1659,7 +1682,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1659
1682
|
});
|
|
1660
1683
|
} catch (e20) {
|
|
1661
1684
|
const gasPrice = 5000000000n;
|
|
1662
|
-
return
|
|
1685
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
1663
1686
|
symbol,
|
|
1664
1687
|
decimals,
|
|
1665
1688
|
fee: gasPrice * gasLimit,
|
|
@@ -1793,9 +1816,9 @@ var loaders = {
|
|
|
1793
1816
|
solana: async () => {
|
|
1794
1817
|
let mod;
|
|
1795
1818
|
try {
|
|
1796
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./solana-
|
|
1819
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./solana-TLHL2KNY.cjs")));
|
|
1797
1820
|
} catch (cause) {
|
|
1798
|
-
throw new (0,
|
|
1821
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1799
1822
|
`Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
|
|
1800
1823
|
{ cause }
|
|
1801
1824
|
);
|
|
@@ -1805,9 +1828,9 @@ var loaders = {
|
|
|
1805
1828
|
ton: async () => {
|
|
1806
1829
|
let mod;
|
|
1807
1830
|
try {
|
|
1808
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./ton-
|
|
1831
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./ton-MMPKWT6N.cjs")));
|
|
1809
1832
|
} catch (cause) {
|
|
1810
|
-
throw new (0,
|
|
1833
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1811
1834
|
`TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
|
|
1812
1835
|
{ cause }
|
|
1813
1836
|
);
|
|
@@ -1817,9 +1840,9 @@ var loaders = {
|
|
|
1817
1840
|
stellar: async () => {
|
|
1818
1841
|
let mod;
|
|
1819
1842
|
try {
|
|
1820
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./stellar-
|
|
1843
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./stellar-FW6C6FBE.cjs")));
|
|
1821
1844
|
} catch (cause) {
|
|
1822
|
-
throw new (0,
|
|
1845
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1823
1846
|
`Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
|
|
1824
1847
|
{ cause }
|
|
1825
1848
|
);
|
|
@@ -1829,9 +1852,9 @@ var loaders = {
|
|
|
1829
1852
|
xrpl: async () => {
|
|
1830
1853
|
let mod;
|
|
1831
1854
|
try {
|
|
1832
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./xrpl-
|
|
1855
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./xrpl-PECT4IMX.cjs")));
|
|
1833
1856
|
} catch (cause) {
|
|
1834
|
-
throw new (0,
|
|
1857
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1835
1858
|
`XRPL selected, but its package isn't installed. Run: npm install xrpl`,
|
|
1836
1859
|
{ cause }
|
|
1837
1860
|
);
|
|
@@ -1841,9 +1864,9 @@ var loaders = {
|
|
|
1841
1864
|
tron: async () => {
|
|
1842
1865
|
let mod;
|
|
1843
1866
|
try {
|
|
1844
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./tron-
|
|
1867
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./tron-JOT4STIG.cjs")));
|
|
1845
1868
|
} catch (cause) {
|
|
1846
|
-
throw new (0,
|
|
1869
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1847
1870
|
`Tron selected, but its package isn't installed. Run: npm install tronweb`,
|
|
1848
1871
|
{ cause }
|
|
1849
1872
|
);
|
|
@@ -1853,9 +1876,9 @@ var loaders = {
|
|
|
1853
1876
|
sui: async () => {
|
|
1854
1877
|
let mod;
|
|
1855
1878
|
try {
|
|
1856
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./sui-
|
|
1879
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./sui-47C2KEZI.cjs")));
|
|
1857
1880
|
} catch (cause) {
|
|
1858
|
-
throw new (0,
|
|
1881
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1859
1882
|
`Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
|
|
1860
1883
|
{ cause }
|
|
1861
1884
|
);
|
|
@@ -1865,9 +1888,9 @@ var loaders = {
|
|
|
1865
1888
|
near: async () => {
|
|
1866
1889
|
let mod;
|
|
1867
1890
|
try {
|
|
1868
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./near-
|
|
1891
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./near-DI2I3MAV.cjs")));
|
|
1869
1892
|
} catch (cause) {
|
|
1870
|
-
throw new (0,
|
|
1893
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1871
1894
|
`NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
|
|
1872
1895
|
{ cause }
|
|
1873
1896
|
);
|
|
@@ -1877,9 +1900,9 @@ var loaders = {
|
|
|
1877
1900
|
aptos: async () => {
|
|
1878
1901
|
let mod;
|
|
1879
1902
|
try {
|
|
1880
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./aptos-
|
|
1903
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./aptos-TRCCJRZA.cjs")));
|
|
1881
1904
|
} catch (cause) {
|
|
1882
|
-
throw new (0,
|
|
1905
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1883
1906
|
`Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
|
|
1884
1907
|
{ cause }
|
|
1885
1908
|
);
|
|
@@ -1889,9 +1912,9 @@ var loaders = {
|
|
|
1889
1912
|
algorand: async () => {
|
|
1890
1913
|
let mod;
|
|
1891
1914
|
try {
|
|
1892
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./algorand-
|
|
1915
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./algorand-HZS43N4P.cjs")));
|
|
1893
1916
|
} catch (cause) {
|
|
1894
|
-
throw new (0,
|
|
1917
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1895
1918
|
`Algorand selected, but its package isn't installed. Run: npm install algosdk`,
|
|
1896
1919
|
{ cause }
|
|
1897
1920
|
);
|
|
@@ -2438,7 +2461,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
|
|
|
2438
2461
|
}
|
|
2439
2462
|
}
|
|
2440
2463
|
if (policy.maxAmount !== void 0) {
|
|
2441
|
-
const cap =
|
|
2464
|
+
const cap = _chunkJG6KRAW6cjs.floorUnits.call(void 0, policy.maxAmount, intent.decimals);
|
|
2442
2465
|
if (intent.amountBase > cap) {
|
|
2443
2466
|
return deny(
|
|
2444
2467
|
"MAX_AMOUNT",
|
|
@@ -2447,7 +2470,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
|
|
|
2447
2470
|
}
|
|
2448
2471
|
}
|
|
2449
2472
|
if (policy.maxTotal !== void 0) {
|
|
2450
|
-
const cap =
|
|
2473
|
+
const cap = _chunkJG6KRAW6cjs.floorUnits.call(void 0, policy.maxTotal, intent.decimals);
|
|
2451
2474
|
if (spentForAssetBase + intent.amountBase > cap) {
|
|
2452
2475
|
return deny(
|
|
2453
2476
|
"MAX_TOTAL",
|
|
@@ -2456,7 +2479,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
|
|
|
2456
2479
|
}
|
|
2457
2480
|
}
|
|
2458
2481
|
if (ctx && policy.windowTotal !== void 0 && policy.windowSeconds !== void 0) {
|
|
2459
|
-
const cap =
|
|
2482
|
+
const cap = _chunkJG6KRAW6cjs.floorUnits.call(void 0, policy.windowTotal, intent.decimals);
|
|
2460
2483
|
if (ctx.spentInWindowBase + intent.amountBase > cap) {
|
|
2461
2484
|
return deny(
|
|
2462
2485
|
"WINDOW_TOTAL",
|
|
@@ -2545,7 +2568,7 @@ var SpendLedger = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
2545
2568
|
symbol: b.symbol,
|
|
2546
2569
|
decimals: b.decimals,
|
|
2547
2570
|
totalBase: b.total.toString(),
|
|
2548
|
-
totalFormatted:
|
|
2571
|
+
totalFormatted: _chunkJG6KRAW6cjs.formatUnits.call(void 0, b.total, b.decimals),
|
|
2549
2572
|
count: b.count
|
|
2550
2573
|
})),
|
|
2551
2574
|
records: [...this.records]
|
|
@@ -2577,8 +2600,29 @@ var PipRailClient = (_class2 = class {
|
|
|
2577
2600
|
this.maxRetries = Math.max(1, _nullishCoalesce(opts.maxPaymentRetries, () => ( 3)));
|
|
2578
2601
|
this.retryTimeoutMs = _nullishCoalesce(opts.retryTimeoutMs, () => ( 3e4));
|
|
2579
2602
|
this.onEvent = _nullishCoalesce(opts.onEvent, () => ( (() => void 0)));
|
|
2603
|
+
this.assertPolicyAmountCaps(opts.policy);
|
|
2580
2604
|
this.assertPolicyTimeOptions(opts.policy);
|
|
2581
2605
|
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Fail LOUDLY at construction on a malformed amount cap — a security boundary
|
|
2608
|
+
* must never silently half-arm, and a misconfigured cap is a programmer error
|
|
2609
|
+
* (→ `TypeError`, no new SDK code). Each cap (`maxAmount` / `maxTotal` /
|
|
2610
|
+
* `windowTotal`) must be a non-negative decimal STRING (the same grammar
|
|
2611
|
+
* {@link floorUnits} accepts), so a typo like `'0.01abc'` fails fast here instead
|
|
2612
|
+
* of lazily throwing a raw `floorUnits` error out of the never-throw read methods.
|
|
2613
|
+
*/
|
|
2614
|
+
assertPolicyAmountCaps(policy) {
|
|
2615
|
+
if (!policy) return;
|
|
2616
|
+
for (const field of ["maxAmount", "maxTotal", "windowTotal"]) {
|
|
2617
|
+
const v = policy[field];
|
|
2618
|
+
if (v === void 0) continue;
|
|
2619
|
+
if (typeof v !== "string" || !/^\d+(\.\d+)?$/.test(v)) {
|
|
2620
|
+
throw new TypeError(
|
|
2621
|
+
`policy.${field} must be a non-negative decimal string (e.g. '0.10'); got ${JSON.stringify(v)}.`
|
|
2622
|
+
);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2582
2626
|
/**
|
|
2583
2627
|
* Fail LOUDLY at construction on a misconfigured time policy — a security
|
|
2584
2628
|
* boundary must never silently half-arm. Two invariants (a misconfiguration is
|
|
@@ -2741,13 +2785,13 @@ var PipRailClient = (_class2 = class {
|
|
|
2741
2785
|
spentBase: b.totalBase.toString()
|
|
2742
2786
|
};
|
|
2743
2787
|
if (maxTotal === void 0) return base2;
|
|
2744
|
-
const capBase =
|
|
2788
|
+
const capBase = _chunkJG6KRAW6cjs.floorUnits.call(void 0, maxTotal, b.decimals);
|
|
2745
2789
|
const remainingBase = capBase > b.totalBase ? capBase - b.totalBase : 0n;
|
|
2746
2790
|
return {
|
|
2747
2791
|
...base2,
|
|
2748
2792
|
capBase: capBase.toString(),
|
|
2749
2793
|
remainingBase: remainingBase.toString(),
|
|
2750
|
-
remainingFormatted:
|
|
2794
|
+
remainingFormatted: _chunkJG6KRAW6cjs.formatUnits.call(void 0, remainingBase, b.decimals)
|
|
2751
2795
|
};
|
|
2752
2796
|
});
|
|
2753
2797
|
}
|
|
@@ -2787,11 +2831,11 @@ var PipRailClient = (_class2 = class {
|
|
|
2787
2831
|
if (res.status !== 402) return null;
|
|
2788
2832
|
const challenge = await parseChallenge(res);
|
|
2789
2833
|
if (!challenge) {
|
|
2790
|
-
throw new (0,
|
|
2834
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)("402 response did not include a parseable x402 challenge.");
|
|
2791
2835
|
}
|
|
2792
2836
|
const { net, wallet } = await this.ensure();
|
|
2793
2837
|
if (!wallet) {
|
|
2794
|
-
throw new (0,
|
|
2838
|
+
throw new (0, _chunkJG6KRAW6cjs.WalletRequiredError)(
|
|
2795
2839
|
"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."
|
|
2796
2840
|
);
|
|
2797
2841
|
}
|
|
@@ -2959,7 +3003,7 @@ var PipRailClient = (_class2 = class {
|
|
|
2959
3003
|
async fetch(url, init) {
|
|
2960
3004
|
const body = _optionalChain([init, 'optionalAccess', _41 => _41.body]);
|
|
2961
3005
|
if (body !== void 0 && body !== null && !isReplayableBodyInit(body)) {
|
|
2962
|
-
throw new (0,
|
|
3006
|
+
throw new (0, _chunkJG6KRAW6cjs.NonReplayableBodyError)(
|
|
2963
3007
|
"fetch(): init.body is not replayable. Pass a string, FormData, URLSearchParams, ArrayBuffer, or Blob \u2014 not a ReadableStream."
|
|
2964
3008
|
);
|
|
2965
3009
|
}
|
|
@@ -2969,7 +3013,7 @@ var PipRailClient = (_class2 = class {
|
|
|
2969
3013
|
const resolved = await this.resolveChallenge(url, firstResponse, schemes);
|
|
2970
3014
|
const { net, wallet, challenge } = resolved;
|
|
2971
3015
|
if (!wallet) {
|
|
2972
|
-
throw new (0,
|
|
3016
|
+
throw new (0, _chunkJG6KRAW6cjs.WalletRequiredError)(
|
|
2973
3017
|
"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)."
|
|
2974
3018
|
);
|
|
2975
3019
|
}
|
|
@@ -2979,7 +3023,7 @@ var PipRailClient = (_class2 = class {
|
|
|
2979
3023
|
if (autoRoute) {
|
|
2980
3024
|
const plan = await this.planFromChallenge(net, wallet, challenge, url, schemes);
|
|
2981
3025
|
if (!plan.best) {
|
|
2982
|
-
throw new (0,
|
|
3026
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(_nullishCoalesce(plan.fundingHint, () => ( "No rail is settleable for this payment.")));
|
|
2983
3027
|
}
|
|
2984
3028
|
accept = plan.best.accept;
|
|
2985
3029
|
quote = plan.best.quote;
|
|
@@ -3003,7 +3047,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3003
3047
|
async resolveChallenge(url, response, schemes) {
|
|
3004
3048
|
const challenge = await parseChallenge(response);
|
|
3005
3049
|
if (!challenge) {
|
|
3006
|
-
throw new (0,
|
|
3050
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)(
|
|
3007
3051
|
"402 response did not include a parseable x402 challenge."
|
|
3008
3052
|
);
|
|
3009
3053
|
}
|
|
@@ -3014,7 +3058,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3014
3058
|
(a) => a.scheme === "exact" && net.supports(a.network)
|
|
3015
3059
|
);
|
|
3016
3060
|
if (schemes.includes("exact") && exactOnNet && typeof net.payExact !== "function") {
|
|
3017
|
-
throw new (0,
|
|
3061
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
3018
3062
|
`This 402 offers a standard 'exact' rail on ${net.network}, but the ${net.family} family can't pay 'exact' (supported on EVM + Solana today), and no 'onchain-proof' rail was offered.`
|
|
3019
3063
|
);
|
|
3020
3064
|
}
|
|
@@ -3023,13 +3067,13 @@ var PipRailClient = (_class2 = class {
|
|
|
3023
3067
|
(a) => a.scheme === "exact" && net.supports(a.network) && net.describeAsset(a.asset) != null
|
|
3024
3068
|
);
|
|
3025
3069
|
if (payable) {
|
|
3026
|
-
throw new (0,
|
|
3070
|
+
throw new (0, _chunkJG6KRAW6cjs.NoCompatibleAcceptError)(
|
|
3027
3071
|
`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).`
|
|
3028
3072
|
);
|
|
3029
3073
|
}
|
|
3030
3074
|
}
|
|
3031
3075
|
const networks = [...new Set(challenge.accepts.map((a) => a.network))].join(", ");
|
|
3032
|
-
throw new (0,
|
|
3076
|
+
throw new (0, _chunkJG6KRAW6cjs.NoCompatibleAcceptError)(
|
|
3033
3077
|
`No accepts[] entry payable by this client on ${net.network} (schemes: ${schemes.join(", ")}; challenge offered: ${networks || "none"}).`
|
|
3034
3078
|
);
|
|
3035
3079
|
}
|
|
@@ -3131,21 +3175,21 @@ var PipRailClient = (_class2 = class {
|
|
|
3131
3175
|
if (isExact) {
|
|
3132
3176
|
if (tokenKnown && bal.token < amount) {
|
|
3133
3177
|
blockers.push("INSUFFICIENT_TOKEN");
|
|
3134
|
-
shortfall.token =
|
|
3178
|
+
shortfall.token = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
|
|
3135
3179
|
}
|
|
3136
3180
|
} else if (isNative) {
|
|
3137
3181
|
if (nativeKnown && bal.native < amount + fee) {
|
|
3138
3182
|
blockers.push("INSUFFICIENT_TOKEN");
|
|
3139
|
-
shortfall.token =
|
|
3183
|
+
shortfall.token = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amount + fee - bal.native, quote.decimals);
|
|
3140
3184
|
}
|
|
3141
3185
|
} else {
|
|
3142
3186
|
if (tokenKnown && bal.token < amount) {
|
|
3143
3187
|
blockers.push("INSUFFICIENT_TOKEN");
|
|
3144
|
-
shortfall.token =
|
|
3188
|
+
shortfall.token = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
|
|
3145
3189
|
}
|
|
3146
3190
|
if (nativeKnown && bal.native < fee) {
|
|
3147
3191
|
blockers.push("INSUFFICIENT_GAS");
|
|
3148
|
-
shortfall.native =
|
|
3192
|
+
shortfall.native = _chunkJG6KRAW6cjs.formatUnits.call(void 0, fee - bal.native, cost.feeDecimals);
|
|
3149
3193
|
} else if (nativeKnown && fee > 0n && bal.native < fee * 3n / 2n) {
|
|
3150
3194
|
warnings.push("THIN_GAS_MARGIN");
|
|
3151
3195
|
}
|
|
@@ -3170,8 +3214,8 @@ var PipRailClient = (_class2 = class {
|
|
|
3170
3214
|
blockers,
|
|
3171
3215
|
warnings,
|
|
3172
3216
|
balance: {
|
|
3173
|
-
token: bal.token != null ?
|
|
3174
|
-
native: bal.native != null ?
|
|
3217
|
+
token: bal.token != null ? _chunkJG6KRAW6cjs.formatUnits.call(void 0, bal.token, quote.decimals) : null,
|
|
3218
|
+
native: bal.native != null ? _chunkJG6KRAW6cjs.formatUnits.call(void 0, bal.native, cost.feeDecimals) : null
|
|
3175
3219
|
},
|
|
3176
3220
|
need: { token: quote.amountFormatted, native: cost.feeFormatted },
|
|
3177
3221
|
...shortfall.token || shortfall.native ? { shortfall } : {},
|
|
@@ -3181,21 +3225,26 @@ var PipRailClient = (_class2 = class {
|
|
|
3181
3225
|
/** Build the agent-facing quote for an accept: TRUE decimals/symbol (via the
|
|
3182
3226
|
* driver's describeAsset) + the policy verdict + a symbol-mismatch flag. */
|
|
3183
3227
|
buildQuote(net, accept, url, description) {
|
|
3184
|
-
if (!/^\d+$/.test(accept.amount)) {
|
|
3185
|
-
throw new (0,
|
|
3186
|
-
`challenge amount "${accept.amount}" is not a base-unit integer.`
|
|
3228
|
+
if (typeof accept.amount !== "string" || !/^\d+$/.test(accept.amount)) {
|
|
3229
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)(
|
|
3230
|
+
`challenge amount "${String(accept.amount)}" is not a base-unit integer string.`
|
|
3231
|
+
);
|
|
3232
|
+
}
|
|
3233
|
+
if (typeof accept.asset !== "string" || accept.asset.length === 0) {
|
|
3234
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)(
|
|
3235
|
+
`challenge on ${accept.network} states no (string) asset \u2014 refusing to price it.`
|
|
3187
3236
|
);
|
|
3188
3237
|
}
|
|
3189
3238
|
const amountBase = BigInt(accept.amount);
|
|
3190
3239
|
const described = net.describeAsset(accept.asset);
|
|
3191
|
-
const decimals = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _44 => _44.decimals]), () => ( accept.extra.decimals));
|
|
3192
|
-
if (decimals
|
|
3193
|
-
throw new (0,
|
|
3194
|
-
`challenge for ${accept.asset} on ${accept.network} states no decimals and the SDK doesn't recognise the token \u2014 refusing to price it.`
|
|
3240
|
+
const decimals = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _44 => _44.decimals]), () => ( _optionalChain([accept, 'access', _45 => _45.extra, 'optionalAccess', _46 => _46.decimals])));
|
|
3241
|
+
if (typeof decimals !== "number" || !Number.isInteger(decimals) || decimals < 0) {
|
|
3242
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)(
|
|
3243
|
+
`challenge for ${accept.asset} on ${accept.network} states no valid decimals and the SDK doesn't recognise the token \u2014 refusing to price it.`
|
|
3195
3244
|
);
|
|
3196
3245
|
}
|
|
3197
|
-
const symbol = _nullishCoalesce(_optionalChain([described, 'optionalAccess',
|
|
3198
|
-
const amountFormatted =
|
|
3246
|
+
const symbol = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _47 => _47.symbol]), () => ( _optionalChain([accept, 'access', _48 => _48.extra, 'optionalAccess', _49 => _49.symbol])));
|
|
3247
|
+
const amountFormatted = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amountBase, decimals);
|
|
3199
3248
|
const intent = {
|
|
3200
3249
|
host: hostOf2(url),
|
|
3201
3250
|
chain: this.opts.chain,
|
|
@@ -3226,7 +3275,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3226
3275
|
this.ledger.totalFor(accept.network, accept.asset),
|
|
3227
3276
|
ctx
|
|
3228
3277
|
);
|
|
3229
|
-
const serverSymbol = accept.extra.symbol;
|
|
3278
|
+
const serverSymbol = _optionalChain([accept, 'access', _50 => _50.extra, 'optionalAccess', _51 => _51.symbol]);
|
|
3230
3279
|
const symbolMismatch = intent.recognized && !!serverSymbol && !!symbol && serverSymbol.toUpperCase() !== symbol.toUpperCase();
|
|
3231
3280
|
return {
|
|
3232
3281
|
url,
|
|
@@ -3253,7 +3302,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3253
3302
|
* TERMINAL expiry/approval decline it must not retry) without parsing prose. */
|
|
3254
3303
|
async authorize(quote) {
|
|
3255
3304
|
if (!quote.withinPolicy) {
|
|
3256
|
-
throw new (0,
|
|
3305
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(
|
|
3257
3306
|
`Payment refused by policy: ${_nullishCoalesce(quote.policyReason, () => ( "not allowed"))}`,
|
|
3258
3307
|
{ reasonCode: reasonCodeForPolicy(quote.policyCode) }
|
|
3259
3308
|
);
|
|
@@ -3264,13 +3313,13 @@ var PipRailClient = (_class2 = class {
|
|
|
3264
3313
|
try {
|
|
3265
3314
|
approved = await hook(quote);
|
|
3266
3315
|
} catch (err) {
|
|
3267
|
-
throw new (0,
|
|
3316
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)("onBeforePay threw \u2014 refusing to pay.", {
|
|
3268
3317
|
cause: err,
|
|
3269
3318
|
reasonCode: "APPROVAL"
|
|
3270
3319
|
});
|
|
3271
3320
|
}
|
|
3272
3321
|
if (!approved) {
|
|
3273
|
-
throw new (0,
|
|
3322
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(
|
|
3274
3323
|
`onBeforePay declined ${quote.amountFormatted} ${_nullishCoalesce(quote.symbol, () => ( ""))}`.trimEnd() + ` on ${quote.network}.`,
|
|
3275
3324
|
{ reasonCode: "APPROVAL" }
|
|
3276
3325
|
);
|
|
@@ -3295,14 +3344,14 @@ var PipRailClient = (_class2 = class {
|
|
|
3295
3344
|
}
|
|
3296
3345
|
async payAndConfirm(net, wallet, accept) {
|
|
3297
3346
|
if (!net.supports(accept.network)) {
|
|
3298
|
-
throw new (0,
|
|
3347
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongChainError)(
|
|
3299
3348
|
`Challenge expects ${accept.network} but client is on ${net.network}.`
|
|
3300
3349
|
);
|
|
3301
3350
|
}
|
|
3302
3351
|
const ref = await net.send(wallet, accept);
|
|
3303
3352
|
this.safeEmit({ kind: "payment-broadcast", ref });
|
|
3304
3353
|
try {
|
|
3305
|
-
const { height } = await net.confirm(ref, _nullishCoalesce(accept.extra.minConfirmations, () => ( 1)));
|
|
3354
|
+
const { height } = await net.confirm(ref, _nullishCoalesce(_optionalChain([accept, 'access', _52 => _52.extra, 'optionalAccess', _53 => _53.minConfirmations]), () => ( 1)));
|
|
3306
3355
|
this.safeEmit({
|
|
3307
3356
|
kind: "payment-confirmed",
|
|
3308
3357
|
ref,
|
|
@@ -3322,9 +3371,9 @@ var PipRailClient = (_class2 = class {
|
|
|
3322
3371
|
const signature = {
|
|
3323
3372
|
x402Version: 2,
|
|
3324
3373
|
accepted: accept,
|
|
3325
|
-
payload: { nonce: accept.extra.nonce, txHash: ref }
|
|
3374
|
+
payload: { nonce: _optionalChain([accept, 'access', _54 => _54.extra, 'optionalAccess', _55 => _55.nonce]), txHash: ref }
|
|
3326
3375
|
};
|
|
3327
|
-
const headers = new Headers(_optionalChain([originalInit, 'optionalAccess',
|
|
3376
|
+
const headers = new Headers(_optionalChain([originalInit, 'optionalAccess', _56 => _56.headers]));
|
|
3328
3377
|
headers.set(HEADER_SIGNATURE, buildSignatureHeader(signature));
|
|
3329
3378
|
let lastResponse = null;
|
|
3330
3379
|
let lastReason = null;
|
|
@@ -3339,7 +3388,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3339
3388
|
() => timeoutController.abort(),
|
|
3340
3389
|
this.retryTimeoutMs
|
|
3341
3390
|
);
|
|
3342
|
-
const signal = _optionalChain([originalInit, 'optionalAccess',
|
|
3391
|
+
const signal = _optionalChain([originalInit, 'optionalAccess', _57 => _57.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, originalInit.signal]) : timeoutController.signal;
|
|
3343
3392
|
try {
|
|
3344
3393
|
lastResponse = await fetch(url, {
|
|
3345
3394
|
..._nullishCoalesce(originalInit, () => ( {})),
|
|
@@ -3348,7 +3397,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3348
3397
|
});
|
|
3349
3398
|
} catch (err) {
|
|
3350
3399
|
if (timeoutController.signal.aborted) {
|
|
3351
|
-
throw new (0,
|
|
3400
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentTimeoutError)(
|
|
3352
3401
|
`Server did not respond within ${this.retryTimeoutMs}ms after broadcasting payment ${ref}. Re-verify or re-submit ref=${ref} \u2014 do NOT re-pay.`,
|
|
3353
3402
|
{ cause: err, ref }
|
|
3354
3403
|
);
|
|
@@ -3370,7 +3419,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3370
3419
|
kind: "payment-failed",
|
|
3371
3420
|
reason: `server returned 402 after broadcasting payment ${ref}${unconfirmedNote} (${why})`
|
|
3372
3421
|
});
|
|
3373
|
-
throw new (0,
|
|
3422
|
+
throw new (0, _chunkJG6KRAW6cjs.MaxRetriesExceededError)(
|
|
3374
3423
|
`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).`,
|
|
3375
3424
|
{ ref }
|
|
3376
3425
|
);
|
|
@@ -3394,17 +3443,17 @@ var PipRailClient = (_class2 = class {
|
|
|
3394
3443
|
*/
|
|
3395
3444
|
async payExactRail(net, wallet, accept, url, init, quote) {
|
|
3396
3445
|
if (!net.payExact) {
|
|
3397
|
-
throw new (0,
|
|
3446
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
3398
3447
|
`the ${net.family} family can't pay a standard 'exact' rail (supported on EVM + Solana today).`
|
|
3399
3448
|
);
|
|
3400
3449
|
}
|
|
3401
|
-
throwIfAborted(_optionalChain([init, 'optionalAccess',
|
|
3450
|
+
throwIfAborted(_optionalChain([init, 'optionalAccess', _58 => _58.signal]));
|
|
3402
3451
|
const { payload, accepted, payerFrom, nonce } = await net.payExact(wallet, accept);
|
|
3403
|
-
const headers = new Headers(_optionalChain([init, 'optionalAccess',
|
|
3452
|
+
const headers = new Headers(_optionalChain([init, 'optionalAccess', _59 => _59.headers]));
|
|
3404
3453
|
headers.set(HEADER_SIGNATURE, buildExactSignatureHeader({ accepted, payload }));
|
|
3405
3454
|
const rejectDefinitive = (why2) => {
|
|
3406
3455
|
this.safeEmit({ kind: "payment-failed", reason: `exact: facilitator rejected nonce=${nonce} (${why2})` });
|
|
3407
|
-
throw new (0,
|
|
3456
|
+
throw new (0, _chunkJG6KRAW6cjs.MaxRetriesExceededError)(
|
|
3408
3457
|
`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}.`,
|
|
3409
3458
|
{ ref: nonce }
|
|
3410
3459
|
);
|
|
@@ -3417,17 +3466,17 @@ var PipRailClient = (_class2 = class {
|
|
|
3417
3466
|
if (Date.now() >= deadline) break;
|
|
3418
3467
|
await new Promise((r) => setTimeout(r, Math.min(2e3, 400 * 2 ** (attempt - 1))));
|
|
3419
3468
|
}
|
|
3420
|
-
throwIfAborted(_optionalChain([init, 'optionalAccess',
|
|
3469
|
+
throwIfAborted(_optionalChain([init, 'optionalAccess', _60 => _60.signal]));
|
|
3421
3470
|
const budget = Math.min(this.retryTimeoutMs, deadline - Date.now());
|
|
3422
3471
|
if (budget <= 0) break;
|
|
3423
3472
|
const timeoutController = new AbortController();
|
|
3424
3473
|
const timeoutId = setTimeout(() => timeoutController.abort(), budget);
|
|
3425
|
-
const signal = _optionalChain([init, 'optionalAccess',
|
|
3474
|
+
const signal = _optionalChain([init, 'optionalAccess', _61 => _61.signal]) && typeof AbortSignal.any === "function" ? AbortSignal.any([timeoutController.signal, init.signal]) : timeoutController.signal;
|
|
3426
3475
|
let response;
|
|
3427
3476
|
try {
|
|
3428
3477
|
response = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), headers, signal });
|
|
3429
3478
|
} catch (err) {
|
|
3430
|
-
throw new (0,
|
|
3479
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentTimeoutError)(
|
|
3431
3480
|
`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.`,
|
|
3432
3481
|
{ cause: err, ref: nonce }
|
|
3433
3482
|
);
|
|
@@ -3443,7 +3492,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3443
3492
|
if (response.ok && !(settle && settle.success === false)) {
|
|
3444
3493
|
const receipt = parseReceipt(response);
|
|
3445
3494
|
this.safeEmit({ kind: "payment-settled", receipt, ...settle ? { settle } : {} });
|
|
3446
|
-
const ref = _optionalChain([settle, 'optionalAccess',
|
|
3495
|
+
const ref = _optionalChain([settle, 'optionalAccess', _62 => _62.transaction]) || _optionalChain([receipt, 'optionalAccess', _63 => _63.transaction]) || `eip3009-nonce:${nonce}`;
|
|
3447
3496
|
this.recordSpend(quote, ref);
|
|
3448
3497
|
return response;
|
|
3449
3498
|
}
|
|
@@ -3460,14 +3509,14 @@ var PipRailClient = (_class2 = class {
|
|
|
3460
3509
|
kind: "payment-failed",
|
|
3461
3510
|
reason: `exact: 402 after submitting authorization nonce=${nonce} (${why})`
|
|
3462
3511
|
});
|
|
3463
|
-
throw new (0,
|
|
3512
|
+
throw new (0, _chunkJG6KRAW6cjs.MaxRetriesExceededError)(
|
|
3464
3513
|
`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}.`,
|
|
3465
3514
|
{ ref: nonce }
|
|
3466
3515
|
);
|
|
3467
3516
|
}
|
|
3468
3517
|
}, _class2);
|
|
3469
3518
|
function throwIfAborted(signal) {
|
|
3470
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
3519
|
+
if (_optionalChain([signal, 'optionalAccess', _64 => _64.aborted])) {
|
|
3471
3520
|
throw _nullishCoalesce(signal.reason, () => ( new DOMException("This operation was aborted.", "AbortError")));
|
|
3472
3521
|
}
|
|
3473
3522
|
}
|
|
@@ -3537,10 +3586,10 @@ function buildFundingHint(options, chainLabel) {
|
|
|
3537
3586
|
return `Couldn't fully read your wallet on ${chainLabel} (RPC throttled) \u2014 retry; you may already be able to pay ${target.quote.amountFormatted} ${sym}.`;
|
|
3538
3587
|
}
|
|
3539
3588
|
const parts = [];
|
|
3540
|
-
if (target.blockers.includes("INSUFFICIENT_TOKEN") && _optionalChain([target, 'access',
|
|
3589
|
+
if (target.blockers.includes("INSUFFICIENT_TOKEN") && _optionalChain([target, 'access', _65 => _65.shortfall, 'optionalAccess', _66 => _66.token])) {
|
|
3541
3590
|
parts.push(`top up ${target.shortfall.token} ${sym}`);
|
|
3542
3591
|
}
|
|
3543
|
-
if (target.blockers.includes("INSUFFICIENT_GAS") && _optionalChain([target, 'access',
|
|
3592
|
+
if (target.blockers.includes("INSUFFICIENT_GAS") && _optionalChain([target, 'access', _67 => _67.shortfall, 'optionalAccess', _68 => _68.native])) {
|
|
3544
3593
|
parts.push(`add ~${target.shortfall.native} ${target.cost.feeSymbol} for gas`);
|
|
3545
3594
|
}
|
|
3546
3595
|
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}.`;
|
|
@@ -3554,7 +3603,7 @@ async function planAcross(clients, url, init) {
|
|
|
3554
3603
|
const status = best ? "ready" : options.some((o) => o.state === "unknown") ? "unknown" : "blocked";
|
|
3555
3604
|
return {
|
|
3556
3605
|
url,
|
|
3557
|
-
network: _nullishCoalesce(_optionalChain([best, 'optionalAccess',
|
|
3606
|
+
network: _nullishCoalesce(_optionalChain([best, 'optionalAccess', _69 => _69.accept, 'access', _70 => _70.network]), () => ( live[0].network)),
|
|
3558
3607
|
status,
|
|
3559
3608
|
payable: best !== null,
|
|
3560
3609
|
best,
|
|
@@ -3573,7 +3622,7 @@ async function fetchAcross(clients, url, init) {
|
|
|
3573
3622
|
const best = rankAcross(live.map((p) => p.plan)).find((o) => o.state === "payable");
|
|
3574
3623
|
if (!best) {
|
|
3575
3624
|
const hint = mergeDeclineHint(live.map((p) => p.plan));
|
|
3576
|
-
throw new (0,
|
|
3625
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(hint || "No funded chain can settle this payment right now.");
|
|
3577
3626
|
}
|
|
3578
3627
|
const owner = live.find((p) => p.plan.options.includes(best)).client;
|
|
3579
3628
|
return owner.fetch(url, { ..._nullishCoalesce(init, () => ( {})), autoRoute: true });
|
|
@@ -3616,8 +3665,8 @@ function isReplayableBodyInit(value) {
|
|
|
3616
3665
|
async function readInvalidReason(response) {
|
|
3617
3666
|
try {
|
|
3618
3667
|
const body = await response.clone().json();
|
|
3619
|
-
const ext = _optionalChain([body, 'optionalAccess',
|
|
3620
|
-
const piprail = _optionalChain([ext, 'optionalAccess',
|
|
3668
|
+
const ext = _optionalChain([body, 'optionalAccess', _71 => _71.extensions]);
|
|
3669
|
+
const piprail = _optionalChain([ext, 'optionalAccess', _72 => _72.piprail]);
|
|
3621
3670
|
if (piprail && typeof piprail.code === "string") {
|
|
3622
3671
|
return {
|
|
3623
3672
|
error: piprail.code,
|
|
@@ -3639,7 +3688,7 @@ async function readInvalidReason(response) {
|
|
|
3639
3688
|
} catch (e29) {
|
|
3640
3689
|
}
|
|
3641
3690
|
const settle = parseSettleResponse(response);
|
|
3642
|
-
if (_optionalChain([settle, 'optionalAccess',
|
|
3691
|
+
if (_optionalChain([settle, 'optionalAccess', _73 => _73.errorReason])) return { error: settle.errorReason, detail: "" };
|
|
3643
3692
|
return null;
|
|
3644
3693
|
}
|
|
3645
3694
|
|
|
@@ -3669,9 +3718,9 @@ var MultiChainPayer = class _MultiChainPayer {
|
|
|
3669
3718
|
* ```ts
|
|
3670
3719
|
* const payer = MultiChainPayer.fromWallets({
|
|
3671
3720
|
* wallets: {
|
|
3672
|
-
* base: {
|
|
3673
|
-
* solana: {
|
|
3674
|
-
* xrpl: {
|
|
3721
|
+
* base: { key: process.env.EVM_KEY! },
|
|
3722
|
+
* solana: { key: process.env.SOLANA_SECRET! },
|
|
3723
|
+
* xrpl: { key: process.env.XRPL_SEED! },
|
|
3675
3724
|
* },
|
|
3676
3725
|
* policy: { maxAmount: '1.00', maxTotal: '20.00', tokens: ['USDC', 'USDT'] },
|
|
3677
3726
|
* })
|
|
@@ -3689,7 +3738,7 @@ var MultiChainPayer = class _MultiChainPayer {
|
|
|
3689
3738
|
wallet,
|
|
3690
3739
|
...opts.policy ? { policy: opts.policy } : {},
|
|
3691
3740
|
...opts.schemes ? { schemes: opts.schemes } : {},
|
|
3692
|
-
..._optionalChain([opts, 'access',
|
|
3741
|
+
..._optionalChain([opts, 'access', _74 => _74.rpcUrls, 'optionalAccess', _75 => _75[chain]]) ? { rpcUrl: opts.rpcUrls[chain] } : {},
|
|
3693
3742
|
...opts.onBeforePay ? { onBeforePay: opts.onBeforePay } : {},
|
|
3694
3743
|
...opts.onEvent ? { onEvent: opts.onEvent } : {},
|
|
3695
3744
|
...opts.maxPaymentRetries != null ? { maxPaymentRetries: opts.maxPaymentRetries } : {},
|
|
@@ -3747,7 +3796,7 @@ var MultiChainPayer = class _MultiChainPayer {
|
|
|
3747
3796
|
* {@link PipRailClient.post}.
|
|
3748
3797
|
*/
|
|
3749
3798
|
post(url, body, init) {
|
|
3750
|
-
const headers = new Headers(_optionalChain([init, 'optionalAccess',
|
|
3799
|
+
const headers = new Headers(_optionalChain([init, 'optionalAccess', _76 => _76.headers]));
|
|
3751
3800
|
let payload;
|
|
3752
3801
|
if (body === void 0 || body === null) {
|
|
3753
3802
|
payload = void 0;
|
|
@@ -3879,7 +3928,7 @@ function summarizePlan(plan) {
|
|
|
3879
3928
|
return `NOT payable: ${_nullishCoalesce(plan.fundingHint, () => ( `no settleable rail on ${plan.network}`))}`;
|
|
3880
3929
|
}
|
|
3881
3930
|
function explainDecline(err) {
|
|
3882
|
-
if (!(err instanceof
|
|
3931
|
+
if (!(err instanceof _chunkJG6KRAW6cjs.PipRailError)) {
|
|
3883
3932
|
return `Payment failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
3884
3933
|
}
|
|
3885
3934
|
switch (err.code) {
|
|
@@ -4015,6 +4064,22 @@ async function readBody(res) {
|
|
|
4015
4064
|
return text;
|
|
4016
4065
|
}
|
|
4017
4066
|
}
|
|
4067
|
+
function toToolError(err) {
|
|
4068
|
+
if (!(err instanceof _chunkJG6KRAW6cjs.PipRailError)) throw err;
|
|
4069
|
+
const out = {
|
|
4070
|
+
ok: false,
|
|
4071
|
+
code: err.code,
|
|
4072
|
+
reason: err.message,
|
|
4073
|
+
explain: explainDecline(err)
|
|
4074
|
+
};
|
|
4075
|
+
if (err instanceof _chunkJG6KRAW6cjs.PaymentDeclinedError) {
|
|
4076
|
+
out.declined = true;
|
|
4077
|
+
if (err.reasonCode) out.reasonCode = err.reasonCode;
|
|
4078
|
+
}
|
|
4079
|
+
const ref = err.ref;
|
|
4080
|
+
if (typeof ref === "string") out.ref = ref;
|
|
4081
|
+
return out;
|
|
4082
|
+
}
|
|
4018
4083
|
function paymentTools(client) {
|
|
4019
4084
|
return [
|
|
4020
4085
|
{
|
|
@@ -4041,23 +4106,27 @@ function paymentTools(client) {
|
|
|
4041
4106
|
additionalProperties: false
|
|
4042
4107
|
},
|
|
4043
4108
|
invoke: async (args) => {
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4109
|
+
try {
|
|
4110
|
+
const opts = {};
|
|
4111
|
+
if (typeof args.query === "string") opts.query = args.query;
|
|
4112
|
+
if (typeof args.network === "string") opts.network = args.network;
|
|
4113
|
+
if (typeof args.maxPrice === "number") opts.maxPrice = args.maxPrice;
|
|
4114
|
+
if (typeof args.limit === "number") opts.limit = args.limit;
|
|
4115
|
+
const found = await client.discover(opts);
|
|
4116
|
+
return {
|
|
4117
|
+
count: found.length,
|
|
4118
|
+
resources: found.map((r) => ({
|
|
4119
|
+
resource: r.resource,
|
|
4120
|
+
name: r.name,
|
|
4121
|
+
description: r.description,
|
|
4122
|
+
source: r.source,
|
|
4123
|
+
priceUsd: r.priceUsd,
|
|
4124
|
+
networks: [...new Set(r.rails.map((rail) => rail.network))]
|
|
4125
|
+
}))
|
|
4126
|
+
};
|
|
4127
|
+
} catch (err) {
|
|
4128
|
+
return toToolError(err);
|
|
4129
|
+
}
|
|
4061
4130
|
}
|
|
4062
4131
|
},
|
|
4063
4132
|
{
|
|
@@ -4080,8 +4149,12 @@ function paymentTools(client) {
|
|
|
4080
4149
|
},
|
|
4081
4150
|
outputSchema: OPEN_OBJECT,
|
|
4082
4151
|
invoke: async (args) => {
|
|
4083
|
-
|
|
4084
|
-
|
|
4152
|
+
try {
|
|
4153
|
+
const quote = await client.quote(String(args.url));
|
|
4154
|
+
return quote ? { gated: true, ...quote } : { gated: false, url: String(args.url) };
|
|
4155
|
+
} catch (err) {
|
|
4156
|
+
return toToolError(err);
|
|
4157
|
+
}
|
|
4085
4158
|
}
|
|
4086
4159
|
},
|
|
4087
4160
|
{
|
|
@@ -4104,34 +4177,38 @@ function paymentTools(client) {
|
|
|
4104
4177
|
},
|
|
4105
4178
|
outputSchema: OPEN_OBJECT,
|
|
4106
4179
|
invoke: async (args) => {
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4180
|
+
try {
|
|
4181
|
+
const plan = await client.planPayment(String(args.url));
|
|
4182
|
+
if (plan == null) return { gated: false, url: String(args.url) };
|
|
4183
|
+
return {
|
|
4184
|
+
gated: true,
|
|
4185
|
+
payable: plan.payable,
|
|
4186
|
+
status: plan.status,
|
|
4187
|
+
fundingHint: plan.fundingHint,
|
|
4188
|
+
// One model-readable line distilling the whole plan.
|
|
4189
|
+
summary: summarizePlan(plan),
|
|
4190
|
+
best: plan.best ? {
|
|
4191
|
+
network: plan.best.accept.network,
|
|
4192
|
+
symbol: plan.best.quote.symbol,
|
|
4193
|
+
amount: plan.best.quote.amountFormatted,
|
|
4194
|
+
gasCoin: plan.best.cost.feeSymbol,
|
|
4195
|
+
gas: plan.best.cost.feeFormatted
|
|
4196
|
+
} : null,
|
|
4197
|
+
options: plan.options.map((o) => ({
|
|
4198
|
+
network: o.accept.network,
|
|
4199
|
+
symbol: o.quote.symbol,
|
|
4200
|
+
amount: o.quote.amountFormatted,
|
|
4201
|
+
state: o.state,
|
|
4202
|
+
blockers: o.blockers,
|
|
4203
|
+
warnings: o.warnings,
|
|
4204
|
+
recipientReady: o.recipient.ready
|
|
4205
|
+
})),
|
|
4206
|
+
// The session's time leash, present only when a time policy is configured.
|
|
4207
|
+
...plan.session ? { session: plan.session } : {}
|
|
4208
|
+
};
|
|
4209
|
+
} catch (err) {
|
|
4210
|
+
return toToolError(err);
|
|
4211
|
+
}
|
|
4135
4212
|
}
|
|
4136
4213
|
},
|
|
4137
4214
|
{
|
|
@@ -4188,14 +4265,14 @@ function paymentTools(client) {
|
|
|
4188
4265
|
receipt: parseReceipt(res)
|
|
4189
4266
|
};
|
|
4190
4267
|
} catch (err) {
|
|
4191
|
-
if (err instanceof
|
|
4268
|
+
if (err instanceof _chunkJG6KRAW6cjs.PipRailError) {
|
|
4192
4269
|
const out = {
|
|
4193
4270
|
ok: false,
|
|
4194
4271
|
code: err.code,
|
|
4195
4272
|
reason: err.message,
|
|
4196
4273
|
explain: explainDecline(err)
|
|
4197
4274
|
};
|
|
4198
|
-
if (err instanceof
|
|
4275
|
+
if (err instanceof _chunkJG6KRAW6cjs.PaymentDeclinedError) {
|
|
4199
4276
|
out.declined = true;
|
|
4200
4277
|
if (err.reasonCode) out.reasonCode = err.reasonCode;
|
|
4201
4278
|
}
|
|
@@ -4237,14 +4314,18 @@ function paymentTools(client) {
|
|
|
4237
4314
|
additionalProperties: false
|
|
4238
4315
|
},
|
|
4239
4316
|
invoke: async (args) => {
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4317
|
+
try {
|
|
4318
|
+
const opts = {};
|
|
4319
|
+
if (typeof args.name === "string") opts.name = args.name;
|
|
4320
|
+
if (typeof args.description === "string") opts.description = args.description;
|
|
4321
|
+
if (typeof args.priceUsd === "number") opts.priceUsd = args.priceUsd;
|
|
4322
|
+
if (typeof args.network === "string") opts.network = args.network;
|
|
4323
|
+
if (typeof args.asset === "string") opts.asset = args.asset;
|
|
4324
|
+
const outcomes = await client.register(String(args.url), opts);
|
|
4325
|
+
return { outcomes };
|
|
4326
|
+
} catch (err) {
|
|
4327
|
+
return toToolError(err);
|
|
4328
|
+
}
|
|
4248
4329
|
}
|
|
4249
4330
|
},
|
|
4250
4331
|
{
|
|
@@ -4260,14 +4341,18 @@ function paymentTools(client) {
|
|
|
4260
4341
|
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
4261
4342
|
outputSchema: OPEN_OBJECT,
|
|
4262
4343
|
invoke: async () => {
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4344
|
+
try {
|
|
4345
|
+
const spent = client.spent();
|
|
4346
|
+
const budget = client.budget();
|
|
4347
|
+
return {
|
|
4348
|
+
spent,
|
|
4349
|
+
remaining: budget.byAsset,
|
|
4350
|
+
session: budget.session,
|
|
4351
|
+
report: formatSpendReport(spent)
|
|
4352
|
+
};
|
|
4353
|
+
} catch (err) {
|
|
4354
|
+
return toToolError(err);
|
|
4355
|
+
}
|
|
4271
4356
|
}
|
|
4272
4357
|
},
|
|
4273
4358
|
{
|
|
@@ -4445,10 +4530,10 @@ async function fetchFacilitatorFeePayer(url, network, timeoutMs = 8e3) {
|
|
|
4445
4530
|
const res = await fetch(`${base2}/supported`, { signal: ctrl.signal });
|
|
4446
4531
|
if (!res.ok) return void 0;
|
|
4447
4532
|
const body = await res.json();
|
|
4448
|
-
const kinds = Array.isArray(_optionalChain([body, 'optionalAccess',
|
|
4533
|
+
const kinds = Array.isArray(_optionalChain([body, 'optionalAccess', _77 => _77.kinds])) ? body.kinds : [];
|
|
4449
4534
|
const want = normalizeNetwork(network);
|
|
4450
|
-
const kind = kinds.find((k) => _optionalChain([k, 'optionalAccess',
|
|
4451
|
-
const fp = _optionalChain([kind, 'optionalAccess',
|
|
4535
|
+
const kind = kinds.find((k) => _optionalChain([k, 'optionalAccess', _78 => _78.scheme]) === "exact" && normalizeNetwork(String(_nullishCoalesce(_optionalChain([k, 'optionalAccess', _79 => _79.network]), () => ( "")))) === want);
|
|
4536
|
+
const fp = _optionalChain([kind, 'optionalAccess', _80 => _80.extra, 'optionalAccess', _81 => _81.feePayer]);
|
|
4452
4537
|
return typeof fp === "string" ? fp : void 0;
|
|
4453
4538
|
} catch (e32) {
|
|
4454
4539
|
return void 0;
|
|
@@ -4457,14 +4542,14 @@ async function fetchFacilitatorFeePayer(url, network, timeoutMs = 8e3) {
|
|
|
4457
4542
|
}
|
|
4458
4543
|
}
|
|
4459
4544
|
function parseFacilitatorSupported(body) {
|
|
4460
|
-
const kinds = _optionalChain([body, 'optionalAccess',
|
|
4545
|
+
const kinds = _optionalChain([body, 'optionalAccess', _82 => _82.kinds]);
|
|
4461
4546
|
if (!Array.isArray(kinds)) return [];
|
|
4462
4547
|
const out = [];
|
|
4463
4548
|
for (const k of kinds) {
|
|
4464
4549
|
if (!k || typeof k !== "object") continue;
|
|
4465
4550
|
const o = k;
|
|
4466
4551
|
if (typeof o.scheme !== "string" || typeof o.network !== "string") continue;
|
|
4467
|
-
const fp = _optionalChain([o, 'access',
|
|
4552
|
+
const fp = _optionalChain([o, 'access', _83 => _83.extra, 'optionalAccess', _84 => _84.feePayer]);
|
|
4468
4553
|
out.push({ scheme: o.scheme, network: o.network, ...typeof fp === "string" ? { feePayer: fp } : {} });
|
|
4469
4554
|
}
|
|
4470
4555
|
return out;
|
|
@@ -4522,13 +4607,13 @@ async function settleViaFacilitator(input) {
|
|
|
4522
4607
|
try {
|
|
4523
4608
|
verify = await post(`${base2}/verify`, body, auth);
|
|
4524
4609
|
} catch (err) {
|
|
4525
|
-
throw new (0,
|
|
4610
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4526
4611
|
`exact settle (facilitator ${base2}): /verify request failed (${err instanceof Error ? err.message : String(err)}).`,
|
|
4527
4612
|
{ cause: err }
|
|
4528
4613
|
);
|
|
4529
4614
|
}
|
|
4530
4615
|
if (verify.status !== 200) {
|
|
4531
|
-
throw new (0,
|
|
4616
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4532
4617
|
`exact settle (facilitator ${base2}): /verify returned HTTP ${verify.status} (transport/auth error).`
|
|
4533
4618
|
);
|
|
4534
4619
|
}
|
|
@@ -4544,13 +4629,13 @@ async function settleViaFacilitator(input) {
|
|
|
4544
4629
|
try {
|
|
4545
4630
|
settle = await post(`${base2}/settle`, body, auth);
|
|
4546
4631
|
} catch (err) {
|
|
4547
|
-
throw new (0,
|
|
4632
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4548
4633
|
`exact settle (facilitator ${base2}): /settle request failed (${err instanceof Error ? err.message : String(err)}).`,
|
|
4549
4634
|
{ cause: err }
|
|
4550
4635
|
);
|
|
4551
4636
|
}
|
|
4552
4637
|
if (settle.status !== 200) {
|
|
4553
|
-
throw new (0,
|
|
4638
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4554
4639
|
`exact settle (facilitator ${base2}): /settle returned HTTP ${settle.status} (transport/auth error).`
|
|
4555
4640
|
);
|
|
4556
4641
|
}
|
|
@@ -4617,7 +4702,7 @@ function createPaymentGate(options) {
|
|
|
4617
4702
|
}
|
|
4618
4703
|
net.assertValidPayTo(payTo);
|
|
4619
4704
|
const { asset, decimals, symbol } = net.resolveToken(a.token);
|
|
4620
|
-
const amountBase =
|
|
4705
|
+
const amountBase = _chunkJG6KRAW6cjs.parseUnits.call(void 0, a.amount, decimals);
|
|
4621
4706
|
const spec = { net, asset, decimals, symbol, amountBase, amountFormatted: a.amount, payTo };
|
|
4622
4707
|
if (options.exact) {
|
|
4623
4708
|
const outcome = await resolveExactRail(net, asset);
|
|
@@ -4649,7 +4734,7 @@ function createPaymentGate(options) {
|
|
|
4649
4734
|
if (settle === "self") {
|
|
4650
4735
|
if (cfg.relayer === void 0) {
|
|
4651
4736
|
throw new Error(
|
|
4652
|
-
"requirePayment: exact `settle: 'self'` needs a `relayer` wallet (the gas-paying key that broadcasts the settle), e.g. exact: { settle: 'self', relayer: {
|
|
4737
|
+
"requirePayment: exact `settle: 'self'` needs a `relayer` wallet (the gas-paying key that broadcasts the settle), e.g. exact: { settle: 'self', relayer: { key } }."
|
|
4653
4738
|
);
|
|
4654
4739
|
}
|
|
4655
4740
|
relayer = net.bindWallet(cfg.relayer);
|
|
@@ -4765,7 +4850,7 @@ function createPaymentGate(options) {
|
|
|
4765
4850
|
accepts,
|
|
4766
4851
|
instruction: describeChallenge({ x402Version: 2, resource: { url: resourceUrl }, accepts })
|
|
4767
4852
|
});
|
|
4768
|
-
const rejectionExt = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
4853
|
+
const rejectionExt = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.extensions]), () => ( {}));
|
|
4769
4854
|
const rejectionPiprail = _nullishCoalesce(rejectionExt.piprail, () => ( {}));
|
|
4770
4855
|
const bodyPiprail = { ..._nullishCoalesce(selfDescribe, () => ( {})), ...rejectionPiprail };
|
|
4771
4856
|
const bodyExtensions = {
|
|
@@ -4784,7 +4869,7 @@ function createPaymentGate(options) {
|
|
|
4784
4869
|
...options.description ? { description: options.description } : {}
|
|
4785
4870
|
},
|
|
4786
4871
|
accepts,
|
|
4787
|
-
..._optionalChain([opts, 'optionalAccess',
|
|
4872
|
+
..._optionalChain([opts, 'optionalAccess', _86 => _86.error]) ? { error: opts.error } : {},
|
|
4788
4873
|
...Object.keys(bodyExtensions).length > 0 ? { extensions: bodyExtensions } : {}
|
|
4789
4874
|
};
|
|
4790
4875
|
const headerChallenge = {
|
|
@@ -4815,7 +4900,7 @@ function createPaymentGate(options) {
|
|
|
4815
4900
|
function enrichReceipt(spec, receipt) {
|
|
4816
4901
|
let amountFormatted = receipt.amount;
|
|
4817
4902
|
try {
|
|
4818
|
-
amountFormatted =
|
|
4903
|
+
amountFormatted = _chunkJG6KRAW6cjs.formatUnits.call(void 0, BigInt(receipt.amount), spec.decimals);
|
|
4819
4904
|
} catch (e35) {
|
|
4820
4905
|
}
|
|
4821
4906
|
return {
|
|
@@ -5005,7 +5090,7 @@ function requirePayment(options) {
|
|
|
5005
5090
|
try {
|
|
5006
5091
|
result = await gate.verify(_nullishCoalesce(req.headers[HEADER_SIGNATURE], () => ( req.headers[HEADER_SIGNATURE_V1])));
|
|
5007
5092
|
} catch (err) {
|
|
5008
|
-
if (err instanceof
|
|
5093
|
+
if (err instanceof _chunkJG6KRAW6cjs.SettlementError) {
|
|
5009
5094
|
res.status(502);
|
|
5010
5095
|
res.json({ x402Version: 2, error: "settlement_failed", detail: err.message });
|
|
5011
5096
|
return;
|
|
@@ -5105,7 +5190,7 @@ function isRetryableStatus(status) {
|
|
|
5105
5190
|
}
|
|
5106
5191
|
var sleep = (ms) => ms > 0 ? new Promise((resolve) => setTimeout(resolve, ms)) : Promise.resolve();
|
|
5107
5192
|
async function signBody(secret, body) {
|
|
5108
|
-
const subtle = _optionalChain([globalThis, 'access',
|
|
5193
|
+
const subtle = _optionalChain([globalThis, 'access', _87 => _87.crypto, 'optionalAccess', _88 => _88.subtle]);
|
|
5109
5194
|
if (!subtle) return null;
|
|
5110
5195
|
try {
|
|
5111
5196
|
const enc = new TextEncoder();
|
|
@@ -5175,7 +5260,7 @@ async function deliverReceipt(receipt, options) {
|
|
|
5175
5260
|
const retryable = status === void 0 ? true : isRetryableStatus(status);
|
|
5176
5261
|
const willRetry = !ok && retryable && attempt < maxAttempts;
|
|
5177
5262
|
try {
|
|
5178
|
-
_optionalChain([onAttempt, 'optionalCall',
|
|
5263
|
+
_optionalChain([onAttempt, 'optionalCall', _89 => _89({ attempt, ok, ...status !== void 0 ? { status } : {}, ...error ? { error } : {}, willRetry })]);
|
|
5179
5264
|
} catch (e39) {
|
|
5180
5265
|
}
|
|
5181
5266
|
if (ok) return { delivered: true, attempts: attempt, status };
|
|
@@ -5291,4 +5376,4 @@ async function deliverReceipt(receipt, options) {
|
|
|
5291
5376
|
|
|
5292
5377
|
|
|
5293
5378
|
|
|
5294
|
-
exports.BRAND = BRAND; exports.CHAINS = CHAINS; exports.ConfirmationTimeoutError =
|
|
5379
|
+
exports.BRAND = BRAND; exports.CHAINS = CHAINS; exports.ConfirmationTimeoutError = _chunkJG6KRAW6cjs.ConfirmationTimeoutError; exports.DIRECTORY_INFO = DIRECTORY_INFO; exports.EIP3009_TYPES = EIP3009_TYPES; exports.EXACT_NETWORK_SLUGS = EXACT_NETWORK_SLUGS; 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 = _chunkJG6KRAW6cjs.InsufficientFundsError; exports.InvalidEnvelopeError = _chunkJG6KRAW6cjs.InvalidEnvelopeError; exports.KNOWN_FACILITATORS = KNOWN_FACILITATORS; exports.MaxRetriesExceededError = _chunkJG6KRAW6cjs.MaxRetriesExceededError; exports.MissingDriverError = _chunkJG6KRAW6cjs.MissingDriverError; exports.MultiChainPayer = MultiChainPayer; exports.NoCompatibleAcceptError = _chunkJG6KRAW6cjs.NoCompatibleAcceptError; exports.NonReplayableBodyError = _chunkJG6KRAW6cjs.NonReplayableBodyError; exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS; exports.PERMIT2_PROXY_CHAIN_IDS = PERMIT2_PROXY_CHAIN_IDS; exports.PERMIT2_WITNESS_TYPES = PERMIT2_WITNESS_TYPES; exports.PIPRAIL_AGENT_GUIDE = PIPRAIL_AGENT_GUIDE; exports.POWERED_BY = POWERED_BY; exports.PaymentDeclinedError = _chunkJG6KRAW6cjs.PaymentDeclinedError; exports.PaymentTimeoutError = _chunkJG6KRAW6cjs.PaymentTimeoutError; exports.PipRailClient = PipRailClient; exports.PipRailError = _chunkJG6KRAW6cjs.PipRailError; exports.REGISTER_ATTRIBUTION = REGISTER_ATTRIBUTION; exports.RecipientNotReadyError = _chunkJG6KRAW6cjs.RecipientNotReadyError; exports.SettlementError = _chunkJG6KRAW6cjs.SettlementError; exports.UnknownTokenError = _chunkJG6KRAW6cjs.UnknownTokenError; exports.UnsupportedNetworkError = _chunkJG6KRAW6cjs.UnsupportedNetworkError; exports.UnsupportedSchemeError = _chunkJG6KRAW6cjs.UnsupportedSchemeError; exports.WalletRequiredError = _chunkJG6KRAW6cjs.WalletRequiredError; exports.WrongChainError = _chunkJG6KRAW6cjs.WrongChainError; exports.WrongFamilyError = _chunkJG6KRAW6cjs.WrongFamilyError; exports.X402_EXACT_PERMIT2_PROXY = X402_EXACT_PERMIT2_PROXY; exports.agentGuide = agentGuide; exports.appendAttribution = appendAttribution; exports.buildBazaarExtension = buildBazaarExtension; exports.buildChallengeHeader = buildChallengeHeader; exports.buildExactAuthorization = buildExactAuthorization; exports.buildExactSignatureHeader = buildExactSignatureHeader; exports.buildOpenApi = buildOpenApi; exports.buildReceiptHeader = buildReceiptHeader; exports.buildSelfDescription = buildSelfDescription; exports.buildSignatureHeader = buildSignatureHeader; exports.buildWellKnownX402 = buildWellKnownX402; exports.buildX402DnsTxt = buildX402DnsTxt; exports.chainIdForExactNetwork = chainIdForExactNetwork; exports.claim402IndexDomain = claim402IndexDomain; exports.classifyChallenge = classifyChallenge; exports.createPaymentGate = createPaymentGate; exports.decorateOutcome = decorateOutcome; exports.deliverReceipt = deliverReceipt; 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.getDirectoryInfo = getDirectoryInfo; exports.isPermit2ProxyChain = isPermit2ProxyChain; exports.knownFacilitatorsFor = knownFacilitatorsFor; exports.normalizeNetwork = normalizeNetwork; exports.parseChallenge = parseChallenge; exports.parseExactPaymentHeader = parseExactPaymentHeader; exports.parseExactRequirements = parseExactRequirements; exports.parseFacilitatorSupported = parseFacilitatorSupported; exports.parseReceipt = parseReceipt; exports.parseSettleResponse = parseSettleResponse; exports.parseSignatureHeader = parseSignatureHeader; exports.paymentTools = paymentTools; exports.pickAccept = pickAccept; exports.planAcross = planAcross; exports.readExactDomain = readExactDomain; exports.register402Index = register402Index; exports.registerDriver = registerDriver; exports.registerX402Scan = registerX402Scan; exports.renderLandingPage = renderLandingPage; exports.requirePayment = requirePayment; exports.resolveChain = resolveChain; exports.searchOpenIndexes = searchOpenIndexes; exports.settleViaFacilitator = settleViaFacilitator; exports.summarizePlan = summarizePlan; exports.toInsufficientFundsError = _chunkJG6KRAW6cjs.toInsufficientFundsError; exports.toInvalidBody = toInvalidBody; exports.verify402IndexDomain = verify402IndexDomain;
|