Fixes: verify addressbook method

This commit is contained in:
Gustavo Cortez 2014-07-07 17:38:17 -03:00
commit 0931024e23
4 changed files with 33 additions and 29 deletions

View file

@ -14,7 +14,7 @@ angular.module('copayApp.controllers').controller('SendController',
var flag;
if (w) {
for (var k in w.addressBook) {
if (w.addressBook[k].copayerId != -1) {
if (w.addressBook[k]) {
flag = true;
break;
}
@ -186,16 +186,6 @@ angular.module('copayApp.controllers').controller('SendController',
}, 500);
};
$scope.verifyAddressbookSignature = function(key) {
$timeout(function() {
var w = $rootScope.wallet;
var isValid = w.verfifyAddressbookSignature(key);
if (!isValid) {
notification.error('Wrong signature', 'Entry of Addressbooks was deleted');
}
}, 10);
};
$scope.toggleAddressBookEntry = function(key) {
var w = $rootScope.wallet;
w.toggleAddressBookEntry(key);
@ -246,7 +236,6 @@ angular.module('copayApp.controllers').controller('SendController',
if (errorMsg) {
notification.error('Error', errorMsg);
} else {
$scope.verifyAddressbookSignature(entry.address);
notification.success('Success', 'New entry has been created');
}
$rootScope.$digest();

View file

@ -145,6 +145,7 @@ Wallet.prototype._handleAddressBook = function(senderId, data, isInbound) {
for (var key in rcv) {
if (!this.addressBook[key]) {
this.addressBook[key] = rcv[key];
var isVerified = this.verifyAddressbookSignature(senderId, key);
hasChange = true;
}
}
@ -852,8 +853,8 @@ Wallet.prototype.setAddressBook = function(key, label) {
this.store();
};
Wallet.prototype.verfifyAddressbookSignature = function(key) {
if (!key) throw new Error('Key is required');
Wallet.prototype.verifyAddressbookSignature = function(senderId, key) {
if (!key) throw new Error('Keys are required');
var signature = this.addressBook[key].signature;
var payload = {
address: key,
@ -861,7 +862,7 @@ Wallet.prototype.verfifyAddressbookSignature = function(key) {
copayerId: this.addressBook[key].copayerId,
createdTs: this.addressBook[key].createdTs
};
var isVerified = this.verifySignedObject(payload, signature);
var isVerified = this.verifySignedJson(senderId, payload, signature);
if (!isVerified) {
// remove wrong signed entry
delete this.addressBook[key];
@ -894,8 +895,8 @@ Wallet.prototype.signJson = function(payload) {
return sign.toString('hex');
}
Wallet.prototype.verifySignedObject = function(payload, signature) {
var pubkey = new Buffer(this.getMyCopayerId(), 'hex');
Wallet.prototype.verifySignedJson = function(senderId, payload, signature) {
var pubkey = new Buffer(senderId, 'hex');
var sign = new Buffer(signature, 'hex');
var v = bitcore.Message.verifyWithPubKey(pubkey, JSON.stringify(payload), sign);
return v;