Skip to content

Commit

Permalink
added derive_operatorid command to egnkey (#247)
Browse files Browse the repository at this point in the history
* added derive_operatorid command to egnkey
also refactored commands to be in their own packages to prevent var/flag conflicts

* update pkg name: derive_operatorid -> operatorid
  • Loading branch information
samlaf authored May 30, 2024
1 parent d3cc43d commit d7928dd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/egnkey/generate.go → cmd/egnkey/generate/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package generate

import (
"encoding/hex"
Expand Down Expand Up @@ -42,7 +42,7 @@ var (
}
)

var commandGenerate = &cli.Command{
var Command = &cli.Command{
Name: "generate",
Aliases: []string{"g"},
Description: `Generate keys for testing purpose.
Expand Down
8 changes: 6 additions & 2 deletions cmd/egnkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"
Expand Down
39 changes: 39 additions & 0 deletions cmd/egnkey/operatorid/operatorid.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions cmd/egnkey/store.go → cmd/egnkey/store/store.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package store

import (
"github.com/Layr-Labs/eigensdk-go/crypto/ecdsa"
Expand All @@ -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.`,
Expand Down

0 comments on commit d7928dd

Please sign in to comment.