@piprail/sdk 2.7.0 → 2.8.0
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 +34 -0
- package/dist/{algorand-TMA62DN2.cjs → algorand-EKD34T4Q.cjs} +32 -32
- package/dist/{algorand-WB6PBJU4.js → algorand-WJL6VRXW.js} +1 -1
- package/dist/{aptos-JQMZNTMD.cjs → aptos-CVHLVMAF.cjs} +31 -31
- package/dist/{aptos-QAAXIUY3.js → aptos-WMPFEASY.js} +1 -1
- package/dist/{chunk-JG6KRAW6.cjs → chunk-VPENSVOI.cjs} +8 -0
- package/dist/{chunk-7XK22JSQ.js → chunk-W3HOMXOF.js} +8 -0
- package/dist/index.cjs +106 -101
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -11
- package/dist/{near-H5AQ253I.cjs → near-NYFMX2KA.cjs} +26 -26
- package/dist/{near-OTPQD6BI.js → near-QV4IOZNX.js} +1 -1
- package/dist/{solana-M3VOHCMO.cjs → solana-L342QCSV.cjs} +64 -33
- package/dist/{solana-3FMCWSEE.js → solana-Z34OWXMO.js} +33 -2
- package/dist/{stellar-U5NCRIOJ.js → stellar-PWC4LETJ.js} +1 -1
- package/dist/{stellar-FW6C6FBE.cjs → stellar-YEXRVR3W.cjs} +20 -20
- package/dist/{sui-47C2KEZI.cjs → sui-EFRSCDWN.cjs} +16 -16
- package/dist/{sui-Y53M4GUM.js → sui-VEOGHBYE.js} +1 -1
- package/dist/{ton-MMPKWT6N.cjs → ton-LZKJWYHV.cjs} +25 -21
- package/dist/{ton-5ZPT5PSP.js → ton-N7KSPSAR.js} +11 -7
- package/dist/{tron-JOT4STIG.cjs → tron-DQU4WTGQ.cjs} +24 -24
- package/dist/{tron-WYS4X2I5.js → tron-WKDUQVZR.js} +1 -1
- package/dist/{xrpl-2MZEOIFY.js → xrpl-6B4IYRWI.js} +1 -1
- package/dist/{xrpl-PECT4IMX.cjs → xrpl-K3U3SBF4.cjs} +20 -20
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.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, _chunkVPENSVOIcjs.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,8 +70,8 @@ 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 _chunkVPENSVOIcjs.InsufficientFundsError) throw err;
|
|
74
|
+
throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
async function payTronNative(params) {
|
|
@@ -84,7 +84,7 @@ async function payTronNative(params) {
|
|
|
84
84
|
return _nullishCoalesce(_nullishCoalesce(broadcast.txid, () => ( _optionalChain([broadcast, 'access', _11 => _11.transaction, 'optionalAccess', _12 => _12.txID]))), () => ( signed.txID));
|
|
85
85
|
}
|
|
86
86
|
if (isTronAffordability(broadcast.code, broadcast.message)) {
|
|
87
|
-
throw new (0,
|
|
87
|
+
throw new (0, _chunkVPENSVOIcjs.InsufficientFundsError)(
|
|
88
88
|
`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).`
|
|
89
89
|
);
|
|
90
90
|
}
|
|
@@ -92,8 +92,8 @@ async function payTronNative(params) {
|
|
|
92
92
|
`Tron TRX broadcast failed: ${_nullishCoalesce(broadcast.code, () => ( ""))} ${decodeMaybeHex(broadcast.message)}`.trim()
|
|
93
93
|
);
|
|
94
94
|
} catch (err) {
|
|
95
|
-
if (err instanceof
|
|
96
|
-
throw _nullishCoalesce(
|
|
95
|
+
if (err instanceof _chunkVPENSVOIcjs.InsufficientFundsError) throw err;
|
|
96
|
+
throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
function decodeMaybeHex(message) {
|
|
@@ -264,13 +264,13 @@ function txNotFound(txid) {
|
|
|
264
264
|
// src/drivers/tron/wallet.ts
|
|
265
265
|
function assertTronWallet(wallet, network) {
|
|
266
266
|
if (typeof wallet !== "object" || wallet === null) {
|
|
267
|
-
throw new (0,
|
|
267
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
268
268
|
`chain ${network} is Tron; wallet must be { key } (32-byte hex).`
|
|
269
269
|
);
|
|
270
270
|
}
|
|
271
|
-
|
|
271
|
+
_chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Tron");
|
|
272
272
|
if (!("key" in wallet)) {
|
|
273
|
-
throw new (0,
|
|
273
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
274
274
|
`chain ${network} is Tron; wallet must be { key } (32-byte hex).`
|
|
275
275
|
);
|
|
276
276
|
}
|
|
@@ -278,14 +278,14 @@ function assertTronWallet(wallet, network) {
|
|
|
278
278
|
}
|
|
279
279
|
function resolveTronPrivateKey(config) {
|
|
280
280
|
if (!config.key) {
|
|
281
|
-
throw new (0,
|
|
281
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("Tron wallet needs { key } (32-byte hex).");
|
|
282
282
|
}
|
|
283
283
|
if (typeof config.key !== "string") {
|
|
284
|
-
throw new (0,
|
|
284
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("Tron wallet { key } must be a 32-byte hex string.");
|
|
285
285
|
}
|
|
286
286
|
const hex = config.key.replace(/^0x/i, "").toLowerCase();
|
|
287
287
|
if (!/^[0-9a-f]{64}$/.test(hex)) {
|
|
288
|
-
throw new (0,
|
|
288
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
289
289
|
"Tron wallet { key } must be a 32-byte hex string (64 hex chars)."
|
|
290
290
|
);
|
|
291
291
|
}
|
|
@@ -335,21 +335,21 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
335
335
|
const info = preset.tokens[token.toUpperCase()];
|
|
336
336
|
if (!info) {
|
|
337
337
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
338
|
-
throw new (0,
|
|
338
|
+
throw new (0, _chunkVPENSVOIcjs.UnknownTokenError)(
|
|
339
339
|
`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.`
|
|
340
340
|
);
|
|
341
341
|
}
|
|
342
342
|
return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
_chunkVPENSVOIcjs.rejectForeignToken.call(void 0, token, "tron", network);
|
|
345
345
|
if (!("address" in token)) {
|
|
346
|
-
throw new (0,
|
|
346
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
347
347
|
`chain ${network} is Tron; a custom token must be { address, decimals } (Base58 T\u2026 contract).`
|
|
348
348
|
);
|
|
349
349
|
}
|
|
350
350
|
const t = token;
|
|
351
351
|
if (t.address.startsWith("0x") || !tronWeb.isAddress(t.address)) {
|
|
352
|
-
throw new (0,
|
|
352
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
353
353
|
`chain ${network} is Tron, but token address "${t.address}" is not a valid Tron contract (T\u2026).`
|
|
354
354
|
);
|
|
355
355
|
}
|
|
@@ -368,12 +368,12 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
368
368
|
},
|
|
369
369
|
assertValidPayTo(payTo) {
|
|
370
370
|
if (payTo.startsWith("0x")) {
|
|
371
|
-
throw new (0,
|
|
371
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
372
372
|
`chain ${network} is Tron, but payTo "${payTo}" looks like an EVM address.`
|
|
373
373
|
);
|
|
374
374
|
}
|
|
375
375
|
if (!tronWeb.isAddress(payTo)) {
|
|
376
|
-
throw new (0,
|
|
376
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
377
377
|
`chain ${network} is Tron, but payTo "${payTo}" is not a valid Tron address (T\u2026).`
|
|
378
378
|
);
|
|
379
379
|
}
|
|
@@ -385,7 +385,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
385
385
|
const privateKey = resolveTronPrivateKey(wallet._native);
|
|
386
386
|
const from = tronWeb.address.fromPrivateKey(privateKey);
|
|
387
387
|
if (!from) {
|
|
388
|
-
throw new (0,
|
|
388
|
+
throw new (0, _chunkVPENSVOIcjs.WrongFamilyError)("Tron wallet { key } could not derive an address.");
|
|
389
389
|
}
|
|
390
390
|
if (accept.asset === "native") {
|
|
391
391
|
return payTronNative({ client: tronWeb, from, privateKey, accept });
|
|
@@ -408,11 +408,11 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
408
408
|
}
|
|
409
409
|
await _chunkCQREG5LEcjs.delay.call(void 0, 2500);
|
|
410
410
|
}
|
|
411
|
-
throw new (0,
|
|
411
|
+
throw new (0, _chunkVPENSVOIcjs.ConfirmationTimeoutError)(`Tron tx ${txid} did not solidify in time.`);
|
|
412
412
|
},
|
|
413
413
|
async estimateCost(accept, opts) {
|
|
414
414
|
if (accept.asset === "native") {
|
|
415
|
-
return
|
|
415
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
416
416
|
symbol: "TRX",
|
|
417
417
|
decimals: TRX_DECIMALS,
|
|
418
418
|
fee: 1300000n,
|
|
@@ -436,7 +436,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
436
436
|
);
|
|
437
437
|
const energy = BigInt(_nullishCoalesce(r.energy_used, () => ( 0)));
|
|
438
438
|
if (energy > 0n) {
|
|
439
|
-
return
|
|
439
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
440
440
|
symbol: "TRX",
|
|
441
441
|
decimals: TRX_DECIMALS,
|
|
442
442
|
fee: energy * ENERGY_PRICE + BANDWIDTH_SUN,
|
|
@@ -447,7 +447,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
447
447
|
} catch (e8) {
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
|
-
return
|
|
450
|
+
return _chunkVPENSVOIcjs.nativeCost.call(void 0, {
|
|
451
451
|
symbol: "TRX",
|
|
452
452
|
decimals: TRX_DECIMALS,
|
|
453
453
|
fee: 30000n * ENERGY_PRICE + BANDWIDTH_SUN,
|
|
@@ -13,7 +13,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunkVPENSVOIcjs = require('./chunk-VPENSVOI.cjs');
|
|
17
17
|
|
|
18
18
|
// src/drivers/xrpl/index.ts
|
|
19
19
|
var _xrpl = require('xrpl');
|
|
@@ -95,17 +95,17 @@ async function payXrpl(params) {
|
|
|
95
95
|
const code = res.engine_result;
|
|
96
96
|
if (code.startsWith("tes")) return _nullishCoalesce(_optionalChain([res, 'access', _ => _.tx_json, 'optionalAccess', _2 => _2.hash]), () => ( signed.hash));
|
|
97
97
|
const recipientMsg = recipientNotReadyMessage(code);
|
|
98
|
-
if (recipientMsg) throw new (0,
|
|
98
|
+
if (recipientMsg) throw new (0, _chunkVPENSVOIcjs.RecipientNotReadyError)(recipientMsg, { cause: makeEngineError(res) });
|
|
99
99
|
if (isAffordabilityCode(code)) {
|
|
100
|
-
throw new (0,
|
|
100
|
+
throw new (0, _chunkVPENSVOIcjs.InsufficientFundsError)(
|
|
101
101
|
`XRPL payment rejected: the sender can't cover it \u2014 balance or the 1 XRP base reserve. (XRPL: ${code})`,
|
|
102
102
|
{ cause: makeEngineError(res) }
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
throw makeEngineError(res);
|
|
106
106
|
} catch (err) {
|
|
107
|
-
if (err instanceof
|
|
108
|
-
throw _nullishCoalesce(
|
|
107
|
+
if (err instanceof _chunkVPENSVOIcjs.InsufficientFundsError || err instanceof _chunkVPENSVOIcjs.RecipientNotReadyError) throw err;
|
|
108
|
+
throw _nullishCoalesce(_chunkVPENSVOIcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
function amountForAccept(accept) {
|
|
@@ -230,7 +230,7 @@ function deliveredBaseUnits(delivered, want, decimals) {
|
|
|
230
230
|
return null;
|
|
231
231
|
}
|
|
232
232
|
try {
|
|
233
|
-
return
|
|
233
|
+
return _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.WrongFamilyError)(
|
|
258
258
|
`chain ${network} is XRPL; wallet must be { key } (s\u2026 seed) or { wallet }.`
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
_chunkVPENSVOIcjs.assertNoLegacyWalletKey.call(void 0, wallet, "XRPL");
|
|
262
262
|
if (!("key" in wallet) && !("wallet" in wallet)) {
|
|
263
|
-
throw new (0,
|
|
263
|
+
throw new (0, _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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
|
+
_chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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, _chunkVPENSVOIcjs.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 _chunkVPENSVOIcjs.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 _chunkVPENSVOIcjs.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 ? _chunkVPENSVOIcjs.parseUnits.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.8.0",
|
|
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",
|