Skip to main content

A Python utility for converting Bitcoin Extended Public Keys between different formats

Project description

๐Ÿ”„ XPubKaleidoscope

A Python utility for converting Bitcoin Extended Public Keys between different formats (xpub, ypub, zpub, tpub, etc.).

๐Ÿ“ Overview

XPubKaleidoscope allows you to easily convert Bitcoin extended public keys between various formats. This is particularly useful when working with different wallet types and Bitcoin address formats. Each key's fingerprint is calculated and displayed to help verify key integrity across conversions.

โœจ Supported formats:

๐ŸŒ Mainnet Single-Signature

  • xpub - Legacy Bitcoin addresses (P2PKH or P2SH) - Path: m/44'/0'/0'
  • ypub - SegWit addresses (P2WPKH in P2SH) - Path: m/49'/0'/0'
  • zpub - Native SegWit addresses (P2WPKH) - Path: m/84'/0'/0'

๐ŸŒ Mainnet Multi-Signature

  • Ypub - Multi-signature P2WSH in P2SH - Path: Custom
  • Zpub - Multi-signature P2WSH - Path: Custom

๐Ÿงช Testnet Single-Signature

  • tpub - Legacy Bitcoin addresses (P2PKH or P2SH) - Path: m/44'/1'/0'
  • upub - SegWit addresses (P2WPKH in P2SH) - Path: m/49'/1'/0'
  • vpub - Native SegWit addresses (P2WPKH) - Path: m/84'/1'/0'

๐Ÿงช Testnet Multi-Signature

  • Upub - Multi-signature P2WSH in P2SH - Path: Custom
  • Vpub - Multi-signature P2WSH - Path: Custom

๐Ÿš€ Setup & Installation

๐Ÿ“ฆ Using pip (Recommended)

pip install xpubkaleidoscope

๐Ÿ› ๏ธ From Source

  1. Clone the repository:
git clone https://github.com/valerio-vaccaro/XPubKaleidoscope.git
cd XPubKaleidoscope
  1. Set up a virtual environment:
python3 -m venv venv

# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On Unix or MacOS:
source venv/bin/activate

pip install -r requirements.txt

To deactivate the virtual environment when you're done:

deactivate

๐Ÿ› ๏ธ Usage

๐Ÿ“š As a Python Package

from xpubkaleidoscope import XPubConverter

# Initialize converter
converter = XPubConverter()

# Convert xpub to different format
result = converter.convert("your_xpub_key_here", target_format="zpub")

# Get key information
info = converter.identify("your_xpub_key_here")

# Convert to all formats
all_formats = converter.convert_all("your_xpub_key_here")

๐Ÿ–ฅ๏ธ Command Line Interface

Identify format:

python xpub_converter.py "your_xpub_key_here" -i

Output example:

๐Ÿ“ฅ Input key:
xpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2PKH or P2SH
  ๐Ÿ”— Derivation Path: m/44'/0'/0'
  ๐Ÿ”‘ Key: xpub6CUGRUo...
  ๐Ÿ” Fingerprint: A1B2C3D4
  ๐Ÿ“ Descriptors:
    External (Receive): pkh([A1B2C3D4/44'/0'/0']xpub6CUGRUo.../0/*)
    Internal (Change): pkh([A1B2C3D4/44'/0'/0']xpub6CUGRUo.../1/*) 

Convert to specific format:

xpubkaleidoscope "your_xpub_key_here" -t zpub

Output example:

๐Ÿ“ฅ Input key:
xpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2PKH or P2SH
  ๐Ÿ”— Derivation Path: m/44'/0'/0'
  ๐Ÿ”‘ Key: xpub6CUGRUo...
  ๐Ÿ” Fingerprint: A1B2C3D4

๐Ÿ“ค Converted key:
zpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2WPKH
  ๐Ÿ”— Derivation Path: m/84'/0'/0'
  ๐Ÿ”‘ Key: zpub6rFR7y4...
  ๐Ÿ” Fingerprint: A1B2C3D4

Convert to all supported formats:

xpubkaleidoscope "your_xpub_key_here" -a

Output example:

๐Ÿ“ฅ Input key:
xpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2PKH or P2SH
  ๐Ÿ”— Derivation Path: m/44'/0'/0'
  ๐Ÿ”‘ Key: xpub6CUGRUo...
  ๐Ÿ” Fingerprint: A1B2C3D4

๐Ÿ“ค Converting to all formats:

ypub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2WPKH in P2SH
  ๐Ÿ”— Derivation Path: m/49'/0'/0'
  ๐Ÿ”‘ Key: ypub6Wq3G6n...
  ๐Ÿ” Fingerprint: A1B2C3D4

zpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2WPKH
  ๐Ÿ”— Derivation Path: m/84'/0'/0'
  ๐Ÿ”‘ Key: zpub6rFR7y4...
  ๐Ÿ” Fingerprint: A1B2C3D4

Show help:

xpubkaleidoscope -h

usage: xpubkaleidoscope [-h] [-t {xpub,ypub,zpub,Ypub,Zpub,tpub,upub,vpub,Upub,Vpub}] [-i] [-a] key

Convert between extended public key formats

positional arguments:
  key                   The extended public key to convert

options:
  -h, --help            show this help message and exit
  -t {xpub,ypub,zpub,Ypub,Zpub,tpub,upub,vpub,Upub,Vpub}, --to {xpub,ypub,zpub,Ypub,Zpub,tpub,upub,vpub,Upub,Vpub}
                        Target format to convert to
  -i, --identify        Only identify the format
  -a, --all             Convert to all supported formats

โœจ Features

  • ๐Ÿ”„ Convert between all major extended public key formats
  • โœ… Validation of input keys
  • ๐ŸŒ Support for both mainnet and testnet
  • ๐Ÿ’ป Simple command-line interface with colored output
  • ๐Ÿ”Œ Support for single-signature and multi-signature formats
  • ๐Ÿ” Key fingerprint verification across conversions
  • ๐Ÿ“ Output descriptors for wallet configuration

๐Ÿ” About Fingerprints

The fingerprint is a 4-byte identifier calculated from the public key using RIPEMD160(SHA256(pubkey)). It remains constant across different format conversions of the same key, helping to verify that the conversion was successful. The fingerprint is displayed in hexadecimal format (e.g., A1B2C3D4).

๐Ÿ“ About Descriptors

Output descriptors are a way to precisely describe how to derive addresses from keys. Each format has two descriptors: one for receiving addresses (external, 0/) and one for change addresses (internal, 1/). All descriptors use xpub format for consistency with Bitcoin Core:

Single-Signature Descriptors

  • xpub/tpub:
    • External: pkh([fingerprint/44'/0'/0']xpub.../0/*)
    • Internal: pkh([fingerprint/44'/0'/0']xpub.../1/*)
  • ypub/upub:
    • External: sh(wpkh([fingerprint/49'/0'/0']xpub.../0/*))
    • Internal: sh(wpkh([fingerprint/49'/0'/0']xpub.../1/*))
  • zpub/vpub:
    • External: wpkh([fingerprint/84'/0'/0']xpub.../0/*)
    • Internal: wpkh([fingerprint/84'/0'/0']xpub.../1/*)

Example output:

zpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: P2WPKH
  ๐Ÿ”— Derivation Path: m/84'/0'/0'
  ๐Ÿ”‘ Key: zpub6rFR7y4...
  ๐Ÿ” Fingerprint: A1B2C3D4
  ๐Ÿ“ Descriptors:
    External (Receive): wpkh([A1B2C3D4/84'/0'/0']xpub6CUGRUo.../0/*)
    Internal (Change): wpkh([A1B2C3D4/84'/0'/0']xpub6CUGRUo.../1/*)

Multi-Signature Descriptors (Partial)

  • Ypub/Upub:
    • External: sh(wsh(multi(k,[fingerprint/path]xpub.../0/*,...)))
    • Internal: sh(wsh(multi(k,[fingerprint/path]xpub.../1/*,...)))
  • Zpub/Vpub:
    • External: wsh(multi(k,[fingerprint/path]xpub.../0/*,...))
    • Internal: wsh(multi(k,[fingerprint/path]xpub.../1/*,...))

Example multi-signature output:

Zpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: Multi-signature P2WSH
  ๐Ÿ”— Derivation Path: Custom
  ๐Ÿ”‘ Key: Zpub6rFR7y4...
  ๐Ÿ” Fingerprint: A1B2C3D4
  ๐Ÿ“ Descriptors:
    External (Receive): wsh(multi(k,[A1B2C3D4/Custom]xpub6CUGRUo.../0/*,...))
    Internal (Change): wsh(multi(k,[A1B2C3D4/Custom]xpub6CUGRUo.../1/*,...))

Note:

  • All keys in descriptors are shown in xpub format for compatibility with Bitcoin Core and other wallet software
  • External (0/*) is used for receiving addresses
  • Internal (1/*) is used for change addresses
  • The asterisk (*) represents the address index

๐Ÿ”— About Derivation Paths

All single-signature formats include a hardened subaccount index (0') in their derivation paths. This follows the BIP44 standard and its derivatives:

  • Purpose: Hardened (e.g., 44', 49', 84')
  • Coin type: 0' for mainnet, 1' for testnet
  • Account: 0' (hardened subaccount)
  • Change and address index: Handled by the descriptor's wildcard (*)

Multi-signature formats use custom derivation paths that should be specified according to your wallet configuration.

Example multi-signature output:

Zpub:
  ๐ŸŒ Network: MAINNET
  ๐Ÿ“ฆ Type: Multi-signature P2WSH
  ๐Ÿ”— Derivation Path: Custom
  ๐Ÿ”‘ Key: Zpub6rFR7y4...
  ๐Ÿ” Fingerprint: A1B2C3D4
  ๐Ÿ“ Descriptors:
    External (Receive): wsh(multi(k,[A1B2C3D4/Custom]Zpub6rFR7y4.../0/*,...))
    Internal (Change): wsh(multi(k,[A1B2C3D4/Custom]Zpub6rFR7y4.../1/*,...))

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โš ๏ธ Disclaimer

Always verify the output addresses and fingerprints before using them for real transactions. Incorrect conversions could lead to loss of funds.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpubkaleidoscope-0.0.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xpubkaleidoscope-0.0.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file xpubkaleidoscope-0.0.1.tar.gz.

File metadata

  • Download URL: xpubkaleidoscope-0.0.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for xpubkaleidoscope-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b9629460f84a78996515d6e115c0175696a2f18b5996c2f0a84d9591d224c440
MD5 e728562fc54bbf08e9f1261ab0ac98e7
BLAKE2b-256 df6e06f1d77021e4ab8d2fd7a585c59f461c25e91fba8a102365334777a9e873

See more details on using hashes here.

File details

Details for the file xpubkaleidoscope-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for xpubkaleidoscope-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a7d233216d9e026906c464a1418d48530fefea1070ba28b50fe24ffbe941820
MD5 4dae7715c53fae1a282ca26e1762114b
BLAKE2b-256 2da71436150f18872fa62708d1b058f9c2f80d81dbe0d9297487df9808cf8813

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page