Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions cmd/operatorcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var commandEncrypt = &cli.Command{
Flags: []cli.Flag{
flag.EcdsaPrivateKeyFlag,
flag.BlsPrivateKeyFlag,
flag.PassphraseFlag,
flag.BlsPassphraseFlag,
flag.EcdsaPassphraseFlag,
flag.EcdsaAliasedPassphraseFlag,
flag.KeyStorePathFlag,
},
}
Expand All @@ -25,7 +27,9 @@ var commandDecrypt = &cli.Command{
Description: "Decrypt the ecdsa and bls private keys",
Action: runDecrypt,
Flags: []cli.Flag{
flag.PassphraseFlag,
flag.BlsPassphraseFlag,
flag.EcdsaPassphraseFlag,
flag.EcdsaAliasedPassphraseFlag,
flag.KeyStorePathFlag,
},
}
Expand All @@ -37,7 +41,8 @@ var commandRegister = &cli.Command{
Flags: []cli.Flag{
flag.EthRPCFlag,
flag.RegistryCoordinatorFlag,
flag.PassphraseFlag,
flag.BlsPassphraseFlag,
flag.EcdsaPassphraseFlag,
flag.KeyStorePathFlag,
flag.SaltFlag,
flag.ExpiryFlag,
Expand All @@ -56,7 +61,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 +75,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 @@ -101,7 +106,8 @@ var commandDeclareAlias = &cli.Command{
Description: "Declare the alias in the eochain",
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
85 changes: 53 additions & 32 deletions internal/operatorcli/operator_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ type avsClient struct {
}

func RunEncrypt(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
if passphrase == "" {
return cli.Exit("passphrase is required", 1)
blsPassphrase := c.String(flag.BlsPassphraseFlag.Name)
if blsPassphrase == "" {
return cli.Exit("BLS passphrase is required", 1)
}

ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
if ecdsaPassphrase == "" {
return cli.Exit("ECDSA passphrase is required", 1)
}

keyStorePath := c.String(flag.KeyStorePathFlag.Name)
Expand All @@ -63,7 +68,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 +79,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 @@ -83,29 +88,39 @@ func RunEncrypt(c *cli.Context) error {
}

func RunDecrypt(c *cli.Context) error {
passphrase := c.String(flag.PassphraseFlag.Name)
if passphrase == "" {
return cli.Exit("passphrase is required", 1)
blsPassphrase := c.String(flag.BlsPassphraseFlag.Name)
if blsPassphrase == "" {
return cli.Exit("BLS passphrase is required", 1)
}

ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
if ecdsaPassphrase == "" {
return cli.Exit("ECDSA passphrase is required", 1)
}

ecdsaAliasedPassphrase := c.String(flag.EcdsaAliasedPassphraseFlag.Name)
if ecdsaAliasedPassphrase == "" {
return cli.Exit("ECDSA aliased passphrase is required", 1)
}

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 @@ -119,7 +134,8 @@ func RunDecrypt(c *cli.Context) error {
}

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

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

if passphrase == "" || keyStorePath == "" {
if ecdsaPassphrase == "" || blsPassphrase == "" || keyStorePath == "" {
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 +160,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 +303,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 +314,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 +391,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 +402,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 +411,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 +491,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 +524,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 +537,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 @@ -533,22 +549,27 @@ func RunDeclareAlias(c *cli.Context) error {
return cli.Exit(fmt.Sprintf("Error creating logger %v", err), 1)
}

passphrase := c.String(flag.PassphraseFlag.Name)
if passphrase == "" {
return cli.Exit("passphrase is required", 1)
ecdsaPassphrase := c.String(flag.EcdsaPassphraseFlag.Name)
if ecdsaPassphrase == "" {
return cli.Exit("ECDSA passphrase is required", 1)
}

ecdsaAliasedPassphrase := c.String(flag.EcdsaAliasedPassphraseFlag.Name)
if ecdsaAliasedPassphrase == "" {
return cli.Exit("ECDSA aliased passphrase is required", 1)
}

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