0

I know how to generate a valid mnemonic and a valid address associated with that mnemonic. However I'm unsure how to generate a private key in ethereum. In Bitcoin, the master node is where you'd get the private key (sometimes called the master private key)

However in ethereum, it seems that generation is kept very straight (the path is a standard "m/44'/60'/0'/0" and it seems that ethereum wallets do not take advantage of more than one account or in some cases more than one address.

Therefore, which node is the private key generated from? The root node and the child node in the path have different extended private keys?

Tag on question, how can I format the extended private key so it is not extended anymore?

0

According to this github issue page it turns out the answer is the private key is not generated as part of the node structure but instead the result of HMACing the first 32 bytes of the the entropy. An example below

import hdkey from 'ethereumjs-wallet/hdkey';
import ethwallet from 'ethereumjs-wallet';
import ethtx from 'ethereumjs-tx';
import bip39 from 'bip39';

const mnemonic = bip39.generateMnemonic();
console.log(`Mnemonic: ${mnemonic}`);
const root = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
const derivedNode = root.derivePath("m/44'/60'/0'/0");
const address = this.generateAddress(derivedNode);
console.log(`Private Key: ${root._hdkey.privateKey.toString('hex')}`);

The actual private key generation occurs in hdkey

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.