0

After a transaction is serialised ready for signature or signature verification, a 4 byte hashTypeCode must be added (step 9 here). As it's derived from a single byte, it has 256 possible values.

What is the Hash Type Code?

1 Answer 1

0

Also known as SigHash, it is an instruction (in a transaction input) from a signer to a verifier to say "to get this to verify, you'll need to construct a transaction template like this." For each input in a transaction, a different hashtypeCode might be used.

It is defined in interpreter.h of the Bitcoin Core software:

/** Signature hash types/flags */
enum
{
    SIGHASH_ALL = 1,
    SIGHASH_NONE = 2,
    SIGHASH_SINGLE = 3,
    SIGHASH_ANYONECANPAY = 0x80,
};

From Raghav Sood:

SIGHASH_ANYONECANPAY is combined with the previous three via a bitwise & (effectively addition in this case), for a total of six possible values.

hashTypeCode hashTypeCode Identifier Tx fields used in signature
0x01 SIGHASH_ALL All inputs and outputs.
0x02 SIGHASH_NONE All inputs. No outputs.
0x03 SIGHASH_SINGLE All input. One output.
0x81 SIGHASH_ANYONECANPAY & SIGHASH_ALL One input. All outputs.
0x82 SIGHASH_ANYONECANPAY & SIGHASH_NONE One input. No outputs.
0x83 SIGHASH_ANYONECANPAY & SIGHASH_SINGLE One input and its corresponding output.

The procedure is described at bitcoin.it

See also: bitcoin.org

2
  • 1
    The sighash type is decided by the signer when spending an input, not the creator of an output, as it's part of the signature they produce. Commented May 4 at 11:56
  • @PieterWuille Thanks, I have some confusion around this atm... will update more as I figure it out
    – Lee
    Commented May 4 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.