Skip to content

Commit

Permalink
make ecdsa optional for certain operations
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Apr 25, 2024
1 parent cb32efd commit c942910
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
34 changes: 22 additions & 12 deletions node/plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"

"log"
"os"
"strings"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/Layr-Labs/eigenda/node"
"github.com/Layr-Labs/eigenda/node/plugin"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"

"github.com/ethereum/go-ethereum/accounts/keystore"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -69,12 +72,16 @@ func pluginOps(ctx *cli.Context) {

operatorID := keyPair.GetPubKeyG1().GetOperatorID()

sk, privateKey, err := plugin.GetECDSAPrivateKey(config.EcdsaKeyFile, config.EcdsaKeyPassword)
if err != nil {
log.Printf("Error: failed to read or decrypt the ECDSA private key: %v", err)
return
var sk *keystore.Key
var privateKey *string
if config.Operation != plugin.OperationListQuorums {
sk, privateKey, err = plugin.GetECDSAPrivateKey(config.EcdsaKeyFile, config.EcdsaKeyPassword)
if err != nil {
log.Printf("Error: failed to read or decrypt the ECDSA private key: %v", err)
return
}
log.Printf("Info: ECDSA key read and decrypted from %s", config.EcdsaKeyFile)
}
log.Printf("Info: ECDSA key read and decrypted from %s", config.EcdsaKeyFile)

loggerConfig := common.DefaultLoggerConfig()
logger, err := common.NewLogger(loggerConfig)
Expand Down Expand Up @@ -117,6 +124,16 @@ func pluginOps(ctx *cli.Context) {
}
}

if config.Operation == plugin.OperationListQuorums {
quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID)
if err != nil {
log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err)
return
}
log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, sk.Address, quorumIds)
return
}

operator := &node.Operator{
Address: sk.Address.Hex(),
Socket: socket,
Expand Down Expand Up @@ -152,13 +169,6 @@ func pluginOps(ctx *cli.Context) {
return
}
log.Printf("Info: successfully updated socket, for operator ID: %x, operator address: %x, socket: %s", operatorID, sk.Address, config.Socket)
} else if config.Operation == plugin.OperationListQuorums {
quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID)
if err != nil {
log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err)
return
}
log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, sk.Address, quorumIds)
} else {
log.Fatalf("Fatal: unsupported operation: %s", config.Operation)
}
Expand Down
8 changes: 6 additions & 2 deletions node/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
// The files for encrypted private keys.
EcdsaKeyFileFlag = cli.StringFlag{
Name: "ecdsa-key-file",
Required: true,
Required: false,
Usage: "Path to the encrypted ecdsa key",
EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "ECDSA_KEY_FILE"),
}
Expand All @@ -53,7 +53,7 @@ var (
// The passwords to decrypt the private keys.
EcdsaKeyPasswordFlag = cli.StringFlag{
Name: "ecdsa-key-password",
Required: true,
Required: false,
Usage: "Password to decrypt the ecdsa key",
EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "ECDSA_KEY_PASSWORD"),
}
Expand Down Expand Up @@ -150,6 +150,10 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
return nil, errors.New("unsupported operation type")
}

if op != OperationListQuorums && len(ctx.GlobalString(EcdsaKeyFileFlag.Name)) == 0 && len(ctx.GlobalString(EcdsaKeyPasswordFlag.Name)) == 0 {
return nil, errors.New("opt-in, opt-out and update-socket operations require ECDSA key file and password")
}

return &Config{
PubIPProvider: ctx.GlobalString(PubIPProviderFlag.Name),
Operation: op,
Expand Down

0 comments on commit c942910

Please sign in to comment.