I am trying really hard to convert Ethereum private keys BIP44 in string format to a type that can (*ecdsa.PrivateKey) be used by rest of the code.

I am trying really hard to convert Ethereum private keys BIP44 in string format to a type that can (*ecdsa.PrivateKey) be used by rest of the code.

import (
    "crypto/x509"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/common/hexutil"
    "github.com/ethereum/go-ethereum/crypto"
)

const (
    privateKey2 string = "0xbacd06016aea4280e14efd7182ba18cd98bf11701943d3d47d76b04bb7baad19"
)

func main() {
    privateKey, err := crypto.GenerateKey()
    if err != nil {
        log.Fatal(err)
    }

    privateKeyBytes := crypto.FromECDSA(privateKey)
    fmt.Println("Only bytes", privateKeyBytes)

    fmt.Println(hexutil.Encode(privateKeyBytes)[2:])

    firstKey := []byte(privateKey2)
    fmt.Println("Only bytes first key", firstKey)

    _, err = x509.ParsePKCS8PrivateKey(firstKey)
    if err != nil {
        fmt.Println("Cannot parse private key")
    }

    // fmt.Println("The address geneerated is ", auth.From)
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.