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