@ecency/sdk 1.0.8 → 1.0.10
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 +4 -4
- package/dist/ecency-sdk.es.d.ts +3 -0
- package/dist/ecency-sdk.es.js +64 -52
- package/package.json +1 -1
package/Readme.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# Ecency
|
1
|
+
# Ecency SDK
|
2
2
|
|
3
3
|
[](https://www.npmjs.com/package/@ecency/wallets) [](https://standardjs.com)
|
4
4
|
|
5
5
|
## Overview
|
6
6
|
|
7
|
-
`@ecency/
|
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/
|
12
|
+
yarn add @ecency/sdk
|
13
13
|
# or
|
14
|
-
npm install @ecency/
|
14
|
+
npm install @ecency/sdk
|
15
15
|
```
|
16
16
|
|
17
17
|
## Setup
|
package/dist/ecency-sdk.es.d.ts
CHANGED
@@ -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 | undefined): 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;
|
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
import { useCallback as
|
2
|
-
import { useQuery as d, useQueryClient as
|
3
|
-
import { BtcWallet as
|
4
|
-
import { EthWallet as
|
5
|
-
import { TrxWallet as
|
6
|
-
import { TonWallet as
|
7
|
-
import { SolWallet as
|
8
|
-
import { AtomWallet as
|
9
|
-
import { AptosWallet as
|
10
|
-
import
|
11
|
-
import { LRUCache as
|
12
|
-
import { PrivateKey as u, Client as
|
13
|
-
import
|
1
|
+
import { useCallback as O } from "react";
|
2
|
+
import { useQuery as d, useQueryClient as y, useMutation as p } from "@tanstack/react-query";
|
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 B 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
15
|
function W(e) {
|
16
16
|
return new Promise((t) => setTimeout(t, e));
|
@@ -18,27 +18,27 @@ function W(e) {
|
|
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.
|
22
|
+
case o.ETH:
|
25
23
|
return new R();
|
26
|
-
case o.
|
24
|
+
case o.TRON:
|
27
25
|
return new K();
|
28
|
-
case o.
|
26
|
+
case o.TON:
|
29
27
|
return new N();
|
30
|
-
case o.
|
28
|
+
case o.SOL:
|
31
29
|
return new C();
|
32
|
-
case o.
|
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
|
-
function
|
39
|
-
return
|
38
|
+
function fe(e) {
|
39
|
+
return j(e).toString("hex");
|
40
40
|
}
|
41
|
-
function
|
41
|
+
function ye(e, t) {
|
42
42
|
return d({
|
43
43
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
44
44
|
queryFn: async () => {
|
@@ -74,12 +74,12 @@ function fe(e, t) {
|
|
74
74
|
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
75
75
|
)).json()).balance / 1e9;
|
76
76
|
case o.APT:
|
77
|
-
const
|
77
|
+
const f = (await (await fetch(
|
78
78
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
79
79
|
)).json()).find(
|
80
|
-
(
|
80
|
+
(k) => k.type.includes("coin::CoinStore")
|
81
81
|
);
|
82
|
-
return
|
82
|
+
return f ? parseInt(f.data.coin.value) / 1e8 : 0;
|
83
83
|
case o.ATOM:
|
84
84
|
return +(await (await fetch(
|
85
85
|
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
|
@@ -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 () =>
|
94
|
+
queryFn: async () => _.generateMnemonic(128)
|
95
95
|
});
|
96
96
|
}
|
97
|
-
const
|
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
|
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 =
|
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
|
-
|
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
|
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
|
175
|
+
const I = {
|
176
176
|
[o.BTC]: "m/44'/0'/0'/0/0",
|
177
177
|
// Bitcoin (BIP44)
|
178
178
|
[o.ETH]: "m/44'/60'/0'/0/0",
|
@@ -189,14 +189,14 @@ const q = {
|
|
189
189
|
// Cosmos (BIP44)
|
190
190
|
};
|
191
191
|
function Te(e, t) {
|
192
|
-
const { data: n } = T(e), s =
|
192
|
+
const { data: n } = T(e), s = y(), a = p({
|
193
193
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
194
194
|
mutationFn: async () => {
|
195
195
|
if (!n)
|
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:
|
199
|
+
hdPath: I[t]
|
200
200
|
}));
|
201
201
|
await W(1e3);
|
202
202
|
const l = await (r == null ? void 0 : r.getNewAddress({
|
@@ -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 =
|
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
|
230
|
+
hiveClient: new E(
|
231
231
|
[
|
232
232
|
"https://api.hive.blog",
|
233
233
|
"https://api.deathwing.me",
|
@@ -251,7 +251,7 @@ const m = {
|
|
251
251
|
function J(e) {
|
252
252
|
const { data: t } = d({
|
253
253
|
queryKey: ["ecency-wallets", "wallets", e]
|
254
|
-
}), { data: n } =
|
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", {
|
@@ -313,7 +313,7 @@ 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
|
316
|
+
async function $(e, t, n) {
|
317
317
|
for (const s of Q[n] || [])
|
318
318
|
try {
|
319
319
|
const a = await t.getDerivedPrivateKey({
|
@@ -330,7 +330,7 @@ async function I(e, t, n) {
|
|
330
330
|
return [];
|
331
331
|
}
|
332
332
|
function ve(e, t) {
|
333
|
-
const n =
|
333
|
+
const n = y(), { mutateAsync: s } = v();
|
334
334
|
return p({
|
335
335
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
336
336
|
mutationFn: async ({ privateKeyOrSeed: a }) => {
|
@@ -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
|
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
|
380
|
+
function G(e) {
|
381
381
|
let t = atob(e);
|
382
382
|
if (t[0] === "{")
|
383
383
|
return JSON.parse(t);
|
@@ -387,17 +387,21 @@ const h = (e) => {
|
|
387
387
|
const t = m.storage.getItem(
|
388
388
|
m.storagePrefix + "_user_" + e
|
389
389
|
);
|
390
|
-
return
|
390
|
+
return G(JSON.parse(t));
|
391
391
|
} catch (t) {
|
392
392
|
console.error(t);
|
393
393
|
return;
|
394
394
|
}
|
395
|
-
},
|
396
|
-
function
|
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
|
-
|
400
|
+
if (!t)
|
401
|
+
throw new Error(
|
402
|
+
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
403
|
+
);
|
404
|
+
const a = V(t);
|
401
405
|
if (a) {
|
402
406
|
const r = u.fromString(a);
|
403
407
|
return m.hiveClient.broadcast.sendOperations(
|
@@ -405,9 +409,9 @@ function V(e = [], t, n) {
|
|
405
409
|
r
|
406
410
|
);
|
407
411
|
}
|
408
|
-
let i =
|
412
|
+
let i = U(t);
|
409
413
|
if (i)
|
410
|
-
return (await new
|
414
|
+
return (await new B.Client({
|
411
415
|
accessToken: i
|
412
416
|
}).broadcast(n(s))).result;
|
413
417
|
throw new Error(
|
@@ -417,7 +421,7 @@ function V(e = [], t, n) {
|
|
417
421
|
});
|
418
422
|
}
|
419
423
|
function z(e) {
|
420
|
-
return
|
424
|
+
return P(
|
421
425
|
["accounts", "update"],
|
422
426
|
e,
|
423
427
|
(t) => [
|
@@ -452,18 +456,26 @@ function Pe(e) {
|
|
452
456
|
)
|
453
457
|
});
|
454
458
|
}
|
459
|
+
function Se(e) {
|
460
|
+
return P(
|
461
|
+
["operations", "sign"],
|
462
|
+
e,
|
463
|
+
(t) => [t]
|
464
|
+
);
|
465
|
+
}
|
455
466
|
export {
|
456
467
|
o as EcencyWalletCurrency,
|
457
468
|
be as EcencyWalletsPrivateApi,
|
458
469
|
W as delay,
|
459
470
|
g as getWallet,
|
460
|
-
|
471
|
+
fe as mnemonicToSeedBip39,
|
461
472
|
z as useAccountUpdate,
|
462
473
|
ge as useCoinGeckoPriceQuery,
|
463
|
-
|
464
|
-
|
474
|
+
ye as useGetExternalWalletBalanceQuery,
|
475
|
+
q as useHiveKeysQuery,
|
465
476
|
ve as useImportWallet,
|
466
477
|
Pe as useSaveWalletInformationToMetadata,
|
467
478
|
T as useSeedPhrase,
|
479
|
+
Se as useSignOperation,
|
468
480
|
Te as useWalletCreate
|
469
481
|
};
|