@@ -26,7 +26,7 @@ const subparsers = parser.addSubparsers({
26
26
27
27
const importKeys = subparsers . addParser ( 'import' , { addHelp : true } ) ;
28
28
importKeys . addArgument (
29
- [ 'file' ] ,
29
+ [ 'file' ] ,
30
30
{
31
31
action : 'store' ,
32
32
help : 'path to a list of public keys generated from admin.js generate'
@@ -59,12 +59,12 @@ signCommand.addArgument(
59
59
}
60
60
) ;
61
61
signCommand . addArgument (
62
- [ '--path' ] ,
63
- {
64
- action : 'store' ,
65
- required : false ,
66
- help : 'optional derivation path to derive from the given key'
67
- }
62
+ [ '--path' ] ,
63
+ {
64
+ action : 'store' ,
65
+ required : false ,
66
+ help : 'optional derivation path to derive from the given key'
67
+ }
68
68
) ;
69
69
signCommand . addArgument (
70
70
[ '--confirm' ] ,
@@ -161,20 +161,20 @@ generateKeysCommand.addArgument(
161
161
162
162
subparsers . addParser ( 'seed' , {
163
163
addHelp : true ,
164
- description : 'Generates a cryptographically secure random seed to be used for Stellar key derivation.\n' +
165
- 'Note: To generate a master key for non-Stellar coins, please install BitGo CLI and run "bitgo newkey"'
164
+ description : 'Generates a cryptographically secure random seed to be used for Stellar key derivation.\n'
165
+ + 'Note: To generate a master key for non-Stellar coins, please install BitGo CLI and run "bitgo newkey"'
166
166
} ) ;
167
167
168
168
const deriveKeyCommand = subparsers . addParser ( 'derive' , { addHelp : true } ) ;
169
169
deriveKeyCommand . addArgument (
170
- [ 'master' ] ,
170
+ [ 'master' ] ,
171
171
{
172
172
action : 'store' ,
173
173
help : 'xpub of the master key (starts with "xpub")'
174
174
}
175
175
) ;
176
176
deriveKeyCommand . addArgument (
177
- [ 'path' ] ,
177
+ [ 'path' ] ,
178
178
{
179
179
action : 'store' ,
180
180
help : 'derivation path of the wallet key (starts with "m/")'
@@ -230,7 +230,8 @@ const validateKey = function(key, type) {
230
230
} ;
231
231
232
232
const saveKeys = co ( function * ( keys , type ) {
233
- // this extracts the possible values directly from the Mongoose schema, which is considered the most accurate set of possible values
233
+ // this extracts the possible values directly from the Mongoose schema,
234
+ // which is considered the most accurate set of possible values
234
235
const validTypes = MasterKey . schema . path ( 'type' ) . enumValues ;
235
236
236
237
if ( ! validTypes . includes ( type ) ) {
@@ -246,7 +247,7 @@ const saveKeys = co(function *(keys, type) {
246
247
path : key . path ,
247
248
signature : key . signature ,
248
249
keyCount : 0
249
- } ) ) ;
250
+ } ) ) ;
250
251
251
252
if ( keyDocs . length === 0 ) {
252
253
console . log ( 'No valid public keys. Please re-generate and try again.' ) ;
@@ -265,7 +266,8 @@ const saveKeys = co(function *(keys, type) {
265
266
console . log ( `New capacity: ${ availableKeys } available ${ type } keys out of ${ totalKeys } total ${ type } keys.` ) ;
266
267
} catch ( e ) {
267
268
console . log ( e . message ) ;
268
- console . log ( 'FAILED to import all public keys. This is usually caused by trying to import a public key that already exists in the database.' ) ;
269
+ console . log ( 'FAILED to import all public keys. '
270
+ + 'This is usually caused by trying to import a public key that already exists in the database.' ) ;
269
271
}
270
272
} ) ;
271
273
@@ -277,7 +279,9 @@ const handleImportKeys = co(function *(args) {
277
279
throw new Error ( 'please specify the path to a CSV file containing the public keys to import' ) ;
278
280
}
279
281
280
- let keys = JSON . parse ( fs . readFileSync ( path , { encoding : 'utf8' } ) ) ;
282
+ const file = yield fs . readFile ( path , { encoding : 'utf8' } ) ;
283
+
284
+ let keys = JSON . parse ( file ) ;
281
285
282
286
keys = formatKeysByType ( keys , type ) ;
283
287
@@ -294,7 +298,8 @@ const handleImportKeys = co(function *(args) {
294
298
* xlmSignature: "KOPASIK------PSDIFAPSDFOAF"
295
299
* path: "100"
296
300
* }
297
- * If this key comes in, we can save it either as type xpub or xlm (depending on what the admin specifies on the command line)
301
+ * If this key comes in, we can save it either as type xpub or xlm
302
+ * (depending on what the admin specifies on the command line)
298
303
* If the above key is imported as type 'xlm', we will change it to the following format:
299
304
* {
300
305
* pub: "GSLKJASDFJASLFASDFAS"
@@ -316,9 +321,9 @@ const formatKeysByType = function(keys, type) {
316
321
signature : type === 'xlm' ? key . xlmSignature : key . signature ,
317
322
path : key . path
318
323
} ) ;
319
- } )
324
+ } ) ;
320
325
return formattedkeys ;
321
- }
326
+ } ;
322
327
323
328
const handleDeriveKey = function ( args ) {
324
329
try {
@@ -364,7 +369,7 @@ const handleVerificationGet = co(function *(args) {
364
369
}
365
370
366
371
if ( _ . isUndefined ( key . verificationInfo ) ) {
367
- key . verificationInfo = '<N/A>'
372
+ key . verificationInfo = '<N/A>' ;
368
373
}
369
374
370
375
// if there are multiple lines, this aligns each line under the first line
@@ -411,15 +416,15 @@ const handleVerification = co(function *(args) {
411
416
}
412
417
} ) ;
413
418
414
- const handleRecoveryInfo = co ( function * ( args ) {
419
+ const handleRecoveryInfo = co ( function * ( args ) {
415
420
const json = JSON . parse ( fs . readFileSync ( args . file ) ) ;
416
421
const pub = json . backupKey ;
417
422
const walletkey = yield WalletKey . findOne ( { pub } ) ;
418
423
const masterkey = yield MasterKey . findOne ( { pub : walletkey . masterKey } ) ;
419
424
json . masterkey = masterkey . pub ;
420
425
json . masterkeypath = masterkey . path ;
421
426
json . walletkeypath = walletkey . path ;
422
- const filename = args . file . substring ( 0 , args . file . length - 5 ) + '-prepared.json' ;
427
+ const filename = args . file . substring ( 0 , args . file . length - 5 ) + '-prepared.json' ;
423
428
console . log ( 'got info... writing file ' + filename ) ;
424
429
fs . writeFileSync ( filename , JSON . stringify ( json , null , 2 ) ) ;
425
430
console . log ( 'done.' ) ;
@@ -429,7 +434,7 @@ const requireDB = function() {
429
434
MasterKey = require ( './models/masterkey.js' ) ;
430
435
WalletKey = require ( './models/walletkey.js' ) ;
431
436
db = require ( './db.js' ) ;
432
- }
437
+ } ;
433
438
434
439
const run = co ( function * ( testArgs ) {
435
440
const args = parser . parseArgs ( testArgs ) ;
@@ -440,7 +445,7 @@ const run = co(function *(testArgs) {
440
445
yield handleImportKeys ( args ) ;
441
446
break ;
442
447
case 'sign' :
443
- signingTool . handleSign ( args ) ;
448
+ yield signingTool . handleSign ( args ) ;
444
449
break ;
445
450
case 'derive' :
446
451
handleDeriveKey ( args ) ;
@@ -466,4 +471,4 @@ const run = co(function *(testArgs) {
466
471
} ) ;
467
472
468
473
// For admin script and unit testing of functions
469
- module . exports = { run, validateKey, saveKeys, db , requireDB } ;
474
+ module . exports = { run, validateKey, saveKeys, db, requireDB } ;
0 commit comments