@piprail/sdk 2.13.1 → 2.14.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 +109 -0
- package/dist/{algorand-AQK5EAUF.cjs → algorand-ICJNXO5V.cjs} +43 -42
- package/dist/{algorand-TQCYK2XT.js → algorand-RM7MP4PK.js} +12 -11
- package/dist/{aptos-RYQOSFBQ.js → aptos-2FIRTMQX.js} +11 -10
- package/dist/{aptos-65UX7GKA.cjs → aptos-MVEG5ZPS.cjs} +41 -40
- package/dist/{chunk-DCOUJZPL.cjs → chunk-57V5DNJT.cjs} +45 -19
- package/dist/{chunk-O32N6MFN.js → chunk-NUPCFNC5.js} +27 -1
- package/dist/index.cjs +503 -239
- package/dist/index.d.cts +279 -7
- package/dist/index.d.ts +279 -7
- package/dist/index.js +299 -35
- package/dist/{ledger-mF_SoiDB.d.ts → ledger-uFtXlIHY.d.cts} +31 -1
- package/dist/{ledger-mF_SoiDB.d.cts → ledger-uFtXlIHY.d.ts} +31 -1
- package/dist/{near-UDPFA6SV.cjs → near-C2IS4RCH.cjs} +39 -30
- package/dist/{near-VDATC5AV.js → near-L2OWD7M6.js} +14 -5
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{solana-RQNXFCZO.cjs → solana-B424IQ5I.cjs} +54 -39
- package/dist/{solana-VYLWFNAH.js → solana-V2TGLHJ4.js} +22 -7
- package/dist/{stellar-OK2HW5PZ.cjs → stellar-4YR4UZQX.cjs} +23 -23
- package/dist/{stellar-KBR4V77T.js → stellar-J7VE7QP7.js} +4 -4
- package/dist/{sui-SVFBJFW5.cjs → sui-F7UW6JXJ.cjs} +35 -27
- package/dist/{sui-BXHB6D3W.js → sui-GMRQAAJH.js} +20 -12
- package/dist/{ton-D7YN6BGR.cjs → ton-3SHFVDLP.cjs} +33 -22
- package/dist/{ton-NNKQFQ6U.js → ton-PEBYBNWJ.js} +18 -7
- package/dist/{tron-WZFU57NX.cjs → tron-BS5EID2U.cjs} +39 -39
- package/dist/{tron-W2D5PQXV.js → tron-ZYJHHROT.js} +10 -10
- package/dist/{xrpl-37E23W53.js → xrpl-P2D6TS6I.js} +13 -13
- package/dist/{xrpl-5NHY3NEL.cjs → xrpl-SUEFOOKW.cjs} +31 -31
- package/package.json +3 -2
|
@@ -10,7 +10,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunk57V5DNJTcjs = require('./chunk-57V5DNJT.cjs');
|
|
14
14
|
|
|
15
15
|
// src/drivers/tron/index.ts
|
|
16
16
|
var _tronweb = require('tronweb');
|
|
@@ -62,7 +62,7 @@ async function payTron(params) {
|
|
|
62
62
|
return _nullishCoalesce(_nullishCoalesce(broadcast.txid, () => ( _optionalChain([broadcast, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8.txID]))), () => ( signed.txID));
|
|
63
63
|
}
|
|
64
64
|
if (isTronAffordability(broadcast.code, broadcast.message)) {
|
|
65
|
-
throw new (0,
|
|
65
|
+
throw new (0, _chunk57V5DNJTcjs.InsufficientFundsError)(
|
|
66
66
|
`Tron payment rejected (${_nullishCoalesce(broadcast.code, () => ( "broadcast"))}): not enough TRX for energy/bandwidth, or insufficient token balance.`
|
|
67
67
|
);
|
|
68
68
|
}
|
|
@@ -70,15 +70,15 @@ async function payTron(params) {
|
|
|
70
70
|
`Tron broadcast failed: ${_nullishCoalesce(broadcast.code, () => ( ""))} ${decodeMaybeHex(broadcast.message)}`.trim()
|
|
71
71
|
);
|
|
72
72
|
} catch (err) {
|
|
73
|
-
if (err instanceof
|
|
74
|
-
throw _nullishCoalesce(
|
|
73
|
+
if (err instanceof _chunk57V5DNJTcjs.InsufficientFundsError) throw err;
|
|
74
|
+
throw _nullishCoalesce(_chunk57V5DNJTcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
async function payTronNative(params) {
|
|
78
78
|
const { client, from, privateKey, accept } = params;
|
|
79
79
|
const sun = BigInt(accept.amount);
|
|
80
80
|
if (sun > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
81
|
-
throw new (0,
|
|
81
|
+
throw new (0, _chunk57V5DNJTcjs.InsufficientFundsError)(
|
|
82
82
|
`Tron native amount ${accept.amount} sun exceeds the safe-integer range tronweb.sendTrx accepts \u2014 price this resource in a smaller native amount or a TRC-20 token.`
|
|
83
83
|
);
|
|
84
84
|
}
|
|
@@ -90,7 +90,7 @@ async function payTronNative(params) {
|
|
|
90
90
|
return _nullishCoalesce(_nullishCoalesce(broadcast.txid, () => ( _optionalChain([broadcast, 'access', _11 => _11.transaction, 'optionalAccess', _12 => _12.txID]))), () => ( signed.txID));
|
|
91
91
|
}
|
|
92
92
|
if (isTronAffordability(broadcast.code, broadcast.message)) {
|
|
93
|
-
throw new (0,
|
|
93
|
+
throw new (0, _chunk57V5DNJTcjs.InsufficientFundsError)(
|
|
94
94
|
`Tron TRX payment rejected (${_nullishCoalesce(broadcast.code, () => ( "broadcast"))}): not enough TRX for the amount plus bandwidth (and the ~1 TRX account-creation fee if the recipient is new).`
|
|
95
95
|
);
|
|
96
96
|
}
|
|
@@ -98,8 +98,8 @@ async function payTronNative(params) {
|
|
|
98
98
|
`Tron TRX broadcast failed: ${_nullishCoalesce(broadcast.code, () => ( ""))} ${decodeMaybeHex(broadcast.message)}`.trim()
|
|
99
99
|
);
|
|
100
100
|
} catch (err) {
|
|
101
|
-
if (err instanceof
|
|
102
|
-
throw _nullishCoalesce(
|
|
101
|
+
if (err instanceof _chunk57V5DNJTcjs.InsufficientFundsError) throw err;
|
|
102
|
+
throw _nullishCoalesce(_chunk57V5DNJTcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
function decodeMaybeHex(message) {
|
|
@@ -141,11 +141,11 @@ async function verifyTron(params) {
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(info.blockTimeStamp / 1e3);
|
|
144
|
-
if (Number.isFinite(ageSeconds)
|
|
144
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
145
145
|
return {
|
|
146
146
|
ok: false,
|
|
147
147
|
error: "payment_expired",
|
|
148
|
-
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
148
|
+
detail: Number.isFinite(ageSeconds) ? `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.` : `Cannot determine the age of ${txid} (no blockTimeStamp) \u2014 fail closed.`
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
const { total, from } = sumTransfersTo(_nullishCoalesce(info.log, () => ( [])), tokenHex20, payToHex20);
|
|
@@ -181,12 +181,15 @@ async function verifyTronNative(params) {
|
|
|
181
181
|
return txNotFound(txid);
|
|
182
182
|
}
|
|
183
183
|
if (!info || !info.id) return txNotFound(txid);
|
|
184
|
+
if (_optionalChain([info, 'access', _17 => _17.receipt, 'optionalAccess', _18 => _18.result]) && info.receipt.result !== "SUCCESS") {
|
|
185
|
+
return { ok: false, error: "tx_reverted", detail: `Tron tx ${txid} did not succeed (receipt.result=${info.receipt.result}).` };
|
|
186
|
+
}
|
|
184
187
|
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(info.blockTimeStamp / 1e3);
|
|
185
|
-
if (Number.isFinite(ageSeconds)
|
|
188
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
186
189
|
return {
|
|
187
190
|
ok: false,
|
|
188
191
|
error: "payment_expired",
|
|
189
|
-
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
192
|
+
detail: Number.isFinite(ageSeconds) ? `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.` : `Cannot determine the age of ${txid} (no blockTimeStamp) \u2014 fail closed.`
|
|
190
193
|
};
|
|
191
194
|
}
|
|
192
195
|
let tx;
|
|
@@ -196,11 +199,11 @@ async function verifyTronNative(params) {
|
|
|
196
199
|
return txNotFound(txid);
|
|
197
200
|
}
|
|
198
201
|
if (!tx) return txNotFound(txid);
|
|
199
|
-
const ret = _optionalChain([tx, 'access',
|
|
202
|
+
const ret = _optionalChain([tx, 'access', _19 => _19.ret, 'optionalAccess', _20 => _20[0], 'optionalAccess', _21 => _21.contractRet]);
|
|
200
203
|
if (ret && ret !== "SUCCESS") {
|
|
201
204
|
return { ok: false, error: "tx_reverted", detail: `Tron tx ${txid} did not succeed (contractRet=${ret}).` };
|
|
202
205
|
}
|
|
203
|
-
const contract = (_nullishCoalesce(_optionalChain([tx, 'access',
|
|
206
|
+
const contract = (_nullishCoalesce(_optionalChain([tx, 'access', _22 => _22.raw_data, 'optionalAccess', _23 => _23.contract]), () => ( [])))[0];
|
|
204
207
|
if (!contract || contract.type !== "TransferContract") {
|
|
205
208
|
return {
|
|
206
209
|
ok: false,
|
|
@@ -208,7 +211,7 @@ async function verifyTronNative(params) {
|
|
|
208
211
|
detail: `Tron tx ${txid} is not a native TRX transfer (TransferContract).`
|
|
209
212
|
};
|
|
210
213
|
}
|
|
211
|
-
const value = _nullishCoalesce(_optionalChain([contract, 'access',
|
|
214
|
+
const value = _nullishCoalesce(_optionalChain([contract, 'access', _24 => _24.parameter, 'optionalAccess', _25 => _25.value]), () => ( {}));
|
|
212
215
|
const to = String(_nullishCoalesce(value.to_address, () => ( ""))).toLowerCase().replace(/^0x/, "");
|
|
213
216
|
if (to !== payToHex41) {
|
|
214
217
|
return { ok: false, error: "wrong_recipient", detail: `Native TRX in ${txid} was not sent to ${accept.payTo}.` };
|
|
@@ -270,13 +273,13 @@ function txNotFound(txid) {
|
|
|
270
273
|
// src/drivers/tron/wallet.ts
|
|
271
274
|
function assertTronWallet(wallet, network) {
|
|
272
275
|
if (typeof wallet !== "object" || wallet === null) {
|
|
273
|
-
throw new (0,
|
|
276
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
274
277
|
`chain ${network} is Tron; wallet must be { key } (32-byte hex).`
|
|
275
278
|
);
|
|
276
279
|
}
|
|
277
|
-
|
|
280
|
+
_chunk57V5DNJTcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Tron");
|
|
278
281
|
if (!("key" in wallet)) {
|
|
279
|
-
throw new (0,
|
|
282
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
280
283
|
`chain ${network} is Tron; wallet must be { key } (32-byte hex).`
|
|
281
284
|
);
|
|
282
285
|
}
|
|
@@ -284,14 +287,14 @@ function assertTronWallet(wallet, network) {
|
|
|
284
287
|
}
|
|
285
288
|
function resolveTronPrivateKey(config) {
|
|
286
289
|
if (!config.key) {
|
|
287
|
-
throw new (0,
|
|
290
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)("Tron wallet needs { key } (32-byte hex).");
|
|
288
291
|
}
|
|
289
292
|
if (typeof config.key !== "string") {
|
|
290
|
-
throw new (0,
|
|
293
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)("Tron wallet { key } must be a 32-byte hex string.");
|
|
291
294
|
}
|
|
292
295
|
const hex = config.key.replace(/^0x/i, "").toLowerCase();
|
|
293
296
|
if (!/^[0-9a-f]{64}$/.test(hex)) {
|
|
294
|
-
throw new (0,
|
|
297
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
295
298
|
"Tron wallet { key } must be a 32-byte hex string (64 hex chars)."
|
|
296
299
|
);
|
|
297
300
|
}
|
|
@@ -341,21 +344,21 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
341
344
|
const info = preset.tokens[token.toUpperCase()];
|
|
342
345
|
if (!info) {
|
|
343
346
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
344
|
-
throw new (0,
|
|
347
|
+
throw new (0, _chunk57V5DNJTcjs.UnknownTokenError)(
|
|
345
348
|
`token "${token}" isn't built in for Tron (known: ${known}). Note: native USDC doesn't exist on Tron. Pass { address, decimals } for a custom TRC-20.`
|
|
346
349
|
);
|
|
347
350
|
}
|
|
348
351
|
return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
|
|
349
352
|
}
|
|
350
|
-
|
|
353
|
+
_chunk57V5DNJTcjs.rejectForeignToken.call(void 0, token, "tron", network);
|
|
351
354
|
if (!("address" in token)) {
|
|
352
|
-
throw new (0,
|
|
355
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
353
356
|
`chain ${network} is Tron; a custom token must be { address, decimals } (Base58 T\u2026 contract).`
|
|
354
357
|
);
|
|
355
358
|
}
|
|
356
359
|
const t = token;
|
|
357
360
|
if (t.address.startsWith("0x") || !tronWeb.isAddress(t.address)) {
|
|
358
|
-
throw new (0,
|
|
361
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
359
362
|
`chain ${network} is Tron, but token address "${t.address}" is not a valid Tron contract (T\u2026).`
|
|
360
363
|
);
|
|
361
364
|
}
|
|
@@ -374,12 +377,12 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
374
377
|
},
|
|
375
378
|
assertValidPayTo(payTo) {
|
|
376
379
|
if (payTo.startsWith("0x")) {
|
|
377
|
-
throw new (0,
|
|
380
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
378
381
|
`chain ${network} is Tron, but payTo "${payTo}" looks like an EVM address.`
|
|
379
382
|
);
|
|
380
383
|
}
|
|
381
384
|
if (!tronWeb.isAddress(payTo)) {
|
|
382
|
-
throw new (0,
|
|
385
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
383
386
|
`chain ${network} is Tron, but payTo "${payTo}" is not a valid Tron address (T\u2026).`
|
|
384
387
|
);
|
|
385
388
|
}
|
|
@@ -391,7 +394,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
391
394
|
const privateKey = resolveTronPrivateKey(wallet._native);
|
|
392
395
|
const from = tronWeb.address.fromPrivateKey(privateKey);
|
|
393
396
|
if (!from) {
|
|
394
|
-
throw new (0,
|
|
397
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)("Tron wallet { key } could not derive an address.");
|
|
395
398
|
}
|
|
396
399
|
if (accept.asset === "native") {
|
|
397
400
|
return payTronNative({ client: tronWeb, from, privateKey, accept });
|
|
@@ -405,7 +408,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
405
408
|
});
|
|
406
409
|
},
|
|
407
410
|
async confirm(ref) {
|
|
408
|
-
const txid =
|
|
411
|
+
const txid = ref;
|
|
409
412
|
for (let i = 0; i < 30; i += 1) {
|
|
410
413
|
try {
|
|
411
414
|
const info = await reader.getTransactionInfo(txid);
|
|
@@ -414,11 +417,11 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
414
417
|
}
|
|
415
418
|
await _chunkCQREG5LEcjs.delay.call(void 0, 2500);
|
|
416
419
|
}
|
|
417
|
-
throw new (0,
|
|
420
|
+
throw new (0, _chunk57V5DNJTcjs.ConfirmationTimeoutError)(`Tron tx ${txid} did not solidify in time.`);
|
|
418
421
|
},
|
|
419
422
|
async estimateCost(accept, opts) {
|
|
420
423
|
if (accept.asset === "native") {
|
|
421
|
-
return
|
|
424
|
+
return _chunk57V5DNJTcjs.nativeCost.call(void 0, {
|
|
422
425
|
symbol: "TRX",
|
|
423
426
|
decimals: TRX_DECIMALS,
|
|
424
427
|
fee: 1300000n,
|
|
@@ -428,7 +431,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
428
431
|
}
|
|
429
432
|
const ENERGY_PRICE = 420n;
|
|
430
433
|
const BANDWIDTH_SUN = 345000n;
|
|
431
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
434
|
+
if (_optionalChain([opts, 'optionalAccess', _26 => _26.from])) {
|
|
432
435
|
try {
|
|
433
436
|
const r = await tronWeb.transactionBuilder.triggerConstantContract(
|
|
434
437
|
accept.asset,
|
|
@@ -442,7 +445,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
442
445
|
);
|
|
443
446
|
const energy = BigInt(_nullishCoalesce(r.energy_used, () => ( 0)));
|
|
444
447
|
if (energy > 0n) {
|
|
445
|
-
return
|
|
448
|
+
return _chunk57V5DNJTcjs.nativeCost.call(void 0, {
|
|
446
449
|
symbol: "TRX",
|
|
447
450
|
decimals: TRX_DECIMALS,
|
|
448
451
|
fee: energy * ENERGY_PRICE + BANDWIDTH_SUN,
|
|
@@ -453,7 +456,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
453
456
|
} catch (e8) {
|
|
454
457
|
}
|
|
455
458
|
}
|
|
456
|
-
return
|
|
459
|
+
return _chunk57V5DNJTcjs.nativeCost.call(void 0, {
|
|
457
460
|
symbol: "TRX",
|
|
458
461
|
decimals: TRX_DECIMALS,
|
|
459
462
|
fee: 30000n * ENERGY_PRICE + BANDWIDTH_SUN,
|
|
@@ -478,7 +481,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
478
481
|
[{ type: "address", value: owner }],
|
|
479
482
|
owner
|
|
480
483
|
);
|
|
481
|
-
const hex = _optionalChain([res, 'optionalAccess',
|
|
484
|
+
const hex = _optionalChain([res, 'optionalAccess', _27 => _27.constant_result, 'optionalAccess', _28 => _28[0]]);
|
|
482
485
|
token = hex == null ? null : BigInt("0x" + hex);
|
|
483
486
|
} catch (e9) {
|
|
484
487
|
token = null;
|
|
@@ -490,7 +493,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
490
493
|
return { ready: "n/a" };
|
|
491
494
|
},
|
|
492
495
|
async verify(ref, accept) {
|
|
493
|
-
const txid =
|
|
496
|
+
const txid = ref;
|
|
494
497
|
if (accept.asset === "native") {
|
|
495
498
|
return verifyTronNative({
|
|
496
499
|
reader,
|
|
@@ -511,9 +514,6 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
511
514
|
}
|
|
512
515
|
};
|
|
513
516
|
}
|
|
514
|
-
function stripTronPrefix(ref) {
|
|
515
|
-
return ref.startsWith("tron:") ? ref.slice(5) : ref;
|
|
516
|
-
}
|
|
517
517
|
|
|
518
518
|
|
|
519
519
|
exports.tronDriver = tronDriver;
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
nativeCost,
|
|
11
11
|
rejectForeignToken,
|
|
12
12
|
toInsufficientFundsError
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-NUPCFNC5.js";
|
|
14
14
|
|
|
15
15
|
// src/drivers/tron/index.ts
|
|
16
16
|
import { TronWeb } from "tronweb";
|
|
@@ -141,11 +141,11 @@ async function verifyTron(params) {
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(info.blockTimeStamp / 1e3);
|
|
144
|
-
if (Number.isFinite(ageSeconds)
|
|
144
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
145
145
|
return {
|
|
146
146
|
ok: false,
|
|
147
147
|
error: "payment_expired",
|
|
148
|
-
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
148
|
+
detail: Number.isFinite(ageSeconds) ? `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.` : `Cannot determine the age of ${txid} (no blockTimeStamp) \u2014 fail closed.`
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
const { total, from } = sumTransfersTo(info.log ?? [], tokenHex20, payToHex20);
|
|
@@ -181,12 +181,15 @@ async function verifyTronNative(params) {
|
|
|
181
181
|
return txNotFound(txid);
|
|
182
182
|
}
|
|
183
183
|
if (!info || !info.id) return txNotFound(txid);
|
|
184
|
+
if (info.receipt?.result && info.receipt.result !== "SUCCESS") {
|
|
185
|
+
return { ok: false, error: "tx_reverted", detail: `Tron tx ${txid} did not succeed (receipt.result=${info.receipt.result}).` };
|
|
186
|
+
}
|
|
184
187
|
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(info.blockTimeStamp / 1e3);
|
|
185
|
-
if (Number.isFinite(ageSeconds)
|
|
188
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
186
189
|
return {
|
|
187
190
|
ok: false,
|
|
188
191
|
error: "payment_expired",
|
|
189
|
-
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
192
|
+
detail: Number.isFinite(ageSeconds) ? `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.` : `Cannot determine the age of ${txid} (no blockTimeStamp) \u2014 fail closed.`
|
|
190
193
|
};
|
|
191
194
|
}
|
|
192
195
|
let tx;
|
|
@@ -405,7 +408,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
405
408
|
});
|
|
406
409
|
},
|
|
407
410
|
async confirm(ref) {
|
|
408
|
-
const txid =
|
|
411
|
+
const txid = ref;
|
|
409
412
|
for (let i = 0; i < 30; i += 1) {
|
|
410
413
|
try {
|
|
411
414
|
const info = await reader.getTransactionInfo(txid);
|
|
@@ -490,7 +493,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
490
493
|
return { ready: "n/a" };
|
|
491
494
|
},
|
|
492
495
|
async verify(ref, accept) {
|
|
493
|
-
const txid =
|
|
496
|
+
const txid = ref;
|
|
494
497
|
if (accept.asset === "native") {
|
|
495
498
|
return verifyTronNative({
|
|
496
499
|
reader,
|
|
@@ -511,9 +514,6 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
511
514
|
}
|
|
512
515
|
};
|
|
513
516
|
}
|
|
514
|
-
function stripTronPrefix(ref) {
|
|
515
|
-
return ref.startsWith("tron:") ? ref.slice(5) : ref;
|
|
516
|
-
}
|
|
517
517
|
export {
|
|
518
518
|
tronDriver
|
|
519
519
|
};
|
|
@@ -10,10 +10,9 @@ import {
|
|
|
10
10
|
assertNoLegacyWalletKey,
|
|
11
11
|
floorUnits,
|
|
12
12
|
nativeCost,
|
|
13
|
-
parseUnits,
|
|
14
13
|
rejectForeignToken,
|
|
15
14
|
toInsufficientFundsError
|
|
16
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-NUPCFNC5.js";
|
|
17
16
|
|
|
18
17
|
// src/drivers/xrpl/index.ts
|
|
19
18
|
import { isValidClassicAddress } from "xrpl";
|
|
@@ -152,7 +151,7 @@ async function verifyXrpl(params) {
|
|
|
152
151
|
const wantAsset = parseXrplAssetId(accept.asset);
|
|
153
152
|
let txs;
|
|
154
153
|
try {
|
|
155
|
-
txs = await reader.transactionsForAccount(accept.payTo,
|
|
154
|
+
txs = await reader.transactionsForAccount(accept.payTo, 200);
|
|
156
155
|
} catch {
|
|
157
156
|
return rpcFailed(nonce);
|
|
158
157
|
}
|
|
@@ -174,15 +173,16 @@ async function verifyXrpl(params) {
|
|
|
174
173
|
detail: `XRPL tx ${tx.hash} for nonce ${nonce} failed on-ledger (${tx.result}).`
|
|
175
174
|
};
|
|
176
175
|
}
|
|
177
|
-
if (typeof tx.date
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
if (typeof tx.date !== "number") {
|
|
177
|
+
return { ok: false, error: "payment_expired", detail: `Cannot determine the age of ${tx.hash} (no ledger date) \u2014 fail closed.` };
|
|
178
|
+
}
|
|
179
|
+
const ageSeconds = Math.floor(Date.now() / 1e3) - (tx.date + RIPPLE_EPOCH_OFFSET);
|
|
180
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
error: "payment_expired",
|
|
184
|
+
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
185
|
+
};
|
|
186
186
|
}
|
|
187
187
|
const paid = deliveredBaseUnits(tx.delivered_amount, wantAsset, accept.extra.decimals);
|
|
188
188
|
if (paid === null) {
|
|
@@ -463,7 +463,7 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
463
463
|
const line = r.lines.find(
|
|
464
464
|
(l) => l.currency.toUpperCase() === (currencyHex ?? "").toUpperCase() && l.account === issuer
|
|
465
465
|
);
|
|
466
|
-
token = line ?
|
|
466
|
+
token = line ? floorUnits(line.balance, XRP_DECIMALS) : 0n;
|
|
467
467
|
} catch (e) {
|
|
468
468
|
token = isXrplActNotFound(e) ? 0n : null;
|
|
469
469
|
}
|
|
@@ -12,8 +12,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
var _chunkDCOUJZPLcjs = require('./chunk-DCOUJZPL.cjs');
|
|
15
|
+
var _chunk57V5DNJTcjs = require('./chunk-57V5DNJT.cjs');
|
|
17
16
|
|
|
18
17
|
// src/drivers/xrpl/index.ts
|
|
19
18
|
var _xrpl = require('xrpl');
|
|
@@ -95,17 +94,17 @@ async function payXrpl(params) {
|
|
|
95
94
|
const code = res.engine_result;
|
|
96
95
|
if (code.startsWith("tes")) return _nullishCoalesce(_optionalChain([res, 'access', _ => _.tx_json, 'optionalAccess', _2 => _2.hash]), () => ( signed.hash));
|
|
97
96
|
const recipientMsg = recipientNotReadyMessage(code);
|
|
98
|
-
if (recipientMsg) throw new (0,
|
|
97
|
+
if (recipientMsg) throw new (0, _chunk57V5DNJTcjs.RecipientNotReadyError)(recipientMsg, { cause: makeEngineError(res) });
|
|
99
98
|
if (isAffordabilityCode(code)) {
|
|
100
|
-
throw new (0,
|
|
99
|
+
throw new (0, _chunk57V5DNJTcjs.InsufficientFundsError)(
|
|
101
100
|
`XRPL payment rejected: the sender can't cover it \u2014 balance or the 1 XRP base reserve. (XRPL: ${code})`,
|
|
102
101
|
{ cause: makeEngineError(res) }
|
|
103
102
|
);
|
|
104
103
|
}
|
|
105
104
|
throw makeEngineError(res);
|
|
106
105
|
} catch (err) {
|
|
107
|
-
if (err instanceof
|
|
108
|
-
throw _nullishCoalesce(
|
|
106
|
+
if (err instanceof _chunk57V5DNJTcjs.InsufficientFundsError || err instanceof _chunk57V5DNJTcjs.RecipientNotReadyError) throw err;
|
|
107
|
+
throw _nullishCoalesce(_chunk57V5DNJTcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
function amountForAccept(accept) {
|
|
@@ -152,7 +151,7 @@ async function verifyXrpl(params) {
|
|
|
152
151
|
const wantAsset = parseXrplAssetId(accept.asset);
|
|
153
152
|
let txs;
|
|
154
153
|
try {
|
|
155
|
-
txs = await reader.transactionsForAccount(accept.payTo,
|
|
154
|
+
txs = await reader.transactionsForAccount(accept.payTo, 200);
|
|
156
155
|
} catch (e2) {
|
|
157
156
|
return rpcFailed(nonce);
|
|
158
157
|
}
|
|
@@ -174,15 +173,16 @@ async function verifyXrpl(params) {
|
|
|
174
173
|
detail: `XRPL tx ${tx.hash} for nonce ${nonce} failed on-ledger (${tx.result}).`
|
|
175
174
|
};
|
|
176
175
|
}
|
|
177
|
-
if (typeof tx.date
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
if (typeof tx.date !== "number") {
|
|
177
|
+
return { ok: false, error: "payment_expired", detail: `Cannot determine the age of ${tx.hash} (no ledger date) \u2014 fail closed.` };
|
|
178
|
+
}
|
|
179
|
+
const ageSeconds = Math.floor(Date.now() / 1e3) - (tx.date + RIPPLE_EPOCH_OFFSET);
|
|
180
|
+
if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
error: "payment_expired",
|
|
184
|
+
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
185
|
+
};
|
|
186
186
|
}
|
|
187
187
|
const paid = deliveredBaseUnits(tx.delivered_amount, wantAsset, accept.extra.decimals);
|
|
188
188
|
if (paid === null) {
|
|
@@ -230,7 +230,7 @@ function deliveredBaseUnits(delivered, want, decimals) {
|
|
|
230
230
|
return null;
|
|
231
231
|
}
|
|
232
232
|
try {
|
|
233
|
-
return
|
|
233
|
+
return _chunk57V5DNJTcjs.floorUnits.call(void 0, delivered.value, decimals);
|
|
234
234
|
} catch (e3) {
|
|
235
235
|
return null;
|
|
236
236
|
}
|
|
@@ -254,13 +254,13 @@ function rpcFailed(nonce) {
|
|
|
254
254
|
|
|
255
255
|
function assertXrplWallet(wallet, network) {
|
|
256
256
|
if (typeof wallet !== "object" || wallet === null) {
|
|
257
|
-
throw new (0,
|
|
257
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
258
258
|
`chain ${network} is XRPL; wallet must be { key } (s\u2026 seed) or { wallet }.`
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
_chunk57V5DNJTcjs.assertNoLegacyWalletKey.call(void 0, wallet, "XRPL");
|
|
262
262
|
if (!("key" in wallet) && !("wallet" in wallet)) {
|
|
263
|
-
throw new (0,
|
|
263
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
264
264
|
`chain ${network} is XRPL; wallet must be { key } (s\u2026 seed) or { wallet }.`
|
|
265
265
|
);
|
|
266
266
|
}
|
|
@@ -270,11 +270,11 @@ function resolveXrplWallet(config) {
|
|
|
270
270
|
if (config.wallet) return config.wallet;
|
|
271
271
|
if (config.key) {
|
|
272
272
|
if (!_xrpl.isValidSecret.call(void 0, config.key)) {
|
|
273
|
-
throw new (0,
|
|
273
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)("XRPL wallet { key } is not a valid s\u2026 secret seed.");
|
|
274
274
|
}
|
|
275
275
|
return _xrpl.Wallet.fromSeed(config.key);
|
|
276
276
|
}
|
|
277
|
-
throw new (0,
|
|
277
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)("XRPL wallet needs { key } (s\u2026 seed) or { wallet }.");
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
// src/drivers/xrpl/index.ts
|
|
@@ -349,7 +349,7 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
349
349
|
const info = preset.tokens[token.toUpperCase()];
|
|
350
350
|
if (!info) {
|
|
351
351
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
352
|
-
throw new (0,
|
|
352
|
+
throw new (0, _chunk57V5DNJTcjs.UnknownTokenError)(
|
|
353
353
|
`token "${token}" isn't built in for XRPL (known: ${known}). Pass { issuer, currencyHex, decimals } for a custom IOU, or use 'native'.`
|
|
354
354
|
);
|
|
355
355
|
}
|
|
@@ -359,10 +359,10 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
359
359
|
symbol: info.symbol
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
-
|
|
362
|
+
_chunk57V5DNJTcjs.rejectForeignToken.call(void 0, token, "xrpl", network);
|
|
363
363
|
const t = token;
|
|
364
364
|
if (!t.issuer || !t.currencyHex || typeof t.decimals !== "number") {
|
|
365
|
-
throw new (0,
|
|
365
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
366
366
|
`chain ${network} is XRPL; a custom token must be { issuer, currencyHex, decimals }.`
|
|
367
367
|
);
|
|
368
368
|
}
|
|
@@ -383,12 +383,12 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
383
383
|
},
|
|
384
384
|
assertValidPayTo(payTo) {
|
|
385
385
|
if (payTo.startsWith("0x")) {
|
|
386
|
-
throw new (0,
|
|
386
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
387
387
|
`chain ${network} is XRPL, but payTo "${payTo}" looks like an EVM address.`
|
|
388
388
|
);
|
|
389
389
|
}
|
|
390
390
|
if (!_xrpl.isValidClassicAddress.call(void 0, payTo)) {
|
|
391
|
-
throw new (0,
|
|
391
|
+
throw new (0, _chunk57V5DNJTcjs.WrongFamilyError)(
|
|
392
392
|
`chain ${network} is XRPL, but payTo "${payTo}" is not a valid XRPL account (r\u2026).`
|
|
393
393
|
);
|
|
394
394
|
}
|
|
@@ -411,14 +411,14 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
411
411
|
}
|
|
412
412
|
await _chunkCQREG5LEcjs.delay.call(void 0, 1500);
|
|
413
413
|
}
|
|
414
|
-
throw new (0,
|
|
414
|
+
throw new (0, _chunk57V5DNJTcjs.ConfirmationTimeoutError)(`XRPL tx ${ref} not validated on-ledger in time.`);
|
|
415
415
|
},
|
|
416
416
|
async estimateCost() {
|
|
417
417
|
try {
|
|
418
418
|
const drops = await payClient.feeDrops();
|
|
419
419
|
const n = Number(drops);
|
|
420
420
|
const fee = BigInt(Number.isFinite(n) && n > 12 ? Math.ceil(n) : 12);
|
|
421
|
-
return
|
|
421
|
+
return _chunk57V5DNJTcjs.nativeCost.call(void 0, {
|
|
422
422
|
symbol: XRP_SYMBOL,
|
|
423
423
|
decimals: XRP_DECIMALS,
|
|
424
424
|
fee,
|
|
@@ -426,7 +426,7 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
426
426
|
detail: `network fee ${fee} drops`
|
|
427
427
|
});
|
|
428
428
|
} catch (e5) {
|
|
429
|
-
return
|
|
429
|
+
return _chunk57V5DNJTcjs.nativeCost.call(void 0, {
|
|
430
430
|
symbol: XRP_SYMBOL,
|
|
431
431
|
decimals: XRP_DECIMALS,
|
|
432
432
|
fee: 12n,
|
|
@@ -463,7 +463,7 @@ function makeXrplNetwork(preset, rpcUrl) {
|
|
|
463
463
|
const line = r.lines.find(
|
|
464
464
|
(l) => l.currency.toUpperCase() === (_nullishCoalesce(currencyHex, () => ( ""))).toUpperCase() && l.account === issuer
|
|
465
465
|
);
|
|
466
|
-
token = line ?
|
|
466
|
+
token = line ? _chunk57V5DNJTcjs.floorUnits.call(void 0, line.balance, XRP_DECIMALS) : 0n;
|
|
467
467
|
} catch (e) {
|
|
468
468
|
token = isXrplActNotFound(e) ? 0n : null;
|
|
469
469
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@piprail/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "Accept x402 crypto payments across 29 chains — every major EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Algorand, Stellar & XRPL — in a couple of lines. No backend, no database, no fee; payments settle straight to your wallet.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"types": "./dist/node.d.cts",
|
|
27
27
|
"default": "./dist/node.cjs"
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
30
31
|
},
|
|
31
32
|
"files": [
|
|
32
33
|
"dist",
|