@ecency/wallets 1.0.1 → 1.0.2

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,50 +1,50 @@
1
- import { useCallback as b } from "react";
2
- import { useQuery as l, useQueryClient as g, useMutation as f } from "@tanstack/react-query";
1
+ import { useMemo as b, useCallback as S } from "react";
2
+ import { useQuery as l, useQueryClient as g, useMutation as d } from "@tanstack/react-query";
3
3
  import { BtcWallet as T } from "@okxweb3/coin-bitcoin";
4
4
  import { EthWallet as R } from "@okxweb3/coin-ethereum";
5
- import { TrxWallet as S } 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, { mnemonicToSeed as D } from "bip39";
11
- import { LRUCache as N } from "lru-cache";
5
+ import { TrxWallet as P } from "@okxweb3/coin-tron";
6
+ import { TonWallet as O } from "@okxweb3/coin-ton";
7
+ import { SolWallet as v } from "@okxweb3/coin-solana";
8
+ import { AtomWallet as k } from "@okxweb3/coin-cosmos";
9
+ import { AptosWallet as A } from "@okxweb3/coin-aptos";
10
+ import D, { mnemonicToSeedSync as N } from "bip39";
11
+ import { LRUCache as K } from "lru-cache";
12
12
  import { PrivateKey as u } from "@hiveio/dhive";
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) {
13
+ var n = /* @__PURE__ */ ((e) => (e.BTC = "btc", e.ETH = "eth", e.APT = "atpos", e.ATOM = "cosmos", e.TON = "ton", e.TRON = "tron", e.SOL = "Solana", e))(n || {});
14
+ function j(e) {
15
15
  return new Promise((t) => setTimeout(t, e));
16
16
  }
17
- function j(e) {
17
+ function _(e) {
18
18
  switch (e) {
19
- case o.BTC:
19
+ case n.BTC:
20
20
  return new T();
21
- case o.ETH:
21
+ case n.ETH:
22
22
  return new R();
23
- case o.TRON:
24
- return new S();
25
- case o.TON:
23
+ case n.TRON:
26
24
  return new P();
27
- case o.SOL:
25
+ case n.TON:
28
26
  return new O();
29
- case o.ATOM:
27
+ case n.SOL:
30
28
  return new v();
31
- case o.APT:
29
+ case n.ATOM:
32
30
  return new k();
31
+ case n.APT:
32
+ return new A();
33
33
  default:
34
34
  return;
35
35
  }
36
36
  }
37
- function ae(e, t) {
37
+ function se(e, t) {
38
38
  return l({
39
39
  queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
40
40
  queryFn: async () => {
41
41
  switch (e) {
42
- case o.BTC:
42
+ case n.BTC:
43
43
  const s = await (await fetch(
44
44
  `https://mempool.space/api/address/${t}`
45
45
  )).json();
46
46
  return (s.chain_stats.funded_txo_sum - s.chain_stats.spent_txo_sum) / 1e8;
47
- case o.ETH:
47
+ case n.ETH:
48
48
  return +(await (await fetch("https://eth.llamarpc.com", {
49
49
  method: "POST",
50
50
  body: JSON.stringify({
@@ -54,7 +54,7 @@ function ae(e, t) {
54
54
  params: [t, "latest"]
55
55
  })
56
56
  })).json()).result / 1e18;
57
- case o.SOL:
57
+ case n.SOL:
58
58
  return (await (await fetch(
59
59
  "https://api.mainnet-beta.solana.com",
60
60
  {
@@ -67,22 +67,22 @@ function ae(e, t) {
67
67
  })
68
68
  }
69
69
  )).json()).result.value / 1e9;
70
- case o.TRON:
70
+ case n.TRON:
71
71
  return (await (await fetch(
72
72
  `https://api.trongrid.io/v1/accounts/${t}`
73
73
  )).json()).data[0].balance / 1e6;
74
- case o.TON:
74
+ case n.TON:
75
75
  return (await (await fetch(
76
76
  `https://tonapi.io/v1/blockchain/getAccount?account=${t}`
77
77
  )).json()).balance / 1e9;
78
- case o.APT:
78
+ case n.APT:
79
79
  const w = (await (await fetch(
80
80
  `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
81
81
  )).json()).find(
82
82
  (h) => h.type.includes("coin::CoinStore")
83
83
  );
84
84
  return w ? parseInt(w.data.coin.value) / 1e8 : 0;
85
- case o.ATOM:
85
+ case n.ATOM:
86
86
  return +(await (await fetch(
87
87
  `https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
88
88
  )).json()).result.value.coins[0].amount / 1e6;
@@ -90,13 +90,13 @@ function ae(e, t) {
90
90
  }
91
91
  });
92
92
  }
93
- function d() {
93
+ function f() {
94
94
  return l({
95
95
  queryKey: ["ecency-wallets", "seed"],
96
- queryFn: async () => A.generateMnemonic(128)
96
+ queryFn: async () => D.generateMnemonic(128)
97
97
  });
98
98
  }
99
- const _ = {
99
+ const W = {
100
100
  max: 500,
101
101
  // how long to live in ms
102
102
  ttl: 1e3 * 60 * 5,
@@ -104,31 +104,31 @@ const _ = {
104
104
  allowStale: !1,
105
105
  updateAgeOnGet: !1,
106
106
  updateAgeOnHas: !1
107
- }, y = new N(_), m = Symbol("undefined"), W = (e, t) => y.set(e, t === void 0 ? m : t), q = (e) => {
107
+ }, y = new K(W), m = Symbol("undefined"), q = (e, t) => y.set(e, t === void 0 ? m : t), x = (e) => {
108
108
  const t = y.get(e);
109
109
  return t === m ? void 0 : t;
110
110
  };
111
- function se(e) {
111
+ function ce(e) {
112
112
  return l({
113
113
  queryKey: ["ecency-wallets", "coingecko-price", e],
114
114
  queryFn: async () => {
115
115
  let t = e;
116
116
  switch (e) {
117
- case o.BTC:
117
+ case n.BTC:
118
118
  t = "binance-wrapped-btc";
119
119
  break;
120
- case o.ETH:
120
+ case n.ETH:
121
121
  t = "ethereum";
122
122
  break;
123
- case o.SOL:
123
+ case n.SOL:
124
124
  t = "solana";
125
125
  break;
126
126
  default:
127
127
  t = e;
128
128
  }
129
- let n = q("gecko"), s;
130
- if (n)
131
- s = n;
129
+ let o = x("gecko"), s;
130
+ if (o)
131
+ s = o;
132
132
  else {
133
133
  const a = await (await fetch(
134
134
  "https://api.coingecko.com/api/v3/simple/price",
@@ -142,67 +142,65 @@ function se(e) {
142
142
  })
143
143
  }
144
144
  )).json();
145
- W("gecko", a === void 0 ? m : a), s = a;
145
+ q("gecko", a === void 0 ? m : a), s = a;
146
146
  }
147
147
  return 1 / +s[Object.keys(s)[0]].usd;
148
148
  },
149
149
  enabled: !!e
150
150
  });
151
151
  }
152
- function L(e) {
153
- const { data: t } = d();
152
+ function B(e) {
153
+ const { data: t } = f(), o = b(
154
+ () => N(t ?? "").toString("hex"),
155
+ [t]
156
+ );
154
157
  return l({
155
- queryKey: [
156
- "ecenc-wallets",
157
- "hive-keys",
158
- e,
159
- D(t ?? "")
160
- ],
158
+ queryKey: ["ecencу-wallets", "hive-keys", e, o],
161
159
  queryFn: async () => {
162
160
  if (!t)
163
161
  throw new Error("[Ecency][Wallets] - no seed to create Hive account");
164
- const n = u.fromLogin(e, t, "owner"), s = u.fromLogin(e, t, "active"), c = u.fromLogin(e, t, "posting"), r = u.fromLogin(e, t, "memo");
162
+ const s = u.fromSeed(o + "owner"), c = u.fromSeed(o + "active"), r = u.fromSeed(o + "posting"), a = u.fromSeed(o + "memo");
165
163
  return {
166
164
  username: e,
167
- owner: n.toString(),
168
- active: s.toString(),
169
- posting: c.toString(),
170
- memo: r.toString(),
171
- ownerPubkey: n.createPublic().toString(),
172
- activePubkey: s.createPublic().toString(),
173
- postingPubkey: c.createPublic().toString(),
174
- memoPubkey: r.createPublic().toString()
165
+ owner: s.toString(),
166
+ active: c.toString(),
167
+ posting: r.toString(),
168
+ memo: a.toString(),
169
+ ownerPubkey: s.createPublic().toString(),
170
+ activePubkey: c.createPublic().toString(),
171
+ postingPubkey: r.createPublic().toString(),
172
+ memoPubkey: a.createPublic().toString()
175
173
  };
176
174
  }
177
175
  });
178
176
  }
179
- const B = {
180
- [o.BTC]: "m/44'/0'/0'/0/0",
177
+ const H = {
178
+ [n.BTC]: "m/44'/0'/0'/0/0",
181
179
  // Bitcoin (BIP44)
182
- [o.ETH]: "m/44'/60'/0'/0/0",
180
+ [n.ETH]: "m/44'/60'/0'/0/0",
183
181
  // Ethereum (BIP44)
184
- [o.SOL]: "m/44'/501'/0'/0/0",
182
+ [n.SOL]: "m/44'/501'/0'/0/0",
185
183
  // Solana (BIP44)
186
- [o.TON]: "m/44'/396'/0'/0/0",
184
+ [n.TON]: "m/44'/396'/0'/0/0",
187
185
  // TON (BIP44)
188
- [o.TRON]: "m/44'/195'/0'/0/0",
186
+ [n.TRON]: "m/44'/195'/0'/0/0",
189
187
  // Tron (BIP44)
190
- [o.APT]: "m/44'/637'/0'/0/0",
188
+ [n.APT]: "m/44'/637'/0'/0/0",
191
189
  // Aptos (BIP44)
192
- [o.ATOM]: "m/44'/118'/0'/0/0"
190
+ [n.ATOM]: "m/44'/118'/0'/0/0"
193
191
  // Cosmos (BIP44)
194
192
  };
195
- function ce(e, t) {
196
- const { data: n } = d(), s = g(), c = f({
193
+ function re(e, t) {
194
+ const { data: o } = f(), s = g(), c = d({
197
195
  mutationKey: ["ecency-wallets", "create-wallet", e, t],
198
196
  mutationFn: async () => {
199
- if (!n)
197
+ if (!o)
200
198
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
201
- const a = j(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
202
- mnemonic: n,
203
- hdPath: B[t]
199
+ const a = _(t), i = await (a == null ? void 0 : a.getDerivedPrivateKey({
200
+ mnemonic: o,
201
+ hdPath: H[t]
204
202
  }));
205
- await K(1e3);
203
+ await j(1e3);
206
204
  const p = await (a == null ? void 0 : a.getNewAddress({
207
205
  privateKey: i
208
206
  }));
@@ -220,31 +218,31 @@ function ce(e, t) {
220
218
  (i) => new Map(i ? Array.from(i.entries()) : []).set(a.currency, a)
221
219
  );
222
220
  }
223
- }), r = b(() => {
221
+ }), r = S(() => {
224
222
  }, []);
225
223
  return {
226
224
  createWallet: c,
227
225
  importWallet: r
228
226
  };
229
227
  }
230
- const H = {};
231
- function x(e) {
228
+ const M = {};
229
+ function C(e) {
232
230
  const { data: t } = l({
233
231
  queryKey: ["ecency-wallets", "wallets", e]
234
- }), { data: n } = L(e);
235
- return f({
232
+ }), { data: o } = B(e);
233
+ return d({
236
234
  mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
237
- mutationFn: ({ currency: s, address: c }) => fetch(H + "/private-api/wallets-add", {
235
+ mutationFn: ({ currency: s, address: c }) => fetch(M + "/private-api/wallets-add", {
238
236
  method: "POST",
239
237
  body: JSON.stringify({
240
238
  username: e,
241
239
  token: s,
242
240
  address: c,
243
241
  meta: {
244
- ownerPublicKey: n == null ? void 0 : n.ownerPubkey,
245
- activePublicKey: n == null ? void 0 : n.activePubkey,
246
- postingPublicKey: n == null ? void 0 : n.postingPubkey,
247
- memoPublicKey: n == null ? void 0 : n.memoPubkey,
242
+ ownerPublicKey: o == null ? void 0 : o.ownerPubkey,
243
+ activePublicKey: o == null ? void 0 : o.activePubkey,
244
+ postingPublicKey: o == null ? void 0 : o.postingPubkey,
245
+ memoPublicKey: o == null ? void 0 : o.memoPubkey,
248
246
  ...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
249
247
  (r, [a, i]) => ({
250
248
  ...r,
@@ -257,18 +255,18 @@ function x(e) {
257
255
  })
258
256
  });
259
257
  }
260
- const re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
258
+ const ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
261
259
  __proto__: null,
262
- useCreateAccountWithWallets: x
260
+ useCreateAccountWithWallets: C
263
261
  }, Symbol.toStringTag, { value: "Module" }));
264
262
  export {
265
- o as EcencyWalletCurrency,
266
- re as EcencyWalletsPrivateApi,
267
- K as delay,
268
- j as getWallet,
269
- se as useCoinGeckoPriceQuery,
270
- ae as useGetExternalWalletBalanceQuery,
271
- L as useHiveKeysQuery,
272
- d as useSeedPhrase,
273
- ce as useWalletCreate
263
+ n as EcencyWalletCurrency,
264
+ ie as EcencyWalletsPrivateApi,
265
+ j as delay,
266
+ _ as getWallet,
267
+ ce as useCoinGeckoPriceQuery,
268
+ se as useGetExternalWalletBalanceQuery,
269
+ B as useHiveKeysQuery,
270
+ f as useSeedPhrase,
271
+ re as useWalletCreate
274
272
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/wallets",
3
3
  "private": false,
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "main": "./dist/ecency-wallets.umd.js",
7
7
  "module": "./dist/ecency-wallets.es.js",