@ecency/sdk 1.0.9 → 1.0.11
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-sdk.es.d.ts +1 -1
- package/dist/ecency-sdk.es.js +77 -69
- package/package.json +1 -1
package/dist/ecency-sdk.es.d.ts
CHANGED
@@ -95,7 +95,7 @@ wallets: Map<EcencyWalletCurrency, EcencyCreateWalletInformation>;
|
|
95
95
|
|
96
96
|
export declare function useSeedPhrase(username: string): UseQueryResult<string, Error>;
|
97
97
|
|
98
|
-
export declare function useSignOperation(username: string): UseMutationResult<any, Error, Operation, unknown>;
|
98
|
+
export declare function useSignOperation(username: string | undefined): UseMutationResult<any, Error, Operation, unknown>;
|
99
99
|
|
100
100
|
export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
|
101
101
|
createWallet: UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
|
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
import { useCallback as O } from "react";
|
2
|
-
import { useQuery as
|
2
|
+
import { useQuery as m, useQueryClient as f, useMutation as u } from "@tanstack/react-query";
|
3
3
|
import { BtcWallet as A } from "@okxweb3/coin-bitcoin";
|
4
4
|
import { EthWallet as R } from "@okxweb3/coin-ethereum";
|
5
5
|
import { TrxWallet as K } from "@okxweb3/coin-tron";
|
6
|
-
import { TonWallet as
|
7
|
-
import { SolWallet as
|
6
|
+
import { TonWallet as C } from "@okxweb3/coin-ton";
|
7
|
+
import { SolWallet as N } from "@okxweb3/coin-solana";
|
8
8
|
import { AtomWallet as x } from "@okxweb3/coin-cosmos";
|
9
|
-
import { AptosWallet as
|
10
|
-
import
|
11
|
-
import {
|
12
|
-
import {
|
13
|
-
import
|
9
|
+
import { AptosWallet as j } from "@okxweb3/coin-aptos";
|
10
|
+
import D, { mnemonicToSeedSync as _ } from "bip39";
|
11
|
+
import { Client as H, PrivateKey as d } from "@hiveio/dhive";
|
12
|
+
import { LRUCache as E } from "lru-cache";
|
13
|
+
import B from "hivesigner";
|
14
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 || {});
|
15
|
-
function
|
15
|
+
function W(e) {
|
16
16
|
return new Promise((t) => setTimeout(t, e));
|
17
17
|
}
|
18
18
|
function g(e) {
|
@@ -24,22 +24,48 @@ function g(e) {
|
|
24
24
|
case o.TRON:
|
25
25
|
return new K();
|
26
26
|
case o.TON:
|
27
|
-
return new N();
|
28
|
-
case o.SOL:
|
29
27
|
return new C();
|
28
|
+
case o.SOL:
|
29
|
+
return new N();
|
30
30
|
case o.ATOM:
|
31
31
|
return new x();
|
32
32
|
case o.APT:
|
33
|
-
return new
|
33
|
+
return new j();
|
34
34
|
default:
|
35
35
|
return;
|
36
36
|
}
|
37
37
|
}
|
38
38
|
function ye(e) {
|
39
|
-
return
|
39
|
+
return _(e).toString("hex");
|
40
40
|
}
|
41
|
+
const p = {
|
42
|
+
privateApiHost: "https://ecency.com",
|
43
|
+
storage: localStorage,
|
44
|
+
storagePrefix: "ecency",
|
45
|
+
hiveClient: new H(
|
46
|
+
[
|
47
|
+
"https://api.hive.blog",
|
48
|
+
"https://api.deathwing.me",
|
49
|
+
"https://rpc.mahdiyari.info",
|
50
|
+
"https://api.openhive.network",
|
51
|
+
"https://techcoderx.com",
|
52
|
+
"https://hive-api.arcange.eu",
|
53
|
+
"https://api.syncad.com",
|
54
|
+
"https://anyx.io",
|
55
|
+
"https://api.c0ff33a.uk",
|
56
|
+
"https://hiveapi.actifit.io",
|
57
|
+
"https://hive-api.3speak.tv"
|
58
|
+
],
|
59
|
+
{
|
60
|
+
timeout: 2e3,
|
61
|
+
failoverThreshold: 2,
|
62
|
+
consoleOnFailover: !0
|
63
|
+
}
|
64
|
+
),
|
65
|
+
heliusApiKey: void 0
|
66
|
+
};
|
41
67
|
function fe(e, t) {
|
42
|
-
return
|
68
|
+
return m({
|
43
69
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
44
70
|
queryFn: async () => {
|
45
71
|
switch (e) {
|
@@ -54,7 +80,7 @@ function fe(e, t) {
|
|
54
80
|
)).json()).ETH.balance;
|
55
81
|
case o.SOL:
|
56
82
|
return (await (await fetch(
|
57
|
-
|
83
|
+
`https://rpc.helius.xyz/?api-key=${p.heliusApiKey}`,
|
58
84
|
{
|
59
85
|
method: "POST",
|
60
86
|
body: JSON.stringify({
|
@@ -62,7 +88,10 @@ function fe(e, t) {
|
|
62
88
|
id: "1",
|
63
89
|
method: "getBalance",
|
64
90
|
params: [t]
|
65
|
-
})
|
91
|
+
}),
|
92
|
+
headers: {
|
93
|
+
"Content-Type": "application/json"
|
94
|
+
}
|
66
95
|
}
|
67
96
|
)).json()).result.value / 1e9;
|
68
97
|
case o.TRON:
|
@@ -89,9 +118,9 @@ function fe(e, t) {
|
|
89
118
|
});
|
90
119
|
}
|
91
120
|
function T(e) {
|
92
|
-
return
|
121
|
+
return m({
|
93
122
|
queryKey: ["ecency-wallets", "seed", e],
|
94
|
-
queryFn: async () =>
|
123
|
+
queryFn: async () => D.generateMnemonic(128)
|
95
124
|
});
|
96
125
|
}
|
97
126
|
const F = {
|
@@ -102,12 +131,12 @@ const F = {
|
|
102
131
|
allowStale: !1,
|
103
132
|
updateAgeOnGet: !1,
|
104
133
|
updateAgeOnHas: !1
|
105
|
-
}, b = new
|
134
|
+
}, b = new E(F), w = Symbol("undefined"), M = (e, t) => b.set(e, t === void 0 ? w : t), L = (e) => {
|
106
135
|
const t = b.get(e);
|
107
136
|
return t === w ? void 0 : t;
|
108
137
|
};
|
109
138
|
function ge(e) {
|
110
|
-
return
|
139
|
+
return m({
|
111
140
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
112
141
|
queryFn: async () => {
|
113
142
|
let t = e;
|
@@ -152,12 +181,12 @@ function ge(e) {
|
|
152
181
|
}
|
153
182
|
function q(e) {
|
154
183
|
const { data: t } = T(e);
|
155
|
-
return
|
184
|
+
return m({
|
156
185
|
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
157
186
|
queryFn: async () => {
|
158
187
|
if (!t)
|
159
188
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
160
|
-
const n =
|
189
|
+
const n = d.fromLogin(e, t, "owner"), s = d.fromLogin(e, t, "active"), a = d.fromLogin(e, t, "posting"), i = d.fromLogin(e, t, "memo");
|
161
190
|
return {
|
162
191
|
username: e,
|
163
192
|
owner: n.toString(),
|
@@ -172,7 +201,7 @@ function q(e) {
|
|
172
201
|
}
|
173
202
|
});
|
174
203
|
}
|
175
|
-
const
|
204
|
+
const I = {
|
176
205
|
[o.BTC]: "m/44'/0'/0'/0/0",
|
177
206
|
// Bitcoin (BIP44)
|
178
207
|
[o.ETH]: "m/44'/60'/0'/0/0",
|
@@ -189,16 +218,16 @@ const J = {
|
|
189
218
|
// Cosmos (BIP44)
|
190
219
|
};
|
191
220
|
function Te(e, t) {
|
192
|
-
const { data: n } = T(e), s = f(), a =
|
221
|
+
const { data: n } = T(e), s = f(), a = u({
|
193
222
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
194
223
|
mutationFn: async () => {
|
195
224
|
if (!n)
|
196
225
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
197
226
|
const r = g(t), c = await (r == null ? void 0 : r.getDerivedPrivateKey({
|
198
227
|
mnemonic: n,
|
199
|
-
hdPath:
|
228
|
+
hdPath: I[t]
|
200
229
|
}));
|
201
|
-
await
|
230
|
+
await W(1e3);
|
202
231
|
const l = await (r == null ? void 0 : r.getNewAddress({
|
203
232
|
privateKey: c
|
204
233
|
}));
|
@@ -223,38 +252,13 @@ function Te(e, t) {
|
|
223
252
|
importWallet: i
|
224
253
|
};
|
225
254
|
}
|
226
|
-
|
227
|
-
|
228
|
-
storage: localStorage,
|
229
|
-
storagePrefix: "ecency",
|
230
|
-
hiveClient: new E(
|
231
|
-
[
|
232
|
-
"https://api.hive.blog",
|
233
|
-
"https://api.deathwing.me",
|
234
|
-
"https://rpc.mahdiyari.info",
|
235
|
-
"https://api.openhive.network",
|
236
|
-
"https://techcoderx.com",
|
237
|
-
"https://hive-api.arcange.eu",
|
238
|
-
"https://api.syncad.com",
|
239
|
-
"https://anyx.io",
|
240
|
-
"https://api.c0ff33a.uk",
|
241
|
-
"https://hiveapi.actifit.io",
|
242
|
-
"https://hive-api.3speak.tv"
|
243
|
-
],
|
244
|
-
{
|
245
|
-
timeout: 2e3,
|
246
|
-
failoverThreshold: 2,
|
247
|
-
consoleOnFailover: !0
|
248
|
-
}
|
249
|
-
)
|
250
|
-
};
|
251
|
-
function Q(e) {
|
252
|
-
const { data: t } = d({
|
255
|
+
function J(e) {
|
256
|
+
const { data: t } = m({
|
253
257
|
queryKey: ["ecency-wallets", "wallets", e]
|
254
258
|
}), { data: n } = q(e);
|
255
|
-
return
|
259
|
+
return u({
|
256
260
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
257
|
-
mutationFn: ({ currency: s, address: a }) => fetch(
|
261
|
+
mutationFn: ({ currency: s, address: a }) => fetch(p.privateApiHost + "/private-api/wallets-add", {
|
258
262
|
method: "POST",
|
259
263
|
headers: {
|
260
264
|
"Content-Type": "application/json"
|
@@ -281,10 +285,10 @@ function Q(e) {
|
|
281
285
|
});
|
282
286
|
}
|
283
287
|
function v() {
|
284
|
-
return
|
288
|
+
return u({
|
285
289
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
286
290
|
mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
|
287
|
-
|
291
|
+
p.privateApiHost + "/private-api/wallets-exist",
|
288
292
|
{
|
289
293
|
method: "POST",
|
290
294
|
headers: {
|
@@ -301,8 +305,8 @@ function v() {
|
|
301
305
|
const be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
302
306
|
__proto__: null,
|
303
307
|
useCheckWalletExistence: v,
|
304
|
-
useCreateAccountWithWallets:
|
305
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
308
|
+
useCreateAccountWithWallets: J
|
309
|
+
}, Symbol.toStringTag, { value: "Module" })), Q = {
|
306
310
|
[o.BTC]: ["m/84'/0'/0'/0/0"],
|
307
311
|
[o.ETH]: ["m/84'/60'/0'/0/0"],
|
308
312
|
// its not working for Trust, Exodus, todo: check others below
|
@@ -314,7 +318,7 @@ const be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
314
318
|
[o.ATOM]: ["m/84'/118'/0'/0'/0"]
|
315
319
|
};
|
316
320
|
async function $(e, t, n) {
|
317
|
-
for (const s of
|
321
|
+
for (const s of Q[n] || [])
|
318
322
|
try {
|
319
323
|
const a = await t.getDerivedPrivateKey({
|
320
324
|
mnemonic: e,
|
@@ -331,7 +335,7 @@ async function $(e, t, n) {
|
|
331
335
|
}
|
332
336
|
function ve(e, t) {
|
333
337
|
const n = f(), { mutateAsync: s } = v();
|
334
|
-
return
|
338
|
+
return u({
|
335
339
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
336
340
|
mutationFn: async ({ privateKeyOrSeed: a }) => {
|
337
341
|
const i = g(t);
|
@@ -384,8 +388,8 @@ function G(e) {
|
|
384
388
|
}
|
385
389
|
const h = (e) => {
|
386
390
|
try {
|
387
|
-
const t =
|
388
|
-
|
391
|
+
const t = p.storage.getItem(
|
392
|
+
p.storagePrefix + "_user_" + e
|
389
393
|
);
|
390
394
|
return G(JSON.parse(t));
|
391
395
|
} catch (t) {
|
@@ -394,20 +398,24 @@ const h = (e) => {
|
|
394
398
|
}
|
395
399
|
}, U = (e) => h(e) && h(e).accessToken, V = (e) => h(e) && h(e).postingKey;
|
396
400
|
function P(e = [], t, n) {
|
397
|
-
return
|
401
|
+
return u({
|
398
402
|
mutationKey: [...e, t],
|
399
403
|
mutationFn: async (s) => {
|
404
|
+
if (!t)
|
405
|
+
throw new Error(
|
406
|
+
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
407
|
+
);
|
400
408
|
const a = V(t);
|
401
409
|
if (a) {
|
402
|
-
const r =
|
403
|
-
return
|
410
|
+
const r = d.fromString(a);
|
411
|
+
return p.hiveClient.broadcast.sendOperations(
|
404
412
|
n(s),
|
405
413
|
r
|
406
414
|
);
|
407
415
|
}
|
408
416
|
let i = U(t);
|
409
417
|
if (i)
|
410
|
-
return (await new
|
418
|
+
return (await new B.Client({
|
411
419
|
accessToken: i
|
412
420
|
}).broadcast(n(s))).result;
|
413
421
|
throw new Error(
|
@@ -437,7 +445,7 @@ function z(e) {
|
|
437
445
|
}
|
438
446
|
function Pe(e) {
|
439
447
|
const { mutateAsync: t } = z(e);
|
440
|
-
return
|
448
|
+
return u({
|
441
449
|
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
|
442
450
|
mutationFn: ({
|
443
451
|
wallets: n
|
@@ -462,7 +470,7 @@ function Se(e) {
|
|
462
470
|
export {
|
463
471
|
o as EcencyWalletCurrency,
|
464
472
|
be as EcencyWalletsPrivateApi,
|
465
|
-
|
473
|
+
W as delay,
|
466
474
|
g as getWallet,
|
467
475
|
ye as mnemonicToSeedBip39,
|
468
476
|
z as useAccountUpdate,
|