Returns whether the input has a valid signature
(self, input_index)
| 300 | return int.from_bytes(hash256(s), 'big') |
| 301 | |
| 302 | def verify_input(self, input_index): |
| 303 | '''Returns whether the input has a valid signature''' |
| 304 | # get the relevant input |
| 305 | tx_in = self.tx_ins[input_index] |
| 306 | # grab the previous ScriptPubKey |
| 307 | script_pubkey = tx_in.script_pubkey(testnet=self.testnet) |
| 308 | # check to see if the ScriptPubkey is a p2sh |
| 309 | if script_pubkey.is_p2sh_script_pubkey(): |
| 310 | # the last cmd has to be the RedeemScript to trigger |
| 311 | cmd = tx_in.script_sig.cmds[-1] |
| 312 | # parse the RedeemScript |
| 313 | raw_redeem = int_to_little_endian(len(cmd), 1) + cmd |
| 314 | redeem_script = Script.parse(BytesIO(raw_redeem)) |
| 315 | # the RedeemScript might be p2wpkh or p2wsh |
| 316 | if redeem_script.is_p2wpkh_script_pubkey(): |
| 317 | z = self.sig_hash_bip143(input_index, redeem_script) |
| 318 | witness = tx_in.witness |
| 319 | elif redeem_script.is_p2wsh_script_pubkey(): |
| 320 | cmd = tx_in.witness[-1] |
| 321 | raw_witness = encode_varint(len(cmd)) + cmd |
| 322 | witness_script = Script.parse(BytesIO(raw_witness)) |
| 323 | z = self.sig_hash_bip143(input_index, witness_script=witness_script) |
| 324 | witness = tx_in.witness |
| 325 | else: |
| 326 | z = self.sig_hash(input_index, redeem_script) |
| 327 | witness = None |
| 328 | else: |
| 329 | # ScriptPubkey might be a p2wpkh or p2wsh |
| 330 | if script_pubkey.is_p2wpkh_script_pubkey(): |
| 331 | z = self.sig_hash_bip143(input_index) |
| 332 | witness = tx_in.witness |
| 333 | elif script_pubkey.is_p2wsh_script_pubkey(): |
| 334 | cmd = tx_in.witness[-1] |
| 335 | raw_witness = encode_varint(len(cmd)) + cmd |
| 336 | witness_script = Script.parse(BytesIO(raw_witness)) |
| 337 | z = self.sig_hash_bip143(input_index, witness_script=witness_script) |
| 338 | witness = tx_in.witness |
| 339 | else: |
| 340 | z = self.sig_hash(input_index) |
| 341 | witness = None |
| 342 | # combine the current ScriptSig and the previous ScriptPubKey |
| 343 | combined = tx_in.script_sig + script_pubkey |
| 344 | # evaluate the combined script |
| 345 | return combined.evaluate(z, witness) |
| 346 | |
| 347 | def verify(self): |
| 348 | '''Verify this transaction''' |
no test coverage detected