I am building a small script to decode the raw coinbase transaction data into a human-readable viewer without external scripts to better my understanding around the subject.
I've noticed that there are many different types of output script types among transactions. (P2SH, P2PK (as seen in genesis block), P2PKH, etc)
One thing I have not been able to grasp is how to obtain the Base58 address in the new SegWit P2WPK and P2WSH types.
For example, Block #542748 has this coinbase transaction which my script determines to have a pay to witness public key (P2WPK) output with
97cfc76442fe717f2a3f0cc9c175f7561b661997 as the public key hash.
The full output script:
Traditionally, in P2PK, P2PKH and P2SH I've used the image on this thread which works quite well.
When I apply the same method as the pubkeyhash (P2PKH) with the following operations I get a totally different address:
Append version byte:
SHA-256 Round 1:
SHA-256 Digest of Round 1:
Append checksum 4 bytes:
This is quite different than
bc1qjl8uwezzlech723lpnyuza0h2cdkvxvh54v3dn which is listed on blockchain.info's website here
What's the best way to obtain the same address they have listed (starting with bc1)?