Skip to content

Commit

Permalink
refactor signer to it's own config (#151)
Browse files Browse the repository at this point in the history
* refactor signer to it's own config

* replace in create

* fix unmarshall

* remove print

* chainid to int64
  • Loading branch information
shrimalmadhur authored Jul 3, 2024
1 parent 3fc61e6 commit c6c9887
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 71 deletions.
28 changes: 14 additions & 14 deletions pkg/operator/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O

switch signerType {
case "local_keystore":
config.SignerType = types.LocalKeystoreSigner
config.SignerConfig.SignerType = types.LocalKeystoreSigner
// Prompt for ecdsa key path
ecdsaKeyPath, err := p.InputString("Enter your ecdsa key path:", "", "",
func(s string) error {
Expand All @@ -211,9 +211,9 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.PrivateKeyStorePath = ecdsaKeyPath
config.SignerConfig.PrivateKeyStorePath = ecdsaKeyPath
case "fireblocks":
config.SignerType = types.FireBlocksSigner
config.SignerConfig.SignerType = types.FireBlocksSigner
// Prompt for fireblocks API key
apiKey, err := p.InputString("Enter your fireblocks api key:", "", "",
func(s string) error {
Expand All @@ -226,7 +226,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.FireblocksConfig.APIKey = apiKey
config.SignerConfig.FireblocksConfig.APIKey = apiKey

// Prompt for fireblocks base url
baseUrl, err := p.InputString("Enter your fireblocks base url:", "https://api.fireblocks.io/", "",
Expand All @@ -240,7 +240,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.FireblocksConfig.BaseUrl = baseUrl
config.SignerConfig.FireblocksConfig.BaseUrl = baseUrl

// Prompt for fireblocks vault account name
vaultAccountName, err := p.InputString("Enter the name of fireblocks vault:", "", "",
Expand All @@ -254,7 +254,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.FireblocksConfig.VaultAccountName = vaultAccountName
config.SignerConfig.FireblocksConfig.VaultAccountName = vaultAccountName

// Prompt for fireblocks API timeout
timeout, err := p.InputInteger("Enter the timeout for fireblocks API (in seconds):", "3", "",
Expand All @@ -268,7 +268,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.FireblocksConfig.Timeout = timeout
config.SignerConfig.FireblocksConfig.Timeout = timeout

// Prompt for fireblocks vault account name
secretStorageType, err := p.Select(
Expand All @@ -277,13 +277,13 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
)
switch secretStorageType {
case "Plain Text":
config.FireblocksConfig.SecretStorageType = types.PlainText
config.FireblocksConfig.SecretKey = "<FILL-ME>"
config.SignerConfig.FireblocksConfig.SecretStorageType = types.PlainText
config.SignerConfig.FireblocksConfig.SecretKey = "<FILL-ME>"
fmt.Println()
fmt.Println("Please fill in the secret key in the operator.yaml file")
fmt.Println()
case "AWS Secret Manager":
config.FireblocksConfig.SecretStorageType = types.AWSSecretManager
config.SignerConfig.FireblocksConfig.SecretStorageType = types.AWSSecretManager
keyName, err := p.InputString("Enter the name of the secret in AWS Secret Manager:", "", "",
func(s string) error {
if len(s) == 0 {
Expand All @@ -295,7 +295,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.FireblocksConfig.SecretKey = keyName
config.SignerConfig.FireblocksConfig.SecretKey = keyName
awsRegion, err := p.InputString("Enter the AWS region where the secret is stored:", "us-east-1", "",
func(s string) error {
if len(s) == 0 {
Expand All @@ -307,14 +307,14 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.FireblocksConfig.AWSRegion = awsRegion
config.SignerConfig.FireblocksConfig.AWSRegion = awsRegion

}
if err != nil {
return types.OperatorConfig{}, err
}
case "web3":
config.SignerType = types.Web3Signer
config.SignerConfig.SignerType = types.Web3Signer
// Prompt for fireblocks API key
web3SignerUrl, err := p.InputString("Enter your web3 signer url:", "", "",
func(s string) error {
Expand All @@ -327,7 +327,7 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
if err != nil {
return types.OperatorConfig{}, err
}
config.Web3SignerConfig.Url = web3SignerUrl
config.SignerConfig.Web3SignerConfig.Url = web3SignerUrl
default:
return types.OperatorConfig{}, fmt.Errorf("unknown signer type %s", signerType)
}
Expand Down
39 changes: 20 additions & 19 deletions pkg/operator/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

"github.com/Layr-Labs/eigensdk-go/aws/secretmanager"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks"
Expand Down Expand Up @@ -43,7 +44,7 @@ func getWallet(
logger eigensdkLogger.Logger,
) (wallet.Wallet, common.Address, error) {
var keyWallet wallet.Wallet
if cfg.SignerType == types.LocalKeystoreSigner {
if cfg.SignerConfig.SignerType == types.LocalKeystoreSigner {
// Check if input is available in the pipe and read the password from it
ecdsaPassword, readFromPipe := utils.GetStdInPassword()
var err error
Expand All @@ -61,14 +62,14 @@ func getWallet(

// This is to expand the tilde in the path to the home directory
// This is not supported by Go's standard library
keyFullPath, err := expandTilde(cfg.PrivateKeyStorePath)
keyFullPath, err := expandTilde(cfg.SignerConfig.PrivateKeyStorePath)
if err != nil {
return nil, common.Address{}, err
}
cfg.PrivateKeyStorePath = keyFullPath
cfg.SignerConfig.PrivateKeyStorePath = keyFullPath

signerCfg := signerv2.Config{
KeystorePath: cfg.PrivateKeyStorePath,
KeystorePath: cfg.SignerConfig.PrivateKeyStorePath,
Password: ecdsaPassword,
}
sgn, sender, err := signerv2.SignerFromConfig(signerCfg, &cfg.ChainId)
Expand All @@ -80,37 +81,37 @@ func getWallet(
return nil, common.Address{}, err
}
return keyWallet, sender, nil
} else if cfg.SignerType == types.FireBlocksSigner {
} else if cfg.SignerConfig.SignerType == types.FireBlocksSigner {
var secretKey string
var err error
switch cfg.FireblocksConfig.SecretStorageType {
switch cfg.SignerConfig.FireblocksConfig.SecretStorageType {
case types.PlainText:
logger.Info("Using plain text secret storage")
secretKey = cfg.FireblocksConfig.SecretKey
secretKey = cfg.SignerConfig.FireblocksConfig.SecretKey
case types.AWSSecretManager:
logger.Info("Using AWS secret manager to get fireblocks secret key")
secretKey, err = secretmanager.ReadStringFromSecretManager(
context.Background(),
cfg.FireblocksConfig.SecretKey,
cfg.FireblocksConfig.AWSRegion,
cfg.SignerConfig.FireblocksConfig.SecretKey,
cfg.SignerConfig.FireblocksConfig.AWSRegion,
)
if err != nil {
return nil, common.Address{}, err
}
logger.Infof("Secret key with name %s from region %s read from AWS secret manager",
cfg.FireblocksConfig.SecretKey,
cfg.FireblocksConfig.AWSRegion,
cfg.SignerConfig.FireblocksConfig.SecretKey,
cfg.SignerConfig.FireblocksConfig.AWSRegion,
)
default:
return nil, common.Address{}, fmt.Errorf("secret storage type %s is not supported",
cfg.FireblocksConfig.SecretStorageType,
cfg.SignerConfig.FireblocksConfig.SecretStorageType,
)
}
fireblocksClient, err := fireblocks.NewClient(
cfg.FireblocksConfig.APIKey,
cfg.SignerConfig.FireblocksConfig.APIKey,
[]byte(secretKey),
cfg.FireblocksConfig.BaseUrl,
time.Duration(cfg.FireblocksConfig.Timeout)*time.Second,
cfg.SignerConfig.FireblocksConfig.BaseUrl,
time.Duration(cfg.SignerConfig.FireblocksConfig.Timeout)*time.Second,
logger,
)
if err != nil {
Expand All @@ -119,7 +120,7 @@ func getWallet(
keyWallet, err = wallet.NewFireblocksWallet(
fireblocksClient,
ethClient,
cfg.FireblocksConfig.VaultAccountName,
cfg.SignerConfig.FireblocksConfig.VaultAccountName,
logger,
)
if err != nil {
Expand All @@ -130,9 +131,9 @@ func getWallet(
return nil, common.Address{}, err
}
return keyWallet, sender, nil
} else if cfg.SignerType == types.Web3Signer {
} else if cfg.SignerConfig.SignerType == types.Web3Signer {
signerCfg := signerv2.Config{
Endpoint: cfg.Web3SignerConfig.Url,
Endpoint: cfg.SignerConfig.Web3SignerConfig.Url,
Address: cfg.Operator.Address,
}
sgn, sender, err := signerv2.SignerFromConfig(signerCfg, &cfg.ChainId)
Expand All @@ -145,7 +146,7 @@ func getWallet(
}
return keyWallet, sender, nil
} else {
return nil, common.Address{}, fmt.Errorf("%s signer is not supported", cfg.SignerType)
return nil, common.Address{}, fmt.Errorf("%s signer is not supported", cfg.SignerConfig.SignerType)
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/operator/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package operator
import (
"context"
"fmt"

"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

Expand Down
1 change: 0 additions & 1 deletion pkg/operator/setclaimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Set the rewards claimer address for the operator.
AvsDirectoryAddress: common.HexToAddress(operatorCfg.ELAVSDirectoryAddress),
RewardsCoordinatorAddress: common.HexToAddress(operatorCfg.ELRewardsCoordinatorAddress),
}
fmt.Println(operatorCfg)

elWriter, err := elcontracts.NewWriterFromConfig(contractCfg, ethClient, logger, noopMetrics, txMgr)
if err != nil {
Expand Down
59 changes: 59 additions & 0 deletions pkg/types/fireblocks_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package types

type FireblocksConfig struct {
APIKey string `yaml:"api_key"`
SecretKey string `yaml:"secret_key"`
BaseUrl string `yaml:"base_url"`
VaultAccountName string `yaml:"vault_account_name"`

SecretStorageType SecretStorageType `yaml:"secret_storage_type"`

// AWSRegion is the region where the secret is stored in AWS Secret Manager
AWSRegion string `yaml:"aws_region"`

// Timeout for API in seconds
Timeout int64 `yaml:"timeout"`
}

func (f *FireblocksConfig) MarshalYAML() (interface{}, error) {
return struct {
APIKey string `yaml:"api_key"`
SecretKey string `yaml:"secret_key"`
BaseUrl string `yaml:"base_url"`
VaultAccountName string `yaml:"vault_account_name"`
SecretStorageType SecretStorageType `yaml:"secret_storage_type"`
AWSRegion string `yaml:"aws_region"`
Timeout int64 `yaml:"timeout"`
}{
APIKey: f.APIKey,
SecretKey: f.SecretKey,
BaseUrl: f.BaseUrl,
VaultAccountName: f.VaultAccountName,
SecretStorageType: f.SecretStorageType,
AWSRegion: f.AWSRegion,
Timeout: f.Timeout,
}, nil
}

func (f *FireblocksConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
var aux struct {
APIKey string `yaml:"api_key"`
SecretKey string `yaml:"secret_key"`
BaseUrl string `yaml:"base_url"`
VaultAccountName string `yaml:"vault_account_name"`
SecretStorageType SecretStorageType `yaml:"secret_storage_type"`
AWSRegion string `yaml:"aws_region"`
Timeout int64 `yaml:"timeout"`
}
if err := unmarshal(&aux); err != nil {
return err
}
f.APIKey = aux.APIKey
f.SecretKey = aux.SecretKey
f.BaseUrl = aux.BaseUrl
f.VaultAccountName = aux.VaultAccountName
f.SecretStorageType = aux.SecretStorageType
f.AWSRegion = aux.AWSRegion
f.Timeout = aux.Timeout
return nil
}
Loading

0 comments on commit c6c9887

Please sign in to comment.