How to retrieve a public key from all types of transaction? Is there a way to get sender's public key based only on the raw transaction data no matter the P2... type?
Is there a way to get sender's public key based only on the raw transaction data no matter the P2... type

Probably, if you exclude all current transaction types whose most popular names don't begin with the words &quot;pay to ...&quot;:




Script type
Public Key in locking script
Public Key in unlocking script




Pay-to-Public-Key-Hash (P2PKH)
No
Yes


Pay-to-Public-Key
Yes
Yes


Multi-Signature
Yes
Yes


OP_RETURN
No
N/A


Pay-to-Script-Hash (P2SH)
No
Yes (in redeem script)


Transaction Puzzle
N/A
N/A


...
?
?




References:

https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch05.html
https://en.bitcoin.it/wiki/Script
https://www.quantabytes.com/articles/a-survey-of-bitcoin-transaction-types

The last of these is the most comprehensive of those listed, however it lacks full details.

The method that can be used to retrieve the public keys in each case (i.e. answer to How?) can be found by inspecting the detailed descriptions in the linked references above. Exact details depend on available tools and skillsets.