1

Very difficult to find definitive info on this.

From what I can find on google and looking at BIP32 it seems like the process to calculate a checksum for an extended key is to decode the base58 string to data, then perform a double sha256 on the data and the first 4 bytes from the double hash are the checksum.

I am trying to take in a non xpub (vpubs, upub ypub etc) and convert it to an xpub/tpub programmatically. Currently I have it working but the last 6 digits of the xpub are always incorrect, I am assuming this is the checksum?

In order to correctly calculate the checksum do I remove the prefix first, then remove the existing checksum then do the double sha256 on the stripped down extended key or do I keep the new xpub prefix and then perform the double sha256? Or am I completely wrong in my assumptions here?

Thanks in advanced!

1

it seems like the process to calculate a checksum for an extended key is to decode the base58 string to data,

If raw_xpub = version + depth + fingerprint + child + chain + DATA than to make the checksum you need to do doublehash of xpriv/xpub (sha256), in python:

hashed_xpub = hashlib.sha256(raw_xpub).digest()
hashed_xpub = hashlib.sha256(hashed_xpub).digest()

and then take the checksum as first 4 characters (0 to 3) and add it at the end of the raw xpub:

raw_xpub += hashed_xpub[:4]

Finally, run it through Base58 to encode it. I think you've might performed base58 operation too early based on your question. It's the last step in the process.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.