@ecency/sdk 1.0.24 → 1.0.26
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/dist/ecency-sdk.es.js +217 -541
- package/dist/index.d.ts +3 -1
- package/dist/modules/core/index.d.ts +2 -0
- package/dist/modules/core/mock-storage.d.ts +9 -0
- package/package.json +5 -15
- package/Readme.md +0 -36
- package/dist/modules/wallets/enums/ecency-wallet-basic-tokens.d.ts +0 -7
- package/dist/modules/wallets/enums/ecency-wallet-currency.d.ts +0 -9
- package/dist/modules/wallets/enums/index.d.ts +0 -2
- package/dist/modules/wallets/functions/get-keys-from-seed.d.ts +0 -3
- package/dist/modules/wallets/functions/index.d.ts +0 -1
- package/dist/modules/wallets/index.d.ts +0 -4
- package/dist/modules/wallets/mutations/index.d.ts +0 -4
- package/dist/modules/wallets/mutations/private-api/check-wallet-existence.d.ts +0 -7
- package/dist/modules/wallets/mutations/private-api/create-account-with-wallets.d.ts +0 -7
- package/dist/modules/wallets/mutations/private-api/index.d.ts +0 -2
- package/dist/modules/wallets/mutations/private-api-namespace.d.ts +0 -2
- package/dist/modules/wallets/mutations/save-wallet-information-to-metadata.d.ts +0 -5
- package/dist/modules/wallets/mutations/use-import-wallet.d.ts +0 -10
- package/dist/modules/wallets/mutations/use-wallet-create.d.ts +0 -6
- package/dist/modules/wallets/queries/get-account-points-query-options.d.ts +0 -9
- package/dist/modules/wallets/queries/index.d.ts +0 -6
- package/dist/modules/wallets/queries/use-coingecko-price-query.d.ts +0 -2
- package/dist/modules/wallets/queries/use-get-account-wallet-list-query.d.ts +0 -9
- package/dist/modules/wallets/queries/use-get-all-tokens-list-query.d.ts +0 -6
- package/dist/modules/wallets/queries/use-get-external-wallet-query.d.ts +0 -10
- package/dist/modules/wallets/queries/use-hive-keys-query.d.ts +0 -2
- package/dist/modules/wallets/queries/use-seed-phrase.d.ts +0 -1
- package/dist/modules/wallets/types/account-points-response.d.ts +0 -4
- package/dist/modules/wallets/types/ecency-create-wallet-information.d.ts +0 -9
- package/dist/modules/wallets/types/ecency-hive-keys.d.ts +0 -12
- package/dist/modules/wallets/types/index.d.ts +0 -3
- package/dist/modules/wallets/utils/delay.d.ts +0 -1
- package/dist/modules/wallets/utils/get-wallet.d.ts +0 -3
- package/dist/modules/wallets/utils/index.d.ts +0 -3
- package/dist/modules/wallets/utils/mnemonic-to-seed-bip-39.d.ts +0 -1
- /package/dist/{config.d.ts → modules/core/config.d.ts} +0 -0
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,45 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import
|
7
|
-
import {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
case a.TON:
|
27
|
-
return new _();
|
28
|
-
case a.SOL:
|
29
|
-
return new j();
|
30
|
-
case a.ATOM:
|
31
|
-
return new D();
|
32
|
-
case a.APT:
|
33
|
-
return new F();
|
34
|
-
default:
|
35
|
-
return;
|
1
|
+
var C = Object.defineProperty;
|
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 {
|
9
|
+
constructor() {
|
10
|
+
g(this, "length", 0);
|
11
|
+
}
|
12
|
+
clear() {
|
13
|
+
throw new Error("Method not implemented.");
|
14
|
+
}
|
15
|
+
getItem(t) {
|
16
|
+
return this[t];
|
17
|
+
}
|
18
|
+
key(t) {
|
19
|
+
return Object.keys(this)[t];
|
20
|
+
}
|
21
|
+
removeItem(t) {
|
22
|
+
delete this[t];
|
23
|
+
}
|
24
|
+
setItem(t, n) {
|
25
|
+
this[t] = n;
|
36
26
|
}
|
37
27
|
}
|
38
|
-
const
|
28
|
+
const a = {
|
39
29
|
privateApiHost: "https://ecency.com",
|
40
|
-
storage: localStorage,
|
30
|
+
storage: typeof window > "u" ? new I() : window.localStorage,
|
41
31
|
storagePrefix: "ecency",
|
42
|
-
hiveClient: new
|
32
|
+
hiveClient: new q(
|
43
33
|
[
|
44
34
|
"https://api.hive.blog",
|
45
35
|
"https://api.deathwing.me",
|
@@ -59,449 +49,117 @@ const p = {
|
|
59
49
|
consoleOnFailover: !0
|
60
50
|
}
|
61
51
|
),
|
62
|
-
heliusApiKey:
|
63
|
-
};
|
64
|
-
function Tt(t, e) {
|
65
|
-
return w({
|
66
|
-
queryKey: ["ecency-wallets", "external-wallet-balance", t, e],
|
67
|
-
queryFn: async () => {
|
68
|
-
switch (t) {
|
69
|
-
case a.BTC:
|
70
|
-
const o = await (await fetch(
|
71
|
-
`https://mempool.space/api/address/${e}`
|
72
|
-
)).json();
|
73
|
-
return (o.chain_stats.funded_txo_sum - o.chain_stats.spent_txo_sum) / 1e8;
|
74
|
-
case a.ETH:
|
75
|
-
return +(await (await fetch(
|
76
|
-
`https://api.ethplorer.io/getAddressInfo/${e}?apiKey=freekey`
|
77
|
-
)).json()).ETH.balance;
|
78
|
-
case a.SOL:
|
79
|
-
return (await (await fetch(
|
80
|
-
`https://rpc.helius.xyz/?api-key=${p.heliusApiKey}`,
|
81
|
-
{
|
82
|
-
method: "POST",
|
83
|
-
body: JSON.stringify({
|
84
|
-
jsonrpc: "2.0",
|
85
|
-
id: "1",
|
86
|
-
method: "getBalance",
|
87
|
-
params: [e]
|
88
|
-
}),
|
89
|
-
headers: {
|
90
|
-
"Content-Type": "application/json"
|
91
|
-
}
|
92
|
-
}
|
93
|
-
)).json()).result.value / 1e9;
|
94
|
-
case a.TRON:
|
95
|
-
return (await (await fetch(
|
96
|
-
`https://api.trongrid.io/v1/accounts/${e}`
|
97
|
-
)).json()).data[0].balance / 1e6;
|
98
|
-
case a.TON:
|
99
|
-
return (await (await fetch(
|
100
|
-
`https://tonapi.io/v1/blockchain/getAccount?account=${e}`
|
101
|
-
)).json()).balance / 1e9;
|
102
|
-
case a.APT:
|
103
|
-
const g = (await (await fetch(
|
104
|
-
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${e}/resources`
|
105
|
-
)).json()).find(
|
106
|
-
(k) => k.type.includes("coin::CoinStore")
|
107
|
-
);
|
108
|
-
return g ? parseInt(g.data.coin.value) / 1e8 : 0;
|
109
|
-
case a.ATOM:
|
110
|
-
return +(await (await fetch(
|
111
|
-
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${e}`
|
112
|
-
)).json()).result.value.coins[0].amount / 1e6;
|
113
|
-
}
|
114
|
-
}
|
115
|
-
});
|
116
|
-
}
|
117
|
-
function P(t) {
|
118
|
-
return w({
|
119
|
-
queryKey: ["ecency-wallets", "seed", t],
|
120
|
-
queryFn: async () => L.generateMnemonic(128)
|
121
|
-
});
|
122
|
-
}
|
123
|
-
const M = {
|
124
|
-
max: 500,
|
125
|
-
// how long to live in ms
|
126
|
-
ttl: 1e3 * 60 * 5,
|
127
|
-
// return stale items before removing from cache?
|
128
|
-
allowStale: !1,
|
129
|
-
updateAgeOnGet: !1,
|
130
|
-
updateAgeOnHas: !1
|
131
|
-
}, O = new q(M), m = Symbol("undefined"), Q = (t, e) => O.set(t, e === void 0 ? m : e), W = (t) => {
|
132
|
-
const e = O.get(t);
|
133
|
-
return e === m ? void 0 : e;
|
134
|
-
};
|
135
|
-
function Pt(t) {
|
136
|
-
return w({
|
137
|
-
queryKey: ["ecency-wallets", "coingecko-price", t],
|
138
|
-
queryFn: async () => {
|
139
|
-
let e = t;
|
140
|
-
switch (t) {
|
141
|
-
case a.BTC:
|
142
|
-
e = "binance-wrapped-btc";
|
143
|
-
break;
|
144
|
-
case a.ETH:
|
145
|
-
e = "ethereum";
|
146
|
-
break;
|
147
|
-
case a.SOL:
|
148
|
-
e = "solana";
|
149
|
-
break;
|
150
|
-
case a.TON:
|
151
|
-
e = "trx";
|
152
|
-
break;
|
153
|
-
default:
|
154
|
-
e = t;
|
155
|
-
}
|
156
|
-
let n = W("gecko"), o;
|
157
|
-
if (n)
|
158
|
-
o = n;
|
159
|
-
else {
|
160
|
-
const i = await (await fetch(
|
161
|
-
"https://api.coingecko.com/api/v3/simple/price",
|
162
|
-
{
|
163
|
-
method: "POST",
|
164
|
-
body: JSON.stringify({
|
165
|
-
params: {
|
166
|
-
ids: [e],
|
167
|
-
vs_currencies: "usd"
|
168
|
-
}
|
169
|
-
})
|
170
|
-
}
|
171
|
-
)).json();
|
172
|
-
Q("gecko", i === void 0 ? m : i), o = i;
|
173
|
-
}
|
174
|
-
return 1 / +o[Object.keys(o)[0]].usd;
|
175
|
-
},
|
176
|
-
enabled: !!t
|
177
|
-
});
|
178
|
-
}
|
179
|
-
function I(t) {
|
180
|
-
const { data: e } = P(t);
|
181
|
-
return w({
|
182
|
-
queryKey: ["ecencу-wallets", "hive-keys", t, e],
|
183
|
-
queryFn: async () => {
|
184
|
-
if (!e)
|
185
|
-
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
186
|
-
const n = u.fromLogin(t, e, "owner"), o = u.fromLogin(t, e, "active"), s = u.fromLogin(t, e, "posting"), r = u.fromLogin(t, e, "memo");
|
187
|
-
return {
|
188
|
-
username: t,
|
189
|
-
owner: n.toString(),
|
190
|
-
active: o.toString(),
|
191
|
-
posting: s.toString(),
|
192
|
-
memo: r.toString(),
|
193
|
-
ownerPubkey: n.createPublic().toString(),
|
194
|
-
activePubkey: o.createPublic().toString(),
|
195
|
-
postingPubkey: s.createPublic().toString(),
|
196
|
-
memoPubkey: r.createPublic().toString()
|
197
|
-
};
|
198
|
-
}
|
199
|
-
});
|
200
|
-
}
|
201
|
-
function Ot(t, e) {
|
202
|
-
return f({
|
203
|
-
queryKey: ["ecency-wallets", "points", t, e],
|
204
|
-
queryFn: async () => await (await fetch(
|
205
|
-
`${p.privateApiHost}/private-api/points`,
|
206
|
-
{
|
207
|
-
method: "POST",
|
208
|
-
body: JSON.stringify({
|
209
|
-
username: t.replace("@", "")
|
210
|
-
})
|
211
|
-
}
|
212
|
-
)).json(),
|
213
|
-
staleTime: 3e4,
|
214
|
-
refetchOnMount: !0,
|
215
|
-
enabled: !!t
|
216
|
-
});
|
217
|
-
}
|
218
|
-
function J(t, e) {
|
219
|
-
return f({
|
220
|
-
queryKey: ["hive-engine", "tokens-list", t, e],
|
221
|
-
queryFn: async () => (await (await fetch(
|
222
|
-
`${p.privateApiHost}/private-api/engine-api`,
|
223
|
-
{
|
224
|
-
method: "POST",
|
225
|
-
body: JSON.stringify({
|
226
|
-
jsonrpc: "2.0",
|
227
|
-
method: "find",
|
228
|
-
params: {
|
229
|
-
contract: "market",
|
230
|
-
table: "metrics",
|
231
|
-
query: {
|
232
|
-
symbol: e,
|
233
|
-
account: t
|
234
|
-
}
|
235
|
-
},
|
236
|
-
id: 1
|
237
|
-
}),
|
238
|
-
headers: { "Content-type": "application/json" }
|
239
|
-
}
|
240
|
-
)).json()).result
|
241
|
-
});
|
242
|
-
}
|
243
|
-
function St(t) {
|
244
|
-
const { data: e } = w(J());
|
245
|
-
return K(
|
246
|
-
() => {
|
247
|
-
var n;
|
248
|
-
return {
|
249
|
-
basic: [
|
250
|
-
d.Points,
|
251
|
-
d.Hive,
|
252
|
-
d.HivePower,
|
253
|
-
d.HiveDollar,
|
254
|
-
d.Spk
|
255
|
-
].filter((o) => o.toLowerCase().includes(t.toLowerCase())),
|
256
|
-
external: Object.values(a).filter(
|
257
|
-
(o) => o.toLowerCase().includes(t.toLowerCase())
|
258
|
-
),
|
259
|
-
layer2: ((n = e == null ? void 0 : e.map(({ symbol: o }) => o)) == null ? void 0 : n.filter(
|
260
|
-
(o) => o.toLowerCase().includes(t.toLowerCase())
|
261
|
-
)) ?? []
|
262
|
-
};
|
263
|
-
},
|
264
|
-
[e, t]
|
265
|
-
);
|
266
|
-
}
|
267
|
-
const $ = {
|
268
|
-
[a.BTC]: "m/44'/0'/0'/0/0",
|
269
|
-
// Bitcoin (BIP44)
|
270
|
-
[a.ETH]: "m/44'/60'/0'/0/0",
|
271
|
-
// Ethereum (BIP44)
|
272
|
-
[a.SOL]: "m/44'/501'/0'/0'",
|
273
|
-
// Solana (BIP44)
|
274
|
-
[a.TON]: "m/44'/607'/0'",
|
275
|
-
// TON (BIP44)
|
276
|
-
[a.TRON]: "m/44'/195'/0'/0/0",
|
277
|
-
// Tron (BIP44)
|
278
|
-
[a.APT]: "m/44'/637'/0'/0'/0'",
|
279
|
-
// Aptos (BIP44)
|
280
|
-
[a.ATOM]: "m/44'/118'/0'/0/0"
|
281
|
-
// Cosmos (BIP44)
|
282
|
-
};
|
283
|
-
function At(t, e) {
|
284
|
-
const { data: n } = P(t), o = v(), s = l({
|
285
|
-
mutationKey: ["ecency-wallets", "create-wallet", t, e],
|
286
|
-
mutationFn: async () => {
|
287
|
-
if (!n)
|
288
|
-
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
289
|
-
const i = T(e), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
|
290
|
-
mnemonic: n,
|
291
|
-
hdPath: $[e]
|
292
|
-
}));
|
293
|
-
await B(1e3);
|
294
|
-
const h = await (i == null ? void 0 : i.getNewAddress({
|
295
|
-
privateKey: c
|
296
|
-
}));
|
297
|
-
return {
|
298
|
-
privateKey: c,
|
299
|
-
address: h.address,
|
300
|
-
publicKey: h.publicKey,
|
301
|
-
username: t,
|
302
|
-
currency: e
|
303
|
-
};
|
304
|
-
},
|
305
|
-
onSuccess: (i) => {
|
306
|
-
o.setQueryData(
|
307
|
-
["ecency-wallets", "wallets", i.username],
|
308
|
-
(c) => new Map(c ? Array.from(c.entries()) : []).set(i.currency, i)
|
309
|
-
);
|
310
|
-
}
|
311
|
-
}), r = C(() => {
|
312
|
-
}, []);
|
313
|
-
return {
|
314
|
-
createWallet: s,
|
315
|
-
importWallet: r
|
316
|
-
};
|
317
|
-
}
|
318
|
-
function G(t) {
|
319
|
-
const { data: e } = w({
|
320
|
-
queryKey: ["ecency-wallets", "wallets", t]
|
321
|
-
}), { data: n } = I(t);
|
322
|
-
return l({
|
323
|
-
mutationKey: ["ecency-wallets", "create-account-with-wallets", t],
|
324
|
-
mutationFn: ({ currency: o, address: s }) => fetch(p.privateApiHost + "/private-api/wallets-add", {
|
325
|
-
method: "POST",
|
326
|
-
headers: {
|
327
|
-
"Content-Type": "application/json"
|
328
|
-
},
|
329
|
-
body: JSON.stringify({
|
330
|
-
username: t,
|
331
|
-
token: o,
|
332
|
-
address: s,
|
333
|
-
meta: {
|
334
|
-
ownerPublicKey: n == null ? void 0 : n.ownerPubkey,
|
335
|
-
activePublicKey: n == null ? void 0 : n.activePubkey,
|
336
|
-
postingPublicKey: n == null ? void 0 : n.postingPubkey,
|
337
|
-
memoPublicKey: n == null ? void 0 : n.memoPubkey,
|
338
|
-
...Array.from((e == null ? void 0 : e.entries()) ?? []).reduce(
|
339
|
-
(r, [i, c]) => ({
|
340
|
-
...r,
|
341
|
-
[i]: c.address
|
342
|
-
}),
|
343
|
-
{}
|
344
|
-
)
|
345
|
-
}
|
346
|
-
})
|
347
|
-
})
|
348
|
-
});
|
349
|
-
}
|
350
|
-
function S() {
|
351
|
-
return l({
|
352
|
-
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
353
|
-
mutationFn: async ({ address: t, currency: e }) => (await (await fetch(
|
354
|
-
p.privateApiHost + "/private-api/wallets-exist",
|
355
|
-
{
|
356
|
-
method: "POST",
|
357
|
-
headers: {
|
358
|
-
"Content-Type": "application/json"
|
359
|
-
},
|
360
|
-
body: JSON.stringify({
|
361
|
-
address: t,
|
362
|
-
token: e
|
363
|
-
})
|
364
|
-
}
|
365
|
-
)).json()).length === 0
|
366
|
-
});
|
367
|
-
}
|
368
|
-
const kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
369
|
-
__proto__: null,
|
370
|
-
useCheckWalletExistence: S,
|
371
|
-
useCreateAccountWithWallets: G
|
372
|
-
}, Symbol.toStringTag, { value: "Module" })), U = {
|
373
|
-
[a.BTC]: ["m/84'/0'/0'/0/0"],
|
374
|
-
[a.ETH]: ["m/84'/60'/0'/0/0"],
|
375
|
-
// its not working for Trust, Exodus, todo: check others below
|
376
|
-
[a.SOL]: ["m/84'/501'/0'/0/0"],
|
377
|
-
[a.TRON]: ["m/44'/195'/0'/0'/0'"],
|
378
|
-
[a.APT]: ["m/84'/637'/0'/0/0"],
|
379
|
-
[a.TON]: [],
|
380
|
-
// Disabled
|
381
|
-
[a.ATOM]: ["m/84'/118'/0'/0'/0"]
|
52
|
+
heliusApiKey: void 0
|
382
53
|
};
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
mnemonic: t,
|
388
|
-
hdPath: o
|
389
|
-
}), r = await e.getNewAddress({
|
390
|
-
privateKey: s,
|
391
|
-
addressType: n === a.BTC ? "segwit_native" : void 0
|
392
|
-
});
|
393
|
-
return [s.toString(), r.address];
|
394
|
-
} catch {
|
395
|
-
return [];
|
396
|
-
}
|
397
|
-
return [];
|
398
|
-
}
|
399
|
-
function Kt(t, e) {
|
400
|
-
const n = v(), { mutateAsync: o } = S();
|
401
|
-
return l({
|
402
|
-
mutationKey: ["ecency-wallets", "import-wallet", t, e],
|
403
|
-
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
404
|
-
const r = T(e);
|
405
|
-
if (!r)
|
406
|
-
throw new Error("Cannot find token for this currency");
|
407
|
-
const i = s.split(" ").length === 12;
|
408
|
-
let c, h = s;
|
409
|
-
if (i ? [h, c] = await V(
|
410
|
-
s,
|
411
|
-
r,
|
412
|
-
e
|
413
|
-
) : c = (await r.getNewAddress({
|
414
|
-
privateKey: s
|
415
|
-
})).address, !c || !s)
|
416
|
-
throw new Error(
|
417
|
-
"Private key/seed phrase isn't matching with public key or token"
|
418
|
-
);
|
419
|
-
if (!await o({
|
420
|
-
address: c,
|
421
|
-
currency: e
|
422
|
-
}))
|
423
|
-
throw new Error(
|
424
|
-
"This wallet has already in use by Hive account. Please, try another one"
|
425
|
-
);
|
426
|
-
return {
|
427
|
-
privateKey: h,
|
428
|
-
address: c,
|
429
|
-
publicKey: ""
|
430
|
-
};
|
431
|
-
},
|
432
|
-
onSuccess: ({ privateKey: s, publicKey: r, address: i }) => {
|
433
|
-
n.setQueryData(
|
434
|
-
["ecency-wallets", "wallets", t],
|
435
|
-
(c) => new Map(c ? Array.from(c.entries()) : []).set(e, {
|
436
|
-
privateKey: s,
|
437
|
-
publicKey: r,
|
438
|
-
address: i,
|
439
|
-
username: t,
|
440
|
-
currency: e,
|
441
|
-
custom: !0
|
442
|
-
})
|
443
|
-
);
|
444
|
-
}
|
445
|
-
});
|
54
|
+
function A(e) {
|
55
|
+
let t = atob(e);
|
56
|
+
if (t[0] === "{")
|
57
|
+
return JSON.parse(t);
|
446
58
|
}
|
447
|
-
|
448
|
-
let e = atob(t);
|
449
|
-
if (e[0] === "{")
|
450
|
-
return JSON.parse(e);
|
451
|
-
}
|
452
|
-
const y = (t) => {
|
59
|
+
const p = (e) => {
|
453
60
|
try {
|
454
|
-
const
|
455
|
-
|
61
|
+
const t = a.storage.getItem(
|
62
|
+
a.storagePrefix + "_user_" + e
|
456
63
|
);
|
457
|
-
return
|
458
|
-
} catch (
|
459
|
-
console.error(
|
64
|
+
return A(JSON.parse(t));
|
65
|
+
} catch (t) {
|
66
|
+
console.error(t);
|
460
67
|
return;
|
461
68
|
}
|
462
|
-
},
|
463
|
-
function
|
464
|
-
return
|
465
|
-
mutationKey: [...
|
466
|
-
mutationFn: async (
|
467
|
-
if (!
|
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({
|
72
|
+
mutationKey: [...e, t],
|
73
|
+
mutationFn: async (i) => {
|
74
|
+
if (!t)
|
468
75
|
throw new Error(
|
469
76
|
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
470
77
|
);
|
471
|
-
const
|
472
|
-
if (
|
473
|
-
const
|
474
|
-
return
|
475
|
-
n(
|
476
|
-
|
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
|
477
84
|
);
|
478
85
|
}
|
479
|
-
let
|
480
|
-
if (
|
481
|
-
return (await new
|
482
|
-
accessToken:
|
483
|
-
}).broadcast(n(
|
86
|
+
let s = D(t);
|
87
|
+
if (s)
|
88
|
+
return (await new v.Client({
|
89
|
+
accessToken: s
|
90
|
+
}).broadcast(n(i))).result;
|
484
91
|
throw new Error(
|
485
92
|
"[SDK][Broadcast] – cannot broadcast w/o posting key or token"
|
486
93
|
);
|
487
94
|
}
|
488
95
|
});
|
489
96
|
}
|
490
|
-
function
|
491
|
-
return
|
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(
|
492
150
|
["accounts", "update"],
|
493
|
-
|
151
|
+
e,
|
494
152
|
({
|
495
|
-
profile:
|
153
|
+
profile: t,
|
496
154
|
tokens: n
|
497
155
|
}) => [
|
498
156
|
[
|
499
157
|
"account_update2",
|
500
158
|
{
|
501
|
-
account:
|
159
|
+
account: e,
|
502
160
|
json_metadata: "",
|
503
161
|
posting_json_metadata: JSON.stringify({
|
504
|
-
profile: { ...
|
162
|
+
profile: { ...t, version: 2 },
|
505
163
|
tokens: n
|
506
164
|
}),
|
507
165
|
extensions: []
|
@@ -510,138 +168,156 @@ function tt(t) {
|
|
510
168
|
]
|
511
169
|
);
|
512
170
|
}
|
513
|
-
function
|
514
|
-
return
|
515
|
-
queryKey: ["get-account-full",
|
171
|
+
function U(e) {
|
172
|
+
return l({
|
173
|
+
queryKey: ["get-account-full", e],
|
516
174
|
queryFn: async () => {
|
517
|
-
if (!
|
175
|
+
if (!e)
|
518
176
|
throw new Error("[SDK] Username is empty");
|
519
|
-
const
|
520
|
-
if (!
|
177
|
+
const t = await a.hiveClient.database.getAccounts([e]);
|
178
|
+
if (!t[0])
|
521
179
|
throw new Error("[SDK] No account with given username");
|
522
|
-
const n = JSON.parse(
|
523
|
-
let
|
180
|
+
const n = JSON.parse(t[0].posting_json_metadata).profile;
|
181
|
+
let i;
|
524
182
|
try {
|
525
|
-
|
183
|
+
i = await a.hiveClient.database.call(
|
526
184
|
"get_follow_count",
|
527
|
-
[
|
185
|
+
[e]
|
528
186
|
);
|
529
187
|
} catch {
|
530
188
|
}
|
531
|
-
const
|
189
|
+
const o = await a.hiveClient.call(
|
532
190
|
"condenser_api",
|
533
191
|
"get_account_reputations",
|
534
|
-
[
|
192
|
+
[e, 1]
|
535
193
|
);
|
536
194
|
return {
|
537
|
-
...
|
538
|
-
follow_stats:
|
539
|
-
reputation:
|
195
|
+
...t,
|
196
|
+
follow_stats: i,
|
197
|
+
reputation: o[0].reputation,
|
540
198
|
profile: {
|
541
199
|
...n,
|
542
|
-
reputation:
|
200
|
+
reputation: o[0].reputation
|
543
201
|
}
|
544
202
|
};
|
545
203
|
},
|
546
|
-
enabled: !!
|
204
|
+
enabled: !!e,
|
547
205
|
staleTime: 6e4
|
548
206
|
});
|
549
207
|
}
|
550
|
-
function
|
551
|
-
return
|
552
|
-
queryKey: ["accounts", "search",
|
553
|
-
enabled: !!
|
554
|
-
queryFn: async () => (await
|
208
|
+
function G(e, t = 5, n = []) {
|
209
|
+
return l({
|
210
|
+
queryKey: ["accounts", "search", e, n],
|
211
|
+
enabled: !!e,
|
212
|
+
queryFn: async () => (await a.hiveClient.database.call(
|
555
213
|
"lookup_accounts",
|
556
|
-
[
|
214
|
+
[e, t]
|
557
215
|
)).filter(
|
558
|
-
(
|
216
|
+
(o) => n.length > 0 ? !n.includes(o) : !0
|
559
217
|
)
|
560
218
|
});
|
561
219
|
}
|
562
|
-
function
|
563
|
-
|
564
|
-
|
565
|
-
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", t],
|
566
|
-
mutationFn: ({
|
567
|
-
wallets: n
|
568
|
-
}) => e({
|
569
|
-
profile: {},
|
570
|
-
tokens: Array.from(n.entries() ?? []).map(([o, s]) => ({
|
571
|
-
symbol: o,
|
572
|
-
type: "CHAIN",
|
573
|
-
meta: {
|
574
|
-
address: s.address
|
575
|
-
}
|
576
|
-
}))
|
577
|
-
})
|
578
|
-
});
|
579
|
-
}
|
580
|
-
function Nt(t) {
|
581
|
-
return l({
|
582
|
-
mutationKey: ["operations", "sign", t],
|
220
|
+
function M(e) {
|
221
|
+
return f({
|
222
|
+
mutationKey: ["operations", "sign", e],
|
583
223
|
mutationFn: ({
|
584
|
-
operation:
|
224
|
+
operation: t,
|
585
225
|
keyOrSeed: n
|
586
226
|
}) => {
|
587
|
-
if (!
|
227
|
+
if (!e)
|
588
228
|
throw new Error("[Operations][Sign] – cannot sign op with anon user");
|
589
|
-
let
|
590
|
-
return n.split(" ").length === 12 ?
|
591
|
-
[
|
592
|
-
|
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(
|
231
|
+
[t],
|
232
|
+
i
|
593
233
|
);
|
594
234
|
}
|
595
235
|
});
|
596
236
|
}
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
t
|
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(
|
601
248
|
e,
|
249
|
+
t,
|
602
250
|
n,
|
603
|
-
(
|
604
|
-
|
251
|
+
(r) => {
|
252
|
+
r.success || s({ message: "Operation cancelled" }), o(r);
|
605
253
|
},
|
606
|
-
|
254
|
+
i
|
607
255
|
);
|
608
|
-
})
|
609
|
-
|
610
|
-
|
611
|
-
|
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({
|
263
|
+
mutationKey: ["operations", "sign-keychain", e],
|
612
264
|
mutationFn: ({ operation: n }) => {
|
613
|
-
if (!
|
265
|
+
if (!e)
|
614
266
|
throw new Error(
|
615
267
|
"[SDK][Keychain] – cannot sign operation with anon user"
|
616
268
|
);
|
617
|
-
return
|
269
|
+
return m(e, [n], t);
|
618
270
|
}
|
619
271
|
});
|
620
272
|
}
|
621
|
-
function
|
622
|
-
return
|
623
|
-
mutationKey: ["operations", "sign-hivesigner",
|
624
|
-
mutationFn: async ({ operation:
|
273
|
+
function R(e = "/") {
|
274
|
+
return f({
|
275
|
+
mutationKey: ["operations", "sign-hivesigner", e],
|
276
|
+
mutationFn: async ({ operation: t }) => v.sendOperation(t, { callback: e }, () => {
|
625
277
|
})
|
626
278
|
});
|
627
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
|
+
}
|
628
305
|
export {
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
At 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
|
647
323
|
};
|
package/dist/index.d.ts
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
export declare class MockStorage implements Storage {
|
2
|
+
[name: string]: any;
|
3
|
+
length: number;
|
4
|
+
clear(): void;
|
5
|
+
getItem(key: string): string | null;
|
6
|
+
key(index: number): string | null;
|
7
|
+
removeItem(key: string): void;
|
8
|
+
setItem(key: string, value: string): void;
|
9
|
+
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ecency/sdk",
|
3
3
|
"private": false,
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.26",
|
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
|
-
"
|
36
|
-
"@
|
37
|
-
"@
|
38
|
-
"
|
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
|
-
[](https://www.npmjs.com/package/@ecency/wallets) [](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 +0,0 @@
|
|
1
|
-
export * from './get-keys-from-seed';
|
@@ -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,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,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,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 +0,0 @@
|
|
1
|
-
export declare function useSeedPhrase(username: string): import('@tanstack/react-query').UseQueryResult<string, Error>;
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare function delay(ms: number): Promise<unknown>;
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare function mnemonicToSeedBip39(value: string): string;
|
File without changes
|