scripts: ensure isPubKeyHashOutput/isScriptHashOutput adhere to BIP62

This commit is contained in:
Daniel Cousens 2015-09-29 18:55:33 +10:00
parent 50f381fb5c
commit f60cb2e491

View file

@ -156,15 +156,14 @@ function isPubKeyHashInput (script) {
} }
function isPubKeyHashOutput (script) { function isPubKeyHashOutput (script) {
var chunks = decompile(script) var buffer = compile(script)
return chunks.length === 5 && return buffer.length === 25 &&
chunks[0] === OPS.OP_DUP && buffer[0] === OPS.OP_DUP &&
chunks[1] === OPS.OP_HASH160 && buffer[1] === OPS.OP_HASH160 &&
Buffer.isBuffer(chunks[2]) && buffer[2] === 0x14 &&
chunks[2].length === 20 && buffer[23] === OPS.OP_EQUALVERIFY &&
chunks[3] === OPS.OP_EQUALVERIFY && buffer[24] === OPS.OP_CHECKSIG
chunks[4] === OPS.OP_CHECKSIG
} }
function isPubKeyInput (script) { function isPubKeyInput (script) {
@ -199,13 +198,12 @@ function isScriptHashInput (script, allowIncomplete) {
} }
function isScriptHashOutput (script) { function isScriptHashOutput (script) {
var chunks = decompile(script) var buffer = compile(script)
return chunks.length === 3 && return buffer.length === 23 &&
chunks[0] === OPS.OP_HASH160 && buffer[0] === OPS.OP_HASH160 &&
Buffer.isBuffer(chunks[1]) && buffer[1] === 0x14 &&
chunks[1].length === 20 && buffer[22] === OPS.OP_EQUAL
chunks[2] === OPS.OP_EQUAL
} }
// allowIncomplete is to account for combining signatures // allowIncomplete is to account for combining signatures