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: CustomZpub- 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: CustomVpub- Multi-signature P2WSH - Path: Custom
๐ Setup & Installation
๐ฆ Using pip (Recommended)
pip install xpubkaleidoscope
๐ ๏ธ From Source
- Clone the repository:
git clone https://github.com/valerio-vaccaro/XPubKaleidoscope.git
cd XPubKaleidoscope
- 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/*)
- External:
- ypub/upub:
- External:
sh(wpkh([fingerprint/49'/0'/0']xpub.../0/*)) - Internal:
sh(wpkh([fingerprint/49'/0'/0']xpub.../1/*))
- External:
- zpub/vpub:
- External:
wpkh([fingerprint/84'/0'/0']xpub.../0/*) - Internal:
wpkh([fingerprint/84'/0'/0']xpub.../1/*)
- External:
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/*,...)))
- External:
- Zpub/Vpub:
- External:
wsh(multi(k,[fingerprint/path]xpub.../0/*,...)) - Internal:
wsh(multi(k,[fingerprint/path]xpub.../1/*,...))
- External:
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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9629460f84a78996515d6e115c0175696a2f18b5996c2f0a84d9591d224c440
|
|
| MD5 |
e728562fc54bbf08e9f1261ab0ac98e7
|
|
| BLAKE2b-256 |
df6e06f1d77021e4ab8d2fd7a585c59f461c25e91fba8a102365334777a9e873
|
File details
Details for the file xpubkaleidoscope-0.0.1-py3-none-any.whl.
File metadata
- Download URL: xpubkaleidoscope-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a7d233216d9e026906c464a1418d48530fefea1070ba28b50fe24ffbe941820
|
|
| MD5 |
4dae7715c53fae1a282ca26e1762114b
|
|
| BLAKE2b-256 |
2da71436150f18872fa62708d1b058f9c2f80d81dbe0d9297487df9808cf8813
|