@ecency/wallets 1.0.13 → 1.0.14
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.js +78 -62
- package/package.json +1 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useCallback as
|
|
2
|
-
import { useQuery as
|
|
1
|
+
import { useCallback as P } from "react";
|
|
2
|
+
import { useQuery as p, useQueryClient as h, useMutation as m } from "@tanstack/react-query";
|
|
3
3
|
import { BtcWallet as S } from "@okxweb3/coin-bitcoin";
|
|
4
4
|
import { EthWallet as R } from "@okxweb3/coin-ethereum";
|
|
5
5
|
import { TrxWallet as O } from "@okxweb3/coin-tron";
|
|
6
6
|
import { TonWallet as A } from "@okxweb3/coin-ton";
|
|
7
7
|
import { SolWallet as k } from "@okxweb3/coin-solana";
|
|
8
|
-
import { AtomWallet as
|
|
9
|
-
import { AptosWallet as
|
|
10
|
-
import
|
|
8
|
+
import { AtomWallet as N } from "@okxweb3/coin-cosmos";
|
|
9
|
+
import { AptosWallet as D } from "@okxweb3/coin-aptos";
|
|
10
|
+
import K, { mnemonicToSeedSync as _ } from "bip39";
|
|
11
11
|
import { LRUCache as H } from "lru-cache";
|
|
12
|
-
import { PrivateKey as
|
|
12
|
+
import { PrivateKey as u } from "@hiveio/dhive";
|
|
13
13
|
var o = /* @__PURE__ */ ((e) => (e.BTC = "btc", e.ETH = "eth", e.APT = "atpos", e.ATOM = "cosmos", e.TON = "ton", e.TRON = "tron", e.SOL = "Solana", e))(o || {});
|
|
14
|
-
function
|
|
14
|
+
function j(e) {
|
|
15
15
|
return new Promise((t) => setTimeout(t, e));
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function T(e) {
|
|
18
18
|
switch (e) {
|
|
19
19
|
case o.BTC:
|
|
20
20
|
return new S();
|
|
@@ -27,18 +27,18 @@ function b(e) {
|
|
|
27
27
|
case o.SOL:
|
|
28
28
|
return new k();
|
|
29
29
|
case o.ATOM:
|
|
30
|
-
return new K();
|
|
31
|
-
case o.APT:
|
|
32
30
|
return new N();
|
|
31
|
+
case o.APT:
|
|
32
|
+
return new D();
|
|
33
33
|
default:
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
37
|
+
function ie(e) {
|
|
38
|
+
return _(e).toString("hex");
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
return
|
|
40
|
+
function ce(e, t) {
|
|
41
|
+
return p({
|
|
42
42
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
|
43
43
|
queryFn: async () => {
|
|
44
44
|
switch (e) {
|
|
@@ -79,12 +79,12 @@ function ie(e, t) {
|
|
|
79
79
|
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
|
80
80
|
)).json()).balance / 1e9;
|
|
81
81
|
case o.APT:
|
|
82
|
-
const
|
|
82
|
+
const y = (await (await fetch(
|
|
83
83
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
84
84
|
)).json()).find(
|
|
85
|
-
(
|
|
85
|
+
(v) => v.type.includes("coin::CoinStore")
|
|
86
86
|
);
|
|
87
|
-
return
|
|
87
|
+
return y ? parseInt(y.data.coin.value) / 1e8 : 0;
|
|
88
88
|
case o.ATOM:
|
|
89
89
|
return +(await (await fetch(
|
|
90
90
|
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
|
|
@@ -93,10 +93,10 @@ function ie(e, t) {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
return
|
|
96
|
+
function b() {
|
|
97
|
+
return p({
|
|
98
98
|
queryKey: ["ecency-wallets", "seed"],
|
|
99
|
-
queryFn: async () =>
|
|
99
|
+
queryFn: async () => K.generateMnemonic(128)
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
const C = {
|
|
@@ -107,12 +107,12 @@ const C = {
|
|
|
107
107
|
allowStale: !1,
|
|
108
108
|
updateAgeOnGet: !1,
|
|
109
109
|
updateAgeOnHas: !1
|
|
110
|
-
},
|
|
111
|
-
const t =
|
|
110
|
+
}, g = new H(C), d = Symbol("undefined"), B = (e, t) => g.set(e, t === void 0 ? d : t), E = (e) => {
|
|
111
|
+
const t = g.get(e);
|
|
112
112
|
return t === d ? void 0 : t;
|
|
113
113
|
};
|
|
114
|
-
function
|
|
115
|
-
return
|
|
114
|
+
function le(e) {
|
|
115
|
+
return p({
|
|
116
116
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
|
117
117
|
queryFn: async () => {
|
|
118
118
|
let t = e;
|
|
@@ -132,7 +132,7 @@ function ce(e) {
|
|
|
132
132
|
default:
|
|
133
133
|
t = e;
|
|
134
134
|
}
|
|
135
|
-
let n =
|
|
135
|
+
let n = E("gecko"), a;
|
|
136
136
|
if (n)
|
|
137
137
|
a = n;
|
|
138
138
|
else {
|
|
@@ -148,21 +148,21 @@ function ce(e) {
|
|
|
148
148
|
})
|
|
149
149
|
}
|
|
150
150
|
)).json();
|
|
151
|
-
|
|
151
|
+
B("gecko", s === void 0 ? d : s), a = s;
|
|
152
152
|
}
|
|
153
153
|
return 1 / +a[Object.keys(a)[0]].usd;
|
|
154
154
|
},
|
|
155
155
|
enabled: !!e
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
function
|
|
159
|
-
const { data: t } =
|
|
160
|
-
return
|
|
158
|
+
function L(e) {
|
|
159
|
+
const { data: t } = b();
|
|
160
|
+
return p({
|
|
161
161
|
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
|
162
162
|
queryFn: async () => {
|
|
163
163
|
if (!t)
|
|
164
164
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
165
|
-
const n =
|
|
165
|
+
const n = u.fromLogin(e, t, "owner"), a = u.fromLogin(e, t, "active"), i = u.fromLogin(e, t, "posting"), r = u.fromLogin(e, t, "memo");
|
|
166
166
|
return {
|
|
167
167
|
username: e,
|
|
168
168
|
owner: n.toString(),
|
|
@@ -177,7 +177,7 @@ function B(e) {
|
|
|
177
177
|
}
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
|
-
const
|
|
180
|
+
const W = {
|
|
181
181
|
[o.BTC]: "m/44'/0'/0'/0/0",
|
|
182
182
|
// Bitcoin (BIP44)
|
|
183
183
|
[o.ETH]: "m/44'/60'/0'/0/0",
|
|
@@ -193,17 +193,17 @@ const L = {
|
|
|
193
193
|
[o.ATOM]: "m/44'/118'/0'/0/0"
|
|
194
194
|
// Cosmos (BIP44)
|
|
195
195
|
};
|
|
196
|
-
function
|
|
197
|
-
const { data: n } =
|
|
196
|
+
function pe(e, t) {
|
|
197
|
+
const { data: n } = b(), a = h(), i = m({
|
|
198
198
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
199
199
|
mutationFn: async () => {
|
|
200
200
|
if (!n)
|
|
201
201
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
202
|
-
const s =
|
|
202
|
+
const s = T(t), c = await (s == null ? void 0 : s.getDerivedPrivateKey({
|
|
203
203
|
mnemonic: n,
|
|
204
|
-
hdPath:
|
|
204
|
+
hdPath: W[t]
|
|
205
205
|
}));
|
|
206
|
-
await
|
|
206
|
+
await j(1e3);
|
|
207
207
|
const l = await (s == null ? void 0 : s.getNewAddress({
|
|
208
208
|
privateKey: c
|
|
209
209
|
}));
|
|
@@ -221,21 +221,21 @@ function le(e, t) {
|
|
|
221
221
|
(c) => new Map(c ? Array.from(c.entries()) : []).set(s.currency, s)
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
|
-
}), r =
|
|
224
|
+
}), r = P(() => {
|
|
225
225
|
}, []);
|
|
226
226
|
return {
|
|
227
227
|
createWallet: i,
|
|
228
228
|
importWallet: r
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
|
-
const
|
|
231
|
+
const q = { privateApiHost: "https://ecency.com" };
|
|
232
232
|
function M(e) {
|
|
233
|
-
const { data: t } =
|
|
233
|
+
const { data: t } = p({
|
|
234
234
|
queryKey: ["ecency-wallets", "wallets", e]
|
|
235
|
-
}), { data: n } =
|
|
235
|
+
}), { data: n } = L(e);
|
|
236
236
|
return m({
|
|
237
237
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
238
|
-
mutationFn: ({ currency: a, address: i }) => fetch(
|
|
238
|
+
mutationFn: ({ currency: a, address: i }) => fetch(q.privateApiHost + "/private-api/wallets-add", {
|
|
239
239
|
method: "POST",
|
|
240
240
|
headers: {
|
|
241
241
|
"Content-Type": "application/json"
|
|
@@ -264,7 +264,7 @@ function M(e) {
|
|
|
264
264
|
const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
265
265
|
__proto__: null,
|
|
266
266
|
useCreateAccountWithWallets: M
|
|
267
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
267
|
+
}, Symbol.toStringTag, { value: "Module" })), x = {
|
|
268
268
|
[o.BTC]: [
|
|
269
269
|
"m/84'/0'/0'/0/0",
|
|
270
270
|
"m/44'/0'/0'/0/0",
|
|
@@ -276,34 +276,50 @@ const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
276
276
|
[o.APT]: ["m/44'/637'/0'/0'/0'"],
|
|
277
277
|
[o.TON]: ["m/44'/607'/0'"],
|
|
278
278
|
[o.ATOM]: ["m/44'/118'/0'/0/0"]
|
|
279
|
+
}, F = {
|
|
280
|
+
[o.BTC]: [
|
|
281
|
+
"",
|
|
282
|
+
// legacy
|
|
283
|
+
"segwit_native",
|
|
284
|
+
"segwite_nested",
|
|
285
|
+
"segwit_taproot"
|
|
286
|
+
],
|
|
287
|
+
[o.ETH]: [void 0],
|
|
288
|
+
[o.SOL]: [void 0],
|
|
289
|
+
[o.TRON]: [void 0],
|
|
290
|
+
[o.APT]: [void 0],
|
|
291
|
+
[o.TON]: [void 0],
|
|
292
|
+
[o.ATOM]: [void 0]
|
|
279
293
|
};
|
|
280
|
-
async function
|
|
281
|
-
for (const i of
|
|
294
|
+
async function Q(e, t, n, a) {
|
|
295
|
+
for (const i of x[a] || [])
|
|
282
296
|
try {
|
|
283
297
|
const r = await n.getDerivedPrivateKey({
|
|
284
298
|
mnemonic: e,
|
|
285
299
|
hdPath: i
|
|
286
300
|
});
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
301
|
+
for (const s of F[a])
|
|
302
|
+
if ((await n.getNewAddress({
|
|
303
|
+
privateKey: r,
|
|
304
|
+
addressType: s
|
|
305
|
+
})).address === t)
|
|
306
|
+
return r;
|
|
291
307
|
} catch {
|
|
292
308
|
return;
|
|
293
309
|
}
|
|
294
310
|
}
|
|
295
|
-
function
|
|
311
|
+
function me(e, t) {
|
|
296
312
|
const n = h();
|
|
297
313
|
return m({
|
|
298
314
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
|
299
315
|
mutationFn: async ({ privateKeyOrSeed: a, address: i }) => {
|
|
300
|
-
const r =
|
|
316
|
+
const r = T(t);
|
|
301
317
|
if (!r)
|
|
302
318
|
throw new Error("Cannot find token for this currency");
|
|
303
319
|
const s = a.split(" ").length === 12;
|
|
304
320
|
let c = !1, l = a;
|
|
305
321
|
if (s)
|
|
306
|
-
l = await
|
|
322
|
+
l = await Q(
|
|
307
323
|
a,
|
|
308
324
|
i,
|
|
309
325
|
r,
|
|
@@ -312,10 +328,10 @@ function pe(e, t) {
|
|
|
312
328
|
else {
|
|
313
329
|
const w = await r.getNewAddress({
|
|
314
330
|
privateKey: a
|
|
315
|
-
}),
|
|
331
|
+
}), f = await r.validPrivateKey({
|
|
316
332
|
privateKey: a
|
|
317
333
|
});
|
|
318
|
-
c = w.address === i &&
|
|
334
|
+
c = w.address === i && f.isValid;
|
|
319
335
|
}
|
|
320
336
|
if (!c)
|
|
321
337
|
throw new Error(
|
|
@@ -345,13 +361,13 @@ function pe(e, t) {
|
|
|
345
361
|
export {
|
|
346
362
|
o as EcencyWalletCurrency,
|
|
347
363
|
ue as EcencyWalletsPrivateApi,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
364
|
+
j as delay,
|
|
365
|
+
T as getWallet,
|
|
366
|
+
ie as mnemonicToSeedBip39,
|
|
367
|
+
le as useCoinGeckoPriceQuery,
|
|
368
|
+
ce as useGetExternalWalletBalanceQuery,
|
|
369
|
+
L as useHiveKeysQuery,
|
|
370
|
+
me as useImportWallet,
|
|
371
|
+
b as useSeedPhrase,
|
|
372
|
+
pe as useWalletCreate
|
|
357
373
|
};
|