@ecency/sdk 1.0.8 → 1.0.9

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.
package/Readme.md CHANGED
@@ -1,17 +1,17 @@
1
- # Ecency wallets – manage Hive account and attach external wallets to it in Ecency system
1
+ # Ecency SDK
2
2
 
3
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
4
 
5
5
  ## Overview
6
6
 
7
- `@ecency/wallets` provides an API for managing Hive blockchain wallets and external cryptocurrency wallets within the Ecency ecosystem.
7
+ `@ecency/sdk` provides an API for managing Hive blockchain wallets and external cryptocurrency wallets within the Ecency ecosystem.
8
8
 
9
9
  ## Installation
10
10
 
11
11
  ```sh
12
- yarn add @ecency/wallets
12
+ yarn add @ecency/sdk
13
13
  # or
14
- npm install @ecency/wallets
14
+ npm install @ecency/sdk
15
15
  ```
16
16
 
17
17
  ## Setup
@@ -1,4 +1,5 @@
1
1
  import { BaseWallet } from '@okxweb3/coin-base';
2
+ import { Operation } from '@hiveio/dhive';
2
3
  import { UseMutationResult } from '@tanstack/react-query';
3
4
  import { UseQueryResult } from '@tanstack/react-query';
4
5
 
@@ -94,6 +95,8 @@ wallets: Map<EcencyWalletCurrency, EcencyCreateWalletInformation>;
94
95
 
95
96
  export declare function useSeedPhrase(username: string): UseQueryResult<string, Error>;
96
97
 
98
+ export declare function useSignOperation(username: string): UseMutationResult<any, Error, Operation, unknown>;
99
+
97
100
  export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
98
101
  createWallet: UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
99
102
  importWallet: () => void;
@@ -1,42 +1,42 @@
1
- import { useCallback as k } from "react";
1
+ import { useCallback as O } from "react";
2
2
  import { useQuery as d, useQueryClient as f, useMutation as p } from "@tanstack/react-query";
3
- import { BtcWallet as O } from "@okxweb3/coin-bitcoin";
4
- import { EthWallet as A } from "@okxweb3/coin-ethereum";
5
- import { TrxWallet as R } from "@okxweb3/coin-tron";
6
- import { TonWallet as K } from "@okxweb3/coin-ton";
7
- import { SolWallet as N } from "@okxweb3/coin-solana";
8
- import { AtomWallet as C } from "@okxweb3/coin-cosmos";
9
- import { AptosWallet as x } from "@okxweb3/coin-aptos";
10
- import D, { mnemonicToSeedSync as _ } from "bip39";
11
- import { LRUCache as j } from "lru-cache";
12
- import { PrivateKey as u, Client as H } from "@hiveio/dhive";
13
- import E from "hivesigner";
3
+ import { BtcWallet as A } from "@okxweb3/coin-bitcoin";
4
+ import { EthWallet as R } from "@okxweb3/coin-ethereum";
5
+ import { TrxWallet as K } from "@okxweb3/coin-tron";
6
+ import { TonWallet as N } from "@okxweb3/coin-ton";
7
+ import { SolWallet as C } from "@okxweb3/coin-solana";
8
+ import { AtomWallet as x } from "@okxweb3/coin-cosmos";
9
+ import { AptosWallet as D } from "@okxweb3/coin-aptos";
10
+ import _, { mnemonicToSeedSync as j } from "bip39";
11
+ import { LRUCache as H } from "lru-cache";
12
+ import { PrivateKey as u, Client as E } from "@hiveio/dhive";
13
+ import W from "hivesigner";
14
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) {
15
+ function B(e) {
16
16
  return new Promise((t) => setTimeout(t, e));
17
17
  }
18
18
  function g(e) {
19
19
  switch (e) {
20
20
  case o.BTC:
21
- return new O();
22
- case o.ETH:
23
21
  return new A();
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 K();
28
- case o.SOL:
26
+ case o.TON:
29
27
  return new N();
30
- case o.ATOM:
28
+ case o.SOL:
31
29
  return new C();
32
- case o.APT:
30
+ case o.ATOM:
33
31
  return new x();
32
+ case o.APT:
33
+ return new D();
34
34
  default:
35
35
  return;
36
36
  }
37
37
  }
38
38
  function ye(e) {
39
- return _(e).toString("hex");
39
+ return j(e).toString("hex");
40
40
  }
41
41
  function fe(e, t) {
42
42
  return d({
@@ -77,7 +77,7 @@ function fe(e, t) {
77
77
  const y = (await (await fetch(
78
78
  `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
79
79
  )).json()).find(
80
- (S) => S.type.includes("coin::CoinStore")
80
+ (k) => k.type.includes("coin::CoinStore")
81
81
  );
82
82
  return y ? parseInt(y.data.coin.value) / 1e8 : 0;
83
83
  case o.ATOM:
@@ -91,10 +91,10 @@ function fe(e, t) {
91
91
  function T(e) {
92
92
  return d({
93
93
  queryKey: ["ecency-wallets", "seed", e],
94
- queryFn: async () => D.generateMnemonic(128)
94
+ queryFn: async () => _.generateMnemonic(128)
95
95
  });
96
96
  }
97
- const B = {
97
+ const F = {
98
98
  max: 500,
99
99
  // how long to live in ms
100
100
  ttl: 1e3 * 60 * 5,
@@ -102,7 +102,7 @@ const B = {
102
102
  allowStale: !1,
103
103
  updateAgeOnGet: !1,
104
104
  updateAgeOnHas: !1
105
- }, b = new j(B), w = Symbol("undefined"), F = (e, t) => b.set(e, t === void 0 ? w : t), M = (e) => {
105
+ }, b = new H(F), w = Symbol("undefined"), M = (e, t) => b.set(e, t === void 0 ? w : t), L = (e) => {
106
106
  const t = b.get(e);
107
107
  return t === w ? void 0 : t;
108
108
  };
@@ -127,7 +127,7 @@ function ge(e) {
127
127
  default:
128
128
  t = e;
129
129
  }
130
- let n = M("gecko"), s;
130
+ let n = L("gecko"), s;
131
131
  if (n)
132
132
  s = n;
133
133
  else {
@@ -143,14 +143,14 @@ function ge(e) {
143
143
  })
144
144
  }
145
145
  )).json();
146
- F("gecko", r === void 0 ? w : r), s = r;
146
+ M("gecko", r === void 0 ? w : r), s = r;
147
147
  }
148
148
  return 1 / +s[Object.keys(s)[0]].usd;
149
149
  },
150
150
  enabled: !!e
151
151
  });
152
152
  }
153
- function L(e) {
153
+ function q(e) {
154
154
  const { data: t } = T(e);
155
155
  return d({
156
156
  queryKey: ["ecencу-wallets", "hive-keys", e, t],
@@ -172,7 +172,7 @@ function L(e) {
172
172
  }
173
173
  });
174
174
  }
175
- const q = {
175
+ const J = {
176
176
  [o.BTC]: "m/44'/0'/0'/0/0",
177
177
  // Bitcoin (BIP44)
178
178
  [o.ETH]: "m/44'/60'/0'/0/0",
@@ -196,9 +196,9 @@ function Te(e, t) {
196
196
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
197
197
  const r = g(t), c = await (r == null ? void 0 : r.getDerivedPrivateKey({
198
198
  mnemonic: n,
199
- hdPath: q[t]
199
+ hdPath: J[t]
200
200
  }));
201
- await W(1e3);
201
+ await B(1e3);
202
202
  const l = await (r == null ? void 0 : r.getNewAddress({
203
203
  privateKey: c
204
204
  }));
@@ -216,7 +216,7 @@ function Te(e, t) {
216
216
  (c) => new Map(c ? Array.from(c.entries()) : []).set(r.currency, r)
217
217
  );
218
218
  }
219
- }), i = k(() => {
219
+ }), i = O(() => {
220
220
  }, []);
221
221
  return {
222
222
  createWallet: a,
@@ -227,7 +227,7 @@ const m = {
227
227
  privateApiHost: "https://ecency.com",
228
228
  storage: localStorage,
229
229
  storagePrefix: "ecency",
230
- hiveClient: new H(
230
+ hiveClient: new E(
231
231
  [
232
232
  "https://api.hive.blog",
233
233
  "https://api.deathwing.me",
@@ -248,10 +248,10 @@ const m = {
248
248
  }
249
249
  )
250
250
  };
251
- function J(e) {
251
+ function Q(e) {
252
252
  const { data: t } = d({
253
253
  queryKey: ["ecency-wallets", "wallets", e]
254
- }), { data: n } = L(e);
254
+ }), { data: n } = q(e);
255
255
  return p({
256
256
  mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
257
257
  mutationFn: ({ currency: s, address: a }) => fetch(m.privateApiHost + "/private-api/wallets-add", {
@@ -301,8 +301,8 @@ function v() {
301
301
  const be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
302
302
  __proto__: null,
303
303
  useCheckWalletExistence: v,
304
- useCreateAccountWithWallets: J
305
- }, Symbol.toStringTag, { value: "Module" })), Q = {
304
+ useCreateAccountWithWallets: Q
305
+ }, Symbol.toStringTag, { value: "Module" })), I = {
306
306
  [o.BTC]: ["m/84'/0'/0'/0/0"],
307
307
  [o.ETH]: ["m/84'/60'/0'/0/0"],
308
308
  // its not working for Trust, Exodus, todo: check others below
@@ -313,8 +313,8 @@ const be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
313
313
  // Disabled
314
314
  [o.ATOM]: ["m/84'/118'/0'/0'/0"]
315
315
  };
316
- async function I(e, t, n) {
317
- for (const s of Q[n] || [])
316
+ async function $(e, t, n) {
317
+ for (const s of I[n] || [])
318
318
  try {
319
319
  const a = await t.getDerivedPrivateKey({
320
320
  mnemonic: e,
@@ -339,7 +339,7 @@ function ve(e, t) {
339
339
  throw new Error("Cannot find token for this currency");
340
340
  const r = a.split(" ").length === 12;
341
341
  let c, l = a;
342
- if (r ? [l, c] = await I(
342
+ if (r ? [l, c] = await $(
343
343
  a,
344
344
  i,
345
345
  t
@@ -377,7 +377,7 @@ function ve(e, t) {
377
377
  }
378
378
  });
379
379
  }
380
- function $(e) {
380
+ function G(e) {
381
381
  let t = atob(e);
382
382
  if (t[0] === "{")
383
383
  return JSON.parse(t);
@@ -387,17 +387,17 @@ const h = (e) => {
387
387
  const t = m.storage.getItem(
388
388
  m.storagePrefix + "_user_" + e
389
389
  );
390
- return $(JSON.parse(t));
390
+ return G(JSON.parse(t));
391
391
  } catch (t) {
392
392
  console.error(t);
393
393
  return;
394
394
  }
395
- }, G = (e) => h(e) && h(e).accessToken, U = (e) => h(e) && h(e).postingKey;
396
- function V(e = [], t, n) {
395
+ }, U = (e) => h(e) && h(e).accessToken, V = (e) => h(e) && h(e).postingKey;
396
+ function P(e = [], t, n) {
397
397
  return p({
398
398
  mutationKey: [...e, t],
399
399
  mutationFn: async (s) => {
400
- const a = U(t);
400
+ const a = V(t);
401
401
  if (a) {
402
402
  const r = u.fromString(a);
403
403
  return m.hiveClient.broadcast.sendOperations(
@@ -405,9 +405,9 @@ function V(e = [], t, n) {
405
405
  r
406
406
  );
407
407
  }
408
- let i = G(t);
408
+ let i = U(t);
409
409
  if (i)
410
- return (await new E.Client({
410
+ return (await new W.Client({
411
411
  accessToken: i
412
412
  }).broadcast(n(s))).result;
413
413
  throw new Error(
@@ -417,7 +417,7 @@ function V(e = [], t, n) {
417
417
  });
418
418
  }
419
419
  function z(e) {
420
- return V(
420
+ return P(
421
421
  ["accounts", "update"],
422
422
  e,
423
423
  (t) => [
@@ -452,18 +452,26 @@ function Pe(e) {
452
452
  )
453
453
  });
454
454
  }
455
+ function Se(e) {
456
+ return P(
457
+ ["operations", "sign"],
458
+ e,
459
+ (t) => [t]
460
+ );
461
+ }
455
462
  export {
456
463
  o as EcencyWalletCurrency,
457
464
  be as EcencyWalletsPrivateApi,
458
- W as delay,
465
+ B as delay,
459
466
  g as getWallet,
460
467
  ye as mnemonicToSeedBip39,
461
468
  z as useAccountUpdate,
462
469
  ge as useCoinGeckoPriceQuery,
463
470
  fe as useGetExternalWalletBalanceQuery,
464
- L as useHiveKeysQuery,
471
+ q as useHiveKeysQuery,
465
472
  ve as useImportWallet,
466
473
  Pe as useSaveWalletInformationToMetadata,
467
474
  T as useSeedPhrase,
475
+ Se as useSignOperation,
468
476
  Te as useWalletCreate
469
477
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/sdk",
3
3
  "private": false,
4
- "version": "1.0.8",
4
+ "version": "1.0.9",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist/ecency-sdk.umd.js",