@@ -462,13 +462,17 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
462462
463463 var input = this . inputs [ vin ]
464464
465- // if redeemScript was provided, enforce consistency
466- if ( input . redeemScript !== undefined && redeemScript ) {
467- if ( ! input . redeemScript . equals ( redeemScript ) ) throw new Error ( 'Inconsistent redeemScript' )
465+ // if redeemScript was previously provided, enforce consistency
466+ if ( input . redeemScript !== undefined &&
467+ redeemScript &&
468+ ! input . redeemScript . equals ( redeemScript ) ) {
469+ throw new Error ( 'Inconsistent redeemScript' )
468470 }
469471
470- if ( input . hashType !== undefined ) {
471- if ( input . hashType !== hashType ) throw new Error ( 'Inconsistent hashType' )
472+ // if hashType was previously provided, enforce consistency
473+ if ( input . hashType !== undefined &&
474+ input . hashType !== hashType ) {
475+ throw new Error ( 'Inconsistent hashType' )
472476 }
473477
474478 var kpPubKey = keyPair . getPublicKeyBuffer ( )
@@ -483,15 +487,15 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
483487 var signatureHash = this . tx . hashForSignature ( vin , hashScript , hashType )
484488
485489 // enforce in order signing of public keys
486- var valid = input . pubKeys . some ( function ( pubKey , i ) {
490+ var signed = input . pubKeys . some ( function ( pubKey , i ) {
487491 if ( ! kpPubKey . equals ( pubKey ) ) return false
488492 if ( input . signatures [ i ] ) throw new Error ( 'Signature already exists' )
489493
490494 input . signatures [ i ] = keyPair . sign ( signatureHash )
491495 return true
492496 } )
493497
494- if ( ! valid ) throw new Error ( 'Key pair cannot sign for this input' )
498+ if ( ! signed ) throw new Error ( 'Key pair cannot sign for this input' )
495499}
496500
497501TransactionBuilder . prototype . __canModifyInputs = function ( ) {
0 commit comments