Skip to content

Commit a7e8593

Browse files
authored
Merge pull request #40 from BitGo/separate-offline
[BG-9476] Separate Offline/Online Commands and Fix Key-Response
2 parents 3d7c5af + 0f96358 commit a7e8593

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

app/admin.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ const pjson = require('../package.json');
88
const fs = require('fs');
99
const crypto = require('crypto');
1010

11-
const db = require('./db.js');
12-
const MasterKey = require('./models/masterkey.js');
11+
let db, MasterKey, WalletKey;
1312
const signingTool = require('./sign.js');
14-
const WalletKey = require('./models/walletkey.js');
1513
const utils = require('./utils');
1614
const bitcoinMessage = require('bitcoinjs-message');
1715

@@ -108,6 +106,15 @@ setVerificationCommand.addArgument(
108106
}
109107
);
110108

109+
const recoveryInfoCommand = subparsers.addParser('recoveryInfo', { addHelp: true });
110+
recoveryInfoCommand.addArgument(
111+
['file'],
112+
{
113+
action: 'store',
114+
help: 'the path to the recovery file that bitgo provided'
115+
}
116+
);
117+
111118
const generateKeysCommand = subparsers.addParser('generate', { addHelp: true });
112119
generateKeysCommand.addArgument(
113120
['master'],
@@ -368,11 +375,32 @@ const handleVerification = co(function *(args) {
368375
}
369376
});
370377

378+
const handleRecoveryInfo = co(function *(args){
379+
const json = JSON.parse(fs.readFileSync(args.file));
380+
const pub = json.backupKey;
381+
const walletkey = yield WalletKey.findOne({ pub });
382+
const masterkey = yield MasterKey.findOne({ pub: walletkey.masterKey });
383+
json.masterkey = masterkey.pub;
384+
json.masterkeypath = masterkey.path;
385+
json.walletkeypath = walletkey.path;
386+
const filename = args.file.substring(0,args.file.length - 5) + '-prepared.json';
387+
console.log('got info... writing file ' + filename);
388+
fs.writeFileSync(filename, JSON.stringify(json, null, 2));
389+
console.log('done.');
390+
});
391+
392+
const requireDB = function() {
393+
MasterKey = require('./models/masterkey.js');
394+
WalletKey = require('./models/walletkey.js');
395+
db = require('./db.js');
396+
}
397+
371398
const run = co(function *(testArgs) {
372399
const args = parser.parseArgs(testArgs);
373400

374401
switch (args.cmd) {
375402
case 'import':
403+
requireDB();
376404
yield handleImportKeys(args);
377405
break;
378406
case 'sign':
@@ -388,11 +416,17 @@ const run = co(function *(testArgs) {
388416
handleGenerateHDSeed();
389417
break;
390418
case 'verification':
419+
requireDB();
391420
yield handleVerification(args);
392421
break;
422+
case 'recoveryInfo':
423+
requireDB();
424+
yield handleRecoveryInfo(args);
393425
}
394426

395-
db.connection.close();
427+
if (db && db.connection) {
428+
db.connection.close();
429+
}
396430
});
397431

398432
// For admin script and unit testing of functions

app/krs.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,14 @@ exports.provisionKey = co(function *(req) {
186186
yield notifyEndpoint(key, 'created');
187187
}
188188

189-
return key;
189+
const response = {
190+
masterKey: masterKey.pub,
191+
path: key.path,
192+
userEmail: key.userEmail,
193+
custom: key.custom,
194+
masterKeySig: masterKey.signature,
195+
pub: key.pub
196+
}
197+
198+
return response;
190199
});

app/sign.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const handleSignXrp = function(recoveryRequest, key, skipConfirm) {
193193
const rippleParse = require('ripple-binary-codec');
194194

195195
const decimals = coinDecimals[recoveryRequest.coin];
196-
const transaction = rippleParse.decode(recoveryRequest.txHex);
196+
const transaction = rippleParse.decode(recoveryRequest.tx);
197197
const customMessage = recoveryRequest.custom ? recoveryRequest.custom.message : 'None';
198198

199199
const outputs = [{

bin/admin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ const admin = require('../app/admin');
66
Promise.try(admin.run).catch(function(e) {
77
console.log(e.message);
88
console.log(e.stack);
9-
admin.db.connection.close();
9+
if (admin.db && admin.db.connection) {
10+
admin.db.connection.close();
11+
}
1012
});

0 commit comments

Comments
 (0)