Skip to content

Commit

Permalink
fix: hide private key
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Jun 20, 2024
1 parent 37b0740 commit 2751b08
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func main() {

openPrometheusAndPprof(cfg.Debug.ListenAddr)

log.Infow("bsc mev-sentry start", "configPath", *configPath, "config", cfg)
hidedCfg, _ := cfg.HidePrivateKey()
log.Infow("bsc mev-sentry start", "configPath", *configPath, "config", hidedCfg)

validators := make(map[string]node.Validator)
for _, v := range cfg.Validators {
Expand Down
19 changes: 19 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"reflect"
"unicode"

jsoniter "github.com/json-iterator/go"
"github.com/naoina/toml"

"github.com/bnb-chain/bsc-mev-sentry/node"
Expand Down Expand Up @@ -39,6 +40,24 @@ func Load(file string) *Config {
return &cfg
}

func (c *Config) HidePrivateKey() (*Config, error) {
origJSON, err := jsoniter.Marshal(c)
if err != nil {
return nil, err
}

clone := Config{}
if err = jsoniter.Unmarshal(origJSON, &clone); err != nil {
return nil, err
}

for i, _ := range clone.Validators {

Check failure on line 54 in config/config.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.21.x, ubuntu-latest)

S1005: unnecessary assignment to the blank identifier (gosimple)
clone.Validators[i].SentryPrivateKey = ""
}

return &clone, nil
}

// TomlSettings - These settings ensure that TOML keys use the same names as Go struct fields.
var tomlSettings = toml.Config{
NormFieldName: func(rt reflect.Type, key string) string {
Expand Down
28 changes: 14 additions & 14 deletions node/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ type ValidatorConfig struct {
PrivateURL string
PublicHostName string

PayAccountMode account.Mode
// PrivateKey private key of sentry wallet
PrivateKey string
// KeystorePath path of keystore
KeystorePath string
// PasswordFilePath stores keystore password
PasswordFilePath string
// PayAccountAddress public address of sentry wallet
PayAccountAddress string
SentryAccountMode account.Mode
// SentryPrivateKey private key of sentry wallet
SentryPrivateKey string
// SentryKeystorePath path of sentry keystore
SentryKeystorePath string
// SentryPasswordFilePath stores sentry keystore password
SentryPasswordFilePath string
// SentryAddress public address of sentry wallet
SentryAddress string
}

func NewValidator(config ValidatorConfig) Validator {
Expand All @@ -77,11 +77,11 @@ func NewValidator(config ValidatorConfig) Validator {
}

acc, err := account.New(&account.Config{
Mode: config.PayAccountMode,
PrivateKey: config.PrivateKey,
KeystorePath: config.KeystorePath,
PasswordFilePath: config.PasswordFilePath,
Address: config.PayAccountAddress})
Mode: config.SentryAccountMode,
PrivateKey: config.SentryPrivateKey,
KeystorePath: config.SentryKeystorePath,
PasswordFilePath: config.SentryPasswordFilePath,
Address: config.SentryAddress})
if err != nil {
log.Panicw("failed to create payAccount", "err", err)
}
Expand Down

0 comments on commit 2751b08

Please sign in to comment.