About Ethereum’s Arbitrarily Deep Hierarchical Key Exchange (HA-DPKG) with Electrum
As the flagship wallet for the Ethereum blockchain, Electrum provides users with a secure way to store and manage their private keys. One of the key features that sets Electrum apart from other wallets is its Arbitrarily Deep Hierarchical Key Exchange (HA-DPKG), which generates a unique public-private key pair from a seed, allowing users to create multiple addresses on the blockchain. In this article, we’ll dive into how Electrum generates a key pair from a seed and explore the inner workings of HA-DPKG.
Generating a Key Pair from a Seed
To generate a key pair with Electrum, you need to provide it with a seed, which is a 12-word phrase that serves as the first part of the public-private key. The seed acts as a password or passphrase that controls access to your Ethereum account. When you create an Electrum wallet, Electrum asks for your seed in a specific format:
M/0'/0 /M/0'/1 *2^20'/0 /M/0'/1
In this example, the first part /M/0
represents the initial seed data (a mix of bytes) and M/0
indicates the second byte. The rest of the string follows a specific format:
M/0'/n1 *2^n /M/n
*2^nindicates that this is an index of 2 raised to the power of
n. For example, if you provide a seed like "G4pBQx8Hj9fRtVwLqyL3ZgT2vDf" with
n=1, Electrum will generate a key pair as follows:
M/0'/0 /M/0'/1 *2^20'/0 /M/0'/1
The resulting public-private key pair is 36 bytes.
Hierarchical Address Generation
Once the key pair is generated, Electrum uses it to create a hierarchy of addresses that can be used for transactions on the Ethereum network. To do this, Electrum takes each byte of the seed and assigns it a specific role in creating a hierarchical address (HA). The roles are:
- M/0
: represents the initial data of the seed.
- n1
: the second byte is assigned to
n1.
2^n: Each subsequent byte is assigned to
n1, with
n1` being one more than the previous value.
Using this hierarchical approach, Electrum generates a sequence of HA addresses from your key pair. For example:
0x00 01 02 03 ... (M/0)
*2^20'00 = 00101010101010
*2^21'00 = 011110111100
*2^22'00 = 000101101000
*2^23'00 =
1x... (n1, n1+1, ...)
Address 0: 0x01 02 03 *2^20'
Address 1: 0x11 12 13 *2^21'
...
These HA addresses can be used for various purposes on the Ethereum network, such as creating a wallet address or generating a contract address.
Conclusion
In conclusion, Electrum’s use of a seed to generate a key pair allows users to create multiple addresses on the Ethereum blockchain. By understanding how Electrum generates these key pairs and hierarchically extracts addresses from them, you can better understand the inner workings of HA-DPKG and improve your overall experience with this popular wallet.