How do I Derive Bech32 Address from P2WPKH Output Script?
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.
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: 0097CFC76442FE717F2A3F0CC9C175F7561B661997
SHA-256 Round 1: f756795a3b878d16bfa9e426a47d857830bb08a02e691f0487cbeac51b510f40
SHA-256 Digest of Round 1: ea7fe8c3b7680b79ff507c7d1b40bfc29ca8269bb1033cc84010506743cce404
Append checksum 4 bytes: 0097CFC76442FE717F2A3F0CC9C175F7561B661997ea7fe8c3
Base58 Encode: 1EqhwhM5t5NxedLoSuJ6BtBvUMLhanBLxa
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)?
https://ift.tt/2xzA5Xq
Comments
Post a Comment