From 1cddb6c5e1e71ec8cb283475f422025d8131304a Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Wed, 6 Feb 2019 18:00:28 -0800 Subject: [PATCH] add generation account binary --- cmd/keygen/main.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cmd/keygen/main.go diff --git a/cmd/keygen/main.go b/cmd/keygen/main.go new file mode 100644 index 000000000..6103ba5a7 --- /dev/null +++ b/cmd/keygen/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "crypto/rand" + "encoding/hex" + "fmt" + "io" + "os" + "strconv" + + crypto2 "github.com/ethereum/go-ethereum/crypto" +) + +var ( + version string + builtBy string + builtAt string + commit string +) + +func main() { + if len(os.Args) < 2 { + fmt.Println("Please provide # of keys to be generated") + os.Exit(1) + } + + if n, err := strconv.Atoi(os.Args[1]); err == nil { + for i := 0; i < n; i++ { + randomBytes := [32]byte{} + _, err := io.ReadFull(rand.Reader, randomBytes[:]) + if err != nil { + fmt.Println("Failed to get randomness for the private key...") + return + } + priKey, err := crypto2.GenerateKey() + if err != nil { + panic("Failed to generate the private key") + } + crypto2.FromECDSA(priKey) + + fmt.Printf("{Address: \"%s\", Private: \"%s\", Public: \"%s\"},\n", crypto2.PubkeyToAddress(priKey.PublicKey).Hex(), hex.EncodeToString(crypto2.FromECDSA(priKey)), crypto2.PubkeyToAddress(priKey.PublicKey).Hex()) + } + } else { + fmt.Println("Unable to parse # as the argument.") + } +}