Fixes typos: Matias's suggestions. Added more tests

This commit is contained in:
Gustavo Cortez 2014-07-07 10:58:43 -03:00
commit 7cdf559fd7
3 changed files with 31 additions and 19 deletions

View file

@ -186,15 +186,15 @@ angular.module('copayApp.controllers').controller('SendController',
}, 500);
};
$scope.signAddressBook = {};
$scope.addressbook = {};
$scope.checkSignAddressBook = function(key) {
$scope.verifyAddressbookSignature = function(key) {
if (key) {
$timeout(function() {
var w = $rootScope.wallet;
var sign = w.verifySignAddressBook(key);
$scope.signAddressBook[key] = sign;
if (!sign) {
var signature = w.verfifyAddressbookSignature(key);
$scope.addressbook[key] = signature;
if (!signature) {
notification.error('Wrong signature', 'Entry of Addressbooks was deleted');
}
}, 10);
@ -253,7 +253,7 @@ angular.module('copayApp.controllers').controller('SendController',
if (errorMsg) {
notification.error('Error', errorMsg);
} else {
$scope.checkSignAddressBook(entry.address);
$scope.verifyAddressbookSignature(entry.address);
notification.success('Success', 'New entry has been created');
}
$rootScope.$digest();

View file

@ -840,19 +840,19 @@ Wallet.prototype.setAddressBook = function(key, label) {
copayerId: copayerId,
createdTs: ts
};
var addressbook = {
var newEntry = {
hidden: false,
createdTs: ts,
copayerId: copayerId,
label: label,
signature: this.signObject(payload)
signature: this.signJson(payload)
};
this.addressBook[key] = addressbook;
this.addressBook[key] = newEntry;
this.sendAddressBook();
this.store();
};
Wallet.prototype.verifySignAddressBook = function(key) {
Wallet.prototype.verfifyAddressbookSignature = function(key) {
if (key) {
var signature = this.addressBook[key].signature;
var payload = {
@ -861,13 +861,16 @@ Wallet.prototype.verifySignAddressBook = function(key) {
copayerId: this.addressBook[key].copayerId,
createdTs: this.addressBook[key].createdTs
};
var sign = this.verifySignedObject(payload, signature);
if (!sign) {
var isVerified = this.verifySignedObject(payload, signature);
if (!isVerified) {
// remove wrong signed entry
delete this.addressBook[key];
this.store();
}
return sign;
return isVerified;
}
else {
throw new Error('Key is required');
}
}
@ -876,6 +879,9 @@ Wallet.prototype.toggleAddressBookEntry = function(key) {
this.addressBook[key].hidden = !this.addressBook[key].hidden;
this.store();
}
else {
throw new Error('Key is required');
}
};
Wallet.prototype.isReady = function() {
@ -888,7 +894,7 @@ Wallet.prototype.offerBackup = function() {
this.store();
};
Wallet.prototype.signObject = function(payload) {
Wallet.prototype.signJson = function(payload) {
var key = new bitcore.Key();
key.private = new Buffer(this.getMyCopayerIdPriv(), 'hex');
key.regenerateSync();