-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the ability to manage rollapp keys (#1054)
- Loading branch information
1 parent
b560aa9
commit 3d1b220
Showing
13 changed files
with
284 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package export | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
|
||
initconfig "github.com/dymensionxyz/roller/cmd/config/init" | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"github.com/dymensionxyz/roller/utils/bash" | ||
"github.com/dymensionxyz/roller/utils/config/tomlconfig" | ||
"github.com/dymensionxyz/roller/utils/errorhandling" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "export", | ||
Short: "Exports the private key of the sequencer key.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home := cmd.Flag(utils.FlagNames.Home).Value.String() | ||
rollerData, err := tomlconfig.LoadRollerConfig(home) | ||
errorhandling.PrettifyErrorIfExists(err) | ||
|
||
var kcs []utils.KeyConfig | ||
if rollerData.HubData.ID != "mock" { | ||
kcs = initconfig.GetSequencerKeysConfig() | ||
} else { | ||
kcs = initconfig.GetMockSequencerKeyConfig(rollerData) | ||
} | ||
|
||
kc := kcs[0] | ||
|
||
expKeyArgs := []string{ | ||
"keys", | ||
"export", | ||
kc.ID, | ||
"--keyring-backend", | ||
"test", | ||
"--keyring-dir", | ||
filepath.Join(home, consts.ConfigDirName.HubKeys), | ||
} | ||
|
||
err = bash.ExecCommandWithInteractions(kc.ChainBinary, expKeyArgs...) | ||
if err != nil { | ||
pterm.Error.Println("failed to export private key: ", err) | ||
return | ||
} | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package importkeys | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/consts" | ||
"github.com/dymensionxyz/roller/cmd/utils" | ||
"github.com/dymensionxyz/roller/utils/bash" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "import <key-name> <priv-key-file-path>", | ||
Args: cobra.ExactArgs(2), | ||
Short: "Exports the private key of the sequencer key.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
home := cmd.Flag(utils.FlagNames.Home).Value.String() | ||
|
||
keyName := args[0] | ||
privKeyFilePath := args[1] | ||
keyringDir := filepath.Join(home, consts.ConfigDirName.HubKeys) | ||
|
||
expKeyArgs := []string{ | ||
"keys", | ||
"import", | ||
keyName, | ||
privKeyFilePath, | ||
"--keyring-backend", | ||
"test", | ||
"--keyring-dir", | ||
keyringDir, | ||
} | ||
|
||
err := bash.ExecCommandWithInteractions(consts.Executables.Dymension, expKeyArgs...) | ||
if err != nil { | ||
pterm.Error.Println("failed to export private key: ", err) | ||
return | ||
} | ||
|
||
pterm.Info.Printf( | ||
"keys were imported into the test keyring, keyring-dir: %s", | ||
keyringDir, | ||
) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package keys | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/roller/cmd/rollapp/keys/export" | ||
importkeys "github.com/dymensionxyz/roller/cmd/rollapp/keys/import" | ||
"github.com/dymensionxyz/roller/cmd/rollapp/keys/list" | ||
"github.com/dymensionxyz/roller/cmd/rollapp/keys/showunarmoredprivkey" | ||
) | ||
|
||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "keys", | ||
Short: "Commands for managing the roller different keys.", | ||
} | ||
cmd.AddCommand(list.Cmd()) | ||
cmd.AddCommand(showunarmoredprivkey.Cmd()) | ||
cmd.AddCommand(export.Cmd()) | ||
cmd.AddCommand(importkeys.Cmd()) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.