Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: trim leading/trailing white space priv key #275

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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