@@ -71,7 +71,7 @@ function expandInput (scriptSig, witnessStack) {
7171 var witnessProgram
7272 var chunks
7373
74- var scriptSigChunks = bscript . decompile ( scriptSig )
74+ var scriptSigChunks = bscript . decompile ( scriptSig ) || [ ]
7575 var sigType = btemplates . classifyInput ( scriptSigChunks , true )
7676 if ( sigType === scriptTypes . P2SH ) {
7777 p2sh = true
@@ -209,7 +209,7 @@ function fixMultisigOrder (input, transaction, vin) {
209209function expandOutput ( script , scriptType , ourPubKey ) {
210210 typeforce ( types . Buffer , script )
211211
212- var scriptChunks = bscript . decompile ( script )
212+ var scriptChunks = bscript . decompile ( script ) || [ ]
213213 if ( ! scriptType ) {
214214 scriptType = btemplates . classifyOutput ( script )
215215 }
@@ -257,17 +257,19 @@ function checkP2SHInput (input, redeemScriptHash) {
257257 if ( input . prevOutType ) {
258258 if ( input . prevOutType !== scriptTypes . P2SH ) throw new Error ( 'PrevOutScript must be P2SH' )
259259
260- var prevOutScriptScriptHash = bscript . decompile ( input . prevOutScript ) [ 1 ]
261- if ( ! prevOutScriptScriptHash . equals ( redeemScriptHash ) ) throw new Error ( 'Inconsistent hash160(redeemScript)' )
260+ var chunks = bscript . decompile ( input . prevOutScript )
261+ if ( ! chunks ) throw new Error ( 'Invalid prevOutScript' )
262+ if ( ! chunks [ 1 ] . equals ( redeemScriptHash ) ) throw new Error ( 'Inconsistent hash160(redeemScript)' )
262263 }
263264}
264265
265266function checkP2WSHInput ( input , witnessScriptHash ) {
266267 if ( input . prevOutType ) {
267268 if ( input . prevOutType !== scriptTypes . P2WSH ) throw new Error ( 'PrevOutScript must be P2WSH' )
268269
269- var scriptHash = bscript . decompile ( input . prevOutScript ) [ 1 ]
270- if ( ! scriptHash . equals ( witnessScriptHash ) ) throw new Error ( 'Inconsistent sha256(witnessScript)' )
270+ var chunks = bscript . decompile ( input . prevOutScript )
271+ if ( ! chunks ) throw new Error ( 'Invalid witnessScript' )
272+ if ( ! chunks [ 1 ] . equals ( witnessScriptHash ) ) throw new Error ( 'Inconsistent sha256(witnessScript)' )
271273 }
272274}
273275
0 commit comments