@ecency/wallets 1.0.1 → 1.0.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.js +91 -93
- package/package.json +1 -1
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useQuery as l, useQueryClient as g, useMutation as
|
|
1
|
+
import { useMemo as b, useCallback as S } from "react";
|
|
2
|
+
import { useQuery as l, useQueryClient as g, useMutation as d } from "@tanstack/react-query";
|
|
3
3
|
import { BtcWallet as T } from "@okxweb3/coin-bitcoin";
|
|
4
4
|
import { EthWallet as R } from "@okxweb3/coin-ethereum";
|
|
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
|
|
5
|
+
import { TrxWallet as P } from "@okxweb3/coin-tron";
|
|
6
|
+
import { TonWallet as O } from "@okxweb3/coin-ton";
|
|
7
|
+
import { SolWallet as v } from "@okxweb3/coin-solana";
|
|
8
|
+
import { AtomWallet as k } from "@okxweb3/coin-cosmos";
|
|
9
|
+
import { AptosWallet as A } from "@okxweb3/coin-aptos";
|
|
10
|
+
import D, { mnemonicToSeedSync as N } from "bip39";
|
|
11
|
+
import { LRUCache as K } from "lru-cache";
|
|
12
12
|
import { PrivateKey as u } from "@hiveio/dhive";
|
|
13
|
-
var
|
|
14
|
-
function
|
|
13
|
+
var n = /* @__PURE__ */ ((e) => (e.BTC = "btc", e.ETH = "eth", e.APT = "atpos", e.ATOM = "cosmos", e.TON = "ton", e.TRON = "tron", e.SOL = "Solana", e))(n || {});
|
|
14
|
+
function j(e) {
|
|
15
15
|
return new Promise((t) => setTimeout(t, e));
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function _(e) {
|
|
18
18
|
switch (e) {
|
|
19
|
-
case
|
|
19
|
+
case n.BTC:
|
|
20
20
|
return new T();
|
|
21
|
-
case
|
|
21
|
+
case n.ETH:
|
|
22
22
|
return new R();
|
|
23
|
-
case
|
|
24
|
-
return new S();
|
|
25
|
-
case o.TON:
|
|
23
|
+
case n.TRON:
|
|
26
24
|
return new P();
|
|
27
|
-
case
|
|
25
|
+
case n.TON:
|
|
28
26
|
return new O();
|
|
29
|
-
case
|
|
27
|
+
case n.SOL:
|
|
30
28
|
return new v();
|
|
31
|
-
case
|
|
29
|
+
case n.ATOM:
|
|
32
30
|
return new k();
|
|
31
|
+
case n.APT:
|
|
32
|
+
return new A();
|
|
33
33
|
default:
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function se(e, t) {
|
|
38
38
|
return l({
|
|
39
39
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
|
40
40
|
queryFn: async () => {
|
|
41
41
|
switch (e) {
|
|
42
|
-
case
|
|
42
|
+
case n.BTC:
|
|
43
43
|
const s = await (await fetch(
|
|
44
44
|
`https://mempool.space/api/address/${t}`
|
|
45
45
|
)).json();
|
|
46
46
|
return (s.chain_stats.funded_txo_sum - s.chain_stats.spent_txo_sum) / 1e8;
|
|
47
|
-
case
|
|
47
|
+
case n.ETH:
|
|
48
48
|
return +(await (await fetch("https://eth.llamarpc.com", {
|
|
49
49
|
method: "POST",
|
|
50
50
|
body: JSON.stringify({
|
|
@@ -54,7 +54,7 @@ function ae(e, t) {
|
|
|
54
54
|
params: [t, "latest"]
|
|
55
55
|
})
|
|
56
56
|
})).json()).result / 1e18;
|
|
57
|
-
case
|
|
57
|
+
case n.SOL:
|
|
58
58
|
return (await (await fetch(
|
|
59
59
|
"https://api.mainnet-beta.solana.com",
|
|
60
60
|
{
|
|
@@ -67,22 +67,22 @@ function ae(e, t) {
|
|
|
67
67
|
})
|
|
68
68
|
}
|
|
69
69
|
)).json()).result.value / 1e9;
|
|
70
|
-
case
|
|
70
|
+
case n.TRON:
|
|
71
71
|
return (await (await fetch(
|
|
72
72
|
`https://api.trongrid.io/v1/accounts/${t}`
|
|
73
73
|
)).json()).data[0].balance / 1e6;
|
|
74
|
-
case
|
|
74
|
+
case n.TON:
|
|
75
75
|
return (await (await fetch(
|
|
76
76
|
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
|
77
77
|
)).json()).balance / 1e9;
|
|
78
|
-
case
|
|
78
|
+
case n.APT:
|
|
79
79
|
const w = (await (await fetch(
|
|
80
80
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
81
81
|
)).json()).find(
|
|
82
82
|
(h) => h.type.includes("coin::CoinStore")
|
|
83
83
|
);
|
|
84
84
|
return w ? parseInt(w.data.coin.value) / 1e8 : 0;
|
|
85
|
-
case
|
|
85
|
+
case n.ATOM:
|
|
86
86
|
return +(await (await fetch(
|
|
87
87
|
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
|
|
88
88
|
)).json()).result.value.coins[0].amount / 1e6;
|
|
@@ -90,13 +90,13 @@ function ae(e, t) {
|
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function f() {
|
|
94
94
|
return l({
|
|
95
95
|
queryKey: ["ecency-wallets", "seed"],
|
|
96
|
-
queryFn: async () =>
|
|
96
|
+
queryFn: async () => D.generateMnemonic(128)
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
const
|
|
99
|
+
const W = {
|
|
100
100
|
max: 500,
|
|
101
101
|
// how long to live in ms
|
|
102
102
|
ttl: 1e3 * 60 * 5,
|
|
@@ -104,31 +104,31 @@ const _ = {
|
|
|
104
104
|
allowStale: !1,
|
|
105
105
|
updateAgeOnGet: !1,
|
|
106
106
|
updateAgeOnHas: !1
|
|
107
|
-
}, y = new
|
|
107
|
+
}, y = new K(W), m = Symbol("undefined"), q = (e, t) => y.set(e, t === void 0 ? m : t), x = (e) => {
|
|
108
108
|
const t = y.get(e);
|
|
109
109
|
return t === m ? void 0 : t;
|
|
110
110
|
};
|
|
111
|
-
function
|
|
111
|
+
function ce(e) {
|
|
112
112
|
return l({
|
|
113
113
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
|
114
114
|
queryFn: async () => {
|
|
115
115
|
let t = e;
|
|
116
116
|
switch (e) {
|
|
117
|
-
case
|
|
117
|
+
case n.BTC:
|
|
118
118
|
t = "binance-wrapped-btc";
|
|
119
119
|
break;
|
|
120
|
-
case
|
|
120
|
+
case n.ETH:
|
|
121
121
|
t = "ethereum";
|
|
122
122
|
break;
|
|
123
|
-
case
|
|
123
|
+
case n.SOL:
|
|
124
124
|
t = "solana";
|
|
125
125
|
break;
|
|
126
126
|
default:
|
|
127
127
|
t = e;
|
|
128
128
|
}
|
|
129
|
-
let
|
|
130
|
-
if (
|
|
131
|
-
s =
|
|
129
|
+
let o = x("gecko"), s;
|
|
130
|
+
if (o)
|
|
131
|
+
s = o;
|
|
132
132
|
else {
|
|
133
133
|
const a = await (await fetch(
|
|
134
134
|
"https://api.coingecko.com/api/v3/simple/price",
|
|
@@ -142,67 +142,65 @@ function se(e) {
|
|
|
142
142
|
})
|
|
143
143
|
}
|
|
144
144
|
)).json();
|
|
145
|
-
|
|
145
|
+
q("gecko", a === void 0 ? m : a), s = a;
|
|
146
146
|
}
|
|
147
147
|
return 1 / +s[Object.keys(s)[0]].usd;
|
|
148
148
|
},
|
|
149
149
|
enabled: !!e
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
|
-
function
|
|
153
|
-
const { data: t } =
|
|
152
|
+
function B(e) {
|
|
153
|
+
const { data: t } = f(), o = b(
|
|
154
|
+
() => N(t ?? "").toString("hex"),
|
|
155
|
+
[t]
|
|
156
|
+
);
|
|
154
157
|
return l({
|
|
155
|
-
queryKey: [
|
|
156
|
-
"ecenc-wallets",
|
|
157
|
-
"hive-keys",
|
|
158
|
-
e,
|
|
159
|
-
D(t ?? "")
|
|
160
|
-
],
|
|
158
|
+
queryKey: ["ecencу-wallets", "hive-keys", e, o],
|
|
161
159
|
queryFn: async () => {
|
|
162
160
|
if (!t)
|
|
163
161
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
164
|
-
const
|
|
162
|
+
const s = u.fromSeed(o + "owner"), c = u.fromSeed(o + "active"), r = u.fromSeed(o + "posting"), a = u.fromSeed(o + "memo");
|
|
165
163
|
return {
|
|
166
164
|
username: e,
|
|
167
|
-
owner:
|
|
168
|
-
active:
|
|
169
|
-
posting:
|
|
170
|
-
memo:
|
|
171
|
-
ownerPubkey:
|
|
172
|
-
activePubkey:
|
|
173
|
-
postingPubkey:
|
|
174
|
-
memoPubkey:
|
|
165
|
+
owner: s.toString(),
|
|
166
|
+
active: c.toString(),
|
|
167
|
+
posting: r.toString(),
|
|
168
|
+
memo: a.toString(),
|
|
169
|
+
ownerPubkey: s.createPublic().toString(),
|
|
170
|
+
activePubkey: c.createPublic().toString(),
|
|
171
|
+
postingPubkey: r.createPublic().toString(),
|
|
172
|
+
memoPubkey: a.createPublic().toString()
|
|
175
173
|
};
|
|
176
174
|
}
|
|
177
175
|
});
|
|
178
176
|
}
|
|
179
|
-
const
|
|
180
|
-
[
|
|
177
|
+
const H = {
|
|
178
|
+
[n.BTC]: "m/44'/0'/0'/0/0",
|
|
181
179
|
// Bitcoin (BIP44)
|
|
182
|
-
[
|
|
180
|
+
[n.ETH]: "m/44'/60'/0'/0/0",
|
|
183
181
|
// Ethereum (BIP44)
|
|
184
|
-
[
|
|
182
|
+
[n.SOL]: "m/44'/501'/0'/0/0",
|
|
185
183
|
// Solana (BIP44)
|
|
186
|
-
[
|
|
184
|
+
[n.TON]: "m/44'/396'/0'/0/0",
|
|
187
185
|
// TON (BIP44)
|
|
188
|
-
[
|
|
186
|
+
[n.TRON]: "m/44'/195'/0'/0/0",
|
|
189
187
|
// Tron (BIP44)
|
|
190
|
-
[
|
|
188
|
+
[n.APT]: "m/44'/637'/0'/0/0",
|
|
191
189
|
// Aptos (BIP44)
|
|
192
|
-
[
|
|
190
|
+
[n.ATOM]: "m/44'/118'/0'/0/0"
|
|
193
191
|
// Cosmos (BIP44)
|
|
194
192
|
};
|
|
195
|
-
function
|
|
196
|
-
const { data:
|
|
193
|
+
function re(e, t) {
|
|
194
|
+
const { data: o } = f(), s = g(), c = d({
|
|
197
195
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
198
196
|
mutationFn: async () => {
|
|
199
|
-
if (!
|
|
197
|
+
if (!o)
|
|
200
198
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
201
|
-
const a =
|
|
202
|
-
mnemonic:
|
|
203
|
-
hdPath:
|
|
199
|
+
const a = _(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
|
|
200
|
+
mnemonic: o,
|
|
201
|
+
hdPath: H[t]
|
|
204
202
|
}));
|
|
205
|
-
await
|
|
203
|
+
await j(1e3);
|
|
206
204
|
const p = await (a == null ? void 0 : a.getNewAddress({
|
|
207
205
|
privateKey: i
|
|
208
206
|
}));
|
|
@@ -220,31 +218,31 @@ function ce(e, t) {
|
|
|
220
218
|
(i) => new Map(i ? Array.from(i.entries()) : []).set(a.currency, a)
|
|
221
219
|
);
|
|
222
220
|
}
|
|
223
|
-
}), r =
|
|
221
|
+
}), r = S(() => {
|
|
224
222
|
}, []);
|
|
225
223
|
return {
|
|
226
224
|
createWallet: c,
|
|
227
225
|
importWallet: r
|
|
228
226
|
};
|
|
229
227
|
}
|
|
230
|
-
const
|
|
231
|
-
function
|
|
228
|
+
const M = {};
|
|
229
|
+
function C(e) {
|
|
232
230
|
const { data: t } = l({
|
|
233
231
|
queryKey: ["ecency-wallets", "wallets", e]
|
|
234
|
-
}), { data:
|
|
235
|
-
return
|
|
232
|
+
}), { data: o } = B(e);
|
|
233
|
+
return d({
|
|
236
234
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
237
|
-
mutationFn: ({ currency: s, address: c }) => fetch(
|
|
235
|
+
mutationFn: ({ currency: s, address: c }) => fetch(M + "/private-api/wallets-add", {
|
|
238
236
|
method: "POST",
|
|
239
237
|
body: JSON.stringify({
|
|
240
238
|
username: e,
|
|
241
239
|
token: s,
|
|
242
240
|
address: c,
|
|
243
241
|
meta: {
|
|
244
|
-
ownerPublicKey:
|
|
245
|
-
activePublicKey:
|
|
246
|
-
postingPublicKey:
|
|
247
|
-
memoPublicKey:
|
|
242
|
+
ownerPublicKey: o == null ? void 0 : o.ownerPubkey,
|
|
243
|
+
activePublicKey: o == null ? void 0 : o.activePubkey,
|
|
244
|
+
postingPublicKey: o == null ? void 0 : o.postingPubkey,
|
|
245
|
+
memoPublicKey: o == null ? void 0 : o.memoPubkey,
|
|
248
246
|
...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
|
|
249
247
|
(r, [a, i]) => ({
|
|
250
248
|
...r,
|
|
@@ -257,18 +255,18 @@ function x(e) {
|
|
|
257
255
|
})
|
|
258
256
|
});
|
|
259
257
|
}
|
|
260
|
-
const
|
|
258
|
+
const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
261
259
|
__proto__: null,
|
|
262
|
-
useCreateAccountWithWallets:
|
|
260
|
+
useCreateAccountWithWallets: C
|
|
263
261
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
264
262
|
export {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
263
|
+
n as EcencyWalletCurrency,
|
|
264
|
+
ie as EcencyWalletsPrivateApi,
|
|
265
|
+
j as delay,
|
|
266
|
+
_ as getWallet,
|
|
267
|
+
ce as useCoinGeckoPriceQuery,
|
|
268
|
+
se as useGetExternalWalletBalanceQuery,
|
|
269
|
+
B as useHiveKeysQuery,
|
|
270
|
+
f as useSeedPhrase,
|
|
271
|
+
re as useWalletCreate
|
|
274
272
|
};
|