2026-03-09 11:07:03 +01:00
# Bitcoin Address Generator
2025-11-10 16:12:36 +01:00
2026-03-09 11:07:03 +01:00
This program allows you to generate different types of Bitcoin addresses in a simple and interactive way. The output includes private keys, public keys, addresses and WIF formats, and can be saved to JSON files.
2025-11-10 16:12:36 +01:00
2026-03-09 11:07:03 +01:00
Address validity was verified using the external tool [SecretScan ](https://secretscan.org/ ).
2025-11-10 16:12:36 +01:00
2026-03-09 11:07:03 +01:00
Currently supported address types:
2025-11-10 16:12:36 +01:00
- **P2PK (Pay-to-PubKey)**
- **P2PKH (Pay-to-PubKey-Hash)**
2026-03-09 11:07:03 +01:00
- **P2SH (Pay-to-Script-Hash, with multisig support)**
2025-11-10 16:12:36 +01:00
- **P2WPKH (Pay-to-Witness-PubKey-Hash, SegWit v0)**
- **P2TR (Pay-to-Taproot, SegWit v1)**
2026-03-09 12:17:07 +01:00
- **HD Wallet (BIP-32/39 with BIP-44/49/84/86 derivation)**
2025-11-10 16:12:36 +01:00
2026-03-09 11:07:03 +01:00
In development:
2025-11-10 16:12:36 +01:00
- **P2WSH (Pay-to-Witness-Script-Hash)**
---
2026-03-09 11:07:03 +01:00
## How it works
2025-11-10 16:12:36 +01:00
2026-03-09 11:07:03 +01:00
The entry point is `__main__.py` . When run, it displays an interactive menu to choose the address type to generate:
2025-11-10 16:12:36 +01:00
```bash
2026-03-09 11:07:03 +01:00
python .
2025-11-10 16:12:36 +01:00
```
2026-03-09 11:07:03 +01:00
Example output:
2025-11-10 16:12:36 +01:00
```
2026-03-09 11:07:03 +01:00
=== BITCOIN ADDRESS GENERATOR ===
Select address type:
2025-11-10 16:12:36 +01:00
1. P2PK
2. P2PKH
3. P2SH
4. P2WPKH
5. P2TR
2026-03-09 12:17:07 +01:00
6. HD Wallet (BIP-44/49/84/86)
2025-11-10 16:12:36 +01:00
```
2026-03-09 11:07:03 +01:00
After selecting an option, the dedicated script runs and guides the user through:
- Network selection (mainnet, testnet, regtest)
- Optional use of compressed/uncompressed keys
- Displaying and saving the data to a `.json` file
2025-11-10 16:12:36 +01:00
2026-03-09 12:17:07 +01:00
Each script is independent (`src/p2pk.py` , `src/p2pkh.py` , `src/p2sh.py` , `src/p2wpkh.py` , `src/p2tr.py` , `src/hd_wallet.py` ) and implements the rules of the respective Bitcoin standard.
2025-11-10 16:12:36 +01:00
---
2026-03-09 11:07:03 +01:00
## Supported address types
2025-11-10 16:12:36 +01:00
### 1. P2PK (Pay-to-PubKey)
2026-03-09 11:07:03 +01:00
- **Standard**: Original Bitcoin format, defined in Satoshi Nakamoto's whitepaper
- **Address format**: No standard address format — uses the public key directly
2025-11-10 16:12:36 +01:00
- **Script**: `<pubkey> OP_CHECKSIG`
2026-03-09 11:07:03 +01:00
- **Pros**: very simple, directly represents the public key, minimal transaction size
- **Cons**: obsolete, incompatible with most modern wallets. Exposes the public key directly on the blockchain, vulnerable to quantum attacks
- **Current use**: Mainly in coinbase transactions and very specific cases
2025-11-10 16:12:36 +01:00
### 2. P2PKH (Pay-to-PubKey-Hash)
2026-03-09 11:07:03 +01:00
- **Standard**: BIP-13 (Base58Check), legacy standard format
- **Address format**: Starts with '1' (mainnet), 'm' or 'n' (testnet)
2025-11-10 16:12:36 +01:00
- **Script**: `OP_DUP OP_HASH160 <pubkey_hash> OP_EQUALVERIFY OP_CHECKSIG`
2026-03-09 11:07:03 +01:00
- **Encoding**: Base58Check with prefix 0x00 (mainnet)
- **Pros**: the "legacy" standard, widely used, supported by all wallets and exchanges. Protection against quantum attacks (public key hash)
- **Cons**: addresses are longer and transaction fees are higher compared to modern (SegWit) types, larger transaction sizes
2025-11-10 16:12:36 +01:00
### 3. P2SH (Pay-to-Script-Hash)
- **Standard**: BIP-16 (Pay to Script Hash), BIP-67 (Deterministic Pay-to-script-hash multi-signature addresses)
2026-03-09 11:07:03 +01:00
- **Address format**: Starts with '3' (mainnet), '2' (testnet/regtest)
2025-11-10 16:12:36 +01:00
- **Script**: `OP_HASH160 <script_hash> OP_EQUAL`
2026-03-09 11:07:03 +01:00
- **Encoding**: Base58Check with prefix 0x05 (mainnet), 0xC4 (testnet/regtest)
- **Pros**: enables addresses based on arbitrary scripts, ideal for multisig and complex contracts. Supported by all modern wallets. Greater flexibility and advanced features
- **Cons**: fees are slightly higher than single-key addresses and requires revealing the script at spend time. Larger transaction sizes due to redeem script
**Current implementation: Multisig**
P2SH support is currently limited to multisig scripts, which represent the most common P2SH use case.
**Available options:**
- **m-of-n configuration**: choose how many signatures are required (m) out of a total number of keys (n)
- Examples: 2-of-3, 3-of-5, 1-of-2, etc.
- Limit: 1 ≤ m ≤ n ≤ 16
- **Network**: mainnet, testnet, regtest
- **Compressed keys**: option to use compressed (33 bytes) or uncompressed (65 bytes) public keys
- **BIP67 sorting**: public keys are automatically sorted to prevent malleability
**Implemented features:**
- Automatic generation of n key pairs (private/public)
- Multisig redeem script construction
- hash160 computation of the redeem script
- Final P2SH address generation
- Structured JSON output with all necessary data
- Private key export in WIF format
- Full JSON file save for backup and future use
2025-11-10 16:12:36 +01:00
### 4. P2WPKH (SegWit v0, Bech32)
- **Standard**: BIP-141 (Segregated Witness), BIP-173 (Base32 address format)
2026-03-09 11:07:03 +01:00
- **Address format**: Starts with 'bc1q' (mainnet), 'tb1q' (testnet), 'bcrt1q' (regtest)
2025-11-10 16:12:36 +01:00
- **Script**: `OP_0 <pubkey_hash>` (20 bytes)
2026-03-09 11:07:03 +01:00
- **Encoding**: Bech32 with HRP 'bc' (mainnet), 'tb' (testnet), 'bcrt' (regtest)
- **Witness program**: version 0, 20 bytes (hash160 of the public key)
- **Pros**: lower fees thanks to SegWit (witness data separated), more compact addresses, supported by almost all modern wallets, protection against transaction malleability
- **Cons**: not all legacy services accept Bech32, requires SegWit support
2025-11-10 16:12:36 +01:00
### 5. P2TR (Taproot, SegWit v1, Bech32m)
- **Standard**: BIP-340 (Schnorr Signatures), BIP-341 (Taproot), BIP-342 (Tapscript), BIP-350 (Bech32m)
2026-03-09 11:07:03 +01:00
- **Address format**: Starts with 'bc1p' (mainnet), 'tb1p' (testnet), 'bcrt1p' (regtest)
2025-11-10 16:12:36 +01:00
- **Script**: `OP_1 <taproot_output>` (32 bytes)
2026-03-09 11:07:03 +01:00
- **Encoding**: Bech32m with HRP 'bc' (mainnet), 'tb' (testnet), 'bcrt' (regtest)
- **Witness program**: version 1, 32 bytes (tweaked public key)
- **Pros**: the most recent type, with greater privacy and flexibility (supports complex scripts hidden behind a single address). Low fees, more efficient Schnorr signatures, signature aggregation
- **Cons**: still relatively new, not supported by all services, higher implementation complexity
2025-11-10 16:12:36 +01:00
2026-03-09 12:17:07 +01:00
### 6. HD Wallet (BIP-32/39/44/49/84/86)
- **Standards**: BIP-32 (hierarchical deterministic wallets), BIP-39 (mnemonic phrases), BIP-44/49/84/86 (derivation paths)
- **Networks**: mainnet, testnet
- **Derivation paths**:
- BIP-44 → P2PKH: `m/44'/0'/account'/0/index` — addresses start with `1` (mainnet)
- BIP-49 → P2SH-P2WPKH: `m/49'/0'/account'/0/index` — addresses start with `3` (mainnet)
- BIP-84 → P2WPKH: `m/84'/0'/account'/0/index` — addresses start with `bc1q` (mainnet)
- BIP-86 → P2TR: `m/86'/0'/account'/0/index` — addresses start with `bc1p` (mainnet)
- **Extended key prefixes**: `xpub` /`xprv` (BIP-44/86), `ypub` /`yprv` (BIP-49), `zpub` /`zprv` (BIP-84)
- **JSON output**: compatible with Electrum wallet format (`keystore` , `xpub` , `xprv` , `derivation` , `root_fingerprint` , `seed_version: 17` )
- **Pros**: deterministic key derivation from a single mnemonic, interoperable with Electrum and other BIP-39 compatible wallets
- **Cons**: requires securely backing up the mnemonic phrase
**Available options:**
- Generate a new 12-word mnemonic or import an existing one
- Optional BIP-39 passphrase
- Account index selection
- Configurable number of receiving addresses to derive
2026-03-09 11:07:03 +01:00
### In development
- **P2WSH (Pay-to-Witness-Script-Hash)**: SegWit version of P2SH, more efficient and secure.
2025-11-10 16:12:36 +01:00
---
2026-03-09 11:07:03 +01:00
## Usage
1. Clone or download the repository.
2. Make sure Python 3 is installed and install the requirements:
2025-11-10 16:12:36 +01:00
2025-11-10 16:22:10 +01:00
Linux/macOS (bash/zsh):
2025-11-10 16:12:36 +01:00
```bash
2026-03-09 11:07:03 +01:00
# Recommended: use a virtual environment
python3 -m venv venv # or: python -m venv venv
2025-11-10 16:12:36 +01:00
source venv/bin/activate
2026-03-09 11:07:03 +01:00
# Install requirements
2025-11-10 16:12:36 +01:00
pip install -r requirements.txt
```
2025-11-10 16:22:10 +01:00
Windows (PowerShell):
```powershell
2026-03-09 11:07:03 +01:00
# Recommended: use a virtual environment
2025-11-10 16:22:10 +01:00
python -m venv venv
.\venv\Scripts\Activate.ps1
2026-03-09 11:07:03 +01:00
# Install requirements
2025-11-10 16:22:10 +01:00
pip install -r requirements.txt
```
2026-03-09 11:07:03 +01:00
3. Run the program from the repository root:
2025-11-10 16:12:36 +01:00
```bash
2026-03-09 11:07:03 +01:00
python .
2025-11-10 16:12:36 +01:00
```
2026-03-09 11:07:03 +01:00
4. Follow the on-screen instructions to generate and save your address.
2025-11-10 16:12:36 +01:00
2026-03-09 11:07:03 +01:00
The data will be saved in a readable and reusable `.json` file.
2025-11-10 16:12:36 +01:00
---
2026-03-09 11:07:03 +01:00
## License
This project is released under the MIT license.