Skip to content

Extended Public Keys

Extended public keys (xpubs) are the foundation of HD (Hierarchical Deterministic) wallet monitoring. This guide explains how they work and how Vigil uses them.

What is an Extended Public Key?

An extended public key contains:

  • A public key
  • A chain code (for deriving child keys)
  • Depth and index information
  • Parent fingerprint

This allows deriving an unlimited number of child public keys and addresses without exposing private keys.

In practice, wallets derive as many addresses as needed over time.

Key Types and Prefixes

Mainnet

Prefix BIP Script Type Address Format
xpub BIP-44 P2PKH 1... (Legacy)
ypub BIP-49 P2SH-P2WPKH 3... (Nested SegWit)
zpub BIP-84 P2WPKH bc1q... (Native SegWit)

Testnet

Prefix BIP Script Type Address Format
tpub BIP-44 P2PKH m.../n...
upub BIP-49 P2SH-P2WPKH 2...
vpub BIP-84 P2WPKH tb1q...

Prefix Conventions

These prefixes are conventions, not protocol rules. The prefix indicates the intended address type, but the actual script depends on how addresses are derived.

Derivation Paths

Standard BIP Paths

BIP Path Purpose
BIP-44 m/44'/0'/0' Legacy P2PKH
BIP-49 m/49'/0'/0' Nested SegWit
BIP-84 m/84'/0'/0' Native SegWit
BIP-86 m/86'/0'/0' Taproot

Path Components

m / purpose' / coin_type' / account' / change / address_index
Component Meaning
m Master key
purpose' BIP number (44, 49, 84, 86)
coin_type' 0 = Bitcoin, 1 = Testnet
account' Account number (0, 1, 2, ...)
change 0 = external, 1 = internal (change)
address_index Address number within chain

Hardened vs Normal Derivation

  • ' or h indicates hardened derivation (e.g., 84')
  • Hardened derivation requires the private key
  • Normal derivation can use only the public key

Why This Matters

Vigil receives your xpub at the account level (e.g., m/84'/0'/0'). We can derive all addresses below this point (change and address_index) using only the public key.

Address Derivation

From an xpub, Vigil derives addresses in two chains:

External Chain (Receiving)

xpub → /0/0  → Address 1 (first receiving address)
xpub → /0/1  → Address 2
xpub → /0/2  → Address 3
...

Internal Chain (Change)

xpub → /1/0  → Change Address 1
xpub → /1/1  → Change Address 2
xpub → /1/2  → Change Address 3
...

Gap Limit

The gap limit determines how many consecutive unused addresses Vigil scans.

How It Works

Address 0: Used ✓
Address 1: Used ✓
Address 2: Unused
Address 3: Unused
...
Address 21: Unused (gap limit = 20)
Address 22: Stop scanning

If address 22 actually exists but isn't found, you need to increase the gap limit.

Use Case Gap Limit
Personal wallet 20 (default)
Merchant receiving 50-100
Exchange/High volume 500+

Exporting Your xpub

Hardware Wallets

  1. Advanced → Export Wallet
  2. Choose Generic JSON or Electrum
  3. Find the xpub in the exported file
  1. Open Ledger Live
  2. Go to your Bitcoin account
  3. Click Account settings (wrench icon)
  4. Click "Advanced" → "Export xpub"
  1. Open Trezor Suite
  2. Go to your Bitcoin account
  3. Click "Show Full Account Public Key"

Software Wallets

  1. Wallet → Information
  2. Copy "Master public key"
  1. Settings → Export
  2. Choose output format
  3. Copy the xpub
# List wallet descriptors (includes xpubs)
bitcoin-cli listdescriptors

Security Considerations

xpub Privacy

An xpub reveals all addresses in a wallet. Anyone with your xpub can:

  • See all your transactions
  • Calculate your total balance
  • Track your future activity

Do not share your xpub publicly.

What an xpub Cannot Do

  • ❌ Spend your funds
  • ❌ Sign transactions
  • ❌ Access your private keys

Best Practices

  1. Use account-level xpubs - Don't export master keys
  2. One xpub per service - If compromised, only that view is affected
  3. Verify service trustworthiness - Only share with trusted services

Next: Network Support →