Skip to content

Commit 50947c9

Browse files
author
Mark Toda
committed
Fix lint
1 parent d7bf444 commit 50947c9

File tree

11 files changed

+370
-211
lines changed

11 files changed

+370
-211
lines changed

app/admin.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const subparsers = parser.addSubparsers({
2626

2727
const importKeys = subparsers.addParser('import', { addHelp: true });
2828
importKeys.addArgument(
29-
[ 'file' ],
29+
['file'],
3030
{
3131
action: 'store',
3232
help: 'path to a list of public keys generated from admin.js generate'
@@ -59,12 +59,12 @@ signCommand.addArgument(
5959
}
6060
);
6161
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+
}
6868
);
6969
signCommand.addArgument(
7070
['--confirm'],
@@ -161,20 +161,20 @@ generateKeysCommand.addArgument(
161161

162162
subparsers.addParser('seed', {
163163
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"'
166166
});
167167

168168
const deriveKeyCommand = subparsers.addParser('derive', { addHelp: true });
169169
deriveKeyCommand.addArgument(
170-
[ 'master' ],
170+
['master'],
171171
{
172172
action: 'store',
173173
help: 'xpub of the master key (starts with "xpub")'
174174
}
175175
);
176176
deriveKeyCommand.addArgument(
177-
[ 'path' ],
177+
['path'],
178178
{
179179
action: 'store',
180180
help: 'derivation path of the wallet key (starts with "m/")'
@@ -230,7 +230,8 @@ const validateKey = function(key, type) {
230230
};
231231

232232
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
234235
const validTypes = MasterKey.schema.path('type').enumValues;
235236

236237
if (!validTypes.includes(type)) {
@@ -246,7 +247,7 @@ const saveKeys = co(function *(keys, type) {
246247
path: key.path,
247248
signature: key.signature,
248249
keyCount: 0
249-
}));
250+
}));
250251

251252
if (keyDocs.length === 0) {
252253
console.log('No valid public keys. Please re-generate and try again.');
@@ -265,7 +266,8 @@ const saveKeys = co(function *(keys, type) {
265266
console.log(`New capacity: ${availableKeys} available ${type} keys out of ${totalKeys} total ${type} keys.`);
266267
} catch (e) {
267268
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.');
269271
}
270272
});
271273

@@ -277,7 +279,9 @@ const handleImportKeys = co(function *(args) {
277279
throw new Error('please specify the path to a CSV file containing the public keys to import');
278280
}
279281

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);
281285

282286
keys = formatKeysByType(keys, type);
283287

@@ -294,7 +298,8 @@ const handleImportKeys = co(function *(args) {
294298
* xlmSignature: "KOPASIK------PSDIFAPSDFOAF"
295299
* path: "100"
296300
* }
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)
298303
* If the above key is imported as type 'xlm', we will change it to the following format:
299304
* {
300305
* pub: "GSLKJASDFJASLFASDFAS"
@@ -316,9 +321,9 @@ const formatKeysByType = function(keys, type) {
316321
signature: type === 'xlm' ? key.xlmSignature : key.signature,
317322
path: key.path
318323
});
319-
})
324+
});
320325
return formattedkeys;
321-
}
326+
};
322327

323328
const handleDeriveKey = function(args) {
324329
try {
@@ -364,7 +369,7 @@ const handleVerificationGet = co(function *(args) {
364369
}
365370

366371
if (_.isUndefined(key.verificationInfo)) {
367-
key.verificationInfo = '<N/A>'
372+
key.verificationInfo = '<N/A>';
368373
}
369374

370375
// if there are multiple lines, this aligns each line under the first line
@@ -411,15 +416,15 @@ const handleVerification = co(function *(args) {
411416
}
412417
});
413418

414-
const handleRecoveryInfo = co(function *(args){
419+
const handleRecoveryInfo = co(function *(args) {
415420
const json = JSON.parse(fs.readFileSync(args.file));
416421
const pub = json.backupKey;
417422
const walletkey = yield WalletKey.findOne({ pub });
418423
const masterkey = yield MasterKey.findOne({ pub: walletkey.masterKey });
419424
json.masterkey = masterkey.pub;
420425
json.masterkeypath = masterkey.path;
421426
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';
423428
console.log('got info... writing file ' + filename);
424429
fs.writeFileSync(filename, JSON.stringify(json, null, 2));
425430
console.log('done.');
@@ -429,7 +434,7 @@ const requireDB = function() {
429434
MasterKey = require('./models/masterkey.js');
430435
WalletKey = require('./models/walletkey.js');
431436
db = require('./db.js');
432-
}
437+
};
433438

434439
const run = co(function *(testArgs) {
435440
const args = parser.parseArgs(testArgs);
@@ -466,4 +471,4 @@ const run = co(function *(testArgs) {
466471
});
467472

468473
// For admin script and unit testing of functions
469-
module.exports = { run, validateKey, saveKeys, db , requireDB };
474+
module.exports = { run, validateKey, saveKeys, db, requireDB };

app/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const express = require('express');
22
const bodyParser = require('body-parser');
3+
const fs = require('fs');
34
const morgan = require('morgan');
5+
const path = require('path');
46

57
const utils = require('./utils');
68
const krs = require('./krs');

app/krs.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const WalletKey = require('./models/walletkey');
1818
* @param state: 'created' when the key is first created
1919
*/
2020
const notifyEndpoint = co(function *(key, state) {
21-
const generateHMAC = function(xpub){
21+
const generateHMAC = function(xpub) {
2222
const hmac = crypto.createHmac('sha256', process.config.provider.secret);
2323
hmac.update(xpub);
2424
return hmac.digest('hex');
@@ -37,7 +37,7 @@ const notifyEndpoint = co(function *(key, state) {
3737
state: state,
3838
xpub: xpub,
3939
hmac: hmac
40-
})
40+
});
4141
} catch (e) {
4242
console.log('error connecting to webhook');
4343
}
@@ -60,7 +60,8 @@ const sendDatabaseLowWarning = co(function *(availableKeys, type) {
6060
const provisionMasterKey = co(function *(coin, customerId) {
6161
const keyType = process.config.supportedcoins[coin];
6262

63-
const key = yield MasterKey.findOneAndUpdate({ coin: null, customerId: null, type: keyType }, { coin: coin, customerId: customerId, type: keyType });
63+
const key = yield MasterKey.findOneAndUpdate({ coin: null, customerId: null, type: keyType },
64+
{ coin: coin, customerId: customerId, type: keyType });
6465

6566
if (!key) {
6667
throw utils.ErrorResponse(500, `no available ${keyType} keys`);
@@ -83,7 +84,7 @@ const provisionMasterKey = co(function *(coin, customerId) {
8384
*/
8485
const getMasterXpub = co(function *(coin, customerId) {
8586

86-
if(process.config.neverReuseMasterKey) {
87+
if (process.config.neverReuseMasterKey) {
8788
return provisionMasterKey(coin, customerId);
8889
}
8990

@@ -128,8 +129,8 @@ exports.provisionKey = co(function *(req) {
128129
if (!req.body.requesterId && !req.body.requesterSecret) {
129130
throw utils.ErrorResponse(401, 'this krs requires you to send a requesterId and requesterSecret to get a key');
130131
}
131-
if (!process.config.requesterAuth.clients[req.body.requesterId] ||
132-
process.config.requesterAuth.clients[req.body.requesterId] !== req.body.requesterSecret) {
132+
if (!process.config.requesterAuth.clients[req.body.requesterId]
133+
|| process.config.requesterAuth.clients[req.body.requesterId] !== req.body.requesterSecret) {
133134
throw utils.ErrorResponse(401, 'invalid requesterSecret');
134135
}
135136
}
@@ -193,7 +194,7 @@ exports.provisionKey = co(function *(req) {
193194
custom: key.custom,
194195
masterKeySig: masterKey.signature,
195196
pub: key.pub
196-
}
197+
};
197198

198199
return response;
199200
});

app/models/masterkey.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const masterKeySchema = new mongoose.Schema({
77
customerId: { type: String },
88
pub: { type: String },
99
path: { type: String },
10-
signature: {type: String},
10+
signature: { type: String },
1111
keyCount: { type: Number }
1212
});
1313

0 commit comments

Comments
 (0)