بلاگ
Metamask: Why does the BIP44 derivation path generate the same address in MetaMask as the Ledger Live derivation path?
Understanding Derivative Paths in MetaMask: 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 Ledger Live and Bitcoin Integration (BIP44) derivative paths. But why is that? In this article, we’ll take a look at the Metamask codebase to understand what’s going on behind the scenes.
Derivative Paths
Derivative paths in cryptocurrency wallets are used to encode a user’s private key into multiple addresses. The most common derivative path is BIP44 (Bitcoin Improvement Proposal 44), which breaks private keys into six sub-parts: m/44'/60'/۰/
, m/44’/61’/۱/, etc. These sub-addresses can then be combined to create a single address.
Ledger Live and MetaMask wallets have different origin paths, as shown in the following code snippet:
m/44'/60'/0'/0/0';
const LEDGER_LIVE_PATH =
const BIP44_PATH =
m/44'/...
Notice that BIP44_PATHuses a different prefix (
m/) and a slightly different structure for child addresses.
The MetaMask code
In the Metamask codebase, we can see how the origin paths are encoded into 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 the child addresses from a BIP44 route
// 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 route as input and returns an array of child addresses. These child addresses are then encoded into the final address.
Why the same origin path in both wallets
Now that we understand how origin paths work, let's look at why MetaMask generates the same address for Ledger Live and BIP44 origin 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 create the final address.
The key insight 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 path ofm/44’/60’/0’/0/0′, it is equivalent to having a single address consisting of four parts: m/44'/60'/۰/
.
In the MetaMask codebase, we do not explicitly encode each child address into an individual address. Instead, we treat the entire derivation path as a whole and concatenate the resulting addresses.
As a result, Ledger Live and BIP44 derivation paths generate the same address in MetaMask. This may seem contradictory at first, but it is actually a consequence of how Metamask handles encoding BIP44 paths into addresses.
Conclusion
Understanding the Metamask codebase can help you understand how the wallet generates addresses for Ledger Live and BIP44 derivation paths. By recognizing the differences between BIP44_PATH
and 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 appreciate the mechanisms that make these wallets work seamlessly.