@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.js
CHANGED
|
@@ -17,13 +17,14 @@ import {
|
|
|
17
17
|
WalletRequiredError,
|
|
18
18
|
WrongChainError,
|
|
19
19
|
WrongFamilyError,
|
|
20
|
+
assertNoLegacyWalletKey,
|
|
20
21
|
floorUnits,
|
|
21
22
|
formatUnits,
|
|
22
23
|
nativeCost,
|
|
23
24
|
parseUnits,
|
|
24
25
|
rejectForeignToken,
|
|
25
26
|
toInsufficientFundsError
|
|
26
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-7XK22JSQ.js";
|
|
27
28
|
|
|
28
29
|
// src/drivers/registry.ts
|
|
29
30
|
var byFamily = /* @__PURE__ */ new Map();
|
|
@@ -319,8 +320,23 @@ import {
|
|
|
319
320
|
} from "viem";
|
|
320
321
|
import { privateKeyToAccount } from "viem/accounts";
|
|
321
322
|
function createWalletAdapter(config, resolved) {
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
assertNoLegacyWalletKey(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 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 = privateKeyToAccount(key);
|
|
335
|
+
} catch (err) {
|
|
336
|
+
throw new 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 = http(resolved.rpcUrl);
|
|
325
341
|
const walletClient = createWalletClient({ account, chain: resolved.chain, transport });
|
|
326
342
|
return { account, walletClient };
|
|
@@ -328,7 +344,7 @@ function createWalletAdapter(config, resolved) {
|
|
|
328
344
|
const wc = config.walletClient;
|
|
329
345
|
if (!wc.account) {
|
|
330
346
|
throw new WrongFamilyError(
|
|
331
|
-
"chain is EVM; the provided walletClient has no attached account. Use `createWalletClient({ account, chain, transport })`, or pass {
|
|
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) {
|
|
@@ -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
|
}
|
|
@@ -1595,9 +1612,15 @@ function makeEvmNetwork(resolved) {
|
|
|
1595
1612
|
}
|
|
1596
1613
|
},
|
|
1597
1614
|
bindWallet(wallet) {
|
|
1598
|
-
if (typeof wallet !== "object" || wallet === null
|
|
1615
|
+
if (typeof wallet !== "object" || wallet === null) {
|
|
1599
1616
|
throw new WrongFamilyError(
|
|
1600
|
-
`chain ${network} is EVM; wallet must be {
|
|
1617
|
+
`chain ${network} is EVM; wallet must be { key } (0x\u2026 hex) or { walletClient }.`
|
|
1618
|
+
);
|
|
1619
|
+
}
|
|
1620
|
+
assertNoLegacyWalletKey(wallet, "EVM");
|
|
1621
|
+
if (!("key" in wallet) && !("walletClient" in wallet)) {
|
|
1622
|
+
throw new 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) };
|
|
@@ -1793,7 +1816,7 @@ var loaders = {
|
|
|
1793
1816
|
solana: async () => {
|
|
1794
1817
|
let mod;
|
|
1795
1818
|
try {
|
|
1796
|
-
mod = await import("./solana-
|
|
1819
|
+
mod = await import("./solana-E4MD6JJ6.js");
|
|
1797
1820
|
} catch (cause) {
|
|
1798
1821
|
throw new MissingDriverError(
|
|
1799
1822
|
`Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
|
|
@@ -1805,7 +1828,7 @@ var loaders = {
|
|
|
1805
1828
|
ton: async () => {
|
|
1806
1829
|
let mod;
|
|
1807
1830
|
try {
|
|
1808
|
-
mod = await import("./ton-
|
|
1831
|
+
mod = await import("./ton-5ZPT5PSP.js");
|
|
1809
1832
|
} catch (cause) {
|
|
1810
1833
|
throw new MissingDriverError(
|
|
1811
1834
|
`TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
|
|
@@ -1817,7 +1840,7 @@ var loaders = {
|
|
|
1817
1840
|
stellar: async () => {
|
|
1818
1841
|
let mod;
|
|
1819
1842
|
try {
|
|
1820
|
-
mod = await import("./stellar-
|
|
1843
|
+
mod = await import("./stellar-U5NCRIOJ.js");
|
|
1821
1844
|
} catch (cause) {
|
|
1822
1845
|
throw new MissingDriverError(
|
|
1823
1846
|
`Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
|
|
@@ -1829,7 +1852,7 @@ var loaders = {
|
|
|
1829
1852
|
xrpl: async () => {
|
|
1830
1853
|
let mod;
|
|
1831
1854
|
try {
|
|
1832
|
-
mod = await import("./xrpl-
|
|
1855
|
+
mod = await import("./xrpl-2MZEOIFY.js");
|
|
1833
1856
|
} catch (cause) {
|
|
1834
1857
|
throw new MissingDriverError(
|
|
1835
1858
|
`XRPL selected, but its package isn't installed. Run: npm install xrpl`,
|
|
@@ -1841,7 +1864,7 @@ var loaders = {
|
|
|
1841
1864
|
tron: async () => {
|
|
1842
1865
|
let mod;
|
|
1843
1866
|
try {
|
|
1844
|
-
mod = await import("./tron-
|
|
1867
|
+
mod = await import("./tron-WYS4X2I5.js");
|
|
1845
1868
|
} catch (cause) {
|
|
1846
1869
|
throw new MissingDriverError(
|
|
1847
1870
|
`Tron selected, but its package isn't installed. Run: npm install tronweb`,
|
|
@@ -1853,7 +1876,7 @@ var loaders = {
|
|
|
1853
1876
|
sui: async () => {
|
|
1854
1877
|
let mod;
|
|
1855
1878
|
try {
|
|
1856
|
-
mod = await import("./sui-
|
|
1879
|
+
mod = await import("./sui-Y53M4GUM.js");
|
|
1857
1880
|
} catch (cause) {
|
|
1858
1881
|
throw new MissingDriverError(
|
|
1859
1882
|
`Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
|
|
@@ -1865,7 +1888,7 @@ var loaders = {
|
|
|
1865
1888
|
near: async () => {
|
|
1866
1889
|
let mod;
|
|
1867
1890
|
try {
|
|
1868
|
-
mod = await import("./near-
|
|
1891
|
+
mod = await import("./near-MTYBCUYM.js");
|
|
1869
1892
|
} catch (cause) {
|
|
1870
1893
|
throw new MissingDriverError(
|
|
1871
1894
|
`NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
|
|
@@ -1877,7 +1900,7 @@ var loaders = {
|
|
|
1877
1900
|
aptos: async () => {
|
|
1878
1901
|
let mod;
|
|
1879
1902
|
try {
|
|
1880
|
-
mod = await import("./aptos-
|
|
1903
|
+
mod = await import("./aptos-RIL56C7L.js");
|
|
1881
1904
|
} catch (cause) {
|
|
1882
1905
|
throw new MissingDriverError(
|
|
1883
1906
|
`Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
|
|
@@ -1889,7 +1912,7 @@ var loaders = {
|
|
|
1889
1912
|
algorand: async () => {
|
|
1890
1913
|
let mod;
|
|
1891
1914
|
try {
|
|
1892
|
-
mod = await import("./algorand-
|
|
1915
|
+
mod = await import("./algorand-GSFVZTBF.js");
|
|
1893
1916
|
} catch (cause) {
|
|
1894
1917
|
throw new MissingDriverError(
|
|
1895
1918
|
`Algorand selected, but its package isn't installed. Run: npm install algosdk`,
|
|
@@ -2577,8 +2600,29 @@ var PipRailClient = class {
|
|
|
2577
2600
|
this.maxRetries = Math.max(1, opts.maxPaymentRetries ?? 3);
|
|
2578
2601
|
this.retryTimeoutMs = opts.retryTimeoutMs ?? 3e4;
|
|
2579
2602
|
this.onEvent = 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
|
|
@@ -3181,20 +3225,25 @@ var PipRailClient = 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)) {
|
|
3228
|
+
if (typeof accept.amount !== "string" || !/^\d+$/.test(accept.amount)) {
|
|
3229
|
+
throw new 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) {
|
|
3185
3234
|
throw new InvalidEnvelopeError(
|
|
3186
|
-
`challenge
|
|
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 = described?.decimals ?? accept.extra
|
|
3192
|
-
if (decimals
|
|
3240
|
+
const decimals = described?.decimals ?? accept.extra?.decimals;
|
|
3241
|
+
if (typeof decimals !== "number" || !Number.isInteger(decimals) || decimals < 0) {
|
|
3193
3242
|
throw new InvalidEnvelopeError(
|
|
3194
|
-
`challenge for ${accept.asset} on ${accept.network} states no decimals and the SDK doesn't recognise the token \u2014 refusing to price it.`
|
|
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 = described?.symbol ?? accept.extra
|
|
3246
|
+
const symbol = described?.symbol ?? accept.extra?.symbol;
|
|
3198
3247
|
const amountFormatted = formatUnits(amountBase, decimals);
|
|
3199
3248
|
const intent = {
|
|
3200
3249
|
host: hostOf2(url),
|
|
@@ -3226,7 +3275,7 @@ var PipRailClient = class {
|
|
|
3226
3275
|
this.ledger.totalFor(accept.network, accept.asset),
|
|
3227
3276
|
ctx
|
|
3228
3277
|
);
|
|
3229
|
-
const serverSymbol = accept.extra
|
|
3278
|
+
const serverSymbol = accept.extra?.symbol;
|
|
3230
3279
|
const symbolMismatch = intent.recognized && !!serverSymbol && !!symbol && serverSymbol.toUpperCase() !== symbol.toUpperCase();
|
|
3231
3280
|
return {
|
|
3232
3281
|
url,
|
|
@@ -3302,7 +3351,7 @@ var PipRailClient = class {
|
|
|
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, accept.extra
|
|
3354
|
+
const { height } = await net.confirm(ref, accept.extra?.minConfirmations ?? 1);
|
|
3306
3355
|
this.safeEmit({
|
|
3307
3356
|
kind: "payment-confirmed",
|
|
3308
3357
|
ref,
|
|
@@ -3322,7 +3371,7 @@ var PipRailClient = class {
|
|
|
3322
3371
|
const signature = {
|
|
3323
3372
|
x402Version: 2,
|
|
3324
3373
|
accepted: accept,
|
|
3325
|
-
payload: { nonce: accept.extra
|
|
3374
|
+
payload: { nonce: accept.extra?.nonce, txHash: ref }
|
|
3326
3375
|
};
|
|
3327
3376
|
const headers = new Headers(originalInit?.headers);
|
|
3328
3377
|
headers.set(HEADER_SIGNATURE, buildSignatureHeader(signature));
|
|
@@ -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
|
* })
|
|
@@ -4015,6 +4064,22 @@ async function readBody(res) {
|
|
|
4015
4064
|
return text;
|
|
4016
4065
|
}
|
|
4017
4066
|
}
|
|
4067
|
+
function toToolError(err) {
|
|
4068
|
+
if (!(err instanceof 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 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
|
{
|
|
@@ -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
|
{
|
|
@@ -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);
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var _chunkJG6KRAW6cjs = require('./chunk-JG6KRAW6.cjs');
|
|
11
12
|
|
|
12
13
|
// src/drivers/near/index.ts
|
|
13
14
|
var _nearapijs = require('near-api-js');
|
|
@@ -53,18 +54,18 @@ async function payNear(params) {
|
|
|
53
54
|
return res.hash;
|
|
54
55
|
} catch (err) {
|
|
55
56
|
if (isNearRegistrationError(err)) {
|
|
56
|
-
throw new (0,
|
|
57
|
+
throw new (0, _chunkJG6KRAW6cjs.RecipientNotReadyError)(
|
|
57
58
|
`NEAR recipient ${accept.payTo} isn't registered on token ${accept.asset} (NEP-145 storage_deposit) \u2014 register it once (\u22480.00125 NEAR) before it can receive. (NEAR: not registered)`,
|
|
58
59
|
{ cause: err }
|
|
59
60
|
);
|
|
60
61
|
}
|
|
61
62
|
if (isNearAffordability(err)) {
|
|
62
|
-
throw new (0,
|
|
63
|
+
throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
|
|
63
64
|
err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
|
|
64
65
|
{ cause: err }
|
|
65
66
|
);
|
|
66
67
|
}
|
|
67
|
-
throw _nullishCoalesce(
|
|
68
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
async function payNearNative(params) {
|
|
@@ -74,12 +75,12 @@ async function payNearNative(params) {
|
|
|
74
75
|
return res.hash;
|
|
75
76
|
} catch (err) {
|
|
76
77
|
if (isNearAffordability(err)) {
|
|
77
|
-
throw new (0,
|
|
78
|
+
throw new (0, _chunkJG6KRAW6cjs.InsufficientFundsError)(
|
|
78
79
|
err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
|
|
79
80
|
{ cause: err }
|
|
80
81
|
);
|
|
81
82
|
}
|
|
82
|
-
throw _nullishCoalesce(
|
|
83
|
+
throw _nullishCoalesce(_chunkJG6KRAW6cjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
function isNearRegistrationError(err) {
|
|
@@ -216,36 +217,27 @@ function txNotFound(hash) {
|
|
|
216
217
|
|
|
217
218
|
function assertNearWallet(wallet, network) {
|
|
218
219
|
if (typeof wallet !== "object" || wallet === null) {
|
|
219
|
-
throw new (0,
|
|
220
|
-
`chain ${network} is NEAR; wallet must be { accountId,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
if ("walletClient" in wallet) {
|
|
224
|
-
throw new (0, _chunkU35MG4TFcjs.WrongFamilyError)(
|
|
225
|
-
`chain ${network} is NEAR; a viem { walletClient } can't be used \u2014 pass { accountId, privateKey }.`
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "keypair" in wallet) {
|
|
229
|
-
throw new (0, _chunkU35MG4TFcjs.WrongFamilyError)(
|
|
230
|
-
`chain ${network} is NEAR; that looks like another family's wallet \u2014 pass { accountId, privateKey }.`
|
|
220
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
221
|
+
`chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
|
|
231
222
|
);
|
|
232
223
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
_chunkJG6KRAW6cjs.assertNoLegacyWalletKey.call(void 0, wallet, "NEAR");
|
|
225
|
+
if (!("accountId" in wallet) || !("key" in wallet)) {
|
|
226
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
227
|
+
`chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
|
|
236
228
|
);
|
|
237
229
|
}
|
|
238
230
|
return wallet;
|
|
239
231
|
}
|
|
240
232
|
function resolveNearWallet(config) {
|
|
241
|
-
if (!config.accountId || !config.
|
|
242
|
-
throw new (0,
|
|
233
|
+
if (!config.accountId || !config.key) {
|
|
234
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
|
|
243
235
|
}
|
|
244
236
|
let signer;
|
|
245
237
|
try {
|
|
246
|
-
signer = _nearapijs.KeyPairSigner.fromSecretKey(config.
|
|
238
|
+
signer = _nearapijs.KeyPairSigner.fromSecretKey(config.key);
|
|
247
239
|
} catch (cause) {
|
|
248
|
-
throw new (0,
|
|
240
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
|
|
249
241
|
cause
|
|
250
242
|
});
|
|
251
243
|
}
|
|
@@ -312,16 +304,16 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
312
304
|
const info = preset.tokens[token.toUpperCase()];
|
|
313
305
|
if (!info) {
|
|
314
306
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
315
|
-
throw new (0,
|
|
307
|
+
throw new (0, _chunkJG6KRAW6cjs.UnknownTokenError)(
|
|
316
308
|
`token "${token}" isn't built in for NEAR (known: ${known}). Pass { contractId, decimals } for a custom NEP-141.`
|
|
317
309
|
);
|
|
318
310
|
}
|
|
319
311
|
return { asset: info.contractId, decimals: info.decimals, symbol: info.symbol };
|
|
320
312
|
}
|
|
321
|
-
|
|
313
|
+
_chunkJG6KRAW6cjs.rejectForeignToken.call(void 0, token, "near", network);
|
|
322
314
|
const t = token;
|
|
323
315
|
if (!t.contractId || typeof t.decimals !== "number") {
|
|
324
|
-
throw new (0,
|
|
316
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
325
317
|
`chain ${network} is NEAR; a custom token must be { contractId, decimals }.`
|
|
326
318
|
);
|
|
327
319
|
}
|
|
@@ -340,12 +332,12 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
340
332
|
},
|
|
341
333
|
assertValidPayTo(payTo) {
|
|
342
334
|
if (payTo.startsWith("0x")) {
|
|
343
|
-
throw new (0,
|
|
335
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
344
336
|
`chain ${network} is NEAR, but payTo "${payTo}" looks like an EVM/Sui 0x address.`
|
|
345
337
|
);
|
|
346
338
|
}
|
|
347
339
|
if (!isValidNearAccountId(payTo)) {
|
|
348
|
-
throw new (0,
|
|
340
|
+
throw new (0, _chunkJG6KRAW6cjs.WrongFamilyError)(
|
|
349
341
|
`chain ${network} is NEAR, but payTo "${payTo}" is not a valid NEAR account id.`
|
|
350
342
|
);
|
|
351
343
|
}
|
|
@@ -389,10 +381,10 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
389
381
|
if (tx && tx.success) return { height: "0" };
|
|
390
382
|
} catch (e7) {
|
|
391
383
|
}
|
|
392
|
-
throw new (0,
|
|
384
|
+
throw new (0, _chunkJG6KRAW6cjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
|
|
393
385
|
},
|
|
394
386
|
async estimateCost() {
|
|
395
|
-
return
|
|
387
|
+
return _chunkJG6KRAW6cjs.nativeCost.call(void 0, {
|
|
396
388
|
symbol: "NEAR",
|
|
397
389
|
decimals: NEAR_DECIMALS,
|
|
398
390
|
fee: 1500000000000000000000n,
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
RecipientNotReadyError,
|
|
5
5
|
UnknownTokenError,
|
|
6
6
|
WrongFamilyError,
|
|
7
|
+
assertNoLegacyWalletKey,
|
|
7
8
|
nativeCost,
|
|
8
9
|
rejectForeignToken,
|
|
9
10
|
toInsufficientFundsError
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-7XK22JSQ.js";
|
|
11
12
|
|
|
12
13
|
// src/drivers/near/index.ts
|
|
13
14
|
import { JsonRpcProvider, Account, actions } from "near-api-js";
|
|
@@ -217,35 +218,26 @@ import { KeyPairSigner } from "near-api-js";
|
|
|
217
218
|
function assertNearWallet(wallet, network) {
|
|
218
219
|
if (typeof wallet !== "object" || wallet === null) {
|
|
219
220
|
throw new WrongFamilyError(
|
|
220
|
-
`chain ${network} is NEAR; wallet must be { accountId,
|
|
221
|
+
`chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
|
|
221
222
|
);
|
|
222
223
|
}
|
|
223
|
-
|
|
224
|
+
assertNoLegacyWalletKey(wallet, "NEAR");
|
|
225
|
+
if (!("accountId" in wallet) || !("key" in wallet)) {
|
|
224
226
|
throw new WrongFamilyError(
|
|
225
|
-
`chain ${network} is NEAR;
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "keypair" in wallet) {
|
|
229
|
-
throw new WrongFamilyError(
|
|
230
|
-
`chain ${network} is NEAR; that looks like another family's wallet \u2014 pass { accountId, privateKey }.`
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
if (!("accountId" in wallet) || !("privateKey" in wallet)) {
|
|
234
|
-
throw new WrongFamilyError(
|
|
235
|
-
`chain ${network} is NEAR; wallet must be { accountId, privateKey } (privateKey = ed25519:\u2026).`
|
|
227
|
+
`chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
|
|
236
228
|
);
|
|
237
229
|
}
|
|
238
230
|
return wallet;
|
|
239
231
|
}
|
|
240
232
|
function resolveNearWallet(config) {
|
|
241
|
-
if (!config.accountId || !config.
|
|
242
|
-
throw new WrongFamilyError("NEAR wallet needs { accountId,
|
|
233
|
+
if (!config.accountId || !config.key) {
|
|
234
|
+
throw new WrongFamilyError("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
|
|
243
235
|
}
|
|
244
236
|
let signer;
|
|
245
237
|
try {
|
|
246
|
-
signer = KeyPairSigner.fromSecretKey(config.
|
|
238
|
+
signer = KeyPairSigner.fromSecretKey(config.key);
|
|
247
239
|
} catch (cause) {
|
|
248
|
-
throw new WrongFamilyError("NEAR wallet {
|
|
240
|
+
throw new WrongFamilyError("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
|
|
249
241
|
cause
|
|
250
242
|
});
|
|
251
243
|
}
|