@ecency/wallets 1.0.13 → 1.0.14

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.
@@ -1,20 +1,20 @@
1
- import { useCallback as v } from "react";
2
- import { useQuery as u, useQueryClient as h, useMutation as m } from "@tanstack/react-query";
1
+ import { useCallback as P } from "react";
2
+ import { useQuery as p, useQueryClient as h, useMutation as m } from "@tanstack/react-query";
3
3
  import { BtcWallet as S } from "@okxweb3/coin-bitcoin";
4
4
  import { EthWallet as R } from "@okxweb3/coin-ethereum";
5
5
  import { TrxWallet as O } from "@okxweb3/coin-tron";
6
6
  import { TonWallet as A } from "@okxweb3/coin-ton";
7
7
  import { SolWallet as k } from "@okxweb3/coin-solana";
8
- import { AtomWallet as K } from "@okxweb3/coin-cosmos";
9
- import { AptosWallet as N } from "@okxweb3/coin-aptos";
10
- import D, { mnemonicToSeedSync as j } from "bip39";
8
+ import { AtomWallet as N } from "@okxweb3/coin-cosmos";
9
+ import { AptosWallet as D } from "@okxweb3/coin-aptos";
10
+ import K, { mnemonicToSeedSync as _ } from "bip39";
11
11
  import { LRUCache as H } from "lru-cache";
12
- import { PrivateKey as p } from "@hiveio/dhive";
12
+ import { PrivateKey as u } from "@hiveio/dhive";
13
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 _(e) {
14
+ function j(e) {
15
15
  return new Promise((t) => setTimeout(t, e));
16
16
  }
17
- function b(e) {
17
+ function T(e) {
18
18
  switch (e) {
19
19
  case o.BTC:
20
20
  return new S();
@@ -27,18 +27,18 @@ function b(e) {
27
27
  case o.SOL:
28
28
  return new k();
29
29
  case o.ATOM:
30
- return new K();
31
- case o.APT:
32
30
  return new N();
31
+ case o.APT:
32
+ return new D();
33
33
  default:
34
34
  return;
35
35
  }
36
36
  }
37
- function re(e) {
38
- return j(e).toString("hex");
37
+ function ie(e) {
38
+ return _(e).toString("hex");
39
39
  }
40
- function ie(e, t) {
41
- return u({
40
+ function ce(e, t) {
41
+ return p({
42
42
  queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
43
43
  queryFn: async () => {
44
44
  switch (e) {
@@ -79,12 +79,12 @@ function ie(e, t) {
79
79
  `https://tonapi.io/v1/blockchain/getAccount?account=${t}`
80
80
  )).json()).balance / 1e9;
81
81
  case o.APT:
82
- const f = (await (await fetch(
82
+ const y = (await (await fetch(
83
83
  `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
84
84
  )).json()).find(
85
- (P) => P.type.includes("coin::CoinStore")
85
+ (v) => v.type.includes("coin::CoinStore")
86
86
  );
87
- return f ? parseInt(f.data.coin.value) / 1e8 : 0;
87
+ return y ? parseInt(y.data.coin.value) / 1e8 : 0;
88
88
  case o.ATOM:
89
89
  return +(await (await fetch(
90
90
  `https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
@@ -93,10 +93,10 @@ function ie(e, t) {
93
93
  }
94
94
  });
95
95
  }
96
- function g() {
97
- return u({
96
+ function b() {
97
+ return p({
98
98
  queryKey: ["ecency-wallets", "seed"],
99
- queryFn: async () => D.generateMnemonic(128)
99
+ queryFn: async () => K.generateMnemonic(128)
100
100
  });
101
101
  }
102
102
  const C = {
@@ -107,12 +107,12 @@ const C = {
107
107
  allowStale: !1,
108
108
  updateAgeOnGet: !1,
109
109
  updateAgeOnHas: !1
110
- }, T = new H(C), d = Symbol("undefined"), W = (e, t) => T.set(e, t === void 0 ? d : t), q = (e) => {
111
- const t = T.get(e);
110
+ }, g = new H(C), d = Symbol("undefined"), B = (e, t) => g.set(e, t === void 0 ? d : t), E = (e) => {
111
+ const t = g.get(e);
112
112
  return t === d ? void 0 : t;
113
113
  };
114
- function ce(e) {
115
- return u({
114
+ function le(e) {
115
+ return p({
116
116
  queryKey: ["ecency-wallets", "coingecko-price", e],
117
117
  queryFn: async () => {
118
118
  let t = e;
@@ -132,7 +132,7 @@ function ce(e) {
132
132
  default:
133
133
  t = e;
134
134
  }
135
- let n = q("gecko"), a;
135
+ let n = E("gecko"), a;
136
136
  if (n)
137
137
  a = n;
138
138
  else {
@@ -148,21 +148,21 @@ function ce(e) {
148
148
  })
149
149
  }
150
150
  )).json();
151
- W("gecko", s === void 0 ? d : s), a = s;
151
+ B("gecko", s === void 0 ? d : s), a = s;
152
152
  }
153
153
  return 1 / +a[Object.keys(a)[0]].usd;
154
154
  },
155
155
  enabled: !!e
156
156
  });
157
157
  }
158
- function B(e) {
159
- const { data: t } = g();
160
- return u({
158
+ function L(e) {
159
+ const { data: t } = b();
160
+ return p({
161
161
  queryKey: ["ecencу-wallets", "hive-keys", e, t],
162
162
  queryFn: async () => {
163
163
  if (!t)
164
164
  throw new Error("[Ecency][Wallets] - no seed to create Hive account");
165
- const n = p.fromLogin(e, t, "owner"), a = p.fromLogin(e, t, "active"), i = p.fromLogin(e, t, "posting"), r = p.fromLogin(e, t, "memo");
165
+ const n = u.fromLogin(e, t, "owner"), a = u.fromLogin(e, t, "active"), i = u.fromLogin(e, t, "posting"), r = u.fromLogin(e, t, "memo");
166
166
  return {
167
167
  username: e,
168
168
  owner: n.toString(),
@@ -177,7 +177,7 @@ function B(e) {
177
177
  }
178
178
  });
179
179
  }
180
- const L = {
180
+ const W = {
181
181
  [o.BTC]: "m/44'/0'/0'/0/0",
182
182
  // Bitcoin (BIP44)
183
183
  [o.ETH]: "m/44'/60'/0'/0/0",
@@ -193,17 +193,17 @@ const L = {
193
193
  [o.ATOM]: "m/44'/118'/0'/0/0"
194
194
  // Cosmos (BIP44)
195
195
  };
196
- function le(e, t) {
197
- const { data: n } = g(), a = h(), i = m({
196
+ function pe(e, t) {
197
+ const { data: n } = b(), a = h(), i = m({
198
198
  mutationKey: ["ecency-wallets", "create-wallet", e, t],
199
199
  mutationFn: async () => {
200
200
  if (!n)
201
201
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
202
- const s = b(t), c = await (s == null ? void 0 : s.getDerivedPrivateKey({
202
+ const s = T(t), c = await (s == null ? void 0 : s.getDerivedPrivateKey({
203
203
  mnemonic: n,
204
- hdPath: L[t]
204
+ hdPath: W[t]
205
205
  }));
206
- await _(1e3);
206
+ await j(1e3);
207
207
  const l = await (s == null ? void 0 : s.getNewAddress({
208
208
  privateKey: c
209
209
  }));
@@ -221,21 +221,21 @@ function le(e, t) {
221
221
  (c) => new Map(c ? Array.from(c.entries()) : []).set(s.currency, s)
222
222
  );
223
223
  }
224
- }), r = v(() => {
224
+ }), r = P(() => {
225
225
  }, []);
226
226
  return {
227
227
  createWallet: i,
228
228
  importWallet: r
229
229
  };
230
230
  }
231
- const x = { privateApiHost: "https://ecency.com" };
231
+ const q = { privateApiHost: "https://ecency.com" };
232
232
  function M(e) {
233
- const { data: t } = u({
233
+ const { data: t } = p({
234
234
  queryKey: ["ecency-wallets", "wallets", e]
235
- }), { data: n } = B(e);
235
+ }), { data: n } = L(e);
236
236
  return m({
237
237
  mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
238
- mutationFn: ({ currency: a, address: i }) => fetch(x.privateApiHost + "/private-api/wallets-add", {
238
+ mutationFn: ({ currency: a, address: i }) => fetch(q.privateApiHost + "/private-api/wallets-add", {
239
239
  method: "POST",
240
240
  headers: {
241
241
  "Content-Type": "application/json"
@@ -264,7 +264,7 @@ function M(e) {
264
264
  const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
265
265
  __proto__: null,
266
266
  useCreateAccountWithWallets: M
267
- }, Symbol.toStringTag, { value: "Module" })), E = {
267
+ }, Symbol.toStringTag, { value: "Module" })), x = {
268
268
  [o.BTC]: [
269
269
  "m/84'/0'/0'/0/0",
270
270
  "m/44'/0'/0'/0/0",
@@ -276,34 +276,50 @@ const ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
276
276
  [o.APT]: ["m/44'/637'/0'/0'/0'"],
277
277
  [o.TON]: ["m/44'/607'/0'"],
278
278
  [o.ATOM]: ["m/44'/118'/0'/0/0"]
279
+ }, F = {
280
+ [o.BTC]: [
281
+ "",
282
+ // legacy
283
+ "segwit_native",
284
+ "segwite_nested",
285
+ "segwit_taproot"
286
+ ],
287
+ [o.ETH]: [void 0],
288
+ [o.SOL]: [void 0],
289
+ [o.TRON]: [void 0],
290
+ [o.APT]: [void 0],
291
+ [o.TON]: [void 0],
292
+ [o.ATOM]: [void 0]
279
293
  };
280
- async function F(e, t, n, a) {
281
- for (const i of E[a] || [])
294
+ async function Q(e, t, n, a) {
295
+ for (const i of x[a] || [])
282
296
  try {
283
297
  const r = await n.getDerivedPrivateKey({
284
298
  mnemonic: e,
285
299
  hdPath: i
286
300
  });
287
- if ((await n.getNewAddress({
288
- privateKey: r
289
- })).address === t)
290
- return r;
301
+ for (const s of F[a])
302
+ if ((await n.getNewAddress({
303
+ privateKey: r,
304
+ addressType: s
305
+ })).address === t)
306
+ return r;
291
307
  } catch {
292
308
  return;
293
309
  }
294
310
  }
295
- function pe(e, t) {
311
+ function me(e, t) {
296
312
  const n = h();
297
313
  return m({
298
314
  mutationKey: ["ecency-wallets", "import-wallet", e, t],
299
315
  mutationFn: async ({ privateKeyOrSeed: a, address: i }) => {
300
- const r = b(t);
316
+ const r = T(t);
301
317
  if (!r)
302
318
  throw new Error("Cannot find token for this currency");
303
319
  const s = a.split(" ").length === 12;
304
320
  let c = !1, l = a;
305
321
  if (s)
306
- l = await F(
322
+ l = await Q(
307
323
  a,
308
324
  i,
309
325
  r,
@@ -312,10 +328,10 @@ function pe(e, t) {
312
328
  else {
313
329
  const w = await r.getNewAddress({
314
330
  privateKey: a
315
- }), y = await r.validPrivateKey({
331
+ }), f = await r.validPrivateKey({
316
332
  privateKey: a
317
333
  });
318
- c = w.address === i && y.isValid;
334
+ c = w.address === i && f.isValid;
319
335
  }
320
336
  if (!c)
321
337
  throw new Error(
@@ -345,13 +361,13 @@ function pe(e, t) {
345
361
  export {
346
362
  o as EcencyWalletCurrency,
347
363
  ue as EcencyWalletsPrivateApi,
348
- _ as delay,
349
- b as getWallet,
350
- re as mnemonicToSeedBip39,
351
- ce as useCoinGeckoPriceQuery,
352
- ie as useGetExternalWalletBalanceQuery,
353
- B as useHiveKeysQuery,
354
- pe as useImportWallet,
355
- g as useSeedPhrase,
356
- le as useWalletCreate
364
+ j as delay,
365
+ T as getWallet,
366
+ ie as mnemonicToSeedBip39,
367
+ le as useCoinGeckoPriceQuery,
368
+ ce as useGetExternalWalletBalanceQuery,
369
+ L as useHiveKeysQuery,
370
+ me as useImportWallet,
371
+ b as useSeedPhrase,
372
+ pe as useWalletCreate
357
373
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/wallets",
3
3
  "private": false,
4
- "version": "1.0.13",
4
+ "version": "1.0.14",
5
5
  "type": "module",
6
6
  "main": "./dist/ecency-wallets.umd.js",
7
7
  "module": "./dist/ecency-wallets.es.js",