@ecency/sdk 1.0.14 → 1.0.16
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.d.ts +28 -1
- package/dist/ecency-sdk.es.js +248 -205
- package/package.json +1 -1
package/dist/ecency-sdk.es.d.ts
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
import { BaseWallet } from '@okxweb3/coin-base';
|
2
2
|
import { Operation } from '@hiveio/dhive';
|
3
|
+
import { TransactionConfirmation } from '@hiveio/dhive';
|
3
4
|
import { UseMutationResult } from '@tanstack/react-query';
|
4
5
|
import { UseQueryResult } from '@tanstack/react-query';
|
5
6
|
|
7
|
+
declare const broadcast: (account: string, operations: Operation[], key: KeychainAuthorityTypes, rpc?: string | null) => Promise<TxResponse>;
|
8
|
+
|
6
9
|
export declare function delay(ms: number): Promise<unknown>;
|
7
10
|
|
8
11
|
export declare interface EcencyCreateWalletInformation {
|
@@ -47,6 +50,18 @@ export { EcencyWalletsPrivateApi }
|
|
47
50
|
|
48
51
|
export declare function getWallet(currency: EcencyWalletCurrency): BaseWallet | undefined;
|
49
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
|
+
|
50
65
|
export declare function mnemonicToSeedBip39(value: string): string;
|
51
66
|
|
52
67
|
declare interface Payload {
|
@@ -63,6 +78,11 @@ declare interface Payload_3 {
|
|
63
78
|
privateKeyOrSeed: string;
|
64
79
|
}
|
65
80
|
|
81
|
+
declare interface TxResponse {
|
82
|
+
success: boolean;
|
83
|
+
result: string;
|
84
|
+
}
|
85
|
+
|
66
86
|
export declare function useAccountUpdate(username: string): UseMutationResult<any, Error, any, unknown>;
|
67
87
|
|
68
88
|
declare function useCheckWalletExistence(): UseMutationResult<boolean, Error, Payload_2, unknown>;
|
@@ -95,7 +115,14 @@ wallets: Map<EcencyWalletCurrency, EcencyCreateWalletInformation>;
|
|
95
115
|
|
96
116
|
export declare function useSeedPhrase(username: string): UseQueryResult<string, Error>;
|
97
117
|
|
98
|
-
export declare function
|
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;
|
99
126
|
|
100
127
|
export declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
|
101
128
|
createWallet: UseMutationResult<EcencyCreateWalletInformation, Error, void, unknown>;
|
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import { useCallback as
|
2
|
-
import { useQuery as
|
1
|
+
import { useCallback as k } from "react";
|
2
|
+
import { useQuery as h, useQueryClient as f, useMutation as l } from "@tanstack/react-query";
|
3
3
|
import { BtcWallet as A } from "@okxweb3/coin-bitcoin";
|
4
|
-
import { EthWallet as
|
5
|
-
import { TrxWallet as
|
4
|
+
import { EthWallet as K } from "@okxweb3/coin-ethereum";
|
5
|
+
import { TrxWallet as R } from "@okxweb3/coin-tron";
|
6
6
|
import { TonWallet as C } from "@okxweb3/coin-ton";
|
7
7
|
import { SolWallet as N } from "@okxweb3/coin-solana";
|
8
8
|
import { AtomWallet as x } from "@okxweb3/coin-cosmos";
|
9
|
-
import { AptosWallet as
|
10
|
-
import
|
11
|
-
import { Client as
|
9
|
+
import { AptosWallet as D } from "@okxweb3/coin-aptos";
|
10
|
+
import _, { mnemonicToSeedSync as j } from "bip39";
|
11
|
+
import { Client as B, PrivateKey as p, cryptoUtils as H } from "@hiveio/dhive";
|
12
12
|
import { LRUCache as E } from "lru-cache";
|
13
|
-
import
|
14
|
-
var o = /* @__PURE__ */ ((
|
15
|
-
function
|
16
|
-
return new Promise((
|
13
|
+
import g from "hivesigner";
|
14
|
+
var o = /* @__PURE__ */ ((t) => (t.BTC = "BTC", t.ETH = "ETH", t.APT = "APT", t.ATOM = "ATOM", t.TON = "TON", t.TRON = "TRX", t.SOL = "SOL", t))(o || {});
|
15
|
+
function F(t) {
|
16
|
+
return new Promise((e) => setTimeout(e, t));
|
17
17
|
}
|
18
|
-
function
|
19
|
-
switch (
|
18
|
+
function T(t) {
|
19
|
+
switch (t) {
|
20
20
|
case o.BTC:
|
21
21
|
return new A();
|
22
22
|
case o.ETH:
|
23
|
-
return new R();
|
24
|
-
case o.TRON:
|
25
23
|
return new K();
|
24
|
+
case o.TRON:
|
25
|
+
return new R();
|
26
26
|
case o.TON:
|
27
27
|
return new C();
|
28
28
|
case o.SOL:
|
@@ -30,19 +30,19 @@ function g(e) {
|
|
30
30
|
case o.ATOM:
|
31
31
|
return new x();
|
32
32
|
case o.APT:
|
33
|
-
return new
|
33
|
+
return new D();
|
34
34
|
default:
|
35
35
|
return;
|
36
36
|
}
|
37
37
|
}
|
38
|
-
function
|
39
|
-
return
|
38
|
+
function gt(t) {
|
39
|
+
return j(t).toString("hex");
|
40
40
|
}
|
41
|
-
const
|
41
|
+
const u = {
|
42
42
|
privateApiHost: "https://ecency.com",
|
43
43
|
storage: localStorage,
|
44
44
|
storagePrefix: "ecency",
|
45
|
-
hiveClient: new
|
45
|
+
hiveClient: new B(
|
46
46
|
[
|
47
47
|
"https://api.hive.blog",
|
48
48
|
"https://api.deathwing.me",
|
@@ -64,30 +64,30 @@ const p = {
|
|
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 Tt(t, e) {
|
68
|
+
return h({
|
69
|
+
queryKey: ["ecency-wallets", "external-wallet-balance", t, e],
|
70
70
|
queryFn: async () => {
|
71
|
-
switch (
|
71
|
+
switch (t) {
|
72
72
|
case o.BTC:
|
73
|
-
const
|
74
|
-
`https://mempool.space/api/address/${
|
73
|
+
const a = await (await fetch(
|
74
|
+
`https://mempool.space/api/address/${e}`
|
75
75
|
)).json();
|
76
|
-
return (
|
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/${e}?apiKey=freekey`
|
80
80
|
)).json()).ETH.balance;
|
81
81
|
case o.SOL:
|
82
82
|
return (await (await fetch(
|
83
|
-
`https://rpc.helius.xyz/?api-key=${
|
83
|
+
`https://rpc.helius.xyz/?api-key=${u.heliusApiKey}`,
|
84
84
|
{
|
85
85
|
method: "POST",
|
86
86
|
body: JSON.stringify({
|
87
87
|
jsonrpc: "2.0",
|
88
88
|
id: "1",
|
89
89
|
method: "getBalance",
|
90
|
-
params: [
|
90
|
+
params: [e]
|
91
91
|
}),
|
92
92
|
headers: {
|
93
93
|
"Content-Type": "application/json"
|
@@ -96,34 +96,34 @@ function fe(e, t) {
|
|
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/${e}`
|
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=${e}`
|
104
104
|
)).json()).balance / 1e9;
|
105
105
|
case o.APT:
|
106
106
|
const y = (await (await fetch(
|
107
|
-
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${
|
107
|
+
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${e}/resources`
|
108
108
|
)).json()).find(
|
109
|
-
(
|
109
|
+
(O) => O.type.includes("coin::CoinStore")
|
110
110
|
);
|
111
111
|
return y ? parseInt(y.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/${e}`
|
115
115
|
)).json()).result.value.coins[0].amount / 1e6;
|
116
116
|
}
|
117
117
|
}
|
118
118
|
});
|
119
119
|
}
|
120
|
-
function
|
121
|
-
return
|
122
|
-
queryKey: ["ecency-wallets", "seed",
|
123
|
-
queryFn: async () =>
|
120
|
+
function b(t) {
|
121
|
+
return h({
|
122
|
+
queryKey: ["ecency-wallets", "seed", t],
|
123
|
+
queryFn: async () => _.generateMnemonic(128)
|
124
124
|
});
|
125
125
|
}
|
126
|
-
const
|
126
|
+
const W = {
|
127
127
|
max: 500,
|
128
128
|
// how long to live in ms
|
129
129
|
ttl: 1e3 * 60 * 5,
|
@@ -131,72 +131,72 @@ const F = {
|
|
131
131
|
allowStale: !1,
|
132
132
|
updateAgeOnGet: !1,
|
133
133
|
updateAgeOnHas: !1
|
134
|
-
},
|
135
|
-
const
|
136
|
-
return
|
134
|
+
}, v = new E(W), w = Symbol("undefined"), L = (t, e) => v.set(t, e === void 0 ? w : e), M = (t) => {
|
135
|
+
const e = v.get(t);
|
136
|
+
return e === w ? void 0 : e;
|
137
137
|
};
|
138
|
-
function
|
139
|
-
return
|
140
|
-
queryKey: ["ecency-wallets", "coingecko-price",
|
138
|
+
function bt(t) {
|
139
|
+
return h({
|
140
|
+
queryKey: ["ecency-wallets", "coingecko-price", t],
|
141
141
|
queryFn: async () => {
|
142
|
-
let
|
143
|
-
switch (
|
142
|
+
let e = t;
|
143
|
+
switch (t) {
|
144
144
|
case o.BTC:
|
145
|
-
|
145
|
+
e = "binance-wrapped-btc";
|
146
146
|
break;
|
147
147
|
case o.ETH:
|
148
|
-
|
148
|
+
e = "ethereum";
|
149
149
|
break;
|
150
150
|
case o.SOL:
|
151
|
-
|
151
|
+
e = "solana";
|
152
152
|
break;
|
153
153
|
case o.TON:
|
154
|
-
|
154
|
+
e = "trx";
|
155
155
|
break;
|
156
156
|
default:
|
157
|
-
|
157
|
+
e = t;
|
158
158
|
}
|
159
|
-
let n =
|
159
|
+
let n = M("gecko"), a;
|
160
160
|
if (n)
|
161
|
-
|
161
|
+
a = n;
|
162
162
|
else {
|
163
|
-
const
|
163
|
+
const i = await (await fetch(
|
164
164
|
"https://api.coingecko.com/api/v3/simple/price",
|
165
165
|
{
|
166
166
|
method: "POST",
|
167
167
|
body: JSON.stringify({
|
168
168
|
params: {
|
169
|
-
ids: [
|
169
|
+
ids: [e],
|
170
170
|
vs_currencies: "usd"
|
171
171
|
}
|
172
172
|
})
|
173
173
|
}
|
174
174
|
)).json();
|
175
|
-
|
175
|
+
L("gecko", i === void 0 ? w : i), a = i;
|
176
176
|
}
|
177
|
-
return 1 / +
|
177
|
+
return 1 / +a[Object.keys(a)[0]].usd;
|
178
178
|
},
|
179
|
-
enabled: !!
|
179
|
+
enabled: !!t
|
180
180
|
});
|
181
181
|
}
|
182
|
-
function q(
|
183
|
-
const { data:
|
184
|
-
return
|
185
|
-
queryKey: ["ecencу-wallets", "hive-keys",
|
182
|
+
function q(t) {
|
183
|
+
const { data: e } = b(t);
|
184
|
+
return h({
|
185
|
+
queryKey: ["ecencу-wallets", "hive-keys", t, e],
|
186
186
|
queryFn: async () => {
|
187
|
-
if (!
|
187
|
+
if (!e)
|
188
188
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
189
|
-
const n =
|
189
|
+
const n = p.fromLogin(t, e, "owner"), a = p.fromLogin(t, e, "active"), s = p.fromLogin(t, e, "posting"), r = p.fromLogin(t, e, "memo");
|
190
190
|
return {
|
191
|
-
username:
|
191
|
+
username: t,
|
192
192
|
owner: n.toString(),
|
193
|
-
active:
|
194
|
-
posting:
|
195
|
-
memo:
|
193
|
+
active: a.toString(),
|
194
|
+
posting: s.toString(),
|
195
|
+
memo: r.toString(),
|
196
196
|
ownerPubkey: n.createPublic().toString(),
|
197
|
-
activePubkey:
|
198
|
-
postingPubkey:
|
199
|
-
memoPubkey:
|
197
|
+
activePubkey: a.createPublic().toString(),
|
198
|
+
postingPubkey: s.createPublic().toString(),
|
199
|
+
memoPubkey: r.createPublic().toString()
|
200
200
|
};
|
201
201
|
}
|
202
202
|
});
|
@@ -217,65 +217,65 @@ const I = {
|
|
217
217
|
[o.ATOM]: "m/44'/118'/0'/0/0"
|
218
218
|
// Cosmos (BIP44)
|
219
219
|
};
|
220
|
-
function
|
221
|
-
const { data: n } =
|
222
|
-
mutationKey: ["ecency-wallets", "create-wallet",
|
220
|
+
function vt(t, e) {
|
221
|
+
const { data: n } = b(t), a = f(), s = l({
|
222
|
+
mutationKey: ["ecency-wallets", "create-wallet", t, e],
|
223
223
|
mutationFn: async () => {
|
224
224
|
if (!n)
|
225
225
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
226
|
-
const
|
226
|
+
const i = T(e), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
|
227
227
|
mnemonic: n,
|
228
|
-
hdPath: I[
|
228
|
+
hdPath: I[e]
|
229
229
|
}));
|
230
|
-
await
|
231
|
-
const
|
230
|
+
await F(1e3);
|
231
|
+
const m = 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: m.address,
|
237
|
+
publicKey: m.publicKey,
|
238
|
+
username: t,
|
239
|
+
currency: e
|
240
240
|
};
|
241
241
|
},
|
242
|
-
onSuccess: (
|
243
|
-
|
244
|
-
["ecency-wallets", "wallets",
|
245
|
-
(c) => new Map(c ? Array.from(c.entries()) : []).set(
|
242
|
+
onSuccess: (i) => {
|
243
|
+
a.setQueryData(
|
244
|
+
["ecency-wallets", "wallets", i.username],
|
245
|
+
(c) => new Map(c ? Array.from(c.entries()) : []).set(i.currency, i)
|
246
246
|
);
|
247
247
|
}
|
248
|
-
}),
|
248
|
+
}), r = k(() => {
|
249
249
|
}, []);
|
250
250
|
return {
|
251
|
-
createWallet:
|
252
|
-
importWallet:
|
251
|
+
createWallet: s,
|
252
|
+
importWallet: r
|
253
253
|
};
|
254
254
|
}
|
255
|
-
function J(
|
256
|
-
const { data:
|
257
|
-
queryKey: ["ecency-wallets", "wallets",
|
258
|
-
}), { data: n } = q(
|
259
|
-
return
|
260
|
-
mutationKey: ["ecency-wallets", "create-account-with-wallets",
|
261
|
-
mutationFn: ({ currency:
|
255
|
+
function J(t) {
|
256
|
+
const { data: e } = h({
|
257
|
+
queryKey: ["ecency-wallets", "wallets", t]
|
258
|
+
}), { data: n } = q(t);
|
259
|
+
return l({
|
260
|
+
mutationKey: ["ecency-wallets", "create-account-with-wallets", t],
|
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:
|
268
|
-
token:
|
269
|
-
address:
|
267
|
+
username: t,
|
268
|
+
token: a,
|
269
|
+
address: s,
|
270
270
|
meta: {
|
271
271
|
ownerPublicKey: n == null ? void 0 : n.ownerPubkey,
|
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((
|
276
|
-
(
|
277
|
-
...
|
278
|
-
[
|
275
|
+
...Array.from((e == null ? void 0 : e.entries()) ?? []).reduce(
|
276
|
+
(r, [i, c]) => ({
|
277
|
+
...r,
|
278
|
+
[i]: c.address
|
279
279
|
}),
|
280
280
|
{}
|
281
281
|
)
|
@@ -284,27 +284,27 @@ function J(e) {
|
|
284
284
|
})
|
285
285
|
});
|
286
286
|
}
|
287
|
-
function
|
288
|
-
return
|
287
|
+
function P() {
|
288
|
+
return l({
|
289
289
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
290
|
-
mutationFn: async ({ address:
|
291
|
-
|
290
|
+
mutationFn: async ({ address: t, currency: e }) => (await (await fetch(
|
291
|
+
u.privateApiHost + "/private-api/wallets-exist",
|
292
292
|
{
|
293
293
|
method: "POST",
|
294
294
|
headers: {
|
295
295
|
"Content-Type": "application/json"
|
296
296
|
},
|
297
297
|
body: JSON.stringify({
|
298
|
-
address:
|
299
|
-
token:
|
298
|
+
address: t,
|
299
|
+
token: e
|
300
300
|
})
|
301
301
|
}
|
302
302
|
)).json()).length === 0
|
303
303
|
});
|
304
304
|
}
|
305
|
-
const
|
305
|
+
const Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
306
306
|
__proto__: null,
|
307
|
-
useCheckWalletExistence:
|
307
|
+
useCheckWalletExistence: P,
|
308
308
|
useCreateAccountWithWallets: J
|
309
309
|
}, Symbol.toStringTag, { value: "Module" })), Q = {
|
310
310
|
[o.BTC]: ["m/84'/0'/0'/0/0"],
|
@@ -317,125 +317,125 @@ const be = /* @__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
|
320
|
+
async function $(t, e, n) {
|
321
|
+
for (const a of Q[n] || [])
|
322
322
|
try {
|
323
|
-
const
|
324
|
-
mnemonic:
|
325
|
-
hdPath:
|
326
|
-
}),
|
327
|
-
privateKey:
|
323
|
+
const s = await e.getDerivedPrivateKey({
|
324
|
+
mnemonic: t,
|
325
|
+
hdPath: a
|
326
|
+
}), r = await e.getNewAddress({
|
327
|
+
privateKey: s,
|
328
328
|
addressType: n === o.BTC ? "segwit_native" : void 0
|
329
329
|
});
|
330
|
-
return [
|
330
|
+
return [s.toString(), r.address];
|
331
331
|
} catch {
|
332
332
|
return [];
|
333
333
|
}
|
334
334
|
return [];
|
335
335
|
}
|
336
|
-
function
|
337
|
-
const n = f(), { mutateAsync:
|
338
|
-
return
|
339
|
-
mutationKey: ["ecency-wallets", "import-wallet",
|
340
|
-
mutationFn: async ({ privateKeyOrSeed:
|
341
|
-
const
|
342
|
-
if (!
|
336
|
+
function St(t, e) {
|
337
|
+
const n = f(), { mutateAsync: a } = P();
|
338
|
+
return l({
|
339
|
+
mutationKey: ["ecency-wallets", "import-wallet", t, e],
|
340
|
+
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
341
|
+
const r = T(e);
|
342
|
+
if (!r)
|
343
343
|
throw new Error("Cannot find token for this currency");
|
344
|
-
const
|
345
|
-
let c,
|
346
|
-
if (
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
) : c = (await
|
351
|
-
privateKey:
|
352
|
-
})).address, !c || !
|
344
|
+
const i = s.split(" ").length === 12;
|
345
|
+
let c, m = s;
|
346
|
+
if (i ? [m, c] = await $(
|
347
|
+
s,
|
348
|
+
r,
|
349
|
+
e
|
350
|
+
) : c = (await r.getNewAddress({
|
351
|
+
privateKey: s
|
352
|
+
})).address, !c || !s)
|
353
353
|
throw new Error(
|
354
354
|
"Private key/seed phrase isn't matching with public key or token"
|
355
355
|
);
|
356
|
-
if (!await
|
356
|
+
if (!await a({
|
357
357
|
address: c,
|
358
|
-
currency:
|
358
|
+
currency: e
|
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: m,
|
365
365
|
address: c,
|
366
366
|
publicKey: ""
|
367
367
|
};
|
368
368
|
},
|
369
|
-
onSuccess: ({ privateKey:
|
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(
|
373
|
-
privateKey:
|
374
|
-
publicKey:
|
375
|
-
address:
|
376
|
-
username:
|
377
|
-
currency:
|
371
|
+
["ecency-wallets", "wallets", t],
|
372
|
+
(c) => new Map(c ? Array.from(c.entries()) : []).set(e, {
|
373
|
+
privateKey: s,
|
374
|
+
publicKey: r,
|
375
|
+
address: i,
|
376
|
+
username: t,
|
377
|
+
currency: e,
|
378
378
|
custom: !0
|
379
379
|
})
|
380
380
|
);
|
381
381
|
}
|
382
382
|
});
|
383
383
|
}
|
384
|
-
function G(
|
385
|
-
let
|
386
|
-
if (
|
387
|
-
return JSON.parse(
|
384
|
+
function G(t) {
|
385
|
+
let e = atob(t);
|
386
|
+
if (e[0] === "{")
|
387
|
+
return JSON.parse(e);
|
388
388
|
}
|
389
|
-
const
|
389
|
+
const d = (t) => {
|
390
390
|
try {
|
391
|
-
const
|
392
|
-
|
391
|
+
const e = u.storage.getItem(
|
392
|
+
u.storagePrefix + "_user_" + t
|
393
393
|
);
|
394
|
-
return G(JSON.parse(
|
395
|
-
} catch (
|
396
|
-
console.error(
|
394
|
+
return G(JSON.parse(e));
|
395
|
+
} catch (e) {
|
396
|
+
console.error(e);
|
397
397
|
return;
|
398
398
|
}
|
399
|
-
}, U = (
|
400
|
-
function
|
401
|
-
return
|
402
|
-
mutationKey: [...
|
403
|
-
mutationFn: async (
|
404
|
-
if (!
|
399
|
+
}, U = (t) => d(t) && d(t).accessToken, V = (t) => d(t) && d(t).postingKey;
|
400
|
+
function z(t = [], e, n) {
|
401
|
+
return l({
|
402
|
+
mutationKey: [...t, e],
|
403
|
+
mutationFn: async (a) => {
|
404
|
+
if (!e)
|
405
405
|
throw new Error(
|
406
406
|
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
407
407
|
);
|
408
|
-
const
|
409
|
-
if (
|
410
|
-
const
|
411
|
-
return
|
412
|
-
n(
|
413
|
-
|
408
|
+
const s = V(e);
|
409
|
+
if (s) {
|
410
|
+
const i = p.fromString(s);
|
411
|
+
return u.hiveClient.broadcast.sendOperations(
|
412
|
+
n(a),
|
413
|
+
i
|
414
414
|
);
|
415
415
|
}
|
416
|
-
let
|
417
|
-
if (
|
418
|
-
return (await new
|
419
|
-
accessToken:
|
420
|
-
}).broadcast(n(
|
416
|
+
let r = U(e);
|
417
|
+
if (r)
|
418
|
+
return (await new g.Client({
|
419
|
+
accessToken: r
|
420
|
+
}).broadcast(n(a))).result;
|
421
421
|
throw new Error(
|
422
422
|
"[SDK][Broadcast] – cannot broadcast w/o posting key or token"
|
423
423
|
);
|
424
424
|
}
|
425
425
|
});
|
426
426
|
}
|
427
|
-
function
|
428
|
-
return
|
427
|
+
function X(t) {
|
428
|
+
return z(
|
429
429
|
["accounts", "update"],
|
430
|
-
|
431
|
-
(
|
430
|
+
t,
|
431
|
+
(e) => [
|
432
432
|
[
|
433
433
|
"account_update2",
|
434
434
|
{
|
435
|
-
account:
|
435
|
+
account: t,
|
436
436
|
json_metadata: "",
|
437
437
|
posting_json_metadata: JSON.stringify({
|
438
|
-
profile: { ...
|
438
|
+
profile: { ...e, version: 2 }
|
439
439
|
}),
|
440
440
|
extensions: []
|
441
441
|
}
|
@@ -443,43 +443,86 @@ function z(e) {
|
|
443
443
|
]
|
444
444
|
);
|
445
445
|
}
|
446
|
-
function
|
447
|
-
const { mutateAsync:
|
448
|
-
return
|
449
|
-
mutationKey: ["ecency-wallets", "save-wallet-to-metadata",
|
446
|
+
function Ot(t) {
|
447
|
+
const { mutateAsync: e } = X(t);
|
448
|
+
return l({
|
449
|
+
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", t],
|
450
450
|
mutationFn: ({
|
451
451
|
wallets: n
|
452
|
-
}) =>
|
452
|
+
}) => e(
|
453
453
|
Array.from(n.entries() ?? []).reduce(
|
454
|
-
(
|
455
|
-
...
|
456
|
-
[
|
454
|
+
(a, [s, r]) => ({
|
455
|
+
...a,
|
456
|
+
[s]: r.address
|
457
457
|
}),
|
458
458
|
{}
|
459
459
|
)
|
460
460
|
)
|
461
461
|
});
|
462
462
|
}
|
463
|
-
function
|
464
|
-
return
|
465
|
-
["operations", "sign"],
|
463
|
+
function kt(t) {
|
464
|
+
return l({
|
465
|
+
mutationKey: ["operations", "sign", t],
|
466
|
+
mutationFn: ({
|
467
|
+
operation: e,
|
468
|
+
keyOrSeed: n
|
469
|
+
}) => {
|
470
|
+
if (!t)
|
471
|
+
throw new Error("[Operations][Sign] – cannot sign op with anon user");
|
472
|
+
let a;
|
473
|
+
return n.split(" ").length === 12 ? a = p.fromLogin(t, n, "active") : H.isWif(n) ? a = p.fromString(n) : a = p.from(n), u.hiveClient.broadcast.sendOperations(
|
474
|
+
[e],
|
475
|
+
a
|
476
|
+
);
|
477
|
+
}
|
478
|
+
});
|
479
|
+
}
|
480
|
+
const Y = (t, e, n, a = null) => new Promise((s, r) => {
|
481
|
+
var i;
|
482
|
+
(i = window.hive_keychain) == null || i.requestBroadcast(
|
483
|
+
t,
|
466
484
|
e,
|
467
|
-
|
485
|
+
n,
|
486
|
+
(c) => {
|
487
|
+
c.success || r({ message: "Operation cancelled" }), s(c);
|
488
|
+
},
|
489
|
+
a
|
468
490
|
);
|
491
|
+
});
|
492
|
+
function At(t, e = "Active") {
|
493
|
+
l({
|
494
|
+
mutationKey: ["operations", "sign-keychain", t],
|
495
|
+
mutationFn: ({ operation: n }) => {
|
496
|
+
if (!t)
|
497
|
+
throw new Error(
|
498
|
+
"[SDK][Keychain] – cannot sign operation with anon user"
|
499
|
+
);
|
500
|
+
return Y(t, [n], e);
|
501
|
+
}
|
502
|
+
});
|
503
|
+
}
|
504
|
+
function Kt(t = "/") {
|
505
|
+
l({
|
506
|
+
mutationKey: ["operations", "sign-hivesigner", t],
|
507
|
+
mutationFn: async ({ operation: e }) => g.sendOperation(e, { callback: t }, () => {
|
508
|
+
})
|
509
|
+
});
|
469
510
|
}
|
470
511
|
export {
|
471
512
|
o as EcencyWalletCurrency,
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
513
|
+
Pt as EcencyWalletsPrivateApi,
|
514
|
+
F as delay,
|
515
|
+
T as getWallet,
|
516
|
+
gt as mnemonicToSeedBip39,
|
517
|
+
X as useAccountUpdate,
|
518
|
+
bt as useCoinGeckoPriceQuery,
|
519
|
+
Tt as useGetExternalWalletBalanceQuery,
|
479
520
|
q as useHiveKeysQuery,
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
521
|
+
St as useImportWallet,
|
522
|
+
Ot as useSaveWalletInformationToMetadata,
|
523
|
+
b as useSeedPhrase,
|
524
|
+
Kt as useSignOperationByHivesigner,
|
525
|
+
kt as useSignOperationByKey,
|
526
|
+
At as useSignOperationByKeychain,
|
527
|
+
vt as useWalletCreate
|
485
528
|
};
|