@ecency/wallets 1.0.6 → 1.0.8

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,43 +1,43 @@
1
- import { useMemo as S, useCallback as T } from "react";
2
- import { useQuery as l, useQueryClient as g, useMutation as w } from "@tanstack/react-query";
3
- import { BtcWallet as R } from "@okxweb3/coin-bitcoin";
4
- import { EthWallet as P } from "@okxweb3/coin-ethereum";
5
- import { TrxWallet as O } from "@okxweb3/coin-tron";
6
- import { TonWallet as v } from "@okxweb3/coin-ton";
7
- import { SolWallet as k } from "@okxweb3/coin-solana";
8
- import { AtomWallet as A } from "@okxweb3/coin-cosmos";
9
- import { AptosWallet as N } from "@okxweb3/coin-aptos";
10
- import D, { mnemonicToSeedSync as y } from "bip39";
11
- import { LRUCache as j } from "lru-cache";
12
- import { PrivateKey as u } from "@hiveio/dhive";
1
+ import { useCallback as b } from "react";
2
+ import { useQuery as l, useQueryClient as g, useMutation as d } from "@tanstack/react-query";
3
+ import { BtcWallet as T } from "@okxweb3/coin-bitcoin";
4
+ import { EthWallet as S } from "@okxweb3/coin-ethereum";
5
+ import { TrxWallet as R } from "@okxweb3/coin-tron";
6
+ import { TonWallet as P } from "@okxweb3/coin-ton";
7
+ import { SolWallet as O } from "@okxweb3/coin-solana";
8
+ import { AtomWallet as v } from "@okxweb3/coin-cosmos";
9
+ import { AptosWallet as k } from "@okxweb3/coin-aptos";
10
+ import A, { mnemonicToSeedSync as N } from "bip39";
11
+ import { LRUCache as D } from "lru-cache";
12
+ import { PrivateKey as p } 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 K(e) {
14
+ function j(e) {
15
15
  return new Promise((t) => setTimeout(t, e));
16
16
  }
17
- function _(e) {
17
+ function K(e) {
18
18
  switch (e) {
19
19
  case o.BTC:
20
- return new R();
20
+ return new T();
21
21
  case o.ETH:
22
- return new P();
22
+ return new S();
23
23
  case o.TRON:
24
- return new O();
24
+ return new R();
25
25
  case o.TON:
26
- return new v();
26
+ return new P();
27
27
  case o.SOL:
28
- return new k();
28
+ return new O();
29
29
  case o.ATOM:
30
- return new A();
30
+ return new v();
31
31
  case o.APT:
32
- return new N();
32
+ return new k();
33
33
  default:
34
34
  return;
35
35
  }
36
36
  }
37
- function se(e) {
38
- return y(e).toString("hex");
37
+ function ae(e) {
38
+ return N(e).toString("hex");
39
39
  }
40
- function ce(e, t) {
40
+ function se(e, t) {
41
41
  return l({
42
42
  queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
43
43
  queryFn: async () => {
@@ -79,12 +79,12 @@ function ce(e, t) {
79
79
  `https://tonapi.io/v1/blockchain/getAccount?account=${t}`
80
80
  )).json()).balance / 1e9;
81
81
  case o.APT:
82
- const d = (await (await fetch(
82
+ const w = (await (await fetch(
83
83
  `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
84
84
  )).json()).find(
85
- (b) => b.type.includes("coin::CoinStore")
85
+ (h) => h.type.includes("coin::CoinStore")
86
86
  );
87
- return d ? parseInt(d.data.coin.value) / 1e8 : 0;
87
+ return w ? parseInt(w.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,13 +93,13 @@ function ce(e, t) {
93
93
  }
94
94
  });
95
95
  }
96
- function f() {
96
+ function y() {
97
97
  return l({
98
98
  queryKey: ["ecency-wallets", "seed"],
99
- queryFn: async () => D.generateMnemonic(128)
99
+ queryFn: async () => A.generateMnemonic(128)
100
100
  });
101
101
  }
102
- const x = {
102
+ const _ = {
103
103
  max: 500,
104
104
  // how long to live in ms
105
105
  ttl: 1e3 * 60 * 5,
@@ -107,11 +107,11 @@ const x = {
107
107
  allowStale: !1,
108
108
  updateAgeOnGet: !1,
109
109
  updateAgeOnHas: !1
110
- }, h = new j(x), m = Symbol("undefined"), H = (e, t) => h.set(e, t === void 0 ? m : t), W = (e) => {
111
- const t = h.get(e);
110
+ }, f = new D(_), m = Symbol("undefined"), H = (e, t) => f.set(e, t === void 0 ? m : t), W = (e) => {
111
+ const t = f.get(e);
112
112
  return t === m ? void 0 : t;
113
113
  };
114
- function re(e) {
114
+ function ce(e) {
115
115
  return l({
116
116
  queryKey: ["ecency-wallets", "coingecko-price", e],
117
117
  queryFn: async () => {
@@ -156,31 +156,28 @@ function re(e) {
156
156
  });
157
157
  }
158
158
  function q(e) {
159
- const { data: t } = f(), n = S(
160
- () => y(t ?? "").toString("hex"),
161
- [t]
162
- );
159
+ const { data: t } = y();
163
160
  return l({
164
- queryKey: ["ecencу-wallets", "hive-keys", e, n],
161
+ queryKey: ["ecencу-wallets", "hive-keys", e, t],
165
162
  queryFn: async () => {
166
163
  if (!t)
167
164
  throw new Error("[Ecency][Wallets] - no seed to create Hive account");
168
- const s = u.fromSeed(n + "owner"), c = u.fromSeed(n + "active"), r = u.fromSeed(n + "posting"), a = u.fromSeed(n + "memo");
165
+ const n = p.fromLogin(e, t, "owner"), s = p.fromLogin(e, t, "active"), c = p.fromLogin(e, t, "posting"), r = p.fromLogin(e, t, "memo");
169
166
  return {
170
167
  username: e,
171
- owner: s.toString(),
172
- active: c.toString(),
173
- posting: r.toString(),
174
- memo: a.toString(),
175
- ownerPubkey: s.createPublic().toString(),
176
- activePubkey: c.createPublic().toString(),
177
- postingPubkey: r.createPublic().toString(),
178
- memoPubkey: a.createPublic().toString()
168
+ owner: n.toString(),
169
+ active: s.toString(),
170
+ posting: c.toString(),
171
+ memo: r.toString(),
172
+ ownerPubkey: n.createPublic().toString(),
173
+ activePubkey: s.createPublic().toString(),
174
+ postingPubkey: c.createPublic().toString(),
175
+ memoPubkey: r.createPublic().toString()
179
176
  };
180
177
  }
181
178
  });
182
179
  }
183
- const B = {
180
+ const x = {
184
181
  [o.BTC]: "m/44'/0'/0'/0/0",
185
182
  // Bitcoin (BIP44)
186
183
  [o.ETH]: "m/44'/60'/0'/0/0",
@@ -196,24 +193,24 @@ const B = {
196
193
  [o.ATOM]: "m/44'/118'/0'/0/0"
197
194
  // Cosmos (BIP44)
198
195
  };
199
- function ie(e, t) {
200
- const { data: n } = f(), s = g(), c = w({
196
+ function re(e, t) {
197
+ const { data: n } = y(), s = g(), c = d({
201
198
  mutationKey: ["ecency-wallets", "create-wallet", e, t],
202
199
  mutationFn: async () => {
203
200
  if (!n)
204
201
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
205
- const a = _(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
202
+ const a = K(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
206
203
  mnemonic: n,
207
- hdPath: B[t]
204
+ hdPath: x[t]
208
205
  }));
209
- await K(1e3);
210
- const p = await (a == null ? void 0 : a.getNewAddress({
206
+ await j(1e3);
207
+ const u = await (a == null ? void 0 : a.getNewAddress({
211
208
  privateKey: i
212
209
  }));
213
210
  return {
214
211
  privateKey: i,
215
- address: p.address,
216
- publicKey: p.publicKey,
212
+ address: u.address,
213
+ publicKey: u.publicKey,
217
214
  username: e,
218
215
  currency: t
219
216
  };
@@ -224,21 +221,21 @@ function ie(e, t) {
224
221
  (i) => new Map(i ? Array.from(i.entries()) : []).set(a.currency, a)
225
222
  );
226
223
  }
227
- }), r = T(() => {
224
+ }), r = b(() => {
228
225
  }, []);
229
226
  return {
230
227
  createWallet: c,
231
228
  importWallet: r
232
229
  };
233
230
  }
234
- const C = { privateApiHost: "https://ecency.com" };
235
- function M(e) {
231
+ const B = { privateApiHost: "https://ecency.com" };
232
+ function L(e) {
236
233
  const { data: t } = l({
237
234
  queryKey: ["ecency-wallets", "wallets", e]
238
235
  }), { data: n } = q(e);
239
- return w({
236
+ return d({
240
237
  mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
241
- mutationFn: ({ currency: s, address: c }) => fetch(C.privateApiHost + "/private-api/wallets-add", {
238
+ mutationFn: ({ currency: s, address: c }) => fetch(B.privateApiHost + "/private-api/wallets-add", {
242
239
  method: "POST",
243
240
  headers: {
244
241
  "Content-Type": "application/json"
@@ -264,19 +261,19 @@ function M(e) {
264
261
  })
265
262
  });
266
263
  }
267
- const le = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
264
+ const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
268
265
  __proto__: null,
269
- useCreateAccountWithWallets: M
266
+ useCreateAccountWithWallets: L
270
267
  }, Symbol.toStringTag, { value: "Module" }));
271
268
  export {
272
269
  o as EcencyWalletCurrency,
273
- le as EcencyWalletsPrivateApi,
274
- K as delay,
275
- _ as getWallet,
276
- se as mnemonicToSeedBip39,
277
- re as useCoinGeckoPriceQuery,
278
- ce as useGetExternalWalletBalanceQuery,
270
+ ie as EcencyWalletsPrivateApi,
271
+ j as delay,
272
+ K as getWallet,
273
+ ae as mnemonicToSeedBip39,
274
+ ce as useCoinGeckoPriceQuery,
275
+ se as useGetExternalWalletBalanceQuery,
279
276
  q as useHiveKeysQuery,
280
- f as useSeedPhrase,
281
- ie as useWalletCreate
277
+ y as useSeedPhrase,
278
+ re as useWalletCreate
282
279
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/wallets",
3
3
  "private": false,
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "main": "./dist/ecency-wallets.umd.js",
7
7
  "module": "./dist/ecency-wallets.es.js",