Last active
April 25, 2023 18:35
-
-
Save thaarok/efc2144e3838e5b878390ac256524576 to your computer and use it in GitHub Desktop.
Reading ethereum JSON keystore to obtain PrivateKey object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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