wative 1.0.6 → 1.0.7
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/lib/index.esm.js +1 -1
- package/lib/index.umd.js +1 -1
- package/package.json +2 -2
- package/src/account.ts +171 -7
- package/src/index.ts +1 -1
- package/src/utils.ts +65 -0
package/src/account.ts
CHANGED
|
@@ -10,10 +10,14 @@ import {
|
|
|
10
10
|
passphraseValidator,
|
|
11
11
|
expandAmountValidator,
|
|
12
12
|
lastAccountNoValidator,
|
|
13
|
+
getAccountIndex,
|
|
14
|
+
getAccountRange,
|
|
15
|
+
confirmSomething,
|
|
13
16
|
} from "./utils";
|
|
14
17
|
import { getAccountAddress, getAccountBalance, getNetworkInfoByName, getNetworkTypeByName, getPKAccountAddress, selectDefaultNetwork, switchNetworkByAccountLabel, switchPPNetwork } from "./network";
|
|
15
18
|
import { showAssets } from './assets';
|
|
16
19
|
import { selectToolsOptions } from './tools';
|
|
20
|
+
import inquirer from "inquirer";
|
|
17
21
|
|
|
18
22
|
const cliProgress = require('cli-progress');
|
|
19
23
|
const { WativeCore } = require("wative-core");
|
|
@@ -199,6 +203,145 @@ const selectAccount = async (keystore_path: string, wative_core: typeof WativeCo
|
|
|
199
203
|
await selectAccount(keystore_path, wative_core);
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
const setDisableAddress = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
|
|
207
|
+
const account_info = await getAccountInfo(keystore_path, account_label);
|
|
208
|
+
|
|
209
|
+
let disable_address_options = [
|
|
210
|
+
"> Back",
|
|
211
|
+
"1.Disabled Slots",
|
|
212
|
+
"2.Add Single",
|
|
213
|
+
"3.Add Range"
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
const selected_disable_address = await selectSomething(disable_address_options);
|
|
217
|
+
switch (selected_disable_address) {
|
|
218
|
+
case "> Back": {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
case "1.Disabled Slots": {
|
|
222
|
+
let disabled_slots = account_info.disabled_slots;
|
|
223
|
+
if (!disabled_slots || disabled_slots.length === 0) {
|
|
224
|
+
console.log(
|
|
225
|
+
chalk.red("No disabled slots here yet")
|
|
226
|
+
)
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let account_data = account_info.data;
|
|
231
|
+
|
|
232
|
+
let disabled_slots_options = [
|
|
233
|
+
"> Back",
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
let default_network = account_info.default_network;
|
|
237
|
+
for (let i = 0; i < disabled_slots.length; i++) {
|
|
238
|
+
let from = disabled_slots[i].from;
|
|
239
|
+
let to = disabled_slots[i].to;
|
|
240
|
+
|
|
241
|
+
let from_default_network = default_network;
|
|
242
|
+
let to_default_network = default_network;
|
|
243
|
+
|
|
244
|
+
if ("default_network" in account_data[from]) {
|
|
245
|
+
from_default_network = account_data[from].default_network;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if ("default_network" in account_data[to]) {
|
|
249
|
+
to_default_network = account_data[to].default_network;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let from_network_type = getNetworkTypeByName(keystore_path, from_default_network);
|
|
253
|
+
let to_network_type = getNetworkTypeByName(keystore_path, to_default_network);
|
|
254
|
+
|
|
255
|
+
if (from_network_type !== "evm" && from_network_type !== "solana") {
|
|
256
|
+
throw new Error(`Invalid network type: ${from_network_type}`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (to_network_type !== "evm" && to_network_type !== "solana") {
|
|
260
|
+
throw new Error(`Invalid network type: ${to_network_type}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let from_address: string;
|
|
264
|
+
let to_address: string;
|
|
265
|
+
|
|
266
|
+
if (from_network_type === "evm") {
|
|
267
|
+
from_address = account_data[from].ciphertexts.evm.address;
|
|
268
|
+
} else {
|
|
269
|
+
from_address = account_data[to].ciphertexts.solana.address;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (to_network_type === "evm") {
|
|
273
|
+
to_address = account_data[to].ciphertexts.evm.address;
|
|
274
|
+
} else {
|
|
275
|
+
to_address = account_data[to].ciphertexts.solana.address;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (from === to) {
|
|
279
|
+
disabled_slots_options.push(`${i + 1}. ${from_address}[${from}]`);
|
|
280
|
+
} else {
|
|
281
|
+
disabled_slots_options.push(`${i + 1}. ${from_address}[${from}]-${to_address}[${to}]`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let selected_disabled_slots = await selectSomething(disabled_slots_options);
|
|
286
|
+
|
|
287
|
+
if (selected_disabled_slots === "> Back") {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let confirm = await confirmSomething(`Are you sure to delete the ${selected_disabled_slots}?`);
|
|
292
|
+
if (!confirm) {
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
let selected_disabled_slots_index = disabled_slots_options.indexOf(selected_disabled_slots) - 1;
|
|
296
|
+
|
|
297
|
+
account_info.disabled_slots.splice(selected_disabled_slots_index, 1);
|
|
298
|
+
saveAccountInfo(keystore_path, account_label, account_info);
|
|
299
|
+
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case "2.Add Single": {
|
|
303
|
+
let account_index_or_address = await getAccountIndex(account_info, "Input address or index");
|
|
304
|
+
if (account_index_or_address === null) {
|
|
305
|
+
console.log(chalk.red("Invalid account index"));
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (account_info.disabled_slots) {
|
|
310
|
+
account_info.disabled_slots.push({
|
|
311
|
+
from: account_index_or_address,
|
|
312
|
+
to: account_index_or_address
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
account_info.disabled_slots = [{
|
|
316
|
+
from: account_index_or_address,
|
|
317
|
+
to: account_index_or_address
|
|
318
|
+
}];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
saveAccountInfo(keystore_path, account_label, account_info);
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case "3.Add Range": {
|
|
325
|
+
let account_range = await getAccountRange(account_info);
|
|
326
|
+
if (!account_range) {
|
|
327
|
+
console.log(chalk.red("Invalid account range"));
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (account_info.disabled_slots) {
|
|
332
|
+
account_info.disabled_slots.push(account_range);
|
|
333
|
+
} else {
|
|
334
|
+
account_info.disabled_slots = [account_range];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
saveAccountInfo(keystore_path, account_label, account_info);
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
await setDisableAddress(keystore_path, account_label, wative_core);
|
|
343
|
+
}
|
|
344
|
+
|
|
202
345
|
|
|
203
346
|
const accountManager = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
|
|
204
347
|
let account_info = await getAccountInfo(keystore_path, account_label);
|
|
@@ -210,8 +353,9 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
210
353
|
'1.Address List',
|
|
211
354
|
'2.Expand Address',
|
|
212
355
|
'3.Slice Address',
|
|
213
|
-
'4.
|
|
214
|
-
|
|
356
|
+
'4.Disable Address',
|
|
357
|
+
'5.Reset Account Password',
|
|
358
|
+
`6.Switch Networks [${account_info.default_network}]`,
|
|
215
359
|
'> Back'
|
|
216
360
|
];
|
|
217
361
|
} else {
|
|
@@ -250,7 +394,11 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
250
394
|
await sliceAddress(keystore_path, account_label, Number(last_account_no), wative_core);
|
|
251
395
|
break;
|
|
252
396
|
}
|
|
253
|
-
case '4.
|
|
397
|
+
case '4.Disable Address': {
|
|
398
|
+
await setDisableAddress(keystore_path, account_label, wative_core);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case '5.Reset Account Password': {
|
|
254
402
|
const password1 = await inputPassword(`Please input new password for Account [${account_label}]`);
|
|
255
403
|
const password2 = await inputPassword(`Please confirm new password for Account [${account_label}]`);
|
|
256
404
|
|
|
@@ -268,7 +416,7 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
268
416
|
await switchNetworkByAccountLabel(keystore_path, account_label, true);
|
|
269
417
|
break;
|
|
270
418
|
}
|
|
271
|
-
case `
|
|
419
|
+
case `6.Switch Networks [${account_info.default_network}]`: {
|
|
272
420
|
await switchNetworkByAccountLabel(keystore_path, account_label, true);
|
|
273
421
|
break;
|
|
274
422
|
}
|
|
@@ -296,11 +444,13 @@ const accountManager = async (keystore_path: string, account_label: string, wati
|
|
|
296
444
|
|
|
297
445
|
const showPPAccounts = async (keystore_path: string, account_label: string, wative_core: typeof WativeCore) => {
|
|
298
446
|
const account_info = await getAccountInfo(keystore_path, account_label);
|
|
299
|
-
let option_accounts = [
|
|
447
|
+
let option_accounts: any = [
|
|
300
448
|
'> Back'
|
|
301
449
|
];
|
|
302
450
|
|
|
451
|
+
let disabled_slots = account_info.disabled_slots;
|
|
303
452
|
for (let i = 0; i < account_info.data.length; i++) {
|
|
453
|
+
|
|
304
454
|
let default_network = account_info.default_network;
|
|
305
455
|
if ("default_network" in account_info.data[i]) {
|
|
306
456
|
default_network = account_info.data[i].default_network;
|
|
@@ -313,10 +463,24 @@ const showPPAccounts = async (keystore_path: string, account_label: string, wati
|
|
|
313
463
|
tag = `(${account_info.data[i].tag})`;
|
|
314
464
|
}
|
|
315
465
|
|
|
466
|
+
let is_disable_address = wative_core.account.checkIsDisableAddress(disabled_slots, i);
|
|
316
467
|
if (network_type === "evm") {
|
|
317
|
-
|
|
468
|
+
if (is_disable_address) {
|
|
469
|
+
option_accounts.push(new inquirer.Separator(
|
|
470
|
+
chalk.yellow(`#${i} ${account_info.data[i].ciphertexts.evm.address} ${tag} [${default_network}]`)
|
|
471
|
+
))
|
|
472
|
+
} else {
|
|
473
|
+
option_accounts.push(`#${i} ${account_info.data[i].ciphertexts.evm.address} ${tag} [${default_network}]`);
|
|
474
|
+
}
|
|
475
|
+
|
|
318
476
|
} else if (network_type === "solana") {
|
|
319
|
-
|
|
477
|
+
if (is_disable_address) {
|
|
478
|
+
option_accounts.push(new inquirer.Separator(
|
|
479
|
+
chalk.yellow(`#${i} ${account_info.data[i].ciphertexts.solana.address} ${tag} [${default_network}]`)
|
|
480
|
+
))
|
|
481
|
+
} else {
|
|
482
|
+
option_accounts.push(`#${i} ${account_info.data[i].ciphertexts.solana.address} ${tag} [${default_network}]`);
|
|
483
|
+
}
|
|
320
484
|
}
|
|
321
485
|
}
|
|
322
486
|
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ const main = async () => {
|
|
|
19
19
|
|
|
20
20
|
const network_path = path.resolve(keystore_path, 'network.json');
|
|
21
21
|
const networks = JSON.parse(fs.readFileSync(network_path, 'utf8'));
|
|
22
|
-
const wative_core = new WativeCore(keystore_path, networks.accounts);
|
|
22
|
+
const wative_core = new WativeCore(keystore_path, networks.accounts, null, true);
|
|
23
23
|
await showHomePage(keystore_path, wative_core);
|
|
24
24
|
}
|
|
25
25
|
|
package/src/utils.ts
CHANGED
|
@@ -24,6 +24,64 @@ export const inputSomething = async (text: string, validate_func?: Function) =>
|
|
|
24
24
|
return inputText.trim().toString()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export const getAccountRange = async (account_info: any) => {
|
|
28
|
+
for (let i = 0; i < 5; i++) {
|
|
29
|
+
let start_address_index = await getAccountIndex(account_info, "Input start address or index");
|
|
30
|
+
if (!start_address_index) {
|
|
31
|
+
console.log(chalk.red("Invalid start account index"));
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
let end_address_index = await getAccountIndex(account_info, "Input end address or index");
|
|
35
|
+
if (!end_address_index) {
|
|
36
|
+
console.log(chalk.red("Invalid end account index"));
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (start_address_index > end_address_index) {
|
|
40
|
+
console.log(chalk.red("Invalid address range"));
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
from: start_address_index,
|
|
45
|
+
to: end_address_index
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const getAccountIndex = async (account_info: any, message: string) => {
|
|
52
|
+
let account_data = account_info.data;
|
|
53
|
+
let account_length = account_data.length;
|
|
54
|
+
if (account_length === 0) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let evm_account_list: any = [];
|
|
59
|
+
let solana_account_list: any = [];
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < account_length; i++) {
|
|
62
|
+
evm_account_list.push(account_data[i].ciphertexts.evm.address.toLocaleLowerCase());
|
|
63
|
+
solana_account_list.push(account_data[i].ciphertexts.solana.address.toLocaleLowerCase());
|
|
64
|
+
}
|
|
65
|
+
let max_account_index = account_length - 1;
|
|
66
|
+
for (let i = 0; i < 5; i++) {
|
|
67
|
+
let account_index_or_address = await inputSomething(message, accountIndexOrAddressValidator);
|
|
68
|
+
let account_chain_type = getAccountChainType(account_index_or_address);
|
|
69
|
+
if (account_chain_type === "unknown") {
|
|
70
|
+
if (Number(account_index_or_address) > max_account_index) {
|
|
71
|
+
console.log(chalk.red("Invalid account index"));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
return Number(account_index_or_address);
|
|
75
|
+
} else if (account_chain_type === "evm" && evm_account_list.indexOf(account_index_or_address.toLocaleLowerCase()) !== -1) {
|
|
76
|
+
return evm_account_list.indexOf(account_index_or_address.toLocaleLowerCase());
|
|
77
|
+
} else if (account_chain_type === "solana" && solana_account_list.indexOf(account_index_or_address.toLocaleLowerCase()) !== -1) {
|
|
78
|
+
return solana_account_list.indexOf(account_index_or_address.toLocaleLowerCase());
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
27
85
|
export const tagValidator = (tag: string) => {
|
|
28
86
|
if (tag === "") {
|
|
29
87
|
return true;
|
|
@@ -86,6 +144,13 @@ export const lastAccountNoValidator = (last_account_no: string) => {
|
|
|
86
144
|
return true;
|
|
87
145
|
}
|
|
88
146
|
|
|
147
|
+
export const accountIndexOrAddressValidator = (account_index_or_address: string) => {
|
|
148
|
+
if (isNaN(Number(account_index_or_address)) === false) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return chainAddressValidator(account_index_or_address);
|
|
152
|
+
}
|
|
153
|
+
|
|
89
154
|
export const chainAddressValidator = (chain_address: string) => {
|
|
90
155
|
let account_chain_type = getAccountChainType(chain_address);
|
|
91
156
|
|