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