utils.
This commit is contained in:
parent
253a6795a3
commit
9cc05a488a
@ -164,14 +164,8 @@ BIP151.prototype.toEncack = function toEncack(writer) {
|
||||
BIP151.prototype.encack = function encack(data) {
|
||||
var p = bcoin.reader(data);
|
||||
var publicKey = p.readBytes(33);
|
||||
var i;
|
||||
|
||||
for (i = 0; i < publicKey.length; i++) {
|
||||
if (publicKey[i] !== 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i === publicKey.length) {
|
||||
if (utils.isZero(publicKey)) {
|
||||
this.rekey();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1741,6 +1741,25 @@ utils.sizeVarint2 = function sizeVarint2(num) {
|
||||
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).
|
||||
* @param {Buffer} a
|
||||
|
||||
Loading…
Reference in New Issue
Block a user