@piprail/sdk 2.0.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 +30 -0
- package/dist/{algorand-RJ4DRWHV.js → algorand-GSFVZTBF.js} +1 -1
- package/dist/{algorand-RUDF55XY.cjs → algorand-HZS43N4P.cjs} +16 -16
- package/dist/{aptos-SMEQXIYJ.js → aptos-RIL56C7L.js} +1 -1
- package/dist/{aptos-PESRG2EQ.cjs → aptos-TRCCJRZA.cjs} +15 -15
- package/dist/{chunk-47VEOHZN.js → chunk-7XK22JSQ.js} +1 -1
- package/dist/{chunk-DKQXW454.cjs → chunk-JG6KRAW6.cjs} +1 -1
- package/dist/index.cjs +269 -192
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +160 -83
- package/dist/{near-VWBV3SUW.cjs → near-DI2I3MAV.cjs} +18 -18
- package/dist/{near-CHE7B2CY.js → near-MTYBCUYM.js} +1 -1
- package/dist/{solana-DTO2R3AT.js → solana-E4MD6JJ6.js} +14 -3
- package/dist/{solana-OIHRPGX2.cjs → solana-TLHL2KNY.cjs} +41 -30
- package/dist/{stellar-AF7PYMMF.cjs → stellar-FW6C6FBE.cjs} +21 -21
- package/dist/{stellar-T5VONOEO.js → stellar-U5NCRIOJ.js} +2 -2
- package/dist/{sui-3TF5XVRT.cjs → sui-47C2KEZI.cjs} +16 -16
- package/dist/{sui-J53NYMVL.js → sui-Y53M4GUM.js} +1 -1
- package/dist/{ton-CPK57L2O.js → ton-5ZPT5PSP.js} +12 -2
- package/dist/{ton-ZEI7YUK7.cjs → ton-MMPKWT6N.cjs} +24 -14
- package/dist/{tron-5B3Q4SMF.cjs → tron-JOT4STIG.cjs} +26 -23
- package/dist/{tron-LZRCDRZC.js → tron-WYS4X2I5.js} +4 -1
- package/dist/{xrpl-AH4FFC2C.js → xrpl-2MZEOIFY.js} +1 -1
- package/dist/{xrpl-BL4QXOVN.cjs → xrpl-PECT4IMX.cjs} +20 -20
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
|
|
28
28
|
|
|
29
29
|
// src/drivers/registry.ts
|
|
30
30
|
var byFamily = /* @__PURE__ */ new Map();
|
|
@@ -53,13 +53,13 @@ function resolveNetwork(opts) {
|
|
|
53
53
|
const family = familyForChain(opts.chain);
|
|
54
54
|
const driver = byFamily.get(family);
|
|
55
55
|
if (!driver) {
|
|
56
|
-
throw new (0,
|
|
56
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedNetworkError)(
|
|
57
57
|
`No driver registered for the "${family}" family \u2014 it may not be mounted yet (use the async resolveNetwork()).`
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
const net = driver.resolve(opts);
|
|
61
61
|
if (!net) {
|
|
62
|
-
throw new (0,
|
|
62
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedNetworkError)(
|
|
63
63
|
`The ${family} driver didn't recognise this chain input.`
|
|
64
64
|
);
|
|
65
65
|
}
|
|
@@ -320,21 +320,35 @@ function resolveChain(input, rpcUrlOverride) {
|
|
|
320
320
|
|
|
321
321
|
var _accounts = require('viem/accounts');
|
|
322
322
|
function createWalletAdapter(config, resolved) {
|
|
323
|
-
|
|
323
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, config, "EVM");
|
|
324
324
|
if ("key" in config) {
|
|
325
|
-
const
|
|
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
|
+
}
|
|
326
340
|
const transport = _viem.http.call(void 0, resolved.rpcUrl);
|
|
327
341
|
const walletClient = _viem.createWalletClient.call(void 0, { account, chain: resolved.chain, transport });
|
|
328
342
|
return { account, walletClient };
|
|
329
343
|
}
|
|
330
344
|
const wc = config.walletClient;
|
|
331
345
|
if (!wc.account) {
|
|
332
|
-
throw new (0,
|
|
346
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
333
347
|
"chain is EVM; the provided walletClient has no attached account. Use `createWalletClient({ account, chain, transport })`, or pass { key }."
|
|
334
348
|
);
|
|
335
349
|
}
|
|
336
350
|
if (wc.chain && wc.chain.id !== resolved.chainId) {
|
|
337
|
-
throw new (0,
|
|
351
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongChainError)(
|
|
338
352
|
`PipRailClient: walletClient is on chain ${wc.chain.id} but the SDK was configured with chain ${resolved.chainId}. They must match.`
|
|
339
353
|
);
|
|
340
354
|
}
|
|
@@ -664,7 +678,7 @@ async function payExactEvm(input) {
|
|
|
664
678
|
code = void 0;
|
|
665
679
|
}
|
|
666
680
|
if (code && code !== "0x") {
|
|
667
|
-
throw new (0,
|
|
681
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
668
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.`
|
|
669
683
|
);
|
|
670
684
|
}
|
|
@@ -674,13 +688,13 @@ async function payExactEvm(input) {
|
|
|
674
688
|
domain = await readExactDomain(publicClient, accept.asset);
|
|
675
689
|
}
|
|
676
690
|
if (!domain) {
|
|
677
|
-
throw new (0,
|
|
691
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
678
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.`
|
|
679
693
|
);
|
|
680
694
|
}
|
|
681
695
|
const g = globalThis.crypto;
|
|
682
696
|
if (!_optionalChain([g, 'optionalAccess', _5 => _5.getRandomValues])) {
|
|
683
|
-
throw new (0,
|
|
697
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
684
698
|
"this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the exact rail needs a CSPRNG nonce."
|
|
685
699
|
);
|
|
686
700
|
}
|
|
@@ -937,7 +951,7 @@ async function verifyAndSettleExactEvm(input) {
|
|
|
937
951
|
args: writeArgs
|
|
938
952
|
});
|
|
939
953
|
} catch (err) {
|
|
940
|
-
throw new (0,
|
|
954
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
941
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.`,
|
|
942
956
|
{ cause: err }
|
|
943
957
|
);
|
|
@@ -949,7 +963,7 @@ async function verifyAndSettleExactEvm(input) {
|
|
|
949
963
|
return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
|
|
950
964
|
}
|
|
951
965
|
} catch (err) {
|
|
952
|
-
throw new (0,
|
|
966
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
953
967
|
`exact settle: broadcast ${txHash} but couldn't confirm it (${shorten(err instanceof Error ? err.message : String(err))}).`,
|
|
954
968
|
{ cause: err }
|
|
955
969
|
);
|
|
@@ -1080,7 +1094,7 @@ function shorten2(msg) {
|
|
|
1080
1094
|
function randomPermit2Nonce() {
|
|
1081
1095
|
const g = globalThis.crypto;
|
|
1082
1096
|
if (!_optionalChain([g, 'optionalAccess', _8 => _8.getRandomValues])) {
|
|
1083
|
-
throw new (0,
|
|
1097
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
1084
1098
|
"this runtime lacks Web Crypto (globalThis.crypto.getRandomValues); the permit2 rail needs a CSPRNG nonce."
|
|
1085
1099
|
);
|
|
1086
1100
|
}
|
|
@@ -1099,7 +1113,7 @@ async function ensurePermit2Allowance(input) {
|
|
|
1099
1113
|
args: [account.address, PERMIT2_ADDRESS]
|
|
1100
1114
|
});
|
|
1101
1115
|
} catch (err) {
|
|
1102
|
-
throw new (0,
|
|
1116
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
1103
1117
|
`permit2: couldn't read the Permit2 allowance for ${token} (${shorten2(err instanceof Error ? err.message : String(err))}).`
|
|
1104
1118
|
);
|
|
1105
1119
|
}
|
|
@@ -1116,7 +1130,7 @@ async function ensurePermit2Allowance(input) {
|
|
|
1116
1130
|
await publicClient.waitForTransactionReceipt({ hash, confirmations: 1 });
|
|
1117
1131
|
return hash;
|
|
1118
1132
|
} catch (err) {
|
|
1119
|
-
throw _nullishCoalesce(
|
|
1133
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
1120
1134
|
`permit2: the one-time Permit2 approval for ${token} failed to broadcast (${shorten2(err instanceof Error ? err.message : String(err))}).`,
|
|
1121
1135
|
{ cause: err }
|
|
1122
1136
|
)));
|
|
@@ -1131,7 +1145,7 @@ async function payPermit2Evm(input) {
|
|
|
1131
1145
|
code = void 0;
|
|
1132
1146
|
}
|
|
1133
1147
|
if (code && code !== "0x") {
|
|
1134
|
-
throw new (0,
|
|
1148
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
1135
1149
|
`permit2 buyer rail requires an EOA signer; ${account.address} is a contract / EIP-1271 / EIP-7702-delegated account. Pay via onchain-proof.`
|
|
1136
1150
|
);
|
|
1137
1151
|
}
|
|
@@ -1306,7 +1320,7 @@ async function verifyAndSettlePermit2Evm(input) {
|
|
|
1306
1320
|
args: settleArgs
|
|
1307
1321
|
});
|
|
1308
1322
|
} catch (err) {
|
|
1309
|
-
throw new (0,
|
|
1323
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
1310
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.`,
|
|
1311
1325
|
{ cause: err }
|
|
1312
1326
|
);
|
|
@@ -1318,7 +1332,7 @@ async function verifyAndSettlePermit2Evm(input) {
|
|
|
1318
1332
|
return { ok: false, error: "tx_reverted", detail: `Settlement tx ${txHash} reverted on-chain.` };
|
|
1319
1333
|
}
|
|
1320
1334
|
} catch (err) {
|
|
1321
|
-
throw new (0,
|
|
1335
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
1322
1336
|
`permit2 settle: broadcast ${txHash} but couldn't confirm it (${shorten2(err instanceof Error ? err.message : String(err))}).`,
|
|
1323
1337
|
{ cause: err }
|
|
1324
1338
|
);
|
|
@@ -1494,6 +1508,7 @@ function isValidChallenge(value) {
|
|
|
1494
1508
|
const v = value;
|
|
1495
1509
|
if (v.x402Version !== 2) return false;
|
|
1496
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;
|
|
1497
1512
|
if (!v.resource || typeof v.resource !== "object") return false;
|
|
1498
1513
|
return true;
|
|
1499
1514
|
}
|
|
@@ -1551,15 +1566,15 @@ function makeEvmNetwork(resolved) {
|
|
|
1551
1566
|
const info = resolved.tokens[token.toUpperCase()];
|
|
1552
1567
|
if (!info) {
|
|
1553
1568
|
const known = Object.keys(resolved.tokens).join(", ") || "(none built in)";
|
|
1554
|
-
throw new (0,
|
|
1569
|
+
throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
|
|
1555
1570
|
`token "${token}" isn't built in for ${resolved.chain.name} (known: ${known}). Pass { address, decimals } instead, or use 'native'.`
|
|
1556
1571
|
);
|
|
1557
1572
|
}
|
|
1558
1573
|
return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
|
|
1559
1574
|
}
|
|
1560
|
-
|
|
1575
|
+
_chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "evm", network);
|
|
1561
1576
|
if (!("address" in token)) {
|
|
1562
|
-
throw new (0,
|
|
1577
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1563
1578
|
`chain ${network} is EVM; a custom token must be { address, decimals }.`
|
|
1564
1579
|
);
|
|
1565
1580
|
}
|
|
@@ -1591,20 +1606,20 @@ function makeEvmNetwork(resolved) {
|
|
|
1591
1606
|
},
|
|
1592
1607
|
assertValidPayTo(payTo) {
|
|
1593
1608
|
if (!_viem.isAddress.call(void 0, payTo)) {
|
|
1594
|
-
throw new (0,
|
|
1609
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1595
1610
|
`chain ${network} is EVM, but payTo "${payTo}" is not a valid 0x address.`
|
|
1596
1611
|
);
|
|
1597
1612
|
}
|
|
1598
1613
|
},
|
|
1599
1614
|
bindWallet(wallet) {
|
|
1600
1615
|
if (typeof wallet !== "object" || wallet === null) {
|
|
1601
|
-
throw new (0,
|
|
1616
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1602
1617
|
`chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
|
|
1603
1618
|
);
|
|
1604
1619
|
}
|
|
1605
|
-
|
|
1620
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "EVM");
|
|
1606
1621
|
if (!("key" in wallet) && !("walletClient" in wallet)) {
|
|
1607
|
-
throw new (0,
|
|
1622
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
1608
1623
|
`chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
|
|
1609
1624
|
);
|
|
1610
1625
|
}
|
|
@@ -1621,12 +1636,12 @@ function makeEvmNetwork(resolved) {
|
|
|
1621
1636
|
});
|
|
1622
1637
|
} catch (err) {
|
|
1623
1638
|
if (isViemInsufficientFunds(err)) {
|
|
1624
|
-
throw new (0,
|
|
1639
|
+
throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
|
|
1625
1640
|
err instanceof Error ? err.message : "Insufficient funds for payment.",
|
|
1626
1641
|
{ cause: err }
|
|
1627
1642
|
);
|
|
1628
1643
|
}
|
|
1629
|
-
throw _nullishCoalesce(
|
|
1644
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
1630
1645
|
}
|
|
1631
1646
|
},
|
|
1632
1647
|
async confirm(ref, minConfirmations) {
|
|
@@ -1637,7 +1652,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1637
1652
|
});
|
|
1638
1653
|
return { height: receipt.blockNumber.toString() };
|
|
1639
1654
|
} catch (err) {
|
|
1640
|
-
throw new (0,
|
|
1655
|
+
throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(
|
|
1641
1656
|
`EVM tx ${ref} did not reach ${minConfirmations} confirmation(s) in time.`,
|
|
1642
1657
|
{ cause: err }
|
|
1643
1658
|
);
|
|
@@ -1647,7 +1662,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1647
1662
|
const { decimals, symbol } = resolved.chain.nativeCurrency;
|
|
1648
1663
|
if (accept.scheme === "exact") {
|
|
1649
1664
|
const permit2 = accept.extra.assetTransferMethod === "permit2";
|
|
1650
|
-
return
|
|
1665
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
1651
1666
|
symbol,
|
|
1652
1667
|
decimals,
|
|
1653
1668
|
fee: 0n,
|
|
@@ -1658,7 +1673,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1658
1673
|
const gasLimit = accept.asset === "native" ? 21000n : 65000n;
|
|
1659
1674
|
try {
|
|
1660
1675
|
const gasPrice = await publicClient.getGasPrice();
|
|
1661
|
-
return
|
|
1676
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
1662
1677
|
symbol,
|
|
1663
1678
|
decimals,
|
|
1664
1679
|
fee: gasPrice * gasLimit,
|
|
@@ -1667,7 +1682,7 @@ function makeEvmNetwork(resolved) {
|
|
|
1667
1682
|
});
|
|
1668
1683
|
} catch (e20) {
|
|
1669
1684
|
const gasPrice = 5000000000n;
|
|
1670
|
-
return
|
|
1685
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
1671
1686
|
symbol,
|
|
1672
1687
|
decimals,
|
|
1673
1688
|
fee: gasPrice * gasLimit,
|
|
@@ -1801,9 +1816,9 @@ var loaders = {
|
|
|
1801
1816
|
solana: async () => {
|
|
1802
1817
|
let mod;
|
|
1803
1818
|
try {
|
|
1804
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./solana-
|
|
1819
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./solana-TLHL2KNY.cjs")));
|
|
1805
1820
|
} catch (cause) {
|
|
1806
|
-
throw new (0,
|
|
1821
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1807
1822
|
`Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
|
|
1808
1823
|
{ cause }
|
|
1809
1824
|
);
|
|
@@ -1813,9 +1828,9 @@ var loaders = {
|
|
|
1813
1828
|
ton: async () => {
|
|
1814
1829
|
let mod;
|
|
1815
1830
|
try {
|
|
1816
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./ton-
|
|
1831
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./ton-MMPKWT6N.cjs")));
|
|
1817
1832
|
} catch (cause) {
|
|
1818
|
-
throw new (0,
|
|
1833
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1819
1834
|
`TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
|
|
1820
1835
|
{ cause }
|
|
1821
1836
|
);
|
|
@@ -1825,9 +1840,9 @@ var loaders = {
|
|
|
1825
1840
|
stellar: async () => {
|
|
1826
1841
|
let mod;
|
|
1827
1842
|
try {
|
|
1828
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./stellar-
|
|
1843
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./stellar-FW6C6FBE.cjs")));
|
|
1829
1844
|
} catch (cause) {
|
|
1830
|
-
throw new (0,
|
|
1845
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1831
1846
|
`Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
|
|
1832
1847
|
{ cause }
|
|
1833
1848
|
);
|
|
@@ -1837,9 +1852,9 @@ var loaders = {
|
|
|
1837
1852
|
xrpl: async () => {
|
|
1838
1853
|
let mod;
|
|
1839
1854
|
try {
|
|
1840
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./xrpl-
|
|
1855
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./xrpl-PECT4IMX.cjs")));
|
|
1841
1856
|
} catch (cause) {
|
|
1842
|
-
throw new (0,
|
|
1857
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1843
1858
|
`XRPL selected, but its package isn't installed. Run: npm install xrpl`,
|
|
1844
1859
|
{ cause }
|
|
1845
1860
|
);
|
|
@@ -1849,9 +1864,9 @@ var loaders = {
|
|
|
1849
1864
|
tron: async () => {
|
|
1850
1865
|
let mod;
|
|
1851
1866
|
try {
|
|
1852
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./tron-
|
|
1867
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./tron-JOT4STIG.cjs")));
|
|
1853
1868
|
} catch (cause) {
|
|
1854
|
-
throw new (0,
|
|
1869
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1855
1870
|
`Tron selected, but its package isn't installed. Run: npm install tronweb`,
|
|
1856
1871
|
{ cause }
|
|
1857
1872
|
);
|
|
@@ -1861,9 +1876,9 @@ var loaders = {
|
|
|
1861
1876
|
sui: async () => {
|
|
1862
1877
|
let mod;
|
|
1863
1878
|
try {
|
|
1864
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./sui-
|
|
1879
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./sui-47C2KEZI.cjs")));
|
|
1865
1880
|
} catch (cause) {
|
|
1866
|
-
throw new (0,
|
|
1881
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1867
1882
|
`Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
|
|
1868
1883
|
{ cause }
|
|
1869
1884
|
);
|
|
@@ -1873,9 +1888,9 @@ var loaders = {
|
|
|
1873
1888
|
near: async () => {
|
|
1874
1889
|
let mod;
|
|
1875
1890
|
try {
|
|
1876
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./near-
|
|
1891
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./near-DI2I3MAV.cjs")));
|
|
1877
1892
|
} catch (cause) {
|
|
1878
|
-
throw new (0,
|
|
1893
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1879
1894
|
`NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
|
|
1880
1895
|
{ cause }
|
|
1881
1896
|
);
|
|
@@ -1885,9 +1900,9 @@ var loaders = {
|
|
|
1885
1900
|
aptos: async () => {
|
|
1886
1901
|
let mod;
|
|
1887
1902
|
try {
|
|
1888
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./aptos-
|
|
1903
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./aptos-TRCCJRZA.cjs")));
|
|
1889
1904
|
} catch (cause) {
|
|
1890
|
-
throw new (0,
|
|
1905
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1891
1906
|
`Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
|
|
1892
1907
|
{ cause }
|
|
1893
1908
|
);
|
|
@@ -1897,9 +1912,9 @@ var loaders = {
|
|
|
1897
1912
|
algorand: async () => {
|
|
1898
1913
|
let mod;
|
|
1899
1914
|
try {
|
|
1900
|
-
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./algorand-
|
|
1915
|
+
mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./algorand-HZS43N4P.cjs")));
|
|
1901
1916
|
} catch (cause) {
|
|
1902
|
-
throw new (0,
|
|
1917
|
+
throw new (0, _chunkJG6KRAW6cjs.MissingDriverError)(
|
|
1903
1918
|
`Algorand selected, but its package isn't installed. Run: npm install algosdk`,
|
|
1904
1919
|
{ cause }
|
|
1905
1920
|
);
|
|
@@ -2446,7 +2461,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
|
|
|
2446
2461
|
}
|
|
2447
2462
|
}
|
|
2448
2463
|
if (policy.maxAmount !== void 0) {
|
|
2449
|
-
const cap =
|
|
2464
|
+
const cap = _chunkJG6KRAW6cjs.floorUnits.call(void 0, policy.maxAmount, intent.decimals);
|
|
2450
2465
|
if (intent.amountBase > cap) {
|
|
2451
2466
|
return deny(
|
|
2452
2467
|
"MAX_AMOUNT",
|
|
@@ -2455,7 +2470,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
|
|
|
2455
2470
|
}
|
|
2456
2471
|
}
|
|
2457
2472
|
if (policy.maxTotal !== void 0) {
|
|
2458
|
-
const cap =
|
|
2473
|
+
const cap = _chunkJG6KRAW6cjs.floorUnits.call(void 0, policy.maxTotal, intent.decimals);
|
|
2459
2474
|
if (spentForAssetBase + intent.amountBase > cap) {
|
|
2460
2475
|
return deny(
|
|
2461
2476
|
"MAX_TOTAL",
|
|
@@ -2464,7 +2479,7 @@ function evaluatePolicy(intent, policy, spentForAssetBase, ctx) {
|
|
|
2464
2479
|
}
|
|
2465
2480
|
}
|
|
2466
2481
|
if (ctx && policy.windowTotal !== void 0 && policy.windowSeconds !== void 0) {
|
|
2467
|
-
const cap =
|
|
2482
|
+
const cap = _chunkJG6KRAW6cjs.floorUnits.call(void 0, policy.windowTotal, intent.decimals);
|
|
2468
2483
|
if (ctx.spentInWindowBase + intent.amountBase > cap) {
|
|
2469
2484
|
return deny(
|
|
2470
2485
|
"WINDOW_TOTAL",
|
|
@@ -2553,7 +2568,7 @@ var SpendLedger = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
2553
2568
|
symbol: b.symbol,
|
|
2554
2569
|
decimals: b.decimals,
|
|
2555
2570
|
totalBase: b.total.toString(),
|
|
2556
|
-
totalFormatted:
|
|
2571
|
+
totalFormatted: _chunkJG6KRAW6cjs.formatUnits.call(void 0, b.total, b.decimals),
|
|
2557
2572
|
count: b.count
|
|
2558
2573
|
})),
|
|
2559
2574
|
records: [...this.records]
|
|
@@ -2585,8 +2600,29 @@ var PipRailClient = (_class2 = class {
|
|
|
2585
2600
|
this.maxRetries = Math.max(1, _nullishCoalesce(opts.maxPaymentRetries, () => ( 3)));
|
|
2586
2601
|
this.retryTimeoutMs = _nullishCoalesce(opts.retryTimeoutMs, () => ( 3e4));
|
|
2587
2602
|
this.onEvent = _nullishCoalesce(opts.onEvent, () => ( (() => void 0)));
|
|
2603
|
+
this.assertPolicyAmountCaps(opts.policy);
|
|
2588
2604
|
this.assertPolicyTimeOptions(opts.policy);
|
|
2589
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
|
+
}
|
|
2590
2626
|
/**
|
|
2591
2627
|
* Fail LOUDLY at construction on a misconfigured time policy — a security
|
|
2592
2628
|
* boundary must never silently half-arm. Two invariants (a misconfiguration is
|
|
@@ -2749,13 +2785,13 @@ var PipRailClient = (_class2 = class {
|
|
|
2749
2785
|
spentBase: b.totalBase.toString()
|
|
2750
2786
|
};
|
|
2751
2787
|
if (maxTotal === void 0) return base2;
|
|
2752
|
-
const capBase =
|
|
2788
|
+
const capBase = _chunkJG6KRAW6cjs.floorUnits.call(void 0, maxTotal, b.decimals);
|
|
2753
2789
|
const remainingBase = capBase > b.totalBase ? capBase - b.totalBase : 0n;
|
|
2754
2790
|
return {
|
|
2755
2791
|
...base2,
|
|
2756
2792
|
capBase: capBase.toString(),
|
|
2757
2793
|
remainingBase: remainingBase.toString(),
|
|
2758
|
-
remainingFormatted:
|
|
2794
|
+
remainingFormatted: _chunkJG6KRAW6cjs.formatUnits.call(void 0, remainingBase, b.decimals)
|
|
2759
2795
|
};
|
|
2760
2796
|
});
|
|
2761
2797
|
}
|
|
@@ -2795,11 +2831,11 @@ var PipRailClient = (_class2 = class {
|
|
|
2795
2831
|
if (res.status !== 402) return null;
|
|
2796
2832
|
const challenge = await parseChallenge(res);
|
|
2797
2833
|
if (!challenge) {
|
|
2798
|
-
throw new (0,
|
|
2834
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)("402 response did not include a parseable x402 challenge.");
|
|
2799
2835
|
}
|
|
2800
2836
|
const { net, wallet } = await this.ensure();
|
|
2801
2837
|
if (!wallet) {
|
|
2802
|
-
throw new (0,
|
|
2838
|
+
throw new (0, _chunkJG6KRAW6cjs.WalletRequiredError)(
|
|
2803
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."
|
|
2804
2840
|
);
|
|
2805
2841
|
}
|
|
@@ -2967,7 +3003,7 @@ var PipRailClient = (_class2 = class {
|
|
|
2967
3003
|
async fetch(url, init) {
|
|
2968
3004
|
const body = _optionalChain([init, 'optionalAccess', _41 => _41.body]);
|
|
2969
3005
|
if (body !== void 0 && body !== null && !isReplayableBodyInit(body)) {
|
|
2970
|
-
throw new (0,
|
|
3006
|
+
throw new (0, _chunkJG6KRAW6cjs.NonReplayableBodyError)(
|
|
2971
3007
|
"fetch(): init.body is not replayable. Pass a string, FormData, URLSearchParams, ArrayBuffer, or Blob \u2014 not a ReadableStream."
|
|
2972
3008
|
);
|
|
2973
3009
|
}
|
|
@@ -2977,7 +3013,7 @@ var PipRailClient = (_class2 = class {
|
|
|
2977
3013
|
const resolved = await this.resolveChallenge(url, firstResponse, schemes);
|
|
2978
3014
|
const { net, wallet, challenge } = resolved;
|
|
2979
3015
|
if (!wallet) {
|
|
2980
|
-
throw new (0,
|
|
3016
|
+
throw new (0, _chunkJG6KRAW6cjs.WalletRequiredError)(
|
|
2981
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)."
|
|
2982
3018
|
);
|
|
2983
3019
|
}
|
|
@@ -2987,7 +3023,7 @@ var PipRailClient = (_class2 = class {
|
|
|
2987
3023
|
if (autoRoute) {
|
|
2988
3024
|
const plan = await this.planFromChallenge(net, wallet, challenge, url, schemes);
|
|
2989
3025
|
if (!plan.best) {
|
|
2990
|
-
throw new (0,
|
|
3026
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(_nullishCoalesce(plan.fundingHint, () => ( "No rail is settleable for this payment.")));
|
|
2991
3027
|
}
|
|
2992
3028
|
accept = plan.best.accept;
|
|
2993
3029
|
quote = plan.best.quote;
|
|
@@ -3011,7 +3047,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3011
3047
|
async resolveChallenge(url, response, schemes) {
|
|
3012
3048
|
const challenge = await parseChallenge(response);
|
|
3013
3049
|
if (!challenge) {
|
|
3014
|
-
throw new (0,
|
|
3050
|
+
throw new (0, _chunkJG6KRAW6cjs.InvalidEnvelopeError)(
|
|
3015
3051
|
"402 response did not include a parseable x402 challenge."
|
|
3016
3052
|
);
|
|
3017
3053
|
}
|
|
@@ -3022,7 +3058,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3022
3058
|
(a) => a.scheme === "exact" && net.supports(a.network)
|
|
3023
3059
|
);
|
|
3024
3060
|
if (schemes.includes("exact") && exactOnNet && typeof net.payExact !== "function") {
|
|
3025
|
-
throw new (0,
|
|
3061
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
3026
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.`
|
|
3027
3063
|
);
|
|
3028
3064
|
}
|
|
@@ -3031,13 +3067,13 @@ var PipRailClient = (_class2 = class {
|
|
|
3031
3067
|
(a) => a.scheme === "exact" && net.supports(a.network) && net.describeAsset(a.asset) != null
|
|
3032
3068
|
);
|
|
3033
3069
|
if (payable) {
|
|
3034
|
-
throw new (0,
|
|
3070
|
+
throw new (0, _chunkJG6KRAW6cjs.NoCompatibleAcceptError)(
|
|
3035
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).`
|
|
3036
3072
|
);
|
|
3037
3073
|
}
|
|
3038
3074
|
}
|
|
3039
3075
|
const networks = [...new Set(challenge.accepts.map((a) => a.network))].join(", ");
|
|
3040
|
-
throw new (0,
|
|
3076
|
+
throw new (0, _chunkJG6KRAW6cjs.NoCompatibleAcceptError)(
|
|
3041
3077
|
`No accepts[] entry payable by this client on ${net.network} (schemes: ${schemes.join(", ")}; challenge offered: ${networks || "none"}).`
|
|
3042
3078
|
);
|
|
3043
3079
|
}
|
|
@@ -3139,21 +3175,21 @@ var PipRailClient = (_class2 = class {
|
|
|
3139
3175
|
if (isExact) {
|
|
3140
3176
|
if (tokenKnown && bal.token < amount) {
|
|
3141
3177
|
blockers.push("INSUFFICIENT_TOKEN");
|
|
3142
|
-
shortfall.token =
|
|
3178
|
+
shortfall.token = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
|
|
3143
3179
|
}
|
|
3144
3180
|
} else if (isNative) {
|
|
3145
3181
|
if (nativeKnown && bal.native < amount + fee) {
|
|
3146
3182
|
blockers.push("INSUFFICIENT_TOKEN");
|
|
3147
|
-
shortfall.token =
|
|
3183
|
+
shortfall.token = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amount + fee - bal.native, quote.decimals);
|
|
3148
3184
|
}
|
|
3149
3185
|
} else {
|
|
3150
3186
|
if (tokenKnown && bal.token < amount) {
|
|
3151
3187
|
blockers.push("INSUFFICIENT_TOKEN");
|
|
3152
|
-
shortfall.token =
|
|
3188
|
+
shortfall.token = _chunkJG6KRAW6cjs.formatUnits.call(void 0, amount - bal.token, quote.decimals);
|
|
3153
3189
|
}
|
|
3154
3190
|
if (nativeKnown && bal.native < fee) {
|
|
3155
3191
|
blockers.push("INSUFFICIENT_GAS");
|
|
3156
|
-
shortfall.native =
|
|
3192
|
+
shortfall.native = _chunkJG6KRAW6cjs.formatUnits.call(void 0, fee - bal.native, cost.feeDecimals);
|
|
3157
3193
|
} else if (nativeKnown && fee > 0n && bal.native < fee * 3n / 2n) {
|
|
3158
3194
|
warnings.push("THIN_GAS_MARGIN");
|
|
3159
3195
|
}
|
|
@@ -3178,8 +3214,8 @@ var PipRailClient = (_class2 = class {
|
|
|
3178
3214
|
blockers,
|
|
3179
3215
|
warnings,
|
|
3180
3216
|
balance: {
|
|
3181
|
-
token: bal.token != null ?
|
|
3182
|
-
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
|
|
3183
3219
|
},
|
|
3184
3220
|
need: { token: quote.amountFormatted, native: cost.feeFormatted },
|
|
3185
3221
|
...shortfall.token || shortfall.native ? { shortfall } : {},
|
|
@@ -3189,21 +3225,26 @@ var PipRailClient = (_class2 = class {
|
|
|
3189
3225
|
/** Build the agent-facing quote for an accept: TRUE decimals/symbol (via the
|
|
3190
3226
|
* driver's describeAsset) + the policy verdict + a symbol-mismatch flag. */
|
|
3191
3227
|
buildQuote(net, accept, url, description) {
|
|
3192
|
-
if (!/^\d+$/.test(accept.amount)) {
|
|
3193
|
-
throw new (0,
|
|
3194
|
-
`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.`
|
|
3195
3236
|
);
|
|
3196
3237
|
}
|
|
3197
3238
|
const amountBase = BigInt(accept.amount);
|
|
3198
3239
|
const described = net.describeAsset(accept.asset);
|
|
3199
|
-
const decimals = _nullishCoalesce(_optionalChain([described, 'optionalAccess', _44 => _44.decimals]), () => ( accept.extra.decimals));
|
|
3200
|
-
if (decimals
|
|
3201
|
-
throw new (0,
|
|
3202
|
-
`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.`
|
|
3203
3244
|
);
|
|
3204
3245
|
}
|
|
3205
|
-
const symbol = _nullishCoalesce(_optionalChain([described, 'optionalAccess',
|
|
3206
|
-
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);
|
|
3207
3248
|
const intent = {
|
|
3208
3249
|
host: hostOf2(url),
|
|
3209
3250
|
chain: this.opts.chain,
|
|
@@ -3234,7 +3275,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3234
3275
|
this.ledger.totalFor(accept.network, accept.asset),
|
|
3235
3276
|
ctx
|
|
3236
3277
|
);
|
|
3237
|
-
const serverSymbol = accept.extra.symbol;
|
|
3278
|
+
const serverSymbol = _optionalChain([accept, 'access', _50 => _50.extra, 'optionalAccess', _51 => _51.symbol]);
|
|
3238
3279
|
const symbolMismatch = intent.recognized && !!serverSymbol && !!symbol && serverSymbol.toUpperCase() !== symbol.toUpperCase();
|
|
3239
3280
|
return {
|
|
3240
3281
|
url,
|
|
@@ -3261,7 +3302,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3261
3302
|
* TERMINAL expiry/approval decline it must not retry) without parsing prose. */
|
|
3262
3303
|
async authorize(quote) {
|
|
3263
3304
|
if (!quote.withinPolicy) {
|
|
3264
|
-
throw new (0,
|
|
3305
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(
|
|
3265
3306
|
`Payment refused by policy: ${_nullishCoalesce(quote.policyReason, () => ( "not allowed"))}`,
|
|
3266
3307
|
{ reasonCode: reasonCodeForPolicy(quote.policyCode) }
|
|
3267
3308
|
);
|
|
@@ -3272,13 +3313,13 @@ var PipRailClient = (_class2 = class {
|
|
|
3272
3313
|
try {
|
|
3273
3314
|
approved = await hook(quote);
|
|
3274
3315
|
} catch (err) {
|
|
3275
|
-
throw new (0,
|
|
3316
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)("onBeforePay threw \u2014 refusing to pay.", {
|
|
3276
3317
|
cause: err,
|
|
3277
3318
|
reasonCode: "APPROVAL"
|
|
3278
3319
|
});
|
|
3279
3320
|
}
|
|
3280
3321
|
if (!approved) {
|
|
3281
|
-
throw new (0,
|
|
3322
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(
|
|
3282
3323
|
`onBeforePay declined ${quote.amountFormatted} ${_nullishCoalesce(quote.symbol, () => ( ""))}`.trimEnd() + ` on ${quote.network}.`,
|
|
3283
3324
|
{ reasonCode: "APPROVAL" }
|
|
3284
3325
|
);
|
|
@@ -3303,14 +3344,14 @@ var PipRailClient = (_class2 = class {
|
|
|
3303
3344
|
}
|
|
3304
3345
|
async payAndConfirm(net, wallet, accept) {
|
|
3305
3346
|
if (!net.supports(accept.network)) {
|
|
3306
|
-
throw new (0,
|
|
3347
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongChainError)(
|
|
3307
3348
|
`Challenge expects ${accept.network} but client is on ${net.network}.`
|
|
3308
3349
|
);
|
|
3309
3350
|
}
|
|
3310
3351
|
const ref = await net.send(wallet, accept);
|
|
3311
3352
|
this.safeEmit({ kind: "payment-broadcast", ref });
|
|
3312
3353
|
try {
|
|
3313
|
-
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)));
|
|
3314
3355
|
this.safeEmit({
|
|
3315
3356
|
kind: "payment-confirmed",
|
|
3316
3357
|
ref,
|
|
@@ -3330,9 +3371,9 @@ var PipRailClient = (_class2 = class {
|
|
|
3330
3371
|
const signature = {
|
|
3331
3372
|
x402Version: 2,
|
|
3332
3373
|
accepted: accept,
|
|
3333
|
-
payload: { nonce: accept.extra.nonce, txHash: ref }
|
|
3374
|
+
payload: { nonce: _optionalChain([accept, 'access', _54 => _54.extra, 'optionalAccess', _55 => _55.nonce]), txHash: ref }
|
|
3334
3375
|
};
|
|
3335
|
-
const headers = new Headers(_optionalChain([originalInit, 'optionalAccess',
|
|
3376
|
+
const headers = new Headers(_optionalChain([originalInit, 'optionalAccess', _56 => _56.headers]));
|
|
3336
3377
|
headers.set(HEADER_SIGNATURE, buildSignatureHeader(signature));
|
|
3337
3378
|
let lastResponse = null;
|
|
3338
3379
|
let lastReason = null;
|
|
@@ -3347,7 +3388,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3347
3388
|
() => timeoutController.abort(),
|
|
3348
3389
|
this.retryTimeoutMs
|
|
3349
3390
|
);
|
|
3350
|
-
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;
|
|
3351
3392
|
try {
|
|
3352
3393
|
lastResponse = await fetch(url, {
|
|
3353
3394
|
..._nullishCoalesce(originalInit, () => ( {})),
|
|
@@ -3356,7 +3397,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3356
3397
|
});
|
|
3357
3398
|
} catch (err) {
|
|
3358
3399
|
if (timeoutController.signal.aborted) {
|
|
3359
|
-
throw new (0,
|
|
3400
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentTimeoutError)(
|
|
3360
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.`,
|
|
3361
3402
|
{ cause: err, ref }
|
|
3362
3403
|
);
|
|
@@ -3378,7 +3419,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3378
3419
|
kind: "payment-failed",
|
|
3379
3420
|
reason: `server returned 402 after broadcasting payment ${ref}${unconfirmedNote} (${why})`
|
|
3380
3421
|
});
|
|
3381
|
-
throw new (0,
|
|
3422
|
+
throw new (0, _chunkJG6KRAW6cjs.MaxRetriesExceededError)(
|
|
3382
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).`,
|
|
3383
3424
|
{ ref }
|
|
3384
3425
|
);
|
|
@@ -3402,17 +3443,17 @@ var PipRailClient = (_class2 = class {
|
|
|
3402
3443
|
*/
|
|
3403
3444
|
async payExactRail(net, wallet, accept, url, init, quote) {
|
|
3404
3445
|
if (!net.payExact) {
|
|
3405
|
-
throw new (0,
|
|
3446
|
+
throw new (0, _chunkJG6KRAW6cjs.UnsupportedSchemeError)(
|
|
3406
3447
|
`the ${net.family} family can't pay a standard 'exact' rail (supported on EVM + Solana today).`
|
|
3407
3448
|
);
|
|
3408
3449
|
}
|
|
3409
|
-
throwIfAborted(_optionalChain([init, 'optionalAccess',
|
|
3450
|
+
throwIfAborted(_optionalChain([init, 'optionalAccess', _58 => _58.signal]));
|
|
3410
3451
|
const { payload, accepted, payerFrom, nonce } = await net.payExact(wallet, accept);
|
|
3411
|
-
const headers = new Headers(_optionalChain([init, 'optionalAccess',
|
|
3452
|
+
const headers = new Headers(_optionalChain([init, 'optionalAccess', _59 => _59.headers]));
|
|
3412
3453
|
headers.set(HEADER_SIGNATURE, buildExactSignatureHeader({ accepted, payload }));
|
|
3413
3454
|
const rejectDefinitive = (why2) => {
|
|
3414
3455
|
this.safeEmit({ kind: "payment-failed", reason: `exact: facilitator rejected nonce=${nonce} (${why2})` });
|
|
3415
|
-
throw new (0,
|
|
3456
|
+
throw new (0, _chunkJG6KRAW6cjs.MaxRetriesExceededError)(
|
|
3416
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}.`,
|
|
3417
3458
|
{ ref: nonce }
|
|
3418
3459
|
);
|
|
@@ -3425,17 +3466,17 @@ var PipRailClient = (_class2 = class {
|
|
|
3425
3466
|
if (Date.now() >= deadline) break;
|
|
3426
3467
|
await new Promise((r) => setTimeout(r, Math.min(2e3, 400 * 2 ** (attempt - 1))));
|
|
3427
3468
|
}
|
|
3428
|
-
throwIfAborted(_optionalChain([init, 'optionalAccess',
|
|
3469
|
+
throwIfAborted(_optionalChain([init, 'optionalAccess', _60 => _60.signal]));
|
|
3429
3470
|
const budget = Math.min(this.retryTimeoutMs, deadline - Date.now());
|
|
3430
3471
|
if (budget <= 0) break;
|
|
3431
3472
|
const timeoutController = new AbortController();
|
|
3432
3473
|
const timeoutId = setTimeout(() => timeoutController.abort(), budget);
|
|
3433
|
-
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;
|
|
3434
3475
|
let response;
|
|
3435
3476
|
try {
|
|
3436
3477
|
response = await fetch(url, { ..._nullishCoalesce(init, () => ( {})), headers, signal });
|
|
3437
3478
|
} catch (err) {
|
|
3438
|
-
throw new (0,
|
|
3479
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentTimeoutError)(
|
|
3439
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.`,
|
|
3440
3481
|
{ cause: err, ref: nonce }
|
|
3441
3482
|
);
|
|
@@ -3451,7 +3492,7 @@ var PipRailClient = (_class2 = class {
|
|
|
3451
3492
|
if (response.ok && !(settle && settle.success === false)) {
|
|
3452
3493
|
const receipt = parseReceipt(response);
|
|
3453
3494
|
this.safeEmit({ kind: "payment-settled", receipt, ...settle ? { settle } : {} });
|
|
3454
|
-
const ref = _optionalChain([settle, 'optionalAccess',
|
|
3495
|
+
const ref = _optionalChain([settle, 'optionalAccess', _62 => _62.transaction]) || _optionalChain([receipt, 'optionalAccess', _63 => _63.transaction]) || `eip3009-nonce:${nonce}`;
|
|
3455
3496
|
this.recordSpend(quote, ref);
|
|
3456
3497
|
return response;
|
|
3457
3498
|
}
|
|
@@ -3468,14 +3509,14 @@ var PipRailClient = (_class2 = class {
|
|
|
3468
3509
|
kind: "payment-failed",
|
|
3469
3510
|
reason: `exact: 402 after submitting authorization nonce=${nonce} (${why})`
|
|
3470
3511
|
});
|
|
3471
|
-
throw new (0,
|
|
3512
|
+
throw new (0, _chunkJG6KRAW6cjs.MaxRetriesExceededError)(
|
|
3472
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}.`,
|
|
3473
3514
|
{ ref: nonce }
|
|
3474
3515
|
);
|
|
3475
3516
|
}
|
|
3476
3517
|
}, _class2);
|
|
3477
3518
|
function throwIfAborted(signal) {
|
|
3478
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
3519
|
+
if (_optionalChain([signal, 'optionalAccess', _64 => _64.aborted])) {
|
|
3479
3520
|
throw _nullishCoalesce(signal.reason, () => ( new DOMException("This operation was aborted.", "AbortError")));
|
|
3480
3521
|
}
|
|
3481
3522
|
}
|
|
@@ -3545,10 +3586,10 @@ function buildFundingHint(options, chainLabel) {
|
|
|
3545
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}.`;
|
|
3546
3587
|
}
|
|
3547
3588
|
const parts = [];
|
|
3548
|
-
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])) {
|
|
3549
3590
|
parts.push(`top up ${target.shortfall.token} ${sym}`);
|
|
3550
3591
|
}
|
|
3551
|
-
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])) {
|
|
3552
3593
|
parts.push(`add ~${target.shortfall.native} ${target.cost.feeSymbol} for gas`);
|
|
3553
3594
|
}
|
|
3554
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}.`;
|
|
@@ -3562,7 +3603,7 @@ async function planAcross(clients, url, init) {
|
|
|
3562
3603
|
const status = best ? "ready" : options.some((o) => o.state === "unknown") ? "unknown" : "blocked";
|
|
3563
3604
|
return {
|
|
3564
3605
|
url,
|
|
3565
|
-
network: _nullishCoalesce(_optionalChain([best, 'optionalAccess',
|
|
3606
|
+
network: _nullishCoalesce(_optionalChain([best, 'optionalAccess', _69 => _69.accept, 'access', _70 => _70.network]), () => ( live[0].network)),
|
|
3566
3607
|
status,
|
|
3567
3608
|
payable: best !== null,
|
|
3568
3609
|
best,
|
|
@@ -3581,7 +3622,7 @@ async function fetchAcross(clients, url, init) {
|
|
|
3581
3622
|
const best = rankAcross(live.map((p) => p.plan)).find((o) => o.state === "payable");
|
|
3582
3623
|
if (!best) {
|
|
3583
3624
|
const hint = mergeDeclineHint(live.map((p) => p.plan));
|
|
3584
|
-
throw new (0,
|
|
3625
|
+
throw new (0, _chunkJG6KRAW6cjs.PaymentDeclinedError)(hint || "No funded chain can settle this payment right now.");
|
|
3585
3626
|
}
|
|
3586
3627
|
const owner = live.find((p) => p.plan.options.includes(best)).client;
|
|
3587
3628
|
return owner.fetch(url, { ..._nullishCoalesce(init, () => ( {})), autoRoute: true });
|
|
@@ -3624,8 +3665,8 @@ function isReplayableBodyInit(value) {
|
|
|
3624
3665
|
async function readInvalidReason(response) {
|
|
3625
3666
|
try {
|
|
3626
3667
|
const body = await response.clone().json();
|
|
3627
|
-
const ext = _optionalChain([body, 'optionalAccess',
|
|
3628
|
-
const piprail = _optionalChain([ext, 'optionalAccess',
|
|
3668
|
+
const ext = _optionalChain([body, 'optionalAccess', _71 => _71.extensions]);
|
|
3669
|
+
const piprail = _optionalChain([ext, 'optionalAccess', _72 => _72.piprail]);
|
|
3629
3670
|
if (piprail && typeof piprail.code === "string") {
|
|
3630
3671
|
return {
|
|
3631
3672
|
error: piprail.code,
|
|
@@ -3647,7 +3688,7 @@ async function readInvalidReason(response) {
|
|
|
3647
3688
|
} catch (e29) {
|
|
3648
3689
|
}
|
|
3649
3690
|
const settle = parseSettleResponse(response);
|
|
3650
|
-
if (_optionalChain([settle, 'optionalAccess',
|
|
3691
|
+
if (_optionalChain([settle, 'optionalAccess', _73 => _73.errorReason])) return { error: settle.errorReason, detail: "" };
|
|
3651
3692
|
return null;
|
|
3652
3693
|
}
|
|
3653
3694
|
|
|
@@ -3697,7 +3738,7 @@ var MultiChainPayer = class _MultiChainPayer {
|
|
|
3697
3738
|
wallet,
|
|
3698
3739
|
...opts.policy ? { policy: opts.policy } : {},
|
|
3699
3740
|
...opts.schemes ? { schemes: opts.schemes } : {},
|
|
3700
|
-
..._optionalChain([opts, 'access',
|
|
3741
|
+
..._optionalChain([opts, 'access', _74 => _74.rpcUrls, 'optionalAccess', _75 => _75[chain]]) ? { rpcUrl: opts.rpcUrls[chain] } : {},
|
|
3701
3742
|
...opts.onBeforePay ? { onBeforePay: opts.onBeforePay } : {},
|
|
3702
3743
|
...opts.onEvent ? { onEvent: opts.onEvent } : {},
|
|
3703
3744
|
...opts.maxPaymentRetries != null ? { maxPaymentRetries: opts.maxPaymentRetries } : {},
|
|
@@ -3755,7 +3796,7 @@ var MultiChainPayer = class _MultiChainPayer {
|
|
|
3755
3796
|
* {@link PipRailClient.post}.
|
|
3756
3797
|
*/
|
|
3757
3798
|
post(url, body, init) {
|
|
3758
|
-
const headers = new Headers(_optionalChain([init, 'optionalAccess',
|
|
3799
|
+
const headers = new Headers(_optionalChain([init, 'optionalAccess', _76 => _76.headers]));
|
|
3759
3800
|
let payload;
|
|
3760
3801
|
if (body === void 0 || body === null) {
|
|
3761
3802
|
payload = void 0;
|
|
@@ -3887,7 +3928,7 @@ function summarizePlan(plan) {
|
|
|
3887
3928
|
return `NOT payable: ${_nullishCoalesce(plan.fundingHint, () => ( `no settleable rail on ${plan.network}`))}`;
|
|
3888
3929
|
}
|
|
3889
3930
|
function explainDecline(err) {
|
|
3890
|
-
if (!(err instanceof
|
|
3931
|
+
if (!(err instanceof _chunkJG6KRAW6cjs.PipRailError)) {
|
|
3891
3932
|
return `Payment failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
3892
3933
|
}
|
|
3893
3934
|
switch (err.code) {
|
|
@@ -4023,6 +4064,22 @@ async function readBody(res) {
|
|
|
4023
4064
|
return text;
|
|
4024
4065
|
}
|
|
4025
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
|
+
}
|
|
4026
4083
|
function paymentTools(client) {
|
|
4027
4084
|
return [
|
|
4028
4085
|
{
|
|
@@ -4049,23 +4106,27 @@ function paymentTools(client) {
|
|
|
4049
4106
|
additionalProperties: false
|
|
4050
4107
|
},
|
|
4051
4108
|
invoke: async (args) => {
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
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
|
+
}
|
|
4069
4130
|
}
|
|
4070
4131
|
},
|
|
4071
4132
|
{
|
|
@@ -4088,8 +4149,12 @@ function paymentTools(client) {
|
|
|
4088
4149
|
},
|
|
4089
4150
|
outputSchema: OPEN_OBJECT,
|
|
4090
4151
|
invoke: async (args) => {
|
|
4091
|
-
|
|
4092
|
-
|
|
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
|
+
}
|
|
4093
4158
|
}
|
|
4094
4159
|
},
|
|
4095
4160
|
{
|
|
@@ -4112,34 +4177,38 @@ function paymentTools(client) {
|
|
|
4112
4177
|
},
|
|
4113
4178
|
outputSchema: OPEN_OBJECT,
|
|
4114
4179
|
invoke: async (args) => {
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
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
|
+
}
|
|
4143
4212
|
}
|
|
4144
4213
|
},
|
|
4145
4214
|
{
|
|
@@ -4196,14 +4265,14 @@ function paymentTools(client) {
|
|
|
4196
4265
|
receipt: parseReceipt(res)
|
|
4197
4266
|
};
|
|
4198
4267
|
} catch (err) {
|
|
4199
|
-
if (err instanceof
|
|
4268
|
+
if (err instanceof _chunkJG6KRAW6cjs.PipRailError) {
|
|
4200
4269
|
const out = {
|
|
4201
4270
|
ok: false,
|
|
4202
4271
|
code: err.code,
|
|
4203
4272
|
reason: err.message,
|
|
4204
4273
|
explain: explainDecline(err)
|
|
4205
4274
|
};
|
|
4206
|
-
if (err instanceof
|
|
4275
|
+
if (err instanceof _chunkJG6KRAW6cjs.PaymentDeclinedError) {
|
|
4207
4276
|
out.declined = true;
|
|
4208
4277
|
if (err.reasonCode) out.reasonCode = err.reasonCode;
|
|
4209
4278
|
}
|
|
@@ -4245,14 +4314,18 @@ function paymentTools(client) {
|
|
|
4245
4314
|
additionalProperties: false
|
|
4246
4315
|
},
|
|
4247
4316
|
invoke: async (args) => {
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
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
|
+
}
|
|
4256
4329
|
}
|
|
4257
4330
|
},
|
|
4258
4331
|
{
|
|
@@ -4268,14 +4341,18 @@ function paymentTools(client) {
|
|
|
4268
4341
|
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
4269
4342
|
outputSchema: OPEN_OBJECT,
|
|
4270
4343
|
invoke: async () => {
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
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
|
+
}
|
|
4279
4356
|
}
|
|
4280
4357
|
},
|
|
4281
4358
|
{
|
|
@@ -4453,10 +4530,10 @@ async function fetchFacilitatorFeePayer(url, network, timeoutMs = 8e3) {
|
|
|
4453
4530
|
const res = await fetch(`${base2}/supported`, { signal: ctrl.signal });
|
|
4454
4531
|
if (!res.ok) return void 0;
|
|
4455
4532
|
const body = await res.json();
|
|
4456
|
-
const kinds = Array.isArray(_optionalChain([body, 'optionalAccess',
|
|
4533
|
+
const kinds = Array.isArray(_optionalChain([body, 'optionalAccess', _77 => _77.kinds])) ? body.kinds : [];
|
|
4457
4534
|
const want = normalizeNetwork(network);
|
|
4458
|
-
const kind = kinds.find((k) => _optionalChain([k, 'optionalAccess',
|
|
4459
|
-
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]);
|
|
4460
4537
|
return typeof fp === "string" ? fp : void 0;
|
|
4461
4538
|
} catch (e32) {
|
|
4462
4539
|
return void 0;
|
|
@@ -4465,14 +4542,14 @@ async function fetchFacilitatorFeePayer(url, network, timeoutMs = 8e3) {
|
|
|
4465
4542
|
}
|
|
4466
4543
|
}
|
|
4467
4544
|
function parseFacilitatorSupported(body) {
|
|
4468
|
-
const kinds = _optionalChain([body, 'optionalAccess',
|
|
4545
|
+
const kinds = _optionalChain([body, 'optionalAccess', _82 => _82.kinds]);
|
|
4469
4546
|
if (!Array.isArray(kinds)) return [];
|
|
4470
4547
|
const out = [];
|
|
4471
4548
|
for (const k of kinds) {
|
|
4472
4549
|
if (!k || typeof k !== "object") continue;
|
|
4473
4550
|
const o = k;
|
|
4474
4551
|
if (typeof o.scheme !== "string" || typeof o.network !== "string") continue;
|
|
4475
|
-
const fp = _optionalChain([o, 'access',
|
|
4552
|
+
const fp = _optionalChain([o, 'access', _83 => _83.extra, 'optionalAccess', _84 => _84.feePayer]);
|
|
4476
4553
|
out.push({ scheme: o.scheme, network: o.network, ...typeof fp === "string" ? { feePayer: fp } : {} });
|
|
4477
4554
|
}
|
|
4478
4555
|
return out;
|
|
@@ -4530,13 +4607,13 @@ async function settleViaFacilitator(input) {
|
|
|
4530
4607
|
try {
|
|
4531
4608
|
verify = await post(`${base2}/verify`, body, auth);
|
|
4532
4609
|
} catch (err) {
|
|
4533
|
-
throw new (0,
|
|
4610
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4534
4611
|
`exact settle (facilitator ${base2}): /verify request failed (${err instanceof Error ? err.message : String(err)}).`,
|
|
4535
4612
|
{ cause: err }
|
|
4536
4613
|
);
|
|
4537
4614
|
}
|
|
4538
4615
|
if (verify.status !== 200) {
|
|
4539
|
-
throw new (0,
|
|
4616
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4540
4617
|
`exact settle (facilitator ${base2}): /verify returned HTTP ${verify.status} (transport/auth error).`
|
|
4541
4618
|
);
|
|
4542
4619
|
}
|
|
@@ -4552,13 +4629,13 @@ async function settleViaFacilitator(input) {
|
|
|
4552
4629
|
try {
|
|
4553
4630
|
settle = await post(`${base2}/settle`, body, auth);
|
|
4554
4631
|
} catch (err) {
|
|
4555
|
-
throw new (0,
|
|
4632
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4556
4633
|
`exact settle (facilitator ${base2}): /settle request failed (${err instanceof Error ? err.message : String(err)}).`,
|
|
4557
4634
|
{ cause: err }
|
|
4558
4635
|
);
|
|
4559
4636
|
}
|
|
4560
4637
|
if (settle.status !== 200) {
|
|
4561
|
-
throw new (0,
|
|
4638
|
+
throw new (0, _chunkJG6KRAW6cjs.SettlementError)(
|
|
4562
4639
|
`exact settle (facilitator ${base2}): /settle returned HTTP ${settle.status} (transport/auth error).`
|
|
4563
4640
|
);
|
|
4564
4641
|
}
|
|
@@ -4625,7 +4702,7 @@ function createPaymentGate(options) {
|
|
|
4625
4702
|
}
|
|
4626
4703
|
net.assertValidPayTo(payTo);
|
|
4627
4704
|
const { asset, decimals, symbol } = net.resolveToken(a.token);
|
|
4628
|
-
const amountBase =
|
|
4705
|
+
const amountBase = _chunkJG6KRAW6cjs.parseUnits.call(void 0, a.amount, decimals);
|
|
4629
4706
|
const spec = { net, asset, decimals, symbol, amountBase, amountFormatted: a.amount, payTo };
|
|
4630
4707
|
if (options.exact) {
|
|
4631
4708
|
const outcome = await resolveExactRail(net, asset);
|
|
@@ -4773,7 +4850,7 @@ function createPaymentGate(options) {
|
|
|
4773
4850
|
accepts,
|
|
4774
4851
|
instruction: describeChallenge({ x402Version: 2, resource: { url: resourceUrl }, accepts })
|
|
4775
4852
|
});
|
|
4776
|
-
const rejectionExt = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
4853
|
+
const rejectionExt = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.extensions]), () => ( {}));
|
|
4777
4854
|
const rejectionPiprail = _nullishCoalesce(rejectionExt.piprail, () => ( {}));
|
|
4778
4855
|
const bodyPiprail = { ..._nullishCoalesce(selfDescribe, () => ( {})), ...rejectionPiprail };
|
|
4779
4856
|
const bodyExtensions = {
|
|
@@ -4792,7 +4869,7 @@ function createPaymentGate(options) {
|
|
|
4792
4869
|
...options.description ? { description: options.description } : {}
|
|
4793
4870
|
},
|
|
4794
4871
|
accepts,
|
|
4795
|
-
..._optionalChain([opts, 'optionalAccess',
|
|
4872
|
+
..._optionalChain([opts, 'optionalAccess', _86 => _86.error]) ? { error: opts.error } : {},
|
|
4796
4873
|
...Object.keys(bodyExtensions).length > 0 ? { extensions: bodyExtensions } : {}
|
|
4797
4874
|
};
|
|
4798
4875
|
const headerChallenge = {
|
|
@@ -4823,7 +4900,7 @@ function createPaymentGate(options) {
|
|
|
4823
4900
|
function enrichReceipt(spec, receipt) {
|
|
4824
4901
|
let amountFormatted = receipt.amount;
|
|
4825
4902
|
try {
|
|
4826
|
-
amountFormatted =
|
|
4903
|
+
amountFormatted = _chunkJG6KRAW6cjs.formatUnits.call(void 0, BigInt(receipt.amount), spec.decimals);
|
|
4827
4904
|
} catch (e35) {
|
|
4828
4905
|
}
|
|
4829
4906
|
return {
|
|
@@ -5013,7 +5090,7 @@ function requirePayment(options) {
|
|
|
5013
5090
|
try {
|
|
5014
5091
|
result = await gate.verify(_nullishCoalesce(req.headers[HEADER_SIGNATURE], () => ( req.headers[HEADER_SIGNATURE_V1])));
|
|
5015
5092
|
} catch (err) {
|
|
5016
|
-
if (err instanceof
|
|
5093
|
+
if (err instanceof _chunkJG6KRAW6cjs.SettlementError) {
|
|
5017
5094
|
res.status(502);
|
|
5018
5095
|
res.json({ x402Version: 2, error: "settlement_failed", detail: err.message });
|
|
5019
5096
|
return;
|
|
@@ -5113,7 +5190,7 @@ function isRetryableStatus(status) {
|
|
|
5113
5190
|
}
|
|
5114
5191
|
var sleep = (ms) => ms > 0 ? new Promise((resolve) => setTimeout(resolve, ms)) : Promise.resolve();
|
|
5115
5192
|
async function signBody(secret, body) {
|
|
5116
|
-
const subtle = _optionalChain([globalThis, 'access',
|
|
5193
|
+
const subtle = _optionalChain([globalThis, 'access', _87 => _87.crypto, 'optionalAccess', _88 => _88.subtle]);
|
|
5117
5194
|
if (!subtle) return null;
|
|
5118
5195
|
try {
|
|
5119
5196
|
const enc = new TextEncoder();
|
|
@@ -5183,7 +5260,7 @@ async function deliverReceipt(receipt, options) {
|
|
|
5183
5260
|
const retryable = status === void 0 ? true : isRetryableStatus(status);
|
|
5184
5261
|
const willRetry = !ok && retryable && attempt < maxAttempts;
|
|
5185
5262
|
try {
|
|
5186
|
-
_optionalChain([onAttempt, 'optionalCall',
|
|
5263
|
+
_optionalChain([onAttempt, 'optionalCall', _89 => _89({ attempt, ok, ...status !== void 0 ? { status } : {}, ...error ? { error } : {}, willRetry })]);
|
|
5187
5264
|
} catch (e39) {
|
|
5188
5265
|
}
|
|
5189
5266
|
if (ok) return { delivered: true, attempts: attempt, status };
|
|
@@ -5299,4 +5376,4 @@ async function deliverReceipt(receipt, options) {
|
|
|
5299
5376
|
|
|
5300
5377
|
|
|
5301
5378
|
|
|
5302
|
-
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;
|