fix spending passwor in export

This commit is contained in:
Matias Alejo Garcia 2016-08-29 16:13:18 -03:00
parent aa42db1458
commit f534b0bc2d
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
3 changed files with 27 additions and 46 deletions

View File

@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.walletName = wallet.credentials.walletName;
$scope.n = wallet.n;
$scope.credentialsEncrypted = wallet.isPrivKeyEncrypted;
$scope.credentialsEncrypted = wallet.isPrivKeyEncrypted();
var isDeletedSeed = function() {
if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted))
@ -20,13 +20,13 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.deleted = isDeletedSeed();
if ($scope.deleted) return;
walletService.getKey(wallet, function(err, mnemonics, xpriv) {
walletService.getKeys(wallet, function(err, keys) {
if (err) {
$state.go('preferences');
return;
}
$scope.credentialsEncrypted = false;
$scope.initFlow(mnemonics, xpriv);
$scope.initFlow(keys);
});
};
@ -41,9 +41,9 @@ angular.module('copayApp.controllers').controller('backupController',
});
};
$scope.initFlow = function() {
var words = wallet.getMnemonic();
xPriv6 = wallet.credentials.xPrivKey.substr(wallet.credentials.xPrivKey.length - 6);
$scope.initFlow = function(keys) {
var words = keys.mnemonic;
xPriv6 = keys.xPrivKey.substr(wallet.credentials.xPrivKey.length - 6);
$scope.mnemonicWords = words.split(/[\u3000\s]+/);
$scope.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords);
@ -128,7 +128,7 @@ angular.module('copayApp.controllers').controller('backupController',
}
if (walletClient.credentials.xPrivKey.substr(walletClient.credentials.xPrivKey-6) != xPriv6) {
walletClient.credentials.xPrivKey = lodash.repeat('x', 64);
delete walletClient.credentials;
return cb('Private key mismatch');
}
}
@ -141,7 +141,6 @@ angular.module('copayApp.controllers').controller('backupController',
var finalStep = function() {
ongoingProcess.set('validatingWords', true);
confirm(function(err) {
xPriv6 = lodash.repeat('x', 6);
ongoingProcess.set('validatingWords', false);
if (err) {
backupError(err);
@ -192,9 +191,4 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.selectComplete = false;
};
$scope.$on('$destroy', function() {
walletService.lock(wallet);
});
});

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('exportController',
function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, notification, gettext, gettextCatalog, $state, $stateParams) {
function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, gettext, gettextCatalog, $state, $stateParams) {
var prevState;
var isWP = platformInfo.isWP;
var isAndroid = platformInfo.isAndroid;
@ -21,7 +21,7 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.canSign = wallet.canSign();
walletService.getEncodedWalletInfo(wallet, function(err, code) {
if (err) {
if (err || !code) {
$log.warn(err);
return $state.go('wallet.preferencesAdvanced')
}
@ -48,10 +48,6 @@ angular.module('copayApp.controllers').controller('exportController',
};
*/
$scope.$on('$destroy', function() {
walletService.lock(wallet);
});
$scope.downloadWalletBackup = function() {
$scope.getAddressbook(function(err, localAddressBook) {
if (err) {
@ -68,7 +64,6 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.error = true;
return;
}
notification.success(gettext('Success'), gettext('Encrypted export file saved'));
$state.go('tabs.home');
});
});

View File

@ -1028,42 +1028,34 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.getEncodedWalletInfo = function(wallet, cb) {
var getCode = function() {
var derivationPath = wallet.credentials.getBaseAddressDerivationPath();
var encodingType = {
mnemonic: 1,
xpriv: 2,
xpub: 3
};
var info;
var derivationPath = wallet.credentials.getBaseAddressDerivationPath();
var encodingType = {
mnemonic: 1,
xpriv: 2,
xpub: 3
};
var info;
// not supported yet
if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign())
return null;
// not supported yet
if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign())
return null;
if (wallet.credentials.mnemonic) {
root.getKeys(wallet, function(err, keys){
if (err || !keys) return cb(err);
if (keys.mnemonic) {
info = {
type: encodingType.mnemonic,
data: wallet.credentials.mnemonic,
data: keys.mnemonic,
}
} else {
info = {
type: encodingType.xpriv,
data: wallet.credentials.xPrivKey
data: keys.xPrivKey
}
}
return info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase);
};
return cb(null, info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase));
fingerprintService.check(wallet, function(err) {
if (err) return cb(err);
root.handleEncryptedWallet(wallet, function(err) {
if (err) return cb(err);
var code = getCode();
return cb(null, code);
});
});
};
@ -1135,7 +1127,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
root.getKey = function(wallet, cb) {
root.getKeys = function(wallet, cb) {
root.prepare(wallet, function(err, password) {
if (err) return cb(err);
var keys;