@ecency/wallets 1.0.6 → 1.0.7
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 +68 -71
- package/package.json +1 -1
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useQuery as l, useQueryClient as g, useMutation as
|
|
3
|
-
import { BtcWallet as
|
|
4
|
-
import { EthWallet as
|
|
5
|
-
import { TrxWallet as
|
|
6
|
-
import { TonWallet as
|
|
7
|
-
import { SolWallet as
|
|
8
|
-
import { AtomWallet as
|
|
9
|
-
import { AptosWallet as
|
|
10
|
-
import
|
|
11
|
-
import { LRUCache as
|
|
12
|
-
import { PrivateKey as
|
|
1
|
+
import { useCallback as b } from "react";
|
|
2
|
+
import { useQuery as l, useQueryClient as g, useMutation as d } from "@tanstack/react-query";
|
|
3
|
+
import { BtcWallet as T } from "@okxweb3/coin-bitcoin";
|
|
4
|
+
import { EthWallet as S } from "@okxweb3/coin-ethereum";
|
|
5
|
+
import { TrxWallet as R } from "@okxweb3/coin-tron";
|
|
6
|
+
import { TonWallet as P } from "@okxweb3/coin-ton";
|
|
7
|
+
import { SolWallet as O } from "@okxweb3/coin-solana";
|
|
8
|
+
import { AtomWallet as v } from "@okxweb3/coin-cosmos";
|
|
9
|
+
import { AptosWallet as k } from "@okxweb3/coin-aptos";
|
|
10
|
+
import A, { mnemonicToSeedSync as N } from "bip39";
|
|
11
|
+
import { LRUCache as D } from "lru-cache";
|
|
12
|
+
import { PrivateKey as p } 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 K(e) {
|
|
18
18
|
switch (e) {
|
|
19
19
|
case o.BTC:
|
|
20
|
-
return new
|
|
20
|
+
return new T();
|
|
21
21
|
case o.ETH:
|
|
22
|
-
return new
|
|
22
|
+
return new S();
|
|
23
23
|
case o.TRON:
|
|
24
|
-
return new
|
|
24
|
+
return new R();
|
|
25
25
|
case o.TON:
|
|
26
|
-
return new
|
|
26
|
+
return new P();
|
|
27
27
|
case o.SOL:
|
|
28
|
-
return new
|
|
28
|
+
return new O();
|
|
29
29
|
case o.ATOM:
|
|
30
|
-
return new
|
|
30
|
+
return new v();
|
|
31
31
|
case o.APT:
|
|
32
|
-
return new
|
|
32
|
+
return new k();
|
|
33
33
|
default:
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
37
|
+
function ae(e) {
|
|
38
|
+
return N(e).toString("hex");
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function se(e, t) {
|
|
41
41
|
return l({
|
|
42
42
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
|
43
43
|
queryFn: async () => {
|
|
@@ -79,12 +79,12 @@ function ce(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 w = (await (await fetch(
|
|
83
83
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
84
84
|
)).json()).find(
|
|
85
|
-
(
|
|
85
|
+
(h) => h.type.includes("coin::CoinStore")
|
|
86
86
|
);
|
|
87
|
-
return
|
|
87
|
+
return w ? parseInt(w.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,13 +93,13 @@ function ce(e, t) {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function y() {
|
|
97
97
|
return l({
|
|
98
98
|
queryKey: ["ecency-wallets", "seed"],
|
|
99
|
-
queryFn: async () =>
|
|
99
|
+
queryFn: async () => A.generateMnemonic(128)
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
const
|
|
102
|
+
const _ = {
|
|
103
103
|
max: 500,
|
|
104
104
|
// how long to live in ms
|
|
105
105
|
ttl: 1e3 * 60 * 5,
|
|
@@ -107,11 +107,11 @@ const x = {
|
|
|
107
107
|
allowStale: !1,
|
|
108
108
|
updateAgeOnGet: !1,
|
|
109
109
|
updateAgeOnHas: !1
|
|
110
|
-
},
|
|
111
|
-
const t =
|
|
110
|
+
}, f = new D(_), m = Symbol("undefined"), H = (e, t) => f.set(e, t === void 0 ? m : t), W = (e) => {
|
|
111
|
+
const t = f.get(e);
|
|
112
112
|
return t === m ? void 0 : t;
|
|
113
113
|
};
|
|
114
|
-
function
|
|
114
|
+
function ce(e) {
|
|
115
115
|
return l({
|
|
116
116
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
|
117
117
|
queryFn: async () => {
|
|
@@ -156,31 +156,28 @@ function re(e) {
|
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
158
|
function q(e) {
|
|
159
|
-
const { data: t } =
|
|
160
|
-
() => y(t ?? "").toString("hex"),
|
|
161
|
-
[t]
|
|
162
|
-
);
|
|
159
|
+
const { data: t } = y();
|
|
163
160
|
return l({
|
|
164
|
-
queryKey: ["ecencу-wallets", "hive-keys", e,
|
|
161
|
+
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
|
165
162
|
queryFn: async () => {
|
|
166
163
|
if (!t)
|
|
167
164
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
168
|
-
const
|
|
165
|
+
const n = p.fromLogin(e, t, "owner"), s = p.fromLogin(e, t, "active"), c = p.fromLogin(e, t, "posting"), r = p.fromLogin(e, t, "memo");
|
|
169
166
|
return {
|
|
170
167
|
username: e,
|
|
171
|
-
owner:
|
|
172
|
-
active:
|
|
173
|
-
posting:
|
|
174
|
-
memo:
|
|
175
|
-
ownerPubkey:
|
|
176
|
-
activePubkey:
|
|
177
|
-
postingPubkey:
|
|
178
|
-
memoPubkey:
|
|
168
|
+
owner: n.toString(),
|
|
169
|
+
active: s.toString(),
|
|
170
|
+
posting: c.toString(),
|
|
171
|
+
memo: r.toString(),
|
|
172
|
+
ownerPubkey: n.createPublic().toString(),
|
|
173
|
+
activePubkey: s.createPublic().toString(),
|
|
174
|
+
postingPubkey: c.createPublic().toString(),
|
|
175
|
+
memoPubkey: r.createPublic().toString()
|
|
179
176
|
};
|
|
180
177
|
}
|
|
181
178
|
});
|
|
182
179
|
}
|
|
183
|
-
const
|
|
180
|
+
const x = {
|
|
184
181
|
[o.BTC]: "m/44'/0'/0'/0/0",
|
|
185
182
|
// Bitcoin (BIP44)
|
|
186
183
|
[o.ETH]: "m/44'/60'/0'/0/0",
|
|
@@ -196,24 +193,24 @@ const B = {
|
|
|
196
193
|
[o.ATOM]: "m/44'/118'/0'/0/0"
|
|
197
194
|
// Cosmos (BIP44)
|
|
198
195
|
};
|
|
199
|
-
function
|
|
200
|
-
const { data: n } =
|
|
196
|
+
function re(e, t) {
|
|
197
|
+
const { data: n } = y(), s = g(), c = d({
|
|
201
198
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
202
199
|
mutationFn: async () => {
|
|
203
200
|
if (!n)
|
|
204
201
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
205
|
-
const a =
|
|
202
|
+
const a = K(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
|
|
206
203
|
mnemonic: n,
|
|
207
|
-
hdPath:
|
|
204
|
+
hdPath: x[t]
|
|
208
205
|
}));
|
|
209
|
-
await
|
|
210
|
-
const
|
|
206
|
+
await j(1e3);
|
|
207
|
+
const u = await (a == null ? void 0 : a.getNewAddress({
|
|
211
208
|
privateKey: i
|
|
212
209
|
}));
|
|
213
210
|
return {
|
|
214
211
|
privateKey: i,
|
|
215
|
-
address:
|
|
216
|
-
publicKey:
|
|
212
|
+
address: u.address,
|
|
213
|
+
publicKey: u.publicKey,
|
|
217
214
|
username: e,
|
|
218
215
|
currency: t
|
|
219
216
|
};
|
|
@@ -224,21 +221,21 @@ function ie(e, t) {
|
|
|
224
221
|
(i) => new Map(i ? Array.from(i.entries()) : []).set(a.currency, a)
|
|
225
222
|
);
|
|
226
223
|
}
|
|
227
|
-
}), r =
|
|
224
|
+
}), r = b(() => {
|
|
228
225
|
}, []);
|
|
229
226
|
return {
|
|
230
227
|
createWallet: c,
|
|
231
228
|
importWallet: r
|
|
232
229
|
};
|
|
233
230
|
}
|
|
234
|
-
const
|
|
235
|
-
function
|
|
231
|
+
const B = { privateApiHost: "https://ecency.com" };
|
|
232
|
+
function L(e) {
|
|
236
233
|
const { data: t } = l({
|
|
237
234
|
queryKey: ["ecency-wallets", "wallets", e]
|
|
238
235
|
}), { data: n } = q(e);
|
|
239
|
-
return
|
|
236
|
+
return d({
|
|
240
237
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
241
|
-
mutationFn: ({ currency: s, address: c }) => fetch(
|
|
238
|
+
mutationFn: ({ currency: s, address: c }) => fetch(B.privateApiHost + "/private-api/wallets-add", {
|
|
242
239
|
method: "POST",
|
|
243
240
|
headers: {
|
|
244
241
|
"Content-Type": "application/json"
|
|
@@ -264,19 +261,19 @@ function M(e) {
|
|
|
264
261
|
})
|
|
265
262
|
});
|
|
266
263
|
}
|
|
267
|
-
const
|
|
264
|
+
const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
268
265
|
__proto__: null,
|
|
269
|
-
useCreateAccountWithWallets:
|
|
266
|
+
useCreateAccountWithWallets: L
|
|
270
267
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
271
268
|
export {
|
|
272
269
|
o as EcencyWalletCurrency,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
270
|
+
ie as EcencyWalletsPrivateApi,
|
|
271
|
+
j as delay,
|
|
272
|
+
K as getWallet,
|
|
273
|
+
ae as mnemonicToSeedBip39,
|
|
274
|
+
ce as useCoinGeckoPriceQuery,
|
|
275
|
+
se as useGetExternalWalletBalanceQuery,
|
|
279
276
|
q as useHiveKeysQuery,
|
|
280
|
-
|
|
281
|
-
|
|
277
|
+
y as useSeedPhrase,
|
|
278
|
+
re as useWalletCreate
|
|
282
279
|
};
|