create working for ledger

This commit is contained in:
Matias Alejo Garcia 2015-11-04 01:54:54 -03:00
parent d1c1638b14
commit f633a15a2d
6 changed files with 56 additions and 52 deletions

View File

@ -100,7 +100,16 @@
</div> </div>
<div ng-hide="hideAdv" class="row"> <div ng-hide="hideAdv" class="row">
<div class="large-12 medium-12 columns">
<div class="large-12 columns">
<label for="bws" class="oh">
<span>Wallet Service URL</span>
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</label>
</div>
<div class="large-12 columns">
<label><span translate>Wallet Seed</span> <label><span translate>Wallet Seed</span>
<select class="m10t" ng-model="seedSource" <select class="m10t" ng-model="seedSource"
ng-options="seed as seed.label for seed in create.seedOptions" ng-options="seed as seed.label for seed in create.seedOptions"
@ -110,29 +119,14 @@
</div> </div>
<div class="large-12 columns"> <div class="large-12 columns">
<label ng-show="index.isChromeApp && totalCopayers > 1 " for="hw-ledger" class="oh"> <div ng-show="create.seedSourceId == 'trezor' || create.seedSourceId == 'ledger'">
<span translate>Use Ledger hardware wallet</span>
<switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" ng-change="isTestnet=false" class="green right m5t m10b"></switch> <label class="oh"><span translate>Account</span>
</label> <select class="m10t" ng-model="account" ng-options="externalIndex as externalIndex for externalIndex in create.accountValues">
<!-- -->
<label ng-show="!index.isCordova && 0" for="hw-trezor" class="oh">
<span translate>Use TREZOR hardware wallet</span>
<switch id="hw-trezor" name="hwTrezor" ng-model="hwTrezor" class="green right m5t m10b"></switch>
</label>
<!-- TODO account
<div ng-show="hwLedger">
<label class="oh"><span translate>Ledger Slot</span>
<select class="m10t" ng-model="externalIndex" ng-options="externalIndex as externalIndex for externalIndex in create.externalIndexValues">
</select> </select>
</label> </label>
<div class="oh text-gray line-b size-12 p10b m20b"><span translate>Ledger supports up to 20 Copay wallets simultaneously. Select which slot should be used to host this wallet</div> <div class="oh text-gray line-b size-12 p10b m20b"><span translate>Multiple wallets accounts are supported on the device simultaneously. Select which account should be used for this wallet</div>
</div> </div>
-->
<label for="network-name" class="oh" ng-show="!hwLedger && !hwTrezor">
<span translate>Testnet</span>
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
</label>
<label for="createPassphrase" class="oh" ng-show="create.seedSourceId=='new' " ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small> <label for="createPassphrase" class="oh" ng-show="create.seedSourceId=='new' " ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small>
<div class="input"> <div class="input">
<input type="text" class="form-control" <input type="text" class="form-control"
@ -152,15 +146,15 @@
<input type="text" class="form-control" name="passphrase" ng-model="passphrase"> <input type="text" class="form-control" name="passphrase" ng-model="passphrase">
</div> </div>
</label> </label>
<label for="network-name" class="oh" ng-show="create.seedSourceId == 'set' || create.seedSourceId == 'new'">
<label for="bws" class="oh"> <span translate>Testnet</span>
<span>Wallet Service URL</span> <switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl">
</label> </label>
</div>
</div>
<div class="box-notification" ng-show="!setSeed && createPassphrase">
</div>
<div class="box-notification" ng-show="create.seedSourceId=='new' && createPassphrase">
<span class="text-warning size-14"> <span class="text-warning size-14">
<i class="fi-alert"></i> <i class="fi-alert"></i>
<span translate> <span translate>
@ -168,8 +162,7 @@
</span> </span>
</span> </span>
</div> </div>
</div>
<button type="submit" class="button round black expand m0" ng-show="totalCopayers != 1" ng-disabled="setupForm.$invalid || create.loading || create.hwWallet"> <button type="submit" class="button round black expand m0" ng-show="totalCopayers != 1" ng-disabled="setupForm.$invalid || create.loading || create.hwWallet">
<span translate>Create {{requiredCopayers}}-of-{{totalCopayers}} wallet</span> <span translate>Create {{requiredCopayers}}-of-{{totalCopayers}} wallet</span>

View File

@ -49,9 +49,8 @@ angular.module('copayApp.controllers').controller('createController',
}]; }];
$scope.seedSource = self.seedOptions[0]; $scope.seedSource = self.seedOptions[0];
// TODO
// TODO // if (!isChromeApp) return;
// if (!isChromeApp) return;
if (n > 1) if (n > 1)
self.seedOptions.push({ self.seedOptions.push({
@ -63,6 +62,7 @@ angular.module('copayApp.controllers').controller('createController',
id: 'trezor', id: 'trezor',
label: gettext('Trezor Hardware Wallet'), label: gettext('Trezor Hardware Wallet'),
}); });
}; };
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1); this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
@ -71,12 +71,18 @@ angular.module('copayApp.controllers').controller('createController',
this.setTotalCopayers = function(tc) { this.setTotalCopayers = function(tc) {
updateRCSelect(tc); updateRCSelect(tc);
updateSeedSourceSelect(tc); updateSeedSourceSelect(tc);
self.seedSourceId = $scope.seedSource.id;
}; };
this.setSeedSource = function(src) { this.setSeedSource = function(src) {
self.seedSourceId = $scope.seedSource.id; self.seedSourceId = $scope.seedSource.id;
console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
if (self.seedSourceId == 'ledger')
self.accountValues = lodash.range(0, 99);
else
self.accountValues = lodash.range(1, 100);
$timeout(function() { $timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
}); });
@ -95,7 +101,7 @@ console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet', networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl bwsurl: $scope.bwsurl
}; };
var setSeed = form.setSeed.$modelValue; var setSeed = self.seedSourceId =='set';
if (setSeed) { if (setSeed) {
var words = form.privateKey.$modelValue; var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) { if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
@ -113,12 +119,16 @@ console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
return; return;
} }
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src = form.hwLedger.$modelValue ? ledger : trezor; if (self.seedSourceId == 'ledger' || self.seedSourceId == 'trezor') {
var account = $scope.account;
if (!account) {
this.error = gettext('Please select account');
return;
}
self.hwWallet = self.seedSourceId == 'ledger' ? 'Ledger' : 'Trezor';
var src = self.seedSourceId == 'ledger' ? ledger : trezor;
var account = form.account.$modelValue;
src.getInfoForNewWallet(opts.n > 1, account, function(err, lopts) { src.getInfoForNewWallet(opts.n > 1, account, function(err, lopts) {
self.hwWallet = false; self.hwWallet = false;
if (err) { if (err) {
@ -178,4 +188,5 @@ console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
$rootScope.hideWalletNavigation = false; $rootScope.hideWalletNavigation = false;
}); });
updateSeedSourceSelect(1); updateSeedSourceSelect(1);
self.seedSourceId = 'new'
}); });

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.services') angular.module('copayApp.services')
.factory('hwWallet', function($log) { .factory('hwWallet', function($log, bwcService) {
var root = {}; var root = {};
// Ledger magic number to get xPub without user confirmation // Ledger magic number to get xPub without user confirmation
@ -11,7 +11,7 @@ angular.module('copayApp.services')
root.LIVENET_PATH = 0; root.LIVENET_PATH = 0;
root._err = function(data) { root._err = function(data) {
var msg = 'HW WALLET Error: ' + (data.error || data.message || 'unknown'); var msg = 'Hardware Wallet Error: ' + (data.error || data.message || 'unknown');
$log.warn(msg); $log.warn(msg);
return msg; return msg;
}; };
@ -23,8 +23,7 @@ angular.module('copayApp.services')
root.getEntropyPath = function(isMultisig, account) { root.getEntropyPath = function(isMultisig, account) {
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH; var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH;
var path = hwWallet.ENTROPY_INDEX_PATH + rootPath + "'/" var path = root.ENTROPY_INDEX_PATH + rootPath + "'/" + account + "'";
account + "'";
return path; return path;
}; };

View File

@ -40,7 +40,7 @@ angular.module('copayApp.services')
root.getInfoForNewWallet = function(isMultisig, account, callback) { root.getInfoForNewWallet = function(isMultisig, account, callback) {
var opts = {}; var opts = {};
root.getEntropySource(isMultisig, account, function(entropySource) { root.getEntropySource(isMultisig, account, function(err, entropySource) {
if (err) return callback(err); if (err) return callback(err);
opts.entropySource = entropySource; opts.entropySource = entropySource;
@ -51,7 +51,7 @@ angular.module('copayApp.services')
} }
opts.extendedPublicKey = data.xpubkey; opts.extendedPublicKey = data.xpubkey;
opts.externalSource = 'ledger'; opts.externalSource = 'ledger';
opts.externalIndex = account; opts.account = account;
return callback(null, opts); return callback(null, opts);
}); });
}); });

View File

@ -181,7 +181,7 @@ angular.module('copayApp.services')
walletClient.seedFromMnemonic(opts.mnemonic, { walletClient.seedFromMnemonic(opts.mnemonic, {
network: network, network: network,
passphrase: opts.passphrase, passphrase: opts.passphrase,
account: 0, account: opts.account || 0,
}); });
} catch (ex) { } catch (ex) {
$log.info(ex); $log.info(ex);
@ -197,7 +197,7 @@ angular.module('copayApp.services')
} else if (opts.extendedPublicKey) { } else if (opts.extendedPublicKey) {
try { try {
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
account: 0 account: opts.account || 0,
}); });
} catch (ex) { } catch (ex) {
$log.warn("Creating wallet from Extended Public Key Arg:", ex, opts); $log.warn("Creating wallet from Extended Public Key Arg:", ex, opts);
@ -420,7 +420,7 @@ angular.module('copayApp.services')
walletClient.importFromMnemonic(words, { walletClient.importFromMnemonic(words, {
network: opts.networkName, network: opts.networkName,
passphrase: opts.passphrase, passphrase: opts.passphrase,
account: 0, account: opts.account,
}, function(err) { }, function(err) {
if (err) if (err)
return bwsError.cb(err, gettext('Could not import'), cb); return bwsError.cb(err, gettext('Could not import'), cb);
@ -437,7 +437,7 @@ angular.module('copayApp.services')
$log.debug('Importing Wallet XPubKey'); $log.debug('Importing Wallet XPubKey');
walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
account: 0 account: opts.account || 0,
}, function(err) { }, function(err) {
if (err) { if (err) {

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.services') angular.module('copayApp.services')
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash, bitcore, hwWallet) { .factory('trezor', function($log, $timeout, gettext, lodash, bitcore, hwWallet) {
var root = {}; var root = {};
var SETTLE_TIME = 3000; var SETTLE_TIME = 3000;
@ -24,10 +24,11 @@ angular.module('copayApp.services')
root.getInfoForNewWallet = function(isMultisig, account, callback) { root.getInfoForNewWallet = function(isMultisig, account, callback) {
account = account - 1;
var opts = {}; var opts = {};
root.getEntropySource(isMultisig, account, function(err, data) { root.getEntropySource(isMultisig, account, function(err, data) {
if (err) return callback(err); if (err) return callback(err);
opts.entropySource = data.entropySource; opts.entropySource = data;
$log.debug('Waiting TREZOR to settle...'); $log.debug('Waiting TREZOR to settle...');
$timeout(function() { $timeout(function() {
@ -37,7 +38,7 @@ angular.module('copayApp.services')
opts.extendedPublicKey = data.xpubkey; opts.extendedPublicKey = data.xpubkey;
opts.externalSource = 'trezor'; opts.externalSource = 'trezor';
opts.externalIndex = account; opts.account = account;
return callback(null, opts); return callback(null, opts);
}); });
}, SETTLE_TIME); }, SETTLE_TIME);