fix ledger paths

This commit is contained in:
Matias Alejo Garcia 2015-09-05 13:03:46 -03:00
commit a8032e1e4b
2 changed files with 12 additions and 7 deletions

View file

@ -7,7 +7,7 @@ angular.module('copayApp.services')
root.MAX_SLOT = 20; root.MAX_SLOT = 20;
// Ledger magic number to get xPub without user confirmation // Ledger magic number to get xPub without user confirmation
root.ENTROPY_INDEX_PATH = "m/0xb11e/"; root.ENTROPY_INDEX_PATH = "0xb11e/";
root.callbacks = {}; root.callbacks = {};
@ -26,6 +26,7 @@ angular.module('copayApp.services')
} }
var b = bwcService.getBitcore(); var b = bwcService.getBitcore();
var x = b.HDPublicKey(data.xpubkey); var x = b.HDPublicKey(data.xpubkey);
data.entropySource = x.publicKey.toString(); data.entropySource = x.publicKey.toString();
return callback(data); return callback(data);
@ -37,6 +38,8 @@ angular.module('copayApp.services')
}; };
root.getXPubKey = function(path, callback) { root.getXPubKey = function(path, callback) {
$log.debug('Ledger deriving xPub path:', path);
root.callbacks["get_xpubkey"] = callback; root.callbacks["get_xpubkey"] = callback;
root._messageAfterSession({ root._messageAfterSession({
command: "get_xpubkey", command: "get_xpubkey",
@ -85,6 +88,7 @@ angular.module('copayApp.services')
root._reverseBytestring(input.prevout.bytes(32)).toString() root._reverseBytestring(input.prevout.bytes(32)).toString()
]); ]);
} }
$log.debug('Ledger signing paths:', paths);
root._messageAfterSession({ root._messageAfterSession({
command: "sign_p2sh", command: "sign_p2sh",
inputs: inputs, inputs: inputs,
@ -143,7 +147,7 @@ angular.module('copayApp.services')
} }
root._getPath = function(index) { root._getPath = function(index) {
return "m/" + index + "'/45'"; return index + "'/45'";
} }
root._splitTransaction = function(transaction) { root._splitTransaction = function(transaction) {

View file

@ -171,7 +171,7 @@ angular.module('copayApp.services')
var network = opts.networkName || 'livenet'; var network = opts.networkName || 'livenet';
if (opts.mnemonic && opts.mnemonic.indexOf('m/' != 0)) { if (opts.mnemonic && opts.mnemonic.indexOf('m/' != 0)) {
var xPrivKey = root._processDerivation(opts.mnemonic, network); var xPrivKey = root._preDerivation(opts.mnemonic, network);
if (!xPrivKey) if (!xPrivKey)
return bwsError.cb('Bad derivation', gettext('Could not import'), cb); return bwsError.cb('Bad derivation', gettext('Could not import'), cb);
opts.mnemonic = null; opts.mnemonic = null;
@ -371,23 +371,24 @@ angular.module('copayApp.services')
}; };
root._processDerivation = function(words, network) { root._preDerivation = function(words, network) {
var wordList = words.split(/ /).filter(function(v) { var wordList = words.split(/ /).filter(function(v) {
return v.length > 0; return v.length > 0;
}); });
var path = wordList.shift(); var path = wordList.shift();
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('processDerivation', path); $log.info('preDerivation:', path);
walletClient.seedFromMnemonic(wordList.join(' '), null, network); walletClient.seedFromMnemonic(wordList.join(' '), null, network);
var k = new bitcore.HDPrivateKey(walletClient.credentials.xPrivKey); var k = new bitcore.HDPrivateKey(walletClient.credentials.xPrivKey);
return k.toString(); var k2 = k.derive(path);
return k2.toString();
}; };
root.importMnemonic = function(words, opts, cb) { root.importMnemonic = function(words, opts, cb) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
if (words.indexOf('m/') == 0) { if (words.indexOf('m/') == 0) {
var xPrivKey = root._processDerivation(words, opts.networkName); var xPrivKey = root._preDerivation(words, opts.networkName);
if (!xPrivKey) if (!xPrivKey)
return bwsError.cb('Bad derivation', gettext('Could not import'), cb); return bwsError.cb('Bad derivation', gettext('Could not import'), cb);
return root.importExtendedPrivateKey(xPrivKey, cb); return root.importExtendedPrivateKey(xPrivKey, cb);