Skip to content
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

added derive_operatorid command to egnkey #247

Merged
merged 2 commits into from
May 30, 2024
Merged
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
39 changes: 39 additions & 0 deletions cmd/egnkey/derive_operatorid/derive_operatorid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package derive_operatorid
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved

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/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/derive_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,
derive_operatorid.Command,
}

app.Usage = "Used to manage batch keys for testing"
Expand Down
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
Loading