From 291ed73916ceb603de0bd7a42f6aeccf6c477ec4 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 21 Aug 2014 14:54:36 -0400 Subject: [PATCH] add test and adv opts to create --- js/controllers/join.js | 2 +- js/controllers/setup.js | 2 ++ js/models/core/WalletFactory.js | 14 +++++++++----- test/test.WalletFactory.js | 21 +++++++++++++++++++++ views/setup.html | 17 ++++++++++++++++- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/js/controllers/join.js b/js/controllers/join.js index beae1eb14..3cf0033ce 100644 --- a/js/controllers/join.js +++ b/js/controllers/join.js @@ -116,7 +116,7 @@ angular.module('copayApp.controllers').controller('JoinController', walletFactory.network.on('badSecret', function() {}); Passphrase.getBase64Async($scope.joinPassword, function(passphrase) { - walletFactory.joinCreateSession($scope.connectionId, $scope.nickname, passphrase, $scope.enterPrivate ? $scope.private : null, function(err, w) { + walletFactory.joinCreateSession($scope.connectionId, $scope.nickname, passphrase, $scope.private, function(err, w) { $scope.loading = false; if (err || !w) { if (err === 'joinError') diff --git a/js/controllers/setup.js b/js/controllers/setup.js index 2c353c209..a87bc871c 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -41,6 +41,7 @@ angular.module('copayApp.controllers').controller('SetupController', $scope.loading = false; $scope.walletPassword = $rootScope.walletPassword; $scope.isMobile = !!window.cordova; + $scope.hideAdv = true; // ng-repeat defined number of times instead of repeating over array? $scope.getNumber = function(num) { @@ -82,6 +83,7 @@ angular.module('copayApp.controllers').controller('SetupController', name: $scope.walletName, nickname: $scope.myNickname, passphrase: passphrase, + privateKeyHex: $scope.private, }; var w = walletFactory.create(opts); controllerUtils.startNetwork(w, $scope); diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 70d28a1ba..909fba68f 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -113,9 +113,15 @@ WalletFactory.prototype.create = function(opts) { opts = opts || {}; this.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID') + (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey')); - opts.privateKey = opts.privateKey || new PrivateKey({ - networkName: this.networkName - }); + var privOpts = { + networkName: this.networkName, + }; + + if (opts.privateKeyHex && opts.privateKeyHex.length>1) { + privOpts.extendedPrivateKeyString = opts.privateKeyHex; + } + + opts.privateKey = opts.privateKey || new PrivateKey(privOpts); var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers; var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers; @@ -216,7 +222,6 @@ WalletFactory.prototype.decodeSecret = function(secret) { WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, privateHex, cb) { -console.log('[WalletFactory.js.218:privateHex:]',privateHex); //TODO var self = this; var s = self.decodeSecret(secret); if (!s) return cb('badSecret'); @@ -229,7 +234,6 @@ console.log('[WalletFactory.js.218:privateHex:]',privateHex); //TODO privOpts.extendedPrivateKeyString = privateHex; } -console.log('[WalletFactory.js.229:privOpts:]',privOpts); //TODO //Create our PrivateK var privateKey = new PrivateKey(privOpts); this.log('\t### PrivateKey Initialized'); diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index 419d2ffcc..8581720f7 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -138,6 +138,27 @@ describe('WalletFactory model', function() { var w = wf.create(); should.exist(w); }); + + it('should be able to create wallets with given pk', function() { + var wf = new WalletFactory(config, '0.0.1'); + var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m'; + var w = wf.create({ + privateKeyHex:priv, + }); + w.privateKey.toObj().extendedPrivateKeyString.should.equal(priv); + }); + + it('should be able to create wallets with random pk', function() { + var wf = new WalletFactory(config, '0.0.1'); + var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m'; + var w1 = wf.create(); + var w2 = wf.create(); + w1.privateKey.toObj().extendedPrivateKeyString.should.not.equal( + w2.privateKey.toObj().extendedPrivateKeyString + ); + }); + + it('should be able to get wallets', function() { var wf = new WalletFactory(config, '0.0.1'); var w = wf.create(); diff --git a/views/setup.html b/views/setup.html index 6ad6d1e36..5a3c873ed 100644 --- a/views/setup.html +++ b/views/setup.html @@ -44,6 +44,21 @@ match="walletPassword" required> + + + Show + Hide + advanced options + +
+

+ +

+
@@ -68,7 +83,7 @@ width="50px">
-

(*) The limits are imposed by the bitcoin network.

+

(*) The limits are imposed by the bitcoin network.

« Back