@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.
@@ -0,0 +1,397 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
11
+
12
+ // src/drivers/algorand/index.ts
13
+ var _algosdk = require('algosdk'); var _algosdk2 = _interopRequireDefault(_algosdk);
14
+
15
+ // src/drivers/algorand/chains.ts
16
+ var ALGO_DECIMALS = 6;
17
+ var ALGO_SYMBOL = "ALGO";
18
+ var ALGORAND_MAINNET = {
19
+ caip2: "algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k",
20
+ defaultAlgod: "https://mainnet-api.algonode.cloud",
21
+ defaultIndexer: "https://mainnet-idx.algonode.cloud",
22
+ tokens: {
23
+ // Circle USDC — ASA id + 6 decimals verified live on mainnet algod
24
+ // (/v2/assets/31566704 → unit-name "USDC", decimals 6, creator = Circle) before shipping.
25
+ // USDC-only: Tether deprecated USDT on Algorand, so it's intentionally omitted.
26
+ USDC: { assetId: 31566704, decimals: 6, symbol: "USDC" }
27
+ }
28
+ };
29
+ function algorandAssetId(assetId) {
30
+ return String(assetId);
31
+ }
32
+ function parseAlgorandAssetId(asset) {
33
+ if (asset === "native") return null;
34
+ if (!/^\d+$/.test(asset)) return null;
35
+ const n = Number(asset);
36
+ return Number.isSafeInteger(n) && n > 0 ? n : null;
37
+ }
38
+
39
+ // src/drivers/algorand/pay.ts
40
+ async function payAlgorand(params) {
41
+ const { client, sk, sender, accept } = params;
42
+ const note = new TextEncoder().encode(accept.extra.nonce);
43
+ const amount = BigInt(accept.amount);
44
+ const assetId = parseAlgorandAssetId(accept.asset);
45
+ try {
46
+ const { txn, txId } = await client.build({
47
+ sender,
48
+ receiver: accept.payTo,
49
+ amount,
50
+ note,
51
+ ...assetId === null ? {} : { assetId }
52
+ });
53
+ await client.signSend({ txn, sk });
54
+ return txId;
55
+ } catch (err) {
56
+ const mapped = mapAlgorandError(err, accept.payTo);
57
+ if (mapped) throw mapped;
58
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
59
+ }
60
+ }
61
+ function mapAlgorandError(err, payTo) {
62
+ const m = err instanceof Error ? err.message : String(err);
63
+ if (/must optin/i.test(m) || /missing from/i.test(m) && m.includes(payTo)) {
64
+ return new (0, _chunkIQGT65WScjs.RecipientNotReadyError)(
65
+ `Algorand recipient ${payTo} hasn't opted into this asset \u2014 it must opt in (a 0-amount asset transfer to itself) before it can receive. (Algorand: ${firstLine(m)})`,
66
+ { cause: err }
67
+ );
68
+ }
69
+ if (/overspend|below min|min(imum)? balance|tried to spend|balance \d+ below|asset \d+ missing from|insufficient|underflow/i.test(
70
+ m
71
+ )) {
72
+ return new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
73
+ `Algorand payment failed: the sender can't cover it \u2014 token balance, ALGO for fees, the 0.1-ALGO minimum balance, or a missing asset opt-in on the sender. (Algorand: ${firstLine(m)})`,
74
+ { cause: err }
75
+ );
76
+ }
77
+ return null;
78
+ }
79
+ function firstLine(message) {
80
+ return message.split("\n")[0].slice(0, 160);
81
+ }
82
+
83
+ // src/drivers/algorand/verify.ts
84
+ async function verifyAlgorand(params) {
85
+ const { reader, accept } = params;
86
+ const nonce = accept.extra.nonce;
87
+ const required = BigInt(accept.amount);
88
+ const wantAssetId = parseAlgorandAssetId(accept.asset);
89
+ let txs;
90
+ try {
91
+ txs = await reader.transactionsForAccount(accept.payTo, 50);
92
+ } catch (e2) {
93
+ return rpcFailed(nonce);
94
+ }
95
+ const tx = txs.find((t) => typeof t.note === "string" && t.note === nonce);
96
+ if (!tx) return notFound(nonce);
97
+ if (typeof tx.roundTime === "number") {
98
+ const ageSeconds = Math.floor(Date.now() / 1e3) - tx.roundTime;
99
+ if (Number.isFinite(ageSeconds) && ageSeconds > accept.maxTimeoutSeconds) {
100
+ return {
101
+ ok: false,
102
+ error: "payment_expired",
103
+ detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
104
+ };
105
+ }
106
+ }
107
+ const isNative = wantAssetId === null;
108
+ const typeOk = isNative ? tx.txType === "pay" : tx.txType === "axfer";
109
+ const assetOk = isNative ? tx.assetId == null : tx.assetId === wantAssetId;
110
+ if (!typeOk || tx.receiver !== accept.payTo || !assetOk) {
111
+ return {
112
+ ok: false,
113
+ error: "transfer_not_found",
114
+ detail: `Algorand tx ${tx.id} carries our nonce but has no matching ${isNative ? "ALGO" : `ASA ${wantAssetId}`} transfer to ${accept.payTo}.`
115
+ };
116
+ }
117
+ let paid = 0n;
118
+ try {
119
+ paid = tx.amount ? BigInt(tx.amount) : 0n;
120
+ } catch (e3) {
121
+ paid = 0n;
122
+ }
123
+ if (paid < required) {
124
+ return { ok: false, error: "amount_too_low", detail: `Paid ${paid}, required ${required}.` };
125
+ }
126
+ return {
127
+ ok: true,
128
+ receipt: {
129
+ scheme: "onchain-proof",
130
+ success: true,
131
+ network: accept.network,
132
+ transaction: tx.id,
133
+ asset: accept.asset,
134
+ amount: accept.amount,
135
+ payer: _nullishCoalesce(tx.sender, () => ( "")),
136
+ payTo: accept.payTo,
137
+ verifiedAt: (/* @__PURE__ */ new Date()).toISOString()
138
+ }
139
+ };
140
+ }
141
+ function notFound(nonce) {
142
+ return {
143
+ ok: false,
144
+ error: "transfer_not_found",
145
+ detail: `No matching Algorand payment found for nonce ${nonce} (not yet settled, or wrong recipient/amount/asset/note).`
146
+ };
147
+ }
148
+ function rpcFailed(nonce) {
149
+ return {
150
+ ok: false,
151
+ error: "tx_not_found",
152
+ detail: `Could not read the Algorand indexer for nonce ${nonce} (transient RPC failure) \u2014 retry.`
153
+ };
154
+ }
155
+
156
+ // src/drivers/algorand/wallet.ts
157
+
158
+ function assertAlgorandWallet(wallet, network) {
159
+ if (typeof wallet !== "object" || wallet === null) {
160
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
161
+ `chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
162
+ );
163
+ }
164
+ if ("privateKey" in wallet || "walletClient" in wallet) {
165
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
166
+ `chain ${network} is Algorand; an EVM/Aptos wallet can't be used \u2014 pass { mnemonic } (25 words) or { account }.`
167
+ );
168
+ }
169
+ if ("secretKey" in wallet || "signer" in wallet || "secret" in wallet || "keypair" in wallet || "keyPair" in wallet || "seed" in wallet || "accountId" in wallet) {
170
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
171
+ `chain ${network} is Algorand; that looks like another family's wallet \u2014 pass { mnemonic } (25 words) or { account }.`
172
+ );
173
+ }
174
+ if (!("mnemonic" in wallet) && !("account" in wallet)) {
175
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
176
+ `chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
177
+ );
178
+ }
179
+ return wallet;
180
+ }
181
+ function resolveAlgorandWallet(config) {
182
+ if (config.account) {
183
+ return { addr: String(config.account.addr), sk: config.account.sk };
184
+ }
185
+ if (config.mnemonic != null) {
186
+ try {
187
+ const { addr, sk } = _algosdk2.default.mnemonicToSecretKey(config.mnemonic);
188
+ return { addr: addr.toString(), sk };
189
+ } catch (cause) {
190
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
191
+ "Algorand wallet { mnemonic } is not a valid 25-word Algorand mnemonic.",
192
+ { cause }
193
+ );
194
+ }
195
+ }
196
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Algorand wallet needs { mnemonic } (25 words) or { account }.");
197
+ }
198
+
199
+ // src/drivers/algorand/index.ts
200
+ var algorandDriver = {
201
+ family: "algorand",
202
+ resolve(opts) {
203
+ if (opts.chain !== "algorand") return null;
204
+ const algodUrl = _nullishCoalesce(opts.rpcUrl, () => ( ALGORAND_MAINNET.defaultAlgod));
205
+ return makeAlgorandNetwork(ALGORAND_MAINNET, algodUrl);
206
+ }
207
+ };
208
+ function makeAlgorandNetwork(preset, algodUrl) {
209
+ const algod = new _algosdk2.default.Algodv2("", algodUrl, "");
210
+ const indexer = new _algosdk2.default.Indexer("", preset.defaultIndexer, "");
211
+ const network = preset.caip2;
212
+ const reader = {
213
+ async transactionsForAccount(account, limit) {
214
+ const res = await indexer.lookupAccountTransactions(account).limit(limit).do();
215
+ return (_nullishCoalesce(res.transactions, () => ( []))).map((t) => adaptTxn(t)).filter((r) => r !== null);
216
+ }
217
+ };
218
+ const payClient = {
219
+ async build(transfer) {
220
+ const suggestedParams = await algod.getTransactionParams().do();
221
+ const common = {
222
+ sender: transfer.sender,
223
+ receiver: transfer.receiver,
224
+ amount: transfer.amount,
225
+ note: transfer.note,
226
+ suggestedParams
227
+ };
228
+ const txn = transfer.assetId === void 0 ? _algosdk2.default.makePaymentTxnWithSuggestedParamsFromObject(common) : _algosdk2.default.makeAssetTransferTxnWithSuggestedParamsFromObject({
229
+ ...common,
230
+ assetIndex: transfer.assetId
231
+ });
232
+ return { txn, txId: txn.txID() };
233
+ },
234
+ async signSend({ txn, sk }) {
235
+ const signed = txn.signTxn(sk);
236
+ await algod.sendRawTransaction(signed).do();
237
+ }
238
+ };
239
+ return {
240
+ family: "algorand",
241
+ network,
242
+ supports: (n) => n === network,
243
+ resolveToken(token) {
244
+ if (token === "native") {
245
+ return { asset: "native", decimals: ALGO_DECIMALS, symbol: ALGO_SYMBOL };
246
+ }
247
+ if (typeof token === "string") {
248
+ const info = preset.tokens[token.toUpperCase()];
249
+ if (!info) {
250
+ const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
251
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
252
+ `token "${token}" isn't built in for Algorand (known: ${known}). Pass { assetId, decimals } for a custom ASA, or use 'native'.`
253
+ );
254
+ }
255
+ return { asset: algorandAssetId(info.assetId), decimals: info.decimals, symbol: info.symbol };
256
+ }
257
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "algorand", network);
258
+ const t = token;
259
+ if (typeof t.assetId !== "number" || typeof t.decimals !== "number") {
260
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
261
+ `chain ${network} is Algorand; a custom token must be { assetId, decimals }.`
262
+ );
263
+ }
264
+ return {
265
+ asset: algorandAssetId(t.assetId),
266
+ decimals: t.decimals,
267
+ ...t.symbol ? { symbol: t.symbol } : {}
268
+ };
269
+ },
270
+ describeAsset(asset) {
271
+ if (asset === "native") return { symbol: ALGO_SYMBOL, decimals: ALGO_DECIMALS };
272
+ for (const info of Object.values(preset.tokens)) {
273
+ if (algorandAssetId(info.assetId) === asset) {
274
+ return { symbol: info.symbol, decimals: info.decimals };
275
+ }
276
+ }
277
+ return null;
278
+ },
279
+ assertValidPayTo(payTo) {
280
+ if (payTo.startsWith("0x")) {
281
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
282
+ `chain ${network} is Algorand, but payTo "${payTo}" looks like an EVM address.`
283
+ );
284
+ }
285
+ if (!_algosdk2.default.isValidAddress(payTo)) {
286
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
287
+ `chain ${network} is Algorand, but payTo "${payTo}" is not a valid Algorand address.`
288
+ );
289
+ }
290
+ },
291
+ bindWallet(wallet) {
292
+ return { _native: assertAlgorandWallet(wallet, network) };
293
+ },
294
+ async send(wallet, accept) {
295
+ const signer = resolveAlgorandWallet(wallet._native);
296
+ return payAlgorand({ client: payClient, sk: signer.sk, sender: signer.addr, accept });
297
+ },
298
+ async confirm(ref) {
299
+ try {
300
+ const info = await _algosdk2.default.waitForConfirmation(algod, ref, 10);
301
+ return { height: String(_nullishCoalesce(info.confirmedRound, () => ( 0))) };
302
+ } catch (err) {
303
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Algorand tx ${ref} did not confirm in time.`, {
304
+ cause: err
305
+ });
306
+ }
307
+ },
308
+ async estimateCost() {
309
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
310
+ symbol: ALGO_SYMBOL,
311
+ decimals: ALGO_DECIMALS,
312
+ fee: 1000n,
313
+ basis: "heuristic",
314
+ detail: "min fee 1000 \xB5Algos (1 transaction)"
315
+ });
316
+ },
317
+ async balanceOf(wallet, asset) {
318
+ let owner;
319
+ try {
320
+ owner = resolveAlgorandWallet(wallet._native).addr;
321
+ } catch (e4) {
322
+ return { token: null, native: null };
323
+ }
324
+ let info;
325
+ try {
326
+ info = await algod.accountInformation(owner).do();
327
+ } catch (e5) {
328
+ return { token: null, native: null };
329
+ }
330
+ const native = info.amount != null ? BigInt(info.amount) : null;
331
+ if (asset === "native") return { token: native, native };
332
+ const assetId = parseAlgorandAssetId(asset);
333
+ const holding = (_nullishCoalesce(info.assets, () => ( []))).find((a) => Number(a.assetId) === assetId);
334
+ return { token: holding ? BigInt(holding.amount) : 0n, native };
335
+ },
336
+ async recipientReady(payTo, asset) {
337
+ if (asset === "native") return { ready: "n/a" };
338
+ const assetId = parseAlgorandAssetId(asset);
339
+ if (assetId == null) return { ready: "unknown" };
340
+ try {
341
+ const info = await algod.accountInformation(payTo).do();
342
+ const optedIn = (_nullishCoalesce(info.assets, () => ( []))).some((a) => Number(a.assetId) === assetId);
343
+ return optedIn ? { ready: true } : { ready: false, reason: "NOT_OPTED_IN" };
344
+ } catch (e) {
345
+ if (/does not exist|no accounts found|404|account not found/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _ => _.message]), () => ( e))))) {
346
+ return { ready: false, reason: "NOT_OPTED_IN" };
347
+ }
348
+ return { ready: "unknown" };
349
+ }
350
+ },
351
+ async verify(_ref, accept) {
352
+ return verifyAlgorand({ reader, accept });
353
+ }
354
+ };
355
+ }
356
+ function adaptTxn(raw) {
357
+ const t = raw;
358
+ if (!t || typeof t.id !== "string") return null;
359
+ const note = t.note && t.note.length ? decodeNote(t.note) : void 0;
360
+ const base = {
361
+ id: t.id,
362
+ txType: String(_nullishCoalesce(t.txType, () => ( ""))),
363
+ ...note !== void 0 ? { note } : {},
364
+ ...t.sender != null ? { sender: String(t.sender) } : {},
365
+ ...typeof t.roundTime === "number" ? { roundTime: t.roundTime } : {}
366
+ };
367
+ if (t.paymentTransaction) {
368
+ const pt = t.paymentTransaction;
369
+ return {
370
+ ...base,
371
+ txType: "pay",
372
+ ...pt.receiver != null ? { receiver: String(pt.receiver) } : {},
373
+ ...pt.amount != null ? { amount: String(pt.amount) } : {}
374
+ };
375
+ }
376
+ if (t.assetTransferTransaction) {
377
+ const att = t.assetTransferTransaction;
378
+ return {
379
+ ...base,
380
+ txType: "axfer",
381
+ ...att.receiver != null ? { receiver: String(att.receiver) } : {},
382
+ ...att.amount != null ? { amount: String(att.amount) } : {},
383
+ ...att.assetId != null ? { assetId: Number(att.assetId) } : {}
384
+ };
385
+ }
386
+ return base;
387
+ }
388
+ function decodeNote(bytes) {
389
+ try {
390
+ return new TextDecoder().decode(bytes);
391
+ } catch (e6) {
392
+ return void 0;
393
+ }
394
+ }
395
+
396
+
397
+ exports.algorandDriver = algorandDriver;
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkYJPWIK5Lcjs = require('./chunk-YJPWIK5L.cjs');
9
+ var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
10
10
 
11
11
  // src/drivers/aptos/index.ts
12
12
  var _tssdk = require('@aptos-labs/ts-sdk');
@@ -55,14 +55,14 @@ async function payAptos(params) {
55
55
  const res = await client.signSubmit({ signer, transaction });
56
56
  return res.hash;
57
57
  } catch (err) {
58
- if (err instanceof _chunkYJPWIK5Lcjs.InsufficientFundsError) throw err;
58
+ if (err instanceof _chunkIQGT65WScjs.InsufficientFundsError) throw err;
59
59
  if (isAptosAffordability(err)) {
60
- throw new (0, _chunkYJPWIK5Lcjs.InsufficientFundsError)(
60
+ throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
61
61
  err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
62
62
  { cause: err }
63
63
  );
64
64
  }
65
- throw _nullishCoalesce(_chunkYJPWIK5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
65
+ throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
66
66
  }
67
67
  }
68
68
  function isAptosAffordability(err) {
@@ -146,22 +146,22 @@ function txNotFound(hash) {
146
146
 
147
147
  function assertAptosWallet(wallet, network) {
148
148
  if (typeof wallet !== "object" || wallet === null) {
149
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
149
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
150
150
  `chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
151
151
  );
152
152
  }
153
153
  if ("walletClient" in wallet) {
154
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
154
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
155
155
  `chain ${network} is Aptos; a viem { walletClient } can't be used \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
156
156
  );
157
157
  }
158
158
  if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keypair" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "accountId" in wallet) {
159
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
159
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
160
160
  `chain ${network} is Aptos; that looks like another family's wallet \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
161
161
  );
162
162
  }
163
163
  if (!("privateKey" in wallet) && !("account" in wallet)) {
164
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
164
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
165
165
  `chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
166
166
  );
167
167
  }
@@ -173,13 +173,13 @@ function resolveAptosAccount(config) {
173
173
  try {
174
174
  return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.privateKey) });
175
175
  } catch (cause) {
176
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
176
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
177
177
  "Aptos wallet { privateKey } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
178
178
  { cause }
179
179
  );
180
180
  }
181
181
  }
182
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)("Aptos wallet needs { privateKey } (ed25519-priv-0x\u2026) or { account }.");
182
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Aptos wallet needs { privateKey } (ed25519-priv-0x\u2026) or { account }.");
183
183
  }
184
184
 
185
185
  // src/drivers/aptos/index.ts
@@ -251,16 +251,16 @@ function makeAptosNetwork(preset, rpcUrl) {
251
251
  const info = preset.tokens[token.toUpperCase()];
252
252
  if (!info) {
253
253
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
254
- throw new (0, _chunkYJPWIK5Lcjs.UnknownTokenError)(
254
+ throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
255
255
  `token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
256
256
  );
257
257
  }
258
258
  return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
259
259
  }
260
- _chunkYJPWIK5Lcjs.rejectForeignToken.call(void 0, token, "aptos", network);
260
+ _chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "aptos", network);
261
261
  const t = token;
262
262
  if (!t.metadata || typeof t.decimals !== "number") {
263
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
263
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
264
264
  `chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
265
265
  );
266
266
  }
@@ -287,7 +287,7 @@ function makeAptosNetwork(preset, rpcUrl) {
287
287
  valid = false;
288
288
  }
289
289
  if (!valid || evmLike) {
290
- throw new (0, _chunkYJPWIK5Lcjs.WrongFamilyError)(
290
+ throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
291
291
  `chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
292
292
  );
293
293
  }
@@ -309,11 +309,11 @@ function makeAptosNetwork(preset, rpcUrl) {
309
309
  const tx = await aptos.waitForTransaction({ transactionHash: ref });
310
310
  return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
311
311
  } catch (err) {
312
- throw new (0, _chunkYJPWIK5Lcjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
312
+ throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
313
313
  }
314
314
  },
315
315
  async estimateCost() {
316
- return _chunkYJPWIK5Lcjs.nativeCost.call(void 0, {
316
+ return _chunkIQGT65WScjs.nativeCost.call(void 0, {
317
317
  symbol: APT_SYMBOL,
318
318
  decimals: APT_DECIMALS,
319
319
  fee: 100000n,
@@ -322,6 +322,34 @@ function makeAptosNetwork(preset, rpcUrl) {
322
322
  detail: "\u22480.001 APT (a simple Fungible-Asset transfer; Aptos gas is sub-cent)"
323
323
  });
324
324
  },
325
+ async balanceOf(wallet, asset) {
326
+ let owner;
327
+ try {
328
+ owner = resolveAptosAccount(wallet._native).accountAddress.toString();
329
+ } catch (e7) {
330
+ return { token: null, native: null };
331
+ }
332
+ const native = await aptos.getAccountAPTAmount({ accountAddress: owner }).then((n) => BigInt(n)).catch(() => null);
333
+ if (asset === "native") return { token: native, native };
334
+ let token = null;
335
+ try {
336
+ const [bal] = await aptos.view({
337
+ payload: {
338
+ function: "0x1::primary_fungible_store::balance",
339
+ typeArguments: ["0x1::fungible_asset::Metadata"],
340
+ functionArguments: [owner, asset]
341
+ }
342
+ });
343
+ token = BigInt(String(bal));
344
+ } catch (e8) {
345
+ token = null;
346
+ }
347
+ return { token, native };
348
+ },
349
+ // No receive prerequisite — the recipient's primary FA store auto-creates on receipt.
350
+ async recipientReady() {
351
+ return { ready: "n/a" };
352
+ },
325
353
  async verify(ref, accept) {
326
354
  return verifyAptos({ reader, hash: ref, accept });
327
355
  }
@@ -6,7 +6,7 @@ import {
6
6
  nativeCost,
7
7
  rejectForeignToken,
8
8
  toInsufficientFundsError
9
- } from "./chunk-AGKC3C7Y.js";
9
+ } from "./chunk-QDS6FBZP.js";
10
10
 
11
11
  // src/drivers/aptos/index.ts
12
12
  import { Aptos, AptosConfig, Network, AccountAddress } from "@aptos-labs/ts-sdk";
@@ -322,6 +322,34 @@ function makeAptosNetwork(preset, rpcUrl) {
322
322
  detail: "\u22480.001 APT (a simple Fungible-Asset transfer; Aptos gas is sub-cent)"
323
323
  });
324
324
  },
325
+ async balanceOf(wallet, asset) {
326
+ let owner;
327
+ try {
328
+ owner = resolveAptosAccount(wallet._native).accountAddress.toString();
329
+ } catch {
330
+ return { token: null, native: null };
331
+ }
332
+ const native = await aptos.getAccountAPTAmount({ accountAddress: owner }).then((n) => BigInt(n)).catch(() => null);
333
+ if (asset === "native") return { token: native, native };
334
+ let token = null;
335
+ try {
336
+ const [bal] = await aptos.view({
337
+ payload: {
338
+ function: "0x1::primary_fungible_store::balance",
339
+ typeArguments: ["0x1::fungible_asset::Metadata"],
340
+ functionArguments: [owner, asset]
341
+ }
342
+ });
343
+ token = BigInt(String(bal));
344
+ } catch {
345
+ token = null;
346
+ }
347
+ return { token, native };
348
+ },
349
+ // No receive prerequisite — the recipient's primary FA store auto-creates on receipt.
350
+ async recipientReady() {
351
+ return { ready: "n/a" };
352
+ },
325
353
  async verify(ref, accept) {
326
354
  return verifyAptos({ reader, hash: ref, accept });
327
355
  }
@@ -82,7 +82,8 @@ var FAMILY_LABEL = {
82
82
  tron: "Tron",
83
83
  sui: "Sui",
84
84
  near: "NEAR",
85
- aptos: "Aptos"
85
+ aptos: "Aptos",
86
+ algorand: "Algorand"
86
87
  };
87
88
  var FAMILY_TOKEN = {
88
89
  evm: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
@@ -93,7 +94,8 @@ var FAMILY_TOKEN = {
93
94
  tron: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
94
95
  sui: { key: "coinType", shape: "{ coinType }", hint: "{ coinType, decimals }" },
95
96
  near: { key: "contractId", shape: "{ contractId }", hint: "{ contractId, decimals }" },
96
- aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" }
97
+ aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" },
98
+ algorand: { key: "assetId", shape: "{ assetId }", hint: "{ assetId, decimals }" }
97
99
  };
98
100
  function rejectForeignToken(token, family, network) {
99
101
  const own = FAMILY_TOKEN[family];
@@ -82,7 +82,8 @@ var FAMILY_LABEL = {
82
82
  tron: "Tron",
83
83
  sui: "Sui",
84
84
  near: "NEAR",
85
- aptos: "Aptos"
85
+ aptos: "Aptos",
86
+ algorand: "Algorand"
86
87
  };
87
88
  var FAMILY_TOKEN = {
88
89
  evm: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
@@ -93,7 +94,8 @@ var FAMILY_TOKEN = {
93
94
  tron: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
94
95
  sui: { key: "coinType", shape: "{ coinType }", hint: "{ coinType, decimals }" },
95
96
  near: { key: "contractId", shape: "{ contractId }", hint: "{ contractId, decimals }" },
96
- aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" }
97
+ aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" },
98
+ algorand: { key: "assetId", shape: "{ assetId }", hint: "{ assetId, decimals }" }
97
99
  };
98
100
  function rejectForeignToken(token, family, network) {
99
101
  const own = FAMILY_TOKEN[family];