From a8032e1e4bb653289ebc9b7054b5b47fc47d940b Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 5 Sep 2015 13:03:46 -0300 Subject: [PATCH] fix ledger paths --- src/js/services/ledger.js | 8 ++++++-- src/js/services/profileService.js | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/js/services/ledger.js b/src/js/services/ledger.js index b55cdb872..0af9410d8 100644 --- a/src/js/services/ledger.js +++ b/src/js/services/ledger.js @@ -7,7 +7,7 @@ angular.module('copayApp.services') root.MAX_SLOT = 20; // Ledger magic number to get xPub without user confirmation - root.ENTROPY_INDEX_PATH = "m/0xb11e/"; + root.ENTROPY_INDEX_PATH = "0xb11e/"; root.callbacks = {}; @@ -26,6 +26,7 @@ angular.module('copayApp.services') } var b = bwcService.getBitcore(); + var x = b.HDPublicKey(data.xpubkey); data.entropySource = x.publicKey.toString(); return callback(data); @@ -37,6 +38,8 @@ angular.module('copayApp.services') }; root.getXPubKey = function(path, callback) { + + $log.debug('Ledger deriving xPub path:', path); root.callbacks["get_xpubkey"] = callback; root._messageAfterSession({ command: "get_xpubkey", @@ -85,6 +88,7 @@ angular.module('copayApp.services') root._reverseBytestring(input.prevout.bytes(32)).toString() ]); } + $log.debug('Ledger signing paths:', paths); root._messageAfterSession({ command: "sign_p2sh", inputs: inputs, @@ -143,7 +147,7 @@ angular.module('copayApp.services') } root._getPath = function(index) { - return "m/" + index + "'/45'"; + return index + "'/45'"; } root._splitTransaction = function(transaction) { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 4e8d6b024..46b0ac3da 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -171,7 +171,7 @@ angular.module('copayApp.services') var network = opts.networkName || 'livenet'; if (opts.mnemonic && opts.mnemonic.indexOf('m/' != 0)) { - var xPrivKey = root._processDerivation(opts.mnemonic, network); + var xPrivKey = root._preDerivation(opts.mnemonic, network); if (!xPrivKey) return bwsError.cb('Bad derivation', gettext('Could not import'), cb); 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) { return v.length > 0; }); var path = wordList.shift(); var walletClient = bwcService.getClient(); - $log.debug('processDerivation', path); + $log.info('preDerivation:', path); walletClient.seedFromMnemonic(wordList.join(' '), null, network); 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) { var walletClient = bwcService.getClient(); if (words.indexOf('m/') == 0) { - var xPrivKey = root._processDerivation(words, opts.networkName); + var xPrivKey = root._preDerivation(words, opts.networkName); if (!xPrivKey) return bwsError.cb('Bad derivation', gettext('Could not import'), cb); return root.importExtendedPrivateKey(xPrivKey, cb);