Skip to content

Commit 0ff5bd5

Browse files
committed
script: add isDefinedHashType to check hashType
1 parent 86b2cf7 commit 0ff5bd5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/script.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,18 @@ function isCanonicalPubKey (buffer) {
134134

135135
function isCanonicalSignature (buffer) {
136136
if (!Buffer.isBuffer(buffer)) return false
137+
if (!isDefinedHashType(buffer[buffer.length - 1])) return false
137138

138139
return bip66.check(buffer.slice(0, -1))
139140
}
140141

142+
function isDefinedHashType (hashType) {
143+
var hashTypeMod = hashType & ~0x80
144+
145+
// return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE
146+
return hashTypeMod > 0x00 && hashTypeMod < 0x04
147+
}
148+
141149
function isPubKeyHashInput (script) {
142150
var chunks = decompile(script)
143151

@@ -369,6 +377,7 @@ module.exports = {
369377

370378
isCanonicalPubKey: isCanonicalPubKey,
371379
isCanonicalSignature: isCanonicalSignature,
380+
isDefinedHashType: isDefinedHashType,
372381
isPubKeyHashInput: isPubKeyHashInput,
373382
isPubKeyHashOutput: isPubKeyHashOutput,
374383
isPubKeyInput: isPubKeyInput,

0 commit comments

Comments
 (0)