2019-09-09 21:31:19 +00:00
|
|
|
// Used for converting keys.yaml files from eth2.0-pm for interop testing.
|
|
|
|
// See: https://github.com/ethereum/eth2.0-pm/tree/master/interop/mocked_start
|
|
|
|
//
|
|
|
|
// This code can be discarded after interop testing.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2020-05-31 20:08:36 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/tools/unencrypted-keys-gen/keygen"
|
2019-09-10 14:24:14 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2019-09-09 21:31:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// KeyPair with hex encoded data.
|
|
|
|
type KeyPair struct {
|
|
|
|
Priv string `yaml:"privkey"`
|
|
|
|
Pub string `yaml:"pubkey"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// KeyPairs represent the data format in the upstream yaml.
|
|
|
|
type KeyPairs []KeyPair
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 3 {
|
|
|
|
fmt.Println("Usage: convert-keys path/to/keys.yaml path/to/output.json")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
inFile := os.Args[1]
|
|
|
|
|
2022-04-18 20:42:07 +00:00
|
|
|
in, err := os.ReadFile(inFile) // #nosec G304
|
2019-09-09 21:31:19 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to read file %s: %v", inFile, err)
|
|
|
|
}
|
|
|
|
data := make(KeyPairs, 0)
|
2021-08-01 03:26:24 +00:00
|
|
|
if err := yaml.UnmarshalStrict(in, &data); err != nil {
|
2019-09-09 21:31:19 +00:00
|
|
|
log.Fatalf("Failed to unmarshal yaml: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
out := &keygen.UnencryptedKeysContainer{}
|
|
|
|
for _, key := range data {
|
|
|
|
pk, err := hex.DecodeString(key.Priv[2:])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to decode hex string %s: %v", key.Priv, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
out.Keys = append(out.Keys, &keygen.UnencryptedKeys{
|
2019-09-10 14:24:14 +00:00
|
|
|
ValidatorKey: pk,
|
2019-09-09 21:31:19 +00:00
|
|
|
WithdrawalKey: pk,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
outFile, err := os.Create(os.Args[2])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to create file at %s: %v", os.Args[2], err)
|
|
|
|
}
|
2020-10-04 15:03:10 +00:00
|
|
|
cleanup := func() {
|
2020-04-13 04:11:09 +00:00
|
|
|
if err := outFile.Close(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-10-04 15:03:10 +00:00
|
|
|
}
|
|
|
|
defer cleanup()
|
2019-09-09 21:31:19 +00:00
|
|
|
if err := keygen.SaveUnencryptedKeysToFile(outFile, out); err != nil {
|
2020-10-04 15:03:10 +00:00
|
|
|
// log.Fatalf will prevent defer from being called
|
|
|
|
cleanup()
|
2019-09-09 21:31:19 +00:00
|
|
|
log.Fatalf("Failed to save %v", err)
|
|
|
|
}
|
|
|
|
log.Printf("Wrote %s\n", os.Args[2])
|
|
|
|
}
|