I am basically trying to get public and private keys by derivation paths from seed phrases for Ethereum accounts using Golang. I have this:
package generator
import (
"fmt"
"github.com/tyler-smith/go-bip32"
"github.com/tyler-smith/go-bip39"
)
type HDWallet struct{}
const BIP_PATH = "m/44'/60'/0'/0/0"
func (wallet *HDWallet) GenerateAddressAndPrivateKey(seedPhrase string) (string, string, error) {
seed, err := bip39.NewSeedWithErrorChecking(seedPhrase, "")
if err != nil {
return "", "", err
}
masterKey, err := bip32.NewMasterKey(seed)
if err != nil {
return "", "", err
}
publicKey := masterKey.PublicKey()
if err != nil {
return "", "", err
}
return ???, ???, nil
}
I have the master key but how do I get derived accounts (public and private keys)?
In order to retrieve the public and private keys as their well-known hex strings (account keys) you need to convert your generated master private and public keys to ECDSA hex string as follows. Btw, usually you wont use the master private and public key.
You can check whether the generated public key as hex string belongs to the private key hex string as follows.
--EDIT--
No guarantee, but try this approach.