diff --git a/cmd/egnkey/generate.go b/cmd/egnkey/generate/generate.go similarity index 99% rename from cmd/egnkey/generate.go rename to cmd/egnkey/generate/generate.go index a2e3049c..28691e80 100644 --- a/cmd/egnkey/generate.go +++ b/cmd/egnkey/generate/generate.go @@ -1,4 +1,4 @@ -package main +package generate import ( "encoding/hex" @@ -42,7 +42,7 @@ var ( } ) -var commandGenerate = &cli.Command{ +var Command = &cli.Command{ Name: "generate", Aliases: []string{"g"}, Description: `Generate keys for testing purpose. diff --git a/cmd/egnkey/main.go b/cmd/egnkey/main.go index f45c06e8..bc2bb284 100644 --- a/cmd/egnkey/main.go +++ b/cmd/egnkey/main.go @@ -4,6 +4,9 @@ import ( "fmt" "os" + "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/operatorid" + "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/generate" + "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/store" "github.com/urfave/cli/v2" ) @@ -12,8 +15,9 @@ func main() { app.Name = "egnkey" app.Description = "Eigenlayer batch keys manager" app.Commands = []*cli.Command{ - commandGenerate, - commandStore, + generate.Command, + store.Command, + operatorid.Command, } app.Usage = "Used to manage batch keys for testing" diff --git a/cmd/egnkey/operatorid/operatorid.go b/cmd/egnkey/operatorid/operatorid.go new file mode 100644 index 00000000..2d91e676 --- /dev/null +++ b/cmd/egnkey/operatorid/operatorid.go @@ -0,0 +1,39 @@ +package operatorid + +import ( + "encoding/hex" + "fmt" + + "github.com/Layr-Labs/eigensdk-go/crypto/bls" + "github.com/Layr-Labs/eigensdk-go/types" + "github.com/urfave/cli/v2" +) + +var ( + PrivateKey = &cli.StringFlag{ + Name: "private-key", + Usage: "(bn254) private key from which to derive operatorId from", + Required: true, + } +) + +var Command = &cli.Command{ + Name: "derive-operator-id", + Aliases: []string{"d"}, + Description: `Given a private key, output its associated operatorId (hash of bn254 G1 pubkey).`, + Action: derive, + Flags: []cli.Flag{ + PrivateKey, + }, +} + +func derive(c *cli.Context) error { + sk := c.String(PrivateKey.Name) + keypair, err := bls.NewKeyPairFromString(sk) + if err != nil { + return err + } + operatorId := types.OperatorIdFromKeyPair(keypair) + fmt.Println("0x" + hex.EncodeToString(operatorId[:])) + return nil +} diff --git a/cmd/egnkey/store.go b/cmd/egnkey/store/store.go similarity index 95% rename from cmd/egnkey/store.go rename to cmd/egnkey/store/store.go index c4bedd3e..203023ff 100644 --- a/cmd/egnkey/store.go +++ b/cmd/egnkey/store/store.go @@ -1,4 +1,4 @@ -package main +package store import ( "github.com/Layr-Labs/eigensdk-go/crypto/ecdsa" @@ -25,7 +25,7 @@ var ( } ) -var commandStore = &cli.Command{ +var Command = &cli.Command{ Name: "convert", Aliases: []string{"c"}, Description: `Stores an ecdsa key to a file, in web3 secret storage format.`,