diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 00bda3b4..c68b91f4 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -1913,8 +1913,9 @@ Script.num = function num(value, flags, size) { // 0x80, remove it from the result's msb and return // a negative. if (value[value.length - 1] & 0x80) { - n = new bn(0x80).ushln(8 * (value.length - 1)).notn(64); - return result.uand(n).neg(); + // n = new bn(0x80).ushln(8 * (value.length - 1)).notn(64); + // return result.uand(n).neg(); + result.setn((value.length * 8) - 1, 0).ineg(); } return result; @@ -1962,8 +1963,20 @@ Script.array = function(value) { // interpreted as a negative when // converting to an integral. + // neg = value.cmpn(0) < 0; + // if (value.testn((value.byteLength() * 8) - 1)) { + // result = value.toArray('le'); + // result.push(neg ? 0x80 : 0); + // return new Buffer(result); + // } + // result = value.toBuffer('le'); + // if (neg) + // result[result.length - 1] |= 0x80; + // return result; + neg = value.cmpn(0) < 0; result = value.toArray('le'); + if (result[result.length - 1] & 0x80) result.push(neg ? 0x80 : 0); else if (neg)