0

i need to retrieve public key of transaction sender.

now i know there are 03 compressed pubkeys and 04 uncompressed ones.

but how is this working with segwit and multisig addresses?

can you please point me to what possible combinations there could be, so i am ready for any possible trnasaction to always get the right key?

thanks a lot!

1 Answer 1

0

I have summarized some popular payment types in my book "Grokking Bitcoin". There are 6 standard payment types:

p2pkh: Pay-to-public-key-hash. The public key is the second (last) item in scriptSig.

p2pkh


p2sh: Pay-to-script-hash. The public key(s) are packed into the redeem script which is the last item in scriptSig. To get them you need to parse the redeem script (which itself is a script) and look for key patterns (push of 33 bytes).

p2sh


p2wpkh: Pay-to-witness-public-key-hash. The public key is found in the witness of the transaction. More specifically in the second item of the witness field with the same index as the input you're investigating (the witness contains one witness field for each input. There's only one witness field in this example, because there's only one input).

p2wpkh


p2wsh: Pay-to-witness-script-hash. The public key(s) are packed into the witness script which is the last item in the input's corresponding witness field. To get them you need to parse the witness script (which itself is a script) and look for key patterns (push of 33 bytes).

p2wsh


p2wpkh nested in p2sh: The pubkey is in the same place as in p2wpkh.

p2wpkh-nested


p2wsh nested in p2sh: The pubkey is in the same place as in p2wsh.

enter image description here

I hope this helps

4

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.