@ecency/wallets 1.0.5 → 1.0.6

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