Skip to content

Commit 11ae365

Browse files
SeungMin Leemajecty
authored andcommitted
Apply the changes in foundry-keystore to CLI
[email protected] and [email protected] were published. We removed unnecessary the Asset type from them and renamed the Platform type to 'keystore'. Therefore, there is no keytype in the renewed keystore. In addition, they use the Ed25519 signature, which uses 64 bytes private key. To apply the changes in foundry-keystore and primitives to foundry-cli, we removed the concept of accountType, renamed it to 'keystore' and changed 32 bytes key private key to 64 bytes.
1 parent 2635a6f commit 11ae365

File tree

14 files changed

+98
-234
lines changed

14 files changed

+98
-234
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ yarn global add foundry-keystore-cli
2828
Options:
2929

3030
-V, --version output the version number
31-
-t, --account-type <accountType> 'platform' or 'asset'. The type of the key (default: platform)
3231
--keys-path <keysPath> the path to store the keys (default: keystore.db)
3332
--network-id <networkId> the id of the network (use 'cc' for mainnet, use 'wc' for corgi) (default: cc)
3433
-h, --help output usage information
@@ -39,20 +38,20 @@ yarn global add foundry-keystore-cli
3938
create [options] create a new key
4039
delete [options] delete a key
4140
import [options] <path> import a key
42-
import-raw [options] <privateKey> import a raw private key (32 byte hexadecimal string)
41+
import-raw [options] <privateKey> import a raw private key (64 byte hexadecimal string)
4342
export [options] export the key
4443

4544
Examples:
4645

47-
cckey create -t platform --passphrase "my password"
46+
cckey create --passphrase "passphrase1"
4847

49-
cckey list -t asset
48+
cckey list
5049

51-
cckey delete -t platform --address "ccc..."
50+
cckey delete --address cccqy6vhjxs8ddf6y6etgdqcs5elcrl6n6t0vdwumu8
5251

53-
cckey import UTC--2018-08-14T06-30-23Z--bbb6685e-7165-819d-0988-fc1a7d2d0523 -t platform --passphrase "satoshi"
52+
cckey import UTC--2020-03-05T02-47-14Z--6adba8c6-04ff-f649-6347-5c7946e28733 --passphrase "passphrase2"
5453

55-
cckey export -t platform --address cccq8ah0efv5ckpx6wy5mwva2aklzwsdw027sqfksrr --passphrase "satoshi"
54+
cckey export --address cccq8ah0efv5ckpx6wy5mwva2aklzwsdw027sqfksrr --passphrase "passphrase3"
5655

57-
cckey import-raw -t platform a05f81608217738d99da8fd227897b87e8890d3c9159b559c7c8bbd408e5fb6e --passphrase "satoshi"
56+
cckey import-raw b71f1a9a5fb62155b7ccc12841867e95a33da91c30515804546c7c5e575f2048287dec3980387a12ef9f159721c853e47e64a37f61407e0231ee62983cd6d2e --passphrase "passphrase4"
5857
```

build-binaries

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ execSync("yarn pkg -t node12-linux-x64,node12-macos-x64,node12-win-x64 --out-pat
1313
console.log("Build done");
1414

1515
const files = [
16-
"codechain-keystore-cli-linux",
17-
"codechain-keystore-cli-macos",
18-
"codechain-keystore-cli-win.exe"
16+
"foundry-keystore-cli-linux",
17+
"foundry-keystore-cli-macos",
18+
"foundry-keystore-cli-win.exe"
1919
];
2020

2121
process.chdir("binaries");

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
"typescript": "^3.0.1"
3535
},
3636
"dependencies": {
37-
"codechain-keystore": "^0.6.3",
38-
"codechain-primitives": "^1.0.4",
3937
"commander": "^2.17.1",
4038
"enquirer": "^2.3.1",
39+
"foundry-keystore": "^0.1.0",
40+
"foundry-primitives": "^0.2.1",
4141
"lodash": "^4.17.14"
4242
}
4343
}

src/command/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Context } from "../types";
22
import { getAddressFromKey } from "../util";
33

44
export async function createKey(
5-
{ cckey, accountType, networkId }: Context,
5+
{ cckey, networkId }: Context,
66
passphrase: string
77
): Promise<void> {
8-
const key = await cckey[accountType].createKey({
8+
const key = await cckey.keystore.createKey({
99
passphrase
1010
});
1111

12-
console.log(getAddressFromKey(accountType, key, networkId));
12+
console.log(getAddressFromKey(key, networkId));
1313
}

src/command/delete.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { Context } from "../types";
55
import { findMatchingKey } from "../util";
66

77
export async function deleteKey(
8-
{ cckey, accountType, networkId }: Context,
8+
{ cckey, networkId }: Context,
99
address: string
1010
): Promise<void> {
11-
const keys = await cckey[accountType].getKeys();
12-
const key = findMatchingKey(accountType, keys, address, networkId);
11+
const keys = await cckey.keystore.getKeys();
12+
const key = findMatchingKey(keys, address, networkId);
1313

1414
const question = {
1515
type: "confirm",
@@ -19,7 +19,7 @@ export async function deleteKey(
1919

2020
const answer: any = await prompt(question);
2121
if (answer.delete) {
22-
const result = await cckey[accountType].deleteKey({ key });
22+
const result = await cckey.keystore.deleteKey({ key });
2323
if (!result) {
2424
throw new CLIError(CLIErrorType.Unknown, {
2525
message: "Delete failed"

src/command/export.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { SecretStorage } from "codechain-keystore";
1+
import { SecretStorage } from "foundry-keystore";
22

33
import { Context } from "../types";
44
import { findMatchingKey } from "../util";
55

66
export async function exportKey(
7-
{ cckey, accountType, networkId }: Context,
7+
{ cckey, networkId }: Context,
88
address: string,
99
passphrase: string
1010
): Promise<SecretStorage> {
11-
const keys = await cckey[accountType].getKeys();
12-
const key = findMatchingKey(accountType, keys, address, networkId);
13-
return cckey[accountType].exportKey({
11+
const keys = await cckey.keystore.getKeys();
12+
const key = findMatchingKey(keys, address, networkId);
13+
return cckey.keystore.exportKey({
1414
key,
1515
passphrase
1616
});

src/command/import.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { SecretStorage } from "codechain-keystore";
1+
import { SecretStorage } from "foundry-keystore";
22

33
import { Context } from "../types";
44
import { getAddressFromKey } from "../util";
55

66
export async function importKey(
7-
{ cckey, accountType, networkId }: Context,
7+
{ cckey, networkId }: Context,
88
secret: SecretStorage,
99
passphrase: string
1010
): Promise<void> {
11-
const key = await cckey[accountType].importKey({
11+
const key = await cckey.keystore.importKey({
1212
secret,
1313
passphrase
1414
});
1515

16-
console.log(getAddressFromKey(accountType, key, networkId));
16+
console.log(getAddressFromKey(key, networkId));
1717
}

src/command/importRaw.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { PrivateKey } from "codechain-keystore/lib/types";
1+
import { PrivateKey } from "foundry-keystore/lib/types";
22

33
import { Context } from "../types";
44
import { getAddressFromKey } from "../util";
55

66
export async function importRawKey(
7-
{ cckey, accountType, networkId }: Context,
7+
{ cckey, networkId }: Context,
88
privateKey: PrivateKey,
99
passphrase: string
1010
): Promise<void> {
11-
const key = await cckey[accountType].importRaw({
11+
const key = await cckey.keystore.importRaw({
1212
privateKey,
1313
passphrase
1414
});
1515

16-
console.log(getAddressFromKey(accountType, key, networkId));
16+
console.log(getAddressFromKey(key, networkId));
1717
}

src/command/list.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import * as _ from "lodash";
33
import { Context } from "../types";
44
import { getAddressFromKey } from "../util";
55

6-
export async function listKeys({
7-
cckey,
8-
accountType,
9-
networkId
10-
}: Context): Promise<void> {
11-
let keys = await cckey[accountType].getKeys();
12-
keys = _.map(keys, key => getAddressFromKey(accountType, key, networkId));
6+
export async function listKeys({ cckey, networkId }: Context): Promise<void> {
7+
let keys = await cckey.keystore.getKeys();
8+
keys = _.map(keys, key => getAddressFromKey(key, networkId));
139
if (keys.length === 0) {
1410
console.log("");
1511
} else {

src/error.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Action } from "./types";
22

33
export enum CLIErrorType {
4-
InvalidAccountType,
54
InvalidAction,
65
InvalidAddress,
76
OptionRequired,
@@ -19,8 +18,6 @@ function getErrorMessage(type: CLIErrorType, args: any = {}) {
1918
const actions: Action[] = ["list", "create", "delete"];
2019

2120
switch (type) {
22-
case CLIErrorType.InvalidAccountType:
23-
return "Account-type should be 'platform' or 'asset'";
2421
case CLIErrorType.InvalidAction:
2522
return `Action should one of the ${JSON.stringify(actions)}`;
2623
case CLIErrorType.InvalidAddress:

0 commit comments

Comments
 (0)