Fixes typos: Matias's suggestions. Added more tests
This commit is contained in:
parent
2ad4aee2d6
commit
7cdf559fd7
3 changed files with 31 additions and 19 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -795,6 +795,9 @@ describe('Wallet model', function() {
|
|||
w.addressBook[key].hidden.should.equal(true);
|
||||
w.toggleAddressBookEntry(key);
|
||||
w.addressBook[key].hidden.should.equal(false);
|
||||
(function() {
|
||||
w.toggleAddressBookEntry();
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
it('handle network addressBook correctly', function() {
|
||||
|
|
@ -827,7 +830,7 @@ describe('Wallet model', function() {
|
|||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115
|
||||
};
|
||||
should.exist(w.signObject(payload));
|
||||
should.exist(w.signJson(payload));
|
||||
});
|
||||
|
||||
it('should verify signed object', function() {
|
||||
|
|
@ -838,7 +841,7 @@ describe('Wallet model', function() {
|
|||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115,
|
||||
};
|
||||
var signature = w.signObject(data);
|
||||
var signature = w.signJson(data);
|
||||
|
||||
w.verifySignedObject(data, signature).should.equal(true);
|
||||
data.label = 'Another';
|
||||
|
|
@ -860,13 +863,16 @@ describe('Wallet model', function() {
|
|||
createdTs: payload.createdTs,
|
||||
copayerId: payload.copayerId,
|
||||
label: payload.label,
|
||||
signature: w.signObject(payload)
|
||||
signature: w.signJson(payload)
|
||||
};
|
||||
w.addressBook[key] = addressbook;
|
||||
|
||||
w.verifySignAddressBook(key).should.equal(true);
|
||||
w.verfifyAddressbookSignature(key).should.equal(true);
|
||||
w.addressBook[key].label = 'Another';
|
||||
w.verifySignAddressBook(key).should.equal(false);
|
||||
w.verfifyAddressbookSignature(key).should.equal(false);
|
||||
(function() {
|
||||
w.verfifyAddressbookSignature();
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue