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