mirror of https://github.com/BTCPrivate/copay.git
fix test 8
This commit is contained in:
parent
ed7916f1be
commit
372d230e17
|
@ -179,22 +179,28 @@ Network.prototype.iterateNonce = function() {
|
||||||
return this.networkNonce;
|
return this.networkNonce;
|
||||||
};
|
};
|
||||||
|
|
||||||
Network.prototype._onMessage = function(enc) {
|
Network.prototype.decode = function(enc) {
|
||||||
|
var sender = enc.pubkey;
|
||||||
var key = this.getKey();
|
var key = this.getKey();
|
||||||
|
var prevnonce = this.networkNonces ? this.networkNonces[sender] : undefined;
|
||||||
|
var opts = {
|
||||||
|
prevnonce: prevnonce
|
||||||
|
};
|
||||||
|
var decoded = AuthMessage.decode(key, enc, opts);
|
||||||
|
|
||||||
|
//if no error thrown in the last step, we can set the copayer's nonce
|
||||||
|
if (!this.networkNonces)
|
||||||
|
this.networkNonces = {};
|
||||||
|
this.networkNonces[sender] = decoded.nonce;
|
||||||
|
|
||||||
|
var payload = decoded.payload;
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
|
||||||
|
Network.prototype._onMessage = function(enc) {
|
||||||
var sender = enc.pubkey;
|
var sender = enc.pubkey;
|
||||||
try {
|
try {
|
||||||
var prevnonce = this.networkNonces ? this.networkNonces[sender] : undefined;
|
var payload = this.decode(enc);
|
||||||
var opts = {
|
|
||||||
prevnonce: prevnonce
|
|
||||||
};
|
|
||||||
var decoded = AuthMessage.decode(key, enc, opts);
|
|
||||||
|
|
||||||
//if no error thrown in the last step, we can set the copayer's nonce
|
|
||||||
if (!this.networkNonces)
|
|
||||||
this.networkNonces = {};
|
|
||||||
this.networkNonces[sender] = decoded.nonce;
|
|
||||||
|
|
||||||
var payload = decoded.payload;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._deletePeer(sender);
|
this._deletePeer(sender);
|
||||||
return;
|
return;
|
||||||
|
@ -359,18 +365,22 @@ Network.prototype.send = function(copayerIds, payload, cb) {
|
||||||
//console.log('sending ' + JSON.stringify(payload));
|
//console.log('sending ' + JSON.stringify(payload));
|
||||||
copayerIds.forEach(function(copayerId) {
|
copayerIds.forEach(function(copayerId) {
|
||||||
//console.log('\t to ' + copayerId);
|
//console.log('\t to ' + copayerId);
|
||||||
self.iterateNonce();
|
var message = self.encode(copayerId, payload);
|
||||||
var opts = {
|
|
||||||
nonce: self.networkNonce
|
|
||||||
};
|
|
||||||
var copayerIdBuf = new Buffer(copayerId, 'hex');
|
|
||||||
var message = AuthMessage.encode(copayerIdBuf, self.getKey(), payload, opts);
|
|
||||||
self.socket.emit('message', message);
|
self.socket.emit('message', message);
|
||||||
});
|
});
|
||||||
if (typeof cb === 'function') cb();
|
if (typeof cb === 'function') cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Network.prototype.encode = function(copayerId, payload) {
|
||||||
|
this.iterateNonce();
|
||||||
|
var opts = {
|
||||||
|
nonce: this.networkNonce
|
||||||
|
};
|
||||||
|
var copayerIdBuf = new Buffer(copayerId, 'hex');
|
||||||
|
var message = AuthMessage.encode(copayerIdBuf, this.getKey(), payload, opts);
|
||||||
|
};
|
||||||
|
|
||||||
Network.prototype.isOnline = function() {
|
Network.prototype.isOnline = function() {
|
||||||
return !!this.socket;
|
return !!this.socket;
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,6 +127,7 @@ describe('Network / Async', function() {
|
||||||
it('should not reject data sent from a peer with hijacked pubkey', function() {
|
it('should not reject data sent from a peer with hijacked pubkey', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
|
n.key = null;
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
type: 'hello',
|
type: 'hello',
|
||||||
|
@ -151,6 +152,7 @@ describe('Network / Async', function() {
|
||||||
it('should reject data sent from a peer with hijacked pubkey', function() {
|
it('should reject data sent from a peer with hijacked pubkey', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
|
n.key = null;
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
type: 'hello',
|
type: 'hello',
|
||||||
|
@ -177,8 +179,7 @@ describe('Network / Async', function() {
|
||||||
it('should not reject data sent from a peer with no previously set nonce but who is setting one now', function() {
|
it('should not reject data sent from a peer with no previously set nonce but who is setting one now', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
//n.networkNonces = {};
|
n.key = null;
|
||||||
//n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('0000000000000001', 'hex'); //previously used nonce
|
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
type: 'hello',
|
type: 'hello',
|
||||||
|
@ -207,6 +208,7 @@ describe('Network / Async', function() {
|
||||||
it('should not reject data sent from a peer with a really big new nonce', function() {
|
it('should not reject data sent from a peer with a really big new nonce', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
|
n.key = null;
|
||||||
n.networkNonces = {};
|
n.networkNonces = {};
|
||||||
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('5000000000000001', 'hex'); //previously used nonce
|
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('5000000000000001', 'hex'); //previously used nonce
|
||||||
|
|
||||||
|
@ -236,6 +238,7 @@ describe('Network / Async', function() {
|
||||||
it('should not reject data sent from a peer with a really big new nonce', function() {
|
it('should not reject data sent from a peer with a really big new nonce', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
|
n.key = false;
|
||||||
n.networkNonces = {};
|
n.networkNonces = {};
|
||||||
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('5000000000000001', 'hex'); //previously used nonce
|
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('5000000000000001', 'hex'); //previously used nonce
|
||||||
|
|
||||||
|
@ -265,6 +268,7 @@ describe('Network / Async', function() {
|
||||||
it('should reject data sent from a peer with an outdated nonce', function() {
|
it('should reject data sent from a peer with an outdated nonce', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
|
n.key = null;
|
||||||
n.networkNonces = {};
|
n.networkNonces = {};
|
||||||
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('0000000000000002', 'hex'); //previously used nonce
|
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('0000000000000002', 'hex'); //previously used nonce
|
||||||
|
|
||||||
|
@ -294,6 +298,7 @@ describe('Network / Async', function() {
|
||||||
it('should reject data sent from a peer with a really big outdated nonce', function() {
|
it('should reject data sent from a peer with a really big outdated nonce', function() {
|
||||||
var n = createN();
|
var n = createN();
|
||||||
n.privkey = key2.private.toString('hex');
|
n.privkey = key2.private.toString('hex');
|
||||||
|
n.key = null;
|
||||||
n.networkNonces = {};
|
n.networkNonces = {};
|
||||||
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('5000000000000002', 'hex'); //previously used nonce
|
n.networkNonces[(new bitcore.SIN(key1.public)).toString()] = new Buffer('5000000000000002', 'hex'); //previously used nonce
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue