@ecency/sdk 1.0.17 → 1.0.18

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 (50) hide show
  1. package/dist/config.d.ts +8 -0
  2. package/dist/ecency-sdk.es.js +174 -161
  3. package/dist/index.d.ts +3 -0
  4. package/dist/modules/accounts/index.d.ts +2 -0
  5. package/dist/modules/accounts/mutations/index.d.ts +1 -0
  6. package/dist/modules/accounts/mutations/use-account-update.d.ts +1 -0
  7. package/dist/modules/accounts/queries/index.d.ts +1 -0
  8. package/dist/modules/accounts/queries/search-accounts-by-username-query-options.d.ts +8 -0
  9. package/dist/modules/core/entities/index.d.ts +1 -0
  10. package/dist/modules/core/entities/user.d.ts +8 -0
  11. package/dist/modules/core/index.d.ts +3 -0
  12. package/dist/modules/core/mutations/index.d.ts +1 -0
  13. package/dist/modules/core/mutations/use-broadcast-mutation.d.ts +3 -0
  14. package/dist/modules/core/storage.d.ts +5 -0
  15. package/dist/modules/core/utils/decoder-encoder.d.ts +2 -0
  16. package/dist/modules/core/utils/index.d.ts +1 -0
  17. package/dist/modules/keychain/index.d.ts +2 -0
  18. package/dist/modules/keychain/keychain.d.ts +9 -0
  19. package/dist/modules/operations/index.d.ts +1 -0
  20. package/dist/modules/operations/mutations/index.d.ts +3 -0
  21. package/dist/modules/operations/mutations/sign-operation-by-hivesigner.d.ts +4 -0
  22. package/dist/modules/operations/mutations/sign-operation-by-key.d.ts +5 -0
  23. package/dist/modules/operations/mutations/sign-operation-by-keychain.d.ts +5 -0
  24. package/dist/modules/wallets/enums/ecency-wallet-currency.d.ts +9 -0
  25. package/dist/modules/wallets/enums/index.d.ts +1 -0
  26. package/dist/modules/wallets/functions/get-keys-from-seed.d.ts +3 -0
  27. package/dist/modules/wallets/functions/index.d.ts +1 -0
  28. package/dist/modules/wallets/index.d.ts +5 -0
  29. package/dist/modules/wallets/mutations/index.d.ts +4 -0
  30. package/dist/modules/wallets/mutations/private-api/check-wallet-existence.d.ts +7 -0
  31. package/dist/modules/wallets/mutations/private-api/create-account-with-wallets.d.ts +7 -0
  32. package/dist/modules/wallets/mutations/private-api/index.d.ts +2 -0
  33. package/dist/modules/wallets/mutations/private-api-namespace.d.ts +2 -0
  34. package/dist/modules/wallets/mutations/save-wallet-information-to-metadata.d.ts +5 -0
  35. package/dist/modules/wallets/mutations/use-import-wallet.d.ts +10 -0
  36. package/dist/modules/wallets/mutations/use-wallet-create.d.ts +6 -0
  37. package/dist/modules/wallets/queries/index.d.ts +4 -0
  38. package/dist/modules/wallets/queries/use-coingecko-price-query.d.ts +2 -0
  39. package/dist/modules/wallets/queries/use-get-external-wallet-query.d.ts +10 -0
  40. package/dist/modules/wallets/queries/use-hive-keys-query.d.ts +2 -0
  41. package/dist/modules/wallets/queries/use-seed-phrase.d.ts +1 -0
  42. package/dist/modules/wallets/types/ecency-create-wallet-information.d.ts +9 -0
  43. package/dist/modules/wallets/types/ecency-hive-keys.d.ts +12 -0
  44. package/dist/modules/wallets/types/index.d.ts +2 -0
  45. package/dist/modules/wallets/utils/delay.d.ts +1 -0
  46. package/dist/modules/wallets/utils/get-wallet.d.ts +3 -0
  47. package/dist/modules/wallets/utils/index.d.ts +3 -0
  48. package/dist/modules/wallets/utils/mnemonic-to-seed-bip-39.d.ts +1 -0
  49. package/package.json +5 -5
  50. package/dist/ecency-sdk.es.d.ts +0 -136
@@ -0,0 +1,8 @@
1
+ import { Client } from '@hiveio/dhive';
2
+ export declare const CONFIG: {
3
+ privateApiHost: string;
4
+ storage: Storage;
5
+ storagePrefix: string;
6
+ hiveClient: Client;
7
+ heliusApiKey: any;
8
+ };
@@ -1,48 +1,48 @@
1
1
  import { useCallback as k } from "react";
2
- import { useQuery as h, useQueryClient as f, useMutation as l } from "@tanstack/react-query";
3
- import { BtcWallet as A } from "@okxweb3/coin-bitcoin";
4
- import { EthWallet as K } from "@okxweb3/coin-ethereum";
5
- import { TrxWallet as R } from "@okxweb3/coin-tron";
6
- import { TonWallet as C } from "@okxweb3/coin-ton";
7
- import { SolWallet as N } from "@okxweb3/coin-solana";
8
- import { AtomWallet as x } from "@okxweb3/coin-cosmos";
2
+ import { useQuery as m, useQueryClient as w, useMutation as l, queryOptions as A } from "@tanstack/react-query";
3
+ import { BtcWallet as K } from "@okxweb3/coin-bitcoin";
4
+ import { EthWallet as R } from "@okxweb3/coin-ethereum";
5
+ import { TrxWallet as C } from "@okxweb3/coin-tron";
6
+ import { TonWallet as N } from "@okxweb3/coin-ton";
7
+ import { SolWallet as _ } from "@okxweb3/coin-solana";
8
+ import { AtomWallet as B } from "@okxweb3/coin-cosmos";
9
9
  import { AptosWallet as D } from "@okxweb3/coin-aptos";
10
- import _, { mnemonicToSeedSync as j } from "bip39";
11
- import { Client as B, PrivateKey as p, cryptoUtils as H } from "@hiveio/dhive";
12
- import { LRUCache as E } from "lru-cache";
10
+ import j, { mnemonicToSeedSync as H } from "bip39";
11
+ import { Client as x, PrivateKey as p, cryptoUtils as E } from "@hiveio/dhive";
12
+ import { LRUCache as F } from "lru-cache";
13
13
  import g from "hivesigner";
14
- var o = /* @__PURE__ */ ((t) => (t.BTC = "BTC", t.ETH = "ETH", t.APT = "APT", t.ATOM = "ATOM", t.TON = "TON", t.TRON = "TRX", t.SOL = "SOL", t))(o || {});
15
- function F(t) {
16
- return new Promise((e) => setTimeout(e, t));
14
+ var o = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(o || {});
15
+ function W(e) {
16
+ return new Promise((t) => setTimeout(t, e));
17
17
  }
18
- function T(t) {
19
- switch (t) {
18
+ function T(e) {
19
+ switch (e) {
20
20
  case o.BTC:
21
- return new A();
22
- case o.ETH:
23
21
  return new K();
24
- case o.TRON:
22
+ case o.ETH:
25
23
  return new R();
26
- case o.TON:
24
+ case o.TRON:
27
25
  return new C();
28
- case o.SOL:
26
+ case o.TON:
29
27
  return new N();
28
+ case o.SOL:
29
+ return new _();
30
30
  case o.ATOM:
31
- return new x();
31
+ return new B();
32
32
  case o.APT:
33
33
  return new D();
34
34
  default:
35
35
  return;
36
36
  }
37
37
  }
38
- function gt(t) {
39
- return j(t).toString("hex");
38
+ function Te(e) {
39
+ return H(e).toString("hex");
40
40
  }
41
41
  const u = {
42
42
  privateApiHost: "https://ecency.com",
43
43
  storage: localStorage,
44
44
  storagePrefix: "ecency",
45
- hiveClient: new B(
45
+ hiveClient: new x(
46
46
  [
47
47
  "https://api.hive.blog",
48
48
  "https://api.deathwing.me",
@@ -64,19 +64,19 @@ const u = {
64
64
  ),
65
65
  heliusApiKey: "fb1e2935-f911-4b1d-8e1c-3863f6879d42"
66
66
  };
67
- function Tt(t, e) {
68
- return h({
69
- queryKey: ["ecency-wallets", "external-wallet-balance", t, e],
67
+ function be(e, t) {
68
+ return m({
69
+ queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
70
70
  queryFn: async () => {
71
- switch (t) {
71
+ switch (e) {
72
72
  case o.BTC:
73
73
  const a = await (await fetch(
74
- `https://mempool.space/api/address/${e}`
74
+ `https://mempool.space/api/address/${t}`
75
75
  )).json();
76
76
  return (a.chain_stats.funded_txo_sum - a.chain_stats.spent_txo_sum) / 1e8;
77
77
  case o.ETH:
78
78
  return +(await (await fetch(
79
- `https://api.ethplorer.io/getAddressInfo/${e}?apiKey=freekey`
79
+ `https://api.ethplorer.io/getAddressInfo/${t}?apiKey=freekey`
80
80
  )).json()).ETH.balance;
81
81
  case o.SOL:
82
82
  return (await (await fetch(
@@ -87,7 +87,7 @@ function Tt(t, e) {
87
87
  jsonrpc: "2.0",
88
88
  id: "1",
89
89
  method: "getBalance",
90
- params: [e]
90
+ params: [t]
91
91
  }),
92
92
  headers: {
93
93
  "Content-Type": "application/json"
@@ -96,34 +96,34 @@ function Tt(t, e) {
96
96
  )).json()).result.value / 1e9;
97
97
  case o.TRON:
98
98
  return (await (await fetch(
99
- `https://api.trongrid.io/v1/accounts/${e}`
99
+ `https://api.trongrid.io/v1/accounts/${t}`
100
100
  )).json()).data[0].balance / 1e6;
101
101
  case o.TON:
102
102
  return (await (await fetch(
103
- `https://tonapi.io/v1/blockchain/getAccount?account=${e}`
103
+ `https://tonapi.io/v1/blockchain/getAccount?account=${t}`
104
104
  )).json()).balance / 1e9;
105
105
  case o.APT:
106
- const y = (await (await fetch(
107
- `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${e}/resources`
106
+ const f = (await (await fetch(
107
+ `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
108
108
  )).json()).find(
109
109
  (O) => O.type.includes("coin::CoinStore")
110
110
  );
111
- return y ? parseInt(y.data.coin.value) / 1e8 : 0;
111
+ return f ? parseInt(f.data.coin.value) / 1e8 : 0;
112
112
  case o.ATOM:
113
113
  return +(await (await fetch(
114
- `https://rest.cosmos.directory/cosmoshub/auth/accounts/${e}`
114
+ `https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
115
115
  )).json()).result.value.coins[0].amount / 1e6;
116
116
  }
117
117
  }
118
118
  });
119
119
  }
120
- function b(t) {
121
- return h({
122
- queryKey: ["ecency-wallets", "seed", t],
123
- queryFn: async () => _.generateMnemonic(128)
120
+ function b(e) {
121
+ return m({
122
+ queryKey: ["ecency-wallets", "seed", e],
123
+ queryFn: async () => j.generateMnemonic(128)
124
124
  });
125
125
  }
126
- const W = {
126
+ const q = {
127
127
  max: 500,
128
128
  // how long to live in ms
129
129
  ttl: 1e3 * 60 * 5,
@@ -131,32 +131,32 @@ const W = {
131
131
  allowStale: !1,
132
132
  updateAgeOnGet: !1,
133
133
  updateAgeOnHas: !1
134
- }, v = new E(W), w = Symbol("undefined"), L = (t, e) => v.set(t, e === void 0 ? w : e), M = (t) => {
135
- const e = v.get(t);
136
- return e === w ? void 0 : e;
134
+ }, v = new F(q), y = Symbol("undefined"), M = (e, t) => v.set(e, t === void 0 ? y : t), L = (e) => {
135
+ const t = v.get(e);
136
+ return t === y ? void 0 : t;
137
137
  };
138
- function bt(t) {
139
- return h({
140
- queryKey: ["ecency-wallets", "coingecko-price", t],
138
+ function ve(e) {
139
+ return m({
140
+ queryKey: ["ecency-wallets", "coingecko-price", e],
141
141
  queryFn: async () => {
142
- let e = t;
143
- switch (t) {
142
+ let t = e;
143
+ switch (e) {
144
144
  case o.BTC:
145
- e = "binance-wrapped-btc";
145
+ t = "binance-wrapped-btc";
146
146
  break;
147
147
  case o.ETH:
148
- e = "ethereum";
148
+ t = "ethereum";
149
149
  break;
150
150
  case o.SOL:
151
- e = "solana";
151
+ t = "solana";
152
152
  break;
153
153
  case o.TON:
154
- e = "trx";
154
+ t = "trx";
155
155
  break;
156
156
  default:
157
- e = t;
157
+ t = e;
158
158
  }
159
- let n = M("gecko"), a;
159
+ let n = L("gecko"), a;
160
160
  if (n)
161
161
  a = n;
162
162
  else {
@@ -166,29 +166,29 @@ function bt(t) {
166
166
  method: "POST",
167
167
  body: JSON.stringify({
168
168
  params: {
169
- ids: [e],
169
+ ids: [t],
170
170
  vs_currencies: "usd"
171
171
  }
172
172
  })
173
173
  }
174
174
  )).json();
175
- L("gecko", i === void 0 ? w : i), a = i;
175
+ M("gecko", i === void 0 ? y : i), a = i;
176
176
  }
177
177
  return 1 / +a[Object.keys(a)[0]].usd;
178
178
  },
179
- enabled: !!t
179
+ enabled: !!e
180
180
  });
181
181
  }
182
- function q(t) {
183
- const { data: e } = b(t);
184
- return h({
185
- queryKey: ["ecencу-wallets", "hive-keys", t, e],
182
+ function Q(e) {
183
+ const { data: t } = b(e);
184
+ return m({
185
+ queryKey: ["ecencу-wallets", "hive-keys", e, t],
186
186
  queryFn: async () => {
187
- if (!e)
187
+ if (!t)
188
188
  throw new Error("[Ecency][Wallets] - no seed to create Hive account");
189
- const n = p.fromLogin(t, e, "owner"), a = p.fromLogin(t, e, "active"), s = p.fromLogin(t, e, "posting"), r = p.fromLogin(t, e, "memo");
189
+ const n = p.fromLogin(e, t, "owner"), a = p.fromLogin(e, t, "active"), s = p.fromLogin(e, t, "posting"), r = p.fromLogin(e, t, "memo");
190
190
  return {
191
- username: t,
191
+ username: e,
192
192
  owner: n.toString(),
193
193
  active: a.toString(),
194
194
  posting: s.toString(),
@@ -217,26 +217,26 @@ const I = {
217
217
  [o.ATOM]: "m/44'/118'/0'/0/0"
218
218
  // Cosmos (BIP44)
219
219
  };
220
- function vt(t, e) {
221
- const { data: n } = b(t), a = f(), s = l({
222
- mutationKey: ["ecency-wallets", "create-wallet", t, e],
220
+ function Pe(e, t) {
221
+ const { data: n } = b(e), a = w(), s = l({
222
+ mutationKey: ["ecency-wallets", "create-wallet", e, t],
223
223
  mutationFn: async () => {
224
224
  if (!n)
225
225
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
226
- const i = T(e), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
226
+ const i = T(t), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
227
227
  mnemonic: n,
228
- hdPath: I[e]
228
+ hdPath: I[t]
229
229
  }));
230
- await F(1e3);
231
- const m = await (i == null ? void 0 : i.getNewAddress({
230
+ await W(1e3);
231
+ const h = await (i == null ? void 0 : i.getNewAddress({
232
232
  privateKey: c
233
233
  }));
234
234
  return {
235
235
  privateKey: c,
236
- address: m.address,
237
- publicKey: m.publicKey,
238
- username: t,
239
- currency: e
236
+ address: h.address,
237
+ publicKey: h.publicKey,
238
+ username: e,
239
+ currency: t
240
240
  };
241
241
  },
242
242
  onSuccess: (i) => {
@@ -252,19 +252,19 @@ function vt(t, e) {
252
252
  importWallet: r
253
253
  };
254
254
  }
255
- function J(t) {
256
- const { data: e } = h({
257
- queryKey: ["ecency-wallets", "wallets", t]
258
- }), { data: n } = q(t);
255
+ function J(e) {
256
+ const { data: t } = m({
257
+ queryKey: ["ecency-wallets", "wallets", e]
258
+ }), { data: n } = Q(e);
259
259
  return l({
260
- mutationKey: ["ecency-wallets", "create-account-with-wallets", t],
260
+ mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
261
261
  mutationFn: ({ currency: a, address: s }) => fetch(u.privateApiHost + "/private-api/wallets-add", {
262
262
  method: "POST",
263
263
  headers: {
264
264
  "Content-Type": "application/json"
265
265
  },
266
266
  body: JSON.stringify({
267
- username: t,
267
+ username: e,
268
268
  token: a,
269
269
  address: s,
270
270
  meta: {
@@ -272,7 +272,7 @@ function J(t) {
272
272
  activePublicKey: n == null ? void 0 : n.activePubkey,
273
273
  postingPublicKey: n == null ? void 0 : n.postingPubkey,
274
274
  memoPublicKey: n == null ? void 0 : n.memoPubkey,
275
- ...Array.from((e == null ? void 0 : e.entries()) ?? []).reduce(
275
+ ...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
276
276
  (r, [i, c]) => ({
277
277
  ...r,
278
278
  [i]: c.address
@@ -287,7 +287,7 @@ function J(t) {
287
287
  function P() {
288
288
  return l({
289
289
  mutationKey: ["ecency-wallets", "check-wallet-existence"],
290
- mutationFn: async ({ address: t, currency: e }) => (await (await fetch(
290
+ mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
291
291
  u.privateApiHost + "/private-api/wallets-exist",
292
292
  {
293
293
  method: "POST",
@@ -295,18 +295,18 @@ function P() {
295
295
  "Content-Type": "application/json"
296
296
  },
297
297
  body: JSON.stringify({
298
- address: t,
299
- token: e
298
+ address: e,
299
+ token: t
300
300
  })
301
301
  }
302
302
  )).json()).length === 0
303
303
  });
304
304
  }
305
- const Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
305
+ const Se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
306
306
  __proto__: null,
307
307
  useCheckWalletExistence: P,
308
308
  useCreateAccountWithWallets: J
309
- }, Symbol.toStringTag, { value: "Module" })), Q = {
309
+ }, Symbol.toStringTag, { value: "Module" })), $ = {
310
310
  [o.BTC]: ["m/84'/0'/0'/0/0"],
311
311
  [o.ETH]: ["m/84'/60'/0'/0/0"],
312
312
  // its not working for Trust, Exodus, todo: check others below
@@ -317,13 +317,13 @@ const Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
317
317
  // Disabled
318
318
  [o.ATOM]: ["m/84'/118'/0'/0'/0"]
319
319
  };
320
- async function $(t, e, n) {
321
- for (const a of Q[n] || [])
320
+ async function G(e, t, n) {
321
+ for (const a of $[n] || [])
322
322
  try {
323
- const s = await e.getDerivedPrivateKey({
324
- mnemonic: t,
323
+ const s = await t.getDerivedPrivateKey({
324
+ mnemonic: e,
325
325
  hdPath: a
326
- }), r = await e.getNewAddress({
326
+ }), r = await t.getNewAddress({
327
327
  privateKey: s,
328
328
  addressType: n === o.BTC ? "segwit_native" : void 0
329
329
  });
@@ -333,20 +333,20 @@ async function $(t, e, n) {
333
333
  }
334
334
  return [];
335
335
  }
336
- function St(t, e) {
337
- const n = f(), { mutateAsync: a } = P();
336
+ function Oe(e, t) {
337
+ const n = w(), { mutateAsync: a } = P();
338
338
  return l({
339
- mutationKey: ["ecency-wallets", "import-wallet", t, e],
339
+ mutationKey: ["ecency-wallets", "import-wallet", e, t],
340
340
  mutationFn: async ({ privateKeyOrSeed: s }) => {
341
- const r = T(e);
341
+ const r = T(t);
342
342
  if (!r)
343
343
  throw new Error("Cannot find token for this currency");
344
344
  const i = s.split(" ").length === 12;
345
- let c, m = s;
346
- if (i ? [m, c] = await $(
345
+ let c, h = s;
346
+ if (i ? [h, c] = await G(
347
347
  s,
348
348
  r,
349
- e
349
+ t
350
350
  ) : c = (await r.getNewAddress({
351
351
  privateKey: s
352
352
  })).address, !c || !s)
@@ -355,57 +355,57 @@ function St(t, e) {
355
355
  );
356
356
  if (!await a({
357
357
  address: c,
358
- currency: e
358
+ currency: t
359
359
  }))
360
360
  throw new Error(
361
361
  "This wallet has already in use by Hive account. Please, try another one"
362
362
  );
363
363
  return {
364
- privateKey: m,
364
+ privateKey: h,
365
365
  address: c,
366
366
  publicKey: ""
367
367
  };
368
368
  },
369
369
  onSuccess: ({ privateKey: s, publicKey: r, address: i }) => {
370
370
  n.setQueryData(
371
- ["ecency-wallets", "wallets", t],
372
- (c) => new Map(c ? Array.from(c.entries()) : []).set(e, {
371
+ ["ecency-wallets", "wallets", e],
372
+ (c) => new Map(c ? Array.from(c.entries()) : []).set(t, {
373
373
  privateKey: s,
374
374
  publicKey: r,
375
375
  address: i,
376
- username: t,
377
- currency: e,
376
+ username: e,
377
+ currency: t,
378
378
  custom: !0
379
379
  })
380
380
  );
381
381
  }
382
382
  });
383
383
  }
384
- function G(t) {
385
- let e = atob(t);
386
- if (e[0] === "{")
387
- return JSON.parse(e);
384
+ function U(e) {
385
+ let t = atob(e);
386
+ if (t[0] === "{")
387
+ return JSON.parse(t);
388
388
  }
389
- const d = (t) => {
389
+ const d = (e) => {
390
390
  try {
391
- const e = u.storage.getItem(
392
- u.storagePrefix + "_user_" + t
391
+ const t = u.storage.getItem(
392
+ u.storagePrefix + "_user_" + e
393
393
  );
394
- return G(JSON.parse(e));
395
- } catch (e) {
396
- console.error(e);
394
+ return U(JSON.parse(t));
395
+ } catch (t) {
396
+ console.error(t);
397
397
  return;
398
398
  }
399
- }, U = (t) => d(t) && d(t).accessToken, V = (t) => d(t) && d(t).postingKey;
400
- function z(t = [], e, n) {
399
+ }, V = (e) => d(e) && d(e).accessToken, z = (e) => d(e) && d(e).postingKey;
400
+ function X(e = [], t, n) {
401
401
  return l({
402
- mutationKey: [...t, e],
402
+ mutationKey: [...e, t],
403
403
  mutationFn: async (a) => {
404
- if (!e)
404
+ if (!t)
405
405
  throw new Error(
406
406
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
407
407
  );
408
- const s = V(e);
408
+ const s = z(t);
409
409
  if (s) {
410
410
  const i = p.fromString(s);
411
411
  return u.hiveClient.broadcast.sendOperations(
@@ -413,7 +413,7 @@ function z(t = [], e, n) {
413
413
  i
414
414
  );
415
415
  }
416
- let r = U(e);
416
+ let r = V(t);
417
417
  if (r)
418
418
  return (await new g.Client({
419
419
  accessToken: r
@@ -424,18 +424,18 @@ function z(t = [], e, n) {
424
424
  }
425
425
  });
426
426
  }
427
- function X(t) {
428
- return z(
427
+ function Y(e) {
428
+ return X(
429
429
  ["accounts", "update"],
430
- t,
431
- (e) => [
430
+ e,
431
+ (t) => [
432
432
  [
433
433
  "account_update2",
434
434
  {
435
- account: t,
435
+ account: e,
436
436
  json_metadata: "",
437
437
  posting_json_metadata: JSON.stringify({
438
- profile: { ...e, version: 2 }
438
+ profile: { ...t, version: 2 }
439
439
  }),
440
440
  extensions: []
441
441
  }
@@ -443,13 +443,25 @@ function X(t) {
443
443
  ]
444
444
  );
445
445
  }
446
- function Ot(t) {
447
- const { mutateAsync: e } = X(t);
446
+ function ke(e, t = 5, n = []) {
447
+ return A({
448
+ queryKey: ["accounts", "search", e, n],
449
+ enabled: !!e,
450
+ queryFn: async () => (await u.hiveClient.database.call(
451
+ "lookup_accounts",
452
+ [e, t]
453
+ )).filter(
454
+ (s) => n.length > 0 ? !n.includes(s) : !0
455
+ )
456
+ });
457
+ }
458
+ function Ae(e) {
459
+ const { mutateAsync: t } = Y(e);
448
460
  return l({
449
- mutationKey: ["ecency-wallets", "save-wallet-to-metadata", t],
461
+ mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
450
462
  mutationFn: ({
451
463
  wallets: n
452
- }) => e(
464
+ }) => t(
453
465
  Array.from(n.entries() ?? []).reduce(
454
466
  (a, [s, r]) => ({
455
467
  ...a,
@@ -460,28 +472,28 @@ function Ot(t) {
460
472
  )
461
473
  });
462
474
  }
463
- function kt(t) {
475
+ function Ke(e) {
464
476
  return l({
465
- mutationKey: ["operations", "sign", t],
477
+ mutationKey: ["operations", "sign", e],
466
478
  mutationFn: ({
467
- operation: e,
479
+ operation: t,
468
480
  keyOrSeed: n
469
481
  }) => {
470
- if (!t)
482
+ if (!e)
471
483
  throw new Error("[Operations][Sign] – cannot sign op with anon user");
472
484
  let a;
473
- return n.split(" ").length === 12 ? a = p.fromLogin(t, n, "active") : H.isWif(n) ? a = p.fromString(n) : a = p.from(n), u.hiveClient.broadcast.sendOperations(
474
- [e],
485
+ return n.split(" ").length === 12 ? a = p.fromLogin(e, n, "active") : E.isWif(n) ? a = p.fromString(n) : a = p.from(n), u.hiveClient.broadcast.sendOperations(
486
+ [t],
475
487
  a
476
488
  );
477
489
  }
478
490
  });
479
491
  }
480
- const Y = (t, e, n, a = null) => new Promise((s, r) => {
492
+ const Z = (e, t, n, a = null) => new Promise((s, r) => {
481
493
  var i;
482
494
  (i = window.hive_keychain) == null || i.requestBroadcast(
483
- t,
484
495
  e,
496
+ t,
485
497
  n,
486
498
  (c) => {
487
499
  c.success || r({ message: "Operation cancelled" }), s(c);
@@ -489,40 +501,41 @@ const Y = (t, e, n, a = null) => new Promise((s, r) => {
489
501
  a
490
502
  );
491
503
  });
492
- function At(t, e = "Active") {
504
+ function Re(e, t = "Active") {
493
505
  return l({
494
- mutationKey: ["operations", "sign-keychain", t],
506
+ mutationKey: ["operations", "sign-keychain", e],
495
507
  mutationFn: ({ operation: n }) => {
496
- if (!t)
508
+ if (!e)
497
509
  throw new Error(
498
510
  "[SDK][Keychain] – cannot sign operation with anon user"
499
511
  );
500
- return Y(t, [n], e);
512
+ return Z(e, [n], t);
501
513
  }
502
514
  });
503
515
  }
504
- function Kt(t = "/") {
516
+ function Ce(e = "/") {
505
517
  return l({
506
- mutationKey: ["operations", "sign-hivesigner", t],
507
- mutationFn: async ({ operation: e }) => g.sendOperation(e, { callback: t }, () => {
518
+ mutationKey: ["operations", "sign-hivesigner", e],
519
+ mutationFn: async ({ operation: t }) => g.sendOperation(t, { callback: e }, () => {
508
520
  })
509
521
  });
510
522
  }
511
523
  export {
512
524
  o as EcencyWalletCurrency,
513
- Pt as EcencyWalletsPrivateApi,
514
- F as delay,
525
+ Se as EcencyWalletsPrivateApi,
526
+ W as delay,
527
+ ke as getSearchAccountsByUsernameQueryOptions,
515
528
  T as getWallet,
516
- gt as mnemonicToSeedBip39,
517
- X as useAccountUpdate,
518
- bt as useCoinGeckoPriceQuery,
519
- Tt as useGetExternalWalletBalanceQuery,
520
- q as useHiveKeysQuery,
521
- St as useImportWallet,
522
- Ot as useSaveWalletInformationToMetadata,
529
+ Te as mnemonicToSeedBip39,
530
+ Y as useAccountUpdate,
531
+ ve as useCoinGeckoPriceQuery,
532
+ be as useGetExternalWalletBalanceQuery,
533
+ Q as useHiveKeysQuery,
534
+ Oe as useImportWallet,
535
+ Ae as useSaveWalletInformationToMetadata,
523
536
  b as useSeedPhrase,
524
- Kt as useSignOperationByHivesigner,
525
- kt as useSignOperationByKey,
526
- At as useSignOperationByKeychain,
527
- vt as useWalletCreate
537
+ Ce as useSignOperationByHivesigner,
538
+ Ke as useSignOperationByKey,
539
+ Re as useSignOperationByKeychain,
540
+ Pe as useWalletCreate
528
541
  };
@@ -0,0 +1,3 @@
1
+ export * from './modules/wallets';
2
+ export * from './modules/accounts';
3
+ export * from './modules/operations';
@@ -0,0 +1,2 @@
1
+ export * from './mutations';
2
+ export * from './queries';
@@ -0,0 +1 @@
1
+ export * from './use-account-update';
@@ -0,0 +1 @@
1
+ export declare function useAccountUpdate(username: string): import('@tanstack/react-query').UseMutationResult<any, Error, any, unknown>;
@@ -0,0 +1 @@
1
+ export * from './search-accounts-by-username-query-options';
@@ -0,0 +1,8 @@
1
+ export declare function getSearchAccountsByUsernameQueryOptions(query: string, limit?: number, excludeList?: string[]): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<string[], Error, string[], (string | string[])[]>, "queryFn"> & {
2
+ queryFn?: import('@tanstack/query-core').QueryFunction<string[], (string | string[])[], never> | undefined;
3
+ } & {
4
+ queryKey: (string | string[])[] & {
5
+ [dataTagSymbol]: string[];
6
+ [dataTagErrorSymbol]: Error;
7
+ };
8
+ };
@@ -0,0 +1 @@
1
+ export * from './user';
@@ -0,0 +1,8 @@
1
+ export interface StoringUser {
2
+ username: string;
3
+ accessToken: string;
4
+ refreshToken: string;
5
+ expiresIn: number;
6
+ postingKey: null | undefined | string;
7
+ index?: number;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from './mutations';
2
+ export * from './storage';
3
+ export * from './entities';
@@ -0,0 +1 @@
1
+ export * from './use-broadcast-mutation';
@@ -0,0 +1,3 @@
1
+ import { useMutation } from '@tanstack/react-query';
2
+ import { Operation } from '@hiveio/dhive';
3
+ export declare function useBroadcastMutation<T>(mutationKey: Parameters<typeof useMutation>[0]["mutationKey"], username: string | undefined, operations: (payload: T) => Operation[]): import('@tanstack/react-query').UseMutationResult<any, Error, T, unknown>;
@@ -0,0 +1,5 @@
1
+ import { StoringUser } from './entities';
2
+ export declare const getUser: (username: string) => StoringUser | undefined;
3
+ export declare const getAccessToken: (username: string) => string | undefined;
4
+ export declare const getPostingKey: (username: string) => null | undefined | string;
5
+ export declare const getRefreshToken: (username: string) => string | undefined;
@@ -0,0 +1,2 @@
1
+ export declare function encodeObj(o: any): string;
2
+ export declare function decodeObj(o: any): any;
@@ -0,0 +1 @@
1
+ export * from './decoder-encoder';
@@ -0,0 +1,2 @@
1
+ import * as Keychain from "./keychain";
2
+ export { Keychain };
@@ -0,0 +1,9 @@
1
+ import { Operation } from '@hiveio/dhive';
2
+ export type KeychainAuthorityTypes = "Owner" | "Active" | "Posting" | "Memo";
3
+ interface TxResponse {
4
+ success: boolean;
5
+ result: string;
6
+ }
7
+ export declare function handshake(): Promise<void>;
8
+ export declare const broadcast: (account: string, operations: Operation[], key: KeychainAuthorityTypes, rpc?: string | null) => Promise<TxResponse>;
9
+ export {};
@@ -0,0 +1 @@
1
+ export * from './mutations';
@@ -0,0 +1,3 @@
1
+ export * from './sign-operation-by-key';
2
+ export * from './sign-operation-by-keychain';
3
+ export * from './sign-operation-by-hivesigner';
@@ -0,0 +1,4 @@
1
+ import { Operation } from '@hiveio/dhive';
2
+ export declare function useSignOperationByHivesigner(callbackUri?: string): import('@tanstack/react-query').UseMutationResult<string | void, Error, {
3
+ operation: Operation;
4
+ }, unknown>;
@@ -0,0 +1,5 @@
1
+ import { Operation } from '@hiveio/dhive';
2
+ export declare function useSignOperationByKey(username: string | undefined): import('@tanstack/react-query').UseMutationResult<import('@hiveio/dhive').TransactionConfirmation, Error, {
3
+ operation: Operation;
4
+ keyOrSeed: string;
5
+ }, unknown>;
@@ -0,0 +1,5 @@
1
+ import { Keychain } from '../../keychain';
2
+ import { Operation } from '@hiveio/dhive';
3
+ export declare function useSignOperationByKeychain(username: string | undefined, keyType?: Keychain.KeychainAuthorityTypes): import('@tanstack/react-query').UseMutationResult<any, Error, {
4
+ operation: Operation;
5
+ }, unknown>;
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1 @@
1
+ export * from './ecency-wallet-currency';
@@ -0,0 +1,3 @@
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]>;
@@ -0,0 +1 @@
1
+ export * from './get-keys-from-seed';
@@ -0,0 +1,5 @@
1
+ export * from './enums';
2
+ export * from './mutations';
3
+ export * from './utils';
4
+ export * from './queries';
5
+ export * from './types';
@@ -0,0 +1,4 @@
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';
@@ -0,0 +1,7 @@
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 {};
@@ -0,0 +1,7 @@
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 {};
@@ -0,0 +1,2 @@
1
+ export * from './create-account-with-wallets';
2
+ export * from './check-wallet-existence';
@@ -0,0 +1,2 @@
1
+ import * as EcencyWalletsPrivateApi from "./private-api";
2
+ export { EcencyWalletsPrivateApi };
@@ -0,0 +1,5 @@
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>;
@@ -0,0 +1,10 @@
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 {};
@@ -0,0 +1,6 @@
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
+ };
@@ -0,0 +1,4 @@
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';
@@ -0,0 +1,2 @@
1
+ import { EcencyWalletCurrency } from '../enums';
2
+ export declare function useCoinGeckoPriceQuery(currency?: EcencyWalletCurrency): import('@tanstack/react-query').UseQueryResult<number, Error>;
@@ -0,0 +1,10 @@
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>;
@@ -0,0 +1,2 @@
1
+ import { EcencyHiveKeys } from '../types';
2
+ export declare function useHiveKeysQuery(username: string): import('@tanstack/react-query').UseQueryResult<EcencyHiveKeys, Error>;
@@ -0,0 +1 @@
1
+ export declare function useSeedPhrase(username: string): import('@tanstack/react-query').UseQueryResult<string, Error>;
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ecency-create-wallet-information';
2
+ export * from './ecency-hive-keys';
@@ -0,0 +1 @@
1
+ export declare function delay(ms: number): Promise<unknown>;
@@ -0,0 +1,3 @@
1
+ import { BaseWallet } from '@okxweb3/coin-base';
2
+ import { EcencyWalletCurrency } from '../enums';
3
+ export declare function getWallet(currency: EcencyWalletCurrency): BaseWallet | undefined;
@@ -0,0 +1,3 @@
1
+ export * from './delay';
2
+ export * from './get-wallet';
3
+ export * from './mnemonic-to-seed-bip-39';
@@ -0,0 +1 @@
1
+ export declare function mnemonicToSeedBip39(value: string): string;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ecency/sdk",
3
3
  "private": false,
4
- "version": "1.0.17",
4
+ "version": "1.0.18",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist/ecency-sdk.umd.js",
8
8
  "module": "./dist/ecency-sdk.es.js",
9
- "typings": "./dist/ecency-sdk.es.d.ts",
9
+ "typings": "./dist/index.d.ts",
10
10
  "files": [
11
11
  "dist",
12
12
  "README.md"
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@hiveio/dhive": "^1.3.2",
21
- "@tanstack/react-query": "^5.66.11",
21
+ "@tanstack/react-query": "^5.74.4",
22
22
  "@types/node": "^22.13.8",
23
23
  "@types/react": "^19.0.10",
24
24
  "@vitejs/plugin-react": "^4.3.4",
@@ -26,9 +26,9 @@
26
26
  "lru-cache": "^11.0.2",
27
27
  "prettier": "^3.5.2",
28
28
  "react": "^19.0.0",
29
- "typescript": "~5.7.2",
29
+ "typescript": "5.8.3",
30
30
  "vite": "^6.2.0",
31
- "vite-plugin-dts": "^4.5.1",
31
+ "vite-plugin-dts": "4.5.3",
32
32
  "vite-plugin-node-polyfills": "^0.23.0"
33
33
  },
34
34
  "dependencies": {
@@ -1,136 +0,0 @@
1
- import { BaseWallet } from '@okxweb3/coin-base';
2
- import { Operation } from '@hiveio/dhive';
3
- import { TransactionConfirmation } from '@hiveio/dhive';
4
- import { UseMutationResult } from '@tanstack/react-query';
5
- import { UseQueryResult } from '@tanstack/react-query';
6
-
7
- declare const broadcast: (account: string, operations: Operation[], key: KeychainAuthorityTypes, rpc?: string | null) => Promise<TxResponse>;
8
-
9
- export declare function delay(ms: number): Promise<unknown>;
10
-
11
- export declare interface EcencyCreateWalletInformation {
12
- address: string;
13
- privateKey: string;
14
- publicKey: string;
15
- username: string;
16
- currency: EcencyWalletCurrency;
17
- custom?: boolean;
18
- }
19
-
20
- export declare interface EcencyHiveKeys {
21
- username: string;
22
- owner: string;
23
- active: string;
24
- posting: string;
25
- memo: string;
26
- masterPassword: string;
27
- ownerPubkey: string;
28
- activePubkey: string;
29
- postingPubkey: string;
30
- memoPubkey: string;
31
- }
32
-
33
- export declare enum EcencyWalletCurrency {
34
- BTC = "BTC",
35
- ETH = "ETH",
36
- APT = "APT",
37
- ATOM = "ATOM",
38
- TON = "TON",
39
- TRON = "TRX",
40
- SOL = "SOL"
41
- }
42
-
43
- declare namespace EcencyWalletsPrivateApi {
44
- export {
45
- useCreateAccountWithWallets,
46
- useCheckWalletExistence
47
- }
48
- }
49
- export { EcencyWalletsPrivateApi }
50
-
51
- export declare function getWallet(currency: EcencyWalletCurrency): BaseWallet | undefined;
52
-
53
- declare function handshake(): Promise<void>;
54
-
55
- declare namespace Keychain {
56
- export {
57
- handshake,
58
- KeychainAuthorityTypes,
59
- broadcast
60
- }
61
- }
62
-
63
- declare type KeychainAuthorityTypes = "Owner" | "Active" | "Posting" | "Memo";
64
-
65
- export declare function mnemonicToSeedBip39(value: string): string;
66
-
67
- declare interface Payload {
68
- currency: EcencyWalletCurrency;
69
- address: string;
70
- }
71
-
72
- declare interface Payload_2 {
73
- address: string;
74
- currency: EcencyWalletCurrency;
75
- }
76
-
77
- declare interface Payload_3 {
78
- privateKeyOrSeed: string;
79
- }
80
-
81
- declare interface TxResponse {
82
- success: boolean;
83
- result: string;
84
- }
85
-
86
- export declare function useAccountUpdate(username: string): UseMutationResult<any, Error, any, unknown>;
87
-
88
- declare function useCheckWalletExistence(): UseMutationResult<boolean, Error, Payload_2, unknown>;
89
-
90
- export declare function useCoinGeckoPriceQuery(currency?: EcencyWalletCurrency): UseQueryResult<number, Error>;
91
-
92
- declare function useCreateAccountWithWallets(username: string): UseMutationResult<Response, Error, Payload, unknown>;
93
-
94
- /**
95
- * Returns information about the actual balance of the given currency address
96
- * using various of public APIs
97
- * todo extract URLs to configs
98
- * @param currency
99
- * @param address
100
- * @returns
101
- */
102
- export declare function useGetExternalWalletBalanceQuery(currency: EcencyWalletCurrency, address: string): UseQueryResult<number, Error>;
103
-
104
- export declare function useHiveKeysQuery(username: string): UseQueryResult<EcencyHiveKeys, Error>;
105
-
106
- export declare function useImportWallet(username: string, currency: EcencyWalletCurrency): UseMutationResult< {
107
- privateKey: string;
108
- address: any;
109
- publicKey: string;
110
- }, Error, Payload_3, unknown>;
111
-
112
- export declare function useSaveWalletInformationToMetadata(username: string): UseMutationResult<any, Error, {
113
- wallets: Map<EcencyWalletCurrency, EcencyCreateWalletInformation>;
114
- }, unknown>;
115
-
116
- export declare function useSeedPhrase(username: string): UseQueryResult<string, Error>;
117
-
118
- export declare function useSignOperationByHivesigner(callbackUri?: string): UseMutationResult<string | void, Error, {
119
- operation: Operation;
120
- }, unknown>;
121
-
122
- export declare function useSignOperationByKey(username: string | undefined): UseMutationResult<TransactionConfirmation, Error, {
123
- operation: Operation;
124
- keyOrSeed: string;
125
- }, unknown>;
126
-
127
- export declare function useSignOperationByKeychain(username: string | undefined, keyType?: Keychain.KeychainAuthorityTypes): UseMutationResult<any, Error, {
128
- operation: Operation;
129
- }, unknown>;
130
-
131
- export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
132
- createWallet: UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
133
- importWallet: () => void;
134
- };
135
-
136
- export { }