@ecency/sdk 1.0.25 → 1.0.27

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.
Files changed (37) hide show
  1. package/dist/ecency-sdk.es.js +170 -517
  2. package/dist/index.d.ts +3 -1
  3. package/dist/modules/core/index.d.ts +2 -0
  4. package/package.json +5 -15
  5. package/Readme.md +0 -36
  6. package/dist/modules/wallets/enums/ecency-wallet-basic-tokens.d.ts +0 -7
  7. package/dist/modules/wallets/enums/ecency-wallet-currency.d.ts +0 -9
  8. package/dist/modules/wallets/enums/index.d.ts +0 -2
  9. package/dist/modules/wallets/functions/get-keys-from-seed.d.ts +0 -3
  10. package/dist/modules/wallets/functions/index.d.ts +0 -1
  11. package/dist/modules/wallets/index.d.ts +0 -4
  12. package/dist/modules/wallets/mutations/index.d.ts +0 -4
  13. package/dist/modules/wallets/mutations/private-api/check-wallet-existence.d.ts +0 -7
  14. package/dist/modules/wallets/mutations/private-api/create-account-with-wallets.d.ts +0 -7
  15. package/dist/modules/wallets/mutations/private-api/index.d.ts +0 -2
  16. package/dist/modules/wallets/mutations/private-api-namespace.d.ts +0 -2
  17. package/dist/modules/wallets/mutations/save-wallet-information-to-metadata.d.ts +0 -5
  18. package/dist/modules/wallets/mutations/use-import-wallet.d.ts +0 -10
  19. package/dist/modules/wallets/mutations/use-wallet-create.d.ts +0 -6
  20. package/dist/modules/wallets/queries/get-account-points-query-options.d.ts +0 -9
  21. package/dist/modules/wallets/queries/index.d.ts +0 -6
  22. package/dist/modules/wallets/queries/use-coingecko-price-query.d.ts +0 -2
  23. package/dist/modules/wallets/queries/use-get-account-wallet-list-query.d.ts +0 -9
  24. package/dist/modules/wallets/queries/use-get-all-tokens-list-query.d.ts +0 -6
  25. package/dist/modules/wallets/queries/use-get-external-wallet-query.d.ts +0 -10
  26. package/dist/modules/wallets/queries/use-hive-keys-query.d.ts +0 -2
  27. package/dist/modules/wallets/queries/use-seed-phrase.d.ts +0 -1
  28. package/dist/modules/wallets/types/account-points-response.d.ts +0 -4
  29. package/dist/modules/wallets/types/ecency-create-wallet-information.d.ts +0 -9
  30. package/dist/modules/wallets/types/ecency-hive-keys.d.ts +0 -12
  31. package/dist/modules/wallets/types/index.d.ts +0 -3
  32. package/dist/modules/wallets/utils/delay.d.ts +0 -1
  33. package/dist/modules/wallets/utils/get-wallet.d.ts +0 -3
  34. package/dist/modules/wallets/utils/index.d.ts +0 -3
  35. package/dist/modules/wallets/utils/mnemonic-to-seed-bip-39.d.ts +0 -1
  36. /package/dist/{config.d.ts → modules/core/config.d.ts} +0 -0
  37. /package/dist/modules/{wallets/utils → core}/mock-storage.d.ts +0 -0
@@ -1,46 +1,13 @@
1
1
  var C = Object.defineProperty;
2
- var R = (e, t, n) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var v = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { useMemo as H, useCallback as N } from "react";
5
- import { useQuery as w, queryOptions as f, useQueryClient as b, useMutation as l } from "@tanstack/react-query";
6
- import { BtcWallet as _ } from "@okxweb3/coin-bitcoin";
7
- import { EthWallet as j } from "@okxweb3/coin-ethereum";
8
- import { TrxWallet as D } from "@okxweb3/coin-tron";
9
- import { TonWallet as F } from "@okxweb3/coin-ton";
10
- import { SolWallet as E } from "@okxweb3/coin-solana";
11
- import { AtomWallet as L } from "@okxweb3/coin-cosmos";
12
- import { AptosWallet as x } from "@okxweb3/coin-aptos";
13
- import q from "bip39";
14
- import { Client as M, PrivateKey as u, cryptoUtils as B } from "@hiveio/dhive";
15
- import { LRUCache as I } from "lru-cache";
16
- import T from "hivesigner";
17
- var a = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(a || {}), d = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(d || {});
18
- function Q(e) {
19
- return new Promise((t) => setTimeout(t, e));
20
- }
21
- function P(e) {
22
- switch (e) {
23
- case a.BTC:
24
- return new _();
25
- case a.ETH:
26
- return new j();
27
- case a.TRON:
28
- return new D();
29
- case a.TON:
30
- return new F();
31
- case a.SOL:
32
- return new E();
33
- case a.ATOM:
34
- return new L();
35
- case a.APT:
36
- return new x();
37
- default:
38
- return;
39
- }
40
- }
41
- class W {
2
+ var K = (e, t, n) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var g = (e, t, n) => K(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { useMutation as f, isServer as Q, QueryClient as O, useQuery as S, useInfiniteQuery as k, queryOptions as l } from "@tanstack/react-query";
5
+ import { Client as q, PrivateKey as y, cryptoUtils as _ } from "@hiveio/dhive";
6
+ import v from "hivesigner";
7
+ import { cache as b } from "react";
8
+ class I {
42
9
  constructor() {
43
- v(this, "length", 0);
10
+ g(this, "length", 0);
44
11
  }
45
12
  clear() {
46
13
  throw new Error("Method not implemented.");
@@ -58,11 +25,11 @@ class W {
58
25
  this[t] = n;
59
26
  }
60
27
  }
61
- const p = {
28
+ const a = {
62
29
  privateApiHost: "https://ecency.com",
63
- storage: typeof window > "u" ? new W() : window.localStorage,
30
+ storage: typeof window > "u" ? new I() : window.localStorage,
64
31
  storagePrefix: "ecency",
65
- hiveClient: new M(
32
+ hiveClient: new q(
66
33
  [
67
34
  "https://api.hive.blog",
68
35
  "https://api.deathwing.me",
@@ -82,436 +49,104 @@ const p = {
82
49
  consoleOnFailover: !0
83
50
  }
84
51
  ),
85
- heliusApiKey: "fb1e2935-f911-4b1d-8e1c-3863f6879d42"
86
- };
87
- function ke(e, t) {
88
- return w({
89
- queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
90
- queryFn: async () => {
91
- switch (e) {
92
- case a.BTC:
93
- const o = await (await fetch(
94
- `https://mempool.space/api/address/${t}`
95
- )).json();
96
- return (o.chain_stats.funded_txo_sum - o.chain_stats.spent_txo_sum) / 1e8;
97
- case a.ETH:
98
- return +(await (await fetch(
99
- `https://api.ethplorer.io/getAddressInfo/${t}?apiKey=freekey`
100
- )).json()).ETH.balance;
101
- case a.SOL:
102
- return (await (await fetch(
103
- `https://rpc.helius.xyz/?api-key=${p.heliusApiKey}`,
104
- {
105
- method: "POST",
106
- body: JSON.stringify({
107
- jsonrpc: "2.0",
108
- id: "1",
109
- method: "getBalance",
110
- params: [t]
111
- }),
112
- headers: {
113
- "Content-Type": "application/json"
114
- }
115
- }
116
- )).json()).result.value / 1e9;
117
- case a.TRON:
118
- return (await (await fetch(
119
- `https://api.trongrid.io/v1/accounts/${t}`
120
- )).json()).data[0].balance / 1e6;
121
- case a.TON:
122
- return (await (await fetch(
123
- `https://tonapi.io/v1/blockchain/getAccount?account=${t}`
124
- )).json()).balance / 1e9;
125
- case a.APT:
126
- const g = (await (await fetch(
127
- `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
128
- )).json()).find(
129
- (K) => K.type.includes("coin::CoinStore")
130
- );
131
- return g ? parseInt(g.data.coin.value) / 1e8 : 0;
132
- case a.ATOM:
133
- return +(await (await fetch(
134
- `https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
135
- )).json()).result.value.coins[0].amount / 1e6;
136
- }
137
- }
138
- });
139
- }
140
- function O(e) {
141
- return w({
142
- queryKey: ["ecency-wallets", "seed", e],
143
- queryFn: async () => q.generateMnemonic(128)
144
- });
145
- }
146
- const J = {
147
- max: 500,
148
- // how long to live in ms
149
- ttl: 1e3 * 60 * 5,
150
- // return stale items before removing from cache?
151
- allowStale: !1,
152
- updateAgeOnGet: !1,
153
- updateAgeOnHas: !1
154
- }, S = new I(J), m = Symbol("undefined"), $ = (e, t) => S.set(e, t === void 0 ? m : t), G = (e) => {
155
- const t = S.get(e);
156
- return t === m ? void 0 : t;
157
- };
158
- function Ke(e) {
159
- return w({
160
- queryKey: ["ecency-wallets", "coingecko-price", e],
161
- queryFn: async () => {
162
- let t = e;
163
- switch (e) {
164
- case a.BTC:
165
- t = "binance-wrapped-btc";
166
- break;
167
- case a.ETH:
168
- t = "ethereum";
169
- break;
170
- case a.SOL:
171
- t = "solana";
172
- break;
173
- case a.TON:
174
- t = "trx";
175
- break;
176
- default:
177
- t = e;
178
- }
179
- let n = G("gecko"), o;
180
- if (n)
181
- o = n;
182
- else {
183
- const r = await (await fetch(
184
- "https://api.coingecko.com/api/v3/simple/price",
185
- {
186
- method: "POST",
187
- body: JSON.stringify({
188
- params: {
189
- ids: [t],
190
- vs_currencies: "usd"
191
- }
192
- })
193
- }
194
- )).json();
195
- $("gecko", r === void 0 ? m : r), o = r;
196
- }
197
- return 1 / +o[Object.keys(o)[0]].usd;
198
- },
199
- enabled: !!e
200
- });
201
- }
202
- function U(e) {
203
- const { data: t } = O(e);
204
- return w({
205
- queryKey: ["ecencу-wallets", "hive-keys", e, t],
206
- queryFn: async () => {
207
- if (!t)
208
- throw new Error("[Ecency][Wallets] - no seed to create Hive account");
209
- const n = u.fromLogin(e, t, "owner"), o = u.fromLogin(e, t, "active"), s = u.fromLogin(e, t, "posting"), i = u.fromLogin(e, t, "memo");
210
- return {
211
- username: e,
212
- owner: n.toString(),
213
- active: o.toString(),
214
- posting: s.toString(),
215
- memo: i.toString(),
216
- ownerPubkey: n.createPublic().toString(),
217
- activePubkey: o.createPublic().toString(),
218
- postingPubkey: s.createPublic().toString(),
219
- memoPubkey: i.createPublic().toString()
220
- };
221
- }
222
- });
223
- }
224
- function Ce(e, t) {
225
- return f({
226
- queryKey: ["ecency-wallets", "points", e, t],
227
- queryFn: async () => await (await fetch(
228
- `${p.privateApiHost}/private-api/points`,
229
- {
230
- method: "POST",
231
- body: JSON.stringify({
232
- username: e.replace("@", "")
233
- })
234
- }
235
- )).json(),
236
- staleTime: 3e4,
237
- refetchOnMount: !0,
238
- enabled: !!e
239
- });
240
- }
241
- function V(e, t) {
242
- return f({
243
- queryKey: ["hive-engine", "tokens-list", e, t],
244
- queryFn: async () => (await (await fetch(
245
- `${p.privateApiHost}/private-api/engine-api`,
246
- {
247
- method: "POST",
248
- body: JSON.stringify({
249
- jsonrpc: "2.0",
250
- method: "find",
251
- params: {
252
- contract: "market",
253
- table: "metrics",
254
- query: {
255
- symbol: t,
256
- account: e
257
- }
258
- },
259
- id: 1
260
- }),
261
- headers: { "Content-type": "application/json" }
262
- }
263
- )).json()).result
264
- });
265
- }
266
- function Re(e) {
267
- const { data: t } = w(V());
268
- return H(
269
- () => {
270
- var n;
271
- return {
272
- basic: [
273
- d.Points,
274
- d.Hive,
275
- d.HivePower,
276
- d.HiveDollar,
277
- d.Spk
278
- ].filter((o) => o.toLowerCase().includes(e.toLowerCase())),
279
- external: Object.values(a).filter(
280
- (o) => o.toLowerCase().includes(e.toLowerCase())
281
- ),
282
- layer2: ((n = t == null ? void 0 : t.map(({ symbol: o }) => o)) == null ? void 0 : n.filter(
283
- (o) => o.toLowerCase().includes(e.toLowerCase())
284
- )) ?? []
285
- };
286
- },
287
- [t, e]
288
- );
289
- }
290
- const z = {
291
- [a.BTC]: "m/44'/0'/0'/0/0",
292
- // Bitcoin (BIP44)
293
- [a.ETH]: "m/44'/60'/0'/0/0",
294
- // Ethereum (BIP44)
295
- [a.SOL]: "m/44'/501'/0'/0'",
296
- // Solana (BIP44)
297
- [a.TON]: "m/44'/607'/0'",
298
- // TON (BIP44)
299
- [a.TRON]: "m/44'/195'/0'/0/0",
300
- // Tron (BIP44)
301
- [a.APT]: "m/44'/637'/0'/0'/0'",
302
- // Aptos (BIP44)
303
- [a.ATOM]: "m/44'/118'/0'/0/0"
304
- // Cosmos (BIP44)
52
+ heliusApiKey: void 0
305
53
  };
306
- function He(e, t) {
307
- const { data: n } = O(e), o = b(), s = l({
308
- mutationKey: ["ecency-wallets", "create-wallet", e, t],
309
- mutationFn: async () => {
310
- if (!n)
311
- throw new Error("[Ecency][Wallets] - No seed to create a wallet");
312
- const r = P(t), c = await (r == null ? void 0 : r.getDerivedPrivateKey({
313
- mnemonic: n,
314
- hdPath: z[t]
315
- }));
316
- await Q(1e3);
317
- const h = await (r == null ? void 0 : r.getNewAddress({
318
- privateKey: c
319
- }));
320
- return {
321
- privateKey: c,
322
- address: h.address,
323
- publicKey: h.publicKey,
324
- username: e,
325
- currency: t
326
- };
327
- },
328
- onSuccess: (r) => {
329
- o.setQueryData(
330
- ["ecency-wallets", "wallets", r.username],
331
- (c) => new Map(c ? Array.from(c.entries()) : []).set(r.currency, r)
332
- );
333
- }
334
- }), i = N(() => {
335
- }, []);
336
- return {
337
- createWallet: s,
338
- importWallet: i
339
- };
340
- }
341
- function X(e) {
342
- const { data: t } = w({
343
- queryKey: ["ecency-wallets", "wallets", e]
344
- }), { data: n } = U(e);
345
- return l({
346
- mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
347
- mutationFn: ({ currency: o, address: s }) => fetch(p.privateApiHost + "/private-api/wallets-add", {
348
- method: "POST",
349
- headers: {
350
- "Content-Type": "application/json"
351
- },
352
- body: JSON.stringify({
353
- username: e,
354
- token: o,
355
- address: s,
356
- meta: {
357
- ownerPublicKey: n == null ? void 0 : n.ownerPubkey,
358
- activePublicKey: n == null ? void 0 : n.activePubkey,
359
- postingPublicKey: n == null ? void 0 : n.postingPubkey,
360
- memoPublicKey: n == null ? void 0 : n.memoPubkey,
361
- ...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
362
- (i, [r, c]) => ({
363
- ...i,
364
- [r]: c.address
365
- }),
366
- {}
367
- )
368
- }
369
- })
370
- })
371
- });
372
- }
373
- function A() {
374
- return l({
375
- mutationKey: ["ecency-wallets", "check-wallet-existence"],
376
- mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
377
- p.privateApiHost + "/private-api/wallets-exist",
378
- {
379
- method: "POST",
380
- headers: {
381
- "Content-Type": "application/json"
382
- },
383
- body: JSON.stringify({
384
- address: e,
385
- token: t
386
- })
387
- }
388
- )).json()).length === 0
389
- });
390
- }
391
- const Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
392
- __proto__: null,
393
- useCheckWalletExistence: A,
394
- useCreateAccountWithWallets: X
395
- }, Symbol.toStringTag, { value: "Module" })), Y = {
396
- [a.BTC]: ["m/84'/0'/0'/0/0"],
397
- [a.ETH]: ["m/84'/60'/0'/0/0"],
398
- // its not working for Trust, Exodus, todo: check others below
399
- [a.SOL]: ["m/84'/501'/0'/0/0"],
400
- [a.TRON]: ["m/44'/195'/0'/0'/0'"],
401
- [a.APT]: ["m/84'/637'/0'/0/0"],
402
- [a.TON]: [],
403
- // Disabled
404
- [a.ATOM]: ["m/84'/118'/0'/0'/0"]
405
- };
406
- async function Z(e, t, n) {
407
- for (const o of Y[n] || [])
408
- try {
409
- const s = await t.getDerivedPrivateKey({
410
- mnemonic: e,
411
- hdPath: o
412
- }), i = await t.getNewAddress({
413
- privateKey: s,
414
- addressType: n === a.BTC ? "segwit_native" : void 0
415
- });
416
- return [s.toString(), i.address];
417
- } catch {
418
- return [];
419
- }
420
- return [];
421
- }
422
- function _e(e, t) {
423
- const n = b(), { mutateAsync: o } = A();
424
- return l({
425
- mutationKey: ["ecency-wallets", "import-wallet", e, t],
426
- mutationFn: async ({ privateKeyOrSeed: s }) => {
427
- const i = P(t);
428
- if (!i)
429
- throw new Error("Cannot find token for this currency");
430
- const r = s.split(" ").length === 12;
431
- let c, h = s;
432
- if (r ? [h, c] = await Z(
433
- s,
434
- i,
435
- t
436
- ) : c = (await i.getNewAddress({
437
- privateKey: s
438
- })).address, !c || !s)
439
- throw new Error(
440
- "Private key/seed phrase isn't matching with public key or token"
441
- );
442
- if (!await o({
443
- address: c,
444
- currency: t
445
- }))
446
- throw new Error(
447
- "This wallet has already in use by Hive account. Please, try another one"
448
- );
449
- return {
450
- privateKey: h,
451
- address: c,
452
- publicKey: ""
453
- };
454
- },
455
- onSuccess: ({ privateKey: s, publicKey: i, address: r }) => {
456
- n.setQueryData(
457
- ["ecency-wallets", "wallets", e],
458
- (c) => new Map(c ? Array.from(c.entries()) : []).set(t, {
459
- privateKey: s,
460
- publicKey: i,
461
- address: r,
462
- username: e,
463
- currency: t,
464
- custom: !0
465
- })
466
- );
467
- }
468
- });
469
- }
470
- function ee(e) {
54
+ function A(e) {
471
55
  let t = atob(e);
472
56
  if (t[0] === "{")
473
57
  return JSON.parse(t);
474
58
  }
475
- const y = (e) => {
59
+ const p = (e) => {
476
60
  try {
477
- const t = p.storage.getItem(
478
- p.storagePrefix + "_user_" + e
61
+ const t = a.storage.getItem(
62
+ a.storagePrefix + "_user_" + e
479
63
  );
480
- return ee(JSON.parse(t));
64
+ return A(JSON.parse(t));
481
65
  } catch (t) {
482
66
  console.error(t);
483
67
  return;
484
68
  }
485
- }, te = (e) => y(e) && y(e).accessToken, ne = (e) => y(e) && y(e).postingKey;
486
- function oe(e = [], t, n) {
487
- return l({
69
+ }, D = (e) => p(e) && p(e).accessToken, F = (e) => p(e) && p(e).postingKey, x = (e) => p(e) && p(e).refreshToken;
70
+ function T(e = [], t, n) {
71
+ return f({
488
72
  mutationKey: [...e, t],
489
- mutationFn: async (o) => {
73
+ mutationFn: async (i) => {
490
74
  if (!t)
491
75
  throw new Error(
492
76
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
493
77
  );
494
- const s = ne(t);
495
- if (s) {
496
- const r = u.fromString(s);
497
- return p.hiveClient.broadcast.sendOperations(
498
- n(o),
499
- r
78
+ const o = F(t);
79
+ if (o) {
80
+ const c = y.fromString(o);
81
+ return a.hiveClient.broadcast.sendOperations(
82
+ n(i),
83
+ c
500
84
  );
501
85
  }
502
- let i = te(t);
503
- if (i)
504
- return (await new T.Client({
505
- accessToken: i
506
- }).broadcast(n(o))).result;
86
+ let s = D(t);
87
+ if (s)
88
+ return (await new v.Client({
89
+ accessToken: s
90
+ }).broadcast(n(i))).result;
507
91
  throw new Error(
508
92
  "[SDK][Broadcast] – cannot broadcast w/o posting key or token"
509
93
  );
510
94
  }
511
95
  });
512
96
  }
513
- function ae(e) {
514
- return oe(
97
+ function d() {
98
+ return new O({
99
+ defaultOptions: {
100
+ queries: {
101
+ // With SSR, we usually want to set some default staleTime
102
+ // above 0 to avoid refetching immediately on the client
103
+ // staleTime: 60 * 1000,
104
+ refetchOnWindowFocus: !1,
105
+ refetchOnMount: !1
106
+ }
107
+ }
108
+ });
109
+ }
110
+ const u = Q ? b(() => d()) : () => d();
111
+ var w;
112
+ ((e) => {
113
+ function t(r) {
114
+ return u().getQueryData(r);
115
+ }
116
+ e.getQueryData = t;
117
+ function n(r) {
118
+ return u().getQueryData(r);
119
+ }
120
+ e.getInfiniteQueryData = n;
121
+ async function i(r) {
122
+ return await u().prefetchQuery(r), t(r.queryKey);
123
+ }
124
+ e.prefetchQuery = i;
125
+ async function o(r) {
126
+ return await u().prefetchInfiniteQuery(r), n(r.queryKey);
127
+ }
128
+ e.prefetchInfiniteQuery = o;
129
+ function s(r) {
130
+ return {
131
+ prefetch: () => i(r),
132
+ getData: () => t(r.queryKey),
133
+ useClientQuery: () => S(r),
134
+ fetchAndGet: () => u().fetchQuery(r)
135
+ };
136
+ }
137
+ e.generateClientServerQuery = s;
138
+ function c(r) {
139
+ return {
140
+ prefetch: () => o(r),
141
+ getData: () => n(r.queryKey),
142
+ useClientQuery: () => k(r),
143
+ fetchAndGet: () => u().fetchInfiniteQuery(r)
144
+ };
145
+ }
146
+ e.generateClientServerInfiniteQuery = c;
147
+ })(w || (w = {}));
148
+ function E(e) {
149
+ return T(
515
150
  ["accounts", "update"],
516
151
  e,
517
152
  ({
@@ -533,36 +168,36 @@ function ae(e) {
533
168
  ]
534
169
  );
535
170
  }
536
- function je(e) {
537
- return f({
171
+ function U(e) {
172
+ return l({
538
173
  queryKey: ["get-account-full", e],
539
174
  queryFn: async () => {
540
175
  if (!e)
541
176
  throw new Error("[SDK] Username is empty");
542
- const t = await p.hiveClient.database.getAccounts([e]);
177
+ const t = await a.hiveClient.database.getAccounts([e]);
543
178
  if (!t[0])
544
179
  throw new Error("[SDK] No account with given username");
545
180
  const n = JSON.parse(t[0].posting_json_metadata).profile;
546
- let o;
181
+ let i;
547
182
  try {
548
- o = await p.hiveClient.database.call(
183
+ i = await a.hiveClient.database.call(
549
184
  "get_follow_count",
550
185
  [e]
551
186
  );
552
187
  } catch {
553
188
  }
554
- const s = await p.hiveClient.call(
189
+ const o = await a.hiveClient.call(
555
190
  "condenser_api",
556
191
  "get_account_reputations",
557
192
  [e, 1]
558
193
  );
559
194
  return {
560
195
  ...t,
561
- follow_stats: o,
562
- reputation: s[0].reputation,
196
+ follow_stats: i,
197
+ reputation: o[0].reputation,
563
198
  profile: {
564
199
  ...n,
565
- reputation: s[0].reputation
200
+ reputation: o[0].reputation
566
201
  }
567
202
  };
568
203
  },
@@ -570,38 +205,20 @@ function je(e) {
570
205
  staleTime: 6e4
571
206
  });
572
207
  }
573
- function De(e, t = 5, n = []) {
574
- return f({
208
+ function G(e, t = 5, n = []) {
209
+ return l({
575
210
  queryKey: ["accounts", "search", e, n],
576
211
  enabled: !!e,
577
- queryFn: async () => (await p.hiveClient.database.call(
212
+ queryFn: async () => (await a.hiveClient.database.call(
578
213
  "lookup_accounts",
579
214
  [e, t]
580
215
  )).filter(
581
- (s) => n.length > 0 ? !n.includes(s) : !0
216
+ (o) => n.length > 0 ? !n.includes(o) : !0
582
217
  )
583
218
  });
584
219
  }
585
- function Fe(e) {
586
- const { mutateAsync: t } = ae(e);
587
- return l({
588
- mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
589
- mutationFn: ({
590
- wallets: n
591
- }) => t({
592
- profile: {},
593
- tokens: Array.from(n.entries() ?? []).map(([o, s]) => ({
594
- symbol: o,
595
- type: "CHAIN",
596
- meta: {
597
- address: s.address
598
- }
599
- }))
600
- })
601
- });
602
- }
603
- function Ee(e) {
604
- return l({
220
+ function M(e) {
221
+ return f({
605
222
  mutationKey: ["operations", "sign", e],
606
223
  mutationFn: ({
607
224
  operation: t,
@@ -609,62 +226,98 @@ function Ee(e) {
609
226
  }) => {
610
227
  if (!e)
611
228
  throw new Error("[Operations][Sign] – cannot sign op with anon user");
612
- let o;
613
- return n.split(" ").length === 12 ? o = u.fromLogin(e, n, "active") : B.isWif(n) ? o = u.fromString(n) : o = u.from(n), p.hiveClient.broadcast.sendOperations(
229
+ let i;
230
+ return n.split(" ").length === 12 ? i = y.fromLogin(e, n, "active") : _.isWif(n) ? i = y.fromString(n) : i = y.from(n), a.hiveClient.broadcast.sendOperations(
614
231
  [t],
615
- o
232
+ i
616
233
  );
617
234
  }
618
235
  });
619
236
  }
620
- const se = (e, t, n, o = null) => new Promise((s, i) => {
621
- var r;
622
- (r = window.hive_keychain) == null || r.requestBroadcast(
237
+ function j() {
238
+ return new Promise((e) => {
239
+ var t;
240
+ (t = window.hive_keychain) == null || t.requestHandshake(() => {
241
+ e();
242
+ });
243
+ });
244
+ }
245
+ const m = (e, t, n, i = null) => new Promise((o, s) => {
246
+ var c;
247
+ (c = window.hive_keychain) == null || c.requestBroadcast(
623
248
  e,
624
249
  t,
625
250
  n,
626
- (c) => {
627
- c.success || i({ message: "Operation cancelled" }), s(c);
251
+ (r) => {
252
+ r.success || s({ message: "Operation cancelled" }), o(r);
628
253
  },
629
- o
254
+ i
630
255
  );
631
- });
632
- function Le(e, t = "Active") {
633
- return l({
256
+ }), W = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
257
+ __proto__: null,
258
+ broadcast: m,
259
+ handshake: j
260
+ }, Symbol.toStringTag, { value: "Module" }));
261
+ function z(e, t = "Active") {
262
+ return f({
634
263
  mutationKey: ["operations", "sign-keychain", e],
635
264
  mutationFn: ({ operation: n }) => {
636
265
  if (!e)
637
266
  throw new Error(
638
267
  "[SDK][Keychain] – cannot sign operation with anon user"
639
268
  );
640
- return se(e, [n], t);
269
+ return m(e, [n], t);
641
270
  }
642
271
  });
643
272
  }
644
- function xe(e = "/") {
645
- return l({
273
+ function R(e = "/") {
274
+ return f({
646
275
  mutationKey: ["operations", "sign-hivesigner", e],
647
- mutationFn: async ({ operation: t }) => T.sendOperation(t, { callback: e }, () => {
276
+ mutationFn: async ({ operation: t }) => v.sendOperation(t, { callback: e }, () => {
648
277
  })
649
278
  });
650
279
  }
280
+ function $(e, t) {
281
+ return l({
282
+ queryKey: ["hive-engine", "tokens-list", e, t],
283
+ queryFn: async () => (await (await fetch(
284
+ `${a.privateApiHost}/private-api/engine-api`,
285
+ {
286
+ method: "POST",
287
+ body: JSON.stringify({
288
+ jsonrpc: "2.0",
289
+ method: "find",
290
+ params: {
291
+ contract: "market",
292
+ table: "metrics",
293
+ query: {
294
+ symbol: t,
295
+ account: e
296
+ }
297
+ },
298
+ id: 1
299
+ }),
300
+ headers: { "Content-type": "application/json" }
301
+ }
302
+ )).json()).result
303
+ });
304
+ }
651
305
  export {
652
- d as EcencyWalletBasicTokens,
653
- a as EcencyWalletCurrency,
654
- Ne as EcencyWalletsPrivateApi,
655
- je as getAccountFullQueryOptions,
656
- Ce as getAccountPointsQueryOptions,
657
- De as getSearchAccountsByUsernameQueryOptions,
658
- ae as useAccountUpdate,
659
- Ke as useCoinGeckoPriceQuery,
660
- Re as useGetAllTokensListQuery,
661
- ke as useGetExternalWalletBalanceQuery,
662
- U as useHiveKeysQuery,
663
- _e as useImportWallet,
664
- Fe as useSaveWalletInformationToMetadata,
665
- O as useSeedPhrase,
666
- xe as useSignOperationByHivesigner,
667
- Ee as useSignOperationByKey,
668
- Le as useSignOperationByKeychain,
669
- He as useWalletCreate
306
+ a as CONFIG,
307
+ w as EcencyQueriesManager,
308
+ W as Keychain,
309
+ D as getAccessToken,
310
+ U as getAccountFullQueryOptions,
311
+ $ as getHiveEngineTokensListQueryOptions,
312
+ F as getPostingKey,
313
+ u as getQueryClient,
314
+ x as getRefreshToken,
315
+ G as getSearchAccountsByUsernameQueryOptions,
316
+ p as getUser,
317
+ d as makeQueryClient,
318
+ E as useAccountUpdate,
319
+ T as useBroadcastMutation,
320
+ R as useSignOperationByHivesigner,
321
+ M as useSignOperationByKey,
322
+ z as useSignOperationByKeychain
670
323
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export * from './modules/wallets';
2
1
  export * from './modules/accounts';
3
2
  export * from './modules/operations';
3
+ export * from './modules/core';
4
+ export * from './modules/hive-engine';
5
+ export * from './modules/keychain';
@@ -1,3 +1,5 @@
1
1
  export * from './mutations';
2
2
  export * from './storage';
3
3
  export * from './entities';
4
+ export * from './config';
5
+ export * from './queries-manager';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/sdk",
3
3
  "private": false,
4
- "version": "1.0.25",
4
+ "version": "1.0.27",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist/ecency-sdk.umd.js",
@@ -17,30 +17,20 @@
17
17
  "preview": "vite preview"
18
18
  },
19
19
  "devDependencies": {
20
- "@hiveio/dhive": "^1.3.2",
21
- "@tanstack/react-query": "^5.74.4",
22
20
  "@types/node": "^22.13.8",
23
21
  "@types/react": "^19.0.10",
24
22
  "@vitejs/plugin-react": "^4.3.4",
25
23
  "eslint": "^9.21.0",
26
- "lru-cache": "^11.0.2",
27
24
  "prettier": "^3.5.2",
28
- "react": "^19.0.0",
29
- "typescript": "5.8.3",
30
25
  "vite": "^6.2.0",
31
26
  "vite-plugin-dts": "4.5.3",
32
27
  "vite-plugin-node-polyfills": "^0.23.0"
33
28
  },
34
29
  "dependencies": {
35
- "@okxweb3/coin-aptos": "^1.2.0",
36
- "@okxweb3/coin-base": "^1.1.2",
37
- "@okxweb3/coin-bitcoin": "^1.2.0",
38
- "@okxweb3/coin-cosmos": "^1.1.0",
39
- "@okxweb3/coin-ethereum": "^1.0.12",
40
- "@okxweb3/coin-solana": "^1.1.0",
41
- "@okxweb3/coin-ton": "^1.1.1-beta.1",
42
- "@okxweb3/coin-tron": "^1.1.0",
43
- "@okxweb3/crypto-lib": "^1.0.10",
30
+ "lru-cache": "^11.0.2",
31
+ "@hiveio/dhive": "^1.3.2",
32
+ "@tanstack/react-query": "^5.74.4",
33
+ "react": "^19.0.0",
44
34
  "bip39": "^3.1.0",
45
35
  "hivesigner": "3.3.4"
46
36
  }
package/Readme.md DELETED
@@ -1,36 +0,0 @@
1
- # Ecency SDK
2
-
3
- [![NPM](https://img.shields.io/npm/v/@ecency/wallets.svg)](https://www.npmjs.com/package/@ecency/wallets) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4
-
5
- ## Overview
6
-
7
- `@ecency/sdk` provides an API for managing Hive blockchain wallets and external cryptocurrency wallets within the Ecency ecosystem.
8
-
9
- ## Installation
10
-
11
- ```sh
12
- yarn add @ecency/sdk
13
- # or
14
- npm install @ecency/sdk
15
- ```
16
-
17
- ## Setup
18
-
19
- 1. Install `react @tanstack/react-query @hiveio/dhive`
20
- 2. Use!
21
-
22
- ## Features
23
-
24
- This package built on top of [@hiveio/dhive](https://www.npmjs.com/package/@hiveio/dhive) and [okweb3](http://okx.github.io/) packages.
25
-
26
- Main functionality is creating wallets based on seed phrase([BIP39](https://www.npmjs.com/package/bip39)) and generating addresses with keys on device. Seed phrases and private keys are never sent to any API, all operations happen locally.
27
-
28
- Supportings tokens: BTC, ETH, SOL, TRX, TON, ATOM, APT – theoretically all child tokens of these systems. Make forks for it.
29
-
30
- ## Roadmap
31
-
32
- - Add more Hive wallets operations
33
- - Allow to sign transactions with external wallets
34
- - Allow to import existing wallets by phrase or private keys
35
- - Support of DASH
36
- - Support of DOGE
@@ -1,7 +0,0 @@
1
- export declare enum EcencyWalletBasicTokens {
2
- Points = "POINTS",
3
- HivePower = "HP",
4
- Hive = "HIVE",
5
- HiveDollar = "HBD",
6
- Spk = "SPK"
7
- }
@@ -1,9 +0,0 @@
1
- export declare enum EcencyWalletCurrency {
2
- BTC = "BTC",
3
- ETH = "ETH",
4
- APT = "APT",
5
- ATOM = "ATOM",
6
- TON = "TON",
7
- TRON = "TRX",
8
- SOL = "SOL"
9
- }
@@ -1,2 +0,0 @@
1
- export * from './ecency-wallet-currency';
2
- export * from './ecency-wallet-basic-tokens';
@@ -1,3 +0,0 @@
1
- import { EcencyWalletCurrency } from '../enums';
2
- import { BaseWallet } from '@okxweb3/coin-base';
3
- export declare function getKeysFromSeed(mnemonic: string, wallet: BaseWallet, currency: EcencyWalletCurrency): Promise<never[] | readonly [any, any]>;
@@ -1 +0,0 @@
1
- export * from './get-keys-from-seed';
@@ -1,4 +0,0 @@
1
- export * from './enums';
2
- export * from './mutations';
3
- export * from './queries';
4
- export * from './types';
@@ -1,4 +0,0 @@
1
- export * from './use-wallet-create';
2
- export * from './private-api-namespace';
3
- export * from './use-import-wallet';
4
- export * from './save-wallet-information-to-metadata';
@@ -1,7 +0,0 @@
1
- import { EcencyWalletCurrency } from '../../enums';
2
- interface Payload {
3
- address: string;
4
- currency: EcencyWalletCurrency;
5
- }
6
- export declare function useCheckWalletExistence(): import('@tanstack/react-query').UseMutationResult<boolean, Error, Payload, unknown>;
7
- export {};
@@ -1,7 +0,0 @@
1
- import { EcencyWalletCurrency } from '../../enums';
2
- interface Payload {
3
- currency: EcencyWalletCurrency;
4
- address: string;
5
- }
6
- export declare function useCreateAccountWithWallets(username: string): import('@tanstack/react-query').UseMutationResult<Response, Error, Payload, unknown>;
7
- export {};
@@ -1,2 +0,0 @@
1
- export * from './create-account-with-wallets';
2
- export * from './check-wallet-existence';
@@ -1,2 +0,0 @@
1
- import * as EcencyWalletsPrivateApi from "./private-api";
2
- export { EcencyWalletsPrivateApi };
@@ -1,5 +0,0 @@
1
- import { EcencyWalletCurrency } from '../enums';
2
- import { EcencyCreateWalletInformation } from '../types';
3
- export declare function useSaveWalletInformationToMetadata(username: string): import('@tanstack/react-query').UseMutationResult<any, Error, {
4
- wallets: Map<EcencyWalletCurrency, EcencyCreateWalletInformation>;
5
- }, unknown>;
@@ -1,10 +0,0 @@
1
- import { EcencyWalletCurrency } from '../enums';
2
- interface Payload {
3
- privateKeyOrSeed: string;
4
- }
5
- export declare function useImportWallet(username: string, currency: EcencyWalletCurrency): import('@tanstack/react-query').UseMutationResult<{
6
- privateKey: string;
7
- address: any;
8
- publicKey: string;
9
- }, Error, Payload, unknown>;
10
- export {};
@@ -1,6 +0,0 @@
1
- import { EcencyCreateWalletInformation } from '../types';
2
- import { EcencyWalletCurrency } from '../enums';
3
- export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
4
- createWallet: import('@tanstack/react-query').UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
5
- importWallet: () => void;
6
- };
@@ -1,9 +0,0 @@
1
- import { AccountPointsResponse } from '../types';
2
- export declare function getAccountPointsQueryOptions(username?: string, filter?: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<AccountPointsResponse, Error, AccountPointsResponse, (string | undefined)[]>, "queryFn"> & {
3
- queryFn?: import('@tanstack/query-core').QueryFunction<AccountPointsResponse, (string | undefined)[], never> | undefined;
4
- } & {
5
- queryKey: (string | undefined)[] & {
6
- [dataTagSymbol]: AccountPointsResponse;
7
- [dataTagErrorSymbol]: Error;
8
- };
9
- };
@@ -1,6 +0,0 @@
1
- export * from './use-get-external-wallet-query';
2
- export * from './use-seed-phrase';
3
- export * from './use-coingecko-price-query';
4
- export * from './use-hive-keys-query';
5
- export * from './get-account-points-query-options';
6
- export * from './use-get-all-tokens-list-query';
@@ -1,2 +0,0 @@
1
- import { EcencyWalletCurrency } from '../enums';
2
- export declare function useCoinGeckoPriceQuery(currency?: EcencyWalletCurrency): import('@tanstack/react-query').UseQueryResult<number, Error>;
@@ -1,9 +0,0 @@
1
- import { EcencyWalletBasicTokens } from '../enums';
2
- export declare function getAccountWalletListQueryOptions(username: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<EcencyWalletBasicTokens[], Error, EcencyWalletBasicTokens[], string[]>, "queryFn"> & {
3
- queryFn?: import('@tanstack/query-core').QueryFunction<EcencyWalletBasicTokens[], string[], never> | undefined;
4
- } & {
5
- queryKey: string[] & {
6
- [dataTagSymbol]: EcencyWalletBasicTokens[];
7
- [dataTagErrorSymbol]: Error;
8
- };
9
- };
@@ -1,6 +0,0 @@
1
- import { EcencyWalletBasicTokens, EcencyWalletCurrency } from '../enums';
2
- export declare function useGetAllTokensListQuery(query: string): {
3
- basic: EcencyWalletBasicTokens[];
4
- external: EcencyWalletCurrency[];
5
- layer2: string[];
6
- };
@@ -1,10 +0,0 @@
1
- import { EcencyWalletCurrency } from '../enums';
2
- /**
3
- * Returns information about the actual balance of the given currency address
4
- * using various of public APIs
5
- * todo extract URLs to configs
6
- * @param currency
7
- * @param address
8
- * @returns
9
- */
10
- export declare function useGetExternalWalletBalanceQuery(currency: EcencyWalletCurrency, address: string): import('@tanstack/react-query').UseQueryResult<number, Error>;
@@ -1,2 +0,0 @@
1
- import { EcencyHiveKeys } from '../types';
2
- export declare function useHiveKeysQuery(username: string): import('@tanstack/react-query').UseQueryResult<EcencyHiveKeys, Error>;
@@ -1 +0,0 @@
1
- export declare function useSeedPhrase(username: string): import('@tanstack/react-query').UseQueryResult<string, Error>;
@@ -1,4 +0,0 @@
1
- export interface AccountPointsResponse {
2
- points: string;
3
- unclaimed_points: string;
4
- }
@@ -1,9 +0,0 @@
1
- import { EcencyWalletCurrency } from '../enums';
2
- export interface EcencyCreateWalletInformation {
3
- address: string;
4
- privateKey: string;
5
- publicKey: string;
6
- username: string;
7
- currency: EcencyWalletCurrency;
8
- custom?: boolean;
9
- }
@@ -1,12 +0,0 @@
1
- export interface EcencyHiveKeys {
2
- username: string;
3
- owner: string;
4
- active: string;
5
- posting: string;
6
- memo: string;
7
- masterPassword: string;
8
- ownerPubkey: string;
9
- activePubkey: string;
10
- postingPubkey: string;
11
- memoPubkey: string;
12
- }
@@ -1,3 +0,0 @@
1
- export * from './ecency-create-wallet-information';
2
- export * from './ecency-hive-keys';
3
- export * from './account-points-response';
@@ -1 +0,0 @@
1
- export declare function delay(ms: number): Promise<unknown>;
@@ -1,3 +0,0 @@
1
- import { BaseWallet } from '@okxweb3/coin-base';
2
- import { EcencyWalletCurrency } from '../enums';
3
- export declare function getWallet(currency: EcencyWalletCurrency): BaseWallet | undefined;
@@ -1,3 +0,0 @@
1
- export * from './delay';
2
- export * from './get-wallet';
3
- export * from './mnemonic-to-seed-bip-39';
@@ -1 +0,0 @@
1
- export declare function mnemonicToSeedBip39(value: string): string;
File without changes