fix account indexes, add base path in settings

This commit is contained in:
Matias Alejo Garcia 2015-11-05 19:46:32 -03:00
commit 791efca714
11 changed files with 162 additions and 74 deletions

View file

@ -1,11 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('createController',
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile, isChromeApp, isDevel) {
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile, isChromeApp, isDevel, derivationPathHelper) {
var self = this;
var defaults = configService.getDefaults();
this.isWindowsPhoneApp = isMobile.Windows() && isCordova;
$scope.account = 1;
/* For compressed keys, m*73 + n*34 <= 496 */
var COPAYER_PAIR_LIMITS = {
@ -25,8 +26,7 @@ angular.module('copayApp.controllers').controller('createController',
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
self.accountValuesForSeed = lodash.range(0, 100);
$scope.accountForSeed = 0;
$scope.derivationPath = derivationPathHelper.default;
// ng-repeat defined number of times instead of repeating over array?
this.getNumber = function(num) {
@ -77,7 +77,6 @@ angular.module('copayApp.controllers').controller('createController',
this.setSeedSource = function(src) {
self.seedSourceId = $scope.seedSource.id;
self.accountValues = lodash.range(1, 100);
$timeout(function() {
$rootScope.$apply();
@ -89,6 +88,7 @@ angular.module('copayApp.controllers').controller('createController',
this.error = gettext('Please enter the required fields');
return;
}
var opts = {
m: $scope.requiredCopayers,
n: $scope.totalCopayers,
@ -96,18 +96,29 @@ angular.module('copayApp.controllers').controller('createController',
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl,
account: $scope.accountForSeed || 0,
use48: $scope.fromHardware,
};
var setSeed = self.seedSourceId =='set';
var setSeed = self.seedSourceId == 'set';
if (setSeed) {
var words = 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;
var pathData = derivationPathHelper.parse($scope.derivationPath);
if (!pathData) {
this.error = gettext('Invalid derivation path');
return;
}
opts.account = pathData.account;
opts.networkName = pathData.networkName;
opts.derivationStrategy = pathData.derivationStrategy;
} else {
opts.passphrase = form.createPassphrase.$modelValue;
}
@ -119,11 +130,15 @@ angular.module('copayApp.controllers').controller('createController',
if (self.seedSourceId == 'ledger' || self.seedSourceId == 'trezor') {
var account = $scope.account;
if (!account) {
this.error = gettext('Please select account');
if (!account || account < 1) {
this.error = gettext('Invalid account number');
return;
}
opts.account = account;
if ( self.seedSourceId == 'trezor')
account = account - 1;
opts.account = account;
self.hwWallet = self.seedSourceId == 'ledger' ? 'Ledger' : 'Trezor';
var src = self.seedSourceId == 'ledger' ? ledger : trezor;

View file

@ -1,14 +1,14 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, isChromeApp, isDevel) {
function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, isChromeApp, isDevel, derivationPathHelper) {
var self = this;
var reader = new FileReader();
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
$scope.accountForSeed = 0;
self.accountValuesForSeed = lodash.range(0, 100);
$scope.derivationPath = derivationPathHelper.default;
$scope.account = 1;
window.ignoreMobilePause = true;
$scope.$on('$destroy', function() {
@ -196,8 +196,16 @@ angular.module('copayApp.controllers').controller('importController',
}
opts.passphrase = form.passphrase.$modelValue || null;
opts.networkName = form.isTestnet.$modelValue ? 'testnet' : 'livenet';
opts.account = $scope.accountForSeed;
var pathData = derivationPathHelper.parse($scope.derivationPath);
if (!pathData) {
this.error = gettext('Invalid derivation path');
return;
}
opts.account = pathData.account;
opts.networkName = pathData.networkName;
opts.derivationStrategy = pathData.derivationStrategy;
_importMnemonic(words, opts);
};
@ -233,15 +241,24 @@ angular.module('copayApp.controllers').controller('importController',
};
this.importHW = function(form) {
if (form.$invalid) {
if (form.$invalid || $scope.account < 0 ) {
this.error = gettext('There is an error in the form');
$timeout(function() {
$scope.$apply();
});
return;
}
this.error = '';
var account = $scope.account;
var account = + $scope.account;
if (self.seedSourceId == 'trezor') {
if ( account < 1) {
this.error = gettext('Invalid account number');
return;
}
account = account - 1;
}
var isMultisig = form.isMultisig.$modelValue;
switch (self.seedSourceId) {
@ -261,7 +278,6 @@ angular.module('copayApp.controllers').controller('importController',
this.setSeedSource = function() {
if (!$scope.seedSource) return;
self.seedSourceId = $scope.seedSource.id;
self.accountValues = lodash.range(1, 100);
$timeout(function() {
$rootScope.$apply();

View file

@ -1,13 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, isChromeApp, isDevel) {
function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, isChromeApp, isDevel,derivationPathHelper) {
var self = this;
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url;
self.accountValuesForSeed = lodash.range(0, 100);
$scope.accountForSeed = 0;
$scope.derivationPath = derivationPathHelper.default;
this.onQrCodeScanned = function(data) {
$scope.secret = data;
@ -62,7 +61,6 @@ angular.module('copayApp.controllers').controller('joinController',
secret: form.secret.$modelValue,
myName: form.myName.$modelValue,
bwsurl: $scope.bwsurl,
account: $scope.accountForSeed || 0,
}
var setSeed = self.seedSourceId =='set';
@ -74,6 +72,15 @@ angular.module('copayApp.controllers').controller('joinController',
opts.mnemonic = words;
}
opts.passphrase = form.passphrase.$modelValue;
var pathData = derivationPathHelper.parse($scope.derivationPath);
if (!pathData) {
this.error = gettext('Invalid derivation path');
return;
}
opts.account = pathData.account;
opts.networkName = pathData.networkName;
opts.derivationStrategy = pathData.derivationStrategy;
} else {
opts.passphrase = form.createPassphrase.$modelValue;
}
@ -85,10 +92,14 @@ angular.module('copayApp.controllers').controller('joinController',
if (self.seedSourceId == 'ledger' || self.seedSourceId == 'trezor') {
var account = $scope.account;
if (!account) {
this.error = gettext('Please select account');
if (!account || account < 1) {
this.error = gettext('Invalid account number');
return;
}
if ( self.seedSourceId == 'trezor')
account = account - 1;
opts.account = account;
self.hwWallet = self.seedSourceId == 'ledger' ? 'Ledger' : 'Trezor';
var src = self.seedSourceId == 'ledger' ? ledger : trezor;

View file

@ -21,13 +21,14 @@ angular
$logProvider.debugEnabled(true);
$provide.decorator('$log', ['$delegate',
function($delegate) {
function($delegate, isDevel) {
var historicLog = historicLogProvider.$get();
['debug', 'info', 'warn', 'error', 'log'].forEach(function(level) {
if (isDevel && level == 'error') return;
var orig = $delegate[level];
$delegate[level] = function() {
if (level == 'error')
console.log(arguments);

View file

@ -0,0 +1,46 @@
'use strict';
angular.module('copayApp.services').factory('derivationPathHelper', function(lodash) {
var root = {};
root.default = "m/44'/0'/0'"
root.parse = function(str) {
var arr = str.split('/');
var ret = {};
if (arr[0] != 'm')
return false;
switch (arr[1]) {
case "44'":
ret.derivationStrategy = 'BIP44';
break;
case "48'":
ret.derivationStrategy = 'BIP48';
break;
default:
return false;
};
switch (arr[2]) {
case "0'":
ret.networkName = 'livenet';
break;
case "1'":
ret.networkName = 'testnet';
break;
default:
return false;
};
var match = arr[3].match(/(\d+)'/);
if (!match)
return false;
ret.account = + match[1]
return ret;
};
return root;
});

View file

@ -13,7 +13,7 @@ angular.module('copayApp.services')
root._err = function(data) {
var msg = 'Hardware Wallet Error: ' + (data.error || data.message || 'unknown');
$log.warn(msg);
return JSON.parse(JSON.stringify(msg));
return msg;
};
root.getAddressPath = function(isMultisig, account) {

View file

@ -24,7 +24,6 @@ angular.module('copayApp.services')
root.getInfoForNewWallet = function(isMultisig, account, callback) {
account = account - 1;
var opts = {};
root.getEntropySource(isMultisig, account, function(err, data) {
if (err) return callback(err);