@piprail/sdk 2.12.0 → 2.13.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.
@@ -10,7 +10,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
10
10
 
11
11
 
12
12
 
13
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
13
+ var _chunkDCOUJZPLcjs = require('./chunk-DCOUJZPL.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, _chunkMWBT7MCEcjs.InsufficientFundsError)(
65
+ throw new (0, _chunkDCOUJZPLcjs.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 _chunkMWBT7MCEcjs.InsufficientFundsError) throw err;
74
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
73
+ if (err instanceof _chunkDCOUJZPLcjs.InsufficientFundsError) throw err;
74
+ throw _nullishCoalesce(_chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.InsufficientFundsError)(
81
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.InsufficientFundsError)(
93
+ throw new (0, _chunkDCOUJZPLcjs.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 _chunkMWBT7MCEcjs.InsufficientFundsError) throw err;
102
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
101
+ if (err instanceof _chunkDCOUJZPLcjs.InsufficientFundsError) throw err;
102
+ throw _nullishCoalesce(_chunkDCOUJZPLcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
103
103
  }
104
104
  }
105
105
  function decodeMaybeHex(message) {
@@ -270,13 +270,13 @@ function txNotFound(txid) {
270
270
  // src/drivers/tron/wallet.ts
271
271
  function assertTronWallet(wallet, network) {
272
272
  if (typeof wallet !== "object" || wallet === null) {
273
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
273
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
274
274
  `chain ${network} is Tron; wallet must be { key } (32-byte hex).`
275
275
  );
276
276
  }
277
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Tron");
277
+ _chunkDCOUJZPLcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Tron");
278
278
  if (!("key" in wallet)) {
279
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
279
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
280
280
  `chain ${network} is Tron; wallet must be { key } (32-byte hex).`
281
281
  );
282
282
  }
@@ -284,14 +284,14 @@ function assertTronWallet(wallet, network) {
284
284
  }
285
285
  function resolveTronPrivateKey(config) {
286
286
  if (!config.key) {
287
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("Tron wallet needs { key } (32-byte hex).");
287
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)("Tron wallet needs { key } (32-byte hex).");
288
288
  }
289
289
  if (typeof config.key !== "string") {
290
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("Tron wallet { key } must be a 32-byte hex string.");
290
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)("Tron wallet { key } must be a 32-byte hex string.");
291
291
  }
292
292
  const hex = config.key.replace(/^0x/i, "").toLowerCase();
293
293
  if (!/^[0-9a-f]{64}$/.test(hex)) {
294
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
294
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
295
295
  "Tron wallet { key } must be a 32-byte hex string (64 hex chars)."
296
296
  );
297
297
  }
@@ -341,21 +341,21 @@ function makeTronNetwork(preset, rpcUrl) {
341
341
  const info = preset.tokens[token.toUpperCase()];
342
342
  if (!info) {
343
343
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
344
- throw new (0, _chunkMWBT7MCEcjs.UnknownTokenError)(
344
+ throw new (0, _chunkDCOUJZPLcjs.UnknownTokenError)(
345
345
  `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
346
  );
347
347
  }
348
348
  return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
349
349
  }
350
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "tron", network);
350
+ _chunkDCOUJZPLcjs.rejectForeignToken.call(void 0, token, "tron", network);
351
351
  if (!("address" in token)) {
352
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
352
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
353
353
  `chain ${network} is Tron; a custom token must be { address, decimals } (Base58 T\u2026 contract).`
354
354
  );
355
355
  }
356
356
  const t = token;
357
357
  if (t.address.startsWith("0x") || !tronWeb.isAddress(t.address)) {
358
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
358
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
359
359
  `chain ${network} is Tron, but token address "${t.address}" is not a valid Tron contract (T\u2026).`
360
360
  );
361
361
  }
@@ -374,12 +374,12 @@ function makeTronNetwork(preset, rpcUrl) {
374
374
  },
375
375
  assertValidPayTo(payTo) {
376
376
  if (payTo.startsWith("0x")) {
377
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
377
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
378
378
  `chain ${network} is Tron, but payTo "${payTo}" looks like an EVM address.`
379
379
  );
380
380
  }
381
381
  if (!tronWeb.isAddress(payTo)) {
382
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
382
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
383
383
  `chain ${network} is Tron, but payTo "${payTo}" is not a valid Tron address (T\u2026).`
384
384
  );
385
385
  }
@@ -391,7 +391,7 @@ function makeTronNetwork(preset, rpcUrl) {
391
391
  const privateKey = resolveTronPrivateKey(wallet._native);
392
392
  const from = tronWeb.address.fromPrivateKey(privateKey);
393
393
  if (!from) {
394
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("Tron wallet { key } could not derive an address.");
394
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)("Tron wallet { key } could not derive an address.");
395
395
  }
396
396
  if (accept.asset === "native") {
397
397
  return payTronNative({ client: tronWeb, from, privateKey, accept });
@@ -414,11 +414,11 @@ function makeTronNetwork(preset, rpcUrl) {
414
414
  }
415
415
  await _chunkCQREG5LEcjs.delay.call(void 0, 2500);
416
416
  }
417
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(`Tron tx ${txid} did not solidify in time.`);
417
+ throw new (0, _chunkDCOUJZPLcjs.ConfirmationTimeoutError)(`Tron tx ${txid} did not solidify in time.`);
418
418
  },
419
419
  async estimateCost(accept, opts) {
420
420
  if (accept.asset === "native") {
421
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
421
+ return _chunkDCOUJZPLcjs.nativeCost.call(void 0, {
422
422
  symbol: "TRX",
423
423
  decimals: TRX_DECIMALS,
424
424
  fee: 1300000n,
@@ -442,7 +442,7 @@ function makeTronNetwork(preset, rpcUrl) {
442
442
  );
443
443
  const energy = BigInt(_nullishCoalesce(r.energy_used, () => ( 0)));
444
444
  if (energy > 0n) {
445
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
445
+ return _chunkDCOUJZPLcjs.nativeCost.call(void 0, {
446
446
  symbol: "TRX",
447
447
  decimals: TRX_DECIMALS,
448
448
  fee: energy * ENERGY_PRICE + BANDWIDTH_SUN,
@@ -453,7 +453,7 @@ function makeTronNetwork(preset, rpcUrl) {
453
453
  } catch (e8) {
454
454
  }
455
455
  }
456
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
456
+ return _chunkDCOUJZPLcjs.nativeCost.call(void 0, {
457
457
  symbol: "TRX",
458
458
  decimals: TRX_DECIMALS,
459
459
  fee: 30000n * ENERGY_PRICE + BANDWIDTH_SUN,
@@ -13,7 +13,7 @@ import {
13
13
  parseUnits,
14
14
  rejectForeignToken,
15
15
  toInsufficientFundsError
16
- } from "./chunk-SC2ZYDHD.js";
16
+ } from "./chunk-O32N6MFN.js";
17
17
 
18
18
  // src/drivers/xrpl/index.ts
19
19
  import { isValidClassicAddress } from "xrpl";
@@ -13,7 +13,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
13
13
 
14
14
 
15
15
 
16
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
16
+ var _chunkDCOUJZPLcjs = require('./chunk-DCOUJZPL.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, _chunkMWBT7MCEcjs.RecipientNotReadyError)(recipientMsg, { cause: makeEngineError(res) });
98
+ if (recipientMsg) throw new (0, _chunkDCOUJZPLcjs.RecipientNotReadyError)(recipientMsg, { cause: makeEngineError(res) });
99
99
  if (isAffordabilityCode(code)) {
100
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
100
+ throw new (0, _chunkDCOUJZPLcjs.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 _chunkMWBT7MCEcjs.InsufficientFundsError || err instanceof _chunkMWBT7MCEcjs.RecipientNotReadyError) throw err;
108
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
107
+ if (err instanceof _chunkDCOUJZPLcjs.InsufficientFundsError || err instanceof _chunkDCOUJZPLcjs.RecipientNotReadyError) throw err;
108
+ throw _nullishCoalesce(_chunkDCOUJZPLcjs.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 _chunkMWBT7MCEcjs.floorUnits.call(void 0, delivered.value, decimals);
233
+ return _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.WrongFamilyError)(
257
+ throw new (0, _chunkDCOUJZPLcjs.WrongFamilyError)(
258
258
  `chain ${network} is XRPL; wallet must be { key } (s\u2026 seed) or { wallet }.`
259
259
  );
260
260
  }
261
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "XRPL");
261
+ _chunkDCOUJZPLcjs.assertNoLegacyWalletKey.call(void 0, wallet, "XRPL");
262
262
  if (!("key" in wallet) && !("wallet" in wallet)) {
263
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
263
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.WrongFamilyError)("XRPL wallet { key } is not a valid s\u2026 secret seed.");
273
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.WrongFamilyError)("XRPL wallet needs { key } (s\u2026 seed) or { wallet }.");
277
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.UnknownTokenError)(
352
+ throw new (0, _chunkDCOUJZPLcjs.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
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "xrpl", network);
362
+ _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.WrongFamilyError)(
365
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.WrongFamilyError)(
386
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.WrongFamilyError)(
391
+ throw new (0, _chunkDCOUJZPLcjs.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, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(`XRPL tx ${ref} not validated on-ledger in time.`);
414
+ throw new (0, _chunkDCOUJZPLcjs.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 _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
421
+ return _chunkDCOUJZPLcjs.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 _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
429
+ return _chunkDCOUJZPLcjs.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 ? _chunkMWBT7MCEcjs.parseUnits.call(void 0, line.balance, XRP_DECIMALS) : 0n;
466
+ token = line ? _chunkDCOUJZPLcjs.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.12.0",
3
+ "version": "2.13.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",