* Verify an input and output script, and a witness if present. * @param {Script} input * @param {Witness} witness * @param {Script} output * @param {TX} tx * @param {Number} index * @param {Amount} value * @param {VerifyFlags} flags * @throws {ScriptError}
(input, witness, output, tx, index, value, flags)
| 3093 | */ |
| 3094 | |
| 3095 | static verify(input, witness, output, tx, index, value, flags) { |
| 3096 | if (flags == null) |
| 3097 | flags = Script.flags.STANDARD_VERIFY_FLAGS; |
| 3098 | |
| 3099 | if (flags & Script.flags.VERIFY_SIGPUSHONLY) { |
| 3100 | if (!input.isPushOnly()) |
| 3101 | throw new ScriptError('SIG_PUSHONLY'); |
| 3102 | } |
| 3103 | |
| 3104 | // Setup a stack. |
| 3105 | let stack = new Stack(); |
| 3106 | |
| 3107 | // Execute the input script |
| 3108 | input.execute(stack, flags, tx, index, value, 0); |
| 3109 | |
| 3110 | // Copy the stack for P2SH |
| 3111 | let copy; |
| 3112 | if (flags & Script.flags.VERIFY_P2SH) |
| 3113 | copy = stack.clone(); |
| 3114 | |
| 3115 | // Execute the previous output script. |
| 3116 | output.execute(stack, flags, tx, index, value, 0); |
| 3117 | |
| 3118 | // Verify the stack values. |
| 3119 | if (stack.length === 0 || !stack.getBool(-1)) |
| 3120 | throw new ScriptError('EVAL_FALSE'); |
| 3121 | |
| 3122 | let hadWitness = false; |
| 3123 | |
| 3124 | if ((flags & Script.flags.VERIFY_WITNESS) && output.isProgram()) { |
| 3125 | hadWitness = true; |
| 3126 | |
| 3127 | // Input script must be empty. |
| 3128 | if (input.raw.length !== 0) |
| 3129 | throw new ScriptError('WITNESS_MALLEATED'); |
| 3130 | |
| 3131 | // Verify the program in the output script. |
| 3132 | Script.verifyProgram(witness, output, flags, tx, index, value); |
| 3133 | |
| 3134 | // Force a cleanstack |
| 3135 | stack.length = 1; |
| 3136 | } |
| 3137 | |
| 3138 | // If the script is P2SH, execute the real output script |
| 3139 | if ((flags & Script.flags.VERIFY_P2SH) && output.isScripthash()) { |
| 3140 | // P2SH can only have push ops in the scriptSig |
| 3141 | if (!input.isPushOnly()) |
| 3142 | throw new ScriptError('SIG_PUSHONLY'); |
| 3143 | |
| 3144 | // Reset the stack |
| 3145 | stack = copy; |
| 3146 | |
| 3147 | // Stack should not be empty at this point |
| 3148 | if (stack.length === 0) |
| 3149 | throw new ScriptError('EVAL_FALSE'); |
| 3150 | |
| 3151 | // Grab the real redeem script |
| 3152 | const raw = stack.pop(); |
nothing calls this directly
no test coverage detected