<p>Also known as SigHash, it is an instruction (in a transaction input) from a <em>signer</em> to a <em>verifier</em> to say &quot;to get this to verify, you'll need to construct a transaction template like this.&quot; For each input in a transaction, a different hashtypeCode might be used.</p>
<p>It is defined in <a href="https://github.com/bitcoin/bitcoin/blob/56f69360dc98bd68704f19646a84d045788d199e/src/script/interpreter.h#L22" rel="nofollow noreferrer">interpreter.h of the Bitcoin Core software</a>:</p>
<pre class="lang-cpp prettyprint-override"><code>/** Signature hash types/flags */
enum
{
    SIGHASH_ALL = 1,
    SIGHASH_NONE = 2,
    SIGHASH_SINGLE = 3,
    SIGHASH_ANYONECANPAY = 0x80,
};
</code></pre>
<p>From <a href="https://raghavsood.com/blog/2018/06/10/bitcoin-signature-types-sighash" rel="nofollow noreferrer">Raghav Sood</a>:</p>
<blockquote>
<p>SIGHASH_ANYONECANPAY is combined with the previous three via a bitwise
&amp; (effectively addition in this case), for a total of six possible
values.</p>
</blockquote>
<div class="s-table-container"><table class="s-table">
<thead>
<tr>
<th><code>hashTypeCode</code></th>
<th><code>hashTypeCode</code> Identifier</th>
<th>Tx fields used in signature</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>0x01</code></td>
<td><code>SIGHASH_ALL</code></td>
<td>All inputs and outputs.</td>
</tr>
<tr>
<td><code>0x02</code></td>
<td><code>SIGHASH_NONE </code></td>
<td>All inputs. No outputs.</td>
</tr>
<tr>
<td><code>0x03</code></td>
<td><code>SIGHASH_SINGLE </code></td>
<td>All input. One output.</td>
</tr>
<tr>
<td><code>0x81</code></td>
<td><code>SIGHASH_ANYONECANPAY &amp; SIGHASH_ALL</code></td>
<td>One input. All outputs.</td>
</tr>
<tr>
<td><code>0x82</code></td>
<td><code>SIGHASH_ANYONECANPAY &amp; SIGHASH_NONE</code></td>
<td>One input. No outputs.</td>
</tr>
<tr>
<td><code>0x83</code></td>
<td><code>SIGHASH_ANYONECANPAY &amp; SIGHASH_SINGLE</code></td>
<td>One input and its corresponding output.</td>
</tr>
</tbody>
</table></div>
<p>The procedure is described at <a href="https://en.bitcoin.it/wiki/OP_CHECKSIG" rel="nofollow noreferrer">bitcoin.it</a></p>
<p>See also:
<a href="https://developer.bitcoin.org/devguide/transactions.html#signature-hash-types" rel="nofollow noreferrer">bitcoin.org</a></p>

CC BY-SA 4.0
2024-05-04T11:56:41.337Z
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.
Pieter Wuille
CC BY-SA 4.0
2024-05-04T12:58:18.840Z
@PieterWuille Thanks, I have some confusion around this atm... will update more as I figure it out
Lee
CC BY-SA 4.0
2024-05-04T08:43:02.280Z
2024-05-04T12:56:35.440Z
2024-05-04T12:56:35.440Z
Lee
<p>After a transaction is serialised ready for signature or signature verification, a 4 byte <code>hashTypeCode</code> must be added (step 9 <a href="https://en.bitcoin.it/w/images/en/7/70/Bitcoin_OpCheckSig_InDetail.png" rel="nofollow noreferrer">here</a>). As it's derived from a single byte, it has <a href="https://bitcoin.stackexchange.com/a/96355/34190">256 possible values</a>.</p>
<p>What is the Hash Type Code?</p>

<transactions><signature><transaction-verification><verification><sighash-flags>
What is the hashTypeCode?
Lee
# What is the hashTypeCode?

(Asked by: username_0 on 2024-05-03)

After a transaction is serialised ready for signature or signature verification, a 4 byte `hashTypeCode` must be added (step 9 [here](https://en.bitcoin.it/w/images/en/7/70/Bitcoin_OpCheckSig_InDetail.png)). As it's derived from a single byte, it has [256 possible values](https://bitcoin.stackexchange.com/a/96355/34190).

What is the Hash Type Code?

**Tags:** transactions, signature, transaction-verification, verification, sighash-flags


---

## 1 answers

### Answer by username_0 on 2024-05-04. Score: 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

> **Comments:**
> **username_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.  
> **username_0**: @PieterWuille Thanks, I have some confusion around this atm... will update more as I figure it out  

---

