@piprail/sdk 2.13.0 → 2.14.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/{algorand-AA3WXKW4.js → algorand-6J3IABVF.js} +12 -11
  3. package/dist/{algorand-FCEECDG6.cjs → algorand-QU6G2DQZ.cjs} +43 -42
  4. package/dist/{aptos-LY67Q6QF.js → aptos-DHOMTBLZ.js} +11 -10
  5. package/dist/{aptos-GHJPO6JJ.cjs → aptos-LFTQGBBK.cjs} +41 -40
  6. package/dist/{chunk-MWBT7MCE.cjs → chunk-GYM46G5L.cjs} +22 -4
  7. package/dist/{chunk-SC2ZYDHD.js → chunk-PAMKCWVW.js} +22 -4
  8. package/dist/index.cjs +505 -234
  9. package/dist/index.d.cts +281 -12
  10. package/dist/index.d.ts +281 -12
  11. package/dist/index.js +302 -31
  12. package/dist/{ledger-mF_SoiDB.d.ts → ledger-uFtXlIHY.d.cts} +31 -1
  13. package/dist/{ledger-mF_SoiDB.d.cts → ledger-uFtXlIHY.d.ts} +31 -1
  14. package/dist/{near-FZBUICCS.js → near-5PXTVQ47.js} +14 -5
  15. package/dist/{near-6KAQVVG2.cjs → near-YNNK7RW7.cjs} +39 -30
  16. package/dist/node.d.cts +2 -2
  17. package/dist/node.d.ts +2 -2
  18. package/dist/{solana-ELUWO6N5.js → solana-HITVI3HF.js} +22 -7
  19. package/dist/{solana-MYF4HBO4.cjs → solana-N3UCNCYE.cjs} +54 -39
  20. package/dist/{stellar-ASP2THL2.js → stellar-2QT6YYKN.js} +4 -4
  21. package/dist/{stellar-CRWBSX4E.cjs → stellar-Y3SQN7S5.cjs} +23 -23
  22. package/dist/{sui-Y4RLKKE2.cjs → sui-4AL4E6XU.cjs} +35 -27
  23. package/dist/{sui-FZIKZNVI.js → sui-FV5L6WF5.js} +20 -12
  24. package/dist/{ton-7GKCTC5H.js → ton-5FWDQ4QR.js} +18 -7
  25. package/dist/{ton-AOR3EURW.cjs → ton-5HDVOTMR.cjs} +33 -22
  26. package/dist/{tron-BMCWN5SS.js → tron-AZDY7BMQ.js} +10 -10
  27. package/dist/{tron-OMXB6EW2.cjs → tron-TX2B4N2A.cjs} +39 -39
  28. package/dist/{xrpl-Y6SQNYLC.cjs → xrpl-5TYDLQFS.cjs} +31 -31
  29. package/dist/{xrpl-DD7TJL5L.js → xrpl-UJL5J7CY.js} +13 -13
  30. package/package.json +1 -1
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
10
+ var _chunkGYM46G5Lcjs = require('./chunk-GYM46G5L.cjs');
11
11
 
12
12
  // src/drivers/sui/index.ts
13
13
  var _jsonRpc = require('@mysten/sui/jsonRpc');
@@ -57,7 +57,7 @@ async function paySui(params) {
57
57
  cursor = page.hasNextPage ? page.nextCursor : null;
58
58
  } while (gathered < amount && cursor);
59
59
  if (!ids.length) {
60
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
60
+ throw new (0, _chunkGYM46G5Lcjs.InsufficientFundsError)(
61
61
  `Sui wallet holds no ${accept.asset} coin objects to pay from.`
62
62
  );
63
63
  }
@@ -75,14 +75,14 @@ async function paySui(params) {
75
75
  });
76
76
  return res.digest;
77
77
  } catch (err) {
78
- if (err instanceof _chunkMWBT7MCEcjs.InsufficientFundsError) throw err;
78
+ if (err instanceof _chunkGYM46G5Lcjs.InsufficientFundsError) throw err;
79
79
  if (isSuiAffordability(err)) {
80
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
80
+ throw new (0, _chunkGYM46G5Lcjs.InsufficientFundsError)(
81
81
  err instanceof Error ? err.message : "Insufficient SUI/coin balance for the payment.",
82
82
  { cause: err }
83
83
  );
84
84
  }
85
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
85
+ throw _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
86
86
  }
87
87
  }
88
88
  function isSuiAffordability(err) {
@@ -105,16 +105,18 @@ async function verifySui(params) {
105
105
  if (tx.status !== "success") {
106
106
  return { ok: false, error: "tx_reverted", detail: `Sui tx ${digest} did not succeed (status=${tx.status}).` };
107
107
  }
108
- if (typeof tx.timestampMs === "number") {
109
- const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(tx.timestampMs / 1e3);
110
- if (ageSeconds > accept.maxTimeoutSeconds) {
111
- return {
112
- ok: false,
113
- error: "payment_expired",
114
- detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
115
- };
116
- }
108
+ if (!Number.isFinite(tx.timestampMs)) {
109
+ return { ok: false, error: "payment_expired", detail: `Cannot determine the age of ${digest} (no/invalid timestampMs) \u2014 fail closed.` };
110
+ }
111
+ const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(tx.timestampMs / 1e3);
112
+ if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
113
+ return {
114
+ ok: false,
115
+ error: "payment_expired",
116
+ detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
117
+ };
117
118
  }
119
+ const want = normalizeSuiAddress(accept.payTo);
118
120
  let paid = 0n;
119
121
  let payer = "";
120
122
  for (const bc of tx.balanceChanges) {
@@ -125,8 +127,8 @@ async function verifySui(params) {
125
127
  } catch (e2) {
126
128
  continue;
127
129
  }
128
- if (bc.owner === accept.payTo && v > 0n) paid += v;
129
- else if (v < 0n && !payer) payer = bc.owner;
130
+ if (bc.owner && normalizeSuiAddress(bc.owner) === want && v > 0n) paid += v;
131
+ else if (v < 0n && !payer) payer = bc.owner ? normalizeSuiAddress(bc.owner) : bc.owner;
130
132
  }
131
133
  if (paid < required) {
132
134
  return {
@@ -157,18 +159,24 @@ function txNotFound(digest) {
157
159
  detail: `Sui tx ${digest} not found or not yet propagated \u2014 retry.`
158
160
  };
159
161
  }
162
+ function normalizeSuiAddress(value) {
163
+ const lower = value.toLowerCase();
164
+ const hex = lower.replace(/^0x/, "");
165
+ if (hex.length === 0 || hex.length > 64 || !/^[0-9a-f]+$/.test(hex)) return lower;
166
+ return `0x${hex.padStart(64, "0")}`;
167
+ }
160
168
 
161
169
  // src/drivers/sui/wallet.ts
162
170
  var _ed25519 = require('@mysten/sui/keypairs/ed25519');
163
171
  function assertSuiWallet(wallet, network) {
164
172
  if (typeof wallet !== "object" || wallet === null) {
165
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
173
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
166
174
  `chain ${network} is Sui; wallet must be { key } (suiprivkey1\u2026 ) or { keypair }.`
167
175
  );
168
176
  }
169
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Sui");
177
+ _chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Sui");
170
178
  if (!("key" in wallet) && !("keypair" in wallet)) {
171
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
179
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
172
180
  `chain ${network} is Sui; wallet must be { key } (suiprivkey1\u2026) or { keypair }.`
173
181
  );
174
182
  }
@@ -180,13 +188,13 @@ function resolveSuiKeypair(config) {
180
188
  try {
181
189
  return _ed25519.Ed25519Keypair.fromSecretKey(config.key);
182
190
  } catch (cause) {
183
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
191
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
184
192
  "Sui wallet { key } is not a valid suiprivkey1\u2026 secret (or 32-byte key).",
185
193
  { cause }
186
194
  );
187
195
  }
188
196
  }
189
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("Sui wallet needs { key } (suiprivkey1\u2026) or { keypair }.");
197
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)("Sui wallet needs { key } (suiprivkey1\u2026) or { keypair }.");
190
198
  }
191
199
 
192
200
  // src/drivers/sui/index.ts
@@ -238,16 +246,16 @@ function makeSuiNetwork(preset, rpcUrl) {
238
246
  const info = preset.tokens[token.toUpperCase()];
239
247
  if (!info) {
240
248
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
241
- throw new (0, _chunkMWBT7MCEcjs.UnknownTokenError)(
249
+ throw new (0, _chunkGYM46G5Lcjs.UnknownTokenError)(
242
250
  `token "${token}" isn't built in for Sui (known: ${known}). Note: no native USDT on Sui. Pass { coinType, decimals } for a custom coin, or use 'native'.`
243
251
  );
244
252
  }
245
253
  return { asset: info.coinType, decimals: info.decimals, symbol: info.symbol };
246
254
  }
247
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "sui", network);
255
+ _chunkGYM46G5Lcjs.rejectForeignToken.call(void 0, token, "sui", network);
248
256
  const t = token;
249
257
  if (!t.coinType || typeof t.decimals !== "number") {
250
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
258
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
251
259
  `chain ${network} is Sui; a custom token must be { coinType, decimals }.`
252
260
  );
253
261
  }
@@ -266,7 +274,7 @@ function makeSuiNetwork(preset, rpcUrl) {
266
274
  },
267
275
  assertValidPayTo(payTo) {
268
276
  if (!_utils.isValidSuiAddress.call(void 0, payTo)) {
269
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
277
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
270
278
  `chain ${network} is Sui, but payTo "${payTo}" is not a valid Sui address (0x + 32 bytes).`
271
279
  );
272
280
  }
@@ -283,11 +291,11 @@ function makeSuiNetwork(preset, rpcUrl) {
283
291
  const tx = await client.waitForTransaction({ digest: ref, options: { showEffects: true } });
284
292
  return { height: String(_nullishCoalesce(tx.checkpoint, () => ( "0"))) };
285
293
  } catch (err) {
286
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
294
+ throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
287
295
  }
288
296
  },
289
297
  async estimateCost() {
290
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
298
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
291
299
  symbol: SUI_SYMBOL,
292
300
  decimals: SUI_DECIMALS,
293
301
  fee: 3000000n,
@@ -7,7 +7,7 @@ import {
7
7
  nativeCost,
8
8
  rejectForeignToken,
9
9
  toInsufficientFundsError
10
- } from "./chunk-SC2ZYDHD.js";
10
+ } from "./chunk-PAMKCWVW.js";
11
11
 
12
12
  // src/drivers/sui/index.ts
13
13
  import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
@@ -105,16 +105,18 @@ async function verifySui(params) {
105
105
  if (tx.status !== "success") {
106
106
  return { ok: false, error: "tx_reverted", detail: `Sui tx ${digest} did not succeed (status=${tx.status}).` };
107
107
  }
108
- if (typeof tx.timestampMs === "number") {
109
- const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(tx.timestampMs / 1e3);
110
- if (ageSeconds > accept.maxTimeoutSeconds) {
111
- return {
112
- ok: false,
113
- error: "payment_expired",
114
- detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
115
- };
116
- }
108
+ if (!Number.isFinite(tx.timestampMs)) {
109
+ return { ok: false, error: "payment_expired", detail: `Cannot determine the age of ${digest} (no/invalid timestampMs) \u2014 fail closed.` };
110
+ }
111
+ const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(tx.timestampMs / 1e3);
112
+ if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
113
+ return {
114
+ ok: false,
115
+ error: "payment_expired",
116
+ detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
117
+ };
117
118
  }
119
+ const want = normalizeSuiAddress(accept.payTo);
118
120
  let paid = 0n;
119
121
  let payer = "";
120
122
  for (const bc of tx.balanceChanges) {
@@ -125,8 +127,8 @@ async function verifySui(params) {
125
127
  } catch {
126
128
  continue;
127
129
  }
128
- if (bc.owner === accept.payTo && v > 0n) paid += v;
129
- else if (v < 0n && !payer) payer = bc.owner;
130
+ if (bc.owner && normalizeSuiAddress(bc.owner) === want && v > 0n) paid += v;
131
+ else if (v < 0n && !payer) payer = bc.owner ? normalizeSuiAddress(bc.owner) : bc.owner;
130
132
  }
131
133
  if (paid < required) {
132
134
  return {
@@ -157,6 +159,12 @@ function txNotFound(digest) {
157
159
  detail: `Sui tx ${digest} not found or not yet propagated \u2014 retry.`
158
160
  };
159
161
  }
162
+ function normalizeSuiAddress(value) {
163
+ const lower = value.toLowerCase();
164
+ const hex = lower.replace(/^0x/, "");
165
+ if (hex.length === 0 || hex.length > 64 || !/^[0-9a-f]+$/.test(hex)) return lower;
166
+ return `0x${hex.padStart(64, "0")}`;
167
+ }
160
168
 
161
169
  // src/drivers/sui/wallet.ts
162
170
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
@@ -9,7 +9,7 @@ import {
9
9
  nativeCost,
10
10
  rejectForeignToken,
11
11
  toInsufficientFundsError
12
- } from "./chunk-SC2ZYDHD.js";
12
+ } from "./chunk-PAMKCWVW.js";
13
13
 
14
14
  // src/drivers/ton/index.ts
15
15
  import { Address as Address2 } from "@ton/core";
@@ -99,7 +99,7 @@ async function verifyTon(params) {
99
99
  };
100
100
  }
101
101
  for (const tx of txs) {
102
- const incoming = extractIncoming(tx);
102
+ const incoming = extractIncoming(tx, accept.asset === "native" ? "native" : "jetton");
103
103
  if (!incoming || incoming.comment !== nonce) continue;
104
104
  if (accept.asset !== "native" && !txSucceeded(tx)) {
105
105
  return { ok: false, error: "tx_reverted", detail: `TON payment for nonce ${nonce} failed on-chain.` };
@@ -132,17 +132,19 @@ async function verifyTon(params) {
132
132
  }
133
133
  return notFound(nonce);
134
134
  }
135
- function extractIncoming(tx) {
135
+ function extractIncoming(tx, kind) {
136
136
  const inMsg = tx.inMessage;
137
137
  if (!inMsg || inMsg.info.type !== "internal" || inMsg.info.bounced) return null;
138
138
  const jetton = parseInternalTransfer(inMsg.body);
139
- if (jetton) {
139
+ if (kind === "jetton") {
140
+ if (!jetton) return null;
140
141
  return {
141
142
  amount: jetton.amount,
142
143
  payer: (jetton.from ?? inMsg.info.src).toString(),
143
144
  comment: jetton.comment
144
145
  };
145
146
  }
147
+ if (jetton) return null;
146
148
  return {
147
149
  amount: inMsg.info.value.coins,
148
150
  payer: inMsg.info.src.toString(),
@@ -153,7 +155,8 @@ function txSucceeded(tx) {
153
155
  const d = tx.description;
154
156
  if (d.type !== "generic") return false;
155
157
  if (d.aborted) return false;
156
- if (d.computePhase.type === "vm" && !d.computePhase.success) return false;
158
+ if (d.computePhase.type !== "vm" || !d.computePhase.success) return false;
159
+ if (d.actionPhase && d.actionPhase.success === false) return false;
157
160
  return true;
158
161
  }
159
162
  function parseInternalTransfer(body) {
@@ -259,6 +262,9 @@ function makeTonNetwork(preset, rpcUrl) {
259
262
  let p = jwCache.get(key);
260
263
  if (!p) {
261
264
  p = client.open(JettonMaster.create(Address2.parse(master))).getWalletAddress(Address2.parse(owner));
265
+ p.catch(() => {
266
+ if (jwCache.get(key) === p) jwCache.delete(key);
267
+ });
262
268
  jwCache.set(key, p);
263
269
  }
264
270
  return p;
@@ -346,7 +352,7 @@ function makeTonNetwork(preset, rpcUrl) {
346
352
  continue;
347
353
  }
348
354
  for (const tx of txs) {
349
- const inc = extractIncoming(tx);
355
+ const inc = extractIncoming(tx, "jetton") ?? extractIncoming(tx, "native");
350
356
  if (inc && inc.comment === nonce) return { height: tx.lt.toString() };
351
357
  }
352
358
  }
@@ -381,7 +387,12 @@ function makeTonNetwork(preset, rpcUrl) {
381
387
  return { ready: "n/a" };
382
388
  },
383
389
  async verify(_ref, accept) {
384
- const watch = await watchAccountFor(accept);
390
+ let watch;
391
+ try {
392
+ watch = await watchAccountFor(accept);
393
+ } catch {
394
+ return { ok: false, error: "tx_not_found", detail: `Could not derive/read the TON jetton wallet (transient RPC failure) \u2014 retry.` };
395
+ }
385
396
  return verifyTon({ client, watch, accept });
386
397
  }
387
398
  };
@@ -9,7 +9,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
9
9
 
10
10
 
11
11
 
12
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
12
+ var _chunkGYM46G5Lcjs = require('./chunk-GYM46G5L.cjs');
13
13
 
14
14
  // src/drivers/ton/index.ts
15
15
  var _core = require('@ton/core');
@@ -76,7 +76,7 @@ async function waitForSeqno(opened, from, { tries = 30, intervalMs = 2e3 } = {})
76
76
  }
77
77
  if (current > from) return;
78
78
  }
79
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(
79
+ throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(
80
80
  `TON wallet seqno did not advance past ${from} \u2014 the payment may not have been accepted.`
81
81
  );
82
82
  }
@@ -99,7 +99,7 @@ async function verifyTon(params) {
99
99
  };
100
100
  }
101
101
  for (const tx of txs) {
102
- const incoming = extractIncoming(tx);
102
+ const incoming = extractIncoming(tx, accept.asset === "native" ? "native" : "jetton");
103
103
  if (!incoming || incoming.comment !== nonce) continue;
104
104
  if (accept.asset !== "native" && !txSucceeded(tx)) {
105
105
  return { ok: false, error: "tx_reverted", detail: `TON payment for nonce ${nonce} failed on-chain.` };
@@ -132,17 +132,19 @@ async function verifyTon(params) {
132
132
  }
133
133
  return notFound(nonce);
134
134
  }
135
- function extractIncoming(tx) {
135
+ function extractIncoming(tx, kind) {
136
136
  const inMsg = tx.inMessage;
137
137
  if (!inMsg || inMsg.info.type !== "internal" || inMsg.info.bounced) return null;
138
138
  const jetton = parseInternalTransfer(inMsg.body);
139
- if (jetton) {
139
+ if (kind === "jetton") {
140
+ if (!jetton) return null;
140
141
  return {
141
142
  amount: jetton.amount,
142
143
  payer: (_nullishCoalesce(jetton.from, () => ( inMsg.info.src))).toString(),
143
144
  comment: jetton.comment
144
145
  };
145
146
  }
147
+ if (jetton) return null;
146
148
  return {
147
149
  amount: inMsg.info.value.coins,
148
150
  payer: inMsg.info.src.toString(),
@@ -153,7 +155,8 @@ function txSucceeded(tx) {
153
155
  const d = tx.description;
154
156
  if (d.type !== "generic") return false;
155
157
  if (d.aborted) return false;
156
- if (d.computePhase.type === "vm" && !d.computePhase.success) return false;
158
+ if (d.computePhase.type !== "vm" || !d.computePhase.success) return false;
159
+ if (d.actionPhase && d.actionPhase.success === false) return false;
157
160
  return true;
158
161
  }
159
162
  function parseInternalTransfer(body) {
@@ -204,13 +207,13 @@ var _crypto = require('@ton/crypto');
204
207
 
205
208
  function assertTonWallet(wallet, network) {
206
209
  if (typeof wallet !== "object" || wallet === null) {
207
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
210
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
208
211
  `chain ${network} is TON; wallet must be { key } (24-word mnemonic) or { keyPair }.`
209
212
  );
210
213
  }
211
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "TON");
214
+ _chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, wallet, "TON");
212
215
  if (!("key" in wallet) && !("keyPair" in wallet)) {
213
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
216
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
214
217
  `chain ${network} is TON; wallet must be { key } (24-word mnemonic) or { keyPair }.`
215
218
  );
216
219
  }
@@ -221,13 +224,13 @@ async function resolveTonWallet(config) {
221
224
  let keyPair;
222
225
  if (config.key) {
223
226
  if (typeof config.key !== "string" && !Array.isArray(config.key)) {
224
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
227
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
225
228
  "chain is TON; the wallet { key } must be a 24-word mnemonic (a string or string[])."
226
229
  );
227
230
  }
228
231
  const words = Array.isArray(config.key) ? config.key : config.key.trim().split(/\s+/);
229
232
  if (!await _crypto.mnemonicValidate.call(void 0, words)) {
230
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
233
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
231
234
  "chain is TON; the wallet { key } is not a valid TON mnemonic (expected 24 words from the TON/BIP-39 wordlist)."
232
235
  );
233
236
  }
@@ -235,7 +238,7 @@ async function resolveTonWallet(config) {
235
238
  } else if (config.keyPair) {
236
239
  keyPair = config.keyPair;
237
240
  } else {
238
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("TON wallet needs { key } (24-word mnemonic) or { keyPair }.");
241
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)("TON wallet needs { key } (24-word mnemonic) or { keyPair }.");
239
242
  }
240
243
  const contract = version === "v5r1" ? _ton.WalletContractV5R1.create({ workchain: 0, publicKey: keyPair.publicKey }) : _ton.WalletContractV4.create({ workchain: 0, publicKey: keyPair.publicKey });
241
244
  return { keyPair, contract };
@@ -259,6 +262,9 @@ function makeTonNetwork(preset, rpcUrl) {
259
262
  let p = jwCache.get(key);
260
263
  if (!p) {
261
264
  p = client.open(_ton.JettonMaster.create(_core.Address.parse(master))).getWalletAddress(_core.Address.parse(owner));
265
+ p.catch(() => {
266
+ if (jwCache.get(key) === p) jwCache.delete(key);
267
+ });
262
268
  jwCache.set(key, p);
263
269
  }
264
270
  return p;
@@ -281,15 +287,15 @@ function makeTonNetwork(preset, rpcUrl) {
281
287
  const info = preset.tokens[token.toUpperCase()];
282
288
  if (!info) {
283
289
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
284
- throw new (0, _chunkMWBT7MCEcjs.UnknownTokenError)(
290
+ throw new (0, _chunkGYM46G5Lcjs.UnknownTokenError)(
285
291
  `token "${token}" isn't built in for TON (known: ${known}). Note: native USDC doesn't exist on TON. Pass { master, decimals } for a custom jetton, or use 'native'.`
286
292
  );
287
293
  }
288
294
  return { asset: info.master, decimals: info.decimals, symbol: info.symbol };
289
295
  }
290
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "ton", network);
296
+ _chunkGYM46G5Lcjs.rejectForeignToken.call(void 0, token, "ton", network);
291
297
  if (!("master" in token)) {
292
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
298
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
293
299
  `chain ${network} is TON; a custom token must be { master, decimals }.`
294
300
  );
295
301
  }
@@ -308,14 +314,14 @@ function makeTonNetwork(preset, rpcUrl) {
308
314
  },
309
315
  assertValidPayTo(payTo) {
310
316
  if (payTo.startsWith("0x")) {
311
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
317
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
312
318
  `chain ${network} is TON, but payTo "${payTo}" looks like an EVM address.`
313
319
  );
314
320
  }
315
321
  try {
316
322
  _core.Address.parse(payTo);
317
323
  } catch (e6) {
318
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
324
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
319
325
  `chain ${network} is TON, but payTo "${payTo}" is not a valid TON address.`
320
326
  );
321
327
  }
@@ -331,7 +337,7 @@ function makeTonNetwork(preset, rpcUrl) {
331
337
  const watch = await watchAccountFor(accept);
332
338
  return encodeRef(watch, accept.extra.nonce);
333
339
  } catch (err) {
334
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
340
+ throw _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
335
341
  }
336
342
  },
337
343
  async confirm(ref) {
@@ -346,16 +352,16 @@ function makeTonNetwork(preset, rpcUrl) {
346
352
  continue;
347
353
  }
348
354
  for (const tx of txs) {
349
- const inc = extractIncoming(tx);
355
+ const inc = _nullishCoalesce(extractIncoming(tx, "jetton"), () => ( extractIncoming(tx, "native")));
350
356
  if (inc && inc.comment === nonce) return { height: tx.lt.toString() };
351
357
  }
352
358
  }
353
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
359
+ throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
354
360
  },
355
361
  async estimateCost(accept) {
356
362
  const fee = accept.asset === "native" ? 10000000n : 50000000n;
357
363
  const detail = accept.asset === "native" ? `~0.01 ${TON_NATIVE_SYMBOL} network fee` : `~0.05 ${TON_NATIVE_SYMBOL} attached for the jetton transfer (leftover refunded)`;
358
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, { symbol: TON_NATIVE_SYMBOL, decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
364
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, { symbol: TON_NATIVE_SYMBOL, decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
359
365
  },
360
366
  async balanceOf(wallet, asset) {
361
367
  let owner;
@@ -381,7 +387,12 @@ function makeTonNetwork(preset, rpcUrl) {
381
387
  return { ready: "n/a" };
382
388
  },
383
389
  async verify(_ref, accept) {
384
- const watch = await watchAccountFor(accept);
390
+ let watch;
391
+ try {
392
+ watch = await watchAccountFor(accept);
393
+ } catch (e10) {
394
+ return { ok: false, error: "tx_not_found", detail: `Could not derive/read the TON jetton wallet (transient RPC failure) \u2014 retry.` };
395
+ }
385
396
  return verifyTon({ client, watch, accept });
386
397
  }
387
398
  };
@@ -10,7 +10,7 @@ import {
10
10
  nativeCost,
11
11
  rejectForeignToken,
12
12
  toInsufficientFundsError
13
- } from "./chunk-SC2ZYDHD.js";
13
+ } from "./chunk-PAMKCWVW.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) && ageSeconds > accept.maxTimeoutSeconds) {
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) && ageSeconds > accept.maxTimeoutSeconds) {
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 = stripTronPrefix(ref);
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 = stripTronPrefix(ref);
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
  };