vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 856 forks source link

How to decode a Sighash type on a TX hex? #178

Open zilveer opened 6 years ago

zilveer commented 6 years ago

Hello, is there anyone here who can guide me on how to decode a Sighash type on a TX hex which is signed?

I am pretty new to this, any help is appreciated.

regards

sr-gi commented 6 years ago

You should check the input script (scriptSig) for the transaction you want to decode. Assuming you are analysing a P2PKH transaction, the structure of the script will be:

< signature >< hash_type >< public_key >

The hash_type is always 1 byte long.

For future questions I would recommend you to ask this type of questions in another place, like the Bitcoin Stack Exchange, since this repo is kind off discontinued.

zilveer commented 6 years ago

@sr-gi thanks for replying back to me.

I will do that but meanwhile u r here what if it's a P2SH transaction how does it look like then?

Thanks for your kind reply.

regards

sr-gi commented 6 years ago

P2SHare more tricky, since them not always require a signature. However, if there is a signature the hash type will be the next byte or the tailing byte, depending on how you interpret the signature (as it happened with P2PKHscripts).

Here you have the structure of a signature:

captura

and here an example where rand s are 32-byte values:

captura

Notice that htrepresents the hash type.