Custom Python Derivation Path Auditor
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
-
Ensure you have Python 3 installed.
-
Copy the code into a file named
path_auditor.py. -
Run it using
python3 path_auditor.py.
Technical Takeaways
-
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.
-
Hardening Symbols: Note that both
'andhare used in different software to represent hardening. A robust auditor should handle both. -
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.
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: