2019-08-28 16:07:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2020-05-31 06:44:34 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/tools/unencrypted-keys-gen/keygen"
|
2019-08-28 16:07:31 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2019-09-11 18:38:35 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/interop"
|
2019-08-28 16:07:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
numKeys = flag.Int("num-keys", 0, "Number of validator private/withdrawal keys to generate")
|
2019-09-18 17:15:26 +00:00
|
|
|
startIndex = flag.Uint64("start-index", 0, "Start index for the determinstic keygen algorithm")
|
2019-08-28 16:07:31 +00:00
|
|
|
outputJSON = flag.String("output-json", "", "JSON file to write output to")
|
2019-08-30 04:32:08 +00:00
|
|
|
overwrite = flag.Bool("overwrite", false, "If the key file exists, it will be overwritten")
|
2019-08-28 16:07:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
if *numKeys == 0 {
|
|
|
|
log.Fatal("Please specify --num-keys to generate")
|
|
|
|
}
|
|
|
|
if *outputJSON == "" {
|
|
|
|
log.Fatal("Please specify an --output-json file to write the unencrypted keys to")
|
|
|
|
}
|
|
|
|
|
2019-08-30 04:32:08 +00:00
|
|
|
if !*overwrite {
|
|
|
|
if _, err := os.Stat(*outputJSON); err == nil {
|
|
|
|
log.Fatal("The file exists. Use a different file name or the --overwrite flag")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 16:07:31 +00:00
|
|
|
file, err := os.Create(*outputJSON)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := file.Close(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-09-18 17:15:26 +00:00
|
|
|
ctnr := generateUnencryptedKeys(*startIndex)
|
2020-05-31 06:44:34 +00:00
|
|
|
if err := keygen.SaveUnencryptedKeysToFile(file, ctnr); err != nil {
|
2019-08-28 16:07:31 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-31 06:44:34 +00:00
|
|
|
func generateUnencryptedKeys(startIndex uint64) *keygen.UnencryptedKeysContainer {
|
|
|
|
ctnr := &keygen.UnencryptedKeysContainer{
|
|
|
|
Keys: make([]*keygen.UnencryptedKeys, *numKeys),
|
2019-08-28 16:07:31 +00:00
|
|
|
}
|
2019-09-11 18:38:35 +00:00
|
|
|
|
2019-09-18 17:15:26 +00:00
|
|
|
sks, _, err := interop.DeterministicallyGenerateKeys(startIndex, uint64(*numKeys))
|
2019-09-11 18:38:35 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, sk := range sks {
|
2020-05-31 06:44:34 +00:00
|
|
|
ctnr.Keys[i] = &keygen.UnencryptedKeys{
|
2019-09-11 18:38:35 +00:00
|
|
|
ValidatorKey: sk.Marshal(),
|
|
|
|
WithdrawalKey: sk.Marshal(),
|
2019-08-28 16:07:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ctnr
|
|
|
|
}
|
|
|
|
|