Skip to content

Commit

Permalink
chore: Add keygen CLI (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: mace <[email protected]>
  • Loading branch information
mj52951 and MakMuftic authored May 20, 2024
1 parent 14fdb0d commit 9d9a113
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/ChainSafe/sygma-relayer/cli/keygen"
"github.com/ChainSafe/sygma-relayer/cli/peer"
"github.com/ChainSafe/sygma-relayer/cli/topology"
"github.com/ChainSafe/sygma-relayer/cli/utils"
Expand All @@ -30,7 +31,7 @@ func init() {
}

func Execute() {
rootCMD.AddCommand(runCMD, peer.PeerCLI, topology.TopologyCLI, utils.UtilsCLI)
rootCMD.AddCommand(runCMD, peer.PeerCLI, topology.TopologyCLI, utils.UtilsCLI, keygen.KeygenCLI)
if err := rootCMD.Execute(); err != nil {
log.Fatal().Err(err).Msg("failed to execute root cmd")
}
Expand Down
17 changes: 17 additions & 0 deletions cli/keygen/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// The Licensed Work is (c) 2022 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

package keygen

import (
"github.com/spf13/cobra"
)

var KeygenCLI = &cobra.Command{
Use: "keygen",
Short: "Key generation",
}

func init() {
KeygenCLI.AddCommand(generateKeyCMD)
}
34 changes: 34 additions & 0 deletions cli/keygen/generateKey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// The Licensed Work is (c) 2022 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

package keygen

import (
"encoding/hex"
"fmt"

"github.com/spf13/cobra"
"github.com/sygmaprotocol/sygma-core/crypto/secp256k1"
)

var (
generateKeyCMD = &cobra.Command{
Use: "gen-key",
Short: "Generate keys for signing transactions",
Long: "Generate keys for signing transactions",
RunE: generateKey,
}
)

func generateKey(cmd *cobra.Command, args []string) error {
kp, err := secp256k1.GenerateKeypair()
if err != nil {
return err
}

privHex := hex.EncodeToString(kp.Encode())

fmt.Printf("Public key: %s\n", kp.PublicKey())
fmt.Printf("Private key: 0x%s\n", privHex)
return nil
}
12 changes: 11 additions & 1 deletion docs/general/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Introduction

This guide details specific Command Line Interface (CLI) commands for the Sygma relayer, focusing on functionalities provided in the `topology`, `peer`, and `utils` modules.
This guide details specific Command Line Interface (CLI) commands for the Sygma relayer, focusing on functionalities provided in the `topology`, `peer`, `keygen` and `utils` modules.

## Topology commands

Expand Down Expand Up @@ -52,6 +52,16 @@ Calculate a libp2p peer ID from the provided base64 encoded libp2p private key.
#### Flags:
- `--private-key`: Base64 encoded libp2p private key.

## Keygen commands

### Generate ECDSA keypair

#### Usage:
`./sygma-relayer keygen gen-key`

#### Description:
Generate a 256-bit ECDSA keypair and print it out. This keypair can be used as a relayer's execution keypair.

## Other util commands

### Derivate SS58 Command (utils)
Expand Down

0 comments on commit 9d9a113

Please sign in to comment.