getting public key from any raw transaction - what to take care of? 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!
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.





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).





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).





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). 





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





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



I hope this helps