add test and adv opts to create

This commit is contained in:
Matias Alejo Garcia 2014-08-21 14:54:36 -04:00
parent dd724a6135
commit 291ed73916
5 changed files with 49 additions and 7 deletions

View File

@ -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')

View File

@ -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);

View File

@ -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');

View File

@ -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();

View File

@ -44,6 +44,21 @@
match="walletPassword"
required>
</div>
<a class="expand small" ng-click="hideAdv=!hideAdv">
<span ng-hide="!hideAdv">Show</span>
<span ng-hide="hideAdv">Hide</span>
advanced options
</a>
<div ng-hide="hideAdv">
<p>
<input type="text"
placeholder="Private Key (Hex)"
name="private"
ng-model="private"
>
</div>
</div>
<div class="row" ng-show="!isSetupWalletPage">
<div class="large-6 medium-6 columns">
@ -68,7 +83,7 @@
width="50px">
</div>
</div>
<p class="comment" ng-show="totalCopayers>1">(*) The limits are imposed by the bitcoin network.</p>
<p class="comment" ng-show="totalCopayers>1 && !isSetupWalletPage">(*) The limits are imposed by the bitcoin network.</p>
<div class="text-right">
<a ng-show="!isSetupWalletPage" class="back-button m20r" href="#!/">&laquo; Back</a>
<a ng-show="isSetupWalletPage" class="back-button m20r"