Created
          June 26, 2025 03:43 
        
      - 
      
- 
        Save rossigee/fac202bab783f55d3e15ba118c4681cf to your computer and use it in GitHub Desktop. 
    Zpub to Xpub converter
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Sometimes you need an 'xpub' when you've been given a 'zpub'. i.e. some multisig wallet generators. | |
| # Converting a zpub to an xpub involves changing the prefix to match the Bitcoin mainnet extended | |
| # public key format. Both are BIP32 extended public keys, but zpub is typically used for SegWit (BIP84), | |
| # while xpub is for legacy addresses (BIP44). The conversion requires adjusting the version bytes. | |
| from base58 import b58decode, b58encode | |
| from hashlib import sha256 | |
| zpub = "zpub..." | |
| decoded = b58decode(zpub) | |
| xpub_version = b"\x04\x88\xb2\x1e" | |
| new_key = xpub_version + decoded[4:-4] | |
| checksum = sha256(sha256(new_key).digest()).digest()[:4] | |
| xpub = b58encode(new_key + checksum).decode() | |
| print(xpub) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment