TeachMeBitcoin

Custom Python Derivation Path Auditor

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

Custom Python Derivation Path Auditor

In this final guide, we will build a Python script that parses a BIP44-style Derivation Path. The script will break down the string into its component levels and explain what each index means in the context of Bitcoin standards.

The Path Auditor

def audit_derivation_path(path_string):
    print(f"--- Derivation Path Audit ---")
    print(f"[*] Path: {path_string}")

    # 1. Clean and split the path
    parts = path_string.split('/')
    if parts[0] != 'm':
        print("[ERROR] Path must start with 'm'")
        return

    # 2. Level Definitions
    levels = ["Master", "Purpose", "Coin Type", "Account", "Change", "Index"]

    # 3. Analyze each part
    for i, part in enumerate(parts):
        if i \u003e= len(levels):
            print(f"[?] Depth {i}: {part}")
            continue

        name = levels[i]
        if part == 'm':
            print(f"[0] {name:12}: Master Root Seed")
            continue

        # Check for hardening
        is_hardened = "'" in part or "h" in part
        index_str = part.replace("'", "").replace("h", "")
        index = int(index_str)

        status = "HARDENED" if is_hardened else "Normal"

        # Add context based on level
        context = ""
        if name == "Purpose":
            if index == 44: context = "(Legacy P2PKH)"
            if index == 49: context = "(Nested SegWit P2SH)"
            if index == 84: context = "(Native SegWit Bech32)"
            if index == 86: context = "(Taproot Bech32m)"
        elif name == "Coin Type":
            if index == 0: context = "(Bitcoin Mainnet)"
            if index == 1: context = "(Bitcoin Testnet)"
        elif name == "Change":
            context = "(Receiving)" if index == 0 else "(Change)"

        print(f"[{i}] {name:12}: {index:10} | {status:8} {context}")

# --- Simulation ---

# A standard Native SegWit path
test_path = "m/84'/0'/0'/0/5"
audit_derivation_path(test_path)

print("\n--- Next Audit ---")

# A Taproot path for a testnet business account
audit_derivation_path("m/86'/1'/1'/0/0")

How to Run the Auditor

  1. Ensure you have Python 3 installed.

  2. Copy the code into a file named path_auditor.py.

  3. Run it using python3 path_auditor.py.

Technical Takeaways

  1. Human Context: Derivation paths are purely for human/software organization. The blockchain doesn't know anything about "Accounts" or "Change." It only knows the final derived address.

  2. Hardening Symbols: Note that both ' and h are used in different software to represent hardening. A robust auditor should handle both.

  3. The Master Path: Every key in a Bitcoin wallet has a path. If you lose the path, you lose the map to your money. This is why "Standard" paths are so important for recovery.

Congratulations! You have completed the Derivation Paths (The BIP Hierarchy) module. You now have the knowledge to navigate the complex tree of keys that makes up a modern Bitcoin wallet.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!