5
2
I am trying to generate SegWit paper wallet address from WIF:
My WIF is L5mHKZsCLS27nSoGM3RdAwuxjvg7XhJdP25LgqdXe6zF11wpWdbT.
I am converting WIF to compressed public key:
Compressed public key: 03fac6879502c4c939cfaadc45999c7ed7366203ad523ab83ad5502c71621a85bb
I am creating P2SH-P2WPKH address using instructions at Creation of P2SH-P2WPKH Address
using following algorithm:
- Calculate the RIPEMD160 of the SHA256 of a public key:
SHA256 of public key: cfad24b0bc2bba2c8bb2c8d619dca2b74221930793bca50df73856f0bbba10c9
RIPEMD160 of SHA256 hash: d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d
- Create P2SH redeemScript as
OP_PUSH publicKeyHash:
redeemScript: 0014d5e5d05edfe2ed61099bf3f0d53be2775bbc6d0d
- Generate scriptPubKey as
OP_HASH160 hash160(redeemScript) OP_EQUAL
scriptPubKey: a914a19949e546c2f4d410cbb061c986b9ff3099ae7087
- Generate RIPEMD160 hash of scriptPubKey:
hash: dc62e525af22d1f0f17cc2a091cf2c9fb36bf553
- Generate address with
0x05prefix and double SHA256 hash checksum:
result: 3MnK46gvixm8hk7mJTQTAqenniSodjXPrJ
Expected result according to segwitaddress is:
33voQqbNAYyig272KjcX8GkucWn2x25WEg
What am I doing wrong?
Update
Thanks to the accepted answer, here are correct steps to do this:
Public key - compressed:
03fac6879502c4c939cfaadc45999c7ed7366203ad523ab83ad5502c71621a85bb
SHA256(public key) =
cfad24b0bc2bba2c8bb2c8d619dca2b74221930793bca50df73856f0bbba10c9
RIPEMD160(SHA256(public key)) =
7646c030f7e75b80f0a31cdcab731e6f424f22b2
redeemScript (OP_0 pubkeyHash160):
00147646c030f7e75b80f0a31cdcab731e6f424f22b2
SHA256(redeemScript) =
a10e523968ba784d24ccd54e613d8f747d6649e42b1df4fdcec6658262620651
RIPEMD160(SHA256(redeemScript)) =
188ba16284702258959d8bb63bb9a5d979b57875
P2SH address base58(0x05 | hash | 4-byte sha256 checksum) =
33voQqbNAYyig272KjcX8GkucWn2x25WEg
Hi Andrew, I was hoping you could help. I think I'm not generating the checksum correctly. Before the base58 encoding, this is the string I have: 05188ba16284702258959d8bb63bb9a5d979b5787555c30444. After base58 that's 33voQqbNAYyig272KjcX8GkucWn2uJk5WT. Last 6 characters are incorrect. Which part am I getting wrong? – user2298995 – 2017-12-17T07:34:01.050
@user2298995 Your checksum is wrong. The hex should be 05188BA16284702258959D8BB63BB9A5D979B57875BFE2FCFD – Andrew Chow – 2017-12-17T16:39:41.000
Thank you very much for your comment! How is the checksum generated then? I took the 4 bytes of sha256(sha256(redeemScript)). Is it not the proper way? – user2298995 – 2017-12-18T17:46:40.957
2No, it is the first 4 bytes of the sha256(sha256(payload)) where the payload is the data you are encoding with the base58 check encoding. In this case, the payload is 05188BA16284702258959D8BB63BB9A5D979B57875 – Andrew Chow – 2017-12-18T17:59:02.847
Oh thank you very much. Very appreciated! – user2298995 – 2017-12-18T19:12:24.703