add derivation path input in mnemonic
This commit is contained in:
parent
f1f4e5cfaf
commit
e395bca072
2 changed files with 30 additions and 4 deletions
|
|
@ -164,12 +164,12 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
||||||
return _importExtendedPrivateKey(words)
|
return _importExtendedPrivateKey(words)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
console.log('[import.js.167]', words.indexOf(' '), words.indexOf('prv')); //TODO
|
|
||||||
var wordList = words.split(/ /).filter(function(v) {
|
var wordList = words.split(/ /).filter(function(v) {
|
||||||
return v.length > 0;
|
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;
|
this.error = gettext('Wrong number of seed words:') + wordList.length;
|
||||||
else
|
else
|
||||||
words = wordList.join(' ');
|
words = wordList.join(' ');
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
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 = {};
|
var root = {};
|
||||||
|
|
||||||
|
|
@ -170,6 +170,13 @@ angular.module('copayApp.services')
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient();
|
||||||
var network = opts.networkName || 'livenet';
|
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) {
|
if (opts.mnemonic) {
|
||||||
try {
|
try {
|
||||||
walletClient.seedFromMnemonic(opts.mnemonic, opts.passphrase, network);
|
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) {
|
root.importMnemonic = function(words, opts, cb) {
|
||||||
var walletClient = bwcService.getClient();
|
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');
|
$log.debug('Importing Wallet Mnemonic');
|
||||||
|
|
||||||
walletClient.importFromMnemonic(words, {
|
walletClient.importFromMnemonic(words, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue