Skip to content

Instantly share code, notes, and snippets.

@thaarok
Last active April 25, 2023 18:35
Show Gist options
  • Save thaarok/efc2144e3838e5b878390ac256524576 to your computer and use it in GitHub Desktop.
Save thaarok/efc2144e3838e5b878390ac256524576 to your computer and use it in GitHub Desktop.
Reading ethereum JSON keystore to obtain PrivateKey object.
package driver
import (
"crypto/ecdsa"
"github.com/gochain/gochain/v4/accounts/keystore"
"os"
"testing"
)
const PrivateKeyStore = "~/.opera/fakenet-1/keystore/UTC--2023-04-25T07-50-08.017708542Z--239fa"
const PrivateKeyPass = "fakepassword"
func readPrivateKeyFromKeystore(t *testing.T) *ecdsa.PrivateKey {
jsonBytes, err := os.ReadFile(PrivateKeyStore)
if err != nil {
t.Fatal(err)
}
key, err := keystore.DecryptKey(jsonBytes, PrivateKeyPass)
if err != nil {
t.Fatal(err)
}
return key.PrivateKey
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment