@@ -108,7 +108,7 @@ async function listCommand(args: any[], option: ListOption) {
108108async function createCommand ( args : any [ ] , option : CreateOption ) {
109109 const cckey = await CCKey . create ( { dbPath : option . parent . keysPath } ) ;
110110 const accountType = parseAccountType ( option . parent . accountType ) ;
111- const passphrase = parsePassphrase ( option . passphrase ) ;
111+ const passphrase = await parsePassphrase ( option . passphrase ) ;
112112 await createKey ( cckey , accountType , passphrase ) ;
113113}
114114
@@ -122,23 +122,23 @@ async function deleteCommand(args: any[], option: DeleteOption) {
122122async function importCommand ( [ path ] : any [ ] , option : ImportOption ) {
123123 const cckey = await CCKey . create ( { dbPath : option . parent . keysPath } ) ;
124124 const accountType = parseAccountType ( option . parent . accountType ) ;
125- const passphrase = parsePassphrase ( option . passphrase ) ;
125+ const passphrase = await parsePassphrase ( option . passphrase ) ;
126126 const contents = fs . readFileSync ( path , { encoding : "utf8" } ) ;
127127 await importKey ( cckey , accountType , JSON . parse ( contents ) , passphrase ) ;
128128}
129129
130130async function importRawCommand ( [ privateKey ] : any [ ] , option : ImportOption ) {
131131 const cckey = await CCKey . create ( { dbPath : option . parent . keysPath } ) ;
132132 const accountType = parseAccountType ( option . parent . accountType ) ;
133- const passphrase = parsePassphrase ( option . passphrase ) ;
133+ const passphrase = await parsePassphrase ( option . passphrase ) ;
134134 await importRawKey ( cckey , accountType , privateKey , passphrase ) ;
135135}
136136
137137async function exportCommand ( args : any [ ] , option : ExportOption ) {
138138 const cckey = await CCKey . create ( { dbPath : option . parent . keysPath } ) ;
139139 const accountType = parseAccountType ( option . parent . accountType ) ;
140140 const address = parseAddress ( option . address ) ;
141- const passphrase = parsePassphrase ( option . passphrase ) ;
141+ const passphrase = await parsePassphrase ( option . passphrase ) ;
142142 const secret = await exportKey ( cckey , accountType , address , passphrase ) ;
143143 const res = option . pretty
144144 ? JSON . stringify ( secret , null , 2 )
@@ -191,11 +191,19 @@ function parseAddress(address: string): string {
191191 return address ;
192192}
193193
194- function parsePassphrase ( passphrase : string ) : string {
195- if ( _ . isUndefined ( passphrase ) ) {
196- throw new CLIError ( CLIErrorType . OptionRequired , {
197- optionName : "passphrase"
198- } ) ;
194+ async function parsePassphrase ( passphrase : string ) : Promise < string > {
195+ if ( ! _ . isUndefined ( passphrase ) ) {
196+ return passphrase ;
199197 }
200- return passphrase ;
198+
199+ const Enquirer = require ( "enquirer" ) ;
200+ const enquirer = new Enquirer ( ) ;
201+ enquirer . register ( "password" , require ( "prompt-password" ) ) ;
202+ var questions = {
203+ type : "password" ,
204+ message : "Enter your passphrase please" ,
205+ name : "passphrase"
206+ } ;
207+ const answers = await enquirer . ask ( questions ) ;
208+ return answers . passphrase ;
201209}
0 commit comments