This commit is contained in:
Christopher Jeffrey 2016-07-21 05:27:42 -07:00
parent 253a6795a3
commit 9cc05a488a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 20 additions and 7 deletions

View File

@ -164,14 +164,8 @@ BIP151.prototype.toEncack = function toEncack(writer) {
BIP151.prototype.encack = function encack(data) { BIP151.prototype.encack = function encack(data) {
var p = bcoin.reader(data); var p = bcoin.reader(data);
var publicKey = p.readBytes(33); var publicKey = p.readBytes(33);
var i;
for (i = 0; i < publicKey.length; i++) { if (utils.isZero(publicKey)) {
if (publicKey[i] !== 0)
break;
}
if (i === publicKey.length) {
this.rekey(); this.rekey();
return; return;
} }

View File

@ -1741,6 +1741,25 @@ utils.sizeVarint2 = function sizeVarint2(num) {
return size; return size;
}; };
/**
* Test whether a buffer is all zeroes.
* @param {Buffer} data
* @returns {Boolean}
*/
utils.isZero = function isZero(data) {
var i;
assert(Buffer.isBuffer(data));
for (i = 0; i < data.length; i++) {
if (data[i] !== 0)
return false;
}
return true;
};
/** /**
* Buffer comparator (memcmp + length comparison). * Buffer comparator (memcmp + length comparison).
* @param {Buffer} a * @param {Buffer} a