@ecency/sdk 1.0.16 → 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.
- package/dist/config.d.ts +8 -0
- package/dist/ecency-sdk.es.js +176 -163
- package/dist/index.d.ts +3 -0
- package/dist/modules/accounts/index.d.ts +2 -0
- package/dist/modules/accounts/mutations/index.d.ts +1 -0
- package/dist/modules/accounts/mutations/use-account-update.d.ts +1 -0
- package/dist/modules/accounts/queries/index.d.ts +1 -0
- package/dist/modules/accounts/queries/search-accounts-by-username-query-options.d.ts +8 -0
- package/dist/modules/core/entities/index.d.ts +1 -0
- package/dist/modules/core/entities/user.d.ts +8 -0
- package/dist/modules/core/index.d.ts +3 -0
- package/dist/modules/core/mutations/index.d.ts +1 -0
- package/dist/modules/core/mutations/use-broadcast-mutation.d.ts +3 -0
- package/dist/modules/core/storage.d.ts +5 -0
- package/dist/modules/core/utils/decoder-encoder.d.ts +2 -0
- package/dist/modules/core/utils/index.d.ts +1 -0
- package/dist/modules/keychain/index.d.ts +2 -0
- package/dist/modules/keychain/keychain.d.ts +9 -0
- package/dist/modules/operations/index.d.ts +1 -0
- package/dist/modules/operations/mutations/index.d.ts +3 -0
- package/dist/modules/operations/mutations/sign-operation-by-hivesigner.d.ts +4 -0
- package/dist/modules/operations/mutations/sign-operation-by-key.d.ts +5 -0
- package/dist/modules/operations/mutations/sign-operation-by-keychain.d.ts +5 -0
- package/dist/modules/wallets/enums/ecency-wallet-currency.d.ts +9 -0
- package/dist/modules/wallets/enums/index.d.ts +1 -0
- package/dist/modules/wallets/functions/get-keys-from-seed.d.ts +3 -0
- package/dist/modules/wallets/functions/index.d.ts +1 -0
- package/dist/modules/wallets/index.d.ts +5 -0
- package/dist/modules/wallets/mutations/index.d.ts +4 -0
- package/dist/modules/wallets/mutations/private-api/check-wallet-existence.d.ts +7 -0
- package/dist/modules/wallets/mutations/private-api/create-account-with-wallets.d.ts +7 -0
- package/dist/modules/wallets/mutations/private-api/index.d.ts +2 -0
- package/dist/modules/wallets/mutations/private-api-namespace.d.ts +2 -0
- package/dist/modules/wallets/mutations/save-wallet-information-to-metadata.d.ts +5 -0
- package/dist/modules/wallets/mutations/use-import-wallet.d.ts +10 -0
- package/dist/modules/wallets/mutations/use-wallet-create.d.ts +6 -0
- package/dist/modules/wallets/queries/index.d.ts +4 -0
- package/dist/modules/wallets/queries/use-coingecko-price-query.d.ts +2 -0
- package/dist/modules/wallets/queries/use-get-external-wallet-query.d.ts +10 -0
- package/dist/modules/wallets/queries/use-hive-keys-query.d.ts +2 -0
- package/dist/modules/wallets/queries/use-seed-phrase.d.ts +1 -0
- package/dist/modules/wallets/types/ecency-create-wallet-information.d.ts +9 -0
- package/dist/modules/wallets/types/ecency-hive-keys.d.ts +12 -0
- package/dist/modules/wallets/types/index.d.ts +2 -0
- package/dist/modules/wallets/utils/delay.d.ts +1 -0
- package/dist/modules/wallets/utils/get-wallet.d.ts +3 -0
- package/dist/modules/wallets/utils/index.d.ts +3 -0
- package/dist/modules/wallets/utils/mnemonic-to-seed-bip-39.d.ts +1 -0
- package/package.json +5 -5
- package/dist/ecency-sdk.es.d.ts +0 -132
package/dist/config.d.ts
ADDED
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,48 +1,48 @@
|
|
1
1
|
import { useCallback as k } from "react";
|
2
|
-
import { useQuery 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
|
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
|
11
|
-
import { Client as
|
12
|
-
import { LRUCache as
|
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__ */ ((
|
15
|
-
function
|
16
|
-
return new Promise((
|
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(
|
19
|
-
switch (
|
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.
|
22
|
+
case o.ETH:
|
25
23
|
return new R();
|
26
|
-
case o.
|
24
|
+
case o.TRON:
|
27
25
|
return new C();
|
28
|
-
case o.
|
26
|
+
case o.TON:
|
29
27
|
return new N();
|
28
|
+
case o.SOL:
|
29
|
+
return new _();
|
30
30
|
case o.ATOM:
|
31
|
-
return new
|
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
|
39
|
-
return
|
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
|
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
|
68
|
-
return
|
69
|
-
queryKey: ["ecency-wallets", "external-wallet-balance",
|
67
|
+
function be(e, t) {
|
68
|
+
return m({
|
69
|
+
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
70
70
|
queryFn: async () => {
|
71
|
-
switch (
|
71
|
+
switch (e) {
|
72
72
|
case o.BTC:
|
73
73
|
const a = await (await fetch(
|
74
|
-
`https://mempool.space/api/address/${
|
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/${
|
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: [
|
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/${
|
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=${
|
103
|
+
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
104
104
|
)).json()).balance / 1e9;
|
105
105
|
case o.APT:
|
106
|
-
const
|
107
|
-
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${
|
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
|
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/${
|
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(
|
121
|
-
return
|
122
|
-
queryKey: ["ecency-wallets", "seed",
|
123
|
-
queryFn: async () =>
|
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
|
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
|
135
|
-
const
|
136
|
-
return
|
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
|
139
|
-
return
|
140
|
-
queryKey: ["ecency-wallets", "coingecko-price",
|
138
|
+
function ve(e) {
|
139
|
+
return m({
|
140
|
+
queryKey: ["ecency-wallets", "coingecko-price", e],
|
141
141
|
queryFn: async () => {
|
142
|
-
let
|
143
|
-
switch (
|
142
|
+
let t = e;
|
143
|
+
switch (e) {
|
144
144
|
case o.BTC:
|
145
|
-
|
145
|
+
t = "binance-wrapped-btc";
|
146
146
|
break;
|
147
147
|
case o.ETH:
|
148
|
-
|
148
|
+
t = "ethereum";
|
149
149
|
break;
|
150
150
|
case o.SOL:
|
151
|
-
|
151
|
+
t = "solana";
|
152
152
|
break;
|
153
153
|
case o.TON:
|
154
|
-
|
154
|
+
t = "trx";
|
155
155
|
break;
|
156
156
|
default:
|
157
|
-
|
157
|
+
t = e;
|
158
158
|
}
|
159
|
-
let n =
|
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: [
|
169
|
+
ids: [t],
|
170
170
|
vs_currencies: "usd"
|
171
171
|
}
|
172
172
|
})
|
173
173
|
}
|
174
174
|
)).json();
|
175
|
-
|
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: !!
|
179
|
+
enabled: !!e
|
180
180
|
});
|
181
181
|
}
|
182
|
-
function
|
183
|
-
const { data:
|
184
|
-
return
|
185
|
-
queryKey: ["ecencу-wallets", "hive-keys",
|
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 (!
|
187
|
+
if (!t)
|
188
188
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
189
|
-
const n = p.fromLogin(
|
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:
|
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
|
221
|
-
const { data: n } = b(
|
222
|
-
mutationKey: ["ecency-wallets", "create-wallet",
|
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(
|
226
|
+
const i = T(t), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
|
227
227
|
mnemonic: n,
|
228
|
-
hdPath: I[
|
228
|
+
hdPath: I[t]
|
229
229
|
}));
|
230
|
-
await
|
231
|
-
const
|
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:
|
237
|
-
publicKey:
|
238
|
-
username:
|
239
|
-
currency:
|
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(
|
256
|
-
const { data:
|
257
|
-
queryKey: ["ecency-wallets", "wallets",
|
258
|
-
}), { data: n } =
|
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",
|
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:
|
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((
|
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:
|
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:
|
299
|
-
token:
|
298
|
+
address: e,
|
299
|
+
token: t
|
300
300
|
})
|
301
301
|
}
|
302
302
|
)).json()).length === 0
|
303
303
|
});
|
304
304
|
}
|
305
|
-
const
|
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" })),
|
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
|
321
|
-
for (const a of
|
320
|
+
async function G(e, t, n) {
|
321
|
+
for (const a of $[n] || [])
|
322
322
|
try {
|
323
|
-
const s = await
|
324
|
-
mnemonic:
|
323
|
+
const s = await t.getDerivedPrivateKey({
|
324
|
+
mnemonic: e,
|
325
325
|
hdPath: a
|
326
|
-
}), r = await
|
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
|
337
|
-
const n =
|
336
|
+
function Oe(e, t) {
|
337
|
+
const n = w(), { mutateAsync: a } = P();
|
338
338
|
return l({
|
339
|
-
mutationKey: ["ecency-wallets", "import-wallet",
|
339
|
+
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
340
340
|
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
341
|
-
const r = T(
|
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,
|
346
|
-
if (i ? [
|
345
|
+
let c, h = s;
|
346
|
+
if (i ? [h, c] = await G(
|
347
347
|
s,
|
348
348
|
r,
|
349
|
-
|
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:
|
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:
|
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",
|
372
|
-
(c) => new Map(c ? Array.from(c.entries()) : []).set(
|
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:
|
377
|
-
currency:
|
376
|
+
username: e,
|
377
|
+
currency: t,
|
378
378
|
custom: !0
|
379
379
|
})
|
380
380
|
);
|
381
381
|
}
|
382
382
|
});
|
383
383
|
}
|
384
|
-
function
|
385
|
-
let
|
386
|
-
if (
|
387
|
-
return JSON.parse(
|
384
|
+
function U(e) {
|
385
|
+
let t = atob(e);
|
386
|
+
if (t[0] === "{")
|
387
|
+
return JSON.parse(t);
|
388
388
|
}
|
389
|
-
const d = (
|
389
|
+
const d = (e) => {
|
390
390
|
try {
|
391
|
-
const
|
392
|
-
u.storagePrefix + "_user_" +
|
391
|
+
const t = u.storage.getItem(
|
392
|
+
u.storagePrefix + "_user_" + e
|
393
393
|
);
|
394
|
-
return
|
395
|
-
} catch (
|
396
|
-
console.error(
|
394
|
+
return U(JSON.parse(t));
|
395
|
+
} catch (t) {
|
396
|
+
console.error(t);
|
397
397
|
return;
|
398
398
|
}
|
399
|
-
},
|
400
|
-
function
|
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: [...
|
402
|
+
mutationKey: [...e, t],
|
403
403
|
mutationFn: async (a) => {
|
404
|
-
if (!
|
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 =
|
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 =
|
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
|
428
|
-
return
|
427
|
+
function Y(e) {
|
428
|
+
return X(
|
429
429
|
["accounts", "update"],
|
430
|
-
|
431
|
-
(
|
430
|
+
e,
|
431
|
+
(t) => [
|
432
432
|
[
|
433
433
|
"account_update2",
|
434
434
|
{
|
435
|
-
account:
|
435
|
+
account: e,
|
436
436
|
json_metadata: "",
|
437
437
|
posting_json_metadata: JSON.stringify({
|
438
|
-
profile: { ...
|
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
|
447
|
-
|
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",
|
461
|
+
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
|
450
462
|
mutationFn: ({
|
451
463
|
wallets: n
|
452
|
-
}) =>
|
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
|
475
|
+
function Ke(e) {
|
464
476
|
return l({
|
465
|
-
mutationKey: ["operations", "sign",
|
477
|
+
mutationKey: ["operations", "sign", e],
|
466
478
|
mutationFn: ({
|
467
|
-
operation:
|
479
|
+
operation: t,
|
468
480
|
keyOrSeed: n
|
469
481
|
}) => {
|
470
|
-
if (!
|
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(
|
474
|
-
[
|
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
|
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
|
493
|
-
l({
|
494
|
-
mutationKey: ["operations", "sign-keychain",
|
504
|
+
function Re(e, t = "Active") {
|
505
|
+
return l({
|
506
|
+
mutationKey: ["operations", "sign-keychain", e],
|
495
507
|
mutationFn: ({ operation: n }) => {
|
496
|
-
if (!
|
508
|
+
if (!e)
|
497
509
|
throw new Error(
|
498
510
|
"[SDK][Keychain] – cannot sign operation with anon user"
|
499
511
|
);
|
500
|
-
return
|
512
|
+
return Z(e, [n], t);
|
501
513
|
}
|
502
514
|
});
|
503
515
|
}
|
504
|
-
function
|
505
|
-
l({
|
506
|
-
mutationKey: ["operations", "sign-hivesigner",
|
507
|
-
mutationFn: async ({ operation:
|
516
|
+
function Ce(e = "/") {
|
517
|
+
return l({
|
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
|
-
|
514
|
-
|
525
|
+
Se as EcencyWalletsPrivateApi,
|
526
|
+
W as delay,
|
527
|
+
ke as getSearchAccountsByUsernameQueryOptions,
|
515
528
|
T as getWallet,
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
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
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
537
|
+
Ce as useSignOperationByHivesigner,
|
538
|
+
Ke as useSignOperationByKey,
|
539
|
+
Re as useSignOperationByKeychain,
|
540
|
+
Pe as useWalletCreate
|
528
541
|
};
|
package/dist/index.d.ts
ADDED
@@ -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 @@
|
|
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 @@
|
|
1
|
+
export * from './decoder-encoder';
|
@@ -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,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 @@
|
|
1
|
+
export * from './ecency-wallet-currency';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './get-keys-from-seed';
|
@@ -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,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,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 @@
|
|
1
|
+
export declare function useSeedPhrase(username: string): import('@tanstack/react-query').UseQueryResult<string, Error>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function delay(ms: number): Promise<unknown>;
|
@@ -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.
|
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/
|
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.
|
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": "
|
29
|
+
"typescript": "5.8.3",
|
30
30
|
"vite": "^6.2.0",
|
31
|
-
"vite-plugin-dts": "
|
31
|
+
"vite-plugin-dts": "4.5.3",
|
32
32
|
"vite-plugin-node-polyfills": "^0.23.0"
|
33
33
|
},
|
34
34
|
"dependencies": {
|
package/dist/ecency-sdk.es.d.ts
DELETED
@@ -1,132 +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): void;
|
119
|
-
|
120
|
-
export declare function useSignOperationByKey(username: string | undefined): UseMutationResult<TransactionConfirmation, Error, {
|
121
|
-
operation: Operation;
|
122
|
-
keyOrSeed: string;
|
123
|
-
}, unknown>;
|
124
|
-
|
125
|
-
export declare function useSignOperationByKeychain(username: string | undefined, keyType?: Keychain.KeychainAuthorityTypes): void;
|
126
|
-
|
127
|
-
export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
|
128
|
-
createWallet: UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
|
129
|
-
importWallet: () => void;
|
130
|
-
};
|
131
|
-
|
132
|
-
export { }
|