Bitcoin Derivation Path

Photo by Kanchanara on Unsplash

Bitcoin Derivation Path

A derivation path is a sequence of numbers and letters. Before we go further let’s give an insight into Hd wallets.

HD WALLETS

HD wallets, short for Hierarchical Deterministic wallets, are a type of wallet that uses a single seed phrase, also known as a mnemonic phrase, to generate an entire tree of private keys and addresses.

The relation between HD wallets, mnemonics, and derivation paths is that the mnemonic phrase, also known as the seed phrase, is used to generate the entire tree of private keys and addresses in an HD wallet. The derivation path is used to determine the specific key for a particular address within the HD wallet. The seed phrase is used to recreate the private key for the wallet, and the derivation path is used to navigate to the specific key for a particular address.

Now that we understand the relation let’s focus on derivation path.

DERIVATION PATH

A derivation path is a sequence of numbers and letters that are used to determine the specific private key for a particular address. It is akin to a formula that specifies how to calculate private keys from the seed. It starts with "m" or "M" which stands for Master, followed by a series of numbers and slashes. Private keys derived from the master private key start with “m.” Public keys derived from the master public key start with “M.” Each number and slash represents a different level in the hierarchy, and the final number represents the specific address or account.

The HD wallet tree structure offers tremendous flexibility. Each parent extended key can have 4 billion children With all that flexibility, however, it becomes quite difficult to navigate this infinite tree. It is especially difficult to transfer HD wallets between implementations.

Two BIPs offer a solution to this complexity by creating some proposed standards for the structure of HD wallet trees. BIP-43 proposes the use of the first hardened child index as a special identifier that signifies the “purpose” of the tree structure. Based on BIP-43, an HD wallet should use only one level-1 branch of the tree, with the index number identifying the structure and namespace of the rest of the tree by defining its purpose. For example, an HD wallet using only branch m/i'/ is intended to signify a specific purpose, and that purpose is identified by the index number “i.”

Extending that specification, BIP-44 proposes a multi-account structure as “purpose” number 44' under BIP-43. All HD wallets following the BIP-44 structure are identified by the fact that they only used one branch of the tree: m/44'/.

BIP-44 specifies the structure as consisting of five predefined tree levels:

m / purpose' / coin_type' / account' / change / address_index

  • The first-level “purpose” is always set to 44'.

  • The second-level “coin_type” specifies the type of cryptocurrency coin, allowing for multicurrency HD wallets where each currency has its own subtree under the second level. examples: Bitcoin is m/44'/0', Bitcoin Testnet is m/44'/1', and Litecoin is m/44'/2'.

  • The third level of the tree is “account,” which allows users to subdivide their wallets into separate logical subaccounts, for accounting or organizational purposes. For example, an HD wallet might contain two bitcoin “accounts”: m/44'/0'/0' and m/44'/0'/1'. Each account is the root of its own subtree.

  • On the fourth level, “change,” an HD wallet has two subtrees, one for creating receiving addresses and one for creating change addresses. Note that whereas the previous levels used hardened derivation, this level uses normal derivation. This is to allow this level of the tree to export extended public keys for use in a nonsecured environment.

    Usable addresses are derived by the HD wallet as children of the fourth level, making

  • The fifth level of the tree is the “address_index.” For example, the third receiving address for bitcoin payments in the primary account would be M/44'/0'/0'/0/2.

Common Derivation Paths Patterns

BIPNAMEPATH
44Legacy Bitcoin (BTC) address (starts with a 1)m/44'/0'/0'/0/0
49P2SH (Pay-to-script-hash) addresses(starts with a 3)m/49'/0'/0'/0/0
84SegWit Bitcoin (BTC) address (starts with a bc1q)m/84'/0'/0'/0/0
86Taproot Bitcoin (BTC) address (starts with a bc1p)m/86'/0'/0'/0/0

In summary, A derivation path is a way to organize and separate different accounts, addresses, or wallets, it's an extension of the Bip32 standard and allows for a hierarchical structure of private keys and addresses, it starts with "m" or "M" followed by a series of numbers and slashes and it's divided into four parts: Purpose, Account, Change, and Address Index. It's important to keep the derivation path and the mnemonic phrase used to generate the private key safe and secure, as anyone with access to these can access the funds in the corresponding wallet.