@ecency/sdk 1.0.20 → 1.0.21
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.js
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
import { useCallback as
|
2
|
-
import { useQuery as m, queryOptions 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 { Client as
|
12
|
-
import { LRUCache as
|
13
|
-
import
|
1
|
+
import { useMemo as K, useCallback as R } from "react";
|
2
|
+
import { useQuery as m, queryOptions as g, useQueryClient as v, useMutation as u } from "@tanstack/react-query";
|
3
|
+
import { BtcWallet as C } from "@okxweb3/coin-bitcoin";
|
4
|
+
import { EthWallet as H } from "@okxweb3/coin-ethereum";
|
5
|
+
import { TrxWallet as N } from "@okxweb3/coin-tron";
|
6
|
+
import { TonWallet as j } from "@okxweb3/coin-ton";
|
7
|
+
import { SolWallet as D } from "@okxweb3/coin-solana";
|
8
|
+
import { AtomWallet as x } from "@okxweb3/coin-cosmos";
|
9
|
+
import { AptosWallet as L } from "@okxweb3/coin-aptos";
|
10
|
+
import _, { mnemonicToSeedSync as F } from "bip39";
|
11
|
+
import { Client as B, PrivateKey as l, cryptoUtils as E } from "@hiveio/dhive";
|
12
|
+
import { LRUCache as q } from "lru-cache";
|
13
|
+
import b from "hivesigner";
|
14
14
|
var a = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(a || {}), h = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(h || {});
|
15
|
-
function
|
15
|
+
function M(e) {
|
16
16
|
return new Promise((t) => setTimeout(t, e));
|
17
17
|
}
|
18
|
-
function
|
18
|
+
function T(e) {
|
19
19
|
switch (e) {
|
20
20
|
case a.BTC:
|
21
|
-
return new R();
|
22
|
-
case a.ETH:
|
23
21
|
return new C();
|
24
|
-
case a.
|
22
|
+
case a.ETH:
|
25
23
|
return new H();
|
26
|
-
case a.
|
24
|
+
case a.TRON:
|
27
25
|
return new N();
|
28
|
-
case a.
|
26
|
+
case a.TON:
|
29
27
|
return new j();
|
30
|
-
case a.
|
28
|
+
case a.SOL:
|
31
29
|
return new D();
|
32
|
-
case a.
|
30
|
+
case a.ATOM:
|
33
31
|
return new x();
|
32
|
+
case a.APT:
|
33
|
+
return new L();
|
34
34
|
default:
|
35
35
|
return;
|
36
36
|
}
|
37
37
|
}
|
38
|
-
function
|
39
|
-
return
|
38
|
+
function Pe(e) {
|
39
|
+
return F(e).toString("hex");
|
40
40
|
}
|
41
41
|
const p = {
|
42
42
|
privateApiHost: "https://ecency.com",
|
43
43
|
storage: localStorage,
|
44
44
|
storagePrefix: "ecency",
|
45
|
-
hiveClient: new
|
45
|
+
hiveClient: new B(
|
46
46
|
[
|
47
47
|
"https://api.hive.blog",
|
48
48
|
"https://api.deathwing.me",
|
@@ -64,7 +64,7 @@ const p = {
|
|
64
64
|
),
|
65
65
|
heliusApiKey: "fb1e2935-f911-4b1d-8e1c-3863f6879d42"
|
66
66
|
};
|
67
|
-
function
|
67
|
+
function Se(e, t) {
|
68
68
|
return m({
|
69
69
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
70
70
|
queryFn: async () => {
|
@@ -106,7 +106,7 @@ function Pe(e, t) {
|
|
106
106
|
const f = (await (await fetch(
|
107
107
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
108
108
|
)).json()).find(
|
109
|
-
(
|
109
|
+
(k) => k.type.includes("coin::CoinStore")
|
110
110
|
);
|
111
111
|
return f ? parseInt(f.data.coin.value) / 1e8 : 0;
|
112
112
|
case a.ATOM:
|
@@ -117,13 +117,13 @@ function Pe(e, t) {
|
|
117
117
|
}
|
118
118
|
});
|
119
119
|
}
|
120
|
-
function
|
120
|
+
function P(e) {
|
121
121
|
return m({
|
122
122
|
queryKey: ["ecency-wallets", "seed", e],
|
123
|
-
queryFn: async () =>
|
123
|
+
queryFn: async () => _.generateMnemonic(128)
|
124
124
|
});
|
125
125
|
}
|
126
|
-
const
|
126
|
+
const W = {
|
127
127
|
max: 500,
|
128
128
|
// how long to live in ms
|
129
129
|
ttl: 1e3 * 60 * 5,
|
@@ -131,11 +131,11 @@ const M = {
|
|
131
131
|
allowStale: !1,
|
132
132
|
updateAgeOnGet: !1,
|
133
133
|
updateAgeOnHas: !1
|
134
|
-
},
|
135
|
-
const t =
|
134
|
+
}, S = new q(W), y = Symbol("undefined"), Q = (e, t) => S.set(e, t === void 0 ? y : t), I = (e) => {
|
135
|
+
const t = S.get(e);
|
136
136
|
return t === y ? void 0 : t;
|
137
137
|
};
|
138
|
-
function
|
138
|
+
function Oe(e) {
|
139
139
|
return m({
|
140
140
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
141
141
|
queryFn: async () => {
|
@@ -156,7 +156,7 @@ function Se(e) {
|
|
156
156
|
default:
|
157
157
|
t = e;
|
158
158
|
}
|
159
|
-
let n =
|
159
|
+
let n = I("gecko"), o;
|
160
160
|
if (n)
|
161
161
|
o = n;
|
162
162
|
else {
|
@@ -172,15 +172,15 @@ function Se(e) {
|
|
172
172
|
})
|
173
173
|
}
|
174
174
|
)).json();
|
175
|
-
|
175
|
+
Q("gecko", i === void 0 ? y : i), o = i;
|
176
176
|
}
|
177
177
|
return 1 / +o[Object.keys(o)[0]].usd;
|
178
178
|
},
|
179
179
|
enabled: !!e
|
180
180
|
});
|
181
181
|
}
|
182
|
-
function
|
183
|
-
const { data: t } =
|
182
|
+
function J(e) {
|
183
|
+
const { data: t } = P(e);
|
184
184
|
return m({
|
185
185
|
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
186
186
|
queryFn: async () => {
|
@@ -201,8 +201,8 @@ function I(e) {
|
|
201
201
|
}
|
202
202
|
});
|
203
203
|
}
|
204
|
-
function
|
205
|
-
return
|
204
|
+
function Ae(e, t) {
|
205
|
+
return g({
|
206
206
|
queryKey: ["ecency-wallets", "points", e, t],
|
207
207
|
queryFn: async () => await (await fetch(
|
208
208
|
`${p.privateApiHost}/private-api/points`,
|
@@ -218,8 +218,8 @@ function Oe(e, t) {
|
|
218
218
|
enabled: !!e
|
219
219
|
});
|
220
220
|
}
|
221
|
-
function
|
222
|
-
return
|
221
|
+
function $(e, t) {
|
222
|
+
return g({
|
223
223
|
queryKey: ["hive-engine", "tokens-list", e, t],
|
224
224
|
queryFn: async () => (await (await fetch(
|
225
225
|
`${p.privateApiHost}/private-api/engine-api`,
|
@@ -243,9 +243,9 @@ function J(e, t) {
|
|
243
243
|
)).json()).result
|
244
244
|
});
|
245
245
|
}
|
246
|
-
function
|
247
|
-
const { data: t } = m(
|
248
|
-
return
|
246
|
+
function ke(e) {
|
247
|
+
const { data: t } = m($());
|
248
|
+
return K(
|
249
249
|
() => {
|
250
250
|
var n;
|
251
251
|
return {
|
@@ -267,7 +267,7 @@ function Ae(e) {
|
|
267
267
|
[t, e]
|
268
268
|
);
|
269
269
|
}
|
270
|
-
const
|
270
|
+
const G = {
|
271
271
|
[a.BTC]: "m/44'/0'/0'/0/0",
|
272
272
|
// Bitcoin (BIP44)
|
273
273
|
[a.ETH]: "m/44'/60'/0'/0/0",
|
@@ -283,17 +283,17 @@ const $ = {
|
|
283
283
|
[a.ATOM]: "m/44'/118'/0'/0/0"
|
284
284
|
// Cosmos (BIP44)
|
285
285
|
};
|
286
|
-
function
|
287
|
-
const { data: n } =
|
286
|
+
function Ke(e, t) {
|
287
|
+
const { data: n } = P(e), o = v(), s = u({
|
288
288
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
289
289
|
mutationFn: async () => {
|
290
290
|
if (!n)
|
291
291
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
292
|
-
const i =
|
292
|
+
const i = T(t), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
|
293
293
|
mnemonic: n,
|
294
|
-
hdPath:
|
294
|
+
hdPath: G[t]
|
295
295
|
}));
|
296
|
-
await
|
296
|
+
await M(1e3);
|
297
297
|
const d = await (i == null ? void 0 : i.getNewAddress({
|
298
298
|
privateKey: c
|
299
299
|
}));
|
@@ -311,17 +311,17 @@ function ke(e, t) {
|
|
311
311
|
(c) => new Map(c ? Array.from(c.entries()) : []).set(i.currency, i)
|
312
312
|
);
|
313
313
|
}
|
314
|
-
}), r =
|
314
|
+
}), r = R(() => {
|
315
315
|
}, []);
|
316
316
|
return {
|
317
317
|
createWallet: s,
|
318
318
|
importWallet: r
|
319
319
|
};
|
320
320
|
}
|
321
|
-
function
|
321
|
+
function V(e) {
|
322
322
|
const { data: t } = m({
|
323
323
|
queryKey: ["ecency-wallets", "wallets", e]
|
324
|
-
}), { data: n } =
|
324
|
+
}), { data: n } = J(e);
|
325
325
|
return u({
|
326
326
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
327
327
|
mutationFn: ({ currency: o, address: s }) => fetch(p.privateApiHost + "/private-api/wallets-add", {
|
@@ -350,7 +350,7 @@ function G(e) {
|
|
350
350
|
})
|
351
351
|
});
|
352
352
|
}
|
353
|
-
function
|
353
|
+
function O() {
|
354
354
|
return u({
|
355
355
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
356
356
|
mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
|
@@ -368,11 +368,11 @@ function A() {
|
|
368
368
|
)).json()).length === 0
|
369
369
|
});
|
370
370
|
}
|
371
|
-
const
|
371
|
+
const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
372
372
|
__proto__: null,
|
373
|
-
useCheckWalletExistence:
|
374
|
-
useCreateAccountWithWallets:
|
375
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
373
|
+
useCheckWalletExistence: O,
|
374
|
+
useCreateAccountWithWallets: V
|
375
|
+
}, Symbol.toStringTag, { value: "Module" })), U = {
|
376
376
|
[a.BTC]: ["m/84'/0'/0'/0/0"],
|
377
377
|
[a.ETH]: ["m/84'/60'/0'/0/0"],
|
378
378
|
// its not working for Trust, Exodus, todo: check others below
|
@@ -383,8 +383,8 @@ const Ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
383
383
|
// Disabled
|
384
384
|
[a.ATOM]: ["m/84'/118'/0'/0'/0"]
|
385
385
|
};
|
386
|
-
async function
|
387
|
-
for (const o of
|
386
|
+
async function z(e, t, n) {
|
387
|
+
for (const o of U[n] || [])
|
388
388
|
try {
|
389
389
|
const s = await t.getDerivedPrivateKey({
|
390
390
|
mnemonic: e,
|
@@ -399,17 +399,17 @@ async function U(e, t, n) {
|
|
399
399
|
}
|
400
400
|
return [];
|
401
401
|
}
|
402
|
-
function
|
403
|
-
const n =
|
402
|
+
function Ce(e, t) {
|
403
|
+
const n = v(), { mutateAsync: o } = O();
|
404
404
|
return u({
|
405
405
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
406
406
|
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
407
|
-
const r =
|
407
|
+
const r = T(t);
|
408
408
|
if (!r)
|
409
409
|
throw new Error("Cannot find token for this currency");
|
410
410
|
const i = s.split(" ").length === 12;
|
411
411
|
let c, d = s;
|
412
|
-
if (i ? [d, c] = await
|
412
|
+
if (i ? [d, c] = await z(
|
413
413
|
s,
|
414
414
|
r,
|
415
415
|
t
|
@@ -447,7 +447,7 @@ function Re(e, t) {
|
|
447
447
|
}
|
448
448
|
});
|
449
449
|
}
|
450
|
-
function
|
450
|
+
function X(e) {
|
451
451
|
let t = atob(e);
|
452
452
|
if (t[0] === "{")
|
453
453
|
return JSON.parse(t);
|
@@ -457,13 +457,13 @@ const w = (e) => {
|
|
457
457
|
const t = p.storage.getItem(
|
458
458
|
p.storagePrefix + "_user_" + e
|
459
459
|
);
|
460
|
-
return
|
460
|
+
return X(JSON.parse(t));
|
461
461
|
} catch (t) {
|
462
462
|
console.error(t);
|
463
463
|
return;
|
464
464
|
}
|
465
|
-
},
|
466
|
-
function
|
465
|
+
}, Y = (e) => w(e) && w(e).accessToken, Z = (e) => w(e) && w(e).postingKey;
|
466
|
+
function ee(e = [], t, n) {
|
467
467
|
return u({
|
468
468
|
mutationKey: [...e, t],
|
469
469
|
mutationFn: async (o) => {
|
@@ -471,7 +471,7 @@ function Z(e = [], t, n) {
|
|
471
471
|
throw new Error(
|
472
472
|
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
473
473
|
);
|
474
|
-
const s =
|
474
|
+
const s = Z(t);
|
475
475
|
if (s) {
|
476
476
|
const i = l.fromString(s);
|
477
477
|
return p.hiveClient.broadcast.sendOperations(
|
@@ -479,9 +479,9 @@ function Z(e = [], t, n) {
|
|
479
479
|
i
|
480
480
|
);
|
481
481
|
}
|
482
|
-
let r =
|
482
|
+
let r = Y(t);
|
483
483
|
if (r)
|
484
|
-
return (await new
|
484
|
+
return (await new b.Client({
|
485
485
|
accessToken: r
|
486
486
|
}).broadcast(n(o))).result;
|
487
487
|
throw new Error(
|
@@ -490,8 +490,8 @@ function Z(e = [], t, n) {
|
|
490
490
|
}
|
491
491
|
});
|
492
492
|
}
|
493
|
-
function
|
494
|
-
return
|
493
|
+
function te(e) {
|
494
|
+
return ee(
|
495
495
|
["accounts", "update"],
|
496
496
|
e,
|
497
497
|
(t) => [
|
@@ -509,8 +509,8 @@ function ee(e) {
|
|
509
509
|
]
|
510
510
|
);
|
511
511
|
}
|
512
|
-
function
|
513
|
-
const { mutateAsync: t } =
|
512
|
+
function He(e) {
|
513
|
+
const { mutateAsync: t } = te(e);
|
514
514
|
return u({
|
515
515
|
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
|
516
516
|
mutationFn: ({
|
@@ -526,7 +526,7 @@ function Ce(e) {
|
|
526
526
|
)
|
527
527
|
});
|
528
528
|
}
|
529
|
-
function
|
529
|
+
function Ne(e) {
|
530
530
|
return u({
|
531
531
|
mutationKey: ["operations", "sign", e],
|
532
532
|
mutationFn: ({
|
@@ -536,14 +536,14 @@ function He(e) {
|
|
536
536
|
if (!e)
|
537
537
|
throw new Error("[Operations][Sign] – cannot sign op with anon user");
|
538
538
|
let o;
|
539
|
-
return n.split(" ").length === 12 ? o = l.fromLogin(e, n, "active") :
|
539
|
+
return n.split(" ").length === 12 ? o = l.fromLogin(e, n, "active") : E.isWif(n) ? o = l.fromString(n) : o = l.from(n), p.hiveClient.broadcast.sendOperations(
|
540
540
|
[t],
|
541
541
|
o
|
542
542
|
);
|
543
543
|
}
|
544
544
|
});
|
545
545
|
}
|
546
|
-
const
|
546
|
+
const ne = (e, t, n, o = null) => new Promise((s, r) => {
|
547
547
|
var i;
|
548
548
|
(i = window.hive_keychain) == null || i.requestBroadcast(
|
549
549
|
e,
|
@@ -555,7 +555,7 @@ const te = (e, t, n, o = null) => new Promise((s, r) => {
|
|
555
555
|
o
|
556
556
|
);
|
557
557
|
});
|
558
|
-
function
|
558
|
+
function je(e, t = "Active") {
|
559
559
|
return u({
|
560
560
|
mutationKey: ["operations", "sign-keychain", e],
|
561
561
|
mutationFn: ({ operation: n }) => {
|
@@ -563,35 +563,35 @@ function Ne(e, t = "Active") {
|
|
563
563
|
throw new Error(
|
564
564
|
"[SDK][Keychain] – cannot sign operation with anon user"
|
565
565
|
);
|
566
|
-
return
|
566
|
+
return ne(e, [n], t);
|
567
567
|
}
|
568
568
|
});
|
569
569
|
}
|
570
|
-
function
|
570
|
+
function De(e = "/") {
|
571
571
|
return u({
|
572
572
|
mutationKey: ["operations", "sign-hivesigner", e],
|
573
|
-
mutationFn: async ({ operation: t }) =>
|
573
|
+
mutationFn: async ({ operation: t }) => b.sendOperation(t, { callback: e }, () => {
|
574
574
|
})
|
575
575
|
});
|
576
576
|
}
|
577
577
|
export {
|
578
578
|
h as EcencyWalletBasicTokens,
|
579
579
|
a as EcencyWalletCurrency,
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
580
|
+
Re as EcencyWalletsPrivateApi,
|
581
|
+
M as delay,
|
582
|
+
Ae as getAccountPointsQueryOptions,
|
583
|
+
T as getWallet,
|
584
|
+
Pe as mnemonicToSeedBip39,
|
585
|
+
te as useAccountUpdate,
|
586
|
+
Oe as useCoinGeckoPriceQuery,
|
587
|
+
ke as useGetAllTokensListQuery,
|
588
|
+
Se as useGetExternalWalletBalanceQuery,
|
589
|
+
J as useHiveKeysQuery,
|
590
|
+
Ce as useImportWallet,
|
591
|
+
He as useSaveWalletInformationToMetadata,
|
592
|
+
P as useSeedPhrase,
|
593
|
+
De as useSignOperationByHivesigner,
|
594
|
+
Ne as useSignOperationByKey,
|
595
|
+
je as useSignOperationByKeychain,
|
596
|
+
Ke as useWalletCreate
|
597
597
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { EcencyWalletBasicTokens, EcencyWalletCurrency } from '../enums';
|
2
|
-
export declare function useGetAllTokensListQuery(query: string):
|
2
|
+
export declare function useGetAllTokensListQuery(query: string): {
|
3
3
|
basic: EcencyWalletBasicTokens[];
|
4
4
|
external: EcencyWalletCurrency[];
|
5
5
|
layer2: string[];
|