Module witness_program

Module witness_program 

Source
Expand description

WitnessProgram

This module contains the representation of a Bitcoin witness program and utility functions related to the representation of such programs.

If the version byte is 0, and the witness program is 20 bytes:

  • It is interpreted as a pay-to-witness-public-key-hash (P2WPKH) program.
  • The witness must consist of exactly 2 items (≤ 520 bytes each). The first one a signature, and the second one a public key.
  • The HASH160 of the public key must match the 20-byte witness program.
  • After normal script evaluation, the signature is verified against the public key with CHECKSIG operation. The verification must result in a single TRUE on the stack.

If the version byte is 0, and the witness program is 32 bytes:

  • It is interpreted as a pay-to-witness-script-hash (P2WSH) program.
  • The witness must consist of an input stack to feed to the script, followed by a serialized script (witnessScript).
  • The witnessScript (≤ 10,000 bytes) is popped off the initial witness stack. SHA256 of the witnessScript must match the 32-byte witness program.
  • The witnessScript is deserialized, and executed after normal script evaluation with the remaining witness stack (≤ 520 bytes for each stack item).
  • The script must not fail, and result in exactly a single TRUE on the stack.

If the version byte is 0, but the witness program is neither 20 nor 32 bytes, the script must fail.

Structs§

WitnessProgram

Enums§

WitnessProgramError