@otoplo/wallet-common 0.4.3 → 0.4.5
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 +141 -119
- package/dist/index.js.map +1 -1
- package/dist/types/services/asset.d.ts.map +1 -1
- package/dist/types/services/discovery.d.ts +6 -2
- package/dist/types/services/discovery.d.ts.map +1 -1
- package/dist/types/services/rostrum.d.ts +7 -2
- package/dist/types/services/rostrum.d.ts.map +1 -1
- package/dist/types/services/wallet.d.ts +4 -13
- package/dist/types/services/wallet.d.ts.map +1 -1
- package/dist/types/types/db.types.d.ts +1 -0
- package/dist/types/types/db.types.d.ts.map +1 -1
- package/dist/types/types/rostrum.types.d.ts +4 -17
- package/dist/types/types/rostrum.types.d.ts.map +1 -1
- package/dist/types/types/wallet.types.d.ts +1 -0
- package/dist/types/types/wallet.types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/services/asset.ts +2 -1
- package/src/services/discovery.ts +30 -21
- package/src/services/rostrum.ts +43 -11
- package/src/services/wallet.ts +18 -35
- package/src/types/db.types.ts +1 -0
- package/src/types/rostrum.types.ts +4 -18
- package/src/types/wallet.types.ts +1 -0
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
|
|
189
|
+
function _e(e) {
|
|
190
190
|
return new y(e).stripTrailingZero().getPrettyValue();
|
|
191
191
|
}
|
|
192
|
-
function
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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.
|
|
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.
|
|
458
|
+
return this.paginate("blockchain.address.listunspent", "unspent", (t) => [
|
|
459
|
+
e,
|
|
460
|
+
"exclude_tokens",
|
|
461
|
+
t
|
|
462
|
+
]);
|
|
448
463
|
}
|
|
449
|
-
|
|
450
|
-
return
|
|
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
|
|
577
|
+
function L(e, t, n) {
|
|
549
578
|
return `${e}'/${t}/${n}`;
|
|
550
579
|
}
|
|
551
|
-
function
|
|
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
|
|
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 :
|
|
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" ?
|
|
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
|
|
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
|
|
599
|
-
return e ?
|
|
627
|
+
function B(e) {
|
|
628
|
+
return e ? Ce(e) : null;
|
|
600
629
|
}
|
|
601
|
-
function
|
|
630
|
+
function Ce(e, t = "https://ipfs.nebula.markets/") {
|
|
602
631
|
return e?.startsWith("ipfs://") ? t + e.substring(7) : e;
|
|
603
632
|
}
|
|
604
|
-
function
|
|
605
|
-
return `${
|
|
633
|
+
function V(e) {
|
|
634
|
+
return `${U()}/metadata/${e}`;
|
|
606
635
|
}
|
|
607
|
-
function
|
|
608
|
-
return `${
|
|
636
|
+
function H(e, t) {
|
|
637
|
+
return `${U()}/assets/${e}/${t}`;
|
|
609
638
|
}
|
|
610
|
-
function
|
|
639
|
+
function U() {
|
|
611
640
|
return `https://${D() ? "testapi" : "api"}.otoplo.com`;
|
|
612
641
|
}
|
|
613
642
|
// src/services/asset.ts
|
|
614
|
-
var
|
|
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(
|
|
734
|
+
return this.performGet(H(e, t), "raw");
|
|
705
735
|
}
|
|
706
736
|
getAssetMetadata(e) {
|
|
707
|
-
return this.performGet(
|
|
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
|
-
},
|
|
723
|
-
function
|
|
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
|
|
727
|
-
let e =
|
|
756
|
+
function K() {
|
|
757
|
+
let e = G();
|
|
728
758
|
return s.sha256ripemd160(e.toBuffer());
|
|
729
759
|
}
|
|
730
|
-
function
|
|
760
|
+
function q(e) {
|
|
731
761
|
return f.empty().add(e.toBuffer());
|
|
732
762
|
}
|
|
733
|
-
function
|
|
734
|
-
let t =
|
|
763
|
+
function J(e) {
|
|
764
|
+
let t = q(e);
|
|
735
765
|
return s.sha256ripemd160(t.toBuffer());
|
|
736
766
|
}
|
|
737
|
-
function
|
|
767
|
+
function Y(e) {
|
|
738
768
|
return e.map((e) => e <= 16 ? p.smallInt(e) : n.fromNumber(e).toScriptNumBuffer());
|
|
739
769
|
}
|
|
740
|
-
function
|
|
770
|
+
function X(t, n) {
|
|
741
771
|
if (n.length !== 2) return;
|
|
742
|
-
let r =
|
|
772
|
+
let r = K(), i = J(t), a = Y(n);
|
|
743
773
|
return e.fromScriptTemplate(r, i, a).toString();
|
|
744
774
|
}
|
|
745
|
-
function
|
|
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
|
|
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,
|
|
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
|
|
967
|
+
function Oe(e = 12) {
|
|
938
968
|
return re(x, e === 24 ? 256 : 128);
|
|
939
969
|
}
|
|
940
|
-
function
|
|
970
|
+
function Z(e) {
|
|
941
971
|
return ae(e, x);
|
|
942
972
|
}
|
|
943
|
-
async function
|
|
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
|
|
956
|
-
let n = r.utf8ToBuffer(t), i = r.getRandomBuffer(16), a = r.getRandomBuffer(12), o = r.utf8ToBuffer(e), s = await
|
|
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
|
|
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
|
|
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
|
|
1003
|
+
async function je(e, t) {
|
|
974
1004
|
try {
|
|
975
1005
|
if (e) {
|
|
976
|
-
let n = await
|
|
977
|
-
if (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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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:
|
|
1264
|
-
if (a.some((e) => e)) r = n, i = a, n +=
|
|
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 =
|
|
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(
|
|
1272
|
-
let
|
|
1273
|
-
return
|
|
1274
|
-
let
|
|
1275
|
-
|
|
1276
|
-
}),
|
|
1277
|
-
}
|
|
1278
|
-
async checkForVaults(
|
|
1279
|
-
let
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
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 ==
|
|
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
|
-
},
|
|
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
|
|
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:
|
|
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:
|
|
1392
|
+
keyPath: L(S.MAIN, e.space, e.idx),
|
|
1356
1393
|
balance: e.balance,
|
|
1357
1394
|
tokensBalance: e.tokensBalance
|
|
1358
1395
|
}));
|
|
@@ -1366,36 +1403,21 @@ var je = class {
|
|
|
1366
1403
|
tip: e
|
|
1367
1404
|
}));
|
|
1368
1405
|
}
|
|
1369
|
-
async initialize() {
|
|
1370
|
-
await this.initRostrum(), await this.walletDb.countAddresses() ? await this.loadWallet() : await this.discoverWallet();
|
|
1371
|
-
}
|
|
1372
1406
|
async discoverWallet() {
|
|
1373
|
-
this.
|
|
1374
|
-
type: "discover_wallet",
|
|
1375
|
-
loading: !0
|
|
1376
|
-
});
|
|
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([
|
|
1407
|
+
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
1408
|
e,
|
|
1379
1409
|
t,
|
|
1380
|
-
n
|
|
1410
|
+
n,
|
|
1411
|
+
r
|
|
1381
1412
|
]);
|
|
1382
|
-
this.receiveAddresses = this.deriveAddresses(C.RECEIVE, 0,
|
|
1383
|
-
type: "discover_wallet",
|
|
1384
|
-
loading: !1
|
|
1385
|
-
}), this.notify({
|
|
1386
|
-
type: "load_wallet",
|
|
1387
|
-
loading: !1
|
|
1388
|
-
});
|
|
1413
|
+
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();
|
|
1389
1414
|
}
|
|
1390
1415
|
async loadWallet() {
|
|
1391
1416
|
this.receiveAddresses = await this.walletDb.getReceiveAddresses(), this.changeAddresses = await this.walletDb.getChangeAddresses();
|
|
1392
1417
|
let e = await this.walletDb.getAccounts();
|
|
1393
1418
|
this.accounts = new Map(e.map((e) => [e.id, e])), this.accountsAddressToId = new Map(e.map((e) => [e.address, e.id]));
|
|
1394
1419
|
let t = await this.walletDb.getVaults();
|
|
1395
|
-
this.vaults = new Map(t.map((e) => [e.address, e])), this.initState(), this.
|
|
1396
|
-
type: "load_wallet",
|
|
1397
|
-
loading: !1
|
|
1398
|
-
}), await this.reconnectSync();
|
|
1420
|
+
this.vaults = new Map(t.map((e) => [e.address, e])), this.initState(), await this.reconnectSync();
|
|
1399
1421
|
}
|
|
1400
1422
|
async initialSync() {
|
|
1401
1423
|
await this.subscribeAddresses(this.getAllAddresses(), !0);
|
|
@@ -1485,6 +1507,9 @@ var je = class {
|
|
|
1485
1507
|
async saveAccounts(e) {
|
|
1486
1508
|
for (let t of e.values()) await this.walletDb.saveAccount(t);
|
|
1487
1509
|
}
|
|
1510
|
+
async saveVaults(e) {
|
|
1511
|
+
for (let t of e.values()) await this.walletDb.saveVault(t);
|
|
1512
|
+
}
|
|
1488
1513
|
async subscribeAddresses(e, t = !1) {
|
|
1489
1514
|
let n = e.map(async (e) => ({
|
|
1490
1515
|
addr: e,
|
|
@@ -1543,7 +1568,7 @@ var je = class {
|
|
|
1543
1568
|
}
|
|
1544
1569
|
let a = await Promise.all(t);
|
|
1545
1570
|
await Promise.all(n);
|
|
1546
|
-
let o = await Promise.all(r), s = [this.postProcessWalletUpdate(o
|
|
1571
|
+
let o = await Promise.all(r), s = [this.postProcessWalletUpdate(o), this.postProcessAccountsUpdate(a)];
|
|
1547
1572
|
i && s.push(this.recoverTokens()), await Promise.all(s), i && this.discoveryResolver && (this.discoveryResolver(), this.discoveryResolver = void 0);
|
|
1548
1573
|
} catch (e) {
|
|
1549
1574
|
console.error("Error processing pending updates:", e);
|
|
@@ -1554,22 +1579,19 @@ var je = class {
|
|
|
1554
1579
|
});
|
|
1555
1580
|
}
|
|
1556
1581
|
}
|
|
1557
|
-
async postProcessWalletUpdate(e
|
|
1582
|
+
async postProcessWalletUpdate(e) {
|
|
1558
1583
|
if (e.length === 0) return;
|
|
1559
|
-
let
|
|
1560
|
-
for (let { txs:
|
|
1561
|
-
let
|
|
1562
|
-
|
|
1563
|
-
let
|
|
1584
|
+
let t = /* @__PURE__ */ new Map();
|
|
1585
|
+
for (let { txs: n } of e) for (let e of n) t.set(e.tx_hash, e);
|
|
1586
|
+
let n = Array.from(t.values());
|
|
1587
|
+
await this.checkGapLimit(C.RECEIVE), await this.checkGapLimit(C.CHANGE);
|
|
1588
|
+
let r = this.getMainAddresses(), i = P(r.map((e) => e.balance)), a = F(r.map((e) => e.tokensBalance));
|
|
1564
1589
|
this.notify({
|
|
1565
1590
|
type: "account_balance_updated",
|
|
1566
1591
|
accountId: -1,
|
|
1567
|
-
balance:
|
|
1568
|
-
tokensBalance:
|
|
1569
|
-
}), this.
|
|
1570
|
-
type: "main_address_updated",
|
|
1571
|
-
address: this.getReceiveAddress()
|
|
1572
|
-
}), await this.postProcessActivity(-1, r, i.map((e) => e.address), o);
|
|
1592
|
+
balance: i,
|
|
1593
|
+
tokensBalance: a
|
|
1594
|
+
}), await this.postProcessActivity(-1, n, r.map((e) => e.address), a);
|
|
1573
1595
|
}
|
|
1574
1596
|
async postProcessAccountsUpdate(e) {
|
|
1575
1597
|
if (e.length === 0) return;
|
|
@@ -1625,8 +1647,8 @@ var je = class {
|
|
|
1625
1647
|
}
|
|
1626
1648
|
async checkGapLimit(e) {
|
|
1627
1649
|
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 <
|
|
1629
|
-
let i =
|
|
1650
|
+
if (r < z.GAP_LIMIT) {
|
|
1651
|
+
let i = z.GAP_LIMIT - r, a = t[t.length - 1].idx;
|
|
1630
1652
|
console.log(`Deriving ${i} more ${n} addresses...`);
|
|
1631
1653
|
let o = this.deriveAddresses(e, a + 1, i);
|
|
1632
1654
|
e === C.RECEIVE ? this.receiveAddresses.push(...o) : this.changeAddresses.push(...o), await this.saveAddresses(o), await this.subscribeAddresses(o);
|
|
@@ -1717,10 +1739,10 @@ var je = class {
|
|
|
1717
1739
|
}
|
|
1718
1740
|
}), await this.subscribeAddresses([e]);
|
|
1719
1741
|
}
|
|
1720
|
-
async recoverVaults(
|
|
1721
|
-
let
|
|
1722
|
-
for (let [
|
|
1723
|
-
return await Promise.all(
|
|
1742
|
+
async recoverVaults() {
|
|
1743
|
+
let e = !1, t = await this.discoveryService.discoverVaults(), n = [];
|
|
1744
|
+
for (let [r, i] of t) this.vaults.has(r) || (e = !0, n.push(this.addVault(i)));
|
|
1745
|
+
return await Promise.all(n), e;
|
|
1724
1746
|
}
|
|
1725
1747
|
async recoverTokens() {
|
|
1726
1748
|
let e = [];
|
|
@@ -1737,7 +1759,7 @@ var je = class {
|
|
|
1737
1759
|
isMainAddress(e) {
|
|
1738
1760
|
return e.type == S.MAIN;
|
|
1739
1761
|
}
|
|
1740
|
-
},
|
|
1762
|
+
}, Ie = class e {
|
|
1741
1763
|
static {
|
|
1742
1764
|
this.POLL_INTERVAL_MS = 12e4;
|
|
1743
1765
|
}
|
|
@@ -1818,6 +1840,6 @@ var je = class {
|
|
|
1818
1840
|
}), a;
|
|
1819
1841
|
}
|
|
1820
1842
|
};
|
|
1821
|
-
export { S as AccountType,
|
|
1843
|
+
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
1844
|
|
|
1823
1845
|
//# sourceMappingURL=index.js.map
|