@ecency/wallets 1.1.1 → 1.2.0
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 → ecency-sdk.es.js} +173 -119
- package/dist/index.d.ts +1 -0
- package/dist/modules/wallets/enums/ecency-wallet-basic-tokens.d.ts +7 -0
- package/dist/modules/wallets/enums/ecency-wallet-currency.d.ts +9 -0
- package/dist/modules/wallets/enums/index.d.ts +2 -0
- package/dist/modules/wallets/functions/get-keys-from-seed.d.ts +3 -0
- package/dist/modules/wallets/functions/index.d.ts +1 -0
- package/dist/modules/wallets/index.d.ts +4 -0
- package/dist/modules/wallets/mutations/index.d.ts +4 -0
- package/dist/modules/wallets/mutations/private-api/check-wallet-existence.d.ts +7 -0
- package/dist/modules/wallets/mutations/private-api/create-account-with-wallets.d.ts +7 -0
- package/dist/modules/wallets/mutations/private-api/index.d.ts +2 -0
- package/dist/modules/wallets/mutations/private-api-namespace.d.ts +2 -0
- package/dist/modules/wallets/mutations/save-wallet-information-to-metadata.d.ts +5 -0
- package/dist/modules/wallets/mutations/use-import-wallet.d.ts +10 -0
- package/dist/modules/wallets/mutations/use-wallet-create.d.ts +6 -0
- package/dist/modules/wallets/queries/get-account-points-query-options.d.ts +9 -0
- package/dist/modules/wallets/queries/index.d.ts +6 -0
- package/dist/modules/wallets/queries/use-coingecko-price-query.d.ts +2 -0
- package/dist/modules/wallets/queries/use-get-account-wallet-list-query.d.ts +9 -0
- package/dist/modules/wallets/queries/use-get-all-tokens-list-query.d.ts +6 -0
- package/dist/modules/wallets/queries/use-get-external-wallet-query.d.ts +10 -0
- package/dist/modules/wallets/queries/use-hive-keys-query.d.ts +2 -0
- package/dist/modules/wallets/queries/use-seed-phrase.d.ts +1 -0
- package/dist/modules/wallets/types/account-points-response.d.ts +4 -0
- package/dist/modules/wallets/types/ecency-create-wallet-information.d.ts +9 -0
- package/dist/modules/wallets/types/ecency-hive-keys.d.ts +12 -0
- package/dist/modules/wallets/types/index.d.ts +3 -0
- package/dist/modules/wallets/utils/delay.d.ts +1 -0
- package/dist/modules/wallets/utils/get-wallet.d.ts +3 -0
- package/dist/modules/wallets/utils/index.d.ts +3 -0
- package/dist/modules/wallets/utils/mnemonic-to-seed-bip-39.d.ts +1 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +10 -8
- package/Readme.md +0 -36
- package/dist/ecency-wallets.es.d.ts +0 -97
|
@@ -1,65 +1,57 @@
|
|
|
1
|
-
import { useCallback as
|
|
2
|
-
import { useQuery as p, useQueryClient as
|
|
3
|
-
import { BtcWallet as
|
|
4
|
-
import { EthWallet as
|
|
5
|
-
import { TrxWallet as
|
|
6
|
-
import { TonWallet as
|
|
1
|
+
import { useMemo as S, useCallback as A } from "react";
|
|
2
|
+
import { useQuery as p, queryOptions as R, useQueryClient as h, useMutation as m } from "@tanstack/react-query";
|
|
3
|
+
import { BtcWallet as k } from "@okxweb3/coin-bitcoin";
|
|
4
|
+
import { EthWallet as H } from "@okxweb3/coin-ethereum";
|
|
5
|
+
import { TrxWallet as C } from "@okxweb3/coin-tron";
|
|
6
|
+
import { TonWallet as K } from "@okxweb3/coin-ton";
|
|
7
7
|
import { SolWallet as N } from "@okxweb3/coin-solana";
|
|
8
|
-
import { AtomWallet as
|
|
9
|
-
import { AptosWallet as
|
|
10
|
-
import j
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
import { AtomWallet as D } from "@okxweb3/coin-cosmos";
|
|
9
|
+
import { AptosWallet as L } from "@okxweb3/coin-aptos";
|
|
10
|
+
import j from "bip39";
|
|
11
|
+
import { CONFIG as d, getHiveEngineTokensListQueryOptions as x, useAccountUpdate as M } from "@ecency/sdk";
|
|
12
|
+
import { LRUCache as _ } from "lru-cache";
|
|
13
|
+
import { PrivateKey as w } from "@hiveio/dhive";
|
|
14
|
+
var o = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(o || {}), u = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(u || {});
|
|
15
|
+
function E(e) {
|
|
15
16
|
return new Promise((t) => setTimeout(t, e));
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
+
function T(e) {
|
|
18
19
|
switch (e) {
|
|
19
20
|
case o.BTC:
|
|
20
|
-
return new
|
|
21
|
+
return new k();
|
|
21
22
|
case o.ETH:
|
|
22
|
-
return new
|
|
23
|
+
return new H();
|
|
23
24
|
case o.TRON:
|
|
24
|
-
return new
|
|
25
|
+
return new C();
|
|
25
26
|
case o.TON:
|
|
26
|
-
return new
|
|
27
|
+
return new K();
|
|
27
28
|
case o.SOL:
|
|
28
29
|
return new N();
|
|
29
30
|
case o.ATOM:
|
|
30
|
-
return new K();
|
|
31
|
-
case o.APT:
|
|
32
31
|
return new D();
|
|
32
|
+
case o.APT:
|
|
33
|
+
return new L();
|
|
33
34
|
default:
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
-
return C(e).toString("hex");
|
|
39
|
-
}
|
|
40
|
-
function ie(e, t) {
|
|
38
|
+
function me(e, t) {
|
|
41
39
|
return p({
|
|
42
40
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
|
43
41
|
queryFn: async () => {
|
|
44
42
|
switch (e) {
|
|
45
43
|
case o.BTC:
|
|
46
|
-
const
|
|
44
|
+
const a = await (await fetch(
|
|
47
45
|
`https://mempool.space/api/address/${t}`
|
|
48
46
|
)).json();
|
|
49
|
-
return (
|
|
47
|
+
return (a.chain_stats.funded_txo_sum - a.chain_stats.spent_txo_sum) / 1e8;
|
|
50
48
|
case o.ETH:
|
|
51
|
-
return +(await (await fetch(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
jsonrpc: "2.0",
|
|
55
|
-
id: "1",
|
|
56
|
-
method: "eth_getBalance",
|
|
57
|
-
params: [t, "latest"]
|
|
58
|
-
})
|
|
59
|
-
})).json()).result / 1e18;
|
|
49
|
+
return +(await (await fetch(
|
|
50
|
+
`https://api.ethplorer.io/getAddressInfo/${t}?apiKey=freekey`
|
|
51
|
+
)).json()).ETH.balance;
|
|
60
52
|
case o.SOL:
|
|
61
53
|
return (await (await fetch(
|
|
62
|
-
|
|
54
|
+
`https://rpc.helius.xyz/?api-key=${d.heliusApiKey}`,
|
|
63
55
|
{
|
|
64
56
|
method: "POST",
|
|
65
57
|
body: JSON.stringify({
|
|
@@ -67,7 +59,10 @@ function ie(e, t) {
|
|
|
67
59
|
id: "1",
|
|
68
60
|
method: "getBalance",
|
|
69
61
|
params: [t]
|
|
70
|
-
})
|
|
62
|
+
}),
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json"
|
|
65
|
+
}
|
|
71
66
|
}
|
|
72
67
|
)).json()).result.value / 1e9;
|
|
73
68
|
case o.TRON:
|
|
@@ -79,12 +74,12 @@ function ie(e, t) {
|
|
|
79
74
|
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
|
80
75
|
)).json()).balance / 1e9;
|
|
81
76
|
case o.APT:
|
|
82
|
-
const
|
|
77
|
+
const f = (await (await fetch(
|
|
83
78
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
84
79
|
)).json()).find(
|
|
85
|
-
(
|
|
80
|
+
(O) => O.type.includes("coin::CoinStore")
|
|
86
81
|
);
|
|
87
|
-
return
|
|
82
|
+
return f ? parseInt(f.data.coin.value) / 1e8 : 0;
|
|
88
83
|
case o.ATOM:
|
|
89
84
|
return +(await (await fetch(
|
|
90
85
|
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
|
|
@@ -93,13 +88,13 @@ function ie(e, t) {
|
|
|
93
88
|
}
|
|
94
89
|
});
|
|
95
90
|
}
|
|
96
|
-
function
|
|
91
|
+
function b(e) {
|
|
97
92
|
return p({
|
|
98
93
|
queryKey: ["ecency-wallets", "seed", e],
|
|
99
94
|
queryFn: async () => j.generateMnemonic(128)
|
|
100
95
|
});
|
|
101
96
|
}
|
|
102
|
-
const
|
|
97
|
+
const F = {
|
|
103
98
|
max: 500,
|
|
104
99
|
// how long to live in ms
|
|
105
100
|
ttl: 1e3 * 60 * 5,
|
|
@@ -107,11 +102,11 @@ const W = {
|
|
|
107
102
|
allowStale: !1,
|
|
108
103
|
updateAgeOnGet: !1,
|
|
109
104
|
updateAgeOnHas: !1
|
|
110
|
-
},
|
|
111
|
-
const t =
|
|
112
|
-
return t ===
|
|
105
|
+
}, g = new _(F), y = Symbol("undefined"), q = (e, t) => g.set(e, t === void 0 ? y : t), W = (e) => {
|
|
106
|
+
const t = g.get(e);
|
|
107
|
+
return t === y ? void 0 : t;
|
|
113
108
|
};
|
|
114
|
-
function
|
|
109
|
+
function we(e) {
|
|
115
110
|
return p({
|
|
116
111
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
|
117
112
|
queryFn: async () => {
|
|
@@ -132,11 +127,11 @@ function le(e) {
|
|
|
132
127
|
default:
|
|
133
128
|
t = e;
|
|
134
129
|
}
|
|
135
|
-
let n =
|
|
130
|
+
let n = W("gecko"), a;
|
|
136
131
|
if (n)
|
|
137
|
-
|
|
132
|
+
a = n;
|
|
138
133
|
else {
|
|
139
|
-
const
|
|
134
|
+
const r = await (await fetch(
|
|
140
135
|
"https://api.coingecko.com/api/v3/simple/price",
|
|
141
136
|
{
|
|
142
137
|
method: "POST",
|
|
@@ -148,35 +143,76 @@ function le(e) {
|
|
|
148
143
|
})
|
|
149
144
|
}
|
|
150
145
|
)).json();
|
|
151
|
-
|
|
146
|
+
q("gecko", r === void 0 ? y : r), a = r;
|
|
152
147
|
}
|
|
153
|
-
return 1 / +
|
|
148
|
+
return 1 / +a[Object.keys(a)[0]].usd;
|
|
154
149
|
},
|
|
155
150
|
enabled: !!e
|
|
156
151
|
});
|
|
157
152
|
}
|
|
158
|
-
function
|
|
159
|
-
const { data: t } =
|
|
153
|
+
function Q(e) {
|
|
154
|
+
const { data: t } = b(e);
|
|
160
155
|
return p({
|
|
161
156
|
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
|
162
157
|
queryFn: async () => {
|
|
163
158
|
if (!t)
|
|
164
159
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
165
|
-
const n =
|
|
160
|
+
const n = w.fromLogin(e, t, "owner"), a = w.fromLogin(e, t, "active"), s = w.fromLogin(e, t, "posting"), c = w.fromLogin(e, t, "memo");
|
|
166
161
|
return {
|
|
167
162
|
username: e,
|
|
168
163
|
owner: n.toString(),
|
|
169
|
-
active:
|
|
164
|
+
active: a.toString(),
|
|
170
165
|
posting: s.toString(),
|
|
171
|
-
memo:
|
|
166
|
+
memo: c.toString(),
|
|
172
167
|
ownerPubkey: n.createPublic().toString(),
|
|
173
|
-
activePubkey:
|
|
168
|
+
activePubkey: a.createPublic().toString(),
|
|
174
169
|
postingPubkey: s.createPublic().toString(),
|
|
175
|
-
memoPubkey:
|
|
170
|
+
memoPubkey: c.createPublic().toString()
|
|
176
171
|
};
|
|
177
172
|
}
|
|
178
173
|
});
|
|
179
174
|
}
|
|
175
|
+
function de(e, t) {
|
|
176
|
+
return R({
|
|
177
|
+
queryKey: ["ecency-wallets", "points", e, t],
|
|
178
|
+
queryFn: async () => await (await fetch(
|
|
179
|
+
`${d.privateApiHost}/private-api/points`,
|
|
180
|
+
{
|
|
181
|
+
method: "POST",
|
|
182
|
+
body: JSON.stringify({
|
|
183
|
+
username: e.replace("@", "")
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
)).json(),
|
|
187
|
+
staleTime: 3e4,
|
|
188
|
+
refetchOnMount: !0,
|
|
189
|
+
enabled: !!e
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function ye(e) {
|
|
193
|
+
const { data: t } = p(x());
|
|
194
|
+
return S(
|
|
195
|
+
() => {
|
|
196
|
+
var n;
|
|
197
|
+
return {
|
|
198
|
+
basic: [
|
|
199
|
+
u.Points,
|
|
200
|
+
u.Hive,
|
|
201
|
+
u.HivePower,
|
|
202
|
+
u.HiveDollar,
|
|
203
|
+
u.Spk
|
|
204
|
+
].filter((a) => a.toLowerCase().includes(e.toLowerCase())),
|
|
205
|
+
external: Object.values(o).filter(
|
|
206
|
+
(a) => a.toLowerCase().includes(e.toLowerCase())
|
|
207
|
+
),
|
|
208
|
+
layer2: ((n = t == null ? void 0 : t.map(({ symbol: a }) => a)) == null ? void 0 : n.filter(
|
|
209
|
+
(a) => a.toLowerCase().includes(e.toLowerCase())
|
|
210
|
+
)) ?? []
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
[t, e]
|
|
214
|
+
);
|
|
215
|
+
}
|
|
180
216
|
const B = {
|
|
181
217
|
[o.BTC]: "m/44'/0'/0'/0/0",
|
|
182
218
|
// Bitcoin (BIP44)
|
|
@@ -193,56 +229,55 @@ const B = {
|
|
|
193
229
|
[o.ATOM]: "m/44'/118'/0'/0/0"
|
|
194
230
|
// Cosmos (BIP44)
|
|
195
231
|
};
|
|
196
|
-
function
|
|
197
|
-
const { data: n } =
|
|
232
|
+
function fe(e, t) {
|
|
233
|
+
const { data: n } = b(e), a = h(), s = m({
|
|
198
234
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
199
235
|
mutationFn: async () => {
|
|
200
236
|
if (!n)
|
|
201
237
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
202
|
-
const
|
|
238
|
+
const r = T(t), i = await (r == null ? void 0 : r.getDerivedPrivateKey({
|
|
203
239
|
mnemonic: n,
|
|
204
240
|
hdPath: B[t]
|
|
205
241
|
}));
|
|
206
|
-
await
|
|
207
|
-
const l = await (
|
|
208
|
-
privateKey:
|
|
242
|
+
await E(1e3);
|
|
243
|
+
const l = await (r == null ? void 0 : r.getNewAddress({
|
|
244
|
+
privateKey: i
|
|
209
245
|
}));
|
|
210
246
|
return {
|
|
211
|
-
privateKey:
|
|
247
|
+
privateKey: i,
|
|
212
248
|
address: l.address,
|
|
213
249
|
publicKey: l.publicKey,
|
|
214
250
|
username: e,
|
|
215
251
|
currency: t
|
|
216
252
|
};
|
|
217
253
|
},
|
|
218
|
-
onSuccess: (
|
|
219
|
-
|
|
220
|
-
["ecency-wallets", "wallets",
|
|
221
|
-
(
|
|
254
|
+
onSuccess: (r) => {
|
|
255
|
+
a.setQueryData(
|
|
256
|
+
["ecency-wallets", "wallets", r.username],
|
|
257
|
+
(i) => new Map(i ? Array.from(i.entries()) : []).set(r.currency, r)
|
|
222
258
|
);
|
|
223
259
|
}
|
|
224
|
-
}),
|
|
260
|
+
}), c = A(() => {
|
|
225
261
|
}, []);
|
|
226
262
|
return {
|
|
227
263
|
createWallet: s,
|
|
228
|
-
importWallet:
|
|
264
|
+
importWallet: c
|
|
229
265
|
};
|
|
230
266
|
}
|
|
231
|
-
|
|
232
|
-
function L(e) {
|
|
267
|
+
function I(e) {
|
|
233
268
|
const { data: t } = p({
|
|
234
269
|
queryKey: ["ecency-wallets", "wallets", e]
|
|
235
|
-
}), { data: n } =
|
|
270
|
+
}), { data: n } = Q(e);
|
|
236
271
|
return m({
|
|
237
272
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
238
|
-
mutationFn: ({ currency:
|
|
273
|
+
mutationFn: ({ currency: a, address: s }) => fetch(d.privateApiHost + "/private-api/wallets-add", {
|
|
239
274
|
method: "POST",
|
|
240
275
|
headers: {
|
|
241
276
|
"Content-Type": "application/json"
|
|
242
277
|
},
|
|
243
278
|
body: JSON.stringify({
|
|
244
279
|
username: e,
|
|
245
|
-
token:
|
|
280
|
+
token: a,
|
|
246
281
|
address: s,
|
|
247
282
|
meta: {
|
|
248
283
|
ownerPublicKey: n == null ? void 0 : n.ownerPubkey,
|
|
@@ -250,9 +285,9 @@ function L(e) {
|
|
|
250
285
|
postingPublicKey: n == null ? void 0 : n.postingPubkey,
|
|
251
286
|
memoPublicKey: n == null ? void 0 : n.memoPubkey,
|
|
252
287
|
...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
|
|
253
|
-
(
|
|
254
|
-
...
|
|
255
|
-
[
|
|
288
|
+
(c, [r, i]) => ({
|
|
289
|
+
...c,
|
|
290
|
+
[r]: i.address
|
|
256
291
|
}),
|
|
257
292
|
{}
|
|
258
293
|
)
|
|
@@ -261,11 +296,11 @@ function L(e) {
|
|
|
261
296
|
})
|
|
262
297
|
});
|
|
263
298
|
}
|
|
264
|
-
function
|
|
299
|
+
function P() {
|
|
265
300
|
return m({
|
|
266
301
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
|
267
302
|
mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
|
|
268
|
-
|
|
303
|
+
d.privateApiHost + "/private-api/wallets-exist",
|
|
269
304
|
{
|
|
270
305
|
method: "POST",
|
|
271
306
|
headers: {
|
|
@@ -279,59 +314,59 @@ function T() {
|
|
|
279
314
|
)).json()).length === 0
|
|
280
315
|
});
|
|
281
316
|
}
|
|
282
|
-
const
|
|
317
|
+
const he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
283
318
|
__proto__: null,
|
|
284
|
-
useCheckWalletExistence:
|
|
285
|
-
useCreateAccountWithWallets:
|
|
286
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
319
|
+
useCheckWalletExistence: P,
|
|
320
|
+
useCreateAccountWithWallets: I
|
|
321
|
+
}, Symbol.toStringTag, { value: "Module" })), $ = {
|
|
287
322
|
[o.BTC]: ["m/84'/0'/0'/0/0"],
|
|
288
323
|
[o.ETH]: ["m/84'/60'/0'/0/0"],
|
|
289
324
|
// its not working for Trust, Exodus, todo: check others below
|
|
290
325
|
[o.SOL]: ["m/84'/501'/0'/0/0"],
|
|
291
|
-
[o.TRON]: ["m/
|
|
326
|
+
[o.TRON]: ["m/44'/195'/0'/0'/0'"],
|
|
292
327
|
[o.APT]: ["m/84'/637'/0'/0/0"],
|
|
293
328
|
[o.TON]: [],
|
|
294
329
|
// Disabled
|
|
295
330
|
[o.ATOM]: ["m/84'/118'/0'/0'/0"]
|
|
296
331
|
};
|
|
297
|
-
async function
|
|
298
|
-
for (const
|
|
332
|
+
async function G(e, t, n) {
|
|
333
|
+
for (const a of $[n] || [])
|
|
299
334
|
try {
|
|
300
335
|
const s = await t.getDerivedPrivateKey({
|
|
301
336
|
mnemonic: e,
|
|
302
|
-
hdPath:
|
|
303
|
-
}),
|
|
337
|
+
hdPath: a
|
|
338
|
+
}), c = await t.getNewAddress({
|
|
304
339
|
privateKey: s,
|
|
305
|
-
addressType: "segwit_native"
|
|
340
|
+
addressType: n === o.BTC ? "segwit_native" : void 0
|
|
306
341
|
});
|
|
307
|
-
return [s.toString(),
|
|
342
|
+
return [s.toString(), c.address];
|
|
308
343
|
} catch {
|
|
309
344
|
return [];
|
|
310
345
|
}
|
|
311
346
|
return [];
|
|
312
347
|
}
|
|
313
|
-
function
|
|
314
|
-
const n =
|
|
348
|
+
function Te(e, t) {
|
|
349
|
+
const n = h(), { mutateAsync: a } = P();
|
|
315
350
|
return m({
|
|
316
351
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
|
317
352
|
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
353
|
+
const c = T(t);
|
|
354
|
+
if (!c)
|
|
320
355
|
throw new Error("Cannot find token for this currency");
|
|
321
|
-
const
|
|
322
|
-
let
|
|
323
|
-
if (
|
|
356
|
+
const r = s.split(" ").length === 12;
|
|
357
|
+
let i, l = s;
|
|
358
|
+
if (r ? [l, i] = await G(
|
|
324
359
|
s,
|
|
325
|
-
|
|
360
|
+
c,
|
|
326
361
|
t
|
|
327
|
-
) :
|
|
362
|
+
) : i = (await c.getNewAddress({
|
|
328
363
|
privateKey: s
|
|
329
|
-
})).address, !
|
|
364
|
+
})).address, !i || !s)
|
|
330
365
|
throw new Error(
|
|
331
366
|
"Private key/seed phrase isn't matching with public key or token"
|
|
332
367
|
);
|
|
333
|
-
if (!await
|
|
334
|
-
address:
|
|
368
|
+
if (!await a({
|
|
369
|
+
address: i,
|
|
335
370
|
currency: t
|
|
336
371
|
}))
|
|
337
372
|
throw new Error(
|
|
@@ -339,17 +374,17 @@ function me(e, t) {
|
|
|
339
374
|
);
|
|
340
375
|
return {
|
|
341
376
|
privateKey: l,
|
|
342
|
-
address:
|
|
377
|
+
address: i,
|
|
343
378
|
publicKey: ""
|
|
344
379
|
};
|
|
345
380
|
},
|
|
346
|
-
onSuccess: ({ privateKey: s, publicKey:
|
|
381
|
+
onSuccess: ({ privateKey: s, publicKey: c, address: r }) => {
|
|
347
382
|
n.setQueryData(
|
|
348
383
|
["ecency-wallets", "wallets", e],
|
|
349
|
-
(
|
|
384
|
+
(i) => new Map(i ? Array.from(i.entries()) : []).set(t, {
|
|
350
385
|
privateKey: s,
|
|
351
|
-
publicKey:
|
|
352
|
-
address:
|
|
386
|
+
publicKey: c,
|
|
387
|
+
address: r,
|
|
353
388
|
username: e,
|
|
354
389
|
currency: t,
|
|
355
390
|
custom: !0
|
|
@@ -358,16 +393,35 @@ function me(e, t) {
|
|
|
358
393
|
}
|
|
359
394
|
});
|
|
360
395
|
}
|
|
396
|
+
function be(e) {
|
|
397
|
+
const { mutateAsync: t } = M(e);
|
|
398
|
+
return m({
|
|
399
|
+
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
|
|
400
|
+
mutationFn: ({
|
|
401
|
+
wallets: n
|
|
402
|
+
}) => t({
|
|
403
|
+
profile: {},
|
|
404
|
+
tokens: Array.from(n.entries() ?? []).map(([a, s]) => ({
|
|
405
|
+
symbol: a,
|
|
406
|
+
type: "CHAIN",
|
|
407
|
+
meta: {
|
|
408
|
+
address: s.address
|
|
409
|
+
}
|
|
410
|
+
}))
|
|
411
|
+
})
|
|
412
|
+
});
|
|
413
|
+
}
|
|
361
414
|
export {
|
|
415
|
+
u as EcencyWalletBasicTokens,
|
|
362
416
|
o as EcencyWalletCurrency,
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
417
|
+
he as EcencyWalletsPrivateApi,
|
|
418
|
+
de as getAccountPointsQueryOptions,
|
|
419
|
+
we as useCoinGeckoPriceQuery,
|
|
420
|
+
ye as useGetAllTokensListQuery,
|
|
421
|
+
me as useGetExternalWalletBalanceQuery,
|
|
422
|
+
Q as useHiveKeysQuery,
|
|
423
|
+
Te as useImportWallet,
|
|
424
|
+
be as useSaveWalletInformationToMetadata,
|
|
425
|
+
b as useSeedPhrase,
|
|
426
|
+
fe as useWalletCreate
|
|
373
427
|
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './modules/wallets';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-keys-from-seed';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EcencyWalletCurrency } from '../../enums';
|
|
2
|
+
interface Payload {
|
|
3
|
+
address: string;
|
|
4
|
+
currency: EcencyWalletCurrency;
|
|
5
|
+
}
|
|
6
|
+
export declare function useCheckWalletExistence(): import('@tanstack/react-query').UseMutationResult<boolean, Error, Payload, unknown>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EcencyWalletCurrency } from '../../enums';
|
|
2
|
+
interface Payload {
|
|
3
|
+
currency: EcencyWalletCurrency;
|
|
4
|
+
address: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function useCreateAccountWithWallets(username: string): import('@tanstack/react-query').UseMutationResult<Response, Error, Payload, unknown>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { EcencyWalletCurrency } from '../enums';
|
|
2
|
+
import { EcencyCreateWalletInformation } from '../types';
|
|
3
|
+
export declare function useSaveWalletInformationToMetadata(username: string): import('@tanstack/react-query').UseMutationResult<any, Error, {
|
|
4
|
+
wallets: Map<EcencyWalletCurrency, EcencyCreateWalletInformation>;
|
|
5
|
+
}, unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EcencyWalletCurrency } from '../enums';
|
|
2
|
+
interface Payload {
|
|
3
|
+
privateKeyOrSeed: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function useImportWallet(username: string, currency: EcencyWalletCurrency): import('@tanstack/react-query').UseMutationResult<{
|
|
6
|
+
privateKey: string;
|
|
7
|
+
address: any;
|
|
8
|
+
publicKey: string;
|
|
9
|
+
}, Error, Payload, unknown>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EcencyCreateWalletInformation } from '../types';
|
|
2
|
+
import { EcencyWalletCurrency } from '../enums';
|
|
3
|
+
export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
|
|
4
|
+
createWallet: import('@tanstack/react-query').UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
|
|
5
|
+
importWallet: () => void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccountPointsResponse } from '../types';
|
|
2
|
+
export declare function getAccountPointsQueryOptions(username?: string, filter?: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<AccountPointsResponse, Error, AccountPointsResponse, (string | undefined)[]>, "queryFn"> & {
|
|
3
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<AccountPointsResponse, (string | undefined)[], never> | undefined;
|
|
4
|
+
} & {
|
|
5
|
+
queryKey: (string | undefined)[] & {
|
|
6
|
+
[dataTagSymbol]: AccountPointsResponse;
|
|
7
|
+
[dataTagErrorSymbol]: Error;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './use-get-external-wallet-query';
|
|
2
|
+
export * from './use-seed-phrase';
|
|
3
|
+
export * from './use-coingecko-price-query';
|
|
4
|
+
export * from './use-hive-keys-query';
|
|
5
|
+
export * from './get-account-points-query-options';
|
|
6
|
+
export * from './use-get-all-tokens-list-query';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EcencyWalletBasicTokens } from '../enums';
|
|
2
|
+
export declare function getAccountWalletListQueryOptions(username: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<EcencyWalletBasicTokens[], Error, EcencyWalletBasicTokens[], string[]>, "queryFn"> & {
|
|
3
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<EcencyWalletBasicTokens[], string[], never> | undefined;
|
|
4
|
+
} & {
|
|
5
|
+
queryKey: string[] & {
|
|
6
|
+
[dataTagSymbol]: EcencyWalletBasicTokens[];
|
|
7
|
+
[dataTagErrorSymbol]: Error;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EcencyWalletCurrency } from '../enums';
|
|
2
|
+
/**
|
|
3
|
+
* Returns information about the actual balance of the given currency address
|
|
4
|
+
* using various of public APIs
|
|
5
|
+
* todo extract URLs to configs
|
|
6
|
+
* @param currency
|
|
7
|
+
* @param address
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function useGetExternalWalletBalanceQuery(currency: EcencyWalletCurrency, address: string): import('@tanstack/react-query').UseQueryResult<number, Error>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useSeedPhrase(username: string): import('@tanstack/react-query').UseQueryResult<string, Error>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function delay(ms: number): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mnemonicToSeedBip39(value: string): string;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecency/wallets",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/ecency-sdk.umd.js",
|
|
8
|
+
"module": "./dist/ecency-sdk.es.js",
|
|
9
|
+
"typings": "./dist/index.d.ts",
|
|
9
10
|
"files": [
|
|
10
11
|
"dist",
|
|
11
12
|
"README.md"
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@hiveio/dhive": "^1.3.2",
|
|
20
|
-
"@tanstack/react-query": "^5.
|
|
21
|
+
"@tanstack/react-query": "^5.74.4",
|
|
21
22
|
"@types/node": "^22.13.8",
|
|
22
23
|
"@types/react": "^19.0.10",
|
|
23
24
|
"@vitejs/plugin-react": "^4.3.4",
|
|
@@ -25,12 +26,12 @@
|
|
|
25
26
|
"lru-cache": "^11.0.2",
|
|
26
27
|
"prettier": "^3.5.2",
|
|
27
28
|
"react": "^19.0.0",
|
|
28
|
-
"typescript": "~5.7.2",
|
|
29
29
|
"vite": "^6.2.0",
|
|
30
|
-
"vite-plugin-dts": "
|
|
30
|
+
"vite-plugin-dts": "4.5.3",
|
|
31
31
|
"vite-plugin-node-polyfills": "^0.23.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@ecency/sdk": "./packages/core",
|
|
34
35
|
"@okxweb3/coin-aptos": "^1.2.0",
|
|
35
36
|
"@okxweb3/coin-base": "^1.1.2",
|
|
36
37
|
"@okxweb3/coin-bitcoin": "^1.2.0",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"@okxweb3/coin-ton": "^1.1.1-beta.1",
|
|
41
42
|
"@okxweb3/coin-tron": "^1.1.0",
|
|
42
43
|
"@okxweb3/crypto-lib": "^1.0.10",
|
|
43
|
-
"bip39": "^3.1.0"
|
|
44
|
+
"bip39": "^3.1.0",
|
|
45
|
+
"hivesigner": "3.3.4"
|
|
44
46
|
}
|
|
45
47
|
}
|
package/Readme.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Ecency wallets – manage Hive account and attach external wallets to it in Ecency system
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@ecency/wallets) [](https://standardjs.com)
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
`@ecency/wallets` provides an API for managing Hive blockchain wallets and external cryptocurrency wallets within the Ecency ecosystem.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
yarn add @ecency/wallets
|
|
13
|
-
# or
|
|
14
|
-
npm install @ecency/wallets
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Setup
|
|
18
|
-
|
|
19
|
-
1. Install `react @tanstack/react-query @hiveio/dhive`
|
|
20
|
-
2. Use!
|
|
21
|
-
|
|
22
|
-
## Features
|
|
23
|
-
|
|
24
|
-
This package built on top of [@hiveio/dhive](https://www.npmjs.com/package/@hiveio/dhive) and [okweb3](http://okx.github.io/) packages.
|
|
25
|
-
|
|
26
|
-
Main functionality is creating wallets based on seed phrase([BIP39](https://www.npmjs.com/package/bip39)) and generating addresses with keys on device. Seed phrases and private keys are never sent to any API, all operations happen locally.
|
|
27
|
-
|
|
28
|
-
Supportings tokens: BTC, ETH, SOL, TRX, TON, ATOM, APT – theoretically all child tokens of these systems. Make forks for it.
|
|
29
|
-
|
|
30
|
-
## Roadmap
|
|
31
|
-
|
|
32
|
-
- Add more Hive wallets operations
|
|
33
|
-
- Allow to sign transactions with external wallets
|
|
34
|
-
- Allow to import existing wallets by phrase or private keys
|
|
35
|
-
- Support of DASH
|
|
36
|
-
- Support of DOGE
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { BaseWallet } from '@okxweb3/coin-base';
|
|
2
|
-
import { UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { UseQueryResult } from '@tanstack/react-query';
|
|
4
|
-
|
|
5
|
-
export declare function delay(ms: number): Promise<unknown>;
|
|
6
|
-
|
|
7
|
-
export declare interface EcencyCreateWalletInformation {
|
|
8
|
-
address: string;
|
|
9
|
-
privateKey: string;
|
|
10
|
-
publicKey: string;
|
|
11
|
-
username: string;
|
|
12
|
-
currency: EcencyWalletCurrency;
|
|
13
|
-
custom?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export declare interface EcencyHiveKeys {
|
|
17
|
-
username: string;
|
|
18
|
-
owner: string;
|
|
19
|
-
active: string;
|
|
20
|
-
posting: string;
|
|
21
|
-
memo: string;
|
|
22
|
-
masterPassword: string;
|
|
23
|
-
ownerPubkey: string;
|
|
24
|
-
activePubkey: string;
|
|
25
|
-
postingPubkey: string;
|
|
26
|
-
memoPubkey: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export declare enum EcencyWalletCurrency {
|
|
30
|
-
BTC = "btc",
|
|
31
|
-
ETH = "eth",
|
|
32
|
-
APT = "aptos",
|
|
33
|
-
ATOM = "cosmos",
|
|
34
|
-
TON = "ton",
|
|
35
|
-
TRON = "tron",
|
|
36
|
-
SOL = "solana"
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare namespace EcencyWalletsPrivateApi {
|
|
40
|
-
export {
|
|
41
|
-
useCreateAccountWithWallets,
|
|
42
|
-
useCheckWalletExistence
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export { EcencyWalletsPrivateApi }
|
|
46
|
-
|
|
47
|
-
export declare function getWallet(currency: EcencyWalletCurrency): BaseWallet | undefined;
|
|
48
|
-
|
|
49
|
-
export declare function mnemonicToSeedBip39(value: string): string;
|
|
50
|
-
|
|
51
|
-
declare interface Payload {
|
|
52
|
-
currency: EcencyWalletCurrency;
|
|
53
|
-
address: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare interface Payload_2 {
|
|
57
|
-
address: string;
|
|
58
|
-
currency: EcencyWalletCurrency;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
declare interface Payload_3 {
|
|
62
|
-
address: string;
|
|
63
|
-
privateKeyOrSeed: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declare function useCheckWalletExistence(): UseMutationResult<boolean, Error, Payload_2, unknown>;
|
|
67
|
-
|
|
68
|
-
export declare function useCoinGeckoPriceQuery(currency?: EcencyWalletCurrency): UseQueryResult<number, Error>;
|
|
69
|
-
|
|
70
|
-
declare function useCreateAccountWithWallets(username: string): UseMutationResult<Response, Error, Payload, unknown>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns information about the actual balance of the given currency address
|
|
74
|
-
* using various of public APIs
|
|
75
|
-
* todo extract URLs to configs
|
|
76
|
-
* @param currency
|
|
77
|
-
* @param address
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
export declare function useGetExternalWalletBalanceQuery(currency: EcencyWalletCurrency, address: string): UseQueryResult<number, Error>;
|
|
81
|
-
|
|
82
|
-
export declare function useHiveKeysQuery(username: string): UseQueryResult<EcencyHiveKeys, Error>;
|
|
83
|
-
|
|
84
|
-
export declare function useImportWallet(username: string, currency: EcencyWalletCurrency): UseMutationResult< {
|
|
85
|
-
privateKey: string;
|
|
86
|
-
address: any;
|
|
87
|
-
publicKey: string;
|
|
88
|
-
}, Error, Payload_3, unknown>;
|
|
89
|
-
|
|
90
|
-
export declare function useSeedPhrase(username: string): UseQueryResult<string, Error>;
|
|
91
|
-
|
|
92
|
-
export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
|
|
93
|
-
createWallet: UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
|
|
94
|
-
importWallet: () => void;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export { }
|