@ecency/wallets 1.1.0 → 1.1.2
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/ecency-wallets.es.d.ts +9 -2
- package/dist/ecency-wallets.es.js +252 -278
- package/package.json +1 -1
|
@@ -38,7 +38,8 @@ export declare enum EcencyWalletCurrency {
|
|
|
38
38
|
|
|
39
39
|
declare namespace EcencyWalletsPrivateApi {
|
|
40
40
|
export {
|
|
41
|
-
useCreateAccountWithWallets
|
|
41
|
+
useCreateAccountWithWallets,
|
|
42
|
+
useCheckWalletExistence
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
export { EcencyWalletsPrivateApi }
|
|
@@ -54,9 +55,15 @@ declare interface Payload {
|
|
|
54
55
|
|
|
55
56
|
declare interface Payload_2 {
|
|
56
57
|
address: string;
|
|
58
|
+
currency: EcencyWalletCurrency;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare interface Payload_3 {
|
|
57
62
|
privateKeyOrSeed: string;
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
declare function useCheckWalletExistence(): UseMutationResult<boolean, Error, Payload_2, unknown>;
|
|
66
|
+
|
|
60
67
|
export declare function useCoinGeckoPriceQuery(currency?: EcencyWalletCurrency): UseQueryResult<number, Error>;
|
|
61
68
|
|
|
62
69
|
declare function useCreateAccountWithWallets(username: string): UseMutationResult<Response, Error, Payload, unknown>;
|
|
@@ -77,7 +84,7 @@ export declare function useImportWallet(username: string, currency: EcencyWallet
|
|
|
77
84
|
privateKey: string;
|
|
78
85
|
address: any;
|
|
79
86
|
publicKey: string;
|
|
80
|
-
}, Error,
|
|
87
|
+
}, Error, Payload_3, unknown>;
|
|
81
88
|
|
|
82
89
|
export declare function useSeedPhrase(username: string): UseQueryResult<string, Error>;
|
|
83
90
|
|
|
@@ -1,76 +1,64 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { BtcWallet } from "@okxweb3/coin-bitcoin";
|
|
4
|
-
import { EthWallet } from "@okxweb3/coin-ethereum";
|
|
5
|
-
import { TrxWallet } from "@okxweb3/coin-tron";
|
|
6
|
-
import { TonWallet } from "@okxweb3/coin-ton";
|
|
7
|
-
import { SolWallet } from "@okxweb3/coin-solana";
|
|
8
|
-
import { AtomWallet } from "@okxweb3/coin-cosmos";
|
|
9
|
-
import { AptosWallet } from "@okxweb3/coin-aptos";
|
|
10
|
-
import
|
|
11
|
-
import { LRUCache } from "lru-cache";
|
|
12
|
-
import { PrivateKey } from "@hiveio/dhive";
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
EcencyWalletCurrency2["APT"] = "aptos";
|
|
17
|
-
EcencyWalletCurrency2["ATOM"] = "cosmos";
|
|
18
|
-
EcencyWalletCurrency2["TON"] = "ton";
|
|
19
|
-
EcencyWalletCurrency2["TRON"] = "tron";
|
|
20
|
-
EcencyWalletCurrency2["SOL"] = "solana";
|
|
21
|
-
return EcencyWalletCurrency2;
|
|
22
|
-
})(EcencyWalletCurrency || {});
|
|
23
|
-
function delay(ms) {
|
|
24
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1
|
+
import { useCallback as R } from "react";
|
|
2
|
+
import { useQuery as p, useQueryClient as y, useMutation as m } from "@tanstack/react-query";
|
|
3
|
+
import { BtcWallet as O } from "@okxweb3/coin-bitcoin";
|
|
4
|
+
import { EthWallet as v } from "@okxweb3/coin-ethereum";
|
|
5
|
+
import { TrxWallet as k } from "@okxweb3/coin-tron";
|
|
6
|
+
import { TonWallet as A } from "@okxweb3/coin-ton";
|
|
7
|
+
import { SolWallet as N } from "@okxweb3/coin-solana";
|
|
8
|
+
import { AtomWallet as K } from "@okxweb3/coin-cosmos";
|
|
9
|
+
import { AptosWallet as D } from "@okxweb3/coin-aptos";
|
|
10
|
+
import j, { mnemonicToSeedSync as C } from "bip39";
|
|
11
|
+
import { LRUCache as H } from "lru-cache";
|
|
12
|
+
import { PrivateKey as u } from "@hiveio/dhive";
|
|
13
|
+
var o = /* @__PURE__ */ ((e) => (e.BTC = "btc", e.ETH = "eth", e.APT = "aptos", e.ATOM = "cosmos", e.TON = "ton", e.TRON = "tron", e.SOL = "solana", e))(o || {});
|
|
14
|
+
function x(e) {
|
|
15
|
+
return new Promise((t) => setTimeout(t, e));
|
|
25
16
|
}
|
|
26
|
-
function
|
|
27
|
-
switch (
|
|
28
|
-
case
|
|
29
|
-
return new
|
|
30
|
-
case
|
|
31
|
-
return new
|
|
32
|
-
case
|
|
33
|
-
return new
|
|
34
|
-
case
|
|
35
|
-
return new
|
|
36
|
-
case
|
|
37
|
-
return new
|
|
38
|
-
case
|
|
39
|
-
return new
|
|
40
|
-
case
|
|
41
|
-
return new
|
|
17
|
+
function h(e) {
|
|
18
|
+
switch (e) {
|
|
19
|
+
case o.BTC:
|
|
20
|
+
return new O();
|
|
21
|
+
case o.ETH:
|
|
22
|
+
return new v();
|
|
23
|
+
case o.TRON:
|
|
24
|
+
return new k();
|
|
25
|
+
case o.TON:
|
|
26
|
+
return new A();
|
|
27
|
+
case o.SOL:
|
|
28
|
+
return new N();
|
|
29
|
+
case o.ATOM:
|
|
30
|
+
return new K();
|
|
31
|
+
case o.APT:
|
|
32
|
+
return new D();
|
|
42
33
|
default:
|
|
43
|
-
return
|
|
34
|
+
return;
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
|
-
function
|
|
47
|
-
return
|
|
37
|
+
function ce(e) {
|
|
38
|
+
return C(e).toString("hex");
|
|
48
39
|
}
|
|
49
|
-
function
|
|
50
|
-
return
|
|
51
|
-
queryKey: ["ecency-wallets", "external-wallet-balance",
|
|
40
|
+
function ie(e, t) {
|
|
41
|
+
return p({
|
|
42
|
+
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
|
52
43
|
queryFn: async () => {
|
|
53
|
-
switch (
|
|
54
|
-
case
|
|
55
|
-
const
|
|
56
|
-
`https://mempool.space/api/address/${
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const ethResponse = await fetch("https://eth.llamarpc.com", {
|
|
44
|
+
switch (e) {
|
|
45
|
+
case o.BTC:
|
|
46
|
+
const r = await (await fetch(
|
|
47
|
+
`https://mempool.space/api/address/${t}`
|
|
48
|
+
)).json();
|
|
49
|
+
return (r.chain_stats.funded_txo_sum - r.chain_stats.spent_txo_sum) / 1e8;
|
|
50
|
+
case o.ETH:
|
|
51
|
+
return +(await (await fetch("https://eth.llamarpc.com", {
|
|
62
52
|
method: "POST",
|
|
63
53
|
body: JSON.stringify({
|
|
64
54
|
jsonrpc: "2.0",
|
|
65
55
|
id: "1",
|
|
66
56
|
method: "eth_getBalance",
|
|
67
|
-
params: [
|
|
57
|
+
params: [t, "latest"]
|
|
68
58
|
})
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
case EcencyWalletCurrency.SOL:
|
|
73
|
-
const solResponse = await fetch(
|
|
59
|
+
})).json()).result / 1e18;
|
|
60
|
+
case o.SOL:
|
|
61
|
+
return (await (await fetch(
|
|
74
62
|
"https://api.mainnet-beta.solana.com",
|
|
75
63
|
{
|
|
76
64
|
method: "POST",
|
|
@@ -78,222 +66,193 @@ function useGetExternalWalletBalanceQuery(currency, address) {
|
|
|
78
66
|
jsonrpc: "2.0",
|
|
79
67
|
id: "1",
|
|
80
68
|
method: "getBalance",
|
|
81
|
-
params: [
|
|
69
|
+
params: [t]
|
|
82
70
|
})
|
|
83
71
|
}
|
|
72
|
+
)).json()).result.value / 1e9;
|
|
73
|
+
case o.TRON:
|
|
74
|
+
return (await (await fetch(
|
|
75
|
+
`https://api.trongrid.io/v1/accounts/${t}`
|
|
76
|
+
)).json()).data[0].balance / 1e6;
|
|
77
|
+
case o.TON:
|
|
78
|
+
return (await (await fetch(
|
|
79
|
+
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
|
80
|
+
)).json()).balance / 1e9;
|
|
81
|
+
case o.APT:
|
|
82
|
+
const d = (await (await fetch(
|
|
83
|
+
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
84
|
+
)).json()).find(
|
|
85
|
+
(S) => S.type.includes("coin::CoinStore")
|
|
84
86
|
);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
const tronResponseData = await tronResponse.json();
|
|
92
|
-
return tronResponseData.data[0].balance / 1e6;
|
|
93
|
-
case EcencyWalletCurrency.TON:
|
|
94
|
-
const tonResponse = await fetch(
|
|
95
|
-
`https://tonapi.io/v1/blockchain/getAccount?account=${address}`
|
|
96
|
-
);
|
|
97
|
-
const tonResponseData = await tonResponse.json();
|
|
98
|
-
return tonResponseData.balance / 1e9;
|
|
99
|
-
case EcencyWalletCurrency.APT:
|
|
100
|
-
const aptResponse = await fetch(
|
|
101
|
-
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${address}/resources`
|
|
102
|
-
);
|
|
103
|
-
const aptResponseData = await aptResponse.json();
|
|
104
|
-
const coinStore = aptResponseData.find(
|
|
105
|
-
(resource) => resource.type.includes("coin::CoinStore")
|
|
106
|
-
);
|
|
107
|
-
if (!coinStore) return 0;
|
|
108
|
-
return parseInt(coinStore.data.coin.value) / 1e8;
|
|
109
|
-
case EcencyWalletCurrency.ATOM:
|
|
110
|
-
const atomResponse = await fetch(
|
|
111
|
-
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${address}`
|
|
112
|
-
);
|
|
113
|
-
const atomResponseData = await atomResponse.json();
|
|
114
|
-
return +atomResponseData.result.value.coins[0].amount / 1e6;
|
|
87
|
+
return d ? parseInt(d.data.coin.value) / 1e8 : 0;
|
|
88
|
+
case o.ATOM:
|
|
89
|
+
return +(await (await fetch(
|
|
90
|
+
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
|
|
91
|
+
)).json()).result.value.coins[0].amount / 1e6;
|
|
115
92
|
}
|
|
116
93
|
}
|
|
117
94
|
});
|
|
118
95
|
}
|
|
119
|
-
function
|
|
120
|
-
return
|
|
121
|
-
queryKey: ["ecency-wallets", "seed",
|
|
122
|
-
queryFn: async () =>
|
|
96
|
+
function f(e) {
|
|
97
|
+
return p({
|
|
98
|
+
queryKey: ["ecency-wallets", "seed", e],
|
|
99
|
+
queryFn: async () => j.generateMnemonic(128)
|
|
123
100
|
});
|
|
124
101
|
}
|
|
125
|
-
const
|
|
102
|
+
const W = {
|
|
126
103
|
max: 500,
|
|
127
104
|
// how long to live in ms
|
|
128
105
|
ttl: 1e3 * 60 * 5,
|
|
129
106
|
// return stale items before removing from cache?
|
|
130
|
-
allowStale:
|
|
131
|
-
updateAgeOnGet:
|
|
132
|
-
updateAgeOnHas:
|
|
107
|
+
allowStale: !1,
|
|
108
|
+
updateAgeOnGet: !1,
|
|
109
|
+
updateAgeOnHas: !1
|
|
110
|
+
}, b = new H(W), w = Symbol("undefined"), _ = (e, t) => b.set(e, t === void 0 ? w : t), E = (e) => {
|
|
111
|
+
const t = b.get(e);
|
|
112
|
+
return t === w ? void 0 : t;
|
|
133
113
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const cacheGet = (key) => {
|
|
138
|
-
const v = cache.get(key);
|
|
139
|
-
return v === undefinedValue ? void 0 : v;
|
|
140
|
-
};
|
|
141
|
-
function useCoinGeckoPriceQuery(currency) {
|
|
142
|
-
return useQuery({
|
|
143
|
-
queryKey: ["ecency-wallets", "coingecko-price", currency],
|
|
114
|
+
function le(e) {
|
|
115
|
+
return p({
|
|
116
|
+
queryKey: ["ecency-wallets", "coingecko-price", e],
|
|
144
117
|
queryFn: async () => {
|
|
145
|
-
let
|
|
146
|
-
switch (
|
|
147
|
-
case
|
|
148
|
-
|
|
118
|
+
let t = e;
|
|
119
|
+
switch (e) {
|
|
120
|
+
case o.BTC:
|
|
121
|
+
t = "binance-wrapped-btc";
|
|
149
122
|
break;
|
|
150
|
-
case
|
|
151
|
-
|
|
123
|
+
case o.ETH:
|
|
124
|
+
t = "ethereum";
|
|
152
125
|
break;
|
|
153
|
-
case
|
|
154
|
-
|
|
126
|
+
case o.SOL:
|
|
127
|
+
t = "solana";
|
|
155
128
|
break;
|
|
156
|
-
case
|
|
157
|
-
|
|
129
|
+
case o.TON:
|
|
130
|
+
t = "trx";
|
|
158
131
|
break;
|
|
159
132
|
default:
|
|
160
|
-
|
|
133
|
+
t = e;
|
|
161
134
|
}
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const httpResponse = await fetch(
|
|
135
|
+
let n = E("gecko"), r;
|
|
136
|
+
if (n)
|
|
137
|
+
r = n;
|
|
138
|
+
else {
|
|
139
|
+
const a = await (await fetch(
|
|
168
140
|
"https://api.coingecko.com/api/v3/simple/price",
|
|
169
141
|
{
|
|
170
142
|
method: "POST",
|
|
171
143
|
body: JSON.stringify({
|
|
172
144
|
params: {
|
|
173
|
-
ids: [
|
|
145
|
+
ids: [t],
|
|
174
146
|
vs_currencies: "usd"
|
|
175
147
|
}
|
|
176
148
|
})
|
|
177
149
|
}
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
cacheSet("gecko", data === void 0 ? undefinedValue : data);
|
|
181
|
-
response = data;
|
|
150
|
+
)).json();
|
|
151
|
+
_("gecko", a === void 0 ? w : a), r = a;
|
|
182
152
|
}
|
|
183
|
-
|
|
184
|
-
return 1 / rateValue;
|
|
153
|
+
return 1 / +r[Object.keys(r)[0]].usd;
|
|
185
154
|
},
|
|
186
|
-
enabled: !!
|
|
155
|
+
enabled: !!e
|
|
187
156
|
});
|
|
188
157
|
}
|
|
189
|
-
function
|
|
190
|
-
const { data:
|
|
191
|
-
return
|
|
192
|
-
queryKey: ["ecencу-wallets", "hive-keys",
|
|
158
|
+
function q(e) {
|
|
159
|
+
const { data: t } = f(e);
|
|
160
|
+
return p({
|
|
161
|
+
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
|
193
162
|
queryFn: async () => {
|
|
194
|
-
if (!
|
|
163
|
+
if (!t)
|
|
195
164
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
196
|
-
|
|
197
|
-
const ownerKey = PrivateKey.fromLogin(username, seed, "owner");
|
|
198
|
-
const activeKey = PrivateKey.fromLogin(username, seed, "active");
|
|
199
|
-
const postingKey = PrivateKey.fromLogin(username, seed, "posting");
|
|
200
|
-
const memoKey = PrivateKey.fromLogin(username, seed, "memo");
|
|
165
|
+
const n = u.fromLogin(e, t, "owner"), r = u.fromLogin(e, t, "active"), s = u.fromLogin(e, t, "posting"), i = u.fromLogin(e, t, "memo");
|
|
201
166
|
return {
|
|
202
|
-
username,
|
|
203
|
-
owner:
|
|
204
|
-
active:
|
|
205
|
-
posting:
|
|
206
|
-
memo:
|
|
207
|
-
ownerPubkey:
|
|
208
|
-
activePubkey:
|
|
209
|
-
postingPubkey:
|
|
210
|
-
memoPubkey:
|
|
167
|
+
username: e,
|
|
168
|
+
owner: n.toString(),
|
|
169
|
+
active: r.toString(),
|
|
170
|
+
posting: s.toString(),
|
|
171
|
+
memo: i.toString(),
|
|
172
|
+
ownerPubkey: n.createPublic().toString(),
|
|
173
|
+
activePubkey: r.createPublic().toString(),
|
|
174
|
+
postingPubkey: s.createPublic().toString(),
|
|
175
|
+
memoPubkey: i.createPublic().toString()
|
|
211
176
|
};
|
|
212
177
|
}
|
|
213
178
|
});
|
|
214
179
|
}
|
|
215
|
-
const
|
|
216
|
-
[
|
|
180
|
+
const B = {
|
|
181
|
+
[o.BTC]: "m/44'/0'/0'/0/0",
|
|
217
182
|
// Bitcoin (BIP44)
|
|
218
|
-
[
|
|
183
|
+
[o.ETH]: "m/44'/60'/0'/0/0",
|
|
219
184
|
// Ethereum (BIP44)
|
|
220
|
-
[
|
|
185
|
+
[o.SOL]: "m/44'/501'/0'/0'",
|
|
221
186
|
// Solana (BIP44)
|
|
222
|
-
[
|
|
187
|
+
[o.TON]: "m/44'/607'/0'",
|
|
223
188
|
// TON (BIP44)
|
|
224
|
-
[
|
|
189
|
+
[o.TRON]: "m/44'/195'/0'/0/0",
|
|
225
190
|
// Tron (BIP44)
|
|
226
|
-
[
|
|
191
|
+
[o.APT]: "m/44'/637'/0'/0'/0'",
|
|
227
192
|
// Aptos (BIP44)
|
|
228
|
-
[
|
|
193
|
+
[o.ATOM]: "m/44'/118'/0'/0/0"
|
|
229
194
|
// Cosmos (BIP44)
|
|
230
195
|
};
|
|
231
|
-
function
|
|
232
|
-
const { data:
|
|
233
|
-
|
|
234
|
-
const createWallet = useMutation({
|
|
235
|
-
mutationKey: ["ecency-wallets", "create-wallet", username, currency],
|
|
196
|
+
function pe(e, t) {
|
|
197
|
+
const { data: n } = f(e), r = y(), s = m({
|
|
198
|
+
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
236
199
|
mutationFn: async () => {
|
|
237
|
-
if (!
|
|
200
|
+
if (!n)
|
|
238
201
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
mnemonic,
|
|
243
|
-
hdPath: PATHS[currency]
|
|
202
|
+
const a = h(t), c = await (a == null ? void 0 : a.getDerivedPrivateKey({
|
|
203
|
+
mnemonic: n,
|
|
204
|
+
hdPath: B[t]
|
|
244
205
|
}));
|
|
245
|
-
await
|
|
246
|
-
const
|
|
247
|
-
privateKey
|
|
206
|
+
await x(1e3);
|
|
207
|
+
const l = await (a == null ? void 0 : a.getNewAddress({
|
|
208
|
+
privateKey: c
|
|
248
209
|
}));
|
|
249
210
|
return {
|
|
250
|
-
privateKey,
|
|
251
|
-
address:
|
|
252
|
-
publicKey:
|
|
253
|
-
username,
|
|
254
|
-
currency
|
|
211
|
+
privateKey: c,
|
|
212
|
+
address: l.address,
|
|
213
|
+
publicKey: l.publicKey,
|
|
214
|
+
username: e,
|
|
215
|
+
currency: t
|
|
255
216
|
};
|
|
256
217
|
},
|
|
257
|
-
onSuccess: (
|
|
258
|
-
|
|
259
|
-
["ecency-wallets", "wallets",
|
|
260
|
-
(
|
|
218
|
+
onSuccess: (a) => {
|
|
219
|
+
r.setQueryData(
|
|
220
|
+
["ecency-wallets", "wallets", a.username],
|
|
221
|
+
(c) => new Map(c ? Array.from(c.entries()) : []).set(a.currency, a)
|
|
261
222
|
);
|
|
262
223
|
}
|
|
263
|
-
})
|
|
264
|
-
const importWallet = useCallback(() => {
|
|
224
|
+
}), i = R(() => {
|
|
265
225
|
}, []);
|
|
266
226
|
return {
|
|
267
|
-
createWallet,
|
|
268
|
-
importWallet
|
|
227
|
+
createWallet: s,
|
|
228
|
+
importWallet: i
|
|
269
229
|
};
|
|
270
230
|
}
|
|
271
|
-
const
|
|
272
|
-
function
|
|
273
|
-
const { data } =
|
|
274
|
-
queryKey: ["ecency-wallets", "wallets",
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
mutationFn: ({ currency, address }) => fetch(CONFIG.privateApiHost + "/private-api/wallets-add", {
|
|
231
|
+
const g = { privateApiHost: "https://ecency.com" };
|
|
232
|
+
function L(e) {
|
|
233
|
+
const { data: t } = p({
|
|
234
|
+
queryKey: ["ecency-wallets", "wallets", e]
|
|
235
|
+
}), { data: n } = q(e);
|
|
236
|
+
return m({
|
|
237
|
+
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
238
|
+
mutationFn: ({ currency: r, address: s }) => fetch(g.privateApiHost + "/private-api/wallets-add", {
|
|
280
239
|
method: "POST",
|
|
281
240
|
headers: {
|
|
282
241
|
"Content-Type": "application/json"
|
|
283
242
|
},
|
|
284
243
|
body: JSON.stringify({
|
|
285
|
-
username,
|
|
286
|
-
token:
|
|
287
|
-
address,
|
|
244
|
+
username: e,
|
|
245
|
+
token: r,
|
|
246
|
+
address: s,
|
|
288
247
|
meta: {
|
|
289
|
-
ownerPublicKey:
|
|
290
|
-
activePublicKey:
|
|
291
|
-
postingPublicKey:
|
|
292
|
-
memoPublicKey:
|
|
293
|
-
...Array.from((
|
|
294
|
-
(
|
|
295
|
-
...
|
|
296
|
-
[
|
|
248
|
+
ownerPublicKey: n == null ? void 0 : n.ownerPubkey,
|
|
249
|
+
activePublicKey: n == null ? void 0 : n.activePubkey,
|
|
250
|
+
postingPublicKey: n == null ? void 0 : n.postingPubkey,
|
|
251
|
+
memoPublicKey: n == null ? void 0 : n.memoPubkey,
|
|
252
|
+
...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
|
|
253
|
+
(i, [a, c]) => ({
|
|
254
|
+
...i,
|
|
255
|
+
[a]: c.address
|
|
297
256
|
}),
|
|
298
257
|
{}
|
|
299
258
|
)
|
|
@@ -302,98 +261,113 @@ function useCreateAccountWithWallets(username) {
|
|
|
302
261
|
})
|
|
303
262
|
});
|
|
304
263
|
}
|
|
305
|
-
|
|
264
|
+
function T() {
|
|
265
|
+
return m({
|
|
266
|
+
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
|
267
|
+
mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
|
|
268
|
+
g.privateApiHost + "/private-api/wallets-exist",
|
|
269
|
+
{
|
|
270
|
+
method: "POST",
|
|
271
|
+
headers: {
|
|
272
|
+
"Content-Type": "application/json"
|
|
273
|
+
},
|
|
274
|
+
body: JSON.stringify({
|
|
275
|
+
address: e,
|
|
276
|
+
token: t
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
)).json()).length === 0
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
306
283
|
__proto__: null,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
[
|
|
311
|
-
[
|
|
284
|
+
useCheckWalletExistence: T,
|
|
285
|
+
useCreateAccountWithWallets: L
|
|
286
|
+
}, Symbol.toStringTag, { value: "Module" })), F = {
|
|
287
|
+
[o.BTC]: ["m/84'/0'/0'/0/0"],
|
|
288
|
+
[o.ETH]: ["m/84'/60'/0'/0/0"],
|
|
312
289
|
// its not working for Trust, Exodus, todo: check others below
|
|
313
|
-
[
|
|
314
|
-
[
|
|
315
|
-
[
|
|
316
|
-
[
|
|
290
|
+
[o.SOL]: ["m/84'/501'/0'/0/0"],
|
|
291
|
+
[o.TRON]: ["m/84'/195'/0'/0/0"],
|
|
292
|
+
[o.APT]: ["m/84'/637'/0'/0/0"],
|
|
293
|
+
[o.TON]: [],
|
|
317
294
|
// Disabled
|
|
318
|
-
[
|
|
295
|
+
[o.ATOM]: ["m/84'/118'/0'/0'/0"]
|
|
319
296
|
};
|
|
320
|
-
async function
|
|
321
|
-
for (const
|
|
297
|
+
async function M(e, t, n) {
|
|
298
|
+
for (const r of F[n] || [])
|
|
322
299
|
try {
|
|
323
|
-
const
|
|
324
|
-
mnemonic,
|
|
325
|
-
hdPath
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
privateKey: derivedPrivateKey,
|
|
300
|
+
const s = await t.getDerivedPrivateKey({
|
|
301
|
+
mnemonic: e,
|
|
302
|
+
hdPath: r
|
|
303
|
+
}), i = await t.getNewAddress({
|
|
304
|
+
privateKey: s,
|
|
329
305
|
addressType: "segwit_native"
|
|
330
306
|
});
|
|
331
|
-
return [
|
|
332
|
-
} catch
|
|
307
|
+
return [s.toString(), i.address];
|
|
308
|
+
} catch {
|
|
333
309
|
return [];
|
|
334
310
|
}
|
|
335
|
-
}
|
|
336
311
|
return [];
|
|
337
312
|
}
|
|
338
|
-
function
|
|
339
|
-
const
|
|
340
|
-
return
|
|
341
|
-
mutationKey: ["ecency-wallets", "import-wallet",
|
|
342
|
-
mutationFn: async ({ privateKeyOrSeed }) => {
|
|
343
|
-
const
|
|
344
|
-
if (!
|
|
313
|
+
function me(e, t) {
|
|
314
|
+
const n = y(), { mutateAsync: r } = T();
|
|
315
|
+
return m({
|
|
316
|
+
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
|
317
|
+
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
|
318
|
+
const i = h(t);
|
|
319
|
+
if (!i)
|
|
345
320
|
throw new Error("Cannot find token for this currency");
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
);
|
|
356
|
-
} else {
|
|
357
|
-
address = (await wallet.getNewAddress({
|
|
358
|
-
privateKey: privateKeyOrSeed
|
|
359
|
-
})).address;
|
|
360
|
-
}
|
|
361
|
-
if (!address || !privateKeyOrSeed) {
|
|
321
|
+
const a = s.split(" ").length === 12;
|
|
322
|
+
let c, l = s;
|
|
323
|
+
if (a ? [l, c] = await M(
|
|
324
|
+
s,
|
|
325
|
+
i,
|
|
326
|
+
t
|
|
327
|
+
) : c = (await i.getNewAddress({
|
|
328
|
+
privateKey: s
|
|
329
|
+
})).address, !c || !s)
|
|
362
330
|
throw new Error(
|
|
363
331
|
"Private key/seed phrase isn't matching with public key or token"
|
|
364
332
|
);
|
|
365
|
-
|
|
333
|
+
if (!await r({
|
|
334
|
+
address: c,
|
|
335
|
+
currency: t
|
|
336
|
+
}))
|
|
337
|
+
throw new Error(
|
|
338
|
+
"This wallet has already in use by Hive account. Please, try another one"
|
|
339
|
+
);
|
|
366
340
|
return {
|
|
367
|
-
privateKey,
|
|
368
|
-
address,
|
|
341
|
+
privateKey: l,
|
|
342
|
+
address: c,
|
|
369
343
|
publicKey: ""
|
|
370
344
|
};
|
|
371
345
|
},
|
|
372
|
-
onSuccess: ({ privateKey, publicKey, address }) => {
|
|
373
|
-
|
|
374
|
-
["ecency-wallets", "wallets",
|
|
375
|
-
(
|
|
376
|
-
privateKey,
|
|
377
|
-
publicKey,
|
|
378
|
-
address,
|
|
379
|
-
username,
|
|
380
|
-
currency,
|
|
381
|
-
custom:
|
|
346
|
+
onSuccess: ({ privateKey: s, publicKey: i, address: a }) => {
|
|
347
|
+
n.setQueryData(
|
|
348
|
+
["ecency-wallets", "wallets", e],
|
|
349
|
+
(c) => new Map(c ? Array.from(c.entries()) : []).set(t, {
|
|
350
|
+
privateKey: s,
|
|
351
|
+
publicKey: i,
|
|
352
|
+
address: a,
|
|
353
|
+
username: e,
|
|
354
|
+
currency: t,
|
|
355
|
+
custom: !0
|
|
382
356
|
})
|
|
383
357
|
);
|
|
384
358
|
}
|
|
385
359
|
});
|
|
386
360
|
}
|
|
387
361
|
export {
|
|
388
|
-
EcencyWalletCurrency,
|
|
389
|
-
|
|
390
|
-
delay,
|
|
391
|
-
getWallet,
|
|
392
|
-
mnemonicToSeedBip39,
|
|
393
|
-
useCoinGeckoPriceQuery,
|
|
394
|
-
useGetExternalWalletBalanceQuery,
|
|
395
|
-
useHiveKeysQuery,
|
|
396
|
-
useImportWallet,
|
|
397
|
-
useSeedPhrase,
|
|
398
|
-
useWalletCreate
|
|
362
|
+
o as EcencyWalletCurrency,
|
|
363
|
+
ue as EcencyWalletsPrivateApi,
|
|
364
|
+
x as delay,
|
|
365
|
+
h as getWallet,
|
|
366
|
+
ce as mnemonicToSeedBip39,
|
|
367
|
+
le as useCoinGeckoPriceQuery,
|
|
368
|
+
ie as useGetExternalWalletBalanceQuery,
|
|
369
|
+
q as useHiveKeysQuery,
|
|
370
|
+
me as useImportWallet,
|
|
371
|
+
f as useSeedPhrase,
|
|
372
|
+
pe as useWalletCreate
|
|
399
373
|
};
|