Merge pull request #356 from bitcoinjs/htenforce
ECSignature: enforce valid hashType in toScriptSignature
This commit is contained in:
commit
f8b9a5f2c3
3 changed files with 40 additions and 4 deletions
|
@ -68,12 +68,12 @@ ECSignature.fromDER = function(buffer) {
|
|||
return new ECSignature(r, s)
|
||||
}
|
||||
|
||||
// FIXME: 0x00, 0x04, 0x80 are SIGHASH_* boundary constants, importing Transaction causes a circular dependency
|
||||
// BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed)
|
||||
ECSignature.parseScriptSignature = function(buffer) {
|
||||
var hashType = buffer.readUInt8(buffer.length - 1)
|
||||
var hashTypeMod = hashType & ~0x80
|
||||
|
||||
assert(hashTypeMod > 0x00 && hashTypeMod < 0x04, 'Invalid hashType')
|
||||
assert(hashTypeMod > 0x00 && hashTypeMod < 0x04, 'Invalid hashType ' + hashType)
|
||||
|
||||
return {
|
||||
signature: ECSignature.fromDER(buffer.slice(0, -1)),
|
||||
|
@ -115,6 +115,9 @@ ECSignature.prototype.toDER = function() {
|
|||
}
|
||||
|
||||
ECSignature.prototype.toScriptSignature = function(hashType) {
|
||||
var hashTypeMod = hashType & ~0x80
|
||||
assert(hashTypeMod > 0x00 && hashTypeMod < 0x04, 'Invalid hashType ' + hashType)
|
||||
|
||||
var hashTypeBuffer = new Buffer(1)
|
||||
hashTypeBuffer.writeUInt8(hashType, 0)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue