@otoplo/wallet-common 0.1.8 → 0.1.9
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 +425 -402
- package/dist/index.js.map +1 -1
- package/package.json +1 -3
- package/src/utils/seed.ts +51 -29
package/dist/index.js
CHANGED
|
@@ -1,60 +1,56 @@
|
|
|
1
|
-
import { AddressType as E, Networks as k, Address as b, CommonUtils as W, BufferUtils as
|
|
2
|
-
import { ElectrumClient as
|
|
3
|
-
import { mnemonicToSeedSync as
|
|
4
|
-
import
|
|
5
|
-
import { DAppProvider as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import { wordlist as fe } from "@scure/bip39/wordlists/english.js";
|
|
11
|
-
import { createSlice as M, createAsyncThunk as He, createSelector as j } from "@reduxjs/toolkit";
|
|
12
|
-
import { useSelector as Ke } from "react-redux";
|
|
13
|
-
const g = -1, oe = 9223372036854775807n, Le = 274710, Mt = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
1
|
+
import { AddressType as E, Networks as k, Address as b, CommonUtils as W, BufferUtils as g, HDPrivateKey as Z, GroupToken as O, GroupIdType as I, TransactionBuilder as Q, Transaction as B, UnitUtils as ee, Script as A, Opcode as v, Hash as U, ScriptOpcode as J, BNExtended as z, Output as Ie, TxSigner as te, SighashType as se, ScriptFactory as xe, OutputSighashType as ae, BufferWriter as Ne } from "libnexa-ts";
|
|
2
|
+
import { ElectrumClient as Ee, TransportScheme as L, ConnectionStatus as Me } from "@otoplo/electrum-client";
|
|
3
|
+
import { mnemonicToSeedSync as Be, generateMnemonic as Ce, validateMnemonic as Pe } from "@scure/bip39";
|
|
4
|
+
import _e from "jszip";
|
|
5
|
+
import { DAppProvider as Oe } from "wallet-comms-sdk";
|
|
6
|
+
import { wordlist as de } from "@scure/bip39/wordlists/english.js";
|
|
7
|
+
import { createSlice as M, createAsyncThunk as Ue, createSelector as j } from "@reduxjs/toolkit";
|
|
8
|
+
import { useSelector as De } from "react-redux";
|
|
9
|
+
const y = -1, ne = 9223372036854775807n, Ve = 274710, St = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
14
10
|
function T() {
|
|
15
11
|
return k.defaultNetwork == k.testnet;
|
|
16
12
|
}
|
|
17
|
-
function
|
|
13
|
+
function bt(a) {
|
|
18
14
|
return T() ? a == "508c843a4b98fb25f57cf9ebafb245a5c16468f06519cdd467059a91e7b79d52" : a == "edc7144fe1ba4edd0edf35d7eea90f6cb1dba42314aa85da8207e97c5339c801";
|
|
19
15
|
}
|
|
20
16
|
function F(a, e = E.PayToScriptTemplate) {
|
|
21
17
|
return b.isValid(a, k.defaultNetwork, e);
|
|
22
18
|
}
|
|
23
|
-
function
|
|
19
|
+
function kt() {
|
|
24
20
|
return `https://${T() ? "testnet-" : ""}explorer.nexa.org`;
|
|
25
21
|
}
|
|
26
22
|
function $() {
|
|
27
23
|
return Math.floor(Date.now() / 1e3);
|
|
28
24
|
}
|
|
29
|
-
function
|
|
25
|
+
function Tt(a, e) {
|
|
30
26
|
const t = (e - a) * 2, s = /* @__PURE__ */ new Date();
|
|
31
27
|
return s.setMinutes(s.getMinutes() + t), s.toLocaleDateString();
|
|
32
28
|
}
|
|
33
|
-
function
|
|
29
|
+
function P(a) {
|
|
34
30
|
return !a || a.length === 0;
|
|
35
31
|
}
|
|
36
|
-
function
|
|
32
|
+
function It(a, e = 0) {
|
|
37
33
|
if (!a || a.length <= e)
|
|
38
34
|
return a || "";
|
|
39
|
-
const t = "...", s = Math.floor((e - t.length) / 2), n = a.slice(0, s),
|
|
40
|
-
return n + t +
|
|
35
|
+
const t = "...", s = Math.floor((e - t.length) / 2), n = a.slice(0, s), i = a.slice(a.length - s);
|
|
36
|
+
return n + t + i;
|
|
41
37
|
}
|
|
42
|
-
function
|
|
38
|
+
function xt(a) {
|
|
43
39
|
return a.length === 0 ? "" : a.charAt(0).toUpperCase() + a.substring(1);
|
|
44
40
|
}
|
|
45
41
|
function R(a) {
|
|
46
|
-
return W.isHexa(a) ?
|
|
42
|
+
return W.isHexa(a) ? g.hexToBuffer(a) : b.fromString(a).data;
|
|
47
43
|
}
|
|
48
44
|
function S(a) {
|
|
49
|
-
return W.isHexa(a) ? a :
|
|
45
|
+
return W.isHexa(a) ? a : g.bufferToHex(R(a));
|
|
50
46
|
}
|
|
51
|
-
function
|
|
47
|
+
function ie(a) {
|
|
52
48
|
return W.isHexa(a) ? new b(R(a), k.defaultNetwork, E.GroupIdAddress).toString() : a;
|
|
53
49
|
}
|
|
54
50
|
function D(a) {
|
|
55
51
|
return a == null || a === "" ? "" : BigInt(a) <= 0n ? "0" : a.toString();
|
|
56
52
|
}
|
|
57
|
-
function
|
|
53
|
+
function re(a) {
|
|
58
54
|
let e = BigInt(0), t = BigInt(0);
|
|
59
55
|
return a.forEach((s) => {
|
|
60
56
|
e += BigInt(s.confirmed), t += BigInt(s.unconfirmed);
|
|
@@ -67,7 +63,7 @@ function G(a) {
|
|
|
67
63
|
e[s] ? (e[s].confirmed = (BigInt(e[s].confirmed) + BigInt(t[s].confirmed)).toString(), e[s].unconfirmed = (BigInt(e[s].unconfirmed) + BigInt(t[s].unconfirmed)).toString()) : e[s] = { confirmed: BigInt(t[s].confirmed).toString(), unconfirmed: BigInt(t[s].unconfirmed).toString() };
|
|
68
64
|
}), e;
|
|
69
65
|
}
|
|
70
|
-
const
|
|
66
|
+
const ue = {
|
|
71
67
|
// Images
|
|
72
68
|
//'.svg': { media: 'image', mime: 'image/svg+xml' },
|
|
73
69
|
".gif": { media: "image", mime: "image/gif" },
|
|
@@ -90,19 +86,19 @@ const pe = {
|
|
|
90
86
|
".wav": { media: "audio", mime: "audio/wav" },
|
|
91
87
|
".m4a": { media: "audio", mime: "audio/mp4" }
|
|
92
88
|
};
|
|
93
|
-
function
|
|
89
|
+
function Nt(a) {
|
|
94
90
|
const e = a.lastIndexOf(".");
|
|
95
91
|
if (e === -1) return "unknown";
|
|
96
92
|
const t = a.slice(e).toLowerCase();
|
|
97
|
-
return
|
|
93
|
+
return ue[t]?.media ?? "unknown";
|
|
98
94
|
}
|
|
99
|
-
function
|
|
95
|
+
function Et(a) {
|
|
100
96
|
const e = a.lastIndexOf(".");
|
|
101
97
|
if (e === -1) return "application/octet-stream";
|
|
102
98
|
const t = a.slice(e).toLowerCase();
|
|
103
|
-
return
|
|
99
|
+
return ue[t]?.mime ?? "application/octet-stream";
|
|
104
100
|
}
|
|
105
|
-
class
|
|
101
|
+
class Mt {
|
|
106
102
|
getPrefix() {
|
|
107
103
|
return T() ? "testnet-" : "";
|
|
108
104
|
}
|
|
@@ -161,7 +157,7 @@ class Vt {
|
|
|
161
157
|
}
|
|
162
158
|
async getRequireAuth() {
|
|
163
159
|
const e = await this.getValue("auth");
|
|
164
|
-
return
|
|
160
|
+
return P(e) || e === "true";
|
|
165
161
|
}
|
|
166
162
|
async setRequireAuth(e) {
|
|
167
163
|
await this.setValue("auth", JSON.stringify(e));
|
|
@@ -171,7 +167,7 @@ class Vt {
|
|
|
171
167
|
return e ? Number(e) : void 0;
|
|
172
168
|
}
|
|
173
169
|
async setReleaseNotesTime(e) {
|
|
174
|
-
|
|
170
|
+
P(e) ? await this.removeValue("show-notes") : await this.setValue("show-notes", e);
|
|
175
171
|
}
|
|
176
172
|
async getIsTestnet() {
|
|
177
173
|
return await this.getValue("testnet") === "1";
|
|
@@ -187,8 +183,8 @@ class Vt {
|
|
|
187
183
|
await this.setValue("auto-lock", `${e}`);
|
|
188
184
|
}
|
|
189
185
|
}
|
|
190
|
-
var f = /* @__PURE__ */ ((a) => (a[a.MAIN = 0] = "MAIN", a[a.VAULT = 1] = "VAULT", a[a.DAPP = 2] = "DAPP", a))(f || {}),
|
|
191
|
-
class
|
|
186
|
+
var f = /* @__PURE__ */ ((a) => (a[a.MAIN = 0] = "MAIN", a[a.VAULT = 1] = "VAULT", a[a.DAPP = 2] = "DAPP", a))(f || {}), m = /* @__PURE__ */ ((a) => (a[a.RECEIVE = 0] = "RECEIVE", a[a.CHANGE = 1] = "CHANGE", a))(m || {}), C = /* @__PURE__ */ ((a) => (a.SignMessage = "signMessage", a.AddToken = "addToken", a.SignTransaction = "signTransaction", a.SendTransaction = "sendTransaction", a))(C || {}), V = /* @__PURE__ */ ((a) => (a.TOKEN = "token", a.NFT = "nft", a))(V || {});
|
|
187
|
+
class Bt {
|
|
192
188
|
store;
|
|
193
189
|
updateCallback;
|
|
194
190
|
constructor(e) {
|
|
@@ -362,7 +358,7 @@ class Rt {
|
|
|
362
358
|
return this.store.upsertVault(t);
|
|
363
359
|
}
|
|
364
360
|
}
|
|
365
|
-
class
|
|
361
|
+
class Ct {
|
|
366
362
|
walletDb;
|
|
367
363
|
tokens = /* @__PURE__ */ new Map();
|
|
368
364
|
nfts = /* @__PURE__ */ new Map();
|
|
@@ -391,7 +387,7 @@ class Ht {
|
|
|
391
387
|
this.nfts.delete(S(e));
|
|
392
388
|
}
|
|
393
389
|
}
|
|
394
|
-
class
|
|
390
|
+
class le {
|
|
395
391
|
kvStore;
|
|
396
392
|
client;
|
|
397
393
|
constructor(e) {
|
|
@@ -467,7 +463,7 @@ class ge {
|
|
|
467
463
|
}
|
|
468
464
|
async connect(e) {
|
|
469
465
|
try {
|
|
470
|
-
e || (e = await this.getCurrentInstance()), this.client = new
|
|
466
|
+
e || (e = await this.getCurrentInstance()), this.client = new Ee("com.otoplo.wallet", "1.4.3", e.host, e.port, e.scheme, 45 * 1e3, 10 * 1e3), await this.client.connect();
|
|
471
467
|
} catch (t) {
|
|
472
468
|
throw t instanceof Error ? console.info(t.message) : console.error(t), t;
|
|
473
469
|
}
|
|
@@ -489,19 +485,19 @@ class ge {
|
|
|
489
485
|
waitForConnection(e = 5e3) {
|
|
490
486
|
const t = Date.now();
|
|
491
487
|
return new Promise((s, n) => {
|
|
492
|
-
const
|
|
493
|
-
if (this.client?.connectionStatus ==
|
|
488
|
+
const i = () => {
|
|
489
|
+
if (this.client?.connectionStatus == Me.CONNECTED)
|
|
494
490
|
return s();
|
|
495
491
|
if (Date.now() - t > e)
|
|
496
492
|
return n(new Error("Rostrum Connection timeout"));
|
|
497
|
-
setTimeout(
|
|
493
|
+
setTimeout(i, 250);
|
|
498
494
|
};
|
|
499
|
-
|
|
495
|
+
i();
|
|
500
496
|
});
|
|
501
497
|
}
|
|
502
498
|
async getCurrentInstance() {
|
|
503
499
|
const e = await this.kvStore.getRostrumParams();
|
|
504
|
-
return e ||
|
|
500
|
+
return e || le.getPredefinedInstances()[0];
|
|
505
501
|
}
|
|
506
502
|
static getPredefinedInstances() {
|
|
507
503
|
return T() ? [
|
|
@@ -530,7 +526,7 @@ class ge {
|
|
|
530
526
|
function x(a, e, t) {
|
|
531
527
|
return `${a}'/${e}/${t}`;
|
|
532
528
|
}
|
|
533
|
-
function
|
|
529
|
+
function Re(a) {
|
|
534
530
|
const e = a.split("/");
|
|
535
531
|
return {
|
|
536
532
|
account: parseInt(e[0].replace("'", "")),
|
|
@@ -538,13 +534,13 @@ function Fe(a) {
|
|
|
538
534
|
index: parseInt(e[2])
|
|
539
535
|
};
|
|
540
536
|
}
|
|
541
|
-
class
|
|
537
|
+
class Pt {
|
|
542
538
|
seed;
|
|
543
539
|
masterKey;
|
|
544
540
|
accountKeys = /* @__PURE__ */ new Map();
|
|
545
541
|
walletKeys = /* @__PURE__ */ new Map();
|
|
546
542
|
init(e) {
|
|
547
|
-
this.seed = typeof e == "string" ?
|
|
543
|
+
this.seed = typeof e == "string" ? Be(e) : e, this.masterKey = Z.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0);
|
|
548
544
|
}
|
|
549
545
|
reset() {
|
|
550
546
|
if (!this.seed)
|
|
@@ -559,13 +555,13 @@ class Kt {
|
|
|
559
555
|
const t = typeof e == "string" ? e : x(e.account, e.type, e.index);
|
|
560
556
|
let s = this.walletKeys.get(t);
|
|
561
557
|
if (!s) {
|
|
562
|
-
const { account: n, type:
|
|
563
|
-
s = this.getAccountKey(n).deriveChild(
|
|
558
|
+
const { account: n, type: i, index: o } = typeof e == "string" ? Re(e) : e;
|
|
559
|
+
s = this.getAccountKey(n).deriveChild(i, !1).deriveChild(o, !1), this.walletKeys.set(t, s);
|
|
564
560
|
}
|
|
565
561
|
return s;
|
|
566
562
|
}
|
|
567
563
|
}
|
|
568
|
-
function
|
|
564
|
+
function he() {
|
|
569
565
|
return {
|
|
570
566
|
name: "NiftyArt",
|
|
571
567
|
ticker: "NIFTY",
|
|
@@ -576,33 +572,33 @@ function me() {
|
|
|
576
572
|
decimals: 0
|
|
577
573
|
};
|
|
578
574
|
}
|
|
579
|
-
function
|
|
580
|
-
return Y(
|
|
575
|
+
function _t(a) {
|
|
576
|
+
return Y(Le() + a, "raw");
|
|
581
577
|
}
|
|
582
578
|
function q(a) {
|
|
583
579
|
try {
|
|
584
580
|
const e = R(a);
|
|
585
|
-
return O.isSubgroup(e) ?
|
|
581
|
+
return O.isSubgroup(e) ? g.bufferToHex(e.subarray(0, 32)) === he().tokenIdHex : !1;
|
|
586
582
|
} catch {
|
|
587
583
|
return !1;
|
|
588
584
|
}
|
|
589
585
|
}
|
|
590
|
-
function
|
|
586
|
+
function He(a) {
|
|
591
587
|
return a = X(a), Y(a, "json");
|
|
592
588
|
}
|
|
593
|
-
function
|
|
589
|
+
function Ke(a) {
|
|
594
590
|
return a = X(a), Y(a, "raw");
|
|
595
591
|
}
|
|
596
|
-
function
|
|
592
|
+
function oe(a, e) {
|
|
597
593
|
return a && typeof a == "string" ? a.startsWith("http") ? a.replace("http://", "https://") : a.startsWith("ipfs://") ? a : `${new URL(e).origin}${a}` : "";
|
|
598
594
|
}
|
|
599
|
-
function
|
|
595
|
+
function Ot(a) {
|
|
600
596
|
return a ? X(a) : null;
|
|
601
597
|
}
|
|
602
598
|
function X(a, e = "https://ipfs.nebula.markets/") {
|
|
603
599
|
return a?.startsWith("ipfs://") ? e + a.substring(7) : a;
|
|
604
600
|
}
|
|
605
|
-
function
|
|
601
|
+
function Le() {
|
|
606
602
|
return `https://${T() ? "testnet." : ""}niftyart.cash/_public/`;
|
|
607
603
|
}
|
|
608
604
|
async function Y(a, e) {
|
|
@@ -619,7 +615,7 @@ async function Y(a, e) {
|
|
|
619
615
|
throw new Error(`Unexpected Error: ${t}`);
|
|
620
616
|
}
|
|
621
617
|
}
|
|
622
|
-
class
|
|
618
|
+
class Ut {
|
|
623
619
|
walletDb;
|
|
624
620
|
rostrumService;
|
|
625
621
|
walletCache;
|
|
@@ -633,21 +629,21 @@ class Gt {
|
|
|
633
629
|
if (c)
|
|
634
630
|
return c;
|
|
635
631
|
}
|
|
636
|
-
const s = await this.rostrumService.getTokenGenesis(e), n =
|
|
637
|
-
let
|
|
632
|
+
const s = await this.rostrumService.getTokenGenesis(e), n = g.hexToBuffer(s.token_id_hex);
|
|
633
|
+
let i = "", o = "";
|
|
638
634
|
if (s.op_return_id == I.NRC2 || s.op_return_id == I.NRC3 || q(e))
|
|
639
635
|
return;
|
|
640
|
-
if (O.isSubgroup(n) && (
|
|
636
|
+
if (O.isSubgroup(n) && (i = new b(O.getParentGroupId(n), k.defaultNetwork, E.GroupIdAddress).toString()), s.document_url)
|
|
641
637
|
try {
|
|
642
638
|
if (s.op_return_id == I.NRC1) {
|
|
643
|
-
const c = await
|
|
639
|
+
const c = await Ke(s.document_url), u = (await _e.loadAsync(c)).file("info.json");
|
|
644
640
|
if (u) {
|
|
645
641
|
const l = await u.async("string"), h = JSON.parse(l);
|
|
646
|
-
o =
|
|
642
|
+
o = oe(h[0]?.icon, s.document_url);
|
|
647
643
|
}
|
|
648
644
|
} else {
|
|
649
|
-
const c = await
|
|
650
|
-
o =
|
|
645
|
+
const c = await He(s.document_url);
|
|
646
|
+
o = oe(c[0]?.icon, s.document_url);
|
|
651
647
|
}
|
|
652
648
|
} catch (c) {
|
|
653
649
|
console.error("Failed to load metadata", c);
|
|
@@ -656,7 +652,7 @@ class Gt {
|
|
|
656
652
|
token: s.group,
|
|
657
653
|
tokenIdHex: s.token_id_hex,
|
|
658
654
|
decimals: s.decimal_places ?? 0,
|
|
659
|
-
parentGroup:
|
|
655
|
+
parentGroup: i,
|
|
660
656
|
name: s.name ?? "",
|
|
661
657
|
ticker: s.ticker ?? "",
|
|
662
658
|
iconUrl: o
|
|
@@ -678,7 +674,7 @@ class Gt {
|
|
|
678
674
|
async getAssetInfo(e) {
|
|
679
675
|
let t = await this.getTokenInfo(e);
|
|
680
676
|
return t || await this.isNftToken(e) && (t = {
|
|
681
|
-
token:
|
|
677
|
+
token: ie(e),
|
|
682
678
|
tokenIdHex: S(e),
|
|
683
679
|
decimals: 0
|
|
684
680
|
}), t;
|
|
@@ -694,33 +690,33 @@ class Gt {
|
|
|
694
690
|
await this.walletDb.saveAsset(o, !0);
|
|
695
691
|
return;
|
|
696
692
|
}
|
|
697
|
-
const
|
|
698
|
-
if (
|
|
693
|
+
const i = await this.rostrumService.getTokenGenesis(t);
|
|
694
|
+
if (i.op_return_id == I.NRC3) {
|
|
699
695
|
const o = R(t);
|
|
700
696
|
if (O.isSubgroup(o)) {
|
|
701
|
-
const
|
|
702
|
-
c?.op_return_id == I.NRC2 && await this.saveNft(e, t,
|
|
697
|
+
const r = new b(o.subarray(0, 32), k.defaultNetwork, E.GroupIdAddress).toString(), c = await this.rostrumService.getTokenGenesis(r);
|
|
698
|
+
c?.op_return_id == I.NRC2 && await this.saveNft(e, t, i.document_url ?? "", r, s, c?.name ?? "");
|
|
703
699
|
}
|
|
704
|
-
} else q(t) && await this.saveNft(e, t, "nifty",
|
|
700
|
+
} else q(t) && await this.saveNft(e, t, "nifty", he().token, s, "");
|
|
705
701
|
}
|
|
706
|
-
async saveNft(e, t, s, n,
|
|
702
|
+
async saveNft(e, t, s, n, i, o) {
|
|
707
703
|
if (s)
|
|
708
704
|
try {
|
|
709
|
-
const
|
|
705
|
+
const r = {
|
|
710
706
|
accountId: e,
|
|
711
707
|
tokenIdHex: t,
|
|
712
708
|
type: V.NFT,
|
|
713
|
-
addedTime:
|
|
709
|
+
addedTime: i
|
|
714
710
|
}, c = {
|
|
715
711
|
parentGroup: n,
|
|
716
|
-
token:
|
|
712
|
+
token: ie(t),
|
|
717
713
|
tokenIdHex: t,
|
|
718
714
|
source: s,
|
|
719
715
|
collection: o
|
|
720
716
|
};
|
|
721
|
-
await this.walletDb.saveNft(
|
|
722
|
-
} catch (
|
|
723
|
-
console.error("failed to save NFT",
|
|
717
|
+
await this.walletDb.saveNft(r, c);
|
|
718
|
+
} catch (r) {
|
|
719
|
+
console.error("failed to save NFT", r);
|
|
724
720
|
}
|
|
725
721
|
}
|
|
726
722
|
async fetchAndSaveTokens(e, t) {
|
|
@@ -730,18 +726,18 @@ class Gt {
|
|
|
730
726
|
}
|
|
731
727
|
}
|
|
732
728
|
async syncNfts(e, t) {
|
|
733
|
-
const s = Object.keys(t), n = await this.walletDb.getLocalNfts(e, 1, 1e3),
|
|
734
|
-
await this.walletDb.deleteNft(e,
|
|
735
|
-
}, o = n?.filter((
|
|
736
|
-
for (const
|
|
737
|
-
await r
|
|
738
|
-
for (const [
|
|
739
|
-
const d = S(
|
|
740
|
-
!u && !l || u && l || !await this.isNftToken(d) || (!u && l ? await
|
|
729
|
+
const s = Object.keys(t), n = await this.walletDb.getLocalNfts(e, 1, 1e3), i = async (r) => {
|
|
730
|
+
await this.walletDb.deleteNft(e, r, !0), this.walletCache.removeNft(r);
|
|
731
|
+
}, o = n?.filter((r) => !s.includes(r.tokenIdHex)) ?? [];
|
|
732
|
+
for (const r of o)
|
|
733
|
+
await i(r.tokenIdHex);
|
|
734
|
+
for (const [r, c] of Object.entries(t)) {
|
|
735
|
+
const d = S(r), u = c && BigInt(c.confirmed) + BigInt(c.unconfirmed) > 0n, l = n?.some((p) => p.tokenIdHex == d);
|
|
736
|
+
!u && !l || u && l || !await this.isNftToken(d) || (!u && l ? await i(d) : await this.handleNftReceive(e, d, $()));
|
|
741
737
|
}
|
|
742
738
|
}
|
|
743
739
|
}
|
|
744
|
-
class
|
|
740
|
+
class Dt {
|
|
745
741
|
rostrumService;
|
|
746
742
|
keyManager;
|
|
747
743
|
walletDb;
|
|
@@ -754,40 +750,40 @@ class qt {
|
|
|
754
750
|
}
|
|
755
751
|
async fetchTransactionsHistory(e, t) {
|
|
756
752
|
let s = t;
|
|
757
|
-
const n = t > 0 ? t + 1 : 0,
|
|
758
|
-
for (const o of
|
|
753
|
+
const n = t > 0 ? t + 1 : 0, i = await this.rostrumService.getTransactionsHistory(e, n);
|
|
754
|
+
for (const o of i)
|
|
759
755
|
s = Math.max(s, o.height);
|
|
760
|
-
return { txs:
|
|
756
|
+
return { txs: i, lastHeight: s };
|
|
761
757
|
}
|
|
762
758
|
async fetchVaultTransactions(e) {
|
|
763
|
-
const t = await this.rostrumService.getTransactionsHistory(e,
|
|
759
|
+
const t = await this.rostrumService.getTransactionsHistory(e, Ve), s = [];
|
|
764
760
|
for (const n of t) {
|
|
765
|
-
const
|
|
766
|
-
s.push(
|
|
761
|
+
const i = this.classifyTransaction(n.tx_hash, [e]);
|
|
762
|
+
s.push(i);
|
|
767
763
|
}
|
|
768
764
|
return Promise.all(s);
|
|
769
765
|
}
|
|
770
766
|
async classifyAndSaveTransaction(e, t, s) {
|
|
771
767
|
const n = await this.classifyTransaction(t, s);
|
|
772
768
|
n.accountId = e;
|
|
773
|
-
const
|
|
769
|
+
const i = {
|
|
774
770
|
...n,
|
|
775
771
|
othersOutputs: JSON.stringify(n.othersOutputs),
|
|
776
772
|
myOutputs: JSON.stringify(n.myOutputs),
|
|
777
773
|
myInputs: JSON.stringify(n.myInputs)
|
|
778
774
|
}, o = /* @__PURE__ */ new Set();
|
|
779
|
-
n.myInputs.forEach((
|
|
780
|
-
for (const
|
|
775
|
+
n.myInputs.forEach((r) => r.assetId && o.add(r.assetId)), n.myOutputs.forEach((r) => r.assetId && o.add(r.assetId));
|
|
776
|
+
for (const r of o)
|
|
781
777
|
await this.walletDb.addAssetTransaction({
|
|
782
778
|
accountId: e,
|
|
783
|
-
assetId:
|
|
779
|
+
assetId: r,
|
|
784
780
|
txIdem: n.txIdem,
|
|
785
781
|
time: n.time
|
|
786
782
|
});
|
|
787
|
-
await this.walletDb.addLocalTransaction(
|
|
783
|
+
await this.walletDb.addLocalTransaction(i);
|
|
788
784
|
}
|
|
789
785
|
async classifyTransaction(e, t) {
|
|
790
|
-
const s = await this.rostrumService.getTransaction(e), n = [],
|
|
786
|
+
const s = await this.rostrumService.getTransaction(e), n = [], i = [], o = [], r = [];
|
|
791
787
|
for (const l of s.vin) {
|
|
792
788
|
const h = {
|
|
793
789
|
address: l.addresses[0],
|
|
@@ -795,20 +791,20 @@ class qt {
|
|
|
795
791
|
assetId: l.token_id_hex ?? "",
|
|
796
792
|
assetAmount: D(l.groupQuantity)
|
|
797
793
|
};
|
|
798
|
-
t.includes(h.address) ? n.push(h) :
|
|
794
|
+
t.includes(h.address) ? n.push(h) : i.push(h);
|
|
799
795
|
}
|
|
800
796
|
for (const l of s.vout) {
|
|
801
|
-
if (
|
|
797
|
+
if (P(l.scriptPubKey.addresses)) continue;
|
|
802
798
|
const h = {
|
|
803
799
|
address: l.scriptPubKey.addresses[0],
|
|
804
800
|
nexaAmount: l.value_satoshi.toString(),
|
|
805
801
|
assetId: l.scriptPubKey.token_id_hex ?? "",
|
|
806
802
|
assetAmount: D(l.scriptPubKey.groupQuantity)
|
|
807
803
|
};
|
|
808
|
-
t.includes(h.address) ? o.push(h) :
|
|
804
|
+
t.includes(h.address) ? o.push(h) : r.push(h);
|
|
809
805
|
}
|
|
810
806
|
let c;
|
|
811
|
-
n.length === 0 ? c = "receive" : o.length === 0 ? c = "send" :
|
|
807
|
+
n.length === 0 ? c = "receive" : o.length === 0 ? c = "send" : i.length === 0 && r.length === 0 ? c = "self" : i.length === 0 && r.length > 0 ? c = "send" : i.length > 0 && r.length === 0 ? c = "receive" : c = "swap";
|
|
812
808
|
const d = s.height > 0;
|
|
813
809
|
return {
|
|
814
810
|
accountId: 0,
|
|
@@ -819,52 +815,52 @@ class qt {
|
|
|
819
815
|
height: d ? s.height : 0,
|
|
820
816
|
type: c,
|
|
821
817
|
fee: s.fee_satoshi.toString(),
|
|
822
|
-
othersOutputs: c == "send" || c == "swap" ?
|
|
818
|
+
othersOutputs: c == "send" || c == "swap" ? r : [],
|
|
823
819
|
myOutputs: o,
|
|
824
820
|
myInputs: n
|
|
825
821
|
};
|
|
826
822
|
}
|
|
827
|
-
async buildAndSignTransferTransaction(e, t, s, n,
|
|
823
|
+
async buildAndSignTransferTransaction(e, t, s, n, i, o, r, c) {
|
|
828
824
|
const d = {
|
|
829
|
-
feeFromAmount:
|
|
825
|
+
feeFromAmount: i
|
|
830
826
|
}, u = this.prepareTransaction(t, n, o, c);
|
|
831
|
-
|
|
827
|
+
r && u.feePerByte(r);
|
|
832
828
|
let l = /* @__PURE__ */ new Map();
|
|
833
829
|
o && (l = await this.populateTokenInputsAndChange(u, e, s, o, BigInt(n)));
|
|
834
830
|
const h = await this.populateNexaInputsAndChange(u, e, s, d);
|
|
835
|
-
return l.forEach((p,
|
|
831
|
+
return l.forEach((p, _) => h.set(_, p)), await this.finalizeTransaction(u, Array.from(h.values()));
|
|
836
832
|
}
|
|
837
833
|
async buildAndSignConsolidateTransaction(e, t, s) {
|
|
838
834
|
const n = {
|
|
839
835
|
isConsolidate: !0,
|
|
840
836
|
templateData: s
|
|
841
|
-
},
|
|
842
|
-
return this.finalizeTransaction(
|
|
837
|
+
}, i = new Q(), o = await this.populateNexaInputsAndChange(i, e, t, n);
|
|
838
|
+
return this.finalizeTransaction(i, Array.from(o.values()));
|
|
843
839
|
}
|
|
844
840
|
prepareTransaction(e, t, s, n) {
|
|
845
841
|
if (!F(e) && !F(e, E.PayToPublicKeyHash))
|
|
846
842
|
throw new Error("Invalid Address.");
|
|
847
843
|
if (s && BigInt(t) < 1n || !s && parseInt(t) < B.DUST_AMOUNT)
|
|
848
844
|
throw new Error("The amount is too low.");
|
|
849
|
-
if (s && BigInt(t) >
|
|
845
|
+
if (s && BigInt(t) > ne || !s && parseInt(t) > B.MAX_MONEY)
|
|
850
846
|
throw new Error("The amount is too high.");
|
|
851
|
-
const
|
|
852
|
-
if (n &&
|
|
847
|
+
const i = new Q();
|
|
848
|
+
if (n && i.addData(n), s) {
|
|
853
849
|
if (!F(s, E.GroupIdAddress))
|
|
854
850
|
throw new Error("Invalid Token ID");
|
|
855
851
|
if (b.getOutputType(e) === 0)
|
|
856
852
|
throw new Error("Token must be sent to script template address");
|
|
857
|
-
|
|
853
|
+
i.to(e, B.DUST_AMOUNT, s, BigInt(t));
|
|
858
854
|
} else
|
|
859
|
-
|
|
860
|
-
return
|
|
855
|
+
i.to(e, t);
|
|
856
|
+
return i;
|
|
861
857
|
}
|
|
862
858
|
async populateNexaInputsAndChange(e, t, s, n) {
|
|
863
|
-
const
|
|
864
|
-
if (
|
|
859
|
+
const i = t.filter((d) => BigInt(d.balance.confirmed) + BigInt(d.balance.unconfirmed) > 0n);
|
|
860
|
+
if (P(i))
|
|
865
861
|
throw new Error("Not enough Nexa balance.");
|
|
866
|
-
const o = /* @__PURE__ */ new Map(),
|
|
867
|
-
for (const d of
|
|
862
|
+
const o = /* @__PURE__ */ new Map(), r = n.isConsolidate ? 0 : Number(e.transaction.outputs.find((d) => d.value > 0n).value);
|
|
863
|
+
for (const d of i) {
|
|
868
864
|
const u = await this.rostrumService.getNexaUtxos(d.address);
|
|
869
865
|
for (const l of u) {
|
|
870
866
|
const h = {
|
|
@@ -884,17 +880,17 @@ class qt {
|
|
|
884
880
|
const p = e.transaction;
|
|
885
881
|
if (p.inputs.length > this.MAX_INPUTS_OUTPUTS)
|
|
886
882
|
throw new Error("Too many inputs. Consider consolidate transactions or reduce the send amount.");
|
|
887
|
-
const
|
|
888
|
-
if (
|
|
883
|
+
const _ = p.getUnspentValue();
|
|
884
|
+
if (_ < 0n)
|
|
889
885
|
continue;
|
|
890
|
-
if (
|
|
886
|
+
if (_ == 0n && n.feeFromAmount) {
|
|
891
887
|
const H = p.estimateRequiredFee();
|
|
892
|
-
return p.updateOutputAmount(0,
|
|
888
|
+
return p.updateOutputAmount(0, r - H), o;
|
|
893
889
|
}
|
|
894
890
|
if (e.change(s), n.feeFromAmount) {
|
|
895
891
|
const H = p.getChangeOutput();
|
|
896
892
|
let K = p.estimateRequiredFee();
|
|
897
|
-
p.updateOutputAmount(0,
|
|
893
|
+
p.updateOutputAmount(0, r - K), !H && p.getChangeOutput() && (K = p.estimateRequiredFee(), p.updateOutputAmount(0, r - K));
|
|
898
894
|
}
|
|
899
895
|
if (p.getUnspentValue() < p.estimateRequiredFee())
|
|
900
896
|
continue;
|
|
@@ -914,13 +910,13 @@ class qt {
|
|
|
914
910
|
};
|
|
915
911
|
throw new Error(JSON.stringify(c));
|
|
916
912
|
}
|
|
917
|
-
async populateTokenInputsAndChange(e, t, s, n,
|
|
918
|
-
const o = S(n),
|
|
919
|
-
if (
|
|
913
|
+
async populateTokenInputsAndChange(e, t, s, n, i) {
|
|
914
|
+
const o = S(n), r = t.filter((u) => Object.keys(u.tokensBalance).includes(o));
|
|
915
|
+
if (P(r))
|
|
920
916
|
throw new Error("Not enough token balance.");
|
|
921
917
|
const c = /* @__PURE__ */ new Map();
|
|
922
918
|
let d = 0n;
|
|
923
|
-
for (const u of
|
|
919
|
+
for (const u of r) {
|
|
924
920
|
const l = await this.rostrumService.getTokenUtxos(u.address, n);
|
|
925
921
|
for (const h of l)
|
|
926
922
|
if (!(BigInt(h.token_amount) < 0n)) {
|
|
@@ -934,14 +930,14 @@ class qt {
|
|
|
934
930
|
const p = this.keyManager.getKey(u.keyPath);
|
|
935
931
|
c.set(u.address, p.privateKey);
|
|
936
932
|
}
|
|
937
|
-
if (d >
|
|
933
|
+
if (d > ne)
|
|
938
934
|
throw new Error("Token inputs exceeded max amount. Consider sending in small chunks");
|
|
939
935
|
if (e.transaction.inputs.length > this.MAX_INPUTS_OUTPUTS)
|
|
940
936
|
throw new Error("Too many inputs. Consider consolidating transactions or reduce the send amount.");
|
|
941
|
-
if (d ==
|
|
937
|
+
if (d == i)
|
|
942
938
|
return c;
|
|
943
|
-
if (d >
|
|
944
|
-
return e.to(s, B.DUST_AMOUNT, n, d -
|
|
939
|
+
if (d > i)
|
|
940
|
+
return e.to(s, B.DUST_AMOUNT, n, d - i), c;
|
|
945
941
|
}
|
|
946
942
|
}
|
|
947
943
|
throw new Error("Not enough token balance");
|
|
@@ -960,36 +956,63 @@ class qt {
|
|
|
960
956
|
return JSON.stringify(t, null, 2);
|
|
961
957
|
}
|
|
962
958
|
}
|
|
963
|
-
function
|
|
964
|
-
return
|
|
959
|
+
function Vt(a = 12) {
|
|
960
|
+
return Ce(de, a === 24 ? 256 : 128);
|
|
965
961
|
}
|
|
966
|
-
function
|
|
967
|
-
return
|
|
962
|
+
function Fe(a) {
|
|
963
|
+
return Pe(a, de);
|
|
968
964
|
}
|
|
969
|
-
async function
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
965
|
+
async function fe(a, e) {
|
|
966
|
+
const t = performance.now(), s = await crypto.subtle.importKey(
|
|
967
|
+
"raw",
|
|
968
|
+
new Uint8Array(a),
|
|
969
|
+
"PBKDF2",
|
|
970
|
+
!1,
|
|
971
|
+
["deriveKey"]
|
|
972
|
+
), n = await crypto.subtle.deriveKey(
|
|
973
|
+
{
|
|
974
|
+
name: "PBKDF2",
|
|
975
|
+
salt: new Uint8Array(e),
|
|
976
|
+
iterations: 21e4,
|
|
977
|
+
hash: "SHA-256"
|
|
978
|
+
},
|
|
979
|
+
s,
|
|
980
|
+
{
|
|
981
|
+
name: "AES-GCM",
|
|
982
|
+
length: 256
|
|
983
|
+
},
|
|
984
|
+
!1,
|
|
985
|
+
["encrypt", "decrypt"]
|
|
986
|
+
);
|
|
987
|
+
return console.log(performance.now() - t), n;
|
|
979
988
|
}
|
|
980
|
-
async function
|
|
981
|
-
const t =
|
|
982
|
-
|
|
989
|
+
async function Rt(a, e) {
|
|
990
|
+
const t = g.utf8ToBuffer(e), s = g.getRandomBuffer(16), n = g.getRandomBuffer(12), i = g.utf8ToBuffer(a), o = await fe(t, s), r = await crypto.subtle.encrypt(
|
|
991
|
+
{
|
|
992
|
+
name: "AES-GCM",
|
|
993
|
+
iv: new Uint8Array(n)
|
|
994
|
+
},
|
|
995
|
+
o,
|
|
996
|
+
new Uint8Array(i)
|
|
997
|
+
), c = g.concat([s, n, new Uint8Array(r)]);
|
|
998
|
+
return g.bufferToBase64(c);
|
|
983
999
|
}
|
|
984
|
-
async function
|
|
985
|
-
const t =
|
|
986
|
-
|
|
1000
|
+
async function Ge(a, e) {
|
|
1001
|
+
const t = g.utf8ToBuffer(e), s = g.base64ToBuffer(a), n = s.slice(0, 16), i = s.slice(16, 28), o = s.slice(28), r = await fe(t, n), c = await crypto.subtle.decrypt(
|
|
1002
|
+
{
|
|
1003
|
+
name: "AES-GCM",
|
|
1004
|
+
iv: i
|
|
1005
|
+
},
|
|
1006
|
+
r,
|
|
1007
|
+
o
|
|
1008
|
+
);
|
|
1009
|
+
return g.bufferToUtf8(new Uint8Array(c));
|
|
987
1010
|
}
|
|
988
|
-
async function
|
|
1011
|
+
async function Ht(a, e) {
|
|
989
1012
|
try {
|
|
990
1013
|
if (a) {
|
|
991
|
-
const t = await
|
|
992
|
-
if (t &&
|
|
1014
|
+
const t = await Ge(a, e);
|
|
1015
|
+
if (t && Fe(t))
|
|
993
1016
|
return t;
|
|
994
1017
|
}
|
|
995
1018
|
return !1;
|
|
@@ -997,7 +1020,7 @@ async function Wt(a, e) {
|
|
|
997
1020
|
return !1;
|
|
998
1021
|
}
|
|
999
1022
|
}
|
|
1000
|
-
const
|
|
1023
|
+
const pe = {
|
|
1001
1024
|
usd: "$",
|
|
1002
1025
|
eur: "€",
|
|
1003
1026
|
gbp: "£",
|
|
@@ -1006,46 +1029,46 @@ const we = {
|
|
|
1006
1029
|
aud: "A$",
|
|
1007
1030
|
cad: "C$",
|
|
1008
1031
|
chf: "Fr"
|
|
1009
|
-
},
|
|
1010
|
-
async function
|
|
1011
|
-
const a =
|
|
1032
|
+
}, ge = Object.keys(pe);
|
|
1033
|
+
async function qe() {
|
|
1034
|
+
const a = ge.join(","), e = await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=nexacoin&include_24hr_change=true&vs_currencies=${a}`);
|
|
1012
1035
|
if (!e.ok)
|
|
1013
1036
|
throw new Error("Failed to fetch price");
|
|
1014
1037
|
return (await e.json()).nexacoin || {};
|
|
1015
1038
|
}
|
|
1016
|
-
function
|
|
1017
|
-
return
|
|
1039
|
+
function Kt(a) {
|
|
1040
|
+
return pe[a] || a;
|
|
1018
1041
|
}
|
|
1019
|
-
function
|
|
1042
|
+
function ye() {
|
|
1020
1043
|
const a = {};
|
|
1021
|
-
return
|
|
1044
|
+
return ge.forEach((e) => {
|
|
1022
1045
|
a[e] = { value: 0, change: 0 };
|
|
1023
1046
|
}), a;
|
|
1024
1047
|
}
|
|
1025
|
-
function
|
|
1048
|
+
function Je() {
|
|
1026
1049
|
return A.empty().add(v.OP_FROMALTSTACK).add(v.OP_DROP).add(v.OP_FROMALTSTACK).add(v.OP_CHECKLOCKTIMEVERIFY).add(v.OP_DROP).add(v.OP_FROMALTSTACK).add(v.OP_CHECKSIGVERIFY);
|
|
1027
1050
|
}
|
|
1028
|
-
function
|
|
1029
|
-
const a =
|
|
1051
|
+
function ze() {
|
|
1052
|
+
const a = Je();
|
|
1030
1053
|
return U.sha256ripemd160(a.toBuffer());
|
|
1031
1054
|
}
|
|
1032
|
-
function
|
|
1055
|
+
function We(a) {
|
|
1033
1056
|
return A.empty().add(a.toBuffer());
|
|
1034
1057
|
}
|
|
1035
|
-
function
|
|
1036
|
-
const e =
|
|
1058
|
+
function je(a) {
|
|
1059
|
+
const e = We(a);
|
|
1037
1060
|
return U.sha256ripemd160(e.toBuffer());
|
|
1038
1061
|
}
|
|
1039
|
-
function
|
|
1062
|
+
function $e(a) {
|
|
1040
1063
|
return a.map((e) => e <= 16 ? J.smallInt(e) : z.fromNumber(e).toScriptNumBuffer());
|
|
1041
1064
|
}
|
|
1042
|
-
function
|
|
1065
|
+
function Xe(a, e) {
|
|
1043
1066
|
if (e.length !== 2)
|
|
1044
1067
|
return;
|
|
1045
|
-
const t =
|
|
1068
|
+
const t = ze(), s = je(a), n = $e(e);
|
|
1046
1069
|
return b.fromScriptTemplate(t, s, n).toString();
|
|
1047
1070
|
}
|
|
1048
|
-
class
|
|
1071
|
+
class Lt {
|
|
1049
1072
|
walletDb;
|
|
1050
1073
|
keyManager;
|
|
1051
1074
|
providers;
|
|
@@ -1066,8 +1089,8 @@ class $t {
|
|
|
1066
1089
|
}
|
|
1067
1090
|
add(e, t, s) {
|
|
1068
1091
|
this.providers.has(e.id) || this.providers.set(e.id, /* @__PURE__ */ new Map());
|
|
1069
|
-
const n = s.details.sessionId,
|
|
1070
|
-
this.registerHandlers(e, t, n),
|
|
1092
|
+
const n = s.details.sessionId, i = this.providers.get(e.id);
|
|
1093
|
+
this.registerHandlers(e, t, n), i.set(n, t), this.notify({ type: "session_added", accountId: e.id, sessionInfo: s });
|
|
1071
1094
|
}
|
|
1072
1095
|
remove(e, t) {
|
|
1073
1096
|
const s = this.providers.get(e);
|
|
@@ -1079,14 +1102,14 @@ class $t {
|
|
|
1079
1102
|
}
|
|
1080
1103
|
async reload(e) {
|
|
1081
1104
|
for (const t of e.values()) {
|
|
1082
|
-
if (t.id ==
|
|
1105
|
+
if (t.id == y)
|
|
1083
1106
|
continue;
|
|
1084
|
-
const s = await this.walletDb.getAccountSessions(t.id), n = this.providers.get(t.id),
|
|
1085
|
-
if (n?.has(
|
|
1107
|
+
const s = await this.walletDb.getAccountSessions(t.id), n = this.providers.get(t.id), i = s.map(async (r) => {
|
|
1108
|
+
if (n?.has(r.sessionId))
|
|
1086
1109
|
return;
|
|
1087
1110
|
let c;
|
|
1088
1111
|
try {
|
|
1089
|
-
c = new
|
|
1112
|
+
c = new Oe(r.uri);
|
|
1090
1113
|
const d = c.getSessionInfo();
|
|
1091
1114
|
await c.connect(3e3);
|
|
1092
1115
|
const u = await c.getAppInfo(2e3);
|
|
@@ -1111,11 +1134,11 @@ class $t {
|
|
|
1111
1134
|
});
|
|
1112
1135
|
return { account: t, provider: c, metadata: { details: d, appInfo: u } };
|
|
1113
1136
|
} catch (d) {
|
|
1114
|
-
console.error(`Failed to reload session ${
|
|
1137
|
+
console.error(`Failed to reload session ${r.sessionId}`, d), c?.disconnect(), await this.walletDb.removeSession(r.sessionId);
|
|
1115
1138
|
}
|
|
1116
|
-
}), o = await Promise.allSettled(
|
|
1117
|
-
for (const
|
|
1118
|
-
|
|
1139
|
+
}), o = await Promise.allSettled(i);
|
|
1140
|
+
for (const r of o)
|
|
1141
|
+
r.status === "fulfilled" && r.value && this.add(r.value.account, r.value.provider, r.value.metadata);
|
|
1119
1142
|
}
|
|
1120
1143
|
}
|
|
1121
1144
|
clear() {
|
|
@@ -1141,23 +1164,23 @@ class $t {
|
|
|
1141
1164
|
async replayMessage(e, t, s) {
|
|
1142
1165
|
const n = this.providers.get(e);
|
|
1143
1166
|
if (n) {
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1167
|
+
const i = n.get(t);
|
|
1168
|
+
i && await i.replayMessage(s);
|
|
1146
1169
|
}
|
|
1147
1170
|
}
|
|
1148
1171
|
registerHandlers(e, t, s) {
|
|
1149
1172
|
t.onSessionDelete(() => this.walletDb.removeSession(s)), t.onClose(() => {
|
|
1150
1173
|
this.removeOnClose && this.remove(e.id, s);
|
|
1151
1174
|
});
|
|
1152
|
-
const n = (
|
|
1153
|
-
this.handlers.set(
|
|
1175
|
+
const n = (i, o) => new Promise((r, c) => {
|
|
1176
|
+
this.handlers.set(i, { resolve: r, reject: c }), this.notify({ type: "new_request", request: { type: i, accountId: e.id, sessionId: s, request: o } });
|
|
1154
1177
|
});
|
|
1155
|
-
t.onSignMessage((
|
|
1156
|
-
const
|
|
1178
|
+
t.onSignMessage((i) => n(C.SignMessage, i)), t.onAddToken((i) => n(C.AddToken, i)), t.onSendTransaction((i) => n(C.SendTransaction, i)), t.onSignTransaction((i) => n(C.SignTransaction, i)), t.onGetAccount(() => {
|
|
1179
|
+
const i = { account: f.DAPP, type: m.RECEIVE, index: e.id };
|
|
1157
1180
|
return {
|
|
1158
1181
|
name: e.name,
|
|
1159
1182
|
address: e.address,
|
|
1160
|
-
pubkey: this.keyManager.getKey(
|
|
1183
|
+
pubkey: this.keyManager.getKey(i).publicKey.toString(),
|
|
1161
1184
|
blockchain: "nexa",
|
|
1162
1185
|
network: k.defaultNetwork.name,
|
|
1163
1186
|
capabilities: {
|
|
@@ -1170,7 +1193,7 @@ class $t {
|
|
|
1170
1193
|
});
|
|
1171
1194
|
}
|
|
1172
1195
|
}
|
|
1173
|
-
class
|
|
1196
|
+
class Ft {
|
|
1174
1197
|
rostrumService;
|
|
1175
1198
|
keyManager;
|
|
1176
1199
|
assetService;
|
|
@@ -1211,17 +1234,17 @@ class Xt {
|
|
|
1211
1234
|
await Promise.all(t);
|
|
1212
1235
|
}
|
|
1213
1236
|
async processInput(e, t) {
|
|
1214
|
-
const s = e.txDetails.tx.inputs[t], n = await this.rostrumService.getUtxo(
|
|
1237
|
+
const s = e.txDetails.tx.inputs[t], n = await this.rostrumService.getUtxo(g.bufferToHex(s.outpoint));
|
|
1215
1238
|
if (n.status == "spent")
|
|
1216
1239
|
throw new Error("Input UTXO is already spent.");
|
|
1217
|
-
if (s.output = new
|
|
1218
|
-
const
|
|
1240
|
+
if (s.output = new Ie(n.amount, n.scriptpubkey), s.output.address == e.address) {
|
|
1241
|
+
const i = n.token_id_hex || "NEXA";
|
|
1219
1242
|
e.myInputs.set(t, {
|
|
1220
1243
|
address: e.address,
|
|
1221
1244
|
nexaAmount: n.amount.toString(),
|
|
1222
|
-
assetId:
|
|
1245
|
+
assetId: i,
|
|
1223
1246
|
assetAmount: D(n.group_quantity) || n.amount.toString()
|
|
1224
|
-
}), e.involvedAssets.add(
|
|
1247
|
+
}), e.involvedAssets.add(i), s.scriptSig.isEmpty() && e.inputsToSign.add(t);
|
|
1225
1248
|
}
|
|
1226
1249
|
s.scriptSig.findPlaceholder() > 0 && e.inputsToSign.add(t);
|
|
1227
1250
|
}
|
|
@@ -1230,13 +1253,13 @@ class Xt {
|
|
|
1230
1253
|
const s = e.txDetails.tx.outputs[t].toObject();
|
|
1231
1254
|
if (s.address !== e.address)
|
|
1232
1255
|
continue;
|
|
1233
|
-
const n = s.groupId ? S(s.groupId) : "NEXA",
|
|
1256
|
+
const n = s.groupId ? S(s.groupId) : "NEXA", i = {
|
|
1234
1257
|
address: s.address,
|
|
1235
1258
|
nexaAmount: s.value.toString(),
|
|
1236
1259
|
assetId: n,
|
|
1237
1260
|
assetAmount: D(s.groupAmount) || s.value.toString()
|
|
1238
1261
|
};
|
|
1239
|
-
e.involvedAssets.add(n), e.myOutputs.set(t,
|
|
1262
|
+
e.involvedAssets.add(n), e.myOutputs.set(t, i);
|
|
1240
1263
|
}
|
|
1241
1264
|
}
|
|
1242
1265
|
signInputs(e) {
|
|
@@ -1246,13 +1269,13 @@ class Xt {
|
|
|
1246
1269
|
const s = e.txDetails.tx.inputs[t], n = this.validateAndGetSubscript(s);
|
|
1247
1270
|
if (s.scriptSig.isEmpty()) {
|
|
1248
1271
|
e.allMyOutputsCovered = !0;
|
|
1249
|
-
const
|
|
1250
|
-
s.scriptSig =
|
|
1272
|
+
const i = te.sign(e.txDetails.tx, t, se.ALL, n, e.privateKey).toTxFormat(), o = A.empty().add(e.privateKey.publicKey.toBuffer());
|
|
1273
|
+
s.scriptSig = xe.buildScriptTemplateIn(void 0, o, A.empty().add(i));
|
|
1251
1274
|
} else {
|
|
1252
|
-
const
|
|
1275
|
+
const i = s.scriptSig.findPlaceholder(), r = s.scriptSig.chunks[i].buf.subarray(64), c = se.fromBuffer(r);
|
|
1253
1276
|
this.processSignatureCoverage(e, c);
|
|
1254
|
-
const d = te.sign(e.txDetails.tx, t, c, n, e.privateKey).toTxFormat(
|
|
1255
|
-
s.scriptSig.replaceChunk(
|
|
1277
|
+
const d = te.sign(e.txDetails.tx, t, c, n, e.privateKey).toTxFormat(r);
|
|
1278
|
+
s.scriptSig.replaceChunk(i, A.empty().add(d));
|
|
1256
1279
|
}
|
|
1257
1280
|
}
|
|
1258
1281
|
if (!e.allMyOutputsCovered)
|
|
@@ -1268,7 +1291,7 @@ class Xt {
|
|
|
1268
1291
|
if (!e.scriptSig.isScriptTemplateIn())
|
|
1269
1292
|
throw new Error("Unsupported input script type.");
|
|
1270
1293
|
const t = e.output.scriptPubKey.getTemplateHash(), s = e.scriptSig.chunks[0].buf;
|
|
1271
|
-
if (
|
|
1294
|
+
if (g.equals(t, U.sha256ripemd160(s)) || g.equals(t, U.sha256sha256(s)))
|
|
1272
1295
|
return A.fromBuffer(s);
|
|
1273
1296
|
throw new Error("Invalid input script template.");
|
|
1274
1297
|
}
|
|
@@ -1296,68 +1319,68 @@ class Xt {
|
|
|
1296
1319
|
}
|
|
1297
1320
|
async processAssetMovements(e) {
|
|
1298
1321
|
const t = Array.from(e.myInputs.values()), s = Array.from(e.myOutputs.values()), n = [];
|
|
1299
|
-
for (const
|
|
1300
|
-
const o = this.processAssetMovement(e,
|
|
1322
|
+
for (const i of e.involvedAssets) {
|
|
1323
|
+
const o = this.processAssetMovement(e, i, t, s);
|
|
1301
1324
|
n.push(o);
|
|
1302
1325
|
}
|
|
1303
1326
|
await Promise.all(n);
|
|
1304
1327
|
}
|
|
1305
1328
|
async processAssetMovement(e, t, s, n) {
|
|
1306
|
-
const
|
|
1307
|
-
if (
|
|
1308
|
-
const
|
|
1309
|
-
t !== "NEXA" && (
|
|
1329
|
+
const i = s.reduce((r, c) => c.assetId === t ? r + BigInt(c.assetAmount) : r, 0n), o = n.reduce((r, c) => c.assetId === t ? r + BigInt(c.assetAmount) : r, 0n);
|
|
1330
|
+
if (i > 0n || o > 0n) {
|
|
1331
|
+
const r = { amount: o - i };
|
|
1332
|
+
t !== "NEXA" && (r.asset = await this.assetService.getAssetInfo(t)), r.amount > 0n ? e.txDetails.receive.push(r) : r.amount < 0n && e.txDetails.send.push(r);
|
|
1310
1333
|
}
|
|
1311
1334
|
}
|
|
1312
1335
|
}
|
|
1313
|
-
const
|
|
1314
|
-
class
|
|
1336
|
+
const Ye = 274710, Ze = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
1337
|
+
class Qe {
|
|
1315
1338
|
rostrumService;
|
|
1316
1339
|
keyManager;
|
|
1317
1340
|
constructor(e, t) {
|
|
1318
1341
|
this.rostrumService = e, this.keyManager = t;
|
|
1319
1342
|
}
|
|
1320
1343
|
async discoverWalletIndex(e, t) {
|
|
1321
|
-
let s = 0, n = !1,
|
|
1344
|
+
let s = 0, n = !1, i = 0;
|
|
1322
1345
|
do {
|
|
1323
1346
|
n = !0;
|
|
1324
|
-
for (let o =
|
|
1325
|
-
const
|
|
1347
|
+
for (let o = i; o < i + 20; o++) {
|
|
1348
|
+
const r = { account: e, type: t, index: o }, c = this.keyManager.getKey(r).privateKey.toAddress().toString();
|
|
1326
1349
|
await this.rostrumService.isAddressUsed(c) && (s = o, n = !1);
|
|
1327
1350
|
}
|
|
1328
|
-
|
|
1351
|
+
i += 20;
|
|
1329
1352
|
} while (!n);
|
|
1330
1353
|
return s;
|
|
1331
1354
|
}
|
|
1332
1355
|
async discoverVaults(e) {
|
|
1333
1356
|
const t = [];
|
|
1334
|
-
for (const
|
|
1335
|
-
const o = this.checkVaultsForAddress(
|
|
1357
|
+
for (const i of e) {
|
|
1358
|
+
const o = this.checkVaultsForAddress(i);
|
|
1336
1359
|
t.push(o);
|
|
1337
1360
|
}
|
|
1338
1361
|
const s = await Promise.all(t), n = /* @__PURE__ */ new Map();
|
|
1339
|
-
return s.forEach((
|
|
1340
|
-
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1362
|
+
return s.forEach((i) => {
|
|
1363
|
+
i.forEach((o) => {
|
|
1364
|
+
const r = this.parseVaultDetails(o);
|
|
1365
|
+
r && n.set(r.address, r);
|
|
1343
1366
|
});
|
|
1344
1367
|
}), n;
|
|
1345
1368
|
}
|
|
1346
1369
|
async checkVaultsForAddress(e) {
|
|
1347
|
-
const t = /* @__PURE__ */ new Set(), s = await this.rostrumService.getTransactionsHistory(e,
|
|
1370
|
+
const t = /* @__PURE__ */ new Set(), s = await this.rostrumService.getTransactionsHistory(e, Ye);
|
|
1348
1371
|
for (const n of s) {
|
|
1349
|
-
const o = (await this.rostrumService.getTransaction(n.tx_hash)).vout.filter((
|
|
1350
|
-
for (const
|
|
1351
|
-
t.add(
|
|
1372
|
+
const o = (await this.rostrumService.getTransaction(n.tx_hash)).vout.filter((r) => r.scriptPubKey.hex.startsWith(Ze));
|
|
1373
|
+
for (const r of o)
|
|
1374
|
+
t.add(r.scriptPubKey.hex);
|
|
1352
1375
|
}
|
|
1353
1376
|
return t;
|
|
1354
1377
|
}
|
|
1355
1378
|
parseVaultDetails(e) {
|
|
1356
|
-
const t = A.fromHex(e), s = new
|
|
1379
|
+
const t = A.fromHex(e), s = new Ne().writeVarLengthBuf(t.toBuffer()).toBuffer(), n = new b(s).toString(), i = t.getVisibleArgs(), o = z.fromScriptNumBuffer(i.chunks[0].buf).toNumber(), r = J.isSmallIntOp(i.chunks[1].opcodenum) ? J.decodeOP_N(i.chunks[1].opcodenum) : z.fromScriptNumBuffer(i.chunks[1].buf).toNumber(), c = [o, r], d = this.keyManager.getKey({ account: f.VAULT, type: m.RECEIVE, index: r }), u = Xe(d.publicKey, c);
|
|
1357
1380
|
return n != u ? void 0 : {
|
|
1358
1381
|
address: n,
|
|
1359
1382
|
block: o,
|
|
1360
|
-
idx:
|
|
1383
|
+
idx: r,
|
|
1361
1384
|
statusHash: "",
|
|
1362
1385
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1363
1386
|
tokensBalance: {},
|
|
@@ -1367,8 +1390,8 @@ class at {
|
|
|
1367
1390
|
}
|
|
1368
1391
|
}
|
|
1369
1392
|
class N {
|
|
1370
|
-
constructor(e, t, s, n,
|
|
1371
|
-
this.keyManager = e, this.kvStore = t, this.walletDb = s, this.rostrumService = n, this.assetService =
|
|
1393
|
+
constructor(e, t, s, n, i, o, r) {
|
|
1394
|
+
this.keyManager = e, this.kvStore = t, this.walletDb = s, this.rostrumService = n, this.assetService = i, this.transactionService = o, this.sessionManager = r, this.discoveryService = new Qe(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();
|
|
1372
1395
|
}
|
|
1373
1396
|
static GAP_LIMIT = 20;
|
|
1374
1397
|
static DEBOUNCE_MS = 1e3;
|
|
@@ -1397,11 +1420,11 @@ class N {
|
|
|
1397
1420
|
getReceiveAddress() {
|
|
1398
1421
|
return this.receiveAddresses.find((e) => !e.used).address;
|
|
1399
1422
|
}
|
|
1400
|
-
getChangeAddress(e =
|
|
1401
|
-
return e !=
|
|
1423
|
+
getChangeAddress(e = y) {
|
|
1424
|
+
return e != y ? this.accounts.get(e).address : this.changeAddresses.find((t) => !t.used).address;
|
|
1402
1425
|
}
|
|
1403
|
-
getUsedAddressKeys(e =
|
|
1404
|
-
if (e !=
|
|
1426
|
+
getUsedAddressKeys(e = y) {
|
|
1427
|
+
if (e != y) {
|
|
1405
1428
|
const t = this.accounts.get(e);
|
|
1406
1429
|
return [{
|
|
1407
1430
|
address: t.address,
|
|
@@ -1428,8 +1451,8 @@ class N {
|
|
|
1428
1451
|
}
|
|
1429
1452
|
async discoverWallet() {
|
|
1430
1453
|
this.notify({ type: "discover_wallet", loading: !0 });
|
|
1431
|
-
const e = this.discoveryService.discoverWalletIndex(f.MAIN,
|
|
1432
|
-
this.receiveAddresses = this.deriveAddresses(
|
|
1454
|
+
const e = this.discoveryService.discoverWalletIndex(f.MAIN, m.RECEIVE), t = this.discoveryService.discoverWalletIndex(f.MAIN, m.CHANGE), s = this.discoveryService.discoverWalletIndex(f.DAPP, m.RECEIVE), [n, i, o] = await Promise.all([e, t, s]);
|
|
1455
|
+
this.receiveAddresses = this.deriveAddresses(m.RECEIVE, 0, n + N.GAP_LIMIT), this.changeAddresses = this.deriveAddresses(m.CHANGE, 0, i + N.GAP_LIMIT), this.accounts = this.deriveAccounts(0, o + 1), this.accounts.forEach((r) => this.accountsAddressToId.set(r.address, r.id)), await this.saveAddresses(this.receiveAddresses), await this.saveAddresses(this.changeAddresses), await this.saveAccounts(this.accounts), this.initState(), await this.initialSync(), this.notify({ type: "discover_wallet", loading: !1 }), this.notify({ type: "load_wallet", loading: !1 }), await this.rescanVaults();
|
|
1433
1456
|
}
|
|
1434
1457
|
async loadWallet() {
|
|
1435
1458
|
this.receiveAddresses = await this.walletDb.getReceiveAddresses(), this.changeAddresses = await this.walletDb.getChangeAddresses();
|
|
@@ -1441,7 +1464,7 @@ class N {
|
|
|
1441
1464
|
async initialSync() {
|
|
1442
1465
|
await this.subscribeAddresses(this.getAllAddresses(), !0);
|
|
1443
1466
|
const e = [];
|
|
1444
|
-
e.push(this.assetService.fetchAndSaveTokens(
|
|
1467
|
+
e.push(this.assetService.fetchAndSaveTokens(y, G(this.getMainAddresses().map((t) => t.tokensBalance))));
|
|
1445
1468
|
for (const t of this.accounts.values())
|
|
1446
1469
|
e.push(this.assetService.fetchAndSaveTokens(t.id, t.tokensBalance));
|
|
1447
1470
|
await Promise.all(e);
|
|
@@ -1457,10 +1480,10 @@ class N {
|
|
|
1457
1480
|
this.notify({
|
|
1458
1481
|
type: "new_account",
|
|
1459
1482
|
account: {
|
|
1460
|
-
id:
|
|
1483
|
+
id: y,
|
|
1461
1484
|
name: "Main Wallet",
|
|
1462
1485
|
address: this.getReceiveAddress(),
|
|
1463
|
-
balance:
|
|
1486
|
+
balance: re(e.map((t) => t.balance)),
|
|
1464
1487
|
tokensBalance: G(e.map((t) => t.tokensBalance)),
|
|
1465
1488
|
tokens: [],
|
|
1466
1489
|
sessions: {}
|
|
@@ -1492,11 +1515,11 @@ class N {
|
|
|
1492
1515
|
}
|
|
1493
1516
|
deriveAddresses(e, t, s) {
|
|
1494
1517
|
const n = [];
|
|
1495
|
-
for (let
|
|
1496
|
-
const o = x(f.MAIN, e,
|
|
1518
|
+
for (let i = t; i < t + s; i++) {
|
|
1519
|
+
const o = x(f.MAIN, e, i), c = {
|
|
1497
1520
|
address: this.keyManager.getKey(o).privateKey.toAddress().toString(),
|
|
1498
1521
|
space: e,
|
|
1499
|
-
idx:
|
|
1522
|
+
idx: i,
|
|
1500
1523
|
used: !1,
|
|
1501
1524
|
height: 0,
|
|
1502
1525
|
statusHash: "",
|
|
@@ -1511,7 +1534,7 @@ class N {
|
|
|
1511
1534
|
deriveAccounts(e, t) {
|
|
1512
1535
|
const s = /* @__PURE__ */ new Map();
|
|
1513
1536
|
for (let n = e; n < e + t; n++) {
|
|
1514
|
-
const
|
|
1537
|
+
const i = x(f.DAPP, 0, n), o = this.keyManager.getKey(i).privateKey.toAddress().toString(), r = {
|
|
1515
1538
|
id: n,
|
|
1516
1539
|
name: `Account ${n + 1}`,
|
|
1517
1540
|
address: o,
|
|
@@ -1522,7 +1545,7 @@ class N {
|
|
|
1522
1545
|
tokensBalance: {},
|
|
1523
1546
|
type: f.DAPP
|
|
1524
1547
|
};
|
|
1525
|
-
s.set(
|
|
1548
|
+
s.set(r.id, r);
|
|
1526
1549
|
}
|
|
1527
1550
|
return s;
|
|
1528
1551
|
}
|
|
@@ -1536,26 +1559,26 @@ class N {
|
|
|
1536
1559
|
}
|
|
1537
1560
|
async subscribeAddresses(e, t = !1) {
|
|
1538
1561
|
const s = e.map(async (o) => {
|
|
1539
|
-
const
|
|
1540
|
-
return { addr: o, result:
|
|
1541
|
-
}), n = [],
|
|
1542
|
-
for (const { addr: o, result:
|
|
1543
|
-
if (
|
|
1562
|
+
const r = await this.rostrumService.subscribeAddress(o.address, this.onSubscribeEvent);
|
|
1563
|
+
return { addr: o, result: r };
|
|
1564
|
+
}), n = [], i = await Promise.all(s);
|
|
1565
|
+
for (const { addr: o, result: r } of i)
|
|
1566
|
+
if (r && typeof r == "string" && o.statusHash != r) {
|
|
1544
1567
|
if (t) {
|
|
1545
1568
|
const c = new Promise((d) => {
|
|
1546
1569
|
this.addressResolvers.set(o.address, d);
|
|
1547
1570
|
});
|
|
1548
1571
|
n.push(c);
|
|
1549
1572
|
}
|
|
1550
|
-
this.registerUpdate({ address: o, result:
|
|
1573
|
+
this.registerUpdate({ address: o, result: r });
|
|
1551
1574
|
}
|
|
1552
1575
|
await Promise.all(n);
|
|
1553
1576
|
}
|
|
1554
1577
|
onSubscribeEvent = (e) => {
|
|
1555
1578
|
if (!Array.isArray(e) || e.length < 2)
|
|
1556
1579
|
return;
|
|
1557
|
-
const [t, s] = e,
|
|
1558
|
-
|
|
1580
|
+
const [t, s] = e, i = this.getAllAddresses().find((o) => o.address === t);
|
|
1581
|
+
i && i.statusHash !== s && this.registerUpdate({ address: i, result: s });
|
|
1559
1582
|
};
|
|
1560
1583
|
registerUpdate(e) {
|
|
1561
1584
|
this.pendingUpdates.set(e.address.address, e), clearTimeout(this.updateTimer), this.updateTimer = setTimeout(() => {
|
|
@@ -1569,26 +1592,26 @@ class N {
|
|
|
1569
1592
|
const e = Array.from(this.pendingUpdates);
|
|
1570
1593
|
this.pendingUpdates.clear();
|
|
1571
1594
|
const t = [], s = [], n = [];
|
|
1572
|
-
for (const [,
|
|
1573
|
-
if (this.isAccountAddress(
|
|
1574
|
-
const c = this.fetchAndUpdateAccount(
|
|
1595
|
+
for (const [, r] of e)
|
|
1596
|
+
if (this.isAccountAddress(r.address)) {
|
|
1597
|
+
const c = this.fetchAndUpdateAccount(r.address, r.result);
|
|
1575
1598
|
t.push(c);
|
|
1576
|
-
} else if (this.isVaultAddress(
|
|
1577
|
-
const c = this.fetchAndUpdateVault(
|
|
1599
|
+
} else if (this.isVaultAddress(r.address)) {
|
|
1600
|
+
const c = this.fetchAndUpdateVault(r.address, r.result);
|
|
1578
1601
|
s.push(c);
|
|
1579
1602
|
} else {
|
|
1580
|
-
const c = this.fetchAndUpdateAddress(
|
|
1603
|
+
const c = this.fetchAndUpdateAddress(r.address, r.result);
|
|
1581
1604
|
n.push(c);
|
|
1582
1605
|
}
|
|
1583
|
-
const
|
|
1606
|
+
const i = await Promise.all(t);
|
|
1584
1607
|
await Promise.all(s);
|
|
1585
1608
|
const o = await Promise.all(n);
|
|
1586
1609
|
if (this.addressResolvers.size > 0)
|
|
1587
|
-
for (const [
|
|
1588
|
-
const c = this.addressResolvers.get(
|
|
1589
|
-
c && (c(), this.addressResolvers.delete(
|
|
1610
|
+
for (const [r] of e) {
|
|
1611
|
+
const c = this.addressResolvers.get(r);
|
|
1612
|
+
c && (c(), this.addressResolvers.delete(r));
|
|
1590
1613
|
}
|
|
1591
|
-
await Promise.all([this.postProcessWalletUpdate(o), this.postProcessAccountUpdate(
|
|
1614
|
+
await Promise.all([this.postProcessWalletUpdate(o), this.postProcessAccountUpdate(i)]);
|
|
1592
1615
|
} catch (e) {
|
|
1593
1616
|
console.error("Error processing pending updates:", e);
|
|
1594
1617
|
} finally {
|
|
@@ -1599,15 +1622,15 @@ class N {
|
|
|
1599
1622
|
if (e.length === 0)
|
|
1600
1623
|
return;
|
|
1601
1624
|
const t = /* @__PURE__ */ new Map();
|
|
1602
|
-
for (const { txs:
|
|
1603
|
-
for (const c of
|
|
1625
|
+
for (const { txs: r } of e)
|
|
1626
|
+
for (const c of r)
|
|
1604
1627
|
t.set(c.tx_hash, c);
|
|
1605
|
-
await this.checkGapLimit(
|
|
1606
|
-
const s = this.getMainAddresses(), n =
|
|
1607
|
-
this.notify({ type: "account_balance_updated", accountId:
|
|
1608
|
-
const o = this.assetService.syncNfts(
|
|
1609
|
-
for (const
|
|
1610
|
-
await this.transactionService.classifyAndSaveTransaction(
|
|
1628
|
+
await this.checkGapLimit(m.RECEIVE), await this.checkGapLimit(m.CHANGE);
|
|
1629
|
+
const s = this.getMainAddresses(), n = re(s.map((r) => r.balance)), i = G(s.map((r) => r.tokensBalance));
|
|
1630
|
+
this.notify({ type: "account_balance_updated", accountId: y, balance: n, tokensBalance: i }), this.notify({ type: "main_address_updated", address: this.getReceiveAddress() });
|
|
1631
|
+
const o = this.assetService.syncNfts(y, i);
|
|
1632
|
+
for (const r of t.values())
|
|
1633
|
+
await this.transactionService.classifyAndSaveTransaction(y, r.tx_hash, s.map((c) => c.address));
|
|
1611
1634
|
await o;
|
|
1612
1635
|
}
|
|
1613
1636
|
async postProcessAccountUpdate(e) {
|
|
@@ -1615,10 +1638,10 @@ class N {
|
|
|
1615
1638
|
for (const { address: t, txs: s } of e) {
|
|
1616
1639
|
const n = t;
|
|
1617
1640
|
this.notify({ type: "account_balance_updated", accountId: n.id, balance: n.balance, tokensBalance: n.tokensBalance });
|
|
1618
|
-
const
|
|
1641
|
+
const i = this.assetService.syncNfts(n.id, n.tokensBalance);
|
|
1619
1642
|
for (const o of s)
|
|
1620
1643
|
await this.transactionService.classifyAndSaveTransaction(n.id, o.tx_hash, [n.address]);
|
|
1621
|
-
await
|
|
1644
|
+
await i;
|
|
1622
1645
|
}
|
|
1623
1646
|
}
|
|
1624
1647
|
async fetchAndUpdateAddress(e, t) {
|
|
@@ -1637,16 +1660,16 @@ class N {
|
|
|
1637
1660
|
return e.height = s.lastHeight, await this.walletDb.saveVault(e), this.notify({ type: "vault_balance_updated", address: e.address, balance: e.balance }), { address: e, txs: s.txs };
|
|
1638
1661
|
}
|
|
1639
1662
|
async checkGapLimit(e) {
|
|
1640
|
-
const t = e ===
|
|
1663
|
+
const t = e === m.RECEIVE ? this.receiveAddresses : this.changeAddresses, s = e === m.RECEIVE ? "Receive" : "Change", n = t.filter((i) => !i.used).length;
|
|
1641
1664
|
if (n < N.GAP_LIMIT) {
|
|
1642
|
-
const
|
|
1643
|
-
console.log(`Deriving ${
|
|
1644
|
-
const
|
|
1645
|
-
e ===
|
|
1665
|
+
const i = N.GAP_LIMIT - n, o = t[t.length - 1].idx;
|
|
1666
|
+
console.log(`Deriving ${i} more ${s} addresses...`);
|
|
1667
|
+
const r = this.deriveAddresses(e, o + 1, i);
|
|
1668
|
+
e === m.RECEIVE ? this.receiveAddresses.push(...r) : this.changeAddresses.push(...r), await this.saveAddresses(r), await this.subscribeAddresses(r);
|
|
1646
1669
|
}
|
|
1647
1670
|
}
|
|
1648
1671
|
async addNewAccount(e, t) {
|
|
1649
|
-
const s = x(f.DAPP, 0, e), n = this.keyManager.getKey(s).privateKey.toAddress().toString(),
|
|
1672
|
+
const s = x(f.DAPP, 0, e), n = this.keyManager.getKey(s).privateKey.toAddress().toString(), i = {
|
|
1650
1673
|
id: e,
|
|
1651
1674
|
name: t,
|
|
1652
1675
|
address: n,
|
|
@@ -1657,14 +1680,14 @@ class N {
|
|
|
1657
1680
|
tokensBalance: {},
|
|
1658
1681
|
type: f.DAPP
|
|
1659
1682
|
};
|
|
1660
|
-
this.accounts.set(e,
|
|
1683
|
+
this.accounts.set(e, i), this.accountsAddressToId.set(n, e), await this.walletDb.saveAccount(i), await this.subscribeAddresses([i]), this.notify({
|
|
1661
1684
|
type: "new_account",
|
|
1662
1685
|
account: {
|
|
1663
|
-
id:
|
|
1664
|
-
name:
|
|
1665
|
-
address:
|
|
1666
|
-
balance:
|
|
1667
|
-
tokensBalance:
|
|
1686
|
+
id: i.id,
|
|
1687
|
+
name: i.name,
|
|
1688
|
+
address: i.address,
|
|
1689
|
+
balance: i.balance,
|
|
1690
|
+
tokensBalance: i.tokensBalance,
|
|
1668
1691
|
tokens: [],
|
|
1669
1692
|
sessions: {}
|
|
1670
1693
|
}
|
|
@@ -1677,7 +1700,7 @@ class N {
|
|
|
1677
1700
|
s.name = t, await this.walletDb.updateAccountName(e, t);
|
|
1678
1701
|
}
|
|
1679
1702
|
rescanAccount(e) {
|
|
1680
|
-
if (e ==
|
|
1703
|
+
if (e == y) {
|
|
1681
1704
|
const t = this.getMainAddresses();
|
|
1682
1705
|
for (const s of t)
|
|
1683
1706
|
s.height = 0, this.registerUpdate({ address: s, result: s.statusHash });
|
|
@@ -1716,8 +1739,8 @@ class N {
|
|
|
1716
1739
|
async rescanVaults() {
|
|
1717
1740
|
let e = !1;
|
|
1718
1741
|
const t = await this.discoveryService.discoverVaults(this.getMainAddresses().map((n) => n.address)), s = [];
|
|
1719
|
-
for (const [n,
|
|
1720
|
-
this.vaults.has(n) || (e = !0, s.push(this.addVault(
|
|
1742
|
+
for (const [n, i] of t)
|
|
1743
|
+
this.vaults.has(n) || (e = !0, s.push(this.addVault(i)));
|
|
1721
1744
|
return await Promise.all(s), e;
|
|
1722
1745
|
}
|
|
1723
1746
|
isVaultAddress(e) {
|
|
@@ -1730,12 +1753,12 @@ class N {
|
|
|
1730
1753
|
return e.type == f.MAIN;
|
|
1731
1754
|
}
|
|
1732
1755
|
}
|
|
1733
|
-
const
|
|
1756
|
+
const et = {
|
|
1734
1757
|
isWalletExist: !1,
|
|
1735
1758
|
isAuthorized: !1
|
|
1736
|
-
},
|
|
1759
|
+
}, me = M({
|
|
1737
1760
|
name: "auth",
|
|
1738
|
-
initialState:
|
|
1761
|
+
initialState: et,
|
|
1739
1762
|
reducers: {
|
|
1740
1763
|
setWalletExist: (a, e) => {
|
|
1741
1764
|
a.isWalletExist = e.payload;
|
|
@@ -1744,12 +1767,12 @@ const nt = {
|
|
|
1744
1767
|
a.isAuthorized = e.payload;
|
|
1745
1768
|
}
|
|
1746
1769
|
}
|
|
1747
|
-
}),
|
|
1770
|
+
}), Gt = me.actions, tt = me.reducer, st = {
|
|
1748
1771
|
modalType: null,
|
|
1749
1772
|
currentRequest: null
|
|
1750
|
-
},
|
|
1773
|
+
}, we = M({
|
|
1751
1774
|
name: "dappModal",
|
|
1752
|
-
initialState:
|
|
1775
|
+
initialState: st,
|
|
1753
1776
|
reducers: {
|
|
1754
1777
|
showRequest(a, e) {
|
|
1755
1778
|
a.modalType = e.payload.type, a.currentRequest = e.payload;
|
|
@@ -1758,24 +1781,24 @@ const nt = {
|
|
|
1758
1781
|
a.modalType = null, a.currentRequest = null;
|
|
1759
1782
|
}
|
|
1760
1783
|
}
|
|
1761
|
-
}),
|
|
1784
|
+
}), qt = we.actions, at = we.reducer, nt = {
|
|
1762
1785
|
counter: 0,
|
|
1763
1786
|
loading: !1
|
|
1764
|
-
},
|
|
1787
|
+
}, ve = M({
|
|
1765
1788
|
name: "loader",
|
|
1766
|
-
initialState:
|
|
1789
|
+
initialState: nt,
|
|
1767
1790
|
reducers: {
|
|
1768
1791
|
setLoader: (a, e) => {
|
|
1769
1792
|
const t = e.payload.loading ? a.counter + 1 : Math.max(0, a.counter - 1);
|
|
1770
1793
|
a.counter = t, a.loading = t > 0, a.text = e.payload.text;
|
|
1771
1794
|
}
|
|
1772
1795
|
}
|
|
1773
|
-
}),
|
|
1796
|
+
}), Jt = ve.actions, it = ve.reducer, rt = {
|
|
1774
1797
|
wallet: {},
|
|
1775
1798
|
web3: {}
|
|
1776
|
-
},
|
|
1799
|
+
}, Ae = M({
|
|
1777
1800
|
name: "notifications",
|
|
1778
|
-
initialState:
|
|
1801
|
+
initialState: rt,
|
|
1779
1802
|
reducers: {
|
|
1780
1803
|
addNotification: (a, e) => {
|
|
1781
1804
|
e.payload.type == "wallet" ? a.wallet[e.payload.id] = e.payload : e.payload.type == "web3" && (a.web3[e.payload.id] = e.payload);
|
|
@@ -1787,16 +1810,16 @@ const nt = {
|
|
|
1787
1810
|
e.payload === "wallet" ? a.wallet = {} : e.payload === "web3" ? a.web3 = {} : e.payload === "all" && (a.wallet = {}, a.web3 = {});
|
|
1788
1811
|
}
|
|
1789
1812
|
}
|
|
1790
|
-
}),
|
|
1813
|
+
}), zt = Ae.actions, ot = Ae.reducer, ct = {
|
|
1791
1814
|
status: "Offline",
|
|
1792
1815
|
height: 0,
|
|
1793
|
-
price:
|
|
1816
|
+
price: ye(),
|
|
1794
1817
|
hasNetwork: !0,
|
|
1795
1818
|
isSuspended: !1
|
|
1796
|
-
},
|
|
1797
|
-
const a =
|
|
1819
|
+
}, ce = Ue("status/fetchPrice", async () => {
|
|
1820
|
+
const a = ye();
|
|
1798
1821
|
try {
|
|
1799
|
-
const e = await
|
|
1822
|
+
const e = await qe();
|
|
1800
1823
|
Object.keys(e).forEach((t) => {
|
|
1801
1824
|
a[t] = {
|
|
1802
1825
|
value: e[t],
|
|
@@ -1806,9 +1829,9 @@ const nt = {
|
|
|
1806
1829
|
} catch {
|
|
1807
1830
|
}
|
|
1808
1831
|
return a;
|
|
1809
|
-
}),
|
|
1832
|
+
}), Se = M({
|
|
1810
1833
|
name: "status",
|
|
1811
|
-
initialState:
|
|
1834
|
+
initialState: ct,
|
|
1812
1835
|
reducers: {
|
|
1813
1836
|
setHeight: (a, e) => {
|
|
1814
1837
|
e.payload > 0 && (a.status = "Online"), a.height = e.payload;
|
|
@@ -1824,18 +1847,18 @@ const nt = {
|
|
|
1824
1847
|
}
|
|
1825
1848
|
},
|
|
1826
1849
|
extraReducers: (a) => {
|
|
1827
|
-
a.addCase(
|
|
1850
|
+
a.addCase(ce.fulfilled, (e, t) => {
|
|
1828
1851
|
e.price = t.payload;
|
|
1829
|
-
}).addCase(
|
|
1852
|
+
}).addCase(ce.rejected, (e, t) => {
|
|
1830
1853
|
console.error(t.error.message);
|
|
1831
1854
|
});
|
|
1832
1855
|
}
|
|
1833
|
-
}),
|
|
1856
|
+
}), Wt = Se.actions, dt = Se.reducer, ut = {
|
|
1834
1857
|
isAuthorized: !1,
|
|
1835
|
-
selectedAccount:
|
|
1858
|
+
selectedAccount: y,
|
|
1836
1859
|
accounts: {
|
|
1837
1860
|
"-1": {
|
|
1838
|
-
id:
|
|
1861
|
+
id: y,
|
|
1839
1862
|
name: "Main Wallet",
|
|
1840
1863
|
address: "",
|
|
1841
1864
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
@@ -1849,9 +1872,9 @@ const nt = {
|
|
|
1849
1872
|
initLoad: !0,
|
|
1850
1873
|
txUpdateTrigger: 0,
|
|
1851
1874
|
nftsUpdateTrigger: 0
|
|
1852
|
-
},
|
|
1875
|
+
}, be = M({
|
|
1853
1876
|
name: "wallet",
|
|
1854
|
-
initialState:
|
|
1877
|
+
initialState: ut,
|
|
1855
1878
|
reducers: {
|
|
1856
1879
|
setInitLoad: (a, e) => {
|
|
1857
1880
|
a.initLoad = e.payload;
|
|
@@ -1872,7 +1895,7 @@ const nt = {
|
|
|
1872
1895
|
a.accounts[e.payload.id] = e.payload;
|
|
1873
1896
|
},
|
|
1874
1897
|
setMainAddress: (a, e) => {
|
|
1875
|
-
a.accounts[
|
|
1898
|
+
a.accounts[y].address = e.payload;
|
|
1876
1899
|
},
|
|
1877
1900
|
setAccountBalance: (a, e) => {
|
|
1878
1901
|
a.accounts[e.payload.id].balance = e.payload.balance, a.accounts[e.payload.id].tokensBalance = e.payload.tokensBalance;
|
|
@@ -1907,108 +1930,108 @@ const nt = {
|
|
|
1907
1930
|
a.accounts[e.payload.accountId].sessions = {};
|
|
1908
1931
|
}
|
|
1909
1932
|
}
|
|
1910
|
-
}),
|
|
1911
|
-
loader:
|
|
1912
|
-
dapp:
|
|
1913
|
-
status:
|
|
1914
|
-
wallet:
|
|
1915
|
-
auth:
|
|
1916
|
-
notifications:
|
|
1917
|
-
}, w =
|
|
1933
|
+
}), jt = be.actions, lt = be.reducer, $t = {
|
|
1934
|
+
loader: it,
|
|
1935
|
+
dapp: at,
|
|
1936
|
+
status: dt,
|
|
1937
|
+
wallet: lt,
|
|
1938
|
+
auth: tt,
|
|
1939
|
+
notifications: ot
|
|
1940
|
+
}, w = De.withTypes(), Xt = () => w((a) => a.auth), Yt = () => w((a) => a.status.height), Zt = (a) => w((e) => e.wallet.accounts[a]), Qt = () => w((a) => a.wallet.selectedAccount), es = () => w((a) => Math.max(...Object.keys(a.wallet.accounts).map(Number))), ts = (a) => w((e) => e.wallet.accounts[a].address), ss = (a) => w((e) => e.wallet.accounts[a].balance), as = (a, e) => w((t) => t.wallet.accounts[a].tokensBalance[e]), ns = (a, e) => w((t) => t.wallet.accounts[a].sessions[e]), is = () => w((a) => a.wallet.vaults), ke = j(
|
|
1918
1941
|
[(a) => a.notifications.wallet],
|
|
1919
1942
|
(a) => Object.values(a).sort((e, t) => t.createdAt - e.createdAt)
|
|
1920
|
-
),
|
|
1943
|
+
), Te = j(
|
|
1921
1944
|
[(a) => a.notifications.web3],
|
|
1922
1945
|
(a) => Object.values(a).sort((e, t) => t.createdAt - e.createdAt)
|
|
1923
|
-
),
|
|
1924
|
-
[
|
|
1946
|
+
), ht = j(
|
|
1947
|
+
[ke, Te],
|
|
1925
1948
|
(a, e) => [...a, ...e].sort((t, s) => s.createdAt - t.createdAt)
|
|
1926
|
-
),
|
|
1949
|
+
), rs = () => w(ke), os = () => w(Te), cs = () => w(ht);
|
|
1927
1950
|
export {
|
|
1928
1951
|
f as AccountType,
|
|
1929
|
-
|
|
1952
|
+
Ut as AssetService,
|
|
1930
1953
|
V as AssetType,
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1954
|
+
Mt as KVStore,
|
|
1955
|
+
Pt as KeyManager,
|
|
1956
|
+
m as KeySpace,
|
|
1957
|
+
y as MAIN_WALLET_ID,
|
|
1958
|
+
ne as MAX_INT64,
|
|
1959
|
+
le as RostrumService,
|
|
1960
|
+
Lt as SessionManager,
|
|
1961
|
+
C as SessionRequestType,
|
|
1962
|
+
Dt as TransactionService,
|
|
1963
|
+
Ft as TransactionTransformer,
|
|
1964
|
+
Ve as VAULT_FIRST_BLOCK,
|
|
1965
|
+
St as VAULT_SCRIPT_PREFIX,
|
|
1966
|
+
Ct as WalletCache,
|
|
1967
|
+
Bt as WalletDB,
|
|
1945
1968
|
N as WalletManager,
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1969
|
+
Gt as authActions,
|
|
1970
|
+
tt as authReducer,
|
|
1971
|
+
xt as capitalizeFirstLetter,
|
|
1972
|
+
ge as currencies,
|
|
1950
1973
|
$ as currentTimestamp,
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1974
|
+
qt as dappModalActions,
|
|
1975
|
+
at as dappModalReducer,
|
|
1976
|
+
Rt as encryptMnemonic,
|
|
1977
|
+
Tt as estimateDateByFutureBlock,
|
|
1978
|
+
Ke as fetchAssetBlob,
|
|
1979
|
+
He as fetchAssetDoc,
|
|
1980
|
+
_t as fetchNiftyNFT,
|
|
1981
|
+
ce as fetchPrice,
|
|
1982
|
+
Vt as generateNewMnemonic,
|
|
1983
|
+
Xe as generateVaultAddress,
|
|
1984
|
+
We as generateVaultConstraint,
|
|
1985
|
+
$e as generateVaultVisibleArgs,
|
|
1963
1986
|
R as getAddressBuffer,
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1987
|
+
Kt as getCurrencySymbol,
|
|
1988
|
+
kt as getExplorerUrl,
|
|
1989
|
+
Nt as getFileMediaType,
|
|
1990
|
+
Et as getFileMimeType,
|
|
1991
|
+
qe as getNexaPrices,
|
|
1992
|
+
he as getNiftyToken,
|
|
1993
|
+
je as getVaultConstraintHash,
|
|
1994
|
+
Je as getVaultTemplate,
|
|
1995
|
+
ze as getVaultTemplateHash,
|
|
1996
|
+
ye as initializePrices,
|
|
1997
|
+
bt as isGenesisHashValid,
|
|
1998
|
+
Fe as isMnemonicValid,
|
|
1976
1999
|
q as isNiftySubgroup,
|
|
1977
|
-
|
|
2000
|
+
P as isNullOrEmpty,
|
|
1978
2001
|
T as isTestnet,
|
|
1979
2002
|
F as isValidNexaAddress,
|
|
1980
2003
|
x as keyPathToString,
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
2004
|
+
Jt as loaderActions,
|
|
2005
|
+
it as loaderReducer,
|
|
2006
|
+
zt as notificationsActions,
|
|
2007
|
+
ot as notificationsReducer,
|
|
2008
|
+
Ot as parseTokenDataUrl,
|
|
2009
|
+
$t as sharedReducers,
|
|
2010
|
+
Wt as statusActions,
|
|
2011
|
+
dt as statusReducer,
|
|
2012
|
+
Re as stringToKeyPath,
|
|
2013
|
+
re as sumBalance,
|
|
1991
2014
|
G as sumTokensBalance,
|
|
1992
2015
|
D as tokenAmountToAssetAmount,
|
|
1993
|
-
|
|
2016
|
+
ie as tokenHexToAddr,
|
|
1994
2017
|
S as tokenIdToHex,
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2018
|
+
oe as transformTokenIconUrl,
|
|
2019
|
+
It as truncateStringMiddle,
|
|
2020
|
+
Zt as useAccount,
|
|
2021
|
+
cs as useAllNotifications,
|
|
2022
|
+
Xt as useAuth,
|
|
2023
|
+
Yt as useBlockHeight,
|
|
2024
|
+
ns as useDAppSession,
|
|
2025
|
+
es as useLastAccountId,
|
|
2026
|
+
ts as useMainReceiveAddress,
|
|
2027
|
+
Qt as useSelectedAccount,
|
|
2028
|
+
as as useTokenBalance,
|
|
2029
|
+
is as useVaults,
|
|
2030
|
+
ss as useWalletBalance,
|
|
2031
|
+
rs as useWalletNotifications,
|
|
2032
|
+
os as useWeb3Notifications,
|
|
2033
|
+
Ht as validateAndDecryptMnemonic,
|
|
2034
|
+
jt as walletActions,
|
|
2035
|
+
lt as walletReducer
|
|
2013
2036
|
};
|
|
2014
2037
|
//# sourceMappingURL=index.js.map
|