@piprail/sdk 1.3.1 → 1.5.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.
@@ -9,7 +9,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
9
9
 
10
10
 
11
11
 
12
- var _chunkYJPWIK5Lcjs = require('./chunk-YJPWIK5L.cjs');
12
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
13
13
 
14
14
  // src/drivers/tron/index.ts
15
15
  var _tronweb = require('tronweb');
@@ -61,7 +61,7 @@ async function payTron(params) {
61
61
  return _nullishCoalesce(_nullishCoalesce(broadcast.txid, () => ( _optionalChain([broadcast, 'access', _7 => _7.transaction, 'optionalAccess', _8 => _8.txID]))), () => ( signed.txID));
62
62
  }
63
63
  if (isTronAffordability(broadcast.code, broadcast.message)) {
64
- throw new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
64
+ throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
65
65
  `Tron payment rejected (${_nullishCoalesce(broadcast.code, () => ( "broadcast"))}): not enough TRX for energy/bandwidth, or insufficient token balance.`
66
66
  );
67
67
  }
@@ -69,8 +69,8 @@ async function payTron(params) {
69
69
  `Tron broadcast failed: ${_nullishCoalesce(broadcast.code, () => ( ""))} ${decodeMaybeHex(broadcast.message)}`.trim()
70
70
  );
71
71
  } catch (err) {
72
- if (err instanceof _chunkYJPWIK5Lcjs.InsufficientFundsError) throw err;
73
- throw _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
72
+ if (err instanceof _chunkIQGT65WScjs.InsufficientFundsError) throw err;
73
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
74
74
  }
75
75
  }
76
76
  async function payTronNative(params) {
@@ -83,7 +83,7 @@ async function payTronNative(params) {
83
83
  return _nullishCoalesce(_nullishCoalesce(broadcast.txid, () => ( _optionalChain([broadcast, 'access', _11 => _11.transaction, 'optionalAccess', _12 => _12.txID]))), () => ( signed.txID));
84
84
  }
85
85
  if (isTronAffordability(broadcast.code, broadcast.message)) {
86
- throw new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
86
+ throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
87
87
  `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).`
88
88
  );
89
89
  }
@@ -91,8 +91,8 @@ async function payTronNative(params) {
91
91
  `Tron TRX broadcast failed: ${_nullishCoalesce(broadcast.code, () => ( ""))} ${decodeMaybeHex(broadcast.message)}`.trim()
92
92
  );
93
93
  } catch (err) {
94
- if (err instanceof _chunkYJPWIK5Lcjs.InsufficientFundsError) throw err;
95
- throw _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
94
+ if (err instanceof _chunkIQGT65WScjs.InsufficientFundsError) throw err;
95
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
96
96
  }
97
97
  }
98
98
  function decodeMaybeHex(message) {
@@ -263,22 +263,22 @@ function txNotFound(txid) {
263
263
  // src/drivers/tron/wallet.ts
264
264
  function assertTronWallet(wallet, network) {
265
265
  if (typeof wallet !== "object" || wallet === null) {
266
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
266
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
267
267
  `chain ${network} is Tron; wallet must be { privateKey } (32-byte hex).`
268
268
  );
269
269
  }
270
270
  if ("walletClient" in wallet) {
271
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
271
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
272
272
  `chain ${network} is Tron; a viem { walletClient } can't be used \u2014 pass { privateKey } (32-byte hex).`
273
273
  );
274
274
  }
275
275
  if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "keypair" in wallet || "seed" in wallet) {
276
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
276
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
277
277
  `chain ${network} is Tron; that looks like a Solana/TON/Stellar/XRPL wallet \u2014 pass { privateKey } (32-byte hex).`
278
278
  );
279
279
  }
280
280
  if (!("privateKey" in wallet)) {
281
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
281
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
282
282
  `chain ${network} is Tron; wallet must be { privateKey } (32-byte hex).`
283
283
  );
284
284
  }
@@ -286,11 +286,11 @@ function assertTronWallet(wallet, network) {
286
286
  }
287
287
  function resolveTronPrivateKey(config) {
288
288
  if (!config.privateKey) {
289
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("Tron wallet needs { privateKey } (32-byte hex).");
289
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Tron wallet needs { privateKey } (32-byte hex).");
290
290
  }
291
291
  const hex = config.privateKey.replace(/^0x/i, "").toLowerCase();
292
292
  if (!/^[0-9a-f]{64}$/.test(hex)) {
293
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
293
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
294
294
  "Tron wallet { privateKey } must be a 32-byte hex string (64 hex chars)."
295
295
  );
296
296
  }
@@ -340,21 +340,21 @@ function makeTronNetwork(preset, rpcUrl) {
340
340
  const info = preset.tokens[token.toUpperCase()];
341
341
  if (!info) {
342
342
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
343
- throw new (0, _chunkYJPWIK5Lcjs.UnknownTokenError)(
343
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
344
344
  `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.`
345
345
  );
346
346
  }
347
347
  return { asset: info.address, decimals: info.decimals, symbol: info.symbol };
348
348
  }
349
- _chunkYJPWIK5Lcjs.rejectForeignToken.call(void 0, token, "tron", network);
349
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "tron", network);
350
350
  if (!("address" in token)) {
351
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
351
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
352
352
  `chain ${network} is Tron; a custom token must be { address, decimals } (Base58 T\u2026 contract).`
353
353
  );
354
354
  }
355
355
  const t = token;
356
356
  if (t.address.startsWith("0x") || !tronWeb.isAddress(t.address)) {
357
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
357
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
358
358
  `chain ${network} is Tron, but token address "${t.address}" is not a valid Tron contract (T\u2026).`
359
359
  );
360
360
  }
@@ -373,12 +373,12 @@ function makeTronNetwork(preset, rpcUrl) {
373
373
  },
374
374
  assertValidPayTo(payTo) {
375
375
  if (payTo.startsWith("0x")) {
376
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
376
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
377
377
  `chain ${network} is Tron, but payTo "${payTo}" looks like an EVM address.`
378
378
  );
379
379
  }
380
380
  if (!tronWeb.isAddress(payTo)) {
381
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
381
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
382
382
  `chain ${network} is Tron, but payTo "${payTo}" is not a valid Tron address (T\u2026).`
383
383
  );
384
384
  }
@@ -390,7 +390,7 @@ function makeTronNetwork(preset, rpcUrl) {
390
390
  const privateKey = resolveTronPrivateKey(wallet._native);
391
391
  const from = tronWeb.address.fromPrivateKey(privateKey);
392
392
  if (!from) {
393
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("Tron wallet { privateKey } could not derive an address.");
393
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Tron wallet { privateKey } could not derive an address.");
394
394
  }
395
395
  if (accept.asset === "native") {
396
396
  return payTronNative({ client: tronWeb, from, privateKey, accept });
@@ -413,11 +413,11 @@ function makeTronNetwork(preset, rpcUrl) {
413
413
  }
414
414
  await _chunkCQREG5LEcjs.delay.call(void 0, 2500);
415
415
  }
416
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(`Tron tx ${txid} did not solidify in time.`);
416
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Tron tx ${txid} did not solidify in time.`);
417
417
  },
418
418
  async estimateCost(accept, opts) {
419
419
  if (accept.asset === "native") {
420
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
420
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
421
421
  symbol: "TRX",
422
422
  decimals: TRX_DECIMALS,
423
423
  fee: 1300000n,
@@ -441,7 +441,7 @@ function makeTronNetwork(preset, rpcUrl) {
441
441
  );
442
442
  const energy = BigInt(_nullishCoalesce(r.energy_used, () => ( 0)));
443
443
  if (energy > 0n) {
444
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
444
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
445
445
  symbol: "TRX",
446
446
  decimals: TRX_DECIMALS,
447
447
  fee: energy * ENERGY_PRICE + BANDWIDTH_SUN,
@@ -452,7 +452,7 @@ function makeTronNetwork(preset, rpcUrl) {
452
452
  } catch (e8) {
453
453
  }
454
454
  }
455
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
455
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
456
456
  symbol: "TRX",
457
457
  decimals: TRX_DECIMALS,
458
458
  fee: 30000n * ENERGY_PRICE + BANDWIDTH_SUN,
@@ -460,6 +460,34 @@ function makeTronNetwork(preset, rpcUrl) {
460
460
  detail: "~30k energy + bandwidth (sender not staked; pass { from } for a precise estimate)"
461
461
  });
462
462
  },
463
+ async balanceOf(wallet, asset) {
464
+ const owner = tronWeb.address.fromPrivateKey(
465
+ resolveTronPrivateKey(wallet._native)
466
+ );
467
+ if (!owner) return { token: null, native: null };
468
+ const native = await tronWeb.trx.getBalance(owner).then((n) => BigInt(n)).catch(() => null);
469
+ if (asset === "native") return { token: native, native };
470
+ let token = null;
471
+ try {
472
+ tronWeb.setAddress(owner);
473
+ const res = await tronWeb.transactionBuilder.triggerConstantContract(
474
+ asset,
475
+ "balanceOf(address)",
476
+ {},
477
+ [{ type: "address", value: owner }],
478
+ owner
479
+ );
480
+ const hex = _optionalChain([res, 'optionalAccess', _25 => _25.constant_result, 'optionalAccess', _26 => _26[0]]);
481
+ token = hex == null ? null : BigInt("0x" + hex);
482
+ } catch (e9) {
483
+ token = null;
484
+ }
485
+ return { token, native };
486
+ },
487
+ // No receive prerequisite — any Tron account receives TRX/TRC-20 immediately.
488
+ async recipientReady() {
489
+ return { ready: "n/a" };
490
+ },
463
491
  async verify(ref, accept) {
464
492
  const txid = stripTronPrefix(ref);
465
493
  if (accept.asset === "native") {
@@ -11,7 +11,8 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
11
11
 
12
12
 
13
13
 
14
- var _chunkYJPWIK5Lcjs = require('./chunk-YJPWIK5L.cjs');
14
+
15
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
15
16
 
16
17
  // src/drivers/xrpl/index.ts
17
18
  var _xrpl = require('xrpl');
@@ -93,17 +94,17 @@ async function payXrpl(params) {
93
94
  const code = res.engine_result;
94
95
  if (code.startsWith("tes")) return _nullishCoalesce(_optionalChain([res, 'access', _ => _.tx_json, 'optionalAccess', _2 => _2.hash]), () => ( signed.hash));
95
96
  const recipientMsg = recipientNotReadyMessage(code);
96
- if (recipientMsg) throw new (0, _chunkYJPWIK5Lcjs.RecipientNotReadyError)(recipientMsg, { cause: makeEngineError(res) });
97
+ if (recipientMsg) throw new (0, _chunkIQGT65WScjs.RecipientNotReadyError)(recipientMsg, { cause: makeEngineError(res) });
97
98
  if (isAffordabilityCode(code)) {
98
- throw new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
99
+ throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
99
100
  `XRPL payment rejected: the sender can't cover it \u2014 balance or the 1 XRP base reserve. (XRPL: ${code})`,
100
101
  { cause: makeEngineError(res) }
101
102
  );
102
103
  }
103
104
  throw makeEngineError(res);
104
105
  } catch (err) {
105
- if (err instanceof _chunkYJPWIK5Lcjs.InsufficientFundsError || err instanceof _chunkYJPWIK5Lcjs.RecipientNotReadyError) throw err;
106
- throw _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
106
+ if (err instanceof _chunkIQGT65WScjs.InsufficientFundsError || err instanceof _chunkIQGT65WScjs.RecipientNotReadyError) throw err;
107
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
107
108
  }
108
109
  }
109
110
  function amountForAccept(accept) {
@@ -228,7 +229,7 @@ function deliveredBaseUnits(delivered, want, decimals) {
228
229
  return null;
229
230
  }
230
231
  try {
231
- return _chunkYJPWIK5Lcjs.floorUnits.call(void 0, delivered.value, decimals);
232
+ return _chunkIQGT65WScjs.floorUnits.call(void 0, delivered.value, decimals);
232
233
  } catch (e3) {
233
234
  return null;
234
235
  }
@@ -252,22 +253,22 @@ function rpcFailed(nonce) {
252
253
 
253
254
  function assertXrplWallet(wallet, network) {
254
255
  if (typeof wallet !== "object" || wallet === null) {
255
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
256
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
256
257
  `chain ${network} is XRPL; wallet must be { seed } (s\u2026 seed) or { wallet }.`
257
258
  );
258
259
  }
259
260
  if ("privateKey" in wallet || "walletClient" in wallet) {
260
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
261
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
261
262
  `chain ${network} is XRPL; an EVM wallet can't be used \u2014 pass { seed } (s\u2026 seed) or { wallet }.`
262
263
  );
263
264
  }
264
265
  if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "keypair" in wallet) {
265
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
266
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
266
267
  `chain ${network} is XRPL; that looks like a Solana/TON/Stellar wallet \u2014 pass { seed } (s\u2026 seed) or { wallet }.`
267
268
  );
268
269
  }
269
270
  if (!("seed" in wallet) && !("wallet" in wallet)) {
270
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
271
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
271
272
  `chain ${network} is XRPL; wallet must be { seed } (s\u2026 seed) or { wallet }.`
272
273
  );
273
274
  }
@@ -277,14 +278,17 @@ function resolveXrplWallet(config) {
277
278
  if (config.wallet) return config.wallet;
278
279
  if (config.seed) {
279
280
  if (!_xrpl.isValidSecret.call(void 0, config.seed)) {
280
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("XRPL wallet { seed } is not a valid s\u2026 secret seed.");
281
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("XRPL wallet { seed } is not a valid s\u2026 secret seed.");
281
282
  }
282
283
  return _xrpl.Wallet.fromSeed(config.seed);
283
284
  }
284
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("XRPL wallet needs { seed } (s\u2026 seed) or { wallet }.");
285
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("XRPL wallet needs { seed } (s\u2026 seed) or { wallet }.");
285
286
  }
286
287
 
287
288
  // src/drivers/xrpl/index.ts
289
+ function isXrplActNotFound(e) {
290
+ return /actNotFound/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _5 => _5.message]), () => ( e))));
291
+ }
288
292
  var xrplDriver = {
289
293
  family: "xrpl",
290
294
  resolve(opts) {
@@ -305,7 +309,7 @@ function makeXrplNetwork(preset, rpcUrl) {
305
309
  const json = await res.json();
306
310
  const result = json.result;
307
311
  if (!result || result.status === "error" || result.error) {
308
- throw new Error(`XRPL RPC ${method} error: ${_nullishCoalesce(_optionalChain([result, 'optionalAccess', _5 => _5.error]), () => ( "unknown"))}`);
312
+ throw new Error(`XRPL RPC ${method} error: ${_nullishCoalesce(_optionalChain([result, 'optionalAccess', _6 => _6.error]), () => ( "unknown"))}`);
309
313
  }
310
314
  return result;
311
315
  }
@@ -353,7 +357,7 @@ function makeXrplNetwork(preset, rpcUrl) {
353
357
  const info = preset.tokens[token.toUpperCase()];
354
358
  if (!info) {
355
359
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
356
- throw new (0, _chunkYJPWIK5Lcjs.UnknownTokenError)(
360
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
357
361
  `token "${token}" isn't built in for XRPL (known: ${known}). Pass { issuer, currencyHex, decimals } for a custom IOU, or use 'native'.`
358
362
  );
359
363
  }
@@ -363,10 +367,10 @@ function makeXrplNetwork(preset, rpcUrl) {
363
367
  symbol: info.symbol
364
368
  };
365
369
  }
366
- _chunkYJPWIK5Lcjs.rejectForeignToken.call(void 0, token, "xrpl", network);
370
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "xrpl", network);
367
371
  const t = token;
368
372
  if (!t.issuer || !t.currencyHex || typeof t.decimals !== "number") {
369
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
373
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
370
374
  `chain ${network} is XRPL; a custom token must be { issuer, currencyHex, decimals }.`
371
375
  );
372
376
  }
@@ -387,12 +391,12 @@ function makeXrplNetwork(preset, rpcUrl) {
387
391
  },
388
392
  assertValidPayTo(payTo) {
389
393
  if (payTo.startsWith("0x")) {
390
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
394
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
391
395
  `chain ${network} is XRPL, but payTo "${payTo}" looks like an EVM address.`
392
396
  );
393
397
  }
394
398
  if (!_xrpl.isValidClassicAddress.call(void 0, payTo)) {
395
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
399
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
396
400
  `chain ${network} is XRPL, but payTo "${payTo}" is not a valid XRPL account (r\u2026).`
397
401
  );
398
402
  }
@@ -415,14 +419,14 @@ function makeXrplNetwork(preset, rpcUrl) {
415
419
  }
416
420
  await _chunkCQREG5LEcjs.delay.call(void 0, 1500);
417
421
  }
418
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(`XRPL tx ${ref} not validated on-ledger in time.`);
422
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`XRPL tx ${ref} not validated on-ledger in time.`);
419
423
  },
420
424
  async estimateCost() {
421
425
  try {
422
426
  const drops = await payClient.feeDrops();
423
427
  const n = Number(drops);
424
428
  const fee = BigInt(Number.isFinite(n) && n > 12 ? Math.ceil(n) : 12);
425
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
429
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
426
430
  symbol: XRP_SYMBOL,
427
431
  decimals: XRP_DECIMALS,
428
432
  fee,
@@ -430,7 +434,7 @@ function makeXrplNetwork(preset, rpcUrl) {
430
434
  detail: `network fee ${fee} drops`
431
435
  });
432
436
  } catch (e5) {
433
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
437
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
434
438
  symbol: XRP_SYMBOL,
435
439
  decimals: XRP_DECIMALS,
436
440
  fee: 12n,
@@ -439,6 +443,62 @@ function makeXrplNetwork(preset, rpcUrl) {
439
443
  });
440
444
  }
441
445
  },
446
+ async balanceOf(wallet, asset) {
447
+ let owner;
448
+ try {
449
+ owner = resolveXrplWallet(wallet._native).classicAddress;
450
+ } catch (e6) {
451
+ return { token: null, native: null };
452
+ }
453
+ let native = null;
454
+ try {
455
+ const r = await rpc("account_info", {
456
+ account: owner,
457
+ ledger_index: "validated"
458
+ });
459
+ native = BigInt(r.account_data.Balance);
460
+ } catch (e) {
461
+ native = isXrplActNotFound(e) ? 0n : null;
462
+ }
463
+ if (asset === "native") return { token: native, native };
464
+ let token = null;
465
+ try {
466
+ const [currencyHex, issuer] = asset.split(":");
467
+ const r = await rpc(
468
+ "account_lines",
469
+ { account: owner, ledger_index: "validated" }
470
+ );
471
+ const line = r.lines.find(
472
+ (l) => l.currency.toUpperCase() === (_nullishCoalesce(currencyHex, () => ( ""))).toUpperCase() && l.account === issuer
473
+ );
474
+ token = line ? _chunkIQGT65WScjs.parseUnits.call(void 0, line.balance, XRP_DECIMALS) : 0n;
475
+ } catch (e) {
476
+ token = isXrplActNotFound(e) ? 0n : null;
477
+ }
478
+ return { token, native };
479
+ },
480
+ async recipientReady(payTo, asset) {
481
+ try {
482
+ await rpc("account_info", { account: payTo, ledger_index: "validated" });
483
+ } catch (e) {
484
+ if (isXrplActNotFound(e)) return { ready: false, reason: "INACTIVE" };
485
+ return { ready: "unknown" };
486
+ }
487
+ if (asset === "native") return { ready: true };
488
+ try {
489
+ const [currencyHex, issuer] = asset.split(":");
490
+ const r = await rpc("account_lines", {
491
+ account: payTo,
492
+ ledger_index: "validated"
493
+ });
494
+ const has = r.lines.some(
495
+ (l) => l.currency.toUpperCase() === (_nullishCoalesce(currencyHex, () => ( ""))).toUpperCase() && l.account === issuer
496
+ );
497
+ return has ? { ready: true } : { ready: false, reason: "NO_TRUSTLINE" };
498
+ } catch (e7) {
499
+ return { ready: "unknown" };
500
+ }
501
+ },
442
502
  async verify(_ref, accept) {
443
503
  return verifyXrpl({ reader, accept });
444
504
  }
@@ -9,9 +9,10 @@ import {
9
9
  WrongFamilyError,
10
10
  floorUnits,
11
11
  nativeCost,
12
+ parseUnits,
12
13
  rejectForeignToken,
13
14
  toInsufficientFundsError
14
- } from "./chunk-AGKC3C7Y.js";
15
+ } from "./chunk-QDS6FBZP.js";
15
16
 
16
17
  // src/drivers/xrpl/index.ts
17
18
  import { isValidClassicAddress } from "xrpl";
@@ -285,6 +286,9 @@ function resolveXrplWallet(config) {
285
286
  }
286
287
 
287
288
  // src/drivers/xrpl/index.ts
289
+ function isXrplActNotFound(e) {
290
+ return /actNotFound/i.test(String(e?.message ?? e));
291
+ }
288
292
  var xrplDriver = {
289
293
  family: "xrpl",
290
294
  resolve(opts) {
@@ -439,6 +443,62 @@ function makeXrplNetwork(preset, rpcUrl) {
439
443
  });
440
444
  }
441
445
  },
446
+ async balanceOf(wallet, asset) {
447
+ let owner;
448
+ try {
449
+ owner = resolveXrplWallet(wallet._native).classicAddress;
450
+ } catch {
451
+ return { token: null, native: null };
452
+ }
453
+ let native = null;
454
+ try {
455
+ const r = await rpc("account_info", {
456
+ account: owner,
457
+ ledger_index: "validated"
458
+ });
459
+ native = BigInt(r.account_data.Balance);
460
+ } catch (e) {
461
+ native = isXrplActNotFound(e) ? 0n : null;
462
+ }
463
+ if (asset === "native") return { token: native, native };
464
+ let token = null;
465
+ try {
466
+ const [currencyHex, issuer] = asset.split(":");
467
+ const r = await rpc(
468
+ "account_lines",
469
+ { account: owner, ledger_index: "validated" }
470
+ );
471
+ const line = r.lines.find(
472
+ (l) => l.currency.toUpperCase() === (currencyHex ?? "").toUpperCase() && l.account === issuer
473
+ );
474
+ token = line ? parseUnits(line.balance, XRP_DECIMALS) : 0n;
475
+ } catch (e) {
476
+ token = isXrplActNotFound(e) ? 0n : null;
477
+ }
478
+ return { token, native };
479
+ },
480
+ async recipientReady(payTo, asset) {
481
+ try {
482
+ await rpc("account_info", { account: payTo, ledger_index: "validated" });
483
+ } catch (e) {
484
+ if (isXrplActNotFound(e)) return { ready: false, reason: "INACTIVE" };
485
+ return { ready: "unknown" };
486
+ }
487
+ if (asset === "native") return { ready: true };
488
+ try {
489
+ const [currencyHex, issuer] = asset.split(":");
490
+ const r = await rpc("account_lines", {
491
+ account: payTo,
492
+ ledger_index: "validated"
493
+ });
494
+ const has = r.lines.some(
495
+ (l) => l.currency.toUpperCase() === (currencyHex ?? "").toUpperCase() && l.account === issuer
496
+ );
497
+ return has ? { ready: true } : { ready: false, reason: "NO_TRUSTLINE" };
498
+ } catch {
499
+ return { ready: "unknown" };
500
+ }
501
+ },
442
502
  async verify(_ref, accept) {
443
503
  return verifyXrpl({ reader, accept });
444
504
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@piprail/sdk",
3
- "version": "1.3.1",
4
- "description": "Accept x402 crypto payments across 27 chains — every major EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Stellar & XRPL — in a couple of lines. No backend, no database, no fee; payments settle straight to your wallet.",
3
+ "version": "1.5.0",
4
+ "description": "Accept x402 crypto payments across 28 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",
7
7
  "module": "./dist/index.js",
@@ -48,6 +48,8 @@
48
48
  "tron",
49
49
  "near",
50
50
  "sui",
51
+ "aptos",
52
+ "algorand",
51
53
  "stellar",
52
54
  "xrpl",
53
55
  "base",
@@ -80,6 +82,7 @@
80
82
  "peerDependencies": {
81
83
  "@aptos-labs/ts-sdk": ">=2 <8",
82
84
  "@mysten/sui": ">=2 <3",
85
+ "algosdk": ">=3 <4",
83
86
  "@solana/spl-token": "^0.4.0",
84
87
  "@solana/web3.js": "^1.95.0",
85
88
  "@stellar/stellar-sdk": ">=13 <16",
@@ -128,6 +131,9 @@
128
131
  },
129
132
  "near-api-js": {
130
133
  "optional": true
134
+ },
135
+ "algosdk": {
136
+ "optional": true
131
137
  }
132
138
  },
133
139
  "devDependencies": {
@@ -140,6 +146,7 @@
140
146
  "@ton/crypto": "^3.3.0",
141
147
  "@ton/ton": "^16.2.4",
142
148
  "@types/node": "^22.10.0",
149
+ "algosdk": "^3.5.2",
143
150
  "bs58": "^5.0.0",
144
151
  "near-api-js": "^7.2.0",
145
152
  "tronweb": "^6.3.0",