From 77c52d1ee3e329cb40367b760ea701e958a59d71 Mon Sep 17 00:00:00 2001 From: Jonathan Chappelow Date: Wed, 6 Sep 2023 11:38:27 -0500 Subject: [PATCH] config: trim leading/trailing white space priv key --- internal/app/kwild/config/config.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/app/kwild/config/config.go b/internal/app/kwild/config/config.go index 2492fe0dd..de877e926 100644 --- a/internal/app/kwild/config/config.go +++ b/internal/app/kwild/config/config.go @@ -1,6 +1,7 @@ package config import ( + "bytes" "encoding/hex" "fmt" "os" @@ -193,14 +194,14 @@ func (cfg *KwildConfig) LoadGenesisAndPrivateKey(autoGen bool) error { */ if fileExists(cfg.AppCfg.PrivateKeyPath) { fmt.Println("Loading private key from file: ", cfg.AppCfg.PrivateKeyPath) - pkeyBytes, err := os.ReadFile(cfg.AppCfg.PrivateKeyPath) + privKeyHex, err := os.ReadFile(cfg.AppCfg.PrivateKeyPath) if err != nil { return fmt.Errorf("error reading private key file: %v", err) } - cfg.AppCfg.PrivateKey = string(pkeyBytes) + cfg.AppCfg.PrivateKey = string(bytes.TrimSpace(privKeyHex)) pkey, err = decodePrivateKey(cfg.AppCfg.PrivateKey) if err != nil { - return fmt.Errorf("error decoding private key: %v", err) + return fmt.Errorf("error decoding private key: %w", err) } } else if autoGen { pkey = ed25519.GenPrivKey() @@ -238,7 +239,7 @@ func (cfg *KwildConfig) LoadGenesisAndPrivateKey(autoGen bool) error { func decodePrivateKey(pkey string) (ed25519.PrivKey, error) { privB, err := hex.DecodeString(pkey) if err != nil { - return nil, fmt.Errorf("error decoding private key: %v", err) + return nil, err } return ed25519.PrivKey(privB), nil }