ECSignature: remove use of assert
This commit is contained in:
parent
f2f0747187
commit
c1a965d096
1 changed files with 7 additions and 10 deletions
|
@ -1,4 +1,3 @@
|
||||||
var assert = require('assert')
|
|
||||||
var typeforce = require('typeforce')
|
var typeforce = require('typeforce')
|
||||||
var types = require('./types')
|
var types = require('./types')
|
||||||
|
|
||||||
|
@ -13,22 +12,20 @@ function ECSignature (r, s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ECSignature.parseCompact = function (buffer) {
|
ECSignature.parseCompact = function (buffer) {
|
||||||
assert.equal(buffer.length, 65, 'Invalid signature length')
|
if (buffer.length !== 65) throw new Error('Invalid signature length')
|
||||||
var i = buffer.readUInt8(0) - 27
|
|
||||||
|
|
||||||
// At most 3 bits
|
var flagByte = buffer.readUInt8(0) - 27
|
||||||
assert.equal(i, i & 7, 'Invalid signature parameter')
|
if (flagByte !== (flagByte & 7)) throw new Error('Invalid signature parameter')
|
||||||
var compressed = !!(i & 4)
|
|
||||||
|
|
||||||
// Recovery param only
|
var compressed = !!(flagByte & 4)
|
||||||
i = i & 3
|
var recoveryParam = flagByte & 3
|
||||||
|
|
||||||
var r = BigInteger.fromBuffer(buffer.slice(1, 33))
|
var r = BigInteger.fromBuffer(buffer.slice(1, 33))
|
||||||
var s = BigInteger.fromBuffer(buffer.slice(33))
|
var s = BigInteger.fromBuffer(buffer.slice(33))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
compressed: compressed,
|
compressed: compressed,
|
||||||
i: i,
|
i: recoveryParam,
|
||||||
signature: new ECSignature(r, s)
|
signature: new ECSignature(r, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +115,7 @@ ECSignature.prototype.toDER = function () {
|
||||||
|
|
||||||
ECSignature.prototype.toScriptSignature = function (hashType) {
|
ECSignature.prototype.toScriptSignature = function (hashType) {
|
||||||
var hashTypeMod = hashType & ~0x80
|
var hashTypeMod = hashType & ~0x80
|
||||||
assert(hashTypeMod > 0x00 && hashTypeMod < 0x04, 'Invalid hashType ' + hashType)
|
if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType)
|
||||||
|
|
||||||
var hashTypeBuffer = new Buffer(1)
|
var hashTypeBuffer = new Buffer(1)
|
||||||
hashTypeBuffer.writeUInt8(hashType, 0)
|
hashTypeBuffer.writeUInt8(hashType, 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue