@ecency/sdk 1.0.0 → 1.0.1
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 +7 -7
- package/dist/ecency-sdk.es.js +33 -33
- package/package.json +1 -1
package/dist/ecency-sdk.es.d.ts
CHANGED
@@ -27,13 +27,13 @@ export declare interface EcencyHiveKeys {
|
|
27
27
|
}
|
28
28
|
|
29
29
|
export declare enum EcencyWalletCurrency {
|
30
|
-
BTC = "
|
31
|
-
ETH = "
|
32
|
-
APT = "
|
33
|
-
ATOM = "
|
34
|
-
TON = "
|
35
|
-
TRON = "
|
36
|
-
SOL = "
|
30
|
+
BTC = "BTC",
|
31
|
+
ETH = "ETH",
|
32
|
+
APT = "APT",
|
33
|
+
ATOM = "ATOM",
|
34
|
+
TON = "TON",
|
35
|
+
TRON = "TRON",
|
36
|
+
SOL = "SOL"
|
37
37
|
}
|
38
38
|
|
39
39
|
declare namespace EcencyWalletsPrivateApi {
|
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
import { useCallback as
|
1
|
+
import { useCallback as O } from "react";
|
2
2
|
import { useQuery as p, useQueryClient as y, useMutation as m } from "@tanstack/react-query";
|
3
|
-
import { BtcWallet as
|
3
|
+
import { BtcWallet as R } from "@okxweb3/coin-bitcoin";
|
4
4
|
import { EthWallet as v } from "@okxweb3/coin-ethereum";
|
5
5
|
import { TrxWallet as k } from "@okxweb3/coin-tron";
|
6
6
|
import { TonWallet as A } from "@okxweb3/coin-ton";
|
7
7
|
import { SolWallet as N } from "@okxweb3/coin-solana";
|
8
8
|
import { AtomWallet as K } from "@okxweb3/coin-cosmos";
|
9
|
-
import { AptosWallet as
|
10
|
-
import
|
11
|
-
import { LRUCache as
|
9
|
+
import { AptosWallet as C } from "@okxweb3/coin-aptos";
|
10
|
+
import D, { mnemonicToSeedSync as H } from "bip39";
|
11
|
+
import { LRUCache as j } from "lru-cache";
|
12
12
|
import { PrivateKey as u } from "@hiveio/dhive";
|
13
|
-
var o = /* @__PURE__ */ ((e) => (e.BTC = "
|
13
|
+
var o = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRON", e.SOL = "SOL", e))(o || {});
|
14
14
|
function x(e) {
|
15
15
|
return new Promise((t) => setTimeout(t, e));
|
16
16
|
}
|
17
17
|
function h(e) {
|
18
18
|
switch (e) {
|
19
19
|
case o.BTC:
|
20
|
-
return new
|
20
|
+
return new R();
|
21
21
|
case o.ETH:
|
22
22
|
return new v();
|
23
23
|
case o.TRON:
|
@@ -29,13 +29,13 @@ function h(e) {
|
|
29
29
|
case o.ATOM:
|
30
30
|
return new K();
|
31
31
|
case o.APT:
|
32
|
-
return new
|
32
|
+
return new C();
|
33
33
|
default:
|
34
34
|
return;
|
35
35
|
}
|
36
36
|
}
|
37
37
|
function ce(e) {
|
38
|
-
return
|
38
|
+
return H(e).toString("hex");
|
39
39
|
}
|
40
40
|
function ie(e, t) {
|
41
41
|
return p({
|
@@ -96,7 +96,7 @@ function ie(e, t) {
|
|
96
96
|
function f(e) {
|
97
97
|
return p({
|
98
98
|
queryKey: ["ecency-wallets", "seed", e],
|
99
|
-
queryFn: async () =>
|
99
|
+
queryFn: async () => D.generateMnemonic(128)
|
100
100
|
});
|
101
101
|
}
|
102
102
|
const W = {
|
@@ -107,8 +107,8 @@ const W = {
|
|
107
107
|
allowStale: !1,
|
108
108
|
updateAgeOnGet: !1,
|
109
109
|
updateAgeOnHas: !1
|
110
|
-
},
|
111
|
-
const t =
|
110
|
+
}, T = new j(W), w = Symbol("undefined"), _ = (e, t) => T.set(e, t === void 0 ? w : t), B = (e) => {
|
111
|
+
const t = T.get(e);
|
112
112
|
return t === w ? void 0 : t;
|
113
113
|
};
|
114
114
|
function le(e) {
|
@@ -132,7 +132,7 @@ function le(e) {
|
|
132
132
|
default:
|
133
133
|
t = e;
|
134
134
|
}
|
135
|
-
let n =
|
135
|
+
let n = B("gecko"), r;
|
136
136
|
if (n)
|
137
137
|
r = n;
|
138
138
|
else {
|
@@ -155,7 +155,7 @@ function le(e) {
|
|
155
155
|
enabled: !!e
|
156
156
|
});
|
157
157
|
}
|
158
|
-
function
|
158
|
+
function E(e) {
|
159
159
|
const { data: t } = f(e);
|
160
160
|
return p({
|
161
161
|
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
@@ -177,7 +177,7 @@ function q(e) {
|
|
177
177
|
}
|
178
178
|
});
|
179
179
|
}
|
180
|
-
const
|
180
|
+
const L = {
|
181
181
|
[o.BTC]: "m/44'/0'/0'/0/0",
|
182
182
|
// Bitcoin (BIP44)
|
183
183
|
[o.ETH]: "m/44'/60'/0'/0/0",
|
@@ -201,7 +201,7 @@ function pe(e, t) {
|
|
201
201
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
202
202
|
const a = h(t), c = await (a == null ? void 0 : a.getDerivedPrivateKey({
|
203
203
|
mnemonic: n,
|
204
|
-
hdPath:
|
204
|
+
hdPath: L[t]
|
205
205
|
}));
|
206
206
|
await x(1e3);
|
207
207
|
const l = await (a == null ? void 0 : a.getNewAddress({
|
@@ -221,21 +221,21 @@ function pe(e, t) {
|
|
221
221
|
(c) => new Map(c ? Array.from(c.entries()) : []).set(a.currency, a)
|
222
222
|
);
|
223
223
|
}
|
224
|
-
}), i =
|
224
|
+
}), i = O(() => {
|
225
225
|
}, []);
|
226
226
|
return {
|
227
227
|
createWallet: s,
|
228
228
|
importWallet: i
|
229
229
|
};
|
230
230
|
}
|
231
|
-
const
|
232
|
-
function
|
231
|
+
const b = { privateApiHost: "https://ecency.com" };
|
232
|
+
function q(e) {
|
233
233
|
const { data: t } = p({
|
234
234
|
queryKey: ["ecency-wallets", "wallets", e]
|
235
|
-
}), { data: n } =
|
235
|
+
}), { data: n } = E(e);
|
236
236
|
return m({
|
237
237
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
238
|
-
mutationFn: ({ currency: r, address: s }) => fetch(
|
238
|
+
mutationFn: ({ currency: r, address: s }) => fetch(b.privateApiHost + "/private-api/wallets-add", {
|
239
239
|
method: "POST",
|
240
240
|
headers: {
|
241
241
|
"Content-Type": "application/json"
|
@@ -261,11 +261,11 @@ function L(e) {
|
|
261
261
|
})
|
262
262
|
});
|
263
263
|
}
|
264
|
-
function
|
264
|
+
function g() {
|
265
265
|
return m({
|
266
266
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
267
267
|
mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
|
268
|
-
|
268
|
+
b.privateApiHost + "/private-api/wallets-exist",
|
269
269
|
{
|
270
270
|
method: "POST",
|
271
271
|
headers: {
|
@@ -281,28 +281,28 @@ function T() {
|
|
281
281
|
}
|
282
282
|
const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
283
283
|
__proto__: null,
|
284
|
-
useCheckWalletExistence:
|
285
|
-
useCreateAccountWithWallets:
|
286
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
284
|
+
useCheckWalletExistence: g,
|
285
|
+
useCreateAccountWithWallets: q
|
286
|
+
}, Symbol.toStringTag, { value: "Module" })), M = {
|
287
287
|
[o.BTC]: ["m/84'/0'/0'/0/0"],
|
288
288
|
[o.ETH]: ["m/84'/60'/0'/0/0"],
|
289
289
|
// its not working for Trust, Exodus, todo: check others below
|
290
290
|
[o.SOL]: ["m/84'/501'/0'/0/0"],
|
291
|
-
[o.TRON]: ["m/
|
291
|
+
[o.TRON]: ["m/44'/195'/0'/0'/0'"],
|
292
292
|
[o.APT]: ["m/84'/637'/0'/0/0"],
|
293
293
|
[o.TON]: [],
|
294
294
|
// Disabled
|
295
295
|
[o.ATOM]: ["m/84'/118'/0'/0'/0"]
|
296
296
|
};
|
297
|
-
async function
|
298
|
-
for (const r of
|
297
|
+
async function F(e, t, n) {
|
298
|
+
for (const r of M[n] || [])
|
299
299
|
try {
|
300
300
|
const s = await t.getDerivedPrivateKey({
|
301
301
|
mnemonic: e,
|
302
302
|
hdPath: r
|
303
303
|
}), i = await t.getNewAddress({
|
304
304
|
privateKey: s,
|
305
|
-
addressType: "segwit_native"
|
305
|
+
addressType: n === o.BTC ? "segwit_native" : void 0
|
306
306
|
});
|
307
307
|
return [s.toString(), i.address];
|
308
308
|
} catch {
|
@@ -311,7 +311,7 @@ async function M(e, t, n) {
|
|
311
311
|
return [];
|
312
312
|
}
|
313
313
|
function me(e, t) {
|
314
|
-
const n = y(), { mutateAsync: r } =
|
314
|
+
const n = y(), { mutateAsync: r } = g();
|
315
315
|
return m({
|
316
316
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
317
317
|
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
@@ -320,7 +320,7 @@ function me(e, t) {
|
|
320
320
|
throw new Error("Cannot find token for this currency");
|
321
321
|
const a = s.split(" ").length === 12;
|
322
322
|
let c, l = s;
|
323
|
-
if (a ? [l, c] = await
|
323
|
+
if (a ? [l, c] = await F(
|
324
324
|
s,
|
325
325
|
i,
|
326
326
|
t
|
@@ -366,7 +366,7 @@ export {
|
|
366
366
|
ce as mnemonicToSeedBip39,
|
367
367
|
le as useCoinGeckoPriceQuery,
|
368
368
|
ie as useGetExternalWalletBalanceQuery,
|
369
|
-
|
369
|
+
E as useHiveKeysQuery,
|
370
370
|
me as useImportWallet,
|
371
371
|
f as useSeedPhrase,
|
372
372
|
pe as useWalletCreate
|