Skip to content
linux2zPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

btc-batch-balance-auditor banner

🪙 btc-batch-balance-auditor — Python Bitcoin Key & Balance Audit Utilities

Derive legacy Bitcoin (P2PKH) addresses & private keys from UTF-8 word lists (100K+ words), audit balances in fast 80-address batches with automatic API failover, and export compressed WIF keys locally.

Python 3.10+ secp256k1 Base58Check and WIF Blockchain APIs


🧭 Quick Overview (Which Script Do I Run First?)

  📝 Your Word List (.txt)
           │
           ▼   Step 2: Run word_to_btc_key.py (offline)
  🔑 Generated Address + Private Key File (<name>_YYYY-MM-DD_HH-MM-SS.txt)
           │
           ▼   Step 3: Run btc_batch_audit.py (80 addresses per API call)
  💰 Active & Funded Results (audit_results_<name>_YYYY-MM-DD_HH-MM-SS.txt)
Order Script What It Does Output File
1️⃣ 🔑 word_to_btc_key.py Derives compressed secp256k1 P2PKH (1...) addresses & hex private keys from a .txt word list (offline) <input_stem>_YYYY-MM-DD_HH-MM-SS.txt
2️⃣ ⚡ btc_batch_audit.py Audits the generated address file in fast batches (80 at a time) for received & current BTC + derives compressed WIF audit_results_<input_stem>_YYYY-MM-DD_HH-MM-SS.txt
Alt 🐢 btc_single_audit.py Slower sequential 1-by-1 address auditor using mempool.space and blockstream.info address_balance_check_YYYY-MM-DD_HH-MM-SS.txt
Check 🩺 api_health_check.py Tests reachability, latency (ms), and JSON structure of all 3 Bitcoin balance APIs Terminal status summary (3/3 healthy)
Sample 📝 my word.txt Ready-to-test sample dictionary (98 sample words + 1 leading blank line) Input sample for Step 2

⚠️ Security Note: Deriving private keys from single words or low-entropy passphrases (brainwallets) is unsafe for storing funds. Use these utilities strictly for learning Bitcoin cryptography, auditing weak passphrases, or recovering your own keys. Never share or commit your word lists, key files, or audit outputs.


🛠️ Step 1: Install Requirements

Prerequisites

  • 🐍 Python 3.10 or newer (python.org) — during Windows installation, check "Add Python to PATH".
  • 🖥️ Tkinter (included automatically with standard Windows/macOS Python; on Ubuntu/Debian Linux, run sudo apt install python3-tk).

Download & Install Dependencies

Open PowerShell / Terminal and run:

# 1. Download this repository and enter the folder
git clone https://github.com/linux2z/btc-batch-balance-auditor.git
cd btc-batch-balance-auditor

# 2. (Recommended) Create and activate a virtual environment
python -m venv .venv

# On Windows (PowerShell):
.venv\Scripts\Activate.ps1
# On macOS / Linux:
# source .venv/bin/activate

# 3. Install the required libraries (base58, ecdsa, requests)
pip install -r requirements.txt

💡 Quick check: If pip install -r requirements.txt finishes without errors, you are ready to run the scripts!


🔑 Step 2: Convert Your Word Dictionary (word_to_btc_key.py)

A sample dictionary file (my word.txt, containing 98 sample words and 1 blank line) is included so you can test right away—or prepare any .txt word list with one word or passphrase per line (works smoothly with small lists or large dictionaries like 100,000+ words).

python word_to_btc_key.py

What Happens When You Run It

  1. 📂 Pick your word list: A file picker window opens—select my word.txt (or your own .txt dictionary file).
  2. 🧹 Automatic cleanup: It reads the file, removes blank lines and duplicate words, and prints how many raw, blank, duplicate, and unique words were found (for my word.txt: 99 raw lines, 1 blank skipped, 98 unique words).
  3. ⚙️ Generates keys & addresses offline: For every unique word, it computes:
    • A legacy Bitcoin address (1...)
    • Its matching 64-character hex private key
  4. 💾 Saves & verifies: Writes each pair on two lines into a timestamped file in the same folder as your word list (e.g. my word_2026-12-03_21-10-00.txt):
    1xm4vFerV3pSgvBFkyzLgT1Ew3HQYrS1V
    ...64-char hex private key...
    
    After finishing, it automatically checks that Output Lines Written == Converted Pairs × 2.

🚀 Tip for 100K+ Word Dictionaries: In word_to_btc_key.py, VERBOSE is set to True by default (prints every single word in the terminal). For very large lists (e.g., 100,000 words), open word_to_btc_key.py and change:

VERBOSE = False
PROGRESS_EVERY = 1000  # prints a milestone every 1,000 words for much faster console output

⚡ Step 3: Batch Audit Balances & Export WIF Keys (btc_batch_audit.py)

Once word_to_btc_key.py finishes creating your timestamped address file, run the fast batch auditor:

python btc_batch_audit.py

What Happens When You Run It

  1. 📂 Select the generated BTC address file:
    • Choose the timestamped file created in Step 2 (for example my word_YYYY-MM-DD_HH-MM-SS.txt, not the raw my word.txt word list).
    • Built-in validation: inspect_address_file() checks that at least 80% (MIN_VALID_ADDRESS_RATIO = 0.8) of address lines are real Bitcoin addresses (1..., 3..., or bc1...). If you accidentally select a word list, it rejects it and lets you pick again.
    • Private keys stay local: When an address line is followed by its 64-character hex (or WIF) private key on the next line, the script pairs them in memory and skips the private key during API calls—your private keys are never sent over the network.
  2. 🌐 Queries balances via two API layers:
    • Primary fast batch endpoint (https://blockchain.info/balance): Sends 80 addresses in a single request (BATCH_SIZE = 80, pausing BATCH_DELAY = 1.0s between batches) to fetch total received coins (total_received), current coins (final_balance), and transaction count (n_tx), calculating total_sent = max(0, total_received - final_balance).
    • Automatic single-address failover (https://mempool.space/api ➡️ https://blockstream.info/api): If blockchain.info rate-limits (429), returns a server error (5xx), or omits an address, it automatically switches to mempool.space and blockstream.info (/address/<address>), summing chain_stats + mempool_stats (funded_txo_sum for received coins, spent_txo_sum for sent coins, and current_balance = total_received - total_sent).
  3. 🔎 Filters & saves matches:
    • Addresses that have never received BTC (total_received <= 0) are skipped.
    • Whenever an address has received BTC (total_received > 0), the script:
      • Converts the paired 64-char hex private key locally into a compressed WIF private key (K... or L...) ready for wallet import.
      • Prints the match in the terminal (highlighting Current Balance in red if > 0 BTC).
      • Appends the full record immediately to audit_results_<input_stem>_YYYY-MM-DD_HH-MM-SS.txt in the same folder so progress is saved even if you stop early.

⚙️ Useful Settings in btc_batch_audit.py

Setting Default What It Controls
START_FROM_ADDRESS 1 Address number to start from (set to None to be asked in the terminal so you can resume a large file)
BATCH_SIZE 80 Number of addresses checked per blockchain.info request
BATCH_DELAY 1.0 Pause in seconds between batch requests to respect rate limits
FALLBACK_REQUEST_DELAY 0.5 Pause in seconds between single-address fallback requests
VERBOSE True Set to False to hide "Never received BTC (skipped)" lines and only show hits

🐢 Alternative: Sequential Single-Address Auditor (btc_single_audit.py)

If you prefer checking addresses slowly one at a time directly against mempool.space/api (with automatic failover to blockstream.info/api) without using blockchain.info, run:

python btc_single_audit.py
  • Uses the exact same address-file validation, local private-key pairing, compressed WIF conversion, and red balance highlighting.
  • Pauses REQUEST_DELAY = 0.6 seconds between requests and saves hits to address_balance_check_YYYY-MM-DD_HH-MM-SS.txt.

🩺 API Health Check (api_health_check.py)

Before running a long balance audit, you can run this quick diagnostic script (requires only requests) to verify that all three Bitcoin APIs are reachable, responsive, and returning the expected JSON fields:

python api_health_check.py
  • Queries the genesis address (TEST_ADDRESS = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa") using a single requests.Session().
  • Checks the primary batch endpoint (https://blockchain.info/balance) for final_balance, total_received, and n_tx.
  • Checks both Esplora fallback endpoints (https://mempool.space/api and https://blockstream.info/api) for chain_stats and mempool_stats (funded_txo_sum, spent_txo_sum, tx_count).
  • Prints per-endpoint latency (ms), HTTP status, BTC stats, and a final working_count/total_apis summary with troubleshooting notes if any endpoint fails.

🔐 How the Cryptography Works (Under the Hood)

Click to expand the step-by-step math used by both scripts
  1. Word ➡️ Private Key (word_to_btc_key.py):
    • Encode the word as UTF-8 bytes and take SHA-256 ➡️ 32-byte private key.
    • Verify 1 <= int(private_key) < SECP256k1.order.
  2. Private Key ➡️ Legacy 1... P2PKH Address (word_to_btc_key.py):
    • Multiply the secp256k1 generator point by the private key to get (X, Y).
    • Build compressed public key: "02" + X if Y is even, or "03" + X if Y is odd.
    • Compute HASH160 = RIPEMD-160(SHA-256(compressed_public_key)).
    • Prepend mainnet version byte 0x00, append the first 4 bytes of SHA-256(SHA-256(payload)), and Base58-encode.
  3. Hex Private Key ➡️ Compressed WIF (btc_batch_audit.py & btc_single_audit.py):
    • Take the 32-byte raw private key, prepend 0x80 (mainnet) and append 0x01 (compressed flag).
    • Append the first 4 bytes of SHA-256(SHA-256(extended)), then Base58-encode to get a K... or L... WIF key.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages