@piprail/sdk 2.14.2 → 2.15.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 +98 -0
- package/README.md +3 -1
- package/dist/{algorand-CSEUTWNW.js → algorand-UF7BLBFN.js} +1 -1
- package/dist/{algorand-I2O24RSM.cjs → algorand-XGSWDMCZ.cjs} +32 -32
- package/dist/{aptos-GA5AEYYL.cjs → aptos-J2QSWHTO.cjs} +31 -31
- package/dist/{aptos-J7QGCWNW.js → aptos-KDLX42CR.js} +1 -1
- package/dist/{chunk-3FR22M3O.cjs → chunk-QONQSZHJ.cjs} +2 -2
- package/dist/{chunk-3ZWM3DKM.js → chunk-QU25LSVS.js} +2 -2
- package/dist/index.cjs +282 -181
- package/dist/index.d.cts +140 -1
- package/dist/index.d.ts +140 -1
- package/dist/index.js +151 -50
- package/dist/{near-NDQLGI4U.cjs → near-5LTTDU6G.cjs} +27 -27
- package/dist/{near-YA4Y4IGC.js → near-OLKCMTBI.js} +1 -1
- package/dist/{solana-OU6IUMQM.cjs → solana-S2T3JNR7.cjs} +32 -32
- package/dist/{solana-MB6G3OA5.js → solana-WO2G7WWZ.js} +1 -1
- package/dist/{stellar-RSNVOIKL.cjs → stellar-E2KWEV2E.cjs} +20 -20
- package/dist/{stellar-WDWSYOED.js → stellar-EUFZLX6J.js} +1 -1
- package/dist/{sui-GVSFNNJX.js → sui-KCIITCYH.js} +6 -2
- package/dist/{sui-MVC46BFJ.cjs → sui-Q3NJOJZS.cjs} +21 -17
- package/dist/{ton-MYOI3U3H.cjs → ton-J7TQWRN4.cjs} +16 -16
- package/dist/{ton-EJMGM3YI.js → ton-WH2JVQOO.js} +1 -1
- package/dist/{tron-VAPVMGJK.js → tron-FXBXDNEY.js} +1 -1
- package/dist/{tron-42X5N4GQ.cjs → tron-HIPMOX7S.cjs} +25 -25
- package/dist/{xrpl-Q2UWPCTJ.js → xrpl-6B2XOXGC.js} +1 -1
- package/dist/{xrpl-MGUBUNSZ.cjs → xrpl-VOUXIUYD.cjs} +20 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
parseUnits,
|
|
33
33
|
rejectForeignToken,
|
|
34
34
|
toInsufficientFundsError
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-QU25LSVS.js";
|
|
36
36
|
|
|
37
37
|
// src/drivers/registry.ts
|
|
38
38
|
var byFamily = /* @__PURE__ */ new Map();
|
|
@@ -1757,7 +1757,16 @@ function decodeBase64Json(value) {
|
|
|
1757
1757
|
return fromBase64Json(value);
|
|
1758
1758
|
}
|
|
1759
1759
|
function toBase64Json(value) {
|
|
1760
|
-
|
|
1760
|
+
let json;
|
|
1761
|
+
try {
|
|
1762
|
+
json = JSON.stringify(value);
|
|
1763
|
+
} catch (cause) {
|
|
1764
|
+
throw new InvalidConfigError(
|
|
1765
|
+
`x402: this payload cannot be serialised to JSON (${cause.message}). Amounts must be decimal STRINGS, not BigInt \u2014 pass '50000', not 50000n.`,
|
|
1766
|
+
{ cause }
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1769
|
+
return encodeBase64(json);
|
|
1761
1770
|
}
|
|
1762
1771
|
function networkForChain(chainId) {
|
|
1763
1772
|
return `eip155:${chainId}`;
|
|
@@ -2296,7 +2305,19 @@ function makeEvmNetwork(resolved) {
|
|
|
2296
2305
|
return resolveExactRailEvm({
|
|
2297
2306
|
asset,
|
|
2298
2307
|
method,
|
|
2299
|
-
|
|
2308
|
+
// `readExactDomain` fails CLOSED to null on two very different causes: the token really
|
|
2309
|
+
// isn't EIP-3009, or the RPC read blipped (rate-limit, timeout, an HTML error page from a
|
|
2310
|
+
// proxy). Treating a blip as "not EIP-3009" silently downgrades a perfectly good gasless
|
|
2311
|
+
// rail to onchain-proof — the merchant's buyers start paying gas and the warning blames
|
|
2312
|
+
// their TOKEN, which is the one thing that isn't wrong. The buyer side already retries
|
|
2313
|
+
// once for exactly this reason (see payExactEvm); the gate side did not, so a rate-limited
|
|
2314
|
+
// public RPC could turn real Base USDC into "this token isn't EIP-3009". Mirror it.
|
|
2315
|
+
readDomain: async (a) => {
|
|
2316
|
+
const first = await readExactDomain(publicClient, a);
|
|
2317
|
+
if (first) return first;
|
|
2318
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
2319
|
+
return readExactDomain(publicClient, a);
|
|
2320
|
+
},
|
|
2300
2321
|
permit2Supported: () => isPermit2ProxyChain(resolved.chainId)
|
|
2301
2322
|
});
|
|
2302
2323
|
},
|
|
@@ -2382,7 +2403,7 @@ var loaders = {
|
|
|
2382
2403
|
solana: async () => {
|
|
2383
2404
|
let mod;
|
|
2384
2405
|
try {
|
|
2385
|
-
mod = await import("./solana-
|
|
2406
|
+
mod = await import("./solana-WO2G7WWZ.js");
|
|
2386
2407
|
} catch (cause) {
|
|
2387
2408
|
throw new MissingDriverError(
|
|
2388
2409
|
`Solana selected, but its packages aren't installed. Run: npm install @solana/web3.js @solana/spl-token bs58`,
|
|
@@ -2394,7 +2415,7 @@ var loaders = {
|
|
|
2394
2415
|
ton: async () => {
|
|
2395
2416
|
let mod;
|
|
2396
2417
|
try {
|
|
2397
|
-
mod = await import("./ton-
|
|
2418
|
+
mod = await import("./ton-WH2JVQOO.js");
|
|
2398
2419
|
} catch (cause) {
|
|
2399
2420
|
throw new MissingDriverError(
|
|
2400
2421
|
`TON selected, but its packages aren't installed. Run: npm install @ton/ton @ton/core @ton/crypto`,
|
|
@@ -2406,7 +2427,7 @@ var loaders = {
|
|
|
2406
2427
|
stellar: async () => {
|
|
2407
2428
|
let mod;
|
|
2408
2429
|
try {
|
|
2409
|
-
mod = await import("./stellar-
|
|
2430
|
+
mod = await import("./stellar-EUFZLX6J.js");
|
|
2410
2431
|
} catch (cause) {
|
|
2411
2432
|
throw new MissingDriverError(
|
|
2412
2433
|
`Stellar selected, but its package isn't installed. Run: npm install @stellar/stellar-sdk`,
|
|
@@ -2418,7 +2439,7 @@ var loaders = {
|
|
|
2418
2439
|
xrpl: async () => {
|
|
2419
2440
|
let mod;
|
|
2420
2441
|
try {
|
|
2421
|
-
mod = await import("./xrpl-
|
|
2442
|
+
mod = await import("./xrpl-6B2XOXGC.js");
|
|
2422
2443
|
} catch (cause) {
|
|
2423
2444
|
throw new MissingDriverError(
|
|
2424
2445
|
`XRPL selected, but its package isn't installed. Run: npm install xrpl`,
|
|
@@ -2430,7 +2451,7 @@ var loaders = {
|
|
|
2430
2451
|
tron: async () => {
|
|
2431
2452
|
let mod;
|
|
2432
2453
|
try {
|
|
2433
|
-
mod = await import("./tron-
|
|
2454
|
+
mod = await import("./tron-FXBXDNEY.js");
|
|
2434
2455
|
} catch (cause) {
|
|
2435
2456
|
throw new MissingDriverError(
|
|
2436
2457
|
`Tron selected, but its package isn't installed. Run: npm install tronweb`,
|
|
@@ -2442,7 +2463,7 @@ var loaders = {
|
|
|
2442
2463
|
sui: async () => {
|
|
2443
2464
|
let mod;
|
|
2444
2465
|
try {
|
|
2445
|
-
mod = await import("./sui-
|
|
2466
|
+
mod = await import("./sui-KCIITCYH.js");
|
|
2446
2467
|
} catch (cause) {
|
|
2447
2468
|
throw new MissingDriverError(
|
|
2448
2469
|
`Sui selected, but its package isn't installed. Run: npm install @mysten/sui`,
|
|
@@ -2454,7 +2475,7 @@ var loaders = {
|
|
|
2454
2475
|
near: async () => {
|
|
2455
2476
|
let mod;
|
|
2456
2477
|
try {
|
|
2457
|
-
mod = await import("./near-
|
|
2478
|
+
mod = await import("./near-OLKCMTBI.js");
|
|
2458
2479
|
} catch (cause) {
|
|
2459
2480
|
throw new MissingDriverError(
|
|
2460
2481
|
`NEAR selected, but its package isn't installed. Run: npm install near-api-js`,
|
|
@@ -2466,7 +2487,7 @@ var loaders = {
|
|
|
2466
2487
|
aptos: async () => {
|
|
2467
2488
|
let mod;
|
|
2468
2489
|
try {
|
|
2469
|
-
mod = await import("./aptos-
|
|
2490
|
+
mod = await import("./aptos-KDLX42CR.js");
|
|
2470
2491
|
} catch (cause) {
|
|
2471
2492
|
throw new MissingDriverError(
|
|
2472
2493
|
`Aptos selected, but its package isn't installed. Run: npm install @aptos-labs/ts-sdk`,
|
|
@@ -2478,7 +2499,7 @@ var loaders = {
|
|
|
2478
2499
|
algorand: async () => {
|
|
2479
2500
|
let mod;
|
|
2480
2501
|
try {
|
|
2481
|
-
mod = await import("./algorand-
|
|
2502
|
+
mod = await import("./algorand-UF7BLBFN.js");
|
|
2482
2503
|
} catch (cause) {
|
|
2483
2504
|
throw new MissingDriverError(
|
|
2484
2505
|
`Algorand selected, but its package isn't installed. Run: npm install algosdk`,
|
|
@@ -6418,13 +6439,6 @@ var KNOWN_FACILITATORS = {
|
|
|
6418
6439
|
settles: ["eip3009"],
|
|
6419
6440
|
note: "Dexter \u2014 keyless, gas-sponsored (Base USDC EIP-3009). LIVE-settled on Base 2026-06-17 (tx 0xdf030e4d5bf41a88c5a3bfe73bb433dfbb90b058d3b8ded63b68e026eedb9de8). Note: ~$0.001 dynamic floor on Base."
|
|
6420
6441
|
},
|
|
6421
|
-
{
|
|
6422
|
-
url: "https://facilitator.corbits.dev",
|
|
6423
|
-
keyless: true,
|
|
6424
|
-
schemes: ["exact"],
|
|
6425
|
-
settles: ["eip3009"],
|
|
6426
|
-
note: "Corbits (Faremeter) \u2014 keyless, sponsors gas (Base USDC EIP-3009). LIVE-settled on Base 2026-06-17 (tx 0x2e41c581af023100429ada81f1371bef82d41dd577ed438d72ddc18676d4213d). Also seeded on Monad + Solana."
|
|
6427
|
-
},
|
|
6428
6442
|
{
|
|
6429
6443
|
url: "https://facilitator.goplausible.xyz",
|
|
6430
6444
|
keyless: true,
|
|
@@ -6438,26 +6452,12 @@ var KNOWN_FACILITATORS = {
|
|
|
6438
6452
|
schemes: ["exact"],
|
|
6439
6453
|
settles: ["eip3009"],
|
|
6440
6454
|
note: "Cascade \u2014 keyless, sponsors gas (Base USDC EIP-3009). LIVE-settled on Base 2026-06-18 (tx 0x2e784725f3c66e170720cc8df43a9248f02ad80914fcbe05dadbdbe411c3b52b)."
|
|
6441
|
-
},
|
|
6442
|
-
{
|
|
6443
|
-
url: "https://facilitator.bitcoinsapi.com",
|
|
6444
|
-
keyless: true,
|
|
6445
|
-
schemes: ["exact"],
|
|
6446
|
-
settles: ["eip3009"],
|
|
6447
|
-
note: "Satoshi (bitcoinsapi) \u2014 keyless, sponsors gas (Base USDC EIP-3009). LIVE-settled on Base 2026-06-18 (tx 0xbb2b6c354b12c6d07cce91e2b337e38327d4b0833bbd1dfbeda3ad495b67b819)."
|
|
6448
6455
|
}
|
|
6449
6456
|
],
|
|
6450
6457
|
// Monad (eip155:143). Corbits + Ultravioleta DAO each keyless-settle the EVM EIP-3009 exact rail
|
|
6451
6458
|
// (Monad's native Circle USDC), buyer paid zero gas — real LIVE settles, not just /supported reads.
|
|
6452
6459
|
// Makes `exact: true` zero-config gasless on Monad.
|
|
6453
6460
|
"eip155:143": [
|
|
6454
|
-
{
|
|
6455
|
-
url: "https://facilitator.corbits.dev",
|
|
6456
|
-
keyless: true,
|
|
6457
|
-
schemes: ["exact"],
|
|
6458
|
-
settles: ["eip3009"],
|
|
6459
|
-
note: "Corbits (Faremeter) \u2014 keyless, sponsors gas (Monad native USDC EIP-3009). LIVE-settled on Monad 2026-06-17 (tx 0x7797be27ce22c17f7433a0389bd22d46e338899b1faac505fffd068174428ae6)."
|
|
6460
|
-
},
|
|
6461
6461
|
{
|
|
6462
6462
|
url: "https://facilitator.ultravioletadao.xyz",
|
|
6463
6463
|
keyless: true,
|
|
@@ -6540,13 +6540,6 @@ var KNOWN_FACILITATORS = {
|
|
|
6540
6540
|
settles: ["eip3009"],
|
|
6541
6541
|
note: "Polygon Labs (the official Polygon facilitator) \u2014 keyless, sponsors gas. LIVE-settled on Polygon 2026-06-18 (tx 0x6a8ca60ea111959a61a85ad6c4f2ed99e192052ec7b9ffb59baa33691a86f419)."
|
|
6542
6542
|
},
|
|
6543
|
-
{
|
|
6544
|
-
url: "https://facilitator.corbits.dev",
|
|
6545
|
-
keyless: true,
|
|
6546
|
-
schemes: ["exact"],
|
|
6547
|
-
settles: ["eip3009"],
|
|
6548
|
-
note: "Corbits (Faremeter) \u2014 keyless, sponsors gas. LIVE-settled on Polygon 2026-06-18 (tx 0x2fadca2ee3cd7fcff32d015e8b06109de6b747d7cd0f80dcd8fb022b2d58d008)."
|
|
6549
|
-
},
|
|
6550
6543
|
{
|
|
6551
6544
|
url: "https://facilitator.ultravioletadao.xyz",
|
|
6552
6545
|
keyless: true,
|
|
@@ -6674,13 +6667,6 @@ var KNOWN_FACILITATORS = {
|
|
|
6674
6667
|
schemes: ["exact"],
|
|
6675
6668
|
settles: ["svm"],
|
|
6676
6669
|
note: "OpenFacilitator \u2014 keyless (no signup), fee-payer sponsor. LIVE-settled on Solana 2026-06-15 (tx 5BabDtX\u2026)."
|
|
6677
|
-
},
|
|
6678
|
-
{
|
|
6679
|
-
url: "https://facilitator.corbits.dev",
|
|
6680
|
-
keyless: true,
|
|
6681
|
-
schemes: ["exact"],
|
|
6682
|
-
settles: ["svm"],
|
|
6683
|
-
note: "Corbits \u2014 keyless, Solana-first fee-payer sponsor. LIVE-settled on Solana 2026-06-15 (tx BCreYer\u2026)."
|
|
6684
6670
|
}
|
|
6685
6671
|
]
|
|
6686
6672
|
// NEAR (near:mainnet) — DELIBERATELY UNSEEDED: no x402 facilitator settles NEAR yet.
|
|
@@ -6871,7 +6857,7 @@ function createPaymentGate(options) {
|
|
|
6871
6857
|
);
|
|
6872
6858
|
}
|
|
6873
6859
|
return {
|
|
6874
|
-
skipReason: `${net.network}:
|
|
6860
|
+
skipReason: `${net.network}: auto-selected Permit2, which a third-party facilitator can't settle \u2014 it would serve onchain-proof only here. Either this token isn't EIP-3009 (use USDC / EURC with the facilitator, or \`settle: 'self'\` to settle Permit2 yourself), OR the EIP-712 domain read failed on your RPC (transient): if you expected a gasless rail here, pass a reliable \`rpcUrl\` and retry.`
|
|
6875
6861
|
};
|
|
6876
6862
|
}
|
|
6877
6863
|
const mode = settle === "self" ? { kind: "self", relayer } : {
|
|
@@ -7220,7 +7206,7 @@ function createPaymentGate(options) {
|
|
|
7220
7206
|
`Proof claims ${sig.accepted.asset} on ${sig.accepted.network}, which this resource doesn't accept (offered: ${specs.map((s) => `${s.asset}@${s.net.network}`).join(", ")}).`
|
|
7221
7207
|
);
|
|
7222
7208
|
}
|
|
7223
|
-
const ref = sig.payload.txHash;
|
|
7209
|
+
const ref = typeof sig.payload.txHash === "string" ? sig.payload.txHash.trim() : sig.payload.txHash;
|
|
7224
7210
|
if (await claimTx(ref)) return rejection("tx_already_used", `Proof ${ref} was already redeemed.`);
|
|
7225
7211
|
let result;
|
|
7226
7212
|
try {
|
|
@@ -7499,7 +7485,36 @@ function createPaymentGate(options) {
|
|
|
7499
7485
|
await settleTx(idKey, result.kind === "paid");
|
|
7500
7486
|
return result.kind === "paid" ? echoPaymentIdentifier(result, id) : result;
|
|
7501
7487
|
}
|
|
7502
|
-
|
|
7488
|
+
async function selfTest() {
|
|
7489
|
+
try {
|
|
7490
|
+
const specs = await ready();
|
|
7491
|
+
const warnings = [];
|
|
7492
|
+
const rails = specs.map((s) => {
|
|
7493
|
+
if (!s.symbol) {
|
|
7494
|
+
warnings.push(
|
|
7495
|
+
`${s.asset} on ${s.net.network}: custom token (no built-in symbol) \u2014 double-check the address + decimals.`
|
|
7496
|
+
);
|
|
7497
|
+
}
|
|
7498
|
+
return {
|
|
7499
|
+
network: s.net.network,
|
|
7500
|
+
asset: s.asset,
|
|
7501
|
+
...s.symbol ? { symbol: s.symbol } : {},
|
|
7502
|
+
decimals: s.decimals,
|
|
7503
|
+
amount: s.amountFormatted,
|
|
7504
|
+
payTo: s.payTo,
|
|
7505
|
+
schemes: [
|
|
7506
|
+
...s.exact ? ["exact"] : [],
|
|
7507
|
+
...s.upto ? ["upto"] : [],
|
|
7508
|
+
"onchain-proof"
|
|
7509
|
+
]
|
|
7510
|
+
};
|
|
7511
|
+
});
|
|
7512
|
+
return { ok: true, rails, warnings };
|
|
7513
|
+
} catch (err) {
|
|
7514
|
+
return { ok: false, rails: [], warnings: [], error: err instanceof Error ? err.message : String(err) };
|
|
7515
|
+
}
|
|
7516
|
+
}
|
|
7517
|
+
return { challenge, verify, verifyObject, describe, landingPage, selfTest };
|
|
7503
7518
|
}
|
|
7504
7519
|
function requirePayment(options) {
|
|
7505
7520
|
if (options.upto) {
|
|
@@ -7551,6 +7566,87 @@ function normaliseHeader(value) {
|
|
|
7551
7566
|
return value;
|
|
7552
7567
|
}
|
|
7553
7568
|
|
|
7569
|
+
// src/merchant.ts
|
|
7570
|
+
function createPaywall({ token = "USDC", ...rest }) {
|
|
7571
|
+
return createPaymentGate({ token, ...rest });
|
|
7572
|
+
}
|
|
7573
|
+
function createTipJar({ token = "USDC", min, ...rest }) {
|
|
7574
|
+
return createPaymentGate({ token, amount: min, ...rest });
|
|
7575
|
+
}
|
|
7576
|
+
|
|
7577
|
+
// src/adapters.ts
|
|
7578
|
+
function jsonResponse(body, status, headers) {
|
|
7579
|
+
return new Response(JSON.stringify(body), {
|
|
7580
|
+
status,
|
|
7581
|
+
headers: { "content-type": "application/json; charset=utf-8", ...headers ?? {} }
|
|
7582
|
+
});
|
|
7583
|
+
}
|
|
7584
|
+
function withSettlementHeaders(res, receiptHeader) {
|
|
7585
|
+
const headers = new Headers();
|
|
7586
|
+
res.headers.forEach((value, key) => {
|
|
7587
|
+
if (key.toLowerCase() !== "set-cookie") headers.append(key, value);
|
|
7588
|
+
});
|
|
7589
|
+
const src = res.headers;
|
|
7590
|
+
const cookies = typeof src.getSetCookie === "function" ? src.getSetCookie() : (() => {
|
|
7591
|
+
const combined = res.headers.get("set-cookie");
|
|
7592
|
+
return combined ? [combined] : [];
|
|
7593
|
+
})();
|
|
7594
|
+
for (const cookie of cookies) headers.append("set-cookie", cookie);
|
|
7595
|
+
headers.set(HEADER_RESPONSE, receiptHeader);
|
|
7596
|
+
headers.set(HEADER_RESPONSE_V1, receiptHeader);
|
|
7597
|
+
return new Response(res.body, { status: res.status, statusText: res.statusText, headers });
|
|
7598
|
+
}
|
|
7599
|
+
function toFetchHandler(gate, serve) {
|
|
7600
|
+
return async (request, ...rest) => {
|
|
7601
|
+
let result;
|
|
7602
|
+
try {
|
|
7603
|
+
const sig = request.headers.get(HEADER_SIGNATURE) ?? request.headers.get(HEADER_SIGNATURE_V1) ?? void 0;
|
|
7604
|
+
result = await gate.verify(sig);
|
|
7605
|
+
} catch (err) {
|
|
7606
|
+
if (err instanceof SettlementError) {
|
|
7607
|
+
return jsonResponse(
|
|
7608
|
+
{
|
|
7609
|
+
x402Version: 2,
|
|
7610
|
+
error: "settlement_failed",
|
|
7611
|
+
detail: err.message,
|
|
7612
|
+
fallback: "The gasless `exact` settlement failed. This resource also accepts `onchain-proof` \u2014 retry by paying that rail yourself (you broadcast the transfer and pay the gas)."
|
|
7613
|
+
},
|
|
7614
|
+
502
|
|
7615
|
+
);
|
|
7616
|
+
}
|
|
7617
|
+
throw err;
|
|
7618
|
+
}
|
|
7619
|
+
if (result.kind === "paid") {
|
|
7620
|
+
const res = await serve(request, ...rest);
|
|
7621
|
+
return withSettlementHeaders(res, result.receiptHeader);
|
|
7622
|
+
}
|
|
7623
|
+
return jsonResponse(result.challenge, 402, { [HEADER_REQUIRED]: result.requiredHeader });
|
|
7624
|
+
};
|
|
7625
|
+
}
|
|
7626
|
+
function toWorker(gate, serve) {
|
|
7627
|
+
return { fetch: toFetchHandler(gate, serve) };
|
|
7628
|
+
}
|
|
7629
|
+
function proxyTo(origin) {
|
|
7630
|
+
const base2 = origin.replace(/\/+$/, "");
|
|
7631
|
+
return (request) => {
|
|
7632
|
+
const inUrl = new URL(request.url);
|
|
7633
|
+
const target = base2 + inUrl.pathname + inUrl.search;
|
|
7634
|
+
const headers = new Headers(request.headers);
|
|
7635
|
+
headers.delete(HEADER_SIGNATURE);
|
|
7636
|
+
headers.delete(HEADER_SIGNATURE_V1);
|
|
7637
|
+
const init = {
|
|
7638
|
+
method: request.method,
|
|
7639
|
+
headers,
|
|
7640
|
+
redirect: "manual"
|
|
7641
|
+
};
|
|
7642
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
7643
|
+
init.body = request.body;
|
|
7644
|
+
init.duplex = "half";
|
|
7645
|
+
}
|
|
7646
|
+
return fetch(target, init);
|
|
7647
|
+
};
|
|
7648
|
+
}
|
|
7649
|
+
|
|
7554
7650
|
// src/receipts.ts
|
|
7555
7651
|
var DEFAULT_RETRIES = 5;
|
|
7556
7652
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
@@ -8092,6 +8188,8 @@ export {
|
|
|
8092
8188
|
createA2APaymentHandler,
|
|
8093
8189
|
createMcpPaymentTool,
|
|
8094
8190
|
createPaymentGate,
|
|
8191
|
+
createPaywall,
|
|
8192
|
+
createTipJar,
|
|
8095
8193
|
decodeBase64Json,
|
|
8096
8194
|
decorateOutcome,
|
|
8097
8195
|
deliverReceipt,
|
|
@@ -8133,6 +8231,7 @@ export {
|
|
|
8133
8231
|
paymentTools,
|
|
8134
8232
|
pickAccept,
|
|
8135
8233
|
planAcross,
|
|
8234
|
+
proxyTo,
|
|
8136
8235
|
rankResources,
|
|
8137
8236
|
readExactDomain,
|
|
8138
8237
|
readPaymentIdentifier,
|
|
@@ -8150,9 +8249,11 @@ export {
|
|
|
8150
8249
|
toA2APaymentFailed,
|
|
8151
8250
|
toA2APaymentReceipts,
|
|
8152
8251
|
toA2APaymentRequired,
|
|
8252
|
+
toFetchHandler,
|
|
8153
8253
|
toInsufficientFundsError,
|
|
8154
8254
|
toInvalidBody,
|
|
8155
8255
|
toMcpPaymentRequired,
|
|
8156
8256
|
toMcpPaymentResponse,
|
|
8257
|
+
toWorker,
|
|
8157
8258
|
verify402IndexDomain
|
|
8158
8259
|
};
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkQONQSZHJcjs = require('./chunk-QONQSZHJ.cjs');
|
|
14
14
|
|
|
15
15
|
// src/drivers/near/index.ts
|
|
16
16
|
var _nearapijs = require('near-api-js');
|
|
@@ -61,18 +61,18 @@ async function payNear(params) {
|
|
|
61
61
|
return res.hash;
|
|
62
62
|
} catch (err) {
|
|
63
63
|
if (isNearRegistrationError(err)) {
|
|
64
|
-
throw new (0,
|
|
64
|
+
throw new (0, _chunkQONQSZHJcjs.RecipientNotReadyError)(
|
|
65
65
|
`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)`,
|
|
66
66
|
{ cause: err }
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
if (isNearAffordability(err)) {
|
|
70
|
-
throw new (0,
|
|
70
|
+
throw new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
|
|
71
71
|
err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
|
|
72
72
|
{ cause: err }
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
-
throw _nullishCoalesce(
|
|
75
|
+
throw _nullishCoalesce(_chunkQONQSZHJcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
async function payNearNative(params) {
|
|
@@ -82,12 +82,12 @@ async function payNearNative(params) {
|
|
|
82
82
|
return res.hash;
|
|
83
83
|
} catch (err) {
|
|
84
84
|
if (isNearAffordability(err)) {
|
|
85
|
-
throw new (0,
|
|
85
|
+
throw new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
|
|
86
86
|
err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
|
|
87
87
|
{ cause: err }
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
throw _nullishCoalesce(
|
|
90
|
+
throw _nullishCoalesce(_chunkQONQSZHJcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function isNearRegistrationError(err) {
|
|
@@ -109,28 +109,28 @@ var NONCE_BLOCK_MULTIPLIER = 1000000n;
|
|
|
109
109
|
async function payExactNear(input) {
|
|
110
110
|
const { signer, senderId, blockHeight, accessKeyNonce, accept } = input;
|
|
111
111
|
if (accept.asset === "native") {
|
|
112
|
-
throw new (0,
|
|
112
|
+
throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(
|
|
113
113
|
"NEAR exact is NEP-141-only (an ft_transfer); native NEAR is not exact-payable. Pay via onchain-proof."
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
if (!isValidNearAccountId(accept.asset)) {
|
|
117
|
-
throw new (0,
|
|
117
|
+
throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`NEAR exact: asset "${accept.asset}" must be a NEP-141 contract account id.`);
|
|
118
118
|
}
|
|
119
119
|
if (!isValidNearAccountId(accept.payTo)) {
|
|
120
|
-
throw new (0,
|
|
120
|
+
throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`NEAR exact: payTo "${accept.payTo}" is not a valid NEAR account id.`);
|
|
121
121
|
}
|
|
122
122
|
if (!isValidNearAccountId(senderId)) {
|
|
123
|
-
throw new (0,
|
|
123
|
+
throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(`NEAR exact: sender "${senderId}" is not a valid NEAR account id.`);
|
|
124
124
|
}
|
|
125
125
|
const t = accept.maxTimeoutSeconds;
|
|
126
126
|
if (!Number.isInteger(t) || t <= 0) {
|
|
127
|
-
throw new (0,
|
|
127
|
+
throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)("NEAR exact: maxTimeoutSeconds must be a positive integer.");
|
|
128
128
|
}
|
|
129
129
|
const timeoutBlocks = BigInt(Math.max(1, Math.ceil(t / ESTIMATED_BLOCK_SECONDS)));
|
|
130
130
|
const maxBlockHeight = blockHeight + timeoutBlocks;
|
|
131
131
|
const nonce = accessKeyNonce + 1n;
|
|
132
132
|
if (nonce >= blockHeight * NONCE_BLOCK_MULTIPLIER) {
|
|
133
|
-
throw new (0,
|
|
133
|
+
throw new (0, _chunkQONQSZHJcjs.UnsupportedSchemeError)(
|
|
134
134
|
"NEAR exact: the access-key nonce is at the protocol ceiling for this block height; cannot build a delegate action."
|
|
135
135
|
);
|
|
136
136
|
}
|
|
@@ -259,7 +259,7 @@ async function verifyAndSettleExactNear(input) {
|
|
|
259
259
|
if (/not enough|insufficient|exceeded the prepaid gas|NotEnoughBalance|doesn't have enough|is not registered/i.test(m)) {
|
|
260
260
|
return fail("tx_reverted", `the ft_transfer would fail on chain: ${shorten(m)}.`);
|
|
261
261
|
}
|
|
262
|
-
throw new (0,
|
|
262
|
+
throw new (0, _chunkQONQSZHJcjs.SettlementError)(
|
|
263
263
|
`NEAR exact settle: the relayer could not submit the delegate (${shorten(m)}). The buyer's signed delegate is still valid \u2014 fund/fix the relayer and the buyer can re-present it.`,
|
|
264
264
|
{ cause: err }
|
|
265
265
|
);
|
|
@@ -408,13 +408,13 @@ function txNotFound(hash) {
|
|
|
408
408
|
|
|
409
409
|
function assertNearWallet(wallet, network) {
|
|
410
410
|
if (typeof wallet !== "object" || wallet === null) {
|
|
411
|
-
throw new (0,
|
|
411
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
|
|
412
412
|
`chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
|
|
413
413
|
);
|
|
414
414
|
}
|
|
415
|
-
|
|
415
|
+
_chunkQONQSZHJcjs.assertNoLegacyWalletKey.call(void 0, wallet, "NEAR");
|
|
416
416
|
if (!("accountId" in wallet) || !("key" in wallet)) {
|
|
417
|
-
throw new (0,
|
|
417
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
|
|
418
418
|
`chain ${network} is NEAR; wallet must be { accountId, key } (key = ed25519:\u2026).`
|
|
419
419
|
);
|
|
420
420
|
}
|
|
@@ -422,13 +422,13 @@ function assertNearWallet(wallet, network) {
|
|
|
422
422
|
}
|
|
423
423
|
function resolveNearWallet(config) {
|
|
424
424
|
if (!config.accountId || !config.key) {
|
|
425
|
-
throw new (0,
|
|
425
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)("NEAR wallet needs { accountId, key } (key = ed25519:\u2026).");
|
|
426
426
|
}
|
|
427
427
|
let signer;
|
|
428
428
|
try {
|
|
429
429
|
signer = _nearapijs.KeyPairSigner.fromSecretKey(config.key);
|
|
430
430
|
} catch (cause) {
|
|
431
|
-
throw new (0,
|
|
431
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)("NEAR wallet { key } is not a valid ed25519:\u2026 secret key.", {
|
|
432
432
|
cause
|
|
433
433
|
});
|
|
434
434
|
}
|
|
@@ -490,16 +490,16 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
490
490
|
const info = preset.tokens[token.toUpperCase()];
|
|
491
491
|
if (!info) {
|
|
492
492
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
493
|
-
throw new (0,
|
|
493
|
+
throw new (0, _chunkQONQSZHJcjs.UnknownTokenError)(
|
|
494
494
|
`token "${token}" isn't built in for NEAR (known: ${known}). Pass { contractId, decimals } for a custom NEP-141.`
|
|
495
495
|
);
|
|
496
496
|
}
|
|
497
497
|
return { asset: info.contractId, decimals: info.decimals, symbol: info.symbol };
|
|
498
498
|
}
|
|
499
|
-
|
|
499
|
+
_chunkQONQSZHJcjs.rejectForeignToken.call(void 0, token, "near", network);
|
|
500
500
|
const t = token;
|
|
501
501
|
if (!t.contractId || typeof t.decimals !== "number") {
|
|
502
|
-
throw new (0,
|
|
502
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
|
|
503
503
|
`chain ${network} is NEAR; a custom token must be { contractId, decimals }.`
|
|
504
504
|
);
|
|
505
505
|
}
|
|
@@ -518,12 +518,12 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
518
518
|
},
|
|
519
519
|
assertValidPayTo(payTo) {
|
|
520
520
|
if (payTo.startsWith("0x")) {
|
|
521
|
-
throw new (0,
|
|
521
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
|
|
522
522
|
`chain ${network} is NEAR, but payTo "${payTo}" looks like an EVM/Sui 0x address.`
|
|
523
523
|
);
|
|
524
524
|
}
|
|
525
525
|
if (!isValidNearAccountId(payTo)) {
|
|
526
|
-
throw new (0,
|
|
526
|
+
throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
|
|
527
527
|
`chain ${network} is NEAR, but payTo "${payTo}" is not a valid NEAR account id.`
|
|
528
528
|
);
|
|
529
529
|
}
|
|
@@ -567,11 +567,11 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
567
567
|
if (tx && tx.success) return { height: "0" };
|
|
568
568
|
} catch (e11) {
|
|
569
569
|
}
|
|
570
|
-
throw new (0,
|
|
570
|
+
throw new (0, _chunkQONQSZHJcjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
|
|
571
571
|
},
|
|
572
572
|
async estimateCost(accept) {
|
|
573
573
|
if (accept.scheme === "exact") {
|
|
574
|
-
return
|
|
574
|
+
return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
|
|
575
575
|
symbol: "NEAR",
|
|
576
576
|
decimals: NEAR_DECIMALS,
|
|
577
577
|
fee: 0n,
|
|
@@ -579,7 +579,7 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
579
579
|
detail: "gasless \u2014 the relayer prepays gas + the 1 yocto; the buyer pays 0 NEAR"
|
|
580
580
|
});
|
|
581
581
|
}
|
|
582
|
-
return
|
|
582
|
+
return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
|
|
583
583
|
symbol: "NEAR",
|
|
584
584
|
decimals: NEAR_DECIMALS,
|
|
585
585
|
fee: 1500000000000000000000n,
|
|
@@ -701,7 +701,7 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
701
701
|
try {
|
|
702
702
|
relayerWallet = resolveNearWallet(relayer._native);
|
|
703
703
|
} catch (err) {
|
|
704
|
-
throw new (0,
|
|
704
|
+
throw new (0, _chunkQONQSZHJcjs.SettlementError)(
|
|
705
705
|
`NEAR exact settle: the relayer wallet is invalid (${err instanceof Error ? err.message : String(err)}).`,
|
|
706
706
|
{ cause: err }
|
|
707
707
|
);
|