diff --git a/.gitignore b/.gitignore index 3be6157..e68f835 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,12 @@ venv/ .venv/ env/ -ENV/ \ No newline at end of file +ENV/ + +# Python cache +__pycache__/ +*.pyc +*.pyo + +# File JSON generati dal programma +*.json \ No newline at end of file diff --git a/README.md b/README.md index e0c422f..9b2eb2f 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,33 @@ -# Generatore di Indirizzi Bitcoin +# Bitcoin Address Generator -Questo programma permette di generare diversi tipi di indirizzi Bitcoin in modo semplice e interattivo. L'output prodotto include chiavi private, chiavi pubbliche, indirizzi e formati WIF, e può essere salvato in file JSON. +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. -Per la verifica della validità degli indirizzi, è stato utilizzato lo strumento esterno [SecretScan](https://secretscan.org/). +Address validity was verified using the external tool [SecretScan](https://secretscan.org/). -Attualmente il programma supporta i seguenti tipi di indirizzi: +Currently supported address types: - **P2PK (Pay-to-PubKey)** - **P2PKH (Pay-to-PubKey-Hash)** -- **P2SH (Pay-to-Script-Hash, con supporto multisig)** +- **P2SH (Pay-to-Script-Hash, with multisig support)** - **P2WPKH (Pay-to-Witness-PubKey-Hash, SegWit v0)** - **P2TR (Pay-to-Taproot, SegWit v1)** -Sono in fase di sviluppo anche: +In development: - **P2WSH (Pay-to-Witness-Script-Hash)** --- -## Come funziona il programma +## How it works -Il file principale è `main.py`. Quando viene eseguito, mostra un menu interattivo che consente di scegliere il tipo di indirizzo da generare: +The entry point is `__main__.py`. When run, it displays an interactive menu to choose the address type to generate: ```bash -python main.py +python . ``` -Esempio di esecuzione: +Example output: ``` -=== GENERATORE INDIRIZZI BITCOIN === -Seleziona il tipo di indirizzo: +=== BITCOIN ADDRESS GENERATOR === +Select address type: 1. P2PK 2. P2PKH 3. P2SH @@ -35,120 +35,118 @@ Seleziona il tipo di indirizzo: 5. P2TR ``` -Dopo aver selezionato un'opzione, lo script dedicato verrà eseguito e guida l'utente attraverso: -- Scelta della rete (mainnet, testnet, regtest) -- Eventuale utilizzo di chiavi compresse/non compresse -- Visualizzazione e salvataggio dei dati in un file `.json` +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 -Ogni script è indipendente (`p2pk.py`, `p2pkh.py`, `p2sh.py`, `p2wpkh.py`, `p2tr.py`) e implementa le regole specifiche del relativo standard Bitcoin. +Each script is independent (`src/p2pk.py`, `src/p2pkh.py`, `src/p2sh.py`, `src/p2wpkh.py`, `src/p2tr.py`) and implements the rules of the respective Bitcoin standard. --- -## Tipologie di indirizzi supportati +## Supported address types ### 1. P2PK (Pay-to-PubKey) -- **Standard**: Formato originale di Bitcoin, definito nel whitepaper di Satoshi Nakamoto -- **Formato indirizzo**: Non ha un formato di indirizzo standard, usa direttamente la chiave pubblica +- **Standard**: Original Bitcoin format, defined in Satoshi Nakamoto's whitepaper +- **Address format**: No standard address format — uses the public key directly - **Script**: ` OP_CHECKSIG` -- **Pro**: molto semplice, rappresenta direttamente la chiave pubblica, dimensioni di transazione minime -- **Contro**: obsoleto, non compatibile con la maggior parte dei wallet moderni. Espone la chiave pubblica subito alla blockchain, vulnerabile agli attacchi quantistici -- **Uso attuale**: Principalmente per coinbase transactions e casi molto specifici +- **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 ### 2. P2PKH (Pay-to-PubKey-Hash) -- **Standard**: BIP-13 (Base58Check), formato legacy standard -- **Formato indirizzo**: Inizia con '1' (mainnet), 'm' o 'n' (testnet) +- **Standard**: BIP-13 (Base58Check), legacy standard format +- **Address format**: Starts with '1' (mainnet), 'm' or 'n' (testnet) - **Script**: `OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG` -- **Codifica**: Base58Check con prefisso 0x00 (mainnet) -- **Pro**: è lo standard "legacy", molto diffuso, supportato da tutti i wallet ed exchange. Protezione contro attacchi quantistici (hash della chiave pubblica) -- **Contro**: gli indirizzi sono più lunghi e le fee di transazione sono più alte rispetto a quelli più moderni (SegWit), dimensioni di transazione maggiori +- **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 ### 3. P2SH (Pay-to-Script-Hash) - **Standard**: BIP-16 (Pay to Script Hash), BIP-67 (Deterministic Pay-to-script-hash multi-signature addresses) -- **Formato indirizzo**: Inizia con '3' (mainnet), '2' (testnet/regtest) +- **Address format**: Starts with '3' (mainnet), '2' (testnet/regtest) - **Script**: `OP_HASH160 OP_EQUAL` -- **Codifica**: Base58Check con prefisso 0x05 (mainnet), 0xC4 (testnet/regtest) -- **Pro**: permette indirizzi basati su script arbitrari, ideale per multisig e contratti complessi. Supportato da tutti i wallet moderni. Maggiore flessibilità e funzionalità avanzate -- **Contro**: le fee sono leggermente più alte rispetto ai singoli indirizzi e richiede la rivelazione dello script al momento della spesa. Dimensioni di transazione maggiori per il redeem script +- **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 -**Implementazione attuale: Multisig** -Attualmente il supporto P2SH è limitato agli script multisig, che rappresentano il caso d'uso più comune per P2SH. +**Current implementation: Multisig** +P2SH support is currently limited to multisig scripts, which represent the most common P2SH use case. -**Opzioni disponibili per l'utente:** -- **Configurazione m-of-n**: l'utente può scegliere quante firme sono richieste (m) su un totale di chiavi (n) - - Esempi: 2-of-3, 3-of-5, 1-of-2, ecc. - - Limite: 1 ≤ m ≤ n ≤ 16 -- **Rete**: mainnet, testnet, regtest -- **Chiavi compresse**: opzione per utilizzare chiavi pubbliche compresse (33 byte) o non compresse (65 byte) -- **Ordinamento BIP67**: le chiavi pubbliche vengono automaticamente ordinate per evitare malleabilità +**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 -**Funzionalità implementate:** -- Generazione automatica di n coppie di chiavi (privata/pubblica) -- Creazione del redeem script multisig -- Calcolo dell'hash160 del redeem script -- Generazione dell'indirizzo P2SH finale -- Output JSON strutturato con tutti i dati necessari -- Esportazione delle chiavi private in formato WIF -- Salvataggio completo in file JSON per backup e utilizzo futuro +**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 ### 4. P2WPKH (SegWit v0, Bech32) - **Standard**: BIP-141 (Segregated Witness), BIP-173 (Base32 address format) -- **Formato indirizzo**: Inizia con 'bc1q' (mainnet), 'tb1q' (testnet), 'bcrt1q' (regtest) +- **Address format**: Starts with 'bc1q' (mainnet), 'tb1q' (testnet), 'bcrt1q' (regtest) - **Script**: `OP_0 ` (20 bytes) -- **Codifica**: Bech32 con HRP 'bc' (mainnet), 'tb' (testnet), 'bcrt' (regtest) -- **Witness Program**: versione 0, 20 bytes (hash160 della chiave pubblica) -- **Pro**: riduce le fee grazie al formato SegWit (witness data separato), indirizzi più compatti, supportato da quasi tutti i wallet moderni, protezione contro transaction malleability -- **Contro**: non tutti i vecchi servizi accettano Bech32, richiede supporto SegWit +- **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 ### 5. P2TR (Taproot, SegWit v1, Bech32m) - **Standard**: BIP-340 (Schnorr Signatures), BIP-341 (Taproot), BIP-342 (Tapscript), BIP-350 (Bech32m) -- **Formato indirizzo**: Inizia con 'bc1p' (mainnet), 'tb1p' (testnet), 'bcrt1p' (regtest) +- **Address format**: Starts with 'bc1p' (mainnet), 'tb1p' (testnet), 'bcrt1p' (regtest) - **Script**: `OP_1 ` (32 bytes) -- **Codifica**: Bech32m con HRP 'bc' (mainnet), 'tb' (testnet), 'bcrt' (regtest) -- **Witness Program**: versione 1, 32 bytes (tweaked public key) -- **Pro**: sono i più recenti, con maggiore privacy e flessibilità (supporta script complessi nascosti dietro un singolo indirizzo). Le fee sono basse, firme Schnorr più efficienti, aggregazione delle firme -- **Contro**: ancora relativamente nuovo, non supportato da tutti i servizi, complessità implementativa maggiore +- **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 -### In sviluppo -- **P2SH (Pay-to-Script-Hash)**: permette indirizzi basati su script arbitrari, molto usato per multisig e contratti complessi. -- **P2WSH (Pay-to-Witness-Script-Hash)**: versione SegWit del P2SH, più efficiente e sicura. +### In development +- **P2WSH (Pay-to-Witness-Script-Hash)**: SegWit version of P2SH, more efficient and secure. --- -## Utilizzo pratico +## Usage + +1. Clone or download the repository. +2. Make sure Python 3 is installed and install the requirements: -1. Clona o scarica il repository. -2. Assicurati di avere Python 3 installato e i requisiti: - Linux/macOS (bash/zsh): ```bash - # Consigliato ambiente virtuale - python3 -m venv venv # oppure: python -m venv venv + # Recommended: use a virtual environment + python3 -m venv venv # or: python -m venv venv source venv/bin/activate - # Installazione requisiti + # Install requirements pip install -r requirements.txt ``` Windows (PowerShell): ```powershell - # Consigliato ambiente virtuale + # Recommended: use a virtual environment python -m venv venv .\venv\Scripts\Activate.ps1 - # Installazione requisiti + # Install requirements pip install -r requirements.txt ``` - -3. Esegui il programma principale: +3. Run the program from the repository root: ```bash - python main.py + python . ``` -4. Segui le istruzioni sullo schermo per generare e salvare il tuo indirizzo. +4. Follow the on-screen instructions to generate and save your address. -I dati saranno salvati in un file `.json` leggibile e riutilizzabile. +The data will be saved in a readable and reusable `.json` file. --- -## LICENZA -Questo progetto è rilasciato sotto licenza MIT \ No newline at end of file +## License +This project is released under the MIT license. diff --git a/main.py b/__main__.py similarity index 83% rename from main.py rename to __main__.py index 2b80868..4bf7b23 100644 --- a/main.py +++ b/__main__.py @@ -13,11 +13,11 @@ def main(): choice = input("Inserisci la tua scelta: ").strip() scripts = { - '1': 'p2pk.py', - '2': 'p2pkh.py', - '3': 'p2sh.py', - '4': 'p2wpkh.py', - '5': 'p2tr.py' + '1': 'src/p2pk.py', + '2': 'src/p2pkh.py', + '3': 'src/p2sh.py', + '4': 'src/p2wpkh.py', + '5': 'src/p2tr.py' } if choice in scripts: diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/p2pk.py b/src/p2pk.py similarity index 100% rename from p2pk.py rename to src/p2pk.py diff --git a/p2pkh.py b/src/p2pkh.py similarity index 100% rename from p2pkh.py rename to src/p2pkh.py diff --git a/p2sh.py b/src/p2sh.py similarity index 100% rename from p2sh.py rename to src/p2sh.py diff --git a/p2tr.py b/src/p2tr.py similarity index 100% rename from p2tr.py rename to src/p2tr.py diff --git a/p2wpkh.py b/src/p2wpkh.py similarity index 100% rename from p2wpkh.py rename to src/p2wpkh.py