Skip to content

Commit

Permalink
config: trim leading/trailing white space priv key
Browse files Browse the repository at this point in the history
  • Loading branch information
jchappelow committed Sep 6, 2023
1 parent 6ddaf63 commit dddbc49
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/app/kwild/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"bytes"
"encoding/hex"
"fmt"
"os"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit dddbc49

Please sign in to comment.