From 452d9e1bda624257e7c5c9fa82a24577b3ceb745 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 2 Sep 2015 15:56:00 -0300 Subject: [PATCH] create/join using mnemonic working --- public/views/backup.html | 45 +++++++-- public/views/create.html | 4 +- public/views/import.html | 24 +++-- public/views/join.html | 7 +- public/views/walletHome.html | 36 +++---- src/js/controllers/import.js | 38 ++++--- src/js/controllers/splash.js | 8 -- src/js/services/bwsError.js | 15 +++ src/js/services/profileService.js | 163 ++++++++++++++---------------- 9 files changed, 188 insertions(+), 152 deletions(-) diff --git a/public/views/backup.html b/public/views/backup.html index ef8b0f3ee..0401c83eb 100644 --- a/public/views/backup.html +++ b/public/views/backup.html @@ -7,16 +7,42 @@
-
+
- In order to restore your Copay wallet you will need these 12 backup words. + You will need these backup words to restore this personal wallet. - Write them down and keep them somethere safe + Write them down and keep them somewhere safe.
+
+
+ + To restore this {{index.m}}-{{index.n}} shared wallet you will need: + : +
    +
  1. Your backup words and access to the wallet service where your wallet is registered +
  2. OR the backup words of all copayers in the wallet +
  3. OR 1 wallet export file and the remaining quorum of backup words (e.g. in a 3-5 wallet: 1 wallet export file + 2 backup words of any of the other copayers). +
+ +
+
+
+
+ + To restore this {{index.m}}-{{index.n}} shared wallet you will need + : +
    +
  1. Your backup words and access to the wallet service where wallet is registered +
  2. OR the backups words of all copayers in the wallet +
+ +
+
+
The backup words had been deleted from this device @@ -37,10 +63,11 @@
- - {{word}} - -
+
+ {{word}} +
+
Once you have wrote your backup words, it is recommended to delete them from this device. @@ -54,7 +81,9 @@
-
+ + +
diff --git a/public/views/import.html b/public/views/import.html index 74507f5eb..ec2eeaf0d 100644 --- a/public/views/import.html +++ b/public/views/import.html @@ -20,21 +20,21 @@
-
+ -
+ -
- QR Code -
+ + + + +
@@ -55,7 +55,7 @@ - +
@@ -69,12 +69,18 @@
-
diff --git a/public/views/join.html b/public/views/join.html index e42f615f8..c298755d4 100644 --- a/public/views/join.html +++ b/public/views/join.html @@ -99,11 +99,12 @@
-
diff --git a/public/views/walletHome.html b/public/views/walletHome.html index b690a50a4..c5772a71e 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -215,16 +215,14 @@

My Bitcoin address

-
+
+
+ + {{home.addrError|translate}} + +
-
- - {{home.addrError|translate}} - -
- - -
+
@@ -246,15 +244,17 @@
-
- - - Share address - -
-
- Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them. +
+
+ + + Share address + +
+
+ Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them. +
diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 3fdf55067..c8d77aae3 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -18,6 +18,7 @@ angular.module('copayApp.controllers').controller('importController', this.setType = function(type) { $scope.type = type; + this.error = null; $timeout(function() { $rootScope.$apply(); }); @@ -63,11 +64,8 @@ angular.module('copayApp.controllers').controller('importController', var _importMnemonic = function(words, passphrase, opts) { self.loading = true; - console.log('[import.js.64:opts:]', opts); //TODO $timeout(function() { - profileService.importWalletMnemonic(words, { - passphrase: passphrase, - }, function(err, ret) { + profileService.importWalletMnemonic(words, opts, function(err, ret) { self.loading = false; if (err) { self.error = err; @@ -83,13 +81,13 @@ angular.module('copayApp.controllers').controller('importController', }, 100); }; -// { -// network: opts.network, -// m: opts.m, -// n: opts.n, -// publicKeyRing: opts.publicKeyRing, -// }, -// + // { + // network: opts.network, + // m: opts.m, + // n: opts.n, + // publicKeyRing: opts.publicKeyRing, + // }, + // $scope.getFile = function() { // If we use onloadend, we need to check the readyState. reader.onloadend = function(evt) { @@ -144,18 +142,28 @@ angular.module('copayApp.controllers').controller('importController', var passphrase = form.passphrase.$modelValue; var words = form.words.$modelValue; + this.error = null; - if (!words || words.split(' ').map(function(v) { - return lodash.trim(v); - }).length != 12) { - this.error = gettext('Please input 12 backup words'); + if (!words) { + this.error = gettext('Please enter the backup words'); + } else { + var wordList = words.split(/ /).filter(function(v){ return v.length>0; }); + if (wordList.length != 12) + this.error = gettext('Please enter 12 backup words'); + else + words = wordList.join(' '); + } + + if (this.error) { $timeout(function() { $scope.$apply(); }); return; } + opts.passphrase = form.passphrase.$modelValue || null; + opts.networkName = form.isTestnet.$modelValue ? 'testnet' : 'livenet'; _importMnemonic(words, passphrase, opts); }; diff --git a/src/js/controllers/splash.js b/src/js/controllers/splash.js index 3b26e5b7f..87ab843ed 100644 --- a/src/js/controllers/splash.js +++ b/src/js/controllers/splash.js @@ -29,12 +29,4 @@ angular.module('copayApp.controllers').controller('splashController', }); }, 100); }; - -console.log('[splash.js.32]'); //TODO - var a = bwcService.getClient(); - -console.log('[splash.js.34]'); //TODO -a.seedFromMnemonic('glare benefit approve speak post afford spot cancel argue cushion unaware kitchen'); -console.log("LISTO", a.credentials); - }); diff --git a/src/js/services/bwsError.js b/src/js/services/bwsError.js index f91c3b541..7791c075a 100644 --- a/src/js/services/bwsError.js +++ b/src/js/services/bwsError.js @@ -84,6 +84,21 @@ angular.module('copayApp.services') case 'WALLET_NOT_FOUND': body = gettextCatalog.getString('Wallet not found'); break; + case 'SERVER_COMPROMISED': + body = gettextCatalog.getString('Server response could not be verified'); + break; + case 'WALLET_DOES_NOT_EXIST': + body = gettextCatalog.getString('This wallet is not registed at the wallet service. Please create it from "Create Wallet" using adding for backup words'); + break; + case 'INVALID_BACKUP': + body = gettextCatalog.getString('Backup words are invalid'); + break; + + + default: + $log.warn('Unknown error type:', err.code); + body = err.code + ':' + err.message; + break; } } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 710a9f40a..b47cb312c 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -146,7 +146,7 @@ angular.module('copayApp.services') return cb(err); } if (!profile) { - // Migration?? + // Migration?? storageService.tryToMigrate(function(err, migratedProfile) { if (err) return cb(err); if (!migratedProfile) @@ -165,52 +165,14 @@ angular.module('copayApp.services') }); }; - root._seedWallet = function(walletClient, network) { - var lang = uxLanguage.getCurrentLanguage(); - -console.log('[profileService.js.170]'); //TODO - try { - walletClient.seedFromRandomWithMnemonic(network, null, lang); - -console.log('[profileService.js.174]'); //TODO - } catch (e) { - $log.info('Error creating seed: ' + e.message); - if (e.message.indexOf('language') > 0) { - $log.info('Using default language for mnemonic'); - walletClient.seedFromRandomWithMnemonic(network); - } else { - throw (e); - } - } - }; - - root._createNewProfile = function(opts, cb) { - - if (opts.noWallet) { - return cb(null, Profile.create()); - } - + root._seedWallet = function(opts, cb) { + opts = opts || {}; var walletClient = bwcService.getClient(); - root._seedWallet(walletClient, 'livenet'); - - walletClient.createWallet('Personal Wallet', 'me', 1, 1, { - network: 'livenet' - }, function(err) { - if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); - var p = Profile.create({ - credentials: [JSON.parse(walletClient.export())], - }); - return cb(null, p); - }) - }; - - root.createWallet = function(opts, cb) { - var walletClient = bwcService.getClient(); - $log.debug('Creating Wallet:', opts); + var network = opts.networkName || 'livenet'; if (opts.mnemonic) { try { - walletClient.seedFromMnemonic(opts.mnemonic); + walletClient.seedFromMnemonic(opts.mnemonic, opts.passphrase, network); } catch (ex) { $log.info(ex); return cb(gettext('Could not create: Invalid Backup Words')); @@ -221,41 +183,69 @@ console.log('[profileService.js.174]'); //TODO } catch (ex) { return cb(gettext('Could not create using the specified extended public key')); } + } else { + var lang = uxLanguage.getCurrentLanguage(); + try { + walletClient.seedFromRandomWithMnemonic(network, opts.passphrase, lang); + } catch (e) { + $log.info('Error creating seed: ' + e.message); + if (e.message.indexOf('language') > 0) { + $log.info('Using default language for mnemonic'); + walletClient.seedFromRandomWithMnemonic(network, opts.passphrase); + } else { + return cb(e); + } + } } - root._seedWallet(walletClient, opts.networkName); + return cb(null, walletClient); + }; - walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, { - network: opts.networkName - }, function(err, secret) { - if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); + root._createNewProfile = function(opts, cb) { - root.profile.credentials.push(JSON.parse(walletClient.export())); - root.setWalletClients(); + if (opts.noWallet) { + return cb(null, Profile.create()); + } - root.setAndStoreFocus(walletClient.credentials.walletId, function() { - storageService.storeProfile(root.profile, function(err) { - return cb(null, secret); + root._seedWallet({}, function(err, walletClient) { + if (err) return cb(err); + + walletClient.createWallet('Personal Wallet', 'me', 1, 1, { + network: 'livenet' + }, function(err) { + if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); + var p = Profile.create({ + credentials: [JSON.parse(walletClient.export())], }); + return cb(null, p); }); }) }; + root.createWallet = function(opts, cb) { + $log.debug('Creating Wallet:', opts); + root._seedWallet(opts, function(err, walletClient) { + if (err) return cb(err); + + walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, { + network: opts.networkName + }, function(err, secret) { + if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); + + root.profile.credentials.push(JSON.parse(walletClient.export())); + root.setWalletClients(); + + root.setAndStoreFocus(walletClient.credentials.walletId, function() { + storageService.storeProfile(root.profile, function(err) { + return cb(null, secret); + }); + }); + }) + }); + }; + root.joinWallet = function(opts, cb) { var walletClient = bwcService.getClient(); $log.debug('Joining Wallet:', opts); - if (opts.extendedPrivateKey) { - try { - walletClient.seedFromExtendedPrivateKey(opts.extendedPrivateKey); - } catch (ex) { - return cb(gettext('Could not join using the specified extended private key')); - } - } else if (opts.extendedPublicKey) { - try { - walletClient.seedFromExternalWalletPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex); - } catch (ex) { - return cb(gettext('Could not create using the specified extended public key')); - } - } try { var walletData = this.getUtils().fromSecret(opts.secret); @@ -269,18 +259,24 @@ console.log('[profileService.js.174]'); //TODO } catch (ex) { return cb(gettext('Bad wallet invitation')); } + opts.networkName = walletData.network; + $log.debug('Joining Wallet:', opts); - walletClient.joinWallet(opts.secret, opts.myName || 'me', function(err) { - if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); + root._seedWallet(opts, function(err, walletClient) { + if (err) return cb(err); - root.profile.credentials.push(JSON.parse(walletClient.export())); - root.setWalletClients(); + walletClient.joinWallet(opts.secret, opts.myName || 'me', function(err) { + if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); - root.setAndStoreFocus(walletClient.credentials.walletId, function() { - storageService.storeProfile(root.profile, function(err) { - return cb(null, opts.secret); + root.profile.credentials.push(JSON.parse(walletClient.export())); + root.setWalletClients(); + + root.setAndStoreFocus(walletClient.credentials.walletId, function() { + storageService.storeProfile(root.profile, function(err) { + return cb(); + }); }); - }); + }) }) }; @@ -351,9 +347,13 @@ console.log('[profileService.js.174]'); //TODO var walletClient = bwcService.getClient(); $log.debug('Importing Wallet Mnemonic'); +console.log('[profileService.js.340]', words, opts); //TODO walletClient.importFromMnemonic(words, { + network: opts.networkName, passphrase: opts.passphrase, }, function(err) { +console.log('[profileService.js.342:err:]',err); //TODO +console.log('[profileService.js.341:walletClient:]',walletClient.credentials.credentials); //TODO if (err) return bwsError.cb(err, gettext('Could not import'), cb); @@ -361,21 +361,6 @@ console.log('[profileService.js.174]'); //TODO }); }; - - root.importWalletMnemonicEx = function(words, opts, cb) { - var walletClient = bwcService.getClient(); - $log.debug('Importing Wallet Mnemonic EX', opts); - - walletClient.importFromMnemonic(words, opts, - function(err) { - if (err) - return bwsError.cb(err, gettext('Could not import'), cb); - - root._addWalletClient(walletClient, cb); - }); - }; - - root.create = function(opts, cb) { $log.info('Creating profile'); configService.get(function(err) {