Skip to content

fix: fix operator set registration command #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions pkg/internal/common/flags/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,16 @@ var (
Usage: "Used to execute an action on behalf of another user. See User Access Management documents for more details.",
EnvVars: []string{"CALLER_ADDRESS"},
}
RegistryCoordinatorAddressFlag = cli.StringFlag{
Name: "registry-coordinator-address",
Aliases: []string{"rca"},
Usage: "Address of the registry coordinator contract. This is required for registering an operator for operator sets",
EnvVars: []string{"REGISTRY_COORDINATOR_ADDRESS"},
}
BlsPrivateKeyFlag = cli.StringFlag{
Name: "bls-private-key",
Aliases: []string{"bls"},
Usage: "BLS private key of Operator for Operator Set registration",
EnvVars: []string{"BLS_PRIVATE_KEY"},
}
)
2 changes: 1 addition & 1 deletion pkg/internal/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func GetTransactionLink(txHash string, chainId *big.Int) string {
if !ok {
return txHash
} else {
return fmt.Sprintf("%s/%s", chainMetadata.BlockExplorerUrl, txHash)
return fmt.Sprintf("%s/tx/%s", chainMetadata.BlockExplorerUrl, txHash)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/common/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func TestGetTransactionLink(t *testing.T) {
name: "valid mainnet tx hash",
chainID: big.NewInt(1),
txHash: "0x123",
expectedTxLink: fmt.Sprintf("%s/%s", utils.MainnetBlockExplorerUrl, "0x123"),
expectedTxLink: fmt.Sprintf("%s/tx/%s", utils.MainnetBlockExplorerUrl, "0x123"),
},
{
name: "valid holesky tx hash",
chainID: big.NewInt(17000),
txHash: "0x123",
expectedTxLink: fmt.Sprintf("%s/%s", utils.HoleskyBlockExplorerUrl, "0x123"),
expectedTxLink: fmt.Sprintf("%s/tx/%s", utils.HoleskyBlockExplorerUrl, "0x123"),
},
{
name: "valid custom chain tx hash",
Expand Down
28 changes: 3 additions & 25 deletions pkg/keys/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package keys
import (
"crypto/ecdsa"
"fmt"
"math/big"
"strings"

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

"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/ethereum/go-ethereum/crypto"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -104,29 +102,9 @@ This command will import keys in $HOME/.eigenlayer/operator_keys/ location
}
return saveEcdsaKey(keyName, p, privateKeyPair, insecure, stdInPassword, readFromPipe, "")
case KeyTypeBLS:
privateKeyBigInt := new(big.Int)
_, ok := privateKeyBigInt.SetString(privateKey, 10)
var blsKeyPair *bls.KeyPair
var err error
if ok {
fmt.Println("Importing from large integer")
blsKeyPair, err = bls.NewKeyPairFromString(privateKey)
if err != nil {
return err
}
} else {
// Try to parse as hex
fmt.Println("Importing from hex")
z := new(big.Int)
privateKey = common.Trim0x(privateKey)
_, ok := z.SetString(privateKey, 16)
if !ok {
return ErrInvalidHexPrivateKey
}
blsKeyPair, err = bls.NewKeyPairFromString(z.String())
if err != nil {
return err
}
blsKeyPair, err := ParseBlsPrivateKey(privateKey)
if err != nil {
return err
}
return saveBlsKey(keyName, p, blsKeyPair, insecure, stdInPassword, readFromPipe)
default:
Expand Down
38 changes: 38 additions & 0 deletions pkg/keys/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package keys

import (
"fmt"
"math/big"

"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
)

// ParseBlsPrivateKey parses a BLS private key from a string either in hex or large integer format.
func ParseBlsPrivateKey(privateKey string) (*bls.KeyPair, error) {
privateKeyBigInt := new(big.Int)
_, ok := privateKeyBigInt.SetString(privateKey, 10)
var blsKeyPair *bls.KeyPair
var err error
if ok {
fmt.Println("Importing from large integer")
blsKeyPair, err = bls.NewKeyPairFromString(privateKey)
if err != nil {
return nil, err
}
} else {
// Try to parse as hex
fmt.Println("Importing from hex")
z := new(big.Int)
privateKey = common.Trim0x(privateKey)
_, ok := z.SetString(privateKey, 16)
if !ok {
return nil, ErrInvalidHexPrivateKey
}
blsKeyPair, err = bls.NewKeyPairFromString(z.String())
if err != nil {
return nil, err
}
}
return blsKeyPair, nil
}
53 changes: 38 additions & 15 deletions pkg/operator/register_operator_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/command"
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/keys"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
Expand Down Expand Up @@ -75,11 +76,12 @@ func (r RegisterOperatorSetCmd) Execute(cCtx *cli.Context) error {
}
receipt, err := eLWriter.RegisterForOperatorSets(
ctx,
config.callerAddress,
config.registryCoordinatorAddress,
elcontracts.RegistrationRequest{
OperatorAddress: config.operatorAddress,
AVSAddress: config.avsAddress,
OperatorSetIds: config.operatorSetIds,
BlsKeyPair: config.blsKeyPair,
WaitForReceipt: true,
})
if err != nil {
Expand Down Expand Up @@ -183,27 +185,46 @@ func readAndValidateRegisterOperatorSetsConfig(cCtx *cli.Context, logger logging
}
}

registryCoordinatorAddress := cCtx.String(flags.RegistryCoordinatorAddressFlag.Name)
if common.IsEmptyString(registryCoordinatorAddress) {
logger.Error("--registry-coordinator-address flag must be set")
return nil, fmt.Errorf("Empty registry coordinator address provided")
}

operatorSetIdsString := cCtx.Uint64Slice(flags.OperatorSetIdsFlag.Name)
operatorSetIds := make([]uint32, len(operatorSetIdsString))
for i, id := range operatorSetIdsString {
operatorSetIds[i] = uint32(id)
}

blsPrivateKey := cCtx.String(flags.BlsPrivateKeyFlag.Name)
if common.IsEmptyString(blsPrivateKey) {
logger.Error("--bls-private-key flag must be set")
return nil, fmt.Errorf("Empty BLS private key provided")
}

blsKeyPair, err := keys.ParseBlsPrivateKey(blsPrivateKey)
if err != nil {
return nil, err
}

config := &RegisterConfig{
avsAddress: avsAddress,
operatorSetIds: operatorSetIds,
operatorAddress: operatorAddress,
callerAddress: callerAddress,
network: network,
environment: environment,
broadcast: broadcast,
rpcUrl: rpcUrl,
chainID: chainId,
signerConfig: signerConfig,
output: output,
outputType: outputType,
delegationManagerAddress: gethcommon.HexToAddress(delegationManagerAddress),
isSilent: isSilent,
avsAddress: avsAddress,
operatorSetIds: operatorSetIds,
operatorAddress: operatorAddress,
callerAddress: callerAddress,
network: network,
environment: environment,
broadcast: broadcast,
rpcUrl: rpcUrl,
chainID: chainId,
signerConfig: signerConfig,
output: output,
outputType: outputType,
delegationManagerAddress: gethcommon.HexToAddress(delegationManagerAddress),
isSilent: isSilent,
registryCoordinatorAddress: gethcommon.HexToAddress(registryCoordinatorAddress),
blsKeyPair: blsKeyPair,
}

return config, nil
Expand All @@ -220,5 +241,7 @@ func getRegistrationFlags() []cli.Flag {
&flags.OperatorSetIdsFlag,
&flags.DelegationManagerAddressFlag,
&flags.SilentFlag,
&flags.RegistryCoordinatorAddressFlag,
&flags.BlsPrivateKeyFlag,
}
}
31 changes: 17 additions & 14 deletions pkg/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"

"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/ethereum/go-ethereum/common"
)

Expand All @@ -25,18 +26,20 @@ type DeregisterConfig struct {
}

type RegisterConfig struct {
avsAddress common.Address
operatorSetIds []uint32
operatorAddress common.Address
callerAddress common.Address
network string
environment string
broadcast bool
rpcUrl string
chainID *big.Int
signerConfig *types.SignerConfig
output string
outputType string
delegationManagerAddress common.Address
isSilent bool
avsAddress common.Address
operatorSetIds []uint32
operatorAddress common.Address
callerAddress common.Address
network string
environment string
broadcast bool
rpcUrl string
chainID *big.Int
signerConfig *types.SignerConfig
output string
outputType string
delegationManagerAddress common.Address
isSilent bool
registryCoordinatorAddress common.Address
blsKeyPair *bls.KeyPair
}
Loading