About MetaMask Derivation Paths: Comparing Ledger Live and BIP44
As a user of the popular cryptocurrency wallet MetaMask, you’ve probably noticed that it generates the same address for both the Ledger Live and Bitcoin Integration (BIP44) derivation paths. But why? In this article, we’ll explore the Metamask codebase to understand what’s going on behind the scenes.
Derivation Paths
In cryptocurrency wallets, derivation paths are used to encode a user’s private key into multiple addresses. The most common derivation path is BIP44 (Bitcoin Improvement Proposal 44), which splits private keys into six children: m/44'/60'/0/
, m/44'/61'/1/
, and so on. These child addresses can then be combined to generate a single address.
Ledger Live Wallet and MetaMask have different origin paths, as shown in the following code snippet:
const LEDGER_LIVE_PATH = m/44'/60'/0'/0/0
;
const BIP44_PATH = m/44'/...
Note that BIP44_PATHuses a different prefix (
m/) and a slightly different structure for child addresses.
MetaMask Code
In the Metamask codebase, we can see how the extraction paths are encoded in an address:
${address}/${getChildren(address)}
const generateAddress = (path) => {
const [address] = path.split('/');
return
;
};
const getChildren = (address) => {
// For simplicity, let's assume that this function extracts child addresses from a BIP44 path
// In reality, this would involve parsing the BIP44 output and extracting the individual address components
const children = [];
for (let i = 1; i < address.length; i += 8) {
children.push(address.substring(i, i + 8));
}
return children;
};
This getChildren function takes a BIP44 path as input and returns an array of child addresses. These child addresses are then encoded into the final address.
Why the same mining path in both wallets
Now that we understand how mining paths work, let’s see why MetaMask generates the same address for both Ledger Live and BIP44 mining paths:
In the generateAddressfunction, we simply take a BIP44 path as input and split it into individual addresses using the
/character. We then concatenate these child addresses to form the final address.
The key insight here is that when we encode a BIP44 path into an address, we can treat each child address independently. In other words, if we have a BIP44 pathm/44'/60'/0'/0/0, this is equivalent to a single four-part address:
m/44'/60'/0/.
In the MetaMask codebase, we do not explicitly encode each child address into a separate address. Instead, we treat the entire branch path as a whole and concatenate the resulting addresses.
As a result, the Ledger Live and BIP44 derivation paths ultimately generate the same address in MetaMask. This may seem counterintuitive at first, but it is actually a consequence of the way Metamask handles encoding BIP44 paths into addresses.
Conclusion
Understanding the Metamask codebase can help you appreciate how the wallet generates addresses for both Ledger Live and BIP44 derivation paths. By recognizing the differences inBIP44_PATHand
LEDDER_LIVE_PATH`, we can see that the MetaMask implementation is indeed equivalent, despite using a different prefix and structure.
In the future, when working with Metamask or other wallets, you will be able to appreciate the underlying mechanisms that make these wallets work smoothly.