Skip to content

Commit c587874

Browse files
committed
Add --keys-path option
keys-path option specifies the path to store the keys.
1 parent cf840a9 commit c587874

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ yarn global add codechain-sdk-cli
2929

3030
-V, --version output the version number
3131
-t, --account-type <accountType> 'platform' or 'asset'. The type of the key (default: platform)
32+
--keys-path <keysPath> the path to store the keys (default: keystore.db)
3233
-h, --help output usage information
3334

3435
Commands:

src/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ import {
2424

2525
const VERSION = "0.1.1";
2626

27+
const DEFAULT_KEYS_PATH = "keystore.db";
28+
2729
program
2830
.version(VERSION)
2931
.option(
3032
"-t, --account-type <accountType>",
3133
"'platform' or 'asset'. The type of the key",
3234
"platform"
35+
)
36+
.option(
37+
"--keys-path <keysPath>",
38+
"the path to store the keys",
39+
DEFAULT_KEYS_PATH
3340
);
3441

3542
program
@@ -93,42 +100,42 @@ function handleError(
93100
}
94101

95102
async function listCommand(args: any[], option: ListOption) {
96-
const cckey = await CCKey.create();
103+
const cckey = await CCKey.create({ dbPath: option.parent.keysPath });
97104
const accountType = parseAccountType(option.parent.accountType);
98105
await listKeys(cckey, accountType);
99106
}
100107

101108
async function createCommand(args: any[], option: CreateOption) {
102-
const cckey = await CCKey.create();
109+
const cckey = await CCKey.create({ dbPath: option.parent.keysPath });
103110
const accountType = parseAccountType(option.parent.accountType);
104111
const passphrase = parsePassphrase(option.passphrase);
105112
await createKey(cckey, accountType, passphrase);
106113
}
107114

108115
async function deleteCommand(args: any[], option: DeleteOption) {
109-
const cckey = await CCKey.create();
116+
const cckey = await CCKey.create({ dbPath: option.parent.keysPath });
110117
const accountType = parseAccountType(option.parent.accountType);
111118
const address = parseAddress(option.address);
112119
await deleteKey(cckey, accountType, address);
113120
}
114121

115122
async function importCommand([path]: any[], option: ImportOption) {
116-
const cckey = await CCKey.create();
123+
const cckey = await CCKey.create({ dbPath: option.parent.keysPath });
117124
const accountType = parseAccountType(option.parent.accountType);
118125
const passphrase = parsePassphrase(option.passphrase);
119126
const contents = fs.readFileSync(path, { encoding: "utf8" });
120127
await importKey(cckey, accountType, JSON.parse(contents), passphrase);
121128
}
122129

123130
async function importRawCommand([privateKey]: any[], option: ImportOption) {
124-
const cckey = await CCKey.create();
131+
const cckey = await CCKey.create({ dbPath: option.parent.keysPath });
125132
const accountType = parseAccountType(option.parent.accountType);
126133
const passphrase = parsePassphrase(option.passphrase);
127134
await importRawKey(cckey, accountType, privateKey, passphrase);
128135
}
129136

130137
async function exportCommand(args: any[], option: ExportOption) {
131-
const cckey = await CCKey.create();
138+
const cckey = await CCKey.create({ dbPath: option.parent.keysPath });
132139
const accountType = parseAccountType(option.parent.accountType);
133140
const address = parseAddress(option.address);
134141
const passphrase = parsePassphrase(option.passphrase);

src/types.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
export type AccountType = "platform" | "asset";
22
export type Action = "list" | "create" | "delete";
33

4+
export interface CommonOption {
5+
accountType: string;
6+
keysPath: string;
7+
}
8+
49
export interface ListOption {
5-
parent: {
6-
accountType: string;
7-
};
10+
parent: CommonOption;
811
}
912

1013
export interface CreateOption {
11-
parent: {
12-
accountType: string;
13-
};
14+
parent: CommonOption;
1415
passphrase: string;
1516
}
1617

1718
export interface DeleteOption {
18-
parent: {
19-
accountType: string;
20-
};
19+
parent: CommonOption;
2120
address: string;
2221
}
2322

2423
export interface ImportOption {
25-
parent: {
26-
accountType: string;
27-
};
24+
parent: CommonOption;
2825
passphrase: string;
2926
}
3027

3128
export interface ExportOption {
32-
parent: {
33-
accountType: string;
34-
};
29+
parent: CommonOption;
3530
address: string;
3631
passphrase: string;
3732
pretty: boolean;

0 commit comments

Comments
 (0)