Understanding Bitcoin Transaction Flags
When working with Bitcoin transactions, a special flag is used to indicate the hashing method used. This flag is commonly called “hashTypeCode” or “sighash”. In this article, we will look at what these flags mean and provide examples of the different types of byte arrays.
1. hashTypeCode = 0x01
The “hashTypeCode” flag indicates that the transaction was signed with a specific hashing method using the ECDSA (Elliptic Curve Digital Signature Algorithm) algorithm. This means that the transaction hash is based on the private key associated with the sender.
uint8_t txHash[32];
txHash[0] = 0x00;
// ... other hash values ...
In a randomly selected transaction, we can use the following byte array:
tx_hash = [0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10]
2. hashTypeCode = 0x02
The “sighash” flag indicates that the transaction was signed using a specific hashing method without providing the private key (i.e., it is a blind signature). This is also called a “blind signature”.
uint8_t sigHash[32];
sigHash[0] = 0x00; // signature type
// ... other hash values ...
In a randomly selected transaction, we can use the following byte array:
sig_hash = [0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09]
3. hashTypeCode = 0x11
The “hashTypeCode” flag indicates that the transaction was signed using a specific hashing method, where the public key is known and was used to calculate the hash.
uint8_t pubKeyHash[32];
pubKeyHash[0] = 0x00;
// ... other hash values ...
In a randomly selected transaction, we can use the following byte array:
pub_key_hash = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
4. hashTypeCode = 0x12
The “sighash” flag indicates that the transaction was signed using a specific hashing method, where the public key is unknown and was used to calculate the hash.
uint8_t pubKeyHash[32];
pubKeyHash[0] = 0x00;
// ... other hash values ...
For a randomly selected transaction, we can use the following byte array:
pub_key_hash = [0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17]
These examples show how to represent different types of Bitcoin transactions and their corresponding hashing methods using byte arrays. Keep in mind that the actual implementation may vary depending on the specific requirements and constraints of your application.
Example use case:
Let’s say you are building a Bitcoin-based cryptocurrency trading platform. You want to handle transactions using different hashing methods (ECDSA, blind signature, etc.). Using this knowledge, you can create efficient and secure transaction processing logic for both confirmed and unconfirmed transactions.
def process_transaction(transaction):
![Bitcoin: hashTypeCode/sighash flag example byte arrays for each type](https://fisacoffee.com/wp-content/uploads/2025/02/f29209e1.png)
Define byte arrays for each hash methodtx_hash = [0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10]
sig_hash = [0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09]
Execute transaction processing logic based on hash methodif transaction.prev_hash is None:
Confirmed transaction: sign with ECDSA public keyprint ("ECDSA signature for confirmed transaction")
Use a library such as cryptography to calculate the hash and create the signature
...elif transaction.sighash == 0x02:
Blind signature without providing private keyprint("Blind signature for unconfirmed transaction")
Use a library like cryptography to perform blind signature
...