Skip to content

Instantly share code, notes, and snippets.

@openoms
Forked from freenancial/xpub_zpub_convert.py
Created August 17, 2020 08:02
Show Gist options
  • Save openoms/4e8a527e4c9757162a53f2dc96e3d229 to your computer and use it in GitHub Desktop.
Save openoms/4e8a527e4c9757162a53f2dc96e3d229 to your computer and use it in GitHub Desktop.
Convert xpub/xprv to zpub/zprv
import base58
x = 'xprv9s21ZrQH143K2f55zo5GiXiX16MiPzBgc2bEXNd77e1ooGsjxAyXjozyuniqiSB76VESjTW8s7vdsK3NFboha6tZgF9BzcDdNtUT6Aw99P2'
zp = b'\x04\xb2\x43\x0c'
base58.b58encode_check(zp + base58.b58decode_check(x)[4:]).decode('ascii')
# output: 'zprvAWgYBBk7JR8GjFTKfWeX8huXM2ecHEAgSFdg6AQssemZuUWCTVJeywKFxCe1iFUwumU4EQhFnSdjdtGVgzdjAaFmQvY3ARrbvLbjsLf6oNE'
# xprv = b'\x04\x88\xad\xe4'
# yprv = b'\x04\x9d\x78\x78'
# zprv = b'\x04\xb2\x43\x0c'
# xpub = b'\x04\x88\xb2\x1e'
# ypub = b'\x04\x9d\x7c\xb2'
# zpub = b'\x04\xb2\x47\x46'
@openoms
Copy link
Author

openoms commented Aug 17, 2020

needs:
pip install base58

@vindard
Copy link

vindard commented May 8, 2021

I just went through the steps to get an aezeed mnemonic to an Electrum-compatible zprv as well... I can't believe how complex this was!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment