@ecency/wallets 1.0.5 → 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.d.ts +2 -0
- package/dist/ecency-wallets.es.js +94 -90
- 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 {
|
|
2
|
-
import { useQuery as l, useQueryClient 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
|
|
13
|
-
var
|
|
14
|
-
function
|
|
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
|
+
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 j(e) {
|
|
15
15
|
return new Promise((t) => setTimeout(t, e));
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function K(e) {
|
|
18
18
|
switch (e) {
|
|
19
|
-
case
|
|
20
|
-
return new
|
|
21
|
-
case
|
|
19
|
+
case o.BTC:
|
|
20
|
+
return new T();
|
|
21
|
+
case o.ETH:
|
|
22
|
+
return new S();
|
|
23
|
+
case o.TRON:
|
|
22
24
|
return new R();
|
|
23
|
-
case
|
|
25
|
+
case o.TON:
|
|
24
26
|
return new P();
|
|
25
|
-
case
|
|
27
|
+
case o.SOL:
|
|
26
28
|
return new O();
|
|
27
|
-
case
|
|
29
|
+
case o.ATOM:
|
|
28
30
|
return new v();
|
|
29
|
-
case
|
|
31
|
+
case o.APT:
|
|
30
32
|
return new k();
|
|
31
|
-
case n.APT:
|
|
32
|
-
return new A();
|
|
33
33
|
default:
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
function ae(e) {
|
|
38
|
+
return N(e).toString("hex");
|
|
39
|
+
}
|
|
37
40
|
function se(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 w = (await (await fetch(
|
|
80
83
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
81
84
|
)).json()).find(
|
|
82
85
|
(h) => h.type.includes("coin::CoinStore")
|
|
83
86
|
);
|
|
84
|
-
return
|
|
85
|
-
case
|
|
87
|
+
return w ? parseInt(w.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;
|
|
@@ -93,10 +96,10 @@ function se(e, t) {
|
|
|
93
96
|
function y() {
|
|
94
97
|
return l({
|
|
95
98
|
queryKey: ["ecency-wallets", "seed"],
|
|
96
|
-
queryFn: async () =>
|
|
99
|
+
queryFn: async () => A.generateMnemonic(128)
|
|
97
100
|
});
|
|
98
101
|
}
|
|
99
|
-
const
|
|
102
|
+
const _ = {
|
|
100
103
|
max: 500,
|
|
101
104
|
// how long to live in ms
|
|
102
105
|
ttl: 1e3 * 60 * 5,
|
|
@@ -104,7 +107,7 @@ const H = {
|
|
|
104
107
|
allowStale: !1,
|
|
105
108
|
updateAgeOnGet: !1,
|
|
106
109
|
updateAgeOnHas: !1
|
|
107
|
-
}, f = new
|
|
110
|
+
}, f = new D(_), m = Symbol("undefined"), H = (e, t) => f.set(e, t === void 0 ? m : t), W = (e) => {
|
|
108
111
|
const t = f.get(e);
|
|
109
112
|
return t === m ? void 0 : t;
|
|
110
113
|
};
|
|
@@ -114,21 +117,24 @@ function ce(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,72 +148,69 @@ 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 } = y()
|
|
154
|
-
() => N(t ?? "").toString("hex"),
|
|
155
|
-
[t]
|
|
156
|
-
);
|
|
158
|
+
function q(e) {
|
|
159
|
+
const { data: t } = y();
|
|
157
160
|
return l({
|
|
158
|
-
queryKey: ["ecencу-wallets", "hive-keys", e,
|
|
161
|
+
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
|
159
162
|
queryFn: async () => {
|
|
160
163
|
if (!t)
|
|
161
164
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
162
|
-
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");
|
|
163
166
|
return {
|
|
164
167
|
username: e,
|
|
165
|
-
owner:
|
|
166
|
-
active:
|
|
167
|
-
posting:
|
|
168
|
-
memo:
|
|
169
|
-
ownerPubkey:
|
|
170
|
-
activePubkey:
|
|
171
|
-
postingPubkey:
|
|
172
|
-
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()
|
|
173
176
|
};
|
|
174
177
|
}
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
|
-
const
|
|
178
|
-
[
|
|
180
|
+
const x = {
|
|
181
|
+
[o.BTC]: "m/44'/0'/0'/0/0",
|
|
179
182
|
// Bitcoin (BIP44)
|
|
180
|
-
[
|
|
183
|
+
[o.ETH]: "m/44'/60'/0'/0/0",
|
|
181
184
|
// Ethereum (BIP44)
|
|
182
|
-
[
|
|
185
|
+
[o.SOL]: "m/44'/501'/0'/0/0",
|
|
183
186
|
// Solana (BIP44)
|
|
184
|
-
[
|
|
187
|
+
[o.TON]: "m/44'/396'/0'/0/0",
|
|
185
188
|
// TON (BIP44)
|
|
186
|
-
[
|
|
189
|
+
[o.TRON]: "m/44'/195'/0'/0/0",
|
|
187
190
|
// Tron (BIP44)
|
|
188
|
-
[
|
|
191
|
+
[o.APT]: "m/44'/637'/0'/0/0",
|
|
189
192
|
// Aptos (BIP44)
|
|
190
|
-
[
|
|
193
|
+
[o.ATOM]: "m/44'/118'/0'/0/0"
|
|
191
194
|
// Cosmos (BIP44)
|
|
192
195
|
};
|
|
193
196
|
function re(e, t) {
|
|
194
|
-
const { data:
|
|
197
|
+
const { data: n } = y(), s = g(), c = d({
|
|
195
198
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
196
199
|
mutationFn: async () => {
|
|
197
|
-
if (!
|
|
200
|
+
if (!n)
|
|
198
201
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
199
|
-
const a =
|
|
200
|
-
mnemonic:
|
|
201
|
-
hdPath:
|
|
202
|
+
const a = K(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
|
|
203
|
+
mnemonic: n,
|
|
204
|
+
hdPath: x[t]
|
|
202
205
|
}));
|
|
203
|
-
await
|
|
204
|
-
const
|
|
206
|
+
await j(1e3);
|
|
207
|
+
const u = await (a == null ? void 0 : a.getNewAddress({
|
|
205
208
|
privateKey: i
|
|
206
209
|
}));
|
|
207
210
|
return {
|
|
208
211
|
privateKey: i,
|
|
209
|
-
address:
|
|
210
|
-
publicKey:
|
|
212
|
+
address: u.address,
|
|
213
|
+
publicKey: u.publicKey,
|
|
211
214
|
username: e,
|
|
212
215
|
currency: t
|
|
213
216
|
};
|
|
@@ -218,21 +221,21 @@ function re(e, t) {
|
|
|
218
221
|
(i) => new Map(i ? Array.from(i.entries()) : []).set(a.currency, a)
|
|
219
222
|
);
|
|
220
223
|
}
|
|
221
|
-
}), r =
|
|
224
|
+
}), r = b(() => {
|
|
222
225
|
}, []);
|
|
223
226
|
return {
|
|
224
227
|
createWallet: c,
|
|
225
228
|
importWallet: r
|
|
226
229
|
};
|
|
227
230
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
231
|
+
const B = { privateApiHost: "https://ecency.com" };
|
|
232
|
+
function L(e) {
|
|
230
233
|
const { data: t } = l({
|
|
231
234
|
queryKey: ["ecency-wallets", "wallets", e]
|
|
232
|
-
}), { data:
|
|
233
|
-
return
|
|
235
|
+
}), { data: n } = q(e);
|
|
236
|
+
return d({
|
|
234
237
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
235
|
-
mutationFn: ({ currency: s, address: c }) => fetch(
|
|
238
|
+
mutationFn: ({ currency: s, address: c }) => fetch(B.privateApiHost + "/private-api/wallets-add", {
|
|
236
239
|
method: "POST",
|
|
237
240
|
headers: {
|
|
238
241
|
"Content-Type": "application/json"
|
|
@@ -242,10 +245,10 @@ function M(e) {
|
|
|
242
245
|
token: s,
|
|
243
246
|
address: c,
|
|
244
247
|
meta: {
|
|
245
|
-
ownerPublicKey:
|
|
246
|
-
activePublicKey:
|
|
247
|
-
postingPublicKey:
|
|
248
|
-
memoPublicKey:
|
|
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,
|
|
249
252
|
...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
|
|
250
253
|
(r, [a, i]) => ({
|
|
251
254
|
...r,
|
|
@@ -260,16 +263,17 @@ function M(e) {
|
|
|
260
263
|
}
|
|
261
264
|
const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
262
265
|
__proto__: null,
|
|
263
|
-
useCreateAccountWithWallets:
|
|
266
|
+
useCreateAccountWithWallets: L
|
|
264
267
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
265
268
|
export {
|
|
266
|
-
|
|
269
|
+
o as EcencyWalletCurrency,
|
|
267
270
|
ie as EcencyWalletsPrivateApi,
|
|
268
|
-
|
|
269
|
-
|
|
271
|
+
j as delay,
|
|
272
|
+
K as getWallet,
|
|
273
|
+
ae as mnemonicToSeedBip39,
|
|
270
274
|
ce as useCoinGeckoPriceQuery,
|
|
271
275
|
se as useGetExternalWalletBalanceQuery,
|
|
272
|
-
|
|
276
|
+
q as useHiveKeysQuery,
|
|
273
277
|
y as useSeedPhrase,
|
|
274
278
|
re as useWalletCreate
|
|
275
279
|
};
|
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.7",
|
|
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"
|