From 0ff5bd569887f5ecfc7a8b184a3fa89e91b61ebc Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sat, 22 Aug 2015 12:31:00 +1000 Subject: [PATCH] script: add isDefinedHashType to check hashType --- src/script.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/script.js b/src/script.js index 783c5da..f4f096c 100644 --- a/src/script.js +++ b/src/script.js @@ -134,10 +134,18 @@ function isCanonicalPubKey (buffer) { function isCanonicalSignature (buffer) { if (!Buffer.isBuffer(buffer)) return false + if (!isDefinedHashType(buffer[buffer.length - 1])) return false return bip66.check(buffer.slice(0, -1)) } +function isDefinedHashType (hashType) { + var hashTypeMod = hashType & ~0x80 + +// return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE + return hashTypeMod > 0x00 && hashTypeMod < 0x04 +} + function isPubKeyHashInput (script) { var chunks = decompile(script) @@ -369,6 +377,7 @@ module.exports = { isCanonicalPubKey: isCanonicalPubKey, isCanonicalSignature: isCanonicalSignature, + isDefinedHashType: isDefinedHashType, isPubKeyHashInput: isPubKeyHashInput, isPubKeyHashOutput: isPubKeyHashOutput, isPubKeyInput: isPubKeyInput,