support xPrivKey seeds

This commit is contained in:
Matias Alejo Garcia 2015-09-05 00:11:14 -03:00
parent b712874c17
commit f1f4e5cfaf
6 changed files with 81 additions and 26 deletions

View File

@ -47,8 +47,8 @@
</div> </div>
<div class="row m20t" ng-show="!wordsC.mnemonicWords"> <div class="row m20t" ng-show="!wordsC.mnemonicWords">
<div class="columns size-14 text-gray" translate> <div class="columns size-14 text-gray text-center" translate>
The wallet seed not available on this device. You can still export the wallet to backup it. Wallet seed not available. You can still export it from Advanced &gt; Export .
</div> </div>
</div> </div>

View File

@ -35,7 +35,7 @@ angular.module('copayApp.controllers').controller('createController',
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq); $scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
}; };
this.externalIndexValues = lodash.range(0,ledger.MAX_SLOT); this.externalIndexValues = lodash.range(0, ledger.MAX_SLOT);
$scope.externalIndex = 0; $scope.externalIndex = 0;
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1); this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
$scope.totalCopayers = defaults.wallet.totalCopayers; $scope.totalCopayers = defaults.wallet.totalCopayers;
@ -62,13 +62,18 @@ angular.module('copayApp.controllers').controller('createController',
}; };
var setSeed = form.setSeed.$modelValue; var setSeed = form.setSeed.$modelValue;
if (setSeed) { if (setSeed) {
opts.mnemonic = form.privateKey.$modelValue; var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
opts.extendedPrivateKey = words;
} else {
opts.mnemonic = words;
}
opts.passphrase = form.passphrase.$modelValue; opts.passphrase = form.passphrase.$modelValue;
} else { } else {
opts.passphrase = form.createPassphrase.$modelValue; opts.passphrase = form.createPassphrase.$modelValue;
} }
if (setSeed && !opts.mnemonic) { if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
this.error = gettext('Please enter the wallet seed'); this.error = gettext('Please enter the wallet seed');
return; return;
} }
@ -90,7 +95,7 @@ angular.module('copayApp.controllers').controller('createController',
} }
}; };
this._create = function (opts) { this._create = function(opts) {
self.loading = true; self.loading = true;
$timeout(function() { $timeout(function() {
profileService.createWallet(opts, function(err, secret, walletId) { profileService.createWallet(opts, function(err, secret, walletId) {
@ -104,9 +109,8 @@ angular.module('copayApp.controllers').controller('createController',
$timeout(function() { $timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
}); });
} } else {
else { if (opts.n == 1 && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
if ( ( opts.mnemonic && opts.n==1) || opts.externalSource ) {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
} else { } else {
go.walletHome(); go.walletHome();
@ -122,11 +126,9 @@ angular.module('copayApp.controllers').controller('createController',
if (what && what == 'my-name') { if (what && what == 'my-name') {
this.hideWalletName = true; this.hideWalletName = true;
this.hideTabs = true; this.hideTabs = true;
} } else if (what && what == 'wallet-name') {
else if (what && what == 'wallet-name'){
this.hideTabs = true; this.hideTabs = true;
} } else {
else {
this.hideWalletName = false; this.hideWalletName = false;
this.hideTabs = false; this.hideTabs = false;
} }

View File

@ -63,11 +63,32 @@ angular.module('copayApp.controllers').controller('importController',
}; };
var _importExtendedPrivateKey = function(xPrivKey) {
self.loading = true;
$timeout(function() {
profileService.importExtendedPrivateKey(xPrivKey, function(err, walletId) {
self.loading = false;
if (err) {
self.error = err;
return $timeout(function() {
$scope.$apply();
});
}
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
});
}, 100);
};
var _importMnemonic = function(words, opts) { var _importMnemonic = function(words, opts) {
self.loading = true; self.loading = true;
$timeout(function() { $timeout(function() {
profileService.importWalletMnemonic(words, opts, function(err, walletId) { profileService.importMnemonic(words, opts, function(err, walletId) {
self.loading = false; self.loading = false;
if (err) { if (err) {
self.error = err; self.error = err;
@ -140,7 +161,11 @@ angular.module('copayApp.controllers').controller('importController',
if (!words) { if (!words) {
this.error = gettext('Please enter the seed words'); this.error = gettext('Please enter the seed words');
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
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;
}); });

View File

@ -737,7 +737,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.showErrorPopup = function (msg, cb) { self.showErrorPopup = function(msg, cb) {
$log.warn('Showing err popup:' + msg); $log.warn('Showing err popup:' + msg);
self.showAlert = { self.showAlert = {
msg: msg, msg: msg,
@ -1015,7 +1015,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.needsBackup = false; self.needsBackup = false;
storageService.setBackupFlag(walletId, function() { storageService.setBackupFlag(walletId, function() {
addressService.expireAddress(walletId, function(err) { addressService.expireAddress(walletId, function(err) {
$timeout(function() {
self.startScan(walletId); self.startScan(walletId);
}, 500);
}); });
}); });
}); });
@ -1108,7 +1110,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
$rootScope.$on('Local/ShowAlert', function(event, msg, cb) { $rootScope.$on('Local/ShowAlert', function(event, msg, cb) {
self.showErrorPopup(msg,cb); self.showErrorPopup(msg, cb);
}); });
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) { $rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {

View File

@ -158,13 +158,18 @@ angular.module('copayApp.controllers').controller('joinController',
var setSeed = form.setSeed.$modelValue; var setSeed = form.setSeed.$modelValue;
if (setSeed) { if (setSeed) {
opts.mnemonic = form.privateKey.$modelValue; var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
opts.extendedPrivateKey = words;
} else {
opts.mnemonic = words;
}
opts.passphrase = form.passphrase.$modelValue; opts.passphrase = form.passphrase.$modelValue;
} else { } else {
opts.passphrase = form.createPassphrase.$modelValue; opts.passphrase = form.createPassphrase.$modelValue;
} }
if (setSeed && !opts.mnemonic) { if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
this.error = gettext('Please enter the wallet seed'); this.error = gettext('Please enter the wallet seed');
return; return;
} }
@ -197,7 +202,7 @@ angular.module('copayApp.controllers').controller('joinController',
} }
$timeout(function() { $timeout(function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if ( ( opts.mnemonic || opts.externalSource ) && fc.isComplete()) { if ( fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
$rootScope.$emit('Local/WalletImported', fc.credentials.walletId); $rootScope.$emit('Local/WalletImported', fc.credentials.walletId);
} else { } else {
go.walletHome(); go.walletHome();

View File

@ -177,6 +177,13 @@ angular.module('copayApp.services')
$log.info(ex); $log.info(ex);
return cb(gettext('Could not create: Invalid wallet seed')); return cb(gettext('Could not create: Invalid wallet seed'));
} }
} else if (opts.extendedPrivateKey) {
try {
walletClient.seedFromExtendedPrivateKey(opts.extendedPrivateKey);
} catch (ex) {
$log.warn(ex);
return cb(gettext('Could not create using the specified extended private key'));
}
} else if (opts.extendedPublicKey) { } else if (opts.extendedPublicKey) {
try { try {
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource); walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource);
@ -344,7 +351,21 @@ angular.module('copayApp.services')
root._addWalletClient(walletClient, cb); root._addWalletClient(walletClient, cb);
}; };
root.importWalletMnemonic = function(words, opts, cb) { root.importExtendedPrivateKey = function(xPrivKey, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet xPrivKey');
walletClient.importFromExtendedPrivateKey(xPrivKey, function(err) {
if (err)
return bwsError.cb(err, gettext('Could not import'), cb);
root._addWalletClient(walletClient, cb);
});
};
root.importMnemonic = function(words, opts, cb) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Importing Wallet Mnemonic'); $log.debug('Importing Wallet Mnemonic');