How to generate a private key for Ethereum from the mnemonic?

Viewed 5271

I generated a new mnemonic using bip39 package: bip39.generateMnemonic(). There is the next step where I need to convert it into 64 characters of hex-string. I can make it using SHA-256 but it looks little weirdly because of I will apply ECDSA-256 and KECCAK-256 to generate a public key.

Is it right way to generate a private key from the mnemonic using SHA-256? Or should I use another hash-function?

P.S. I am a noobie in Ethereum system.

2 Answers

There is a library called tweetNacl that have several functionalities including generating a keyPair from a seed. It is also available in dart as pineNacl here.

I have not tried the dart one myself but you should be able to generate a keyPair from a seed. You can also see conversion of mnemonic into a 32-byte seed here

After scrolling through some really confusing documentation of its dart implementation. You should be able to generate a keyPair from a seed with something like a function like this

Related