@otoplo/wallet-common 0.4.2 → 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 +246 -224
- 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/market.d.ts +1 -1
- package/dist/types/services/market.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/transaction.d.ts.map +1 -1
- package/dist/types/services/wallet.d.ts +2 -1
- 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/dist/types/utils/common.d.ts +42 -4
- package/dist/types/utils/common.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +0 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/vault.d.ts +3 -0
- package/dist/types/utils/vault.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/market.ts +1 -1
- package/src/services/rostrum.ts +43 -11
- package/src/services/transaction.ts +2 -1
- package/src/services/wallet.ts +16 -11
- 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/src/utils/common.ts +26 -15
- package/src/utils/index.ts +0 -1
- package/src/utils/vault.ts +12 -2
- package/dist/types/utils/market.d.ts +0 -45
- package/dist/types/utils/market.d.ts.map +0 -1
- package/src/utils/market.ts +0 -43
package/dist/index.js
CHANGED
|
@@ -11,50 +11,83 @@ var S = /* @__PURE__ */ function(e) {
|
|
|
11
11
|
return e[e.RECEIVE = 0] = "RECEIVE", e[e.CHANGE = 1] = "CHANGE", e;
|
|
12
12
|
}({}), w = /* @__PURE__ */ function(e) {
|
|
13
13
|
return e.SignMessage = "signMessage", e.AddToken = "addToken", e.SignTransaction = "signTransaction", e.SendTransaction = "sendTransaction", e;
|
|
14
|
-
}({}), se = -1, ce = 9223372036854775807n, T =
|
|
15
|
-
|
|
14
|
+
}({}), se = -1, ce = 9223372036854775807n, T = {
|
|
15
|
+
usd: {
|
|
16
|
+
symbol: "$",
|
|
17
|
+
name: "US Dollar"
|
|
18
|
+
},
|
|
19
|
+
eur: {
|
|
20
|
+
symbol: "€",
|
|
21
|
+
name: "Euro"
|
|
22
|
+
},
|
|
23
|
+
gbp: {
|
|
24
|
+
symbol: "£",
|
|
25
|
+
name: "British Pound"
|
|
26
|
+
},
|
|
27
|
+
aud: {
|
|
28
|
+
symbol: "A$",
|
|
29
|
+
name: "Australian Dollar"
|
|
30
|
+
},
|
|
31
|
+
cad: {
|
|
32
|
+
symbol: "CA$",
|
|
33
|
+
name: "Canadian Dollar"
|
|
34
|
+
},
|
|
35
|
+
chf: {
|
|
36
|
+
symbol: "CHF",
|
|
37
|
+
name: "Swiss Franc"
|
|
38
|
+
},
|
|
39
|
+
inr: {
|
|
40
|
+
symbol: "₹",
|
|
41
|
+
name: "Indian Rupee"
|
|
42
|
+
},
|
|
43
|
+
cny: {
|
|
44
|
+
symbol: "CN¥",
|
|
45
|
+
name: "Chinese Yuan"
|
|
46
|
+
},
|
|
47
|
+
jpy: {
|
|
48
|
+
symbol: "¥",
|
|
49
|
+
name: "Japanese Yen"
|
|
50
|
+
}
|
|
51
|
+
}, E = Object.keys(T);
|
|
52
|
+
function D() {
|
|
16
53
|
return c.defaultNetwork == c.testnet;
|
|
17
54
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
55
|
+
function le(e) {
|
|
56
|
+
return D() ? e == "508c843a4b98fb25f57cf9ebafb245a5c16468f06519cdd467059a91e7b79d52" : e == "edc7144fe1ba4edd0edf35d7eea90f6cb1dba42314aa85da8207e97c5339c801";
|
|
20
57
|
}
|
|
21
|
-
function
|
|
58
|
+
function O(n, r = t.PayToScriptTemplate) {
|
|
22
59
|
return e.isValid(n, c.defaultNetwork, r);
|
|
23
60
|
}
|
|
24
|
-
function
|
|
25
|
-
return `https://${
|
|
61
|
+
function ue() {
|
|
62
|
+
return `https://${D() ? "testnet-" : ""}explorer.nexa.org`;
|
|
26
63
|
}
|
|
27
|
-
function
|
|
64
|
+
function k() {
|
|
28
65
|
return Math.floor(Date.now() / 1e3);
|
|
29
66
|
}
|
|
30
|
-
function
|
|
31
|
-
let n = (t - e) * 2, r = /* @__PURE__ */ new Date();
|
|
32
|
-
return r.setMinutes(r.getMinutes() + n), r.toLocaleDateString();
|
|
33
|
-
}
|
|
34
|
-
function k(e) {
|
|
67
|
+
function A(e) {
|
|
35
68
|
return !e || e.length === 0;
|
|
36
69
|
}
|
|
37
|
-
function
|
|
70
|
+
function de(e, t = 0) {
|
|
38
71
|
if (!e || e.length <= t) return e || "";
|
|
39
72
|
let n = Math.floor((t - 3) / 2), r = e.slice(0, n), i = e.slice(e.length - n);
|
|
40
73
|
return r + "..." + i;
|
|
41
74
|
}
|
|
42
|
-
function
|
|
75
|
+
function fe(e) {
|
|
43
76
|
return e.length === 0 ? "" : e.charAt(0).toUpperCase() + e.substring(1);
|
|
44
77
|
}
|
|
45
|
-
function
|
|
78
|
+
function j(t) {
|
|
46
79
|
return a.isHexa(t) ? r.hexToBuffer(t) : e.fromString(t).data;
|
|
47
80
|
}
|
|
48
|
-
function
|
|
49
|
-
return a.isHexa(e) ? e : r.bufferToHex(
|
|
81
|
+
function M(e) {
|
|
82
|
+
return a.isHexa(e) ? e : r.bufferToHex(j(e));
|
|
50
83
|
}
|
|
51
|
-
function
|
|
52
|
-
return a.isHexa(n) ? new e(
|
|
84
|
+
function pe(n) {
|
|
85
|
+
return a.isHexa(n) ? new e(j(n), c.defaultNetwork, t.GroupIdAddress).toString() : n;
|
|
53
86
|
}
|
|
54
|
-
function
|
|
87
|
+
function N(e) {
|
|
55
88
|
return e == null || e === "" ? "" : BigInt(e) <= 0n ? "0" : e.toString();
|
|
56
89
|
}
|
|
57
|
-
function
|
|
90
|
+
function P(e) {
|
|
58
91
|
let t = BigInt(0), n = BigInt(0);
|
|
59
92
|
return e.forEach((e) => {
|
|
60
93
|
t += BigInt(e.confirmed), n += BigInt(e.unconfirmed);
|
|
@@ -63,7 +96,7 @@ function N(e) {
|
|
|
63
96
|
unconfirmed: n.toString()
|
|
64
97
|
};
|
|
65
98
|
}
|
|
66
|
-
function
|
|
99
|
+
function F(e) {
|
|
67
100
|
let t = {};
|
|
68
101
|
return e.forEach((e) => {
|
|
69
102
|
for (let n in e) t[n] ? (t[n].confirmed = (BigInt(t[n].confirmed) + BigInt(e[n].confirmed)).toString(), t[n].unconfirmed = (BigInt(t[n].unconfirmed) + BigInt(e[n].unconfirmed)).toString()) : t[n] = {
|
|
@@ -72,7 +105,7 @@ function P(e) {
|
|
|
72
105
|
};
|
|
73
106
|
}), t;
|
|
74
107
|
}
|
|
75
|
-
var
|
|
108
|
+
var I = {
|
|
76
109
|
".gif": {
|
|
77
110
|
media: "image",
|
|
78
111
|
mime: "image/gif"
|
|
@@ -142,23 +175,29 @@ var F = {
|
|
|
142
175
|
mime: "audio/mp4"
|
|
143
176
|
}
|
|
144
177
|
};
|
|
145
|
-
function
|
|
178
|
+
function me(e) {
|
|
146
179
|
let t = e.lastIndexOf(".");
|
|
147
|
-
return t === -1 ? "unknown" :
|
|
180
|
+
return t === -1 ? "unknown" : I[e.slice(t).toLowerCase()]?.media ?? "unknown";
|
|
148
181
|
}
|
|
149
|
-
function
|
|
182
|
+
function he(e) {
|
|
150
183
|
let t = e.lastIndexOf(".");
|
|
151
|
-
return t === -1 ? "application/octet-stream" :
|
|
184
|
+
return t === -1 ? "application/octet-stream" : I[e.slice(t).toLowerCase()]?.mime ?? "application/octet-stream";
|
|
152
185
|
}
|
|
153
|
-
function
|
|
186
|
+
function ge(e) {
|
|
154
187
|
return new Promise((t) => setTimeout(t, e));
|
|
155
188
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
189
|
+
function _e(e) {
|
|
190
|
+
return new y(e).stripTrailingZero().getPrettyValue();
|
|
191
|
+
}
|
|
192
|
+
function ve(e, t, n, r = "en-US") {
|
|
193
|
+
let i = y.multiply(e, t);
|
|
194
|
+
return new Intl.NumberFormat(r, {
|
|
195
|
+
style: "currency",
|
|
196
|
+
currency: n
|
|
197
|
+
}).format(Number(i));
|
|
159
198
|
}
|
|
160
199
|
// src/persistence/wallet-db.ts
|
|
161
|
-
var
|
|
200
|
+
var ye = class {
|
|
162
201
|
constructor(e) {
|
|
163
202
|
this.repository = e;
|
|
164
203
|
}
|
|
@@ -207,7 +246,7 @@ var be = class {
|
|
|
207
246
|
accountId: e,
|
|
208
247
|
tokenIdHex: t.tokenIdHex,
|
|
209
248
|
type: "token",
|
|
210
|
-
addedTime:
|
|
249
|
+
addedTime: k()
|
|
211
250
|
};
|
|
212
251
|
await this.repository.upsertToken(t), await this.saveAsset(n);
|
|
213
252
|
}
|
|
@@ -347,7 +386,7 @@ var be = class {
|
|
|
347
386
|
removeSetting(e) {
|
|
348
387
|
return this.repository.deleteSetting(e);
|
|
349
388
|
}
|
|
350
|
-
},
|
|
389
|
+
}, be = class {
|
|
351
390
|
constructor(e) {
|
|
352
391
|
this.tokens = /* @__PURE__ */ new Map(), this.nfts = /* @__PURE__ */ new Map(), this.walletDb = e;
|
|
353
392
|
}
|
|
@@ -355,22 +394,22 @@ var be = class {
|
|
|
355
394
|
this.tokens.clear(), this.nfts.clear();
|
|
356
395
|
}
|
|
357
396
|
async getToken(e) {
|
|
358
|
-
if (e =
|
|
397
|
+
if (e = M(e), this.tokens.has(e)) return this.tokens.get(e);
|
|
359
398
|
let t = await this.walletDb.getToken(e);
|
|
360
399
|
return t && this.tokens.set(e, t), t;
|
|
361
400
|
}
|
|
362
401
|
async getNft(e) {
|
|
363
|
-
if (e =
|
|
402
|
+
if (e = M(e), this.nfts.has(e)) return this.nfts.get(e);
|
|
364
403
|
let t = await this.walletDb.getNft(e);
|
|
365
404
|
return t && this.nfts.set(e, t), t;
|
|
366
405
|
}
|
|
367
406
|
removeToken(e) {
|
|
368
|
-
this.tokens.delete(
|
|
407
|
+
this.tokens.delete(M(e));
|
|
369
408
|
}
|
|
370
409
|
removeNft(e) {
|
|
371
|
-
this.nfts.delete(
|
|
410
|
+
this.nfts.delete(M(e));
|
|
372
411
|
}
|
|
373
|
-
},
|
|
412
|
+
}, xe = class e {
|
|
374
413
|
constructor(e) {
|
|
375
414
|
this.walletDb = e;
|
|
376
415
|
}
|
|
@@ -384,7 +423,18 @@ var be = class {
|
|
|
384
423
|
return this.execute("blockchain.address.get_balance", e, "exclude_tokens");
|
|
385
424
|
}
|
|
386
425
|
getTransactionsHistory(e, t = 0) {
|
|
387
|
-
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
|
+
]);
|
|
388
438
|
}
|
|
389
439
|
getFirstUse(e) {
|
|
390
440
|
return this.execute("blockchain.address.get_first_use", e);
|
|
@@ -405,10 +455,18 @@ var be = class {
|
|
|
405
455
|
return this.execute("blockchain.utxo.get", e);
|
|
406
456
|
}
|
|
407
457
|
getNexaUtxos(e) {
|
|
408
|
-
return this.
|
|
458
|
+
return this.paginate("blockchain.address.listunspent", "unspent", (t) => [
|
|
459
|
+
e,
|
|
460
|
+
"exclude_tokens",
|
|
461
|
+
t
|
|
462
|
+
]);
|
|
409
463
|
}
|
|
410
|
-
|
|
411
|
-
return
|
|
464
|
+
getTokenUtxos(e, t) {
|
|
465
|
+
return this.paginate("token.address.listunspent", "unspent", (n) => [
|
|
466
|
+
e,
|
|
467
|
+
n,
|
|
468
|
+
t
|
|
469
|
+
]);
|
|
412
470
|
}
|
|
413
471
|
async getTokensBalance(e) {
|
|
414
472
|
let t = await this.execute("token.address.get_balance", e), n = {};
|
|
@@ -422,9 +480,6 @@ var be = class {
|
|
|
422
480
|
});
|
|
423
481
|
return n;
|
|
424
482
|
}
|
|
425
|
-
getTokenGenesis(e) {
|
|
426
|
-
return this.execute("token.genesis.info", e);
|
|
427
|
-
}
|
|
428
483
|
broadcast(e) {
|
|
429
484
|
return this.execute("blockchain.transaction.broadcast", e);
|
|
430
485
|
}
|
|
@@ -459,6 +514,19 @@ var be = class {
|
|
|
459
514
|
return console.error(e), !1;
|
|
460
515
|
}
|
|
461
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
|
+
}
|
|
462
530
|
async execute(e, ...t) {
|
|
463
531
|
await this.waitForConnection();
|
|
464
532
|
let n = await this.client.request(e, ...t);
|
|
@@ -487,7 +555,7 @@ var be = class {
|
|
|
487
555
|
return t ? JSON.parse(t) : e.getPredefinedInstances()[0];
|
|
488
556
|
}
|
|
489
557
|
static getPredefinedInstances() {
|
|
490
|
-
return
|
|
558
|
+
return D() ? [{
|
|
491
559
|
scheme: b.WSS,
|
|
492
560
|
host: "testnet-electrum.nexa.org",
|
|
493
561
|
port: 30004,
|
|
@@ -506,10 +574,10 @@ var be = class {
|
|
|
506
574
|
}
|
|
507
575
|
};
|
|
508
576
|
// src/utils/keypath.ts
|
|
509
|
-
function
|
|
577
|
+
function L(e, t, n) {
|
|
510
578
|
return `${e}'/${t}/${n}`;
|
|
511
579
|
}
|
|
512
|
-
function
|
|
580
|
+
function R(e) {
|
|
513
581
|
let t = e.split("/");
|
|
514
582
|
return {
|
|
515
583
|
account: parseInt(t[0].replace("'", "")),
|
|
@@ -518,7 +586,7 @@ function L(e) {
|
|
|
518
586
|
};
|
|
519
587
|
}
|
|
520
588
|
// src/services/key.ts
|
|
521
|
-
var
|
|
589
|
+
var z = class {
|
|
522
590
|
constructor() {
|
|
523
591
|
this.accountKeys = /* @__PURE__ */ new Map(), this.walletKeys = /* @__PURE__ */ new Map();
|
|
524
592
|
}
|
|
@@ -544,35 +612,35 @@ var R = class {
|
|
|
544
612
|
}).privateKey.toAddress().toString();
|
|
545
613
|
}
|
|
546
614
|
getKey(e) {
|
|
547
|
-
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);
|
|
548
616
|
if (!n) {
|
|
549
|
-
let { account: r, type: i, index: a } = typeof e == "string" ?
|
|
617
|
+
let { account: r, type: i, index: a } = typeof e == "string" ? R(e) : e;
|
|
550
618
|
n = this.getAccountKey(r).deriveChild(i, !1).deriveChild(a, !1), this.walletKeys.set(t, n);
|
|
551
619
|
}
|
|
552
620
|
return n;
|
|
553
621
|
}
|
|
554
622
|
};
|
|
555
623
|
// src/utils/asset.ts
|
|
556
|
-
function
|
|
624
|
+
function Se(e, t) {
|
|
557
625
|
return e && typeof e == "string" ? e.startsWith("http") ? e.replace("http://", "https://") : e.startsWith("ipfs://") ? e : `${new URL(t).origin}${e}` : "";
|
|
558
626
|
}
|
|
559
|
-
function
|
|
560
|
-
return e ?
|
|
627
|
+
function B(e) {
|
|
628
|
+
return e ? Ce(e) : null;
|
|
561
629
|
}
|
|
562
|
-
function
|
|
630
|
+
function Ce(e, t = "https://ipfs.nebula.markets/") {
|
|
563
631
|
return e?.startsWith("ipfs://") ? t + e.substring(7) : e;
|
|
564
632
|
}
|
|
565
|
-
function
|
|
566
|
-
return `${
|
|
633
|
+
function V(e) {
|
|
634
|
+
return `${U()}/metadata/${e}`;
|
|
567
635
|
}
|
|
568
|
-
function
|
|
569
|
-
return `${
|
|
636
|
+
function H(e, t) {
|
|
637
|
+
return `${U()}/assets/${e}/${t}`;
|
|
570
638
|
}
|
|
571
|
-
function
|
|
572
|
-
return `https://${
|
|
639
|
+
function U() {
|
|
640
|
+
return `https://${D() ? "testapi" : "api"}.otoplo.com`;
|
|
573
641
|
}
|
|
574
642
|
// src/services/asset.ts
|
|
575
|
-
var
|
|
643
|
+
var we = class {
|
|
576
644
|
constructor(e, t) {
|
|
577
645
|
this.walletDb = e, this.walletCache = t;
|
|
578
646
|
}
|
|
@@ -604,7 +672,8 @@ var Ee = class {
|
|
|
604
672
|
author: n.author,
|
|
605
673
|
public: n.public,
|
|
606
674
|
front: n.front,
|
|
607
|
-
back: n.back
|
|
675
|
+
back: n.back,
|
|
676
|
+
thumb: n.thumb
|
|
608
677
|
}
|
|
609
678
|
} : await this.getAssetMetadata(e);
|
|
610
679
|
} catch (e) {
|
|
@@ -645,8 +714,8 @@ var Ee = class {
|
|
|
645
714
|
let n = Object.keys(t), r = await this.walletDb.getAssets(e, "nft"), i = r?.filter((e) => !n.includes(e.tokenIdHex)) ?? [];
|
|
646
715
|
for (let t of i) await this.deleteNft(e, t.tokenIdHex);
|
|
647
716
|
for (let [n, i] of Object.entries(t)) {
|
|
648
|
-
let t =
|
|
649
|
-
!a && !o || a && o || (!a && o ? await this.deleteNft(e, t) : await this.handleNftReceive(e, t,
|
|
717
|
+
let t = M(n), a = i && BigInt(i.confirmed) + BigInt(i.unconfirmed) > 0n, o = r?.some((e) => e.tokenIdHex == t);
|
|
718
|
+
!a && !o || a && o || (!a && o ? await this.deleteNft(e, t) : await this.handleNftReceive(e, t, k()));
|
|
650
719
|
}
|
|
651
720
|
}
|
|
652
721
|
async saveToken(e, t) {
|
|
@@ -662,10 +731,10 @@ var Ee = class {
|
|
|
662
731
|
await this.walletDb.deleteNft(e, t), this.walletCache.removeNft(t);
|
|
663
732
|
}
|
|
664
733
|
getAssetFile(e, t) {
|
|
665
|
-
return this.performGet(
|
|
734
|
+
return this.performGet(H(e, t), "raw");
|
|
666
735
|
}
|
|
667
736
|
getAssetMetadata(e) {
|
|
668
|
-
return this.performGet(
|
|
737
|
+
return this.performGet(V(e), "json");
|
|
669
738
|
}
|
|
670
739
|
async performGet(e, t) {
|
|
671
740
|
try {
|
|
@@ -680,7 +749,35 @@ var Ee = class {
|
|
|
680
749
|
throw Error(`Unexpected Error: ${e}`);
|
|
681
750
|
}
|
|
682
751
|
}
|
|
683
|
-
},
|
|
752
|
+
}, W = 274710, Te = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
753
|
+
function G() {
|
|
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);
|
|
755
|
+
}
|
|
756
|
+
function K() {
|
|
757
|
+
let e = G();
|
|
758
|
+
return s.sha256ripemd160(e.toBuffer());
|
|
759
|
+
}
|
|
760
|
+
function q(e) {
|
|
761
|
+
return f.empty().add(e.toBuffer());
|
|
762
|
+
}
|
|
763
|
+
function J(e) {
|
|
764
|
+
let t = q(e);
|
|
765
|
+
return s.sha256ripemd160(t.toBuffer());
|
|
766
|
+
}
|
|
767
|
+
function Y(e) {
|
|
768
|
+
return e.map((e) => e <= 16 ? p.smallInt(e) : n.fromNumber(e).toScriptNumBuffer());
|
|
769
|
+
}
|
|
770
|
+
function X(t, n) {
|
|
771
|
+
if (n.length !== 2) return;
|
|
772
|
+
let r = K(), i = J(t), a = Y(n);
|
|
773
|
+
return e.fromScriptTemplate(r, i, a).toString();
|
|
774
|
+
}
|
|
775
|
+
function Ee(e, t) {
|
|
776
|
+
let n = (t - e) * 2, r = /* @__PURE__ */ new Date();
|
|
777
|
+
return r.setMinutes(r.getMinutes() + n), r.toLocaleDateString();
|
|
778
|
+
}
|
|
779
|
+
// src/services/transaction.ts
|
|
780
|
+
var De = class {
|
|
684
781
|
constructor(e, t, n) {
|
|
685
782
|
this.MAX_INPUTS_OUTPUTS = 250, this.rostrumService = e, this.keyManager = t, this.walletDb = n;
|
|
686
783
|
}
|
|
@@ -696,7 +793,7 @@ var Ee = class {
|
|
|
696
793
|
};
|
|
697
794
|
}
|
|
698
795
|
async fetchVaultTransactions(e) {
|
|
699
|
-
let t = await this.rostrumService.getTransactionsHistory(e,
|
|
796
|
+
let t = await this.rostrumService.getTransactionsHistory(e, W), n = [];
|
|
700
797
|
for (let r of t) {
|
|
701
798
|
let t = this.classifyTransaction(r.tx_hash, [e]);
|
|
702
799
|
n.push(t);
|
|
@@ -723,17 +820,17 @@ var Ee = class {
|
|
|
723
820
|
address: e.addresses[0],
|
|
724
821
|
nexaAmount: e.value_satoshi.toString(),
|
|
725
822
|
assetId: e.token_id_hex ?? "",
|
|
726
|
-
assetAmount:
|
|
823
|
+
assetAmount: N(e.groupQuantity)
|
|
727
824
|
};
|
|
728
825
|
t.includes(n.address) ? r.push(n) : i.push(n);
|
|
729
826
|
}
|
|
730
827
|
for (let e of n.vout) {
|
|
731
|
-
if (
|
|
828
|
+
if (A(e.scriptPubKey.addresses)) continue;
|
|
732
829
|
let n = {
|
|
733
830
|
address: e.scriptPubKey.addresses[0],
|
|
734
831
|
nexaAmount: e.value_satoshi.toString(),
|
|
735
832
|
assetId: e.scriptPubKey.token_id_hex ?? "",
|
|
736
|
-
assetAmount:
|
|
833
|
+
assetAmount: N(e.scriptPubKey.groupQuantity)
|
|
737
834
|
};
|
|
738
835
|
t.includes(n.address) ? a.push(n) : o.push(n);
|
|
739
836
|
}
|
|
@@ -744,7 +841,7 @@ var Ee = class {
|
|
|
744
841
|
accountId: 0,
|
|
745
842
|
txId: n.txid,
|
|
746
843
|
txIdem: n.txidem,
|
|
747
|
-
time: c ? n.time :
|
|
844
|
+
time: c ? n.time : k(),
|
|
748
845
|
height: c ? n.height : 0,
|
|
749
846
|
type: s,
|
|
750
847
|
fee: n.fee_satoshi.toString(),
|
|
@@ -769,12 +866,12 @@ var Ee = class {
|
|
|
769
866
|
return this.finalizeTransaction(i, Array.from(a.values()));
|
|
770
867
|
}
|
|
771
868
|
prepareTransaction(n, r, i, a) {
|
|
772
|
-
if (!
|
|
869
|
+
if (!O(n) && !O(n, t.PayToPublicKeyHash)) throw Error("Invalid Address.");
|
|
773
870
|
if (i && BigInt(r) < 1n || !i && parseInt(r) < h.DUST_AMOUNT) throw Error("The amount is too low.");
|
|
774
871
|
if (i && BigInt(r) > 9223372036854775807n || !i && parseInt(r) > h.MAX_MONEY) throw Error("The amount is too high.");
|
|
775
872
|
let o = new g();
|
|
776
873
|
if (a && o.addData(a), i) {
|
|
777
|
-
if (!
|
|
874
|
+
if (!O(i, t.GroupIdAddress)) throw Error("Invalid Token ID");
|
|
778
875
|
if (e.getOutputType(n) === 0) throw Error("Token must be sent to script template address");
|
|
779
876
|
o.to(n, h.DUST_AMOUNT, i, BigInt(r));
|
|
780
877
|
} else o.to(n, r);
|
|
@@ -782,7 +879,7 @@ var Ee = class {
|
|
|
782
879
|
}
|
|
783
880
|
async populateNexaInputsAndChange(e, t, n, r) {
|
|
784
881
|
let i = t.filter((e) => BigInt(e.balance.confirmed) + BigInt(e.balance.unconfirmed) > 0n);
|
|
785
|
-
if (
|
|
882
|
+
if (A(i)) throw Error("Not enough Nexa balance.");
|
|
786
883
|
let a = /* @__PURE__ */ new Map(), o = r.isConsolidate ? 0 : Number(e.transaction.outputs.find((e) => e.value > 0n).value);
|
|
787
884
|
for (let t of i) {
|
|
788
885
|
let i = await this.rostrumService.getNexaUtxos(t.address);
|
|
@@ -829,8 +926,8 @@ var Ee = class {
|
|
|
829
926
|
throw Error(JSON.stringify(s));
|
|
830
927
|
}
|
|
831
928
|
async populateTokenInputsAndChange(e, t, n, r, i) {
|
|
832
|
-
let a =
|
|
833
|
-
if (
|
|
929
|
+
let a = M(r), o = t.filter((e) => Object.keys(e.tokensBalance).includes(a));
|
|
930
|
+
if (A(o)) throw Error("Not enough token balance.");
|
|
834
931
|
let s = /* @__PURE__ */ new Map(), c = 0n;
|
|
835
932
|
for (let t of o) {
|
|
836
933
|
let a = await this.rostrumService.getTokenUtxos(t.address, r);
|
|
@@ -870,10 +967,10 @@ var Ee = class {
|
|
|
870
967
|
function Oe(e = 12) {
|
|
871
968
|
return re(x, e === 24 ? 256 : 128);
|
|
872
969
|
}
|
|
873
|
-
function
|
|
970
|
+
function Z(e) {
|
|
874
971
|
return ae(e, x);
|
|
875
972
|
}
|
|
876
|
-
async function
|
|
973
|
+
async function Q(e, t) {
|
|
877
974
|
let n = await crypto.subtle.importKey("raw", new Uint8Array(e), "PBKDF2", !1, ["deriveKey"]);
|
|
878
975
|
return crypto.subtle.deriveKey({
|
|
879
976
|
name: "PBKDF2",
|
|
@@ -886,7 +983,7 @@ async function U(e, t) {
|
|
|
886
983
|
}, !1, ["encrypt", "decrypt"]);
|
|
887
984
|
}
|
|
888
985
|
async function ke(e, t) {
|
|
889
|
-
let n = r.utf8ToBuffer(t), i = r.getRandomBuffer(16), a = r.getRandomBuffer(12), o = r.utf8ToBuffer(e), s = await
|
|
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({
|
|
890
987
|
name: "AES-GCM",
|
|
891
988
|
iv: new Uint8Array(a)
|
|
892
989
|
}, s, new Uint8Array(o)), l = r.concat([
|
|
@@ -897,7 +994,7 @@ async function ke(e, t) {
|
|
|
897
994
|
return r.bufferToBase64(l);
|
|
898
995
|
}
|
|
899
996
|
async function Ae(e, t) {
|
|
900
|
-
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
|
|
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({
|
|
901
998
|
name: "AES-GCM",
|
|
902
999
|
iv: o
|
|
903
1000
|
}, c, s);
|
|
@@ -907,101 +1004,15 @@ async function je(e, t) {
|
|
|
907
1004
|
try {
|
|
908
1005
|
if (e) {
|
|
909
1006
|
let n = await Ae(e, t);
|
|
910
|
-
if (n &&
|
|
1007
|
+
if (n && Z(n)) return n;
|
|
911
1008
|
}
|
|
912
1009
|
return !1;
|
|
913
1010
|
} catch {
|
|
914
1011
|
return !1;
|
|
915
1012
|
}
|
|
916
1013
|
}
|
|
917
|
-
// src/utils/market.ts
|
|
918
|
-
var W = [
|
|
919
|
-
{
|
|
920
|
-
code: "usd",
|
|
921
|
-
symbol: "$",
|
|
922
|
-
name: "US Dollar"
|
|
923
|
-
},
|
|
924
|
-
{
|
|
925
|
-
code: "eur",
|
|
926
|
-
symbol: "€",
|
|
927
|
-
name: "Euro"
|
|
928
|
-
},
|
|
929
|
-
{
|
|
930
|
-
code: "gbp",
|
|
931
|
-
symbol: "£",
|
|
932
|
-
name: "British Pound"
|
|
933
|
-
},
|
|
934
|
-
{
|
|
935
|
-
code: "aud",
|
|
936
|
-
symbol: "A$",
|
|
937
|
-
name: "Australian Dollar"
|
|
938
|
-
},
|
|
939
|
-
{
|
|
940
|
-
code: "cad",
|
|
941
|
-
symbol: "C$",
|
|
942
|
-
name: "Canadian Dollar"
|
|
943
|
-
},
|
|
944
|
-
{
|
|
945
|
-
code: "chf",
|
|
946
|
-
symbol: "Fr",
|
|
947
|
-
name: "Swiss Franc"
|
|
948
|
-
},
|
|
949
|
-
{
|
|
950
|
-
code: "inr",
|
|
951
|
-
symbol: "₹",
|
|
952
|
-
name: "Indian Rupee"
|
|
953
|
-
},
|
|
954
|
-
{
|
|
955
|
-
code: "cny",
|
|
956
|
-
symbol: "¥",
|
|
957
|
-
name: "Chinese Yuan"
|
|
958
|
-
},
|
|
959
|
-
{
|
|
960
|
-
code: "jpy",
|
|
961
|
-
symbol: "¥",
|
|
962
|
-
name: "Japanese Yen"
|
|
963
|
-
}
|
|
964
|
-
], G = Object.fromEntries(W.map((e) => [e.code, e.symbol])), K = W.map((e) => e.code);
|
|
965
|
-
function Me(e) {
|
|
966
|
-
return G[e] || e;
|
|
967
|
-
}
|
|
968
|
-
function Ne(e, t, n) {
|
|
969
|
-
let r = y.multiply(e, t), i = y.round(r, 2, y.RoundingModes.HALF_DOWN);
|
|
970
|
-
return n ? q(i, n) : i;
|
|
971
|
-
}
|
|
972
|
-
function q(e, t, n = "en-US") {
|
|
973
|
-
return new Intl.NumberFormat(n, {
|
|
974
|
-
style: "currency",
|
|
975
|
-
currency: t,
|
|
976
|
-
maximumFractionDigits: 2,
|
|
977
|
-
minimumFractionDigits: 2
|
|
978
|
-
}).format(Number(e));
|
|
979
|
-
}
|
|
980
|
-
// src/utils/vault.ts
|
|
981
|
-
function J() {
|
|
982
|
-
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);
|
|
983
|
-
}
|
|
984
|
-
function Y() {
|
|
985
|
-
let e = J();
|
|
986
|
-
return s.sha256ripemd160(e.toBuffer());
|
|
987
|
-
}
|
|
988
|
-
function X(e) {
|
|
989
|
-
return f.empty().add(e.toBuffer());
|
|
990
|
-
}
|
|
991
|
-
function Z(e) {
|
|
992
|
-
let t = X(e);
|
|
993
|
-
return s.sha256ripemd160(t.toBuffer());
|
|
994
|
-
}
|
|
995
|
-
function Q(e) {
|
|
996
|
-
return e.map((e) => e <= 16 ? p.smallInt(e) : n.fromNumber(e).toScriptNumBuffer());
|
|
997
|
-
}
|
|
998
|
-
function $(t, n) {
|
|
999
|
-
if (n.length !== 2) return;
|
|
1000
|
-
let r = Y(), i = Z(t), a = Q(n);
|
|
1001
|
-
return e.fromScriptTemplate(r, i, a).toString();
|
|
1002
|
-
}
|
|
1003
1014
|
// src/services/session.ts
|
|
1004
|
-
var
|
|
1015
|
+
var Me = class {
|
|
1005
1016
|
constructor(e, t) {
|
|
1006
1017
|
this.walletDb = e, this.keyManager = t, this.providers = /* @__PURE__ */ new Map(), this.handlers = /* @__PURE__ */ new Map(), this.removeOnClose = !0;
|
|
1007
1018
|
}
|
|
@@ -1147,7 +1158,7 @@ var Pe = class {
|
|
|
1147
1158
|
};
|
|
1148
1159
|
});
|
|
1149
1160
|
}
|
|
1150
|
-
},
|
|
1161
|
+
}, Ne = class {
|
|
1151
1162
|
constructor(e, t, n) {
|
|
1152
1163
|
this.rostrumService = e, this.keyManager = t, this.assetService = n;
|
|
1153
1164
|
}
|
|
@@ -1193,7 +1204,7 @@ var Pe = class {
|
|
|
1193
1204
|
address: e.address,
|
|
1194
1205
|
nexaAmount: i.amount.toString(),
|
|
1195
1206
|
assetId: r,
|
|
1196
|
-
assetAmount:
|
|
1207
|
+
assetAmount: N(i.group_quantity) || i.amount.toString()
|
|
1197
1208
|
}), e.involvedAssets.add(r), n.scriptSig.isEmpty() && e.inputsToSign.add(t);
|
|
1198
1209
|
}
|
|
1199
1210
|
n.scriptSig.findPlaceholder() > 0 && e.inputsToSign.add(t);
|
|
@@ -1202,11 +1213,11 @@ var Pe = class {
|
|
|
1202
1213
|
for (let t = 0; t < e.txDetails.tx.outputs.length; t++) {
|
|
1203
1214
|
let n = e.txDetails.tx.outputs[t].toObject();
|
|
1204
1215
|
if (n.address !== e.address) continue;
|
|
1205
|
-
let r = n.groupId ?
|
|
1216
|
+
let r = n.groupId ? M(n.groupId) : "NEXA", i = {
|
|
1206
1217
|
address: n.address,
|
|
1207
1218
|
nexaAmount: n.value.toString(),
|
|
1208
1219
|
assetId: r,
|
|
1209
|
-
assetAmount:
|
|
1220
|
+
assetAmount: N(n.groupAmount) || n.value.toString()
|
|
1210
1221
|
};
|
|
1211
1222
|
e.involvedAssets.add(r), e.myOutputs.set(t, i);
|
|
1212
1223
|
}
|
|
@@ -1272,39 +1283,46 @@ var Pe = class {
|
|
|
1272
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);
|
|
1273
1284
|
}
|
|
1274
1285
|
}
|
|
1275
|
-
},
|
|
1286
|
+
}, $ = 5, Pe = class {
|
|
1276
1287
|
constructor(e, t) {
|
|
1277
1288
|
this.rostrumService = e, this.keyManager = t;
|
|
1278
1289
|
}
|
|
1279
1290
|
async discoverWalletIndex(e, t) {
|
|
1280
1291
|
let n = 0, r = -1, i = [];
|
|
1281
1292
|
for (;;) {
|
|
1282
|
-
let a = await Promise.all(Array.from({ length:
|
|
1283
|
-
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;
|
|
1284
1295
|
else break;
|
|
1285
1296
|
}
|
|
1286
1297
|
if (r === -1) return -1;
|
|
1287
|
-
for (let e =
|
|
1298
|
+
for (let e = z.GAP_LIMIT - 1; e >= 0; e--) if (i[e]) return r + e;
|
|
1288
1299
|
return r;
|
|
1289
1300
|
}
|
|
1290
|
-
async discoverVaults(
|
|
1291
|
-
let
|
|
1292
|
-
return
|
|
1293
|
-
let
|
|
1294
|
-
|
|
1295
|
-
}),
|
|
1296
|
-
}
|
|
1297
|
-
async checkForVaults(
|
|
1298
|
-
let
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
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;
|
|
1304
1322
|
}
|
|
1305
1323
|
parseVaultDetails(t) {
|
|
1306
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];
|
|
1307
|
-
if (o ==
|
|
1325
|
+
if (o == X(this.keyManager.getKey({
|
|
1308
1326
|
account: S.VAULT,
|
|
1309
1327
|
type: C.RECEIVE,
|
|
1310
1328
|
index: l
|
|
@@ -1322,7 +1340,7 @@ var Pe = class {
|
|
|
1322
1340
|
type: S.VAULT
|
|
1323
1341
|
};
|
|
1324
1342
|
}
|
|
1325
|
-
},
|
|
1343
|
+
}, Fe = class e {
|
|
1326
1344
|
static {
|
|
1327
1345
|
this.DEBOUNCE_MS = 2e3;
|
|
1328
1346
|
}
|
|
@@ -1334,7 +1352,7 @@ var Pe = class {
|
|
|
1334
1352
|
address: r,
|
|
1335
1353
|
result: n
|
|
1336
1354
|
});
|
|
1337
|
-
}, 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();
|
|
1338
1356
|
}
|
|
1339
1357
|
onUpdate(e) {
|
|
1340
1358
|
this.updateCallback = e;
|
|
@@ -1364,14 +1382,14 @@ var Pe = class {
|
|
|
1364
1382
|
let t = this.accounts.get(e);
|
|
1365
1383
|
return [{
|
|
1366
1384
|
address: t.address,
|
|
1367
|
-
keyPath:
|
|
1385
|
+
keyPath: L(S.DAPP, 0, t.id),
|
|
1368
1386
|
balance: t.balance,
|
|
1369
1387
|
tokensBalance: t.tokensBalance
|
|
1370
1388
|
}];
|
|
1371
1389
|
}
|
|
1372
1390
|
return this.getMainAddresses().filter((e) => e.used).map((e) => ({
|
|
1373
1391
|
address: e.address,
|
|
1374
|
-
keyPath:
|
|
1392
|
+
keyPath: L(S.MAIN, e.space, e.idx),
|
|
1375
1393
|
balance: e.balance,
|
|
1376
1394
|
tokensBalance: e.tokensBalance
|
|
1377
1395
|
}));
|
|
@@ -1393,12 +1411,13 @@ var Pe = class {
|
|
|
1393
1411
|
type: "discover_wallet",
|
|
1394
1412
|
loading: !0
|
|
1395
1413
|
});
|
|
1396
|
-
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),
|
|
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([
|
|
1397
1415
|
e,
|
|
1398
1416
|
t,
|
|
1399
|
-
n
|
|
1417
|
+
n,
|
|
1418
|
+
r
|
|
1400
1419
|
]);
|
|
1401
|
-
this.receiveAddresses = this.deriveAddresses(C.RECEIVE, 0,
|
|
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({
|
|
1402
1421
|
type: "discover_wallet",
|
|
1403
1422
|
loading: !1
|
|
1404
1423
|
}), this.notify({
|
|
@@ -1430,8 +1449,8 @@ var Pe = class {
|
|
|
1430
1449
|
id: -1,
|
|
1431
1450
|
name: "HD Wallet",
|
|
1432
1451
|
address: this.getReceiveAddress(),
|
|
1433
|
-
balance:
|
|
1434
|
-
tokensBalance:
|
|
1452
|
+
balance: P(e.map((e) => e.balance)),
|
|
1453
|
+
tokensBalance: F(e.map((e) => e.tokensBalance)),
|
|
1435
1454
|
sessions: {}
|
|
1436
1455
|
}
|
|
1437
1456
|
});
|
|
@@ -1504,6 +1523,9 @@ var Pe = class {
|
|
|
1504
1523
|
async saveAccounts(e) {
|
|
1505
1524
|
for (let t of e.values()) await this.walletDb.saveAccount(t);
|
|
1506
1525
|
}
|
|
1526
|
+
async saveVaults(e) {
|
|
1527
|
+
for (let t of e.values()) await this.walletDb.saveVault(t);
|
|
1528
|
+
}
|
|
1507
1529
|
async subscribeAddresses(e, t = !1) {
|
|
1508
1530
|
let n = e.map(async (e) => ({
|
|
1509
1531
|
addr: e,
|
|
@@ -1562,7 +1584,7 @@ var Pe = class {
|
|
|
1562
1584
|
}
|
|
1563
1585
|
let a = await Promise.all(t);
|
|
1564
1586
|
await Promise.all(n);
|
|
1565
|
-
let o = await Promise.all(r), s = [this.postProcessWalletUpdate(o
|
|
1587
|
+
let o = await Promise.all(r), s = [this.postProcessWalletUpdate(o), this.postProcessAccountsUpdate(a)];
|
|
1566
1588
|
i && s.push(this.recoverTokens()), await Promise.all(s), i && this.discoveryResolver && (this.discoveryResolver(), this.discoveryResolver = void 0);
|
|
1567
1589
|
} catch (e) {
|
|
1568
1590
|
console.error("Error processing pending updates:", e);
|
|
@@ -1573,22 +1595,22 @@ var Pe = class {
|
|
|
1573
1595
|
});
|
|
1574
1596
|
}
|
|
1575
1597
|
}
|
|
1576
|
-
async postProcessWalletUpdate(e
|
|
1598
|
+
async postProcessWalletUpdate(e) {
|
|
1577
1599
|
if (e.length === 0) return;
|
|
1578
|
-
let
|
|
1579
|
-
for (let { txs:
|
|
1580
|
-
let
|
|
1581
|
-
|
|
1582
|
-
let
|
|
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));
|
|
1583
1605
|
this.notify({
|
|
1584
1606
|
type: "account_balance_updated",
|
|
1585
1607
|
accountId: -1,
|
|
1586
|
-
balance:
|
|
1587
|
-
tokensBalance:
|
|
1608
|
+
balance: i,
|
|
1609
|
+
tokensBalance: a
|
|
1588
1610
|
}), this.notify({
|
|
1589
1611
|
type: "main_address_updated",
|
|
1590
1612
|
address: this.getReceiveAddress()
|
|
1591
|
-
}), await this.postProcessActivity(-1,
|
|
1613
|
+
}), await this.postProcessActivity(-1, n, r.map((e) => e.address), a);
|
|
1592
1614
|
}
|
|
1593
1615
|
async postProcessAccountsUpdate(e) {
|
|
1594
1616
|
if (e.length === 0) return;
|
|
@@ -1644,8 +1666,8 @@ var Pe = class {
|
|
|
1644
1666
|
}
|
|
1645
1667
|
async checkGapLimit(e) {
|
|
1646
1668
|
let t = e === C.RECEIVE ? this.receiveAddresses : this.changeAddresses, n = e === C.RECEIVE ? "Receive" : "Change", r = t.filter((e) => !e.used).length;
|
|
1647
|
-
if (r <
|
|
1648
|
-
let i =
|
|
1669
|
+
if (r < z.GAP_LIMIT) {
|
|
1670
|
+
let i = z.GAP_LIMIT - r, a = t[t.length - 1].idx;
|
|
1649
1671
|
console.log(`Deriving ${i} more ${n} addresses...`);
|
|
1650
1672
|
let o = this.deriveAddresses(e, a + 1, i);
|
|
1651
1673
|
e === C.RECEIVE ? this.receiveAddresses.push(...o) : this.changeAddresses.push(...o), await this.saveAddresses(o), await this.subscribeAddresses(o);
|
|
@@ -1736,14 +1758,14 @@ var Pe = class {
|
|
|
1736
1758
|
}
|
|
1737
1759
|
}), await this.subscribeAddresses([e]);
|
|
1738
1760
|
}
|
|
1739
|
-
async recoverVaults(
|
|
1740
|
-
let
|
|
1741
|
-
for (let [
|
|
1742
|
-
return await Promise.all(
|
|
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;
|
|
1743
1765
|
}
|
|
1744
1766
|
async recoverTokens() {
|
|
1745
1767
|
let e = [];
|
|
1746
|
-
e.push(this.assetService.syncTokens(-1,
|
|
1768
|
+
e.push(this.assetService.syncTokens(-1, F(this.getMainAddresses().map((e) => e.tokensBalance))));
|
|
1747
1769
|
for (let t of this.accounts.values()) e.push(this.assetService.syncTokens(t.id, t.tokensBalance));
|
|
1748
1770
|
await Promise.all(e);
|
|
1749
1771
|
}
|
|
@@ -1756,7 +1778,7 @@ var Pe = class {
|
|
|
1756
1778
|
isMainAddress(e) {
|
|
1757
1779
|
return e.type == S.MAIN;
|
|
1758
1780
|
}
|
|
1759
|
-
},
|
|
1781
|
+
}, Ie = class e {
|
|
1760
1782
|
static {
|
|
1761
1783
|
this.POLL_INTERVAL_MS = 12e4;
|
|
1762
1784
|
}
|
|
@@ -1778,7 +1800,7 @@ var Pe = class {
|
|
|
1778
1800
|
async init() {
|
|
1779
1801
|
this.stop();
|
|
1780
1802
|
let t = await this.walletDb.getSetting(e.CURRENCY_SETTING);
|
|
1781
|
-
this.currency =
|
|
1803
|
+
this.currency = E.includes(t) ? t : "usd", this.notify({
|
|
1782
1804
|
type: "currency_updated",
|
|
1783
1805
|
currency: this.currency
|
|
1784
1806
|
}), this.running = !0, this.poll();
|
|
@@ -1837,6 +1859,6 @@ var Pe = class {
|
|
|
1837
1859
|
}), a;
|
|
1838
1860
|
}
|
|
1839
1861
|
};
|
|
1840
|
-
export { S as AccountType,
|
|
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 };
|
|
1841
1863
|
|
|
1842
1864
|
//# sourceMappingURL=index.js.map
|