SHARE
TWEET

Untitled

a guest Jan 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "crypto/ecdsa"
  5.     "fmt"
  6.     "io/ioutil"
  7.     "log"
  8.     "os"
  9.  
  10.     "github.com/ethereum/go-ethereum/accounts/keystore"
  11.     "github.com/ethereum/go-ethereum/crypto"
  12. )
  13.  
  14. func main() {
  15.  
  16.     priv := loadPrivateKey("z-devkey--f7f1af2cd620deb3a99685e403703b947a556678")
  17.     addr := crypto.PubkeyToAddress(priv.PublicKey)
  18.     fmt.Println("Keystore eth address:", addr.Hex())
  19.     // Expect address = 0xf7f1af2cd620deb3a99685e403703b947a556678
  20. }
  21. func loadPrivateKey(keyloc string) *ecdsa.PrivateKey {
  22.     keyfile, err := os.Open(keyloc)
  23.     must(fmt.Sprintf("could not load keystore file at %s\n", keyloc), err)
  24.     reader, err := ioutil.ReadAll(keyfile)
  25.     must("", err)
  26.     key, err := keystore.DecryptKey(reader, "")
  27.     must("could not decrypt key", err)
  28.     return key.PrivateKey
  29. }
  30.  
  31. func must(errText string, err error) {
  32.     if err != nil {
  33.         log.Fatalf("%s: %s\n", errText, err)
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top