mirror of https://github.com/BTCPrivate/copay.git
add derivation path input in mnemonic
This commit is contained in:
parent
f1f4e5cfaf
commit
e395bca072
|
@ -164,12 +164,12 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||
return _importExtendedPrivateKey(words)
|
||||
} else {
|
||||
|
||||
console.log('[import.js.167]', words.indexOf(' '), words.indexOf('prv')); //TODO
|
||||
var wordList = words.split(/ /).filter(function(v) {
|
||||
return v.length > 0;
|
||||
});
|
||||
if ((wordList.length % 3) != 0)
|
||||
|
||||
// m/ allows to enter a custom derivation
|
||||
if ((wordList.length % 3) != 0 && wordList[0].indexOf('m/') != 0)
|
||||
this.error = gettext('Wrong number of seed words:') + wordList.length;
|
||||
else
|
||||
words = wordList.join(' ');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services')
|
||||
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, nodeWebkit, bwsError, uxLanguage, ledger) {
|
||||
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, nodeWebkit, bwsError, uxLanguage, ledger, bitcore) {
|
||||
|
||||
var root = {};
|
||||
|
||||
|
@ -170,6 +170,13 @@ angular.module('copayApp.services')
|
|||
var walletClient = bwcService.getClient();
|
||||
var network = opts.networkName || 'livenet';
|
||||
|
||||
if (opts.mnemonic && opts.mnemonic.indexOf('m/' != 0)) {
|
||||
var xPrivKey = root._processDerivation(opts.mnemonic, network);
|
||||
if (!xPrivKey)
|
||||
return bwsError.cb('Bad derivation', gettext('Could not import'), cb);
|
||||
opts.mnemonic = null;
|
||||
opts.extendedPrivateKey = xPrivKey;
|
||||
}
|
||||
if (opts.mnemonic) {
|
||||
try {
|
||||
walletClient.seedFromMnemonic(opts.mnemonic, opts.passphrase, network);
|
||||
|
@ -364,9 +371,28 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
|
||||
root._processDerivation = 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);
|
||||
walletClient.seedFromMnemonic(wordList.join(' '), null, network);
|
||||
var k = new bitcore.HDPrivateKey(walletClient.credentials.xPrivKey);
|
||||
return k.toString();
|
||||
};
|
||||
|
||||
root.importMnemonic = function(words, opts, cb) {
|
||||
var walletClient = bwcService.getClient();
|
||||
|
||||
if (words.indexOf('m/') == 0) {
|
||||
var xPrivKey = root._processDerivation(words, opts.networkName);
|
||||
if (!xPrivKey)
|
||||
return bwsError.cb('Bad derivation', gettext('Could not import'), cb);
|
||||
return root.importExtendedPrivateKey(xPrivKey, cb);
|
||||
}
|
||||
|
||||
$log.debug('Importing Wallet Mnemonic');
|
||||
|
||||
walletClient.importFromMnemonic(words, {
|
||||
|
|
Loading…
Reference in New Issue