prysm-pulse/tools/unencrypted-keys-gen/main.go

92 lines
2.2 KiB
Go
Raw Normal View History

package main
import (
"flag"
"github.com/prysmaticlabs/prysm/shared/bls"
"log"
"os"
"github.com/prysmaticlabs/prysm/shared/interop"
"github.com/prysmaticlabs/prysm/tools/unencrypted-keys-gen/keygen"
)
var (
numKeys = flag.Int("num-keys", 0, "Number of validator private/withdrawal keys to generate")
startIndex = flag.Uint64("start-index", 0, "Start index for the determinstic keygen algorithm")
random = flag.Bool("random", false, "Randomly generate keys")
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")
)
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")
}
}
file, err := os.Create(*outputJSON)
if err != nil {
log.Fatal(err)
}
defer func() {
if err := file.Close(); err != nil {
log.Fatal(err)
}
}()
var ctnr *keygen.UnencryptedKeysContainer
if *random {
ctnr = generateRandomKeys(*numKeys)
} else {
ctnr = generateUnencryptedKeys(*startIndex)
}
Refactor dependencies, make Prysm "go gettable" (#6053) * Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-05-31 06:44:34 +00:00
if err := keygen.SaveUnencryptedKeysToFile(file, ctnr); err != nil {
log.Fatal(err)
}
}
func generateRandomKeys(num int) *keygen.UnencryptedKeysContainer {
ctnr := &keygen.UnencryptedKeysContainer{
Keys: make([]*keygen.UnencryptedKeys, num),
}
for i := 0; i < num; i++ {
sk := bls.RandKey()
ctnr.Keys[i] = &keygen.UnencryptedKeys{
ValidatorKey: sk.Marshal(),
WithdrawalKey: sk.Marshal(),
}
}
return ctnr
}
Refactor dependencies, make Prysm "go gettable" (#6053) * Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-05-31 06:44:34 +00:00
func generateUnencryptedKeys(startIndex uint64) *keygen.UnencryptedKeysContainer {
ctnr := &keygen.UnencryptedKeysContainer{
Keys: make([]*keygen.UnencryptedKeys, *numKeys),
}
sks, _, err := interop.DeterministicallyGenerateKeys(startIndex, uint64(*numKeys))
if err != nil {
panic(err)
}
for i, sk := range sks {
Refactor dependencies, make Prysm "go gettable" (#6053) * Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-05-31 06:44:34 +00:00
ctnr.Keys[i] = &keygen.UnencryptedKeys{
ValidatorKey: sk.Marshal(),
WithdrawalKey: sk.Marshal(),
}
}
return ctnr
}