@everyprotocol/every-cli 0.1.2 → 0.1.3

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/wallet.js CHANGED
@@ -3,106 +3,88 @@ import { Keyring } from "@polkadot/keyring";
3
3
  import { mnemonicGenerate, cryptoWaitReady } from "@polkadot/util-crypto";
4
4
  import { bytesToHex } from "viem";
5
5
  import * as fs from "fs";
6
- import { decodeSubstratePair, getPassword, getPasswordConfirm, loadKeystore, resolveKeystoreDir, resolveKeystoreFile, saveKeystore, } from "./utils.js";
7
- // Wallet commands
8
- export function genWalletCommands() {
9
- const walletCmd = new Command().name("wallet").description("manage wallets");
10
- // List command
11
- const listCmd = new Command()
12
- .name("list")
13
- .description("List all wallets")
14
- .option("--foundry", "use foundry keystore directory (~/.foundry/keystores)")
15
- .option("--dir <dir>", "specify a custom keystore directory")
16
- .action(async (options) => {
17
- const dir = resolveKeystoreDir(options);
18
- const files = fs.readdirSync(dir);
19
- files.forEach((file) => console.log(file));
20
- });
21
- // Generate command
22
- const generateCmd = new Command()
23
- .name("new")
24
- .description("Generate a new wallet")
25
- .option("-t, --type <type>", "key type (ed25519, sr25519, ethereum)", "sr25519")
26
- .option("-p, --password <password>", "password to encrypt the keystore")
27
- .option("-P, --password-file <file>", "password file")
28
- .option("--dir <dir>", "specify keystore directory")
29
- .option("--foundry", "use foundry keystore directory (~/.foundry/keystores)")
30
- .argument("<name>", "name of the wallet")
31
- .action(async (name, options) => {
32
- const password = getPasswordConfirm(options);
33
- await cryptoWaitReady();
34
- const keyring = new Keyring();
35
- const mnemonic = mnemonicGenerate();
36
- const pair = keyring.addFromUri(mnemonic, { name }, options.type);
37
- const json = pair.toJson(password);
38
- saveKeystore(json, name, options);
39
- });
40
- // Import command
41
- const importCmd = new Command()
42
- .name("import")
43
- .description("Import a wallet from a secrete URI")
44
- .option("-t, --type <type>", "key type (sr25519, ed25519, ethereum)", "sr25519")
45
- .option("-p, --password <password>", "password to encrypt the keystore")
46
- .option("-P, --password-file <file>", "password file")
47
- .option("--dir <dir>", "specify a custom keystore directory")
48
- .option("--foundry", "use foundry keystore directory (~/.foundry/keystores)")
49
- .argument("<name>", "name of the wallet")
50
- .argument("<suri>", "secret URI")
51
- .action(async (name, suri, options) => {
52
- const password = getPasswordConfirm(options);
53
- await cryptoWaitReady();
54
- const keyring = new Keyring({ type: options.type });
55
- const pair = keyring.addFromUri(suri);
56
- const json = pair.toJson(password);
57
- saveKeystore(json, name, options);
58
- });
59
- // Inspect command
60
- const inspectCmd = new Command()
61
- .name("inspect")
62
- .description("Inspect a wallet")
63
- .option("-t, --type <type>", "key type (sr25519, ed25519, ethereum)", "sr25519")
64
- .option("-p, --password <password>", "password to decrypt the keystore")
65
- .option("-P, --password-file <file>", "file containing the password")
66
- .option("-x, --decrypt", "also decrypt the private key", false)
67
- .option("--dir <dir>", "specify a custom keystore directory")
68
- .option("--foundry", "use foundry keystore directory (~/.foundry/keystores)")
69
- .argument("<name>", "name of the wallet")
70
- .action(async (name, options) => {
71
- const file = resolveKeystoreFile(name, options);
72
- const keyData = loadKeystore(file);
73
- await cryptoWaitReady();
74
- const keyring = new Keyring({ type: options.type });
75
- const account = keyring.addFromJson(keyData);
76
- let password;
77
- if (account.isLocked) {
78
- password = getPassword(options);
79
- account.unlock(password);
80
- }
81
- let decoded;
82
- if (options.decrypt) {
83
- decoded = decodeSubstratePair(keyData, password);
84
- }
85
- let keystoreDisplay = "~/.every/keystores";
86
- if (options.foundry) {
87
- keystoreDisplay = "~/.foundry/keystores";
88
- }
89
- else if (options.dir) {
90
- keystoreDisplay = options.dir;
91
- }
92
- console.log(` Keystore: ${keystoreDisplay}`);
93
- console.log(` Wallet: ${name}`);
94
- console.log(` Type: ${account.type}`);
95
- console.log(` Meta: ${JSON.stringify(account.meta)}`);
96
- console.log(` Address: ${account.address}`);
97
- console.log(`AddressRaw: ${bytesToHex(account.addressRaw)}`);
98
- console.log(` PublicKey: ${bytesToHex(account.publicKey)}`);
99
- if (decoded) {
100
- console.log(`SecretKey: ${bytesToHex(decoded.secretKey)}`);
101
- }
102
- });
103
- walletCmd.addCommand(listCmd);
104
- walletCmd.addCommand(generateCmd);
105
- walletCmd.addCommand(importCmd);
106
- walletCmd.addCommand(inspectCmd);
107
- return walletCmd;
108
- }
6
+ import { getPasswordConfirm, keystoreFromAccount, resolveKeystoreDir, saveKeystore } from "./utils.js";
7
+ const listCmd = new Command()
8
+ .name("list")
9
+ .description("List all wallets")
10
+ .option("-f, --foundry", "use foundry keystore directory (~/.foundry/keystores)")
11
+ .option("--dir <dir>", "specify a custom keystore directory")
12
+ .action(async (options) => {
13
+ const dir = resolveKeystoreDir(options);
14
+ const files = fs.readdirSync(dir);
15
+ files.forEach((file) => console.log(file));
16
+ });
17
+ const generateCmd = new Command()
18
+ .name("new")
19
+ .description("Generate a new wallet")
20
+ .option("-t, --type <type>", "key type (sr25519, ed25519, ethereum)", "sr25519")
21
+ .option("-p, --password <password>", "password to encrypt the keystore")
22
+ .option("-P, --password-file <file>", "password file")
23
+ .option("--dir <dir>", "specify keystore directory")
24
+ .argument("<name>", "name of the wallet")
25
+ .action(async (name, options) => {
26
+ const password = getPasswordConfirm(options);
27
+ await cryptoWaitReady();
28
+ const keyring = new Keyring();
29
+ const mnemonic = mnemonicGenerate();
30
+ const pair = keyring.addFromUri(mnemonic, { name }, options.type);
31
+ const json = pair.toJson(password);
32
+ saveKeystore(json, name, options);
33
+ });
34
+ const importCmd = new Command()
35
+ .name("import")
36
+ .description("Import a wallet from a secrete URI")
37
+ .option("-t, --type <type>", "key type (sr25519, ed25519, ethereum)", "sr25519")
38
+ .option("-p, --password <password>", "password to encrypt the keystore")
39
+ .option("-P, --password-file <file>", "password file")
40
+ .option("--dir <dir>", "specify a custom keystore directory")
41
+ .option("-f, --foundry", "use foundry keystore directory (~/.foundry/keystores)")
42
+ .argument("<name>", "name of the wallet")
43
+ .argument("<suri>", "secret URI")
44
+ .action(async (name, suri, options) => {
45
+ const password = getPasswordConfirm(options);
46
+ await cryptoWaitReady();
47
+ const keyring = new Keyring({ type: options.type });
48
+ const pair = keyring.addFromUri(suri);
49
+ const json = pair.toJson(password);
50
+ saveKeystore(json, name, options);
51
+ });
52
+ const inspectCmd = new Command()
53
+ .name("inspect")
54
+ .description("Inspect a wallet")
55
+ .option("-t, --type <type>", "key type (sr25519, ed25519, ethereum)", "sr25519")
56
+ .option("-p, --password <password>", "password to decrypt the keystore")
57
+ .option("-P, --password-file <file>", "file containing the password")
58
+ .option("-x, --decrypt", "also decrypt the private key", false)
59
+ .option("--dir <dir>", "specify a custom keystore directory")
60
+ .option("-f, --foundry", "use foundry keystore directory (~/.foundry/keystores)")
61
+ .argument("<name>", "name of the wallet")
62
+ .action(async (name, options) => {
63
+ const keystore = await keystoreFromAccount(name, options);
64
+ let decoded;
65
+ if (options.decrypt) {
66
+ decoded = await keystore.privateKey();
67
+ }
68
+ let dir = "~/.every/keystores";
69
+ if (options.foundry) {
70
+ dir = "~/.foundry/keystores";
71
+ }
72
+ else if (options.dir) {
73
+ dir = options.dir;
74
+ }
75
+ console.log(` Keystore: ${dir}/${name}`);
76
+ console.log(` Store Type: ${keystore.type()}`);
77
+ console.log(` Key Type: ${keystore.keyType()}`);
78
+ console.log(` Address: ${await keystore.address()}`);
79
+ console.log(` Public Key: ${bytesToHex(await keystore.publicKey())}`);
80
+ if (decoded) {
81
+ console.log(`Private Key: ${bytesToHex(decoded)}`);
82
+ }
83
+ });
84
+ export const walletCmd = new Command()
85
+ .name("wallet")
86
+ .description("manage wallets")
87
+ .addCommand(listCmd)
88
+ .addCommand(generateCmd)
89
+ .addCommand(importCmd)
90
+ .addCommand(inspectCmd);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@everyprotocol/every-cli",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "files": [
6
6
  "dist/",
7
7
  "abis/",