@otoplo/wallet-common 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -186,10 +186,10 @@ function he(e) {
186
186
  function ge(e) {
187
187
  return new Promise((t) => setTimeout(t, e));
188
188
  }
189
- function L(e) {
189
+ function _e(e) {
190
190
  return new y(e).stripTrailingZero().getPrettyValue();
191
191
  }
192
- function _e(e, t, n, r = "en-US") {
192
+ function ve(e, t, n, r = "en-US") {
193
193
  let i = y.multiply(e, t);
194
194
  return new Intl.NumberFormat(r, {
195
195
  style: "currency",
@@ -197,7 +197,7 @@ function _e(e, t, n, r = "en-US") {
197
197
  }).format(Number(i));
198
198
  }
199
199
  // src/persistence/wallet-db.ts
200
- var ve = class {
200
+ var ye = class {
201
201
  constructor(e) {
202
202
  this.repository = e;
203
203
  }
@@ -386,7 +386,7 @@ var ve = class {
386
386
  removeSetting(e) {
387
387
  return this.repository.deleteSetting(e);
388
388
  }
389
- }, ye = class {
389
+ }, be = class {
390
390
  constructor(e) {
391
391
  this.tokens = /* @__PURE__ */ new Map(), this.nfts = /* @__PURE__ */ new Map(), this.walletDb = e;
392
392
  }
@@ -409,7 +409,7 @@ var ve = class {
409
409
  removeNft(e) {
410
410
  this.nfts.delete(M(e));
411
411
  }
412
- }, be = class e {
412
+ }, xe = class e {
413
413
  constructor(e) {
414
414
  this.walletDb = e;
415
415
  }
@@ -423,7 +423,18 @@ var ve = class {
423
423
  return this.execute("blockchain.address.get_balance", e, "exclude_tokens");
424
424
  }
425
425
  getTransactionsHistory(e, t = 0) {
426
- return this.execute("blockchain.address.get_history", e, { from_height: t });
426
+ return this.paginate("blockchain.address.get_history", "history", (n) => [
427
+ e,
428
+ { from_height: t },
429
+ n
430
+ ]);
431
+ }
432
+ listTemplateScripts(e, t = null) {
433
+ return this.paginate("blockchain.script.list_template", "scripts", (n) => [
434
+ e,
435
+ t,
436
+ n
437
+ ]);
427
438
  }
428
439
  getFirstUse(e) {
429
440
  return this.execute("blockchain.address.get_first_use", e);
@@ -444,10 +455,18 @@ var ve = class {
444
455
  return this.execute("blockchain.utxo.get", e);
445
456
  }
446
457
  getNexaUtxos(e) {
447
- return this.execute("blockchain.address.listunspent", e, "exclude_tokens");
458
+ return this.paginate("blockchain.address.listunspent", "unspent", (t) => [
459
+ e,
460
+ "exclude_tokens",
461
+ t
462
+ ]);
448
463
  }
449
- async getTokenUtxos(e, t) {
450
- return (await this.execute("token.address.listunspent", e, null, t)).unspent;
464
+ getTokenUtxos(e, t) {
465
+ return this.paginate("token.address.listunspent", "unspent", (n) => [
466
+ e,
467
+ n,
468
+ t
469
+ ]);
451
470
  }
452
471
  async getTokensBalance(e) {
453
472
  let t = await this.execute("token.address.get_balance", e), n = {};
@@ -461,9 +480,6 @@ var ve = class {
461
480
  });
462
481
  return n;
463
482
  }
464
- getTokenGenesis(e) {
465
- return this.execute("token.genesis.info", e);
466
- }
467
483
  broadcast(e) {
468
484
  return this.execute("blockchain.transaction.broadcast", e);
469
485
  }
@@ -498,6 +514,19 @@ var ve = class {
498
514
  return console.error(e), !1;
499
515
  }
500
516
  }
517
+ async paginate(e, t, n, r = 3) {
518
+ for (let i = 0;; i++) try {
519
+ let r = [], i = "start";
520
+ for (; i;) {
521
+ let a = await this.execute(e, ...n(i));
522
+ r.push(...a[t] ?? []), i = a.cursor ?? null;
523
+ }
524
+ return r;
525
+ } catch (e) {
526
+ if (i < r && e instanceof Error && e.message.includes("cursor expired")) continue;
527
+ throw e;
528
+ }
529
+ }
501
530
  async execute(e, ...t) {
502
531
  await this.waitForConnection();
503
532
  let n = await this.client.request(e, ...t);
@@ -545,10 +574,10 @@ var ve = class {
545
574
  }
546
575
  };
547
576
  // src/utils/keypath.ts
548
- function R(e, t, n) {
577
+ function L(e, t, n) {
549
578
  return `${e}'/${t}/${n}`;
550
579
  }
551
- function z(e) {
580
+ function R(e) {
552
581
  let t = e.split("/");
553
582
  return {
554
583
  account: parseInt(t[0].replace("'", "")),
@@ -557,7 +586,7 @@ function z(e) {
557
586
  };
558
587
  }
559
588
  // src/services/key.ts
560
- var B = class {
589
+ var z = class {
561
590
  constructor() {
562
591
  this.accountKeys = /* @__PURE__ */ new Map(), this.walletKeys = /* @__PURE__ */ new Map();
563
592
  }
@@ -583,35 +612,35 @@ var B = class {
583
612
  }).privateKey.toAddress().toString();
584
613
  }
585
614
  getKey(e) {
586
- let t = typeof e == "string" ? e : R(e.account, e.type, e.index), n = this.walletKeys.get(t);
615
+ let t = typeof e == "string" ? e : L(e.account, e.type, e.index), n = this.walletKeys.get(t);
587
616
  if (!n) {
588
- let { account: r, type: i, index: a } = typeof e == "string" ? z(e) : e;
617
+ let { account: r, type: i, index: a } = typeof e == "string" ? R(e) : e;
589
618
  n = this.getAccountKey(r).deriveChild(i, !1).deriveChild(a, !1), this.walletKeys.set(t, n);
590
619
  }
591
620
  return n;
592
621
  }
593
622
  };
594
623
  // src/utils/asset.ts
595
- function xe(e, t) {
624
+ function Se(e, t) {
596
625
  return e && typeof e == "string" ? e.startsWith("http") ? e.replace("http://", "https://") : e.startsWith("ipfs://") ? e : `${new URL(t).origin}${e}` : "";
597
626
  }
598
- function V(e) {
599
- return e ? Se(e) : null;
627
+ function B(e) {
628
+ return e ? Ce(e) : null;
600
629
  }
601
- function Se(e, t = "https://ipfs.nebula.markets/") {
630
+ function Ce(e, t = "https://ipfs.nebula.markets/") {
602
631
  return e?.startsWith("ipfs://") ? t + e.substring(7) : e;
603
632
  }
604
- function H(e) {
605
- return `${W()}/metadata/${e}`;
633
+ function V(e) {
634
+ return `${U()}/metadata/${e}`;
606
635
  }
607
- function U(e, t) {
608
- return `${W()}/assets/${e}/${t}`;
636
+ function H(e, t) {
637
+ return `${U()}/assets/${e}/${t}`;
609
638
  }
610
- function W() {
639
+ function U() {
611
640
  return `https://${D() ? "testapi" : "api"}.otoplo.com`;
612
641
  }
613
642
  // src/services/asset.ts
614
- var Ce = class {
643
+ var we = class {
615
644
  constructor(e, t) {
616
645
  this.walletDb = e, this.walletCache = t;
617
646
  }
@@ -643,7 +672,8 @@ var Ce = class {
643
672
  author: n.author,
644
673
  public: n.public,
645
674
  front: n.front,
646
- back: n.back
675
+ back: n.back,
676
+ thumb: n.thumb
647
677
  }
648
678
  } : await this.getAssetMetadata(e);
649
679
  } catch (e) {
@@ -701,10 +731,10 @@ var Ce = class {
701
731
  await this.walletDb.deleteNft(e, t), this.walletCache.removeNft(t);
702
732
  }
703
733
  getAssetFile(e, t) {
704
- return this.performGet(U(e, t), "raw");
734
+ return this.performGet(H(e, t), "raw");
705
735
  }
706
736
  getAssetMetadata(e) {
707
- return this.performGet(H(e), "json");
737
+ return this.performGet(V(e), "json");
708
738
  }
709
739
  async performGet(e, t) {
710
740
  try {
@@ -719,35 +749,35 @@ var Ce = class {
719
749
  throw Error(`Unexpected Error: ${e}`);
720
750
  }
721
751
  }
722
- }, G = 274710, we = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
723
- function K() {
752
+ }, W = 274710, Te = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
753
+ function G() {
724
754
  return f.empty().add(l.OP_FROMALTSTACK).add(l.OP_DROP).add(l.OP_FROMALTSTACK).add(l.OP_CHECKLOCKTIMEVERIFY).add(l.OP_DROP).add(l.OP_FROMALTSTACK).add(l.OP_CHECKSIGVERIFY);
725
755
  }
726
- function q() {
727
- let e = K();
756
+ function K() {
757
+ let e = G();
728
758
  return s.sha256ripemd160(e.toBuffer());
729
759
  }
730
- function J(e) {
760
+ function q(e) {
731
761
  return f.empty().add(e.toBuffer());
732
762
  }
733
- function Y(e) {
734
- let t = J(e);
763
+ function J(e) {
764
+ let t = q(e);
735
765
  return s.sha256ripemd160(t.toBuffer());
736
766
  }
737
- function X(e) {
767
+ function Y(e) {
738
768
  return e.map((e) => e <= 16 ? p.smallInt(e) : n.fromNumber(e).toScriptNumBuffer());
739
769
  }
740
- function Z(t, n) {
770
+ function X(t, n) {
741
771
  if (n.length !== 2) return;
742
- let r = q(), i = Y(t), a = X(n);
772
+ let r = K(), i = J(t), a = Y(n);
743
773
  return e.fromScriptTemplate(r, i, a).toString();
744
774
  }
745
- function Te(e, t) {
775
+ function Ee(e, t) {
746
776
  let n = (t - e) * 2, r = /* @__PURE__ */ new Date();
747
777
  return r.setMinutes(r.getMinutes() + n), r.toLocaleDateString();
748
778
  }
749
779
  // src/services/transaction.ts
750
- var Ee = class {
780
+ var De = class {
751
781
  constructor(e, t, n) {
752
782
  this.MAX_INPUTS_OUTPUTS = 250, this.rostrumService = e, this.keyManager = t, this.walletDb = n;
753
783
  }
@@ -763,7 +793,7 @@ var Ee = class {
763
793
  };
764
794
  }
765
795
  async fetchVaultTransactions(e) {
766
- let t = await this.rostrumService.getTransactionsHistory(e, G), n = [];
796
+ let t = await this.rostrumService.getTransactionsHistory(e, W), n = [];
767
797
  for (let r of t) {
768
798
  let t = this.classifyTransaction(r.tx_hash, [e]);
769
799
  n.push(t);
@@ -934,13 +964,13 @@ var Ee = class {
934
964
  }
935
965
  };
936
966
  // src/utils/seed.ts
937
- function De(e = 12) {
967
+ function Oe(e = 12) {
938
968
  return re(x, e === 24 ? 256 : 128);
939
969
  }
940
- function Q(e) {
970
+ function Z(e) {
941
971
  return ae(e, x);
942
972
  }
943
- async function $(e, t) {
973
+ async function Q(e, t) {
944
974
  let n = await crypto.subtle.importKey("raw", new Uint8Array(e), "PBKDF2", !1, ["deriveKey"]);
945
975
  return crypto.subtle.deriveKey({
946
976
  name: "PBKDF2",
@@ -952,8 +982,8 @@ async function $(e, t) {
952
982
  length: 256
953
983
  }, !1, ["encrypt", "decrypt"]);
954
984
  }
955
- async function Oe(e, t) {
956
- let n = r.utf8ToBuffer(t), i = r.getRandomBuffer(16), a = r.getRandomBuffer(12), o = r.utf8ToBuffer(e), s = await $(n, i), c = await crypto.subtle.encrypt({
985
+ async function ke(e, t) {
986
+ let n = r.utf8ToBuffer(t), i = r.getRandomBuffer(16), a = r.getRandomBuffer(12), o = r.utf8ToBuffer(e), s = await Q(n, i), c = await crypto.subtle.encrypt({
957
987
  name: "AES-GCM",
958
988
  iv: new Uint8Array(a)
959
989
  }, s, new Uint8Array(o)), l = r.concat([
@@ -963,18 +993,18 @@ async function Oe(e, t) {
963
993
  ]);
964
994
  return r.bufferToBase64(l);
965
995
  }
966
- async function ke(e, t) {
967
- let n = r.utf8ToBuffer(t), i = r.base64ToBuffer(e), a = i.slice(0, 16), o = i.slice(16, 28), s = i.slice(28), c = await $(n, a), l = await crypto.subtle.decrypt({
996
+ async function Ae(e, t) {
997
+ let n = r.utf8ToBuffer(t), i = r.base64ToBuffer(e), a = i.slice(0, 16), o = i.slice(16, 28), s = i.slice(28), c = await Q(n, a), l = await crypto.subtle.decrypt({
968
998
  name: "AES-GCM",
969
999
  iv: o
970
1000
  }, c, s);
971
1001
  return r.bufferToUtf8(new Uint8Array(l));
972
1002
  }
973
- async function Ae(e, t) {
1003
+ async function je(e, t) {
974
1004
  try {
975
1005
  if (e) {
976
- let n = await ke(e, t);
977
- if (n && Q(n)) return n;
1006
+ let n = await Ae(e, t);
1007
+ if (n && Z(n)) return n;
978
1008
  }
979
1009
  return !1;
980
1010
  } catch {
@@ -982,7 +1012,7 @@ async function Ae(e, t) {
982
1012
  }
983
1013
  }
984
1014
  // src/services/session.ts
985
- var je = class {
1015
+ var Me = class {
986
1016
  constructor(e, t) {
987
1017
  this.walletDb = e, this.keyManager = t, this.providers = /* @__PURE__ */ new Map(), this.handlers = /* @__PURE__ */ new Map(), this.removeOnClose = !0;
988
1018
  }
@@ -1128,7 +1158,7 @@ var je = class {
1128
1158
  };
1129
1159
  });
1130
1160
  }
1131
- }, Me = class {
1161
+ }, Ne = class {
1132
1162
  constructor(e, t, n) {
1133
1163
  this.rostrumService = e, this.keyManager = t, this.assetService = n;
1134
1164
  }
@@ -1253,39 +1283,46 @@ var je = class {
1253
1283
  t !== "NEXA" && (n.asset = await this.assetService.getAssetInfo(t)), n.amount > 0n ? e.txDetails.receive.push(n) : n.amount < 0n && e.txDetails.send.push(n);
1254
1284
  }
1255
1285
  }
1256
- }, Ne = 274710, Pe = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76", Fe = class {
1286
+ }, $ = 5, Pe = class {
1257
1287
  constructor(e, t) {
1258
1288
  this.rostrumService = e, this.keyManager = t;
1259
1289
  }
1260
1290
  async discoverWalletIndex(e, t) {
1261
1291
  let n = 0, r = -1, i = [];
1262
1292
  for (;;) {
1263
- let a = await Promise.all(Array.from({ length: B.GAP_LIMIT }, (r, i) => this.rostrumService.isAddressUsed(this.keyManager.deriveAddress(e, t, n + i))));
1264
- if (a.some((e) => e)) r = n, i = a, n += B.GAP_LIMIT;
1293
+ let a = await Promise.all(Array.from({ length: z.GAP_LIMIT }, (r, i) => this.rostrumService.isAddressUsed(this.keyManager.deriveAddress(e, t, n + i))));
1294
+ if (a.some((e) => e)) r = n, i = a, n += z.GAP_LIMIT;
1265
1295
  else break;
1266
1296
  }
1267
1297
  if (r === -1) return -1;
1268
- for (let e = B.GAP_LIMIT - 1; e >= 0; e--) if (i[e]) return r + e;
1298
+ for (let e = z.GAP_LIMIT - 1; e >= 0; e--) if (i[e]) return r + e;
1269
1299
  return r;
1270
1300
  }
1271
- async discoverVaults(e) {
1272
- let t = await this.checkForVaults(e), n = /* @__PURE__ */ new Map();
1273
- return t.forEach((e) => {
1274
- let t = this.parseVaultDetails(e);
1275
- t && n.set(t.address, t);
1276
- }), n;
1277
- }
1278
- async checkForVaults(e) {
1279
- let t = /* @__PURE__ */ new Set();
1280
- return await Promise.all(e.map(async (e) => {
1281
- if (e.height > 0 && e.height < Ne) return;
1282
- let n = await this.rostrumService.getTransaction(e.tx_hash);
1283
- for (let e of n.vout) e.scriptPubKey.hex.startsWith(Pe) && t.add(e.scriptPubKey.hex);
1284
- })), t;
1301
+ async discoverVaults() {
1302
+ let e = await this.checkForVaults(), t = /* @__PURE__ */ new Map();
1303
+ return e.forEach((e) => {
1304
+ let n = this.parseVaultDetails(e);
1305
+ n && t.set(n.address, n);
1306
+ }), t;
1307
+ }
1308
+ async checkForVaults() {
1309
+ let e = /* @__PURE__ */ new Set(), t = r.bufferToHex(K()), n = 0;
1310
+ for (let i = 0; n < $; i += $) {
1311
+ let a = await Promise.all(Array.from({ length: $ }, (e, n) => {
1312
+ let a = this.keyManager.getKey({
1313
+ account: S.VAULT,
1314
+ type: C.RECEIVE,
1315
+ index: i + n
1316
+ }), o = r.bufferToHex(J(a.publicKey));
1317
+ return this.rostrumService.listTemplateScripts(t, o);
1318
+ }));
1319
+ for (let t of a) t.length === 0 ? n++ : (n = 0, t.forEach((t) => e.add(t.scriptpubkey)));
1320
+ }
1321
+ return e;
1285
1322
  }
1286
1323
  parseVaultDetails(t) {
1287
1324
  let r = f.fromHex(t), a = new i().writeVarLengthBuf(r.toBuffer()).toBuffer(), o = new e(a).toString(), s = r.getVisibleArgs(), c = n.fromScriptNumBuffer(s.chunks[0].buf).toNumber(), l = p.isSmallIntOp(s.chunks[1].opcodenum) ? p.decodeOP_N(s.chunks[1].opcodenum) : n.fromScriptNumBuffer(s.chunks[1].buf).toNumber(), u = [c, l];
1288
- if (o == Z(this.keyManager.getKey({
1325
+ if (o == X(this.keyManager.getKey({
1289
1326
  account: S.VAULT,
1290
1327
  type: C.RECEIVE,
1291
1328
  index: l
@@ -1303,7 +1340,7 @@ var je = class {
1303
1340
  type: S.VAULT
1304
1341
  };
1305
1342
  }
1306
- }, Ie = class e {
1343
+ }, Fe = class e {
1307
1344
  static {
1308
1345
  this.DEBOUNCE_MS = 2e3;
1309
1346
  }
@@ -1315,7 +1352,7 @@ var je = class {
1315
1352
  address: r,
1316
1353
  result: n
1317
1354
  });
1318
- }, this.discoveryService = new Fe(this.rostrumService, this.keyManager), this.accounts = /* @__PURE__ */ new Map(), this.accountsAddressToId = /* @__PURE__ */ new Map(), this.receiveAddresses = [], this.changeAddresses = [], this.vaults = /* @__PURE__ */ new Map(), this.pendingUpdates = /* @__PURE__ */ new Map(), this.addressResolvers = /* @__PURE__ */ new Map();
1355
+ }, this.discoveryService = new Pe(this.rostrumService, this.keyManager), this.accounts = /* @__PURE__ */ new Map(), this.accountsAddressToId = /* @__PURE__ */ new Map(), this.receiveAddresses = [], this.changeAddresses = [], this.vaults = /* @__PURE__ */ new Map(), this.pendingUpdates = /* @__PURE__ */ new Map(), this.addressResolvers = /* @__PURE__ */ new Map();
1319
1356
  }
1320
1357
  onUpdate(e) {
1321
1358
  this.updateCallback = e;
@@ -1345,14 +1382,14 @@ var je = class {
1345
1382
  let t = this.accounts.get(e);
1346
1383
  return [{
1347
1384
  address: t.address,
1348
- keyPath: R(S.DAPP, 0, t.id),
1385
+ keyPath: L(S.DAPP, 0, t.id),
1349
1386
  balance: t.balance,
1350
1387
  tokensBalance: t.tokensBalance
1351
1388
  }];
1352
1389
  }
1353
1390
  return this.getMainAddresses().filter((e) => e.used).map((e) => ({
1354
1391
  address: e.address,
1355
- keyPath: R(S.MAIN, e.space, e.idx),
1392
+ keyPath: L(S.MAIN, e.space, e.idx),
1356
1393
  balance: e.balance,
1357
1394
  tokensBalance: e.tokensBalance
1358
1395
  }));
@@ -1374,12 +1411,13 @@ var je = class {
1374
1411
  type: "discover_wallet",
1375
1412
  loading: !0
1376
1413
  });
1377
- let e = this.discoveryService.discoverWalletIndex(S.MAIN, C.RECEIVE), t = this.discoveryService.discoverWalletIndex(S.MAIN, C.CHANGE), n = this.discoveryService.discoverWalletIndex(S.DAPP, C.RECEIVE), [r, i, a] = await Promise.all([
1414
+ let e = this.discoveryService.discoverWalletIndex(S.MAIN, C.RECEIVE), t = this.discoveryService.discoverWalletIndex(S.MAIN, C.CHANGE), n = this.discoveryService.discoverWalletIndex(S.DAPP, C.RECEIVE), r = this.discoveryService.discoverVaults(), [i, a, o, s] = await Promise.all([
1378
1415
  e,
1379
1416
  t,
1380
- n
1417
+ n,
1418
+ r
1381
1419
  ]);
1382
- this.receiveAddresses = this.deriveAddresses(C.RECEIVE, 0, r + B.GAP_LIMIT + 1), this.changeAddresses = this.deriveAddresses(C.CHANGE, 0, i + B.GAP_LIMIT + 1), this.accounts = this.deriveAccounts(0, a < 0 ? 1 : a + 1), this.accounts.forEach((e) => this.accountsAddressToId.set(e.address, e.id)), await this.saveAddresses(this.receiveAddresses), await this.saveAddresses(this.changeAddresses), await this.saveAccounts(this.accounts), this.initState(), await this.initialSync(), this.notify({
1420
+ this.receiveAddresses = this.deriveAddresses(C.RECEIVE, 0, i + z.GAP_LIMIT + 1), this.changeAddresses = this.deriveAddresses(C.CHANGE, 0, a + z.GAP_LIMIT + 1), this.accounts = this.deriveAccounts(0, o < 0 ? 1 : o + 1), this.accounts.forEach((e) => this.accountsAddressToId.set(e.address, e.id)), this.vaults = s, await this.saveAddresses(this.receiveAddresses), await this.saveAddresses(this.changeAddresses), await this.saveAccounts(this.accounts), await this.saveVaults(this.vaults), this.initState(), await this.initialSync(), this.notify({
1383
1421
  type: "discover_wallet",
1384
1422
  loading: !1
1385
1423
  }), this.notify({
@@ -1485,6 +1523,9 @@ var je = class {
1485
1523
  async saveAccounts(e) {
1486
1524
  for (let t of e.values()) await this.walletDb.saveAccount(t);
1487
1525
  }
1526
+ async saveVaults(e) {
1527
+ for (let t of e.values()) await this.walletDb.saveVault(t);
1528
+ }
1488
1529
  async subscribeAddresses(e, t = !1) {
1489
1530
  let n = e.map(async (e) => ({
1490
1531
  addr: e,
@@ -1543,7 +1584,7 @@ var je = class {
1543
1584
  }
1544
1585
  let a = await Promise.all(t);
1545
1586
  await Promise.all(n);
1546
- let o = await Promise.all(r), s = [this.postProcessWalletUpdate(o, i), this.postProcessAccountsUpdate(a)];
1587
+ let o = await Promise.all(r), s = [this.postProcessWalletUpdate(o), this.postProcessAccountsUpdate(a)];
1547
1588
  i && s.push(this.recoverTokens()), await Promise.all(s), i && this.discoveryResolver && (this.discoveryResolver(), this.discoveryResolver = void 0);
1548
1589
  } catch (e) {
1549
1590
  console.error("Error processing pending updates:", e);
@@ -1554,22 +1595,22 @@ var je = class {
1554
1595
  });
1555
1596
  }
1556
1597
  }
1557
- async postProcessWalletUpdate(e, t) {
1598
+ async postProcessWalletUpdate(e) {
1558
1599
  if (e.length === 0) return;
1559
- let n = /* @__PURE__ */ new Map();
1560
- for (let { txs: t } of e) for (let e of t) n.set(e.tx_hash, e);
1561
- let r = Array.from(n.values());
1562
- t && this.recoverVaults(r), await this.checkGapLimit(C.RECEIVE), await this.checkGapLimit(C.CHANGE);
1563
- let i = this.getMainAddresses(), a = P(i.map((e) => e.balance)), o = F(i.map((e) => e.tokensBalance));
1600
+ let t = /* @__PURE__ */ new Map();
1601
+ for (let { txs: n } of e) for (let e of n) t.set(e.tx_hash, e);
1602
+ let n = Array.from(t.values());
1603
+ await this.checkGapLimit(C.RECEIVE), await this.checkGapLimit(C.CHANGE);
1604
+ let r = this.getMainAddresses(), i = P(r.map((e) => e.balance)), a = F(r.map((e) => e.tokensBalance));
1564
1605
  this.notify({
1565
1606
  type: "account_balance_updated",
1566
1607
  accountId: -1,
1567
- balance: a,
1568
- tokensBalance: o
1608
+ balance: i,
1609
+ tokensBalance: a
1569
1610
  }), this.notify({
1570
1611
  type: "main_address_updated",
1571
1612
  address: this.getReceiveAddress()
1572
- }), await this.postProcessActivity(-1, r, i.map((e) => e.address), o);
1613
+ }), await this.postProcessActivity(-1, n, r.map((e) => e.address), a);
1573
1614
  }
1574
1615
  async postProcessAccountsUpdate(e) {
1575
1616
  if (e.length === 0) return;
@@ -1625,8 +1666,8 @@ var je = class {
1625
1666
  }
1626
1667
  async checkGapLimit(e) {
1627
1668
  let t = e === C.RECEIVE ? this.receiveAddresses : this.changeAddresses, n = e === C.RECEIVE ? "Receive" : "Change", r = t.filter((e) => !e.used).length;
1628
- if (r < B.GAP_LIMIT) {
1629
- let i = B.GAP_LIMIT - r, a = t[t.length - 1].idx;
1669
+ if (r < z.GAP_LIMIT) {
1670
+ let i = z.GAP_LIMIT - r, a = t[t.length - 1].idx;
1630
1671
  console.log(`Deriving ${i} more ${n} addresses...`);
1631
1672
  let o = this.deriveAddresses(e, a + 1, i);
1632
1673
  e === C.RECEIVE ? this.receiveAddresses.push(...o) : this.changeAddresses.push(...o), await this.saveAddresses(o), await this.subscribeAddresses(o);
@@ -1717,10 +1758,10 @@ var je = class {
1717
1758
  }
1718
1759
  }), await this.subscribeAddresses([e]);
1719
1760
  }
1720
- async recoverVaults(e) {
1721
- let t = !1, n = await this.discoveryService.discoverVaults(e), r = [];
1722
- for (let [e, i] of n) this.vaults.has(e) || (t = !0, r.push(this.addVault(i)));
1723
- return await Promise.all(r), t;
1761
+ async recoverVaults() {
1762
+ let e = !1, t = await this.discoveryService.discoverVaults(), n = [];
1763
+ for (let [r, i] of t) this.vaults.has(r) || (e = !0, n.push(this.addVault(i)));
1764
+ return await Promise.all(n), e;
1724
1765
  }
1725
1766
  async recoverTokens() {
1726
1767
  let e = [];
@@ -1737,7 +1778,7 @@ var je = class {
1737
1778
  isMainAddress(e) {
1738
1779
  return e.type == S.MAIN;
1739
1780
  }
1740
- }, Le = class e {
1781
+ }, Ie = class e {
1741
1782
  static {
1742
1783
  this.POLL_INTERVAL_MS = 12e4;
1743
1784
  }
@@ -1818,6 +1859,6 @@ var je = class {
1818
1859
  }), a;
1819
1860
  }
1820
1861
  };
1821
- export { S as AccountType, Ce as AssetService, T as CURRENCIES, se as HD_WALLET_ID, B as KeyManager, C as KeySpace, ce as MAX_INT64, Le as MarketService, be as RostrumService, je as SessionManager, w as SessionRequestType, Ee as TransactionService, Me as TransactionTransformer, G as VAULT_FIRST_BLOCK, we as VAULT_SCRIPT_PREFIX, ye as WalletCache, ve as WalletDB, Ie as WalletManager, _e as calculateFiatValue, fe as capitalizeFirstLetter, E as currencyCodes, k as currentTimestamp, Oe as encryptMnemonic, Te as estimateDateByFutureBlock, De as generateNewMnemonic, Z as generateVaultAddress, J as generateVaultConstraint, X as generateVaultVisibleArgs, j as getAddressBuffer, U as getAssetFileUrl, H as getAssetMetadataUrl, ue as getExplorerUrl, me as getFileMediaType, he as getFileMimeType, Y as getVaultConstraintHash, K as getVaultTemplate, q as getVaultTemplateHash, le as isGenesisHashValid, Q as isMnemonicValid, A as isNullOrEmpty, D as isTestnet, O as isValidNexaAddress, R as keyPathToString, V as parseTokenDataUrl, L as prettifyAmount, ge as sleep, z as stringToKeyPath, P as sumBalance, F as sumTokensBalance, N as tokenAmountToAssetAmount, pe as tokenHexToAddr, M as tokenIdToHex, xe as transformTokenIconUrl, de as truncateStringMiddle, Ae as validateAndDecryptMnemonic };
1862
+ export { S as AccountType, we as AssetService, T as CURRENCIES, se as HD_WALLET_ID, z as KeyManager, C as KeySpace, ce as MAX_INT64, Ie as MarketService, xe as RostrumService, Me as SessionManager, w as SessionRequestType, De as TransactionService, Ne as TransactionTransformer, W as VAULT_FIRST_BLOCK, Te as VAULT_SCRIPT_PREFIX, be as WalletCache, ye as WalletDB, Fe as WalletManager, ve as calculateFiatValue, fe as capitalizeFirstLetter, E as currencyCodes, k as currentTimestamp, ke as encryptMnemonic, Ee as estimateDateByFutureBlock, Oe as generateNewMnemonic, X as generateVaultAddress, q as generateVaultConstraint, Y as generateVaultVisibleArgs, j as getAddressBuffer, H as getAssetFileUrl, V as getAssetMetadataUrl, ue as getExplorerUrl, me as getFileMediaType, he as getFileMimeType, J as getVaultConstraintHash, G as getVaultTemplate, K as getVaultTemplateHash, le as isGenesisHashValid, Z as isMnemonicValid, A as isNullOrEmpty, D as isTestnet, O as isValidNexaAddress, L as keyPathToString, B as parseTokenDataUrl, _e as prettifyAmount, ge as sleep, R as stringToKeyPath, P as sumBalance, F as sumTokensBalance, N as tokenAmountToAssetAmount, pe as tokenHexToAddr, M as tokenIdToHex, Se as transformTokenIconUrl, de as truncateStringMiddle, je as validateAndDecryptMnemonic };
1822
1863
 
1823
1864
  //# sourceMappingURL=index.js.map