@@ -24,12 +24,19 @@ import {
2424
2525const VERSION = "0.1.1" ;
2626
27+ const DEFAULT_KEYS_PATH = "keystore.db" ;
28+
2729program
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
3542program
@@ -93,42 +100,42 @@ function handleError(
93100}
94101
95102async 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
101108async 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
108115async 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
115122async 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
123130async 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
130137async 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 ) ;
0 commit comments