Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 12 additions & 2 deletions cmd/operatorcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var commandEncrypt = &cli.Command{
flag.EcdsaPrivateKeyFlag,
flag.BlsPrivateKeyFlag,
flag.PassphraseFlag,
flag.BlsPassphraseFlag,
flag.EcdsaPassphraseFlag,
flag.EcdsaAliasedPassphraseFlag,
flag.KeyStorePathFlag,
},
}
Expand All @@ -26,6 +29,9 @@ var commandDecrypt = &cli.Command{
Action: runDecrypt,
Flags: []cli.Flag{
flag.PassphraseFlag,
flag.BlsPassphraseFlag,
flag.EcdsaPassphraseFlag,
flag.EcdsaAliasedPassphraseFlag,
flag.KeyStorePathFlag,
},
}
Expand All @@ -38,6 +44,8 @@ var commandRegister = &cli.Command{
flag.EthRPCFlag,
flag.RegistryCoordinatorFlag,
flag.PassphraseFlag,
flag.BlsPassphraseFlag,
flag.EcdsaPassphraseFlag,
flag.KeyStorePathFlag,
flag.SaltFlag,
flag.ExpiryFlag,
Expand All @@ -56,7 +64,7 @@ var commandDeregister = &cli.Command{
Flags: []cli.Flag{
flag.EthRPCFlag,
flag.RegistryCoordinatorFlag,
flag.PassphraseFlag,
flag.EcdsaPassphraseFlag,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to support the old PassphraseFlag (for backward compatibility)

flag.KeyStorePathFlag,
flag.EcdsaPrivateKeyFlag,
flag.QuorumNumberFlag,
Expand All @@ -70,7 +78,7 @@ var commandPrintStatus = &cli.Command{
Flags: []cli.Flag{
flag.EthRPCFlag,
flag.RegistryCoordinatorFlag,
flag.PassphraseFlag,
flag.EcdsaPassphraseFlag,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to support the old PassphraseFlag (for backward compatibility)

flag.KeyStorePathFlag,
flag.EcdsaPrivateKeyFlag,
flag.QuorumNumberFlag,
Expand Down Expand Up @@ -102,6 +110,8 @@ var commandDeclareAlias = &cli.Command{
Action: runDeclareAlias,
Flags: []cli.Flag{
flag.PassphraseFlag,
flag.EcdsaPassphraseFlag,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare alias requires the ecdsa private key to sign and submit the transaction. The alias ecdsa is used to get the address of the alias

flag.EcdsaAliasedPassphraseFlag,
flag.KeyStorePathFlag,
flag.EOChainEthRPCFlag,
flag.EOConfigAddressFlag,
Expand Down
15 changes: 15 additions & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ var (
Usage: "passphrase to open the encrypted private key",
EnvVars: []string{"EO_PASSPHRASE"},
}
BlsPassphraseFlag = &cli.StringFlag{
Name: "bls-passphrase",
Usage: "passphrase to open the encrypted BLS private key",
EnvVars: []string{"EO_BLS_PASSPHRASE"},
}
EcdsaPassphraseFlag = &cli.StringFlag{
Name: "ecdsa-passphrase",
Usage: "passphrase to open the encrypted ECDSA private key",
EnvVars: []string{"EO_ECDSA_PASSPHRASE"},
}
EcdsaAliasedPassphraseFlag = &cli.StringFlag{
Name: "ecdsa-aliased-passphrase",
Usage: "passphrase to open the encrypted aliased ECDSA private key",
EnvVars: []string{"EO_ALIASED_ECDSA_PASSPHRASE"},
}
ValidatorRoleFlag = &cli.StringFlag{
Name: "validator-role",
Usage: "role of the operator",
Expand Down
83 changes: 58 additions & 25 deletions internal/operatorcli/operator_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ type avsClient struct {

func RunEncrypt(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
blsPassphrase := c.String(flag.BlsPassphraseFlag.Name)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)

if passphrase == "" {
return cli.Exit("passphrase is required", 1)
if blsPassphrase == "" || ecdsaPassphrase == "" {
return cli.Exit("either passphrase or bls/ecdsa passphrase is required", 1)
}
} else {
blsPassphrase = passphrase
ecdsaPassphrase = passphrase
}
Comment on lines 54 to 61
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to change the order of checking the flags.
first checks the new flags (the configuration we want to have)
second check the backward compatbility


keyStorePath := c.String(flag.KeyStorePathFlag.Name)
Expand All @@ -63,7 +71,7 @@ func RunEncrypt(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("Invalid EDCSA private key %v", err), 1)
}

if err = eigensdkecdsa.WriteKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPair, passphrase); err != nil {
if err = eigensdkecdsa.WriteKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPair, ecdsaPassphrase); err != nil {
return cli.Exit(fmt.Sprintf("Error writing the ecdsaEncryptedWallet.json file %v", err), 1)
}
fmt.Println("ecdsa address ", crypto.PubkeyToAddress(ecdsaPair.PublicKey), "saved")
Expand All @@ -74,7 +82,7 @@ func RunEncrypt(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("Invalid BLS private key %v", err), 1)
}

if err = blsKeyPair.SaveToFile(filepath.Join(keyStorePath, "blsEncryptedWallet.json"), passphrase); err != nil {
if err = blsKeyPair.SaveToFile(filepath.Join(keyStorePath, "blsEncryptedWallet.json"), blsPassphrase); err != nil {
return cli.Exit(fmt.Sprintf("Error writing the blsEncryptedWallet.json file %v", err), 1)
}
fmt.Println("bls address G1, G2 ", blsKeyPair.GetPubKeyG1().String(), ", ", blsKeyPair.GetPubKeyG2().String(), "saved")
Expand All @@ -84,28 +92,38 @@ func RunEncrypt(c *cli.Context) error {

func RunDecrypt(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
blsPassphrase := c.String(flag.BlsPassphraseFlag.Name)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
ecdsaAliasedPassphrase := c.String(flag.EcdsaAliasedPassphraseFlag.Name)

if passphrase == "" {
return cli.Exit("passphrase is required", 1)
if blsPassphrase == "" || ecdsaPassphrase == "" || ecdsaAliasedPassphrase == "" {
return cli.Exit("either passphrase or bls/ecdsa/aliased ecdsa passphrase is required", 1)
}
} else {
blsPassphrase = passphrase
ecdsaPassphrase = passphrase
ecdsaAliasedPassphrase = passphrase
}

keyStorePath := c.String(flag.KeyStorePathFlag.Name)
if keyStorePath == "" {
return cli.Exit("keystore-path is required", 1)
}

ecdsaPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), passphrase)
ecdsaPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Error reading the ecdsaEncryptedWallet.json file %v", err), 1)
}
fmt.Println("ecdsa address ", crypto.PubkeyToAddress(ecdsaPair.PublicKey), "private key", hex.EncodeToString(ecdsaPair.D.Bytes()))

blsKeyPair, err := eigensdkbls.ReadPrivateKeyFromFile(filepath.Join(keyStorePath, "blsEncryptedWallet.json"), passphrase)
blsKeyPair, err := eigensdkbls.ReadPrivateKeyFromFile(filepath.Join(keyStorePath, "blsEncryptedWallet.json"), blsPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Error reading the blsEncryptedWallet.json file %v", err), 1)
}
fmt.Println("bls address G1, G2 ", blsKeyPair.GetPubKeyG1().String(), ", ", blsKeyPair.GetPubKeyG2().String(), "private key", blsKeyPair.PrivKey.String())

ecdsaEOChainPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaAliasedEncryptedWallet.json"), passphrase)
ecdsaEOChainPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaAliasedEncryptedWallet.json"), ecdsaAliasedPassphrase)
if err != nil {
if err == os.ErrNotExist {
fmt.Println("eochain alias was not set in the system")
Expand All @@ -120,6 +138,8 @@ func RunDecrypt(c *cli.Context) error {

func RunRegister(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
blsPassphrase := c.String(flag.BlsPassphraseFlag.Name)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
keyStorePath := c.String(flag.KeyStorePathFlag.Name)

var ecdsaPair *ecdsa.PrivateKey
Expand All @@ -131,9 +151,14 @@ func RunRegister(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("error creating logger %v", err), 1)
}

if passphrase == "" || keyStorePath == "" {
if passphrase != "" {
blsPassphrase = passphrase
ecdsaPassphrase = passphrase
}
Comment on lines +154 to +157
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is default value to passphrase this will be true.
Need to reverse the order (or check if the new flags are empty)


if blsPassphrase == "" || ecdsaPassphrase == "" || keyStorePath == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the new approach of having a passphrase per key, need to spilt this if into smaller and unrelated it statements

if c.String(flag.EcdsaPrivateKeyFlag.Name) == "" || c.String(flag.BlsPrivateKeyFlag.Name) == "" {
return cli.Exit("either passphrase and keystore-path or ecdsa-private-key and bls-private-key are required", 1)
return cli.Exit("either ecdsa/bls passphrase and keystore-path or ecdsa-private-key and bls-private-key are required", 1)
}
ecdsaPair, err = crypto.HexToECDSA(c.String(flag.EcdsaPrivateKeyFlag.Name))
if err != nil {
Expand All @@ -144,11 +169,11 @@ func RunRegister(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("Invalid BLS private key %v", err), 1)
}
} else {
ecdsaPair, err = eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), passphrase)
ecdsaPair, err = eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Failed to read ecdsaEncryptedWallet.json file %v", err), 1)
}
blsKeyPair, err = eigensdkbls.ReadPrivateKeyFromFile(filepath.Join(keyStorePath, "blsEncryptedWallet.json"), passphrase)
blsKeyPair, err = eigensdkbls.ReadPrivateKeyFromFile(filepath.Join(keyStorePath, "blsEncryptedWallet.json"), blsPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Failed to read blsEncryptedWallet.json file %v", err), 1)
}
Expand Down Expand Up @@ -287,7 +312,7 @@ func RunRegister(c *cli.Context) error {
}

func RunDeregister(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only override the general passphrase if the dedicated one is not provided, like the encrypt command works no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since deregister doesn't require more than one password i've left it as it is, but made it explicit with ecdsa passphrase flag that it is ecdsa key password

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be backward compatibility, so we should pass the two passphrase flags use the backward compatibility flag if the correct flag is empty

keyStorePath := c.String(flag.KeyStorePathFlag.Name)

var ecdsaPair *ecdsa.PrivateKey
Expand All @@ -298,16 +323,16 @@ func RunDeregister(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("error creating logger %v", err), 1)
}

if passphrase == "" || keyStorePath == "" {
if ecdsaPassphrase == "" || keyStorePath == "" {
if c.String(flag.EcdsaPrivateKeyFlag.Name) == "" {
return cli.Exit("either passphrase and keystore-path or ecdsa-private-key are required", 1)
return cli.Exit("either ecdsa/bls passphrase and keystore-path or ecdsa-private-key are required", 1)
}
ecdsaPair, err = crypto.HexToECDSA(c.String(flag.EcdsaPrivateKeyFlag.Name))
if err != nil {
return cli.Exit(fmt.Sprintf("Invalid EDCSA private key %v", err), 1)
}
} else {
ecdsaPair, err = eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), passphrase)
ecdsaPair, err = eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Failed to read ecdsaEncryptedWallet.json file %v", err), 1)
}
Expand Down Expand Up @@ -375,7 +400,7 @@ func RunDeregister(c *cli.Context) error {
}

func RunPrintStatus(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same issue as decrypt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback to the deregister

keyStorePath := c.String(flag.KeyStorePathFlag.Name)

var ecdsaPair *ecdsa.PrivateKey
Expand All @@ -386,7 +411,7 @@ func RunPrintStatus(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("error creating logger %v", err), 1)
}

if passphrase == "" || keyStorePath == "" {
if ecdsaPassphrase == "" || keyStorePath == "" {
if c.String(flag.EcdsaPrivateKeyFlag.Name) == "" {
return cli.Exit("either passphrase and keystore-path or ecdsa-private-key are required", 1)
}
Expand All @@ -395,7 +420,7 @@ func RunPrintStatus(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("Invalid EDCSA private key %v", err), 1)
}
} else {
ecdsaPair, err = eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), passphrase)
ecdsaPair, err = eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Failed to read ecdsaEncryptedWallet.json file %v", err), 1)
}
Expand Down Expand Up @@ -475,15 +500,15 @@ func RunGenerateAlias(c *cli.Context) error {
}

// The following summarizes the logic of setting the alias in the eochain
// An alias exists | specified as argument | override flag | expected behavior
// An alias exists | specified as argument | override flag | expected behavior
// yes | no | no | use the existing value
// yes | no | yes | use the existing value
// yes | yes | no | return an error
// yes | yes | yes | use the value from the cli
// no | no | no | generate a new value
// no | no | yes | generate a new value
// no | yes | no | use the value from the cli
// no | yes | yes | use the value from the cli
// no | yes | yes | use the value from the cli

var err error
var aliasEcdsaPair *ecdsa.PrivateKey
Expand All @@ -508,7 +533,7 @@ func RunGenerateAlias(c *cli.Context) error {
if c.String(flag.EcdsaPrivateKeyFlag.Name) != "" {
if !c.Bool(flag.OverrideFlag.Name) {
return cli.Exit("The alias key already exists, cannot override", 1)
}
}
// Use the private key passed in the command line
aliasEcdsaPair, err = crypto.HexToECDSA(c.String(flag.EcdsaPrivateKeyFlag.Name))
if err != nil {
Expand All @@ -521,7 +546,7 @@ func RunGenerateAlias(c *cli.Context) error {
if err = eigensdkecdsa.WriteKey(filepath.Join(keyStorePath, "ecdsaAliasedEncryptedWallet.json"), aliasEcdsaPair, passphrase); err != nil {
return cli.Exit(fmt.Sprintf("Error writing the ecdsaAliasedEncryptedWallet.json file %v", err), 1)
}

fmt.Println("alias ecdsa address ", crypto.PubkeyToAddress(aliasEcdsaPair.PublicKey), "encrpyted and saved")

return nil
Expand All @@ -534,21 +559,29 @@ func RunDeclareAlias(c *cli.Context) error {
}

passphrase := c.String(flag.PassphraseFlag.Name)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
ecdsaAliasedPassphrase := c.String(flag.EcdsaAliasedPassphraseFlag.Name)

if passphrase == "" {
return cli.Exit("passphrase is required", 1)
if ecdsaPassphrase == "" || ecdsaAliasedPassphrase == "" {
return cli.Exit("either passphrase or ecdsa/aliased ecdsa passphrase is required", 1)
}
} else {
ecdsaPassphrase = passphrase
ecdsaAliasedPassphrase = passphrase
}

keyStorePath := c.String(flag.KeyStorePathFlag.Name)
if keyStorePath == "" {
return cli.Exit("keystore-path is required", 1)
}

ethEcdsaPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), passphrase)
ethEcdsaPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaEncryptedWallet.json"), ecdsaPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Failed to read ecdsaEncryptedWallet.json file %v", err), 1)
}

aliasEcdsaPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaAliasedEncryptedWallet.json"), passphrase)
aliasEcdsaPair, err := eigensdkecdsa.ReadKey(filepath.Join(keyStorePath, "ecdsaAliasedEncryptedWallet.json"), ecdsaAliasedPassphrase)
if err != nil {
return cli.Exit(fmt.Sprintf("Failed to read ecdsaAliasedEncryptedWallet.json file %v", err), 1)
}
Expand Down