github.com/prysmaticlabs/prysm@v1.4.4/tools/unencrypted-keys-gen/keygen/keygen.go (about) 1 package keygen 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io" 7 8 log "github.com/sirupsen/logrus" 9 ) 10 11 // UnencryptedKeysContainer defines the structure of the unecrypted key JSON file. 12 type UnencryptedKeysContainer struct { 13 Keys []*UnencryptedKeys `json:"keys"` 14 } 15 16 // UnencryptedKeys is the inner struct of the JSON file. 17 type UnencryptedKeys struct { 18 ValidatorKey []byte `json:"validator_key"` 19 WithdrawalKey []byte `json:"withdrawal_key"` 20 } 21 22 // SaveUnencryptedKeysToFile JSON encodes the container and writes to the writer. 23 func SaveUnencryptedKeysToFile(w io.Writer, ctnr *UnencryptedKeysContainer) error { 24 enc, err := json.Marshal(ctnr) 25 if err != nil { 26 log.Fatal(err) 27 } 28 n, err := w.Write(enc) 29 if err != nil { 30 return err 31 } 32 if n != len(enc) { 33 return fmt.Errorf("failed to write %d bytes to file, wrote %d", len(enc), n) 34 } 35 return nil 36 }