From 9a5e711d35fb3f71ff0e8797f67dc601b8ae708d Mon Sep 17 00:00:00 2001 From: harry Date: Thu, 23 Feb 2023 10:01:31 +0000 Subject: [PATCH 1/2] [Tooling] Update CLI to support key management (Issue #489) (#524) ## Description This PR adds the `Keys` endpoint to the CLI and adds the relevant subcommands to interact with the keybase from the users' perspective. The new `Keys` namespace allows for CRUD operations on keys and gives users access to creating, importing and exporting keys (as a raw string or JSON encoded string), deleting keys, listing all keys and getting specific keys as well as signing and verifying hex-encoded byte messages. ![image](https://user-images.githubusercontent.com/53987565/219619590-1a802307-2653-4b07-984a-9f1b277f6824.png) ![image](https://user-images.githubusercontent.com/53987565/219866188-efb62b0d-aaa1-47cb-b2cc-ccb918eb8a0d.png) ## Issue Fixes #489 ## Type of change Please mark the relevant option(s): - [x] New feature, functionality or library - [ ] Bug fix - [ ] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other ## List of changes - Add Keys CLI namespace - Add keybase-related subcommands - Return keypair when importing or creating a new key - Reformat tests - Remove `Exists()` function from keybase interface ## Testing - [x] `make develop_test` - [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md) w/ all of the steps outlined in the `README` ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have tested my changes using the available tooling - [x] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s) --- app/client/cli/account.go | 2 +- app/client/cli/cmd.go | 4 +- app/client/cli/gov.go | 2 +- app/client/cli/keys.go | 682 ++++++++++++++++++ app/client/cli/utils.go | 46 ++ app/client/doc/CHANGELOG.md | 4 + app/client/doc/commands/client.md | 5 +- app/client/doc/commands/client_Account.md | 4 +- .../doc/commands/client_Account_Send.md | 4 +- app/client/doc/commands/client_Application.md | 4 +- .../commands/client_Application_EditStake.md | 4 +- .../doc/commands/client_Application_Stake.md | 4 +- .../commands/client_Application_Unpause.md | 4 +- .../commands/client_Application_Unstake.md | 4 +- app/client/doc/commands/client_Consensus.md | 4 +- .../doc/commands/client_Consensus_Height.md | 4 +- .../doc/commands/client_Consensus_Round.md | 4 +- .../doc/commands/client_Consensus_State.md | 4 +- .../doc/commands/client_Consensus_Step.md | 4 +- app/client/doc/commands/client_Fisherman.md | 4 +- .../commands/client_Fisherman_EditStake.md | 4 +- .../doc/commands/client_Fisherman_Stake.md | 4 +- .../doc/commands/client_Fisherman_Unpause.md | 4 +- .../doc/commands/client_Fisherman_Unstake.md | 4 +- app/client/doc/commands/client_Governance.md | 4 +- .../client_Governance_ChangeParameter.md | 4 +- app/client/doc/commands/client_Keys.md | 34 + app/client/doc/commands/client_Keys_Create.md | 33 + app/client/doc/commands/client_Keys_Delete.md | 32 + app/client/doc/commands/client_Keys_Export.md | 34 + app/client/doc/commands/client_Keys_Get.md | 31 + app/client/doc/commands/client_Keys_Import.md | 35 + app/client/doc/commands/client_Keys_List.md | 31 + app/client/doc/commands/client_Keys_Sign.md | 32 + app/client/doc/commands/client_Keys_SignTx.md | 34 + app/client/doc/commands/client_Keys_Update.md | 34 + app/client/doc/commands/client_Keys_Verify.md | 32 + .../doc/commands/client_Keys_VerifyTx.md | 34 + app/client/doc/commands/client_Node.md | 27 + app/client/doc/commands/client_Servicer.md | 4 +- .../doc/commands/client_Servicer_EditStake.md | 4 +- .../doc/commands/client_Servicer_Stake.md | 4 +- .../doc/commands/client_Servicer_Unpause.md | 4 +- .../doc/commands/client_Servicer_Unstake.md | 4 +- app/client/doc/commands/client_System.md | 4 +- .../doc/commands/client_System_Health.md | 4 +- .../doc/commands/client_System_Version.md | 4 +- app/client/doc/commands/client_Validator.md | 4 +- .../commands/client_Validator_EditStake.md | 4 +- .../doc/commands/client_Validator_Stake.md | 4 +- .../doc/commands/client_Validator_Unpause.md | 4 +- .../doc/commands/client_Validator_Unstake.md | 4 +- app/client/doc/commands/client_debug.md | 4 +- app/client/keybase/debug/keystore.go | 26 +- app/client/keybase/keybase.go | 7 +- app/client/keybase/keybase_test.go | 204 ++---- app/client/keybase/keystore.go | 68 +- shared/CHANGELOG.md | 4 + shared/converters/file_utils.go | 77 ++ 59 files changed, 1407 insertions(+), 279 deletions(-) create mode 100644 app/client/cli/keys.go create mode 100644 app/client/doc/commands/client_Keys.md create mode 100644 app/client/doc/commands/client_Keys_Create.md create mode 100644 app/client/doc/commands/client_Keys_Delete.md create mode 100644 app/client/doc/commands/client_Keys_Export.md create mode 100644 app/client/doc/commands/client_Keys_Get.md create mode 100644 app/client/doc/commands/client_Keys_Import.md create mode 100644 app/client/doc/commands/client_Keys_List.md create mode 100644 app/client/doc/commands/client_Keys_Sign.md create mode 100644 app/client/doc/commands/client_Keys_SignTx.md create mode 100644 app/client/doc/commands/client_Keys_Update.md create mode 100644 app/client/doc/commands/client_Keys_Verify.md create mode 100644 app/client/doc/commands/client_Keys_VerifyTx.md create mode 100644 app/client/doc/commands/client_Node.md create mode 100644 shared/converters/file_utils.go diff --git a/app/client/cli/account.go b/app/client/cli/account.go index b9a25aa370..db02098db6 100644 --- a/app/client/cli/account.go +++ b/app/client/cli/account.go @@ -45,7 +45,7 @@ func accountCommands() []*cobra.Command { toAddr := crypto.AddressFromString(args[1]) amount := args[2] - // Open the debug keybase at the specified path + // Open the keybase at the specified path pocketDir := strings.TrimSuffix(dataDir, "/") keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) if err != nil { diff --git a/app/client/cli/cmd.go b/app/client/cli/cmd.go index 88f7cef71f..61f4c37652 100644 --- a/app/client/cli/cmd.go +++ b/app/client/cli/cmd.go @@ -2,7 +2,7 @@ package cli import ( "context" - "log" + "github.com/pokt-network/pocket/logger" "os" // NOTE: Imported for debug purposes in order to populate the keybase with the pre-generated keys @@ -25,7 +25,7 @@ var ( func init() { homeDir, err := os.UserHomeDir() if err != nil { - log.Fatalf("[ERROR] Cannot find user home directory: %s", err.Error()) + logger.Global.Fatal().Err(err).Msg("Cannot find user home directory") } rootCmd.PersistentFlags().StringVar(&remoteCLIURL, "remote_cli_url", defaults.DefaultRemoteCLIURL, "takes a remote endpoint in the form of :// (uses RPC Port)") rootCmd.PersistentFlags().BoolVar(&nonInteractive, "non_interactive", false, "if true skips the interactive prompts wherever possible (useful for scripting & automation)") diff --git a/app/client/cli/gov.go b/app/client/cli/gov.go index cd3650a4a4..bc622a6942 100644 --- a/app/client/cli/gov.go +++ b/app/client/cli/gov.go @@ -49,7 +49,7 @@ func govCommands() []*cobra.Command { // TODO(deblasis): implement RPC client, route and handler fmt.Printf("changing parameter %s owned by %s to %s\n", args[1], args[0], args[2]) - // Open the debug keybase at the specified path + // Open the keybase at the specified path pocketDir := strings.TrimSuffix(dataDir, "/") keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) if err != nil { diff --git a/app/client/cli/keys.go b/app/client/cli/keys.go new file mode 100644 index 0000000000..dc1ff75fee --- /dev/null +++ b/app/client/cli/keys.go @@ -0,0 +1,682 @@ +package cli + +import ( + "bytes" + "encoding/hex" + "fmt" + "github.com/pokt-network/pocket/logger" + "github.com/pokt-network/pocket/shared/codec" + "github.com/pokt-network/pocket/shared/converters" + "github.com/pokt-network/pocket/shared/crypto" + utilTypes "github.com/pokt-network/pocket/utility/types" + "path/filepath" + "strings" + + "github.com/pokt-network/pocket/app/client/keybase" + "github.com/spf13/cobra" +) + +var ( + outputFile string + inputFile string + exportAs string + importAs string + hint string + newPwd string +) + +func init() { + rootCmd.AddCommand(NewKeysCommand()) +} + +func NewKeysCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "Keys", + Short: "Key specific commands", + Aliases: []string{"keys"}, + Args: cobra.ExactArgs(0), + } + + createCmds := keysCreateCommands() + updateCmds := keysUpdateCommands() + deleteCmds := keysDeleteCommands() + getCmds := keysGetCommands() + exportCmds := keysExportCommands() + importCmds := keysImportCommands() + signMsgCmds := keysSignMsgCommands() + signTxCmds := keysSignTxCommands() + + // Add --pwd and --hint flags + applySubcommandOptions(createCmds, attachPwdFlagToSubcommands()) + applySubcommandOptions(createCmds, attachHintFlagToSubcommands()) + + // Add --pwd, --new_pwd and --hint flags + applySubcommandOptions(updateCmds, attachPwdFlagToSubcommands()) + applySubcommandOptions(updateCmds, attachNewPwdFlagToSubcommands()) + applySubcommandOptions(updateCmds, attachHintFlagToSubcommands()) + + // Add --pwd flag + applySubcommandOptions(deleteCmds, attachPwdFlagToSubcommands()) + + // Add --pwd, --output_file and --export_format flags + applySubcommandOptions(exportCmds, attachPwdFlagToSubcommands()) + applySubcommandOptions(exportCmds, attachOutputFlagToSubcommands()) + applySubcommandOptions(exportCmds, attachExportFlagToSubcommands()) + + // Add --pwd, --hint, --input_file and --import_format flags + applySubcommandOptions(importCmds, attachPwdFlagToSubcommands()) + applySubcommandOptions(importCmds, attachHintFlagToSubcommands()) + applySubcommandOptions(importCmds, attachInputFlagToSubcommands()) + applySubcommandOptions(importCmds, attachImportFlagToSubcommands()) + + // Add --pwd flag + applySubcommandOptions(signMsgCmds, attachPwdFlagToSubcommands()) + + // Add --pwd, --input_file and --output_file flags + applySubcommandOptions(signTxCmds, attachPwdFlagToSubcommands()) + applySubcommandOptions(signTxCmds, attachInputFlagToSubcommands()) + applySubcommandOptions(signTxCmds, attachOutputFlagToSubcommands()) + + cmd.AddCommand(createCmds...) + cmd.AddCommand(updateCmds...) + cmd.AddCommand(deleteCmds...) + cmd.AddCommand(getCmds...) + cmd.AddCommand(exportCmds...) + cmd.AddCommand(importCmds...) + cmd.AddCommand(signMsgCmds...) + cmd.AddCommand(signTxCmds...) + + return cmd +} + +func keysCreateCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Create", + Short: "Create new key", + Long: "Creates a new key and stores it in the keybase", + Aliases: []string{"create"}, + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + } + + kp, err := kb.Create(pwd, hint) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", kp.GetAddressString()).Msg("New Key Created") + + return nil + }, + }, + } + return cmds +} + +func keysUpdateCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Update [--pwd] [--new_pwd] [--hint]", + Short: "Updates the key to have a new passphrase and hint", + Long: "Updates the passphrase and hint of in the keybase, using either the values from the flags provided or from the CLI prompts.", + Aliases: []string{"update"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + newPwd = readPassphraseMessage(newPwd, "New passphrase: ") + } + + err = kb.UpdatePassphrase(addrHex, pwd, newPwd, hint) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", addrHex).Msg("Key updated") + + return nil + }, + }, + } + return cmds +} + +func keysDeleteCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Delete ", + Short: "Deletes the key from the keybase", + Long: "Deletes from the keybase", + Aliases: []string{"delete"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + } + + err = kb.Delete(addrHex, pwd) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", addrHex).Msg("Key deleted") + + return nil + }, + }, + } + return cmds +} + +func keysGetCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "List", + Short: "List all keys", + Long: "List all of the hex addresses of the keys stored in the keybase", + Aliases: []string{"list"}, + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + addresses, _, err := kb.GetAll() + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Strs("addresses", addresses).Msg("Get all keys") + + return nil + }, + }, + { + Use: "Get ", + Short: "Get the address and public key from the keybase", + Long: "Get the address and public key of from the keybase, provided it is stored", + Aliases: []string{"get"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + kp, err := kb.Get(addrHex) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", addrHex).Str("public_key", kp.GetPublicKey().String()).Msg("Found key") + + return nil + }, + }, + } + return cmds +} + +func keysExportCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Export [--export_format] [--output_file]", + Short: "Exports the private key as a raw string or JSON to either STDOUT or to a file", + Long: "Exports the private key of as a raw or JSON encoded string depending on [--output_format], written to STDOUT or [--output_file]", + Aliases: []string{"export"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + } + + // Select the correct format to export private key + var exportString string + switch strings.ToLower(exportAs) { + case "json": + exportString, err = kb.ExportPrivJSON(addrHex, pwd) + if err != nil { + return err + } + case "raw": + exportString, err = kb.ExportPrivString(addrHex, pwd) + if err != nil { + return err + } + default: + return fmt.Errorf("invalid export format: got %s, want [raw]/[json]", exportAs) + } + + if err := kb.Stop(); err != nil { + return err + } + + // Write to stdout or file + if outputFile == "" { + logger.Global.Info().Str("private_key", exportString).Msg("Key exported") + return nil + } + + logger.Global.Info().Str("output_file", outputFile).Msg("Exporting private key string to file...") + + return converters.WriteOutput(exportString, outputFile) + }, + }, + } + return cmds +} + +func keysImportCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Import [privateKeyString] [--input_file] [--import_format]", + Short: "Imports a key from a string or from a file", + Long: "Imports [privateKeyString] or from [--input_file] into the keybase, provided it is in the form of [--import_format]", + Aliases: []string{"import"}, + Args: cobra.MaximumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get import string + var privateKeyString string + if len(args) == 1 { + privateKeyString = args[0] + } else if inputFile != "" { + privateKeyBz, err := converters.ReadInput(inputFile) + privateKeyString = string(privateKeyBz) + if err != nil { + return err + } + } else { + return fmt.Errorf("no input file or argument provided") + } + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + } + + // Determine correct way to import the private key + var kp crypto.KeyPair + switch strings.ToLower(importAs) { + case "json": + kp, err = kb.ImportFromJSON(privateKeyString, pwd) + if err != nil { + return err + } + case "raw": + kp, err = kb.ImportFromString(privateKeyString, pwd, hint) + if err != nil { + return err + } + default: + return fmt.Errorf("invalid import format: got %s, want [raw]/[json]", exportAs) + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", kp.GetAddressString()).Msg("Key imported") + + return nil + }, + }, + } + return cmds +} + +func keysSignMsgCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "Sign ", + Short: "Signs a message using the key provided", + Long: "Signs with from the keybase, returning the signature", + Aliases: []string{"sign"}, + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + msgHex := args[1] + msgBz, err := hex.DecodeString(msgHex) + if err != nil { + return err + } + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + } + + sigBz, err := kb.Sign(addrHex, pwd, msgBz) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + sigHex := hex.EncodeToString(sigBz) + + logger.Global.Info().Str("signature", sigHex).Str("address", addrHex).Msg("Message signed") + + return nil + }, + }, + { + Use: "Verify ", + Short: "Verifies the signature is valid from the signer", + Long: "Verify that is a valid signature of signed by ", + Aliases: []string{"verify"}, + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + msgHex := args[1] + msgBz, err := hex.DecodeString(msgHex) + if err != nil { + return err + } + sigHex := args[2] + sigBz, err := hex.DecodeString(sigHex) + if err != nil { + return err + } + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + valid, err := kb.Verify(addrHex, msgBz, sigBz) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", addrHex).Bool("valid", valid).Msg("Signature checked") + + return nil + }, + }, + } + return cmds +} + +func keysSignTxCommands() []*cobra.Command { + cmds := []*cobra.Command{ + { + Use: "SignTx [--input_file] [--output_file]", + Short: "Signs a transaction using the key provided", + Long: "Signs [--input_file] with from the keybase, writing the signed transaction to [--output_file]", + Aliases: []string{"signtx"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + + if inputFile == "" { + return fmt.Errorf("no input file provided") + } else if outputFile == "" { + return fmt.Errorf("no output file provided") + } + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + if !nonInteractive { + pwd = readPassphrase(pwd) + } + + privKey, err := kb.GetPrivKey(addrHex, pwd) + if err != nil { + return err + } + + if err := kb.Stop(); err != nil { + return err + } + + // Unmarshal Tx from input file + txBz, err := converters.ReadInput(inputFile) + if err != nil { + return err + } + txProto := new(utilTypes.Transaction) + if err := codec.GetCodec().Unmarshal(txBz, txProto); err != nil { + return err + } + + // Sign the serialised transaction + txSigBz, err := txProto.SignableBytes() + if err != nil { + return err + } + + sigBz, err := privKey.Sign(txSigBz) + if err != nil { + return err + } + + // Add signature to the transaction + sig := new(utilTypes.Signature) + sig.PublicKey = privKey.PublicKey().Bytes() + sig.Signature = sigBz + txProto.Signature = sig + + // Re-serealise the transaction and write to output_file + txBz, err = codec.GetCodec().Marshal(txProto) + if err != nil { + return err + } + + if err := converters.WriteOutput(txBz, outputFile); err != nil { + return err + } + + logger.Global.Info().Str("signed_transaction_file", outputFile).Str("address", addrHex).Msg("Message signed") + + return nil + }, + }, + { + Use: "VerifyTx [--input_file]", + Short: "Verifies the transaction's signature is valid from the signer", + Long: "Verify that [--input_file] contains a valid signature for the transaction in the file signed by ", + Aliases: []string{"verifytx"}, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // Unpack CLI args + addrHex := args[0] + + if inputFile == "" { + return fmt.Errorf("no input file provided") + } + + // Open the debug keybase at the specified path + pocketDir := strings.TrimSuffix(dataDir, "/") + keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix) + if err != nil { + return err + } + kb, err := keybase.NewKeybase(keybasePath) + if err != nil { + return err + } + + pubKey, err := kb.GetPubKey(addrHex) + if err != nil { + return err + } + + // Unmarshal Tx from input file + txBz, err := converters.ReadInput(inputFile) + if err != nil { + return err + } + txProto := new(utilTypes.Transaction) + if err := codec.GetCodec().Unmarshal(txBz, txProto); err != nil { + return err + } + + // Extract signature and begin verification + var valid bool + sigBz := txProto.Signature.Signature + sigPub := txProto.Signature.PublicKey + + // First check public keys are the same + if !bytes.Equal(sigPub, pubKey.Bytes()) { + valid = false + } else { + // Verify the signable bytes of the transaction + txSigBz, err := txProto.SignableBytes() + if err != nil { + return err + } + + valid, err = kb.Verify(addrHex, txSigBz, sigBz) + if err != nil { + return err + } + } + + if err := kb.Stop(); err != nil { + return err + } + + logger.Global.Info().Str("address", addrHex).Bool("valid", valid).Msg("Signature checked") + + return nil + }, + }, + } + return cmds +} diff --git a/app/client/cli/utils.go b/app/client/cli/utils.go index d90798250b..8242e4fc31 100644 --- a/app/client/cli/utils.go +++ b/app/client/cli/utils.go @@ -144,6 +144,16 @@ func readPassphrase(currPwd string) string { return credentials(currPwd) } +func readPassphraseMessage(currPwd, prompt string) string { + if strings.TrimSpace(currPwd) == "" { + fmt.Println(prompt) + } else { + fmt.Println("Using Passphrase provided via flag") + } + + return credentials(currPwd) +} + func validateStakeAmount(amount string) error { am, err := converters.StringToBigInt(amount) if err != nil { @@ -174,6 +184,42 @@ func attachPwdFlagToSubcommands() []cmdOption { }} } +func attachNewPwdFlagToSubcommands() []cmdOption { + return []cmdOption{func(c *cobra.Command) { + c.Flags().StringVar(&pwd, "new_pwd", "", "new passphrase for private key, non empty usage bypass interactive prompt") + }} +} + +func attachOutputFlagToSubcommands() []cmdOption { + return []cmdOption{func(c *cobra.Command) { + c.Flags().StringVar(&outputFile, "output_file", "", "output file to write results to") + }} +} + +func attachInputFlagToSubcommands() []cmdOption { + return []cmdOption{func(c *cobra.Command) { + c.Flags().StringVar(&inputFile, "input_file", "", "input file to read data from") + }} +} + +func attachExportFlagToSubcommands() []cmdOption { + return []cmdOption{func(c *cobra.Command) { + c.Flags().StringVar(&exportAs, "export_format", "json", "export the private key in the specified format") + }} +} + +func attachImportFlagToSubcommands() []cmdOption { + return []cmdOption{func(c *cobra.Command) { + c.Flags().StringVar(&importAs, "import_format", "raw", "import the private key from the specified format") + }} +} + +func attachHintFlagToSubcommands() []cmdOption { + return []cmdOption{func(c *cobra.Command) { + c.Flags().StringVar(&hint, "hint", "", "hint for the passphrase of the private key") + }} +} + func unableToConnectToRpc(err error) error { fmt.Printf("❌ Unable to connect to the RPC @ %s\n\nError: %s", boldText(remoteCLIURL), err) return nil diff --git a/app/client/doc/CHANGELOG.md b/app/client/doc/CHANGELOG.md index 7e5da66165..47722c0e9c 100644 --- a/app/client/doc/CHANGELOG.md +++ b/app/client/doc/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.17] - 2023-02-23 + +- Add CLI endpoints to interact with the keybase + ## [0.0.0.16] - 2023-02-21 - Rename ServiceNode Actor Type Name to Servicer diff --git a/app/client/doc/commands/client.md b/app/client/doc/commands/client.md index aca659d186..33c801a9e3 100644 --- a/app/client/doc/commands/client.md +++ b/app/client/doc/commands/client.md @@ -9,7 +9,7 @@ The CLI is meant to be an user but also a machine friendly way for interacting w ### Options ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") -h, --help help for client --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") @@ -22,9 +22,10 @@ The CLI is meant to be an user but also a machine friendly way for interacting w * [client Consensus](client_Consensus.md) - Consensus specific commands * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands * [client Governance](client_Governance.md) - Governance specific commands +* [client Keys](client_Keys.md) - Key specific commands * [client Servicer](client_Servicer.md) - Servicer actor specific commands * [client System](client_System.md) - Commands related to health and troubleshooting of the node instance * [client Validator](client_Validator.md) - Validator actor specific commands * [client debug](client_debug.md) - Debug utility for rapid development -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Account.md b/app/client/doc/commands/client_Account.md index 770c1a6cde..8214598be3 100644 --- a/app/client/doc/commands/client_Account.md +++ b/app/client/doc/commands/client_Account.md @@ -11,7 +11,7 @@ Account specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -21,4 +21,4 @@ Account specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Account Send](client_Account_Send.md) - Send -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Account_Send.md b/app/client/doc/commands/client_Account_Send.md index 3526a3277e..38f8a80afe 100644 --- a/app/client/doc/commands/client_Account_Send.md +++ b/app/client/doc/commands/client_Account_Send.md @@ -20,7 +20,7 @@ client Account Send [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Account Send [flags] * [client Account](client_Account.md) - Account specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Application.md b/app/client/doc/commands/client_Application.md index 424c846f0a..1f0b0392cc 100644 --- a/app/client/doc/commands/client_Application.md +++ b/app/client/doc/commands/client_Application.md @@ -11,7 +11,7 @@ Application actor specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -24,4 +24,4 @@ Application actor specific commands * [client Application Unpause](client_Application_Unpause.md) - Unpause * [client Application Unstake](client_Application_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Application_EditStake.md b/app/client/doc/commands/client_Application_EditStake.md index f641c57a75..f0bdf437d2 100644 --- a/app/client/doc/commands/client_Application_EditStake.md +++ b/app/client/doc/commands/client_Application_EditStake.md @@ -20,7 +20,7 @@ client Application EditStake [f ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Application EditStake [f * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Application_Stake.md b/app/client/doc/commands/client_Application_Stake.md index 65683fac75..33c74ab5c0 100644 --- a/app/client/doc/commands/client_Application_Stake.md +++ b/app/client/doc/commands/client_Application_Stake.md @@ -28,7 +28,7 @@ client Application Stake [flags ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -37,4 +37,4 @@ client Application Stake [flags * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Application_Unpause.md b/app/client/doc/commands/client_Application_Unpause.md index 68d2fbbf5b..7cc042b728 100644 --- a/app/client/doc/commands/client_Application_Unpause.md +++ b/app/client/doc/commands/client_Application_Unpause.md @@ -20,7 +20,7 @@ client Application Unpause [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Application Unpause [flags] * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Application_Unstake.md b/app/client/doc/commands/client_Application_Unstake.md index 62d2b6bcbf..ec20f4f59f 100644 --- a/app/client/doc/commands/client_Application_Unstake.md +++ b/app/client/doc/commands/client_Application_Unstake.md @@ -20,7 +20,7 @@ client Application Unstake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Application Unstake [flags] * [client Application](client_Application.md) - Application actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Consensus.md b/app/client/doc/commands/client_Consensus.md index add906f964..0aec0ab64b 100644 --- a/app/client/doc/commands/client_Consensus.md +++ b/app/client/doc/commands/client_Consensus.md @@ -11,7 +11,7 @@ Consensus specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -24,4 +24,4 @@ Consensus specific commands * [client Consensus State](client_Consensus_State.md) - Returns "Height/Round/Step" * [client Consensus Step](client_Consensus_Step.md) - Returns the Step -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Consensus_Height.md b/app/client/doc/commands/client_Consensus_Height.md index 23508f5a78..baec2bc2fb 100644 --- a/app/client/doc/commands/client_Consensus_Height.md +++ b/app/client/doc/commands/client_Consensus_Height.md @@ -19,7 +19,7 @@ client Consensus Height [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -28,4 +28,4 @@ client Consensus Height [flags] * [client Consensus](client_Consensus.md) - Consensus specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Consensus_Round.md b/app/client/doc/commands/client_Consensus_Round.md index 858921ad6f..0a2536c0af 100644 --- a/app/client/doc/commands/client_Consensus_Round.md +++ b/app/client/doc/commands/client_Consensus_Round.md @@ -19,7 +19,7 @@ client Consensus Round [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -28,4 +28,4 @@ client Consensus Round [flags] * [client Consensus](client_Consensus.md) - Consensus specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Consensus_State.md b/app/client/doc/commands/client_Consensus_State.md index 2aaa4a44fa..fccfe174bb 100644 --- a/app/client/doc/commands/client_Consensus_State.md +++ b/app/client/doc/commands/client_Consensus_State.md @@ -19,7 +19,7 @@ client Consensus State [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -28,4 +28,4 @@ client Consensus State [flags] * [client Consensus](client_Consensus.md) - Consensus specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Consensus_Step.md b/app/client/doc/commands/client_Consensus_Step.md index 5856ab0e6f..dc29be2608 100644 --- a/app/client/doc/commands/client_Consensus_Step.md +++ b/app/client/doc/commands/client_Consensus_Step.md @@ -19,7 +19,7 @@ client Consensus Step [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -28,4 +28,4 @@ client Consensus Step [flags] * [client Consensus](client_Consensus.md) - Consensus specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Fisherman.md b/app/client/doc/commands/client_Fisherman.md index eb143cc7fb..fb62b8e95f 100644 --- a/app/client/doc/commands/client_Fisherman.md +++ b/app/client/doc/commands/client_Fisherman.md @@ -11,7 +11,7 @@ Fisherman actor specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -24,4 +24,4 @@ Fisherman actor specific commands * [client Fisherman Unpause](client_Fisherman_Unpause.md) - Unpause * [client Fisherman Unstake](client_Fisherman_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Fisherman_EditStake.md b/app/client/doc/commands/client_Fisherman_EditStake.md index b2214624ff..cfe7855fe2 100644 --- a/app/client/doc/commands/client_Fisherman_EditStake.md +++ b/app/client/doc/commands/client_Fisherman_EditStake.md @@ -20,7 +20,7 @@ client Fisherman EditStake [fla ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Fisherman EditStake [fla * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Fisherman_Stake.md b/app/client/doc/commands/client_Fisherman_Stake.md index a6ac9f18b2..7f8c2f9b0e 100644 --- a/app/client/doc/commands/client_Fisherman_Stake.md +++ b/app/client/doc/commands/client_Fisherman_Stake.md @@ -28,7 +28,7 @@ client Fisherman Stake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -37,4 +37,4 @@ client Fisherman Stake [flags] * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Fisherman_Unpause.md b/app/client/doc/commands/client_Fisherman_Unpause.md index 39416d45a1..30930c4e7e 100644 --- a/app/client/doc/commands/client_Fisherman_Unpause.md +++ b/app/client/doc/commands/client_Fisherman_Unpause.md @@ -20,7 +20,7 @@ client Fisherman Unpause [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Fisherman Unpause [flags] * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Fisherman_Unstake.md b/app/client/doc/commands/client_Fisherman_Unstake.md index 3a25e7d6d7..7e4f71d3b9 100644 --- a/app/client/doc/commands/client_Fisherman_Unstake.md +++ b/app/client/doc/commands/client_Fisherman_Unstake.md @@ -20,7 +20,7 @@ client Fisherman Unstake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Fisherman Unstake [flags] * [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Governance.md b/app/client/doc/commands/client_Governance.md index ea2d75b506..d87612e418 100644 --- a/app/client/doc/commands/client_Governance.md +++ b/app/client/doc/commands/client_Governance.md @@ -11,7 +11,7 @@ Governance specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -21,4 +21,4 @@ Governance specific commands * [client](client.md) - Pocket Network Command Line Interface (CLI) * [client Governance ChangeParameter](client_Governance_ChangeParameter.md) - ChangeParameter -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Governance_ChangeParameter.md b/app/client/doc/commands/client_Governance_ChangeParameter.md index 41b89c49d3..dedb2543e7 100644 --- a/app/client/doc/commands/client_Governance_ChangeParameter.md +++ b/app/client/doc/commands/client_Governance_ChangeParameter.md @@ -20,7 +20,7 @@ client Governance ChangeParameter [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Governance ChangeParameter [flags] * [client Governance](client_Governance.md) - Governance specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys.md b/app/client/doc/commands/client_Keys.md new file mode 100644 index 0000000000..7929f2c377 --- /dev/null +++ b/app/client/doc/commands/client_Keys.md @@ -0,0 +1,34 @@ +## client Keys + +Key specific commands + +### Options + +``` + -h, --help help for Keys +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client](client.md) - Pocket Network Command Line Interface (CLI) +* [client Keys Create](client_Keys_Create.md) - Create new key +* [client Keys Delete](client_Keys_Delete.md) - Deletes the key from the keybase +* [client Keys Export](client_Keys_Export.md) - Exports the private key as a raw string or JSON to either STDOUT or to a file +* [client Keys Get](client_Keys_Get.md) - Get the address and public key from the keybase +* [client Keys Import](client_Keys_Import.md) - Imports a key from a string or from a file +* [client Keys List](client_Keys_List.md) - List all keys +* [client Keys Sign](client_Keys_Sign.md) - Signs a message using the key provided +* [client Keys SignTx](client_Keys_SignTx.md) - Signs a transaction using the key provided +* [client Keys Update](client_Keys_Update.md) - Updates the key to have a new passphrase and hint +* [client Keys Verify](client_Keys_Verify.md) - Verifies the signature is valid from the signer +* [client Keys VerifyTx](client_Keys_VerifyTx.md) - Verifies the transaction's signature is valid from the signer + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Create.md b/app/client/doc/commands/client_Keys_Create.md new file mode 100644 index 0000000000..0afa30144c --- /dev/null +++ b/app/client/doc/commands/client_Keys_Create.md @@ -0,0 +1,33 @@ +## client Keys Create + +Create new key + +### Synopsis + +Creates a new key and stores it in the keybase + +``` +client Keys Create [flags] +``` + +### Options + +``` + -h, --help help for Create + --hint string hint for the passphrase of the private key + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Delete.md b/app/client/doc/commands/client_Keys_Delete.md new file mode 100644 index 0000000000..4d02a4370b --- /dev/null +++ b/app/client/doc/commands/client_Keys_Delete.md @@ -0,0 +1,32 @@ +## client Keys Delete + +Deletes the key from the keybase + +### Synopsis + +Deletes from the keybase + +``` +client Keys Delete [flags] +``` + +### Options + +``` + -h, --help help for Delete + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Export.md b/app/client/doc/commands/client_Keys_Export.md new file mode 100644 index 0000000000..51c9c7d7ab --- /dev/null +++ b/app/client/doc/commands/client_Keys_Export.md @@ -0,0 +1,34 @@ +## client Keys Export + +Exports the private key as a raw string or JSON to either STDOUT or to a file + +### Synopsis + +Exports the private key of as a raw or JSON encoded string depending on [--output_format], written to STDOUT or [--output_file] + +``` +client Keys Export [--export_format] [--output_file] [flags] +``` + +### Options + +``` + --export_format string export the private key in the specified format (default "json") + -h, --help help for Export + --output_file string output file to write results to + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Get.md b/app/client/doc/commands/client_Keys_Get.md new file mode 100644 index 0000000000..5485a6f862 --- /dev/null +++ b/app/client/doc/commands/client_Keys_Get.md @@ -0,0 +1,31 @@ +## client Keys Get + +Get the address and public key from the keybase + +### Synopsis + +Get the address and public key of from the keybase, provided it is stored + +``` +client Keys Get [flags] +``` + +### Options + +``` + -h, --help help for Get +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Import.md b/app/client/doc/commands/client_Keys_Import.md new file mode 100644 index 0000000000..a2f145f770 --- /dev/null +++ b/app/client/doc/commands/client_Keys_Import.md @@ -0,0 +1,35 @@ +## client Keys Import + +Imports a key from a string or from a file + +### Synopsis + +Imports [privateKeyString] or from [--input_file] into the keybase, provided it is in the form of [--import_format] + +``` +client Keys Import [privateKeyString] [--input_file] [--import_format] [flags] +``` + +### Options + +``` + -h, --help help for Import + --hint string hint for the passphrase of the private key + --import_format string import the private key from the specified format (default "raw") + --input_file string input file to read data from + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_List.md b/app/client/doc/commands/client_Keys_List.md new file mode 100644 index 0000000000..804d17edeb --- /dev/null +++ b/app/client/doc/commands/client_Keys_List.md @@ -0,0 +1,31 @@ +## client Keys List + +List all keys + +### Synopsis + +List all of the hex addresses of the keys stored in the keybase + +``` +client Keys List [flags] +``` + +### Options + +``` + -h, --help help for List +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Sign.md b/app/client/doc/commands/client_Keys_Sign.md new file mode 100644 index 0000000000..e19d35c8a0 --- /dev/null +++ b/app/client/doc/commands/client_Keys_Sign.md @@ -0,0 +1,32 @@ +## client Keys Sign + +Signs a message using the key provided + +### Synopsis + +Signs with from the keybase, returning the signature + +``` +client Keys Sign [flags] +``` + +### Options + +``` + -h, --help help for Sign + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_SignTx.md b/app/client/doc/commands/client_Keys_SignTx.md new file mode 100644 index 0000000000..52c8733058 --- /dev/null +++ b/app/client/doc/commands/client_Keys_SignTx.md @@ -0,0 +1,34 @@ +## client Keys SignTx + +Signs a transaction using the key provided + +### Synopsis + +Signs [--input_file] with from the keybase, writing the signed transaction to [--output_file] + +``` +client Keys SignTx [--input_file] [--output_file] [flags] +``` + +### Options + +``` + -h, --help help for SignTx + --input_file string input file to read data from + --output_file string output file to write results to + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Update.md b/app/client/doc/commands/client_Keys_Update.md new file mode 100644 index 0000000000..80d3015eee --- /dev/null +++ b/app/client/doc/commands/client_Keys_Update.md @@ -0,0 +1,34 @@ +## client Keys Update + +Updates the key to have a new passphrase and hint + +### Synopsis + +Updates the passphrase and hint of in the keybase, using either the values from the flags provided or from the CLI prompts. + +``` +client Keys Update [--pwd] [--new_pwd] [--hint] [flags] +``` + +### Options + +``` + -h, --help help for Update + --hint string hint for the passphrase of the private key + --new_pwd string new passphrase for private key, non empty usage bypass interactive prompt + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_Verify.md b/app/client/doc/commands/client_Keys_Verify.md new file mode 100644 index 0000000000..032af7da16 --- /dev/null +++ b/app/client/doc/commands/client_Keys_Verify.md @@ -0,0 +1,32 @@ +## client Keys Verify + +Verifies the signature is valid from the signer + +### Synopsis + +Verify that is a valid signature of signed by + +``` +client Keys Verify [flags] +``` + +### Options + +``` + -h, --help help for Verify + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Keys_VerifyTx.md b/app/client/doc/commands/client_Keys_VerifyTx.md new file mode 100644 index 0000000000..94f121d67c --- /dev/null +++ b/app/client/doc/commands/client_Keys_VerifyTx.md @@ -0,0 +1,34 @@ +## client Keys VerifyTx + +Verifies the transaction's signature is valid from the signer + +### Synopsis + +Verify that [--input_file] contains a valid signature for the transaction in the file signed by + +``` +client Keys VerifyTx [--input_file] [flags] +``` + +### Options + +``` + -h, --help help for VerifyTx + --input_file string input file to read data from + --output_file string output file to write results to + --pwd string passphrase used by the cmd, non empty usage bypass interactive prompt +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client Keys](client_Keys.md) - Key specific commands + +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Node.md b/app/client/doc/commands/client_Node.md new file mode 100644 index 0000000000..72713bc0c3 --- /dev/null +++ b/app/client/doc/commands/client_Node.md @@ -0,0 +1,27 @@ +## client Node + +Node actor specific commands + +### Options + +``` + -h, --help help for Node +``` + +### Options inherited from parent commands + +``` + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") + --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) + --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") +``` + +### SEE ALSO + +* [client](client.md) - Pocket Network Command Line Interface (CLI) +* [client Node EditStake](client_Node_EditStake.md) - EditStake +* [client Node Stake](client_Node_Stake.md) - Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds. +* [client Node Unpause](client_Node_Unpause.md) - Unpause +* [client Node Unstake](client_Node_Unstake.md) - Unstake + +###### Auto generated by spf13/cobra on 21-Feb-2023 diff --git a/app/client/doc/commands/client_Servicer.md b/app/client/doc/commands/client_Servicer.md index e65cb2fb6e..f1c7489f6d 100644 --- a/app/client/doc/commands/client_Servicer.md +++ b/app/client/doc/commands/client_Servicer.md @@ -11,7 +11,7 @@ Servicer actor specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -24,4 +24,4 @@ Servicer actor specific commands * [client Servicer Unpause](client_Servicer_Unpause.md) - Unpause * [client Servicer Unstake](client_Servicer_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Servicer_EditStake.md b/app/client/doc/commands/client_Servicer_EditStake.md index 6e07f9a5a4..15b625366b 100644 --- a/app/client/doc/commands/client_Servicer_EditStake.md +++ b/app/client/doc/commands/client_Servicer_EditStake.md @@ -20,7 +20,7 @@ client Servicer EditStake [flag ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Servicer EditStake [flag * [client Servicer](client_Servicer.md) - Servicer actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Servicer_Stake.md b/app/client/doc/commands/client_Servicer_Stake.md index 01c4a75b49..f49527be32 100644 --- a/app/client/doc/commands/client_Servicer_Stake.md +++ b/app/client/doc/commands/client_Servicer_Stake.md @@ -28,7 +28,7 @@ client Servicer Stake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -37,4 +37,4 @@ client Servicer Stake [flags] * [client Servicer](client_Servicer.md) - Servicer actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Servicer_Unpause.md b/app/client/doc/commands/client_Servicer_Unpause.md index 188205d24e..c09fd83e02 100644 --- a/app/client/doc/commands/client_Servicer_Unpause.md +++ b/app/client/doc/commands/client_Servicer_Unpause.md @@ -20,7 +20,7 @@ client Servicer Unpause [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Servicer Unpause [flags] * [client Servicer](client_Servicer.md) - Servicer actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Servicer_Unstake.md b/app/client/doc/commands/client_Servicer_Unstake.md index fc20e22841..d08ec81086 100644 --- a/app/client/doc/commands/client_Servicer_Unstake.md +++ b/app/client/doc/commands/client_Servicer_Unstake.md @@ -20,7 +20,7 @@ client Servicer Unstake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Servicer Unstake [flags] * [client Servicer](client_Servicer.md) - Servicer actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_System.md b/app/client/doc/commands/client_System.md index 4e2b69e465..77ba67c77b 100644 --- a/app/client/doc/commands/client_System.md +++ b/app/client/doc/commands/client_System.md @@ -11,7 +11,7 @@ Commands related to health and troubleshooting of the node instance ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -22,4 +22,4 @@ Commands related to health and troubleshooting of the node instance * [client System Health](client_System_Health.md) - RPC endpoint liveness * [client System Version](client_System_Version.md) - Advertised node software version -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_System_Health.md b/app/client/doc/commands/client_System_Health.md index adbf4c209e..37cdc9ad59 100644 --- a/app/client/doc/commands/client_System_Health.md +++ b/app/client/doc/commands/client_System_Health.md @@ -19,7 +19,7 @@ client System Health [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -28,4 +28,4 @@ client System Health [flags] * [client System](client_System.md) - Commands related to health and troubleshooting of the node instance -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_System_Version.md b/app/client/doc/commands/client_System_Version.md index 5b9df6d4a2..65610b606c 100644 --- a/app/client/doc/commands/client_System_Version.md +++ b/app/client/doc/commands/client_System_Version.md @@ -19,7 +19,7 @@ client System Version [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -28,4 +28,4 @@ client System Version [flags] * [client System](client_System.md) - Commands related to health and troubleshooting of the node instance -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Validator.md b/app/client/doc/commands/client_Validator.md index cdcf521bf3..b33b9271a1 100644 --- a/app/client/doc/commands/client_Validator.md +++ b/app/client/doc/commands/client_Validator.md @@ -11,7 +11,7 @@ Validator actor specific commands ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -24,4 +24,4 @@ Validator actor specific commands * [client Validator Unpause](client_Validator_Unpause.md) - Unpause * [client Validator Unstake](client_Validator_Unstake.md) - Unstake -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Validator_EditStake.md b/app/client/doc/commands/client_Validator_EditStake.md index ae6ba1742d..80dd3dbea2 100644 --- a/app/client/doc/commands/client_Validator_EditStake.md +++ b/app/client/doc/commands/client_Validator_EditStake.md @@ -20,7 +20,7 @@ client Validator EditStake [fla ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Validator EditStake [fla * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Validator_Stake.md b/app/client/doc/commands/client_Validator_Stake.md index 72b9da78ff..836ee23c14 100644 --- a/app/client/doc/commands/client_Validator_Stake.md +++ b/app/client/doc/commands/client_Validator_Stake.md @@ -28,7 +28,7 @@ client Validator Stake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -37,4 +37,4 @@ client Validator Stake [flags] * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Validator_Unpause.md b/app/client/doc/commands/client_Validator_Unpause.md index dbca468af8..84494dbe2a 100644 --- a/app/client/doc/commands/client_Validator_Unpause.md +++ b/app/client/doc/commands/client_Validator_Unpause.md @@ -20,7 +20,7 @@ client Validator Unpause [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Validator Unpause [flags] * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_Validator_Unstake.md b/app/client/doc/commands/client_Validator_Unstake.md index df319ebcda..486d2df25d 100644 --- a/app/client/doc/commands/client_Validator_Unstake.md +++ b/app/client/doc/commands/client_Validator_Unstake.md @@ -20,7 +20,7 @@ client Validator Unstake [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -29,4 +29,4 @@ client Validator Unstake [flags] * [client Validator](client_Validator.md) - Validator actor specific commands -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/doc/commands/client_debug.md b/app/client/doc/commands/client_debug.md index bc74e3f15b..6d69844bda 100644 --- a/app/client/doc/commands/client_debug.md +++ b/app/client/doc/commands/client_debug.md @@ -15,7 +15,7 @@ client debug [flags] ### Options inherited from parent commands ``` - --data_dir string Path to store pocket related data (keybase etc.) (default "/Users/olshansky/.pocket") + --data_dir string Path to store pocket related data (keybase etc.) (default "/home/harry/.pocket") --non_interactive if true skips the interactive prompts wherever possible (useful for scripting & automation) --remote_cli_url string takes a remote endpoint in the form of :// (uses RPC Port) (default "http://localhost:50832") ``` @@ -24,4 +24,4 @@ client debug [flags] * [client](client.md) - Pocket Network Command Line Interface (CLI) -###### Auto generated by spf13/cobra on 19-Feb-2023 +###### Auto generated by spf13/cobra on 23-Feb-2023 diff --git a/app/client/keybase/debug/keystore.go b/app/client/keybase/debug/keystore.go index 60a3e14c9a..9e8eca0c65 100644 --- a/app/client/keybase/debug/keystore.go +++ b/app/client/keybase/debug/keystore.go @@ -1,15 +1,14 @@ package debug import ( - "errors" "fmt" - "io/fs" - "log" + "github.com/pokt-network/pocket/shared/converters" "os" "path/filepath" r "runtime" "github.com/pokt-network/pocket/app/client/keybase" + "github.com/pokt-network/pocket/logger" "github.com/pokt-network/pocket/runtime" cryptoPocket "github.com/pokt-network/pocket/shared/crypto" pocketk8s "github.com/pokt-network/pocket/shared/k8s" @@ -34,12 +33,13 @@ var ( func init() { homeDir, err := os.UserHomeDir() if err != nil { - log.Fatalf("[ERROR] Cannot find user home directory: %s", err.Error()) + logger.Global.Fatal().Err(err).Msg("Cannot find user home directory") } debugKeybasePath = homeDir + debugKeybaseSuffix - if err := initializeDebugKeybase(); err != nil { // Initialise the debug keybase with the 999 validators - log.Fatalf("[ERROR] Cannot initialise the keybase with the validator keys: %s", err.Error()) + // Initialise the debug keybase with the 999 validators + if err := initializeDebugKeybase(); err != nil { + logger.Global.Fatal().Err(err).Msg("Cannot initialise the keybase with the validator keys") } } @@ -133,7 +133,7 @@ func fetchValidatorPrivateKeysFromFile() (map[string]string, error) { _, current, _, _ := r.Caller(0) //nolint:gocritic // Use path to find private-keys yaml file from being called in any location in the repo yamlFile := filepath.Join(current, privateKeysYamlFile) - if exists, err := fileExists(yamlFile); !exists || err != nil { + if exists, err := converters.FileExists(yamlFile); !exists || err != nil { return nil, fmt.Errorf("unable to find YAML file: %s", yamlFile) } @@ -159,15 +159,3 @@ func fetchValidatorPrivateKeysFromFile() (map[string]string, error) { } return validatorKeysMap, nil } - -// Check file at the given path exists -func fileExists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if errors.Is(err, fs.ErrNotExist) { - return false, nil - } - return false, err -} diff --git a/app/client/keybase/keybase.go b/app/client/keybase/keybase.go index fca1e4ad1a..7160e5dc03 100644 --- a/app/client/keybase/keybase.go +++ b/app/client/keybase/keybase.go @@ -14,18 +14,17 @@ type Keybase interface { Stop() error // Create new keypair entry in DB - Create(passphrase, hint string) error + Create(passphrase, hint string) (crypto.KeyPair, error) // Insert a new keypair from the private key hex string provided into the DB - ImportFromString(privStr, passphrase, hint string) error + ImportFromString(privStr, passphrase, hint string) (crypto.KeyPair, error) // Insert a new keypair from the JSON string of the encrypted private key into the DB - ImportFromJSON(jsonStr, passphrase string) error + ImportFromJSON(jsonStr, passphrase string) (crypto.KeyPair, error) // Accessors Get(address string) (crypto.KeyPair, error) GetPubKey(address string) (crypto.PublicKey, error) GetPrivKey(address, passphrase string) (crypto.PrivateKey, error) GetAll() (addresses []string, keyPairs []crypto.KeyPair, err error) - Exists(address string) (bool, error) // Exporters ExportPrivString(address, passphrase string) (string, error) diff --git a/app/client/keybase/keybase_test.go b/app/client/keybase/keybase_test.go index aafbf08654..01abe1826e 100644 --- a/app/client/keybase/keybase_test.go +++ b/app/client/keybase/keybase_test.go @@ -33,58 +33,47 @@ func TestKeybase_CreateNewKey(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.Create(testPassphrase, testHint) + keypair, err := db.Create(testPassphrase, testHint) require.NoError(t, err) - addresses, keypairs, err := db.GetAll() + key, err := db.Get(keypair.GetAddressString()) require.NoError(t, err) - require.Equal(t, len(addresses), 1) - require.Equal(t, len(keypairs), 1) + require.Equal(t, len(key.GetAddressBytes()), crypto.AddressLen) - addr := addresses[0] - kp := keypairs[0] - require.Equal(t, len(kp.GetAddressBytes()), crypto.AddressLen) - require.Equal(t, addr, kp.GetAddressString()) + _, err = key.Unarmour(testPassphrase) + require.NoError(t, err) } func TestKeybase_CreateNewKeyNoPassphrase(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.Create("", "") + keypair, err := db.Create("", "") require.NoError(t, err) - addresses, keypairs, err := db.GetAll() + key, err := db.Get(keypair.GetAddressString()) require.NoError(t, err) - require.Equal(t, len(addresses), 1) - require.Equal(t, len(keypairs), 1) + require.Equal(t, len(key.GetAddressBytes()), crypto.AddressLen) - addr := addresses[0] - kp := keypairs[0] - require.Equal(t, len(kp.GetAddressBytes()), crypto.AddressLen) - require.Equal(t, addr, kp.GetAddressString()) + _, err = key.Unarmour("") + require.NoError(t, err) } func TestKeybase_ImportKeyFromString(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.ImportFromString(testPrivString, testPassphrase, testHint) + keypair, err := db.ImportFromString(testPrivString, testPassphrase, testHint) require.NoError(t, err) - addresses, keypairs, err := db.GetAll() + key, err := db.Get(keypair.GetAddressString()) require.NoError(t, err) - require.Equal(t, len(addresses), 1) - require.Equal(t, len(keypairs), 1) - addr := addresses[0] - kp := keypairs[0] - require.Equal(t, len(kp.GetAddressBytes()), crypto.AddressLen) - require.Equal(t, addr, kp.GetAddressString()) - require.Equal(t, kp.GetAddressString(), testAddr) - require.Equal(t, kp.GetPublicKey().String(), testPubString) + require.Equal(t, len(key.GetAddressBytes()), crypto.AddressLen) + require.Equal(t, key.GetAddressString(), testAddr) + require.Equal(t, key.GetPublicKey().String(), testPubString) - privKey, err := kp.Unarmour(testPassphrase) + privKey, err := key.Unarmour(testPassphrase) require.NoError(t, err) require.Equal(t, privKey.String(), testPrivString) } @@ -93,24 +82,18 @@ func TestKeybase_ImportKeyFromStringNoPassphrase(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.ImportFromString(testPrivString, "", "") + keypair, err := db.ImportFromJSON(testJSONString, testPassphrase) require.NoError(t, err) - addresses, keypairs, err := db.GetAll() + key, err := db.Get(keypair.GetAddressString()) require.NoError(t, err) - require.Equal(t, len(addresses), 1) - require.Equal(t, len(keypairs), 1) + require.Equal(t, len(key.GetAddressBytes()), crypto.AddressLen) + require.Equal(t, key.GetAddressString(), testJSONAddr) + require.Equal(t, key.GetPublicKey().String(), testJSONPubString) - addr := addresses[0] - kp := keypairs[0] - require.Equal(t, len(kp.GetAddressBytes()), crypto.AddressLen) - require.Equal(t, addr, kp.GetAddressString()) - require.Equal(t, kp.GetAddressString(), testAddr) - require.Equal(t, kp.GetPublicKey().String(), testPubString) - - privKey, err := kp.Unarmour("") + privKey, err := keypair.Unarmour(testPassphrase) require.NoError(t, err) - require.Equal(t, privKey.String(), testPrivString) + require.Equal(t, privKey.String(), testJSONPrivString) } // TODO: Improve this test/create functions to check string validity @@ -124,30 +107,25 @@ func TestKeybase_ImportKeyFromStringInvalidString(t *testing.T) { falseBz, err := hex.DecodeString(falseAddr) require.NoError(t, err) - err = db.ImportFromString(falseAddr, testPassphrase, testHint) + keypair, err := db.ImportFromString(falseAddr, testPassphrase, testHint) require.EqualError(t, err, crypto.ErrInvalidPrivateKeyLen(len(falseBz)).Error()) + require.Nil(t, keypair) } func TestKeybase_ImportKeyFromJSON(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.ImportFromJSON(testJSONString, testPassphrase) + keypair, err := db.ImportFromJSON(testJSONString, testPassphrase) require.NoError(t, err) - addresses, keypairs, err := db.GetAll() + key, err := db.Get(keypair.GetAddressString()) require.NoError(t, err) - require.Equal(t, len(addresses), 1) - require.Equal(t, len(keypairs), 1) - - addr := addresses[0] - kp := keypairs[0] - require.Equal(t, len(kp.GetAddressBytes()), crypto.AddressLen) - require.Equal(t, addr, kp.GetAddressString()) - require.Equal(t, kp.GetAddressString(), testJSONAddr) - require.Equal(t, kp.GetPublicKey().String(), testJSONPubString) + require.Equal(t, len(key.GetAddressBytes()), crypto.AddressLen) + require.Equal(t, key.GetAddressString(), testJSONAddr) + require.Equal(t, key.GetPublicKey().String(), testJSONPubString) - privKey, err := kp.Unarmour(testPassphrase) + privKey, err := key.Unarmour(testPassphrase) require.NoError(t, err) require.Equal(t, privKey.String(), testJSONPrivString) } @@ -158,15 +136,15 @@ func TestKeybase_GetKey(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - kp, err := db.Get(testKey.Address().String()) + key, err := db.Get(keypair.GetAddressString()) require.NoError(t, err) - require.Equal(t, testKey.Address().Bytes(), kp.GetAddressBytes()) - require.Equal(t, kp.GetAddressString(), testKey.Address().String()) + require.Equal(t, testKey.Address().Bytes(), key.GetAddressBytes()) + require.Equal(t, key.GetAddressString(), testKey.Address().String()) - privKey, err := kp.Unarmour(testPassphrase) + privKey, err := keypair.Unarmour(testPassphrase) require.NoError(t, err) equal := privKey.Equals(testKey) @@ -180,34 +158,9 @@ func TestKeybase_GetKeyDoesntExist(t *testing.T) { testKey := createTestKeys(t, 1)[0] - kp, err := db.Get(testKey.Address().String()) + keypair, err := db.Get(testKey.Address().String()) require.EqualError(t, err, ErrorAddrNotFound(testKey.Address().String()).Error()) - require.Equal(t, kp, nil) -} - -func TestKeybase_CheckKeyExists(t *testing.T) { - db := initDB(t) - defer stopDB(t, db) - - testKey := createTestKeys(t, 1)[0] - - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) - require.NoError(t, err) - - exists, err := db.Exists(testKey.Address().String()) - require.NoError(t, err) - require.Equal(t, exists, true) -} - -func TestKeybase_CheckKeyExistsDoesntExist(t *testing.T) { - db := initDB(t) - defer stopDB(t, db) - - testKey := createTestKeys(t, 1)[0] - - exists, err := db.Exists(testKey.Address().String()) - require.EqualError(t, err, ErrorAddrNotFound(testKey.Address().String()).Error()) - require.Equal(t, exists, false) + require.Equal(t, keypair, nil) } func TestKeybase_GetAllKeys(t *testing.T) { @@ -217,8 +170,9 @@ func TestKeybase_GetAllKeys(t *testing.T) { pkm := make(map[string]crypto.PrivateKey, 0) pks := createTestKeys(t, 5) for i := 0; i < 5; i++ { - err := db.ImportFromString(pks[i].String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(pks[i].String(), testPassphrase, testHint) require.NoError(t, err) + require.NotNil(t, keypair) pkm[pks[i].Address().String()] = pks[i] } @@ -244,10 +198,10 @@ func TestKeybase_GetPubKey(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - pubKey, err := db.GetPubKey(testKey.Address().String()) + pubKey, err := db.GetPubKey(keypair.GetAddressString()) require.NoError(t, err) require.Equal(t, testKey.Address().Bytes(), pubKey.Address().Bytes()) require.Equal(t, pubKey.Address().String(), testKey.Address().String()) @@ -262,10 +216,10 @@ func TestKeybase_GetPrivKey(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - privKey, err := db.GetPrivKey(testKey.Address().String(), testPassphrase) + privKey, err := db.GetPrivKey(keypair.GetAddressString(), testPassphrase) require.NoError(t, err) require.Equal(t, testKey.Address().Bytes(), privKey.Address().Bytes()) require.Equal(t, privKey.Address().String(), testKey.Address().String()) @@ -281,10 +235,10 @@ func TestKeybase_GetPrivKeyWrongPassphrase(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - privKey, err := db.GetPrivKey(testKey.Address().String(), testNewPassphrase) + privKey, err := db.GetPrivKey(keypair.GetAddressString(), testNewPassphrase) require.Equal(t, err, crypto.ErrorWrongPassphrase) require.Nil(t, privKey) } @@ -295,13 +249,10 @@ func TestKeybase_UpdatePassphrase(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - _, err = db.GetPrivKey(testKey.Address().String(), testPassphrase) - require.NoError(t, err) - - err = db.UpdatePassphrase(testKey.Address().String(), testPassphrase, testNewPassphrase, testHint) + err = db.UpdatePassphrase(keypair.GetAddressString(), testPassphrase, testNewPassphrase, testHint) require.NoError(t, err) privKey, err := db.GetPrivKey(testKey.Address().String(), testNewPassphrase) @@ -320,13 +271,10 @@ func TestKeybase_UpdatePassphraseWrongPassphrase(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) - require.NoError(t, err) - - _, err = db.GetPrivKey(testKey.Address().String(), testPassphrase) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - err = db.UpdatePassphrase(testKey.Address().String(), testNewPassphrase, testNewPassphrase, testHint) + err = db.UpdatePassphrase(keypair.GetAddressString(), testNewPassphrase, testNewPassphrase, testHint) require.ErrorIs(t, err, crypto.ErrorWrongPassphrase) } @@ -336,18 +284,15 @@ func TestKeybase_DeleteKey(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) - require.NoError(t, err) - - _, err = db.GetPrivKey(testKey.Address().String(), testPassphrase) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - err = db.Delete(testKey.Address().String(), testPassphrase) + err = db.Delete(keypair.GetAddressString(), testPassphrase) require.NoError(t, err) - kp, err := db.Get(testKey.Address().String()) + delKey, err := db.Get(testKey.Address().String()) require.EqualError(t, err, ErrorAddrNotFound(testKey.Address().String()).Error()) - require.Equal(t, kp, nil) + require.Equal(t, delKey, nil) } func TestKeybase_DeleteKeyWrongPassphrase(t *testing.T) { @@ -356,13 +301,10 @@ func TestKeybase_DeleteKeyWrongPassphrase(t *testing.T) { testKey := createTestKeys(t, 1)[0] - err := db.ImportFromString(testKey.String(), testPassphrase, testHint) + keypair, err := db.ImportFromString(testKey.String(), testPassphrase, testHint) require.NoError(t, err) - _, err = db.GetPrivKey(testKey.Address().String(), testPassphrase) - require.NoError(t, err) - - err = db.Delete(testKey.Address().String(), testNewPassphrase) + err = db.Delete(keypair.GetAddressString(), testNewPassphrase) require.ErrorIs(t, err, crypto.ErrorWrongPassphrase) } @@ -370,21 +312,16 @@ func TestKeybase_SignMessage(t *testing.T) { db := initDB(t) defer stopDB(t, db) - pk := createTestKeyFromString(t, testPrivString) - - err := db.ImportFromString(testPrivString, testPassphrase, testHint) - require.NoError(t, err) - - privKey, err := db.GetPrivKey(pk.Address().String(), testPassphrase) + keypair, err := db.ImportFromString(testPrivString, testPassphrase, testHint) require.NoError(t, err) txBz, err := hex.DecodeString(testTx) require.NoError(t, err) - signedMsg, err := db.Sign(privKey.Address().String(), testPassphrase, txBz) + signedMsg, err := db.Sign(keypair.GetAddressString(), testPassphrase, txBz) require.NoError(t, err) - verified, err := db.Verify(privKey.Address().String(), txBz, signedMsg) + verified, err := db.Verify(keypair.GetAddressString(), txBz, signedMsg) require.NoError(t, err) require.Equal(t, verified, true) } @@ -393,18 +330,13 @@ func TestKeybase_SignMessageWrongPassphrase(t *testing.T) { db := initDB(t) defer stopDB(t, db) - pk := createTestKeyFromString(t, testPrivString) - - err := db.ImportFromString(testPrivString, testPassphrase, testHint) - require.NoError(t, err) - - privKey, err := db.GetPrivKey(pk.Address().String(), testPassphrase) + keypair, err := db.ImportFromString(testPrivString, testPassphrase, testHint) require.NoError(t, err) txBz, err := hex.DecodeString(testTx) require.NoError(t, err) - signedMsg, err := db.Sign(privKey.Address().String(), testNewPassphrase, txBz) + signedMsg, err := db.Sign(keypair.GetAddressString(), testNewPassphrase, txBz) require.ErrorIs(t, err, crypto.ErrorWrongPassphrase) require.Nil(t, signedMsg) } @@ -413,7 +345,7 @@ func TestKeybase_ExportString(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.ImportFromString(testPrivString, testPassphrase, testHint) + _, err := db.ImportFromString(testPrivString, testPassphrase, testHint) require.NoError(t, err) privStr, err := db.ExportPrivString(testAddr, testPassphrase) @@ -425,7 +357,7 @@ func TestKeybase_ExportJSON(t *testing.T) { db := initDB(t) defer stopDB(t, db) - err := db.ImportFromString(testPrivString, testPassphrase, testHint) + _, err := db.ImportFromString(testPrivString, testPassphrase, testHint) require.NoError(t, err) jsonStr, err := db.ExportPrivJSON(testAddr, testPassphrase) @@ -434,12 +366,12 @@ func TestKeybase_ExportJSON(t *testing.T) { err = db.Delete(testAddr, testPassphrase) require.NoError(t, err) - err = db.ImportFromJSON(jsonStr, testPassphrase) + keypair, err := db.ImportFromJSON(jsonStr, testPassphrase) require.NoError(t, err) privKey, err := db.GetPrivKey(testAddr, testPassphrase) require.NoError(t, err) - require.Equal(t, privKey.Address().String(), testAddr) + require.Equal(t, keypair.GetAddressString(), testAddr) require.Equal(t, privKey.String(), testPrivString) } @@ -461,12 +393,6 @@ func createTestKeys(t *testing.T, n int) []crypto.PrivateKey { return pks } -func createTestKeyFromString(t *testing.T, str string) crypto.PrivateKey { - privKey, err := crypto.NewPrivateKey(str) - require.NoError(t, err) - return privKey -} - func stopDB(t *testing.T, db Keybase) { err := db.Stop() require.NoError(t, err) diff --git a/app/client/keybase/keystore.go b/app/client/keybase/keystore.go index c1537a9b50..4b742e9cb4 100644 --- a/app/client/keybase/keystore.go +++ b/app/client/keybase/keystore.go @@ -3,10 +3,8 @@ package keybase import ( "bytes" "encoding/hex" - "errors" "fmt" - "io/fs" - "os" + "github.com/pokt-network/pocket/shared/converters" "strings" "github.com/dgraph-io/badger/v3" @@ -32,7 +30,7 @@ type badgerKeybase struct { // Creates/Opens the DB at the specified path func NewKeybase(path string) (Keybase, error) { - pathExists, err := dirExists(path) // Creates path if it doesn't exist + pathExists, err := converters.DirExists(path) // Creates path if it doesn't exist if err != nil || !pathExists { return nil, err } @@ -66,9 +64,9 @@ func (keybase *badgerKeybase) Stop() error { // Create a new key and store the serialised KeyPair encoding in the DB // Using the PublicKey.Address() return value as the key for storage -func (keybase *badgerKeybase) Create(passphrase, hint string) error { - err := keybase.db.Update(func(tx *badger.Txn) error { - keyPair, err := crypto.CreateNewKey(passphrase, hint) +func (keybase *badgerKeybase) Create(passphrase, hint string) (keyPair crypto.KeyPair, err error) { + err = keybase.db.Update(func(tx *badger.Txn) (err error) { + keyPair, err = crypto.CreateNewKey(passphrase, hint) if err != nil { return err } @@ -84,15 +82,18 @@ func (keybase *badgerKeybase) Create(passphrase, hint string) error { return tx.Set(addrKey, keypairBz) }) + if err != nil { + return nil, err + } - return err + return keyPair, nil } // Create a new KeyPair from the private key hex string and store the serialised KeyPair encoding in the DB // Using the PublicKey.Address() return value as the key for storage -func (keybase *badgerKeybase) ImportFromString(privKeyHex, passphrase, hint string) error { - err := keybase.db.Update(func(tx *badger.Txn) error { - keyPair, err := crypto.CreateNewKeyFromString(privKeyHex, passphrase, hint) +func (keybase *badgerKeybase) ImportFromString(privKeyHex, passphrase, hint string) (keyPair crypto.KeyPair, err error) { + err = keybase.db.Update(func(tx *badger.Txn) (err error) { + keyPair, err = crypto.CreateNewKeyFromString(privKeyHex, passphrase, hint) if err != nil { return err } @@ -108,15 +109,18 @@ func (keybase *badgerKeybase) ImportFromString(privKeyHex, passphrase, hint stri return tx.Set(addrKey, keypairBz) }) + if err != nil { + return nil, err + } - return err + return keyPair, nil } // Create a new KeyPair from the private key JSON string and store the serialised KeyPair encoding in the DB // Using the PublicKey.Address() return value as the key for storage -func (keybase *badgerKeybase) ImportFromJSON(jsonStr, passphrase string) error { - err := keybase.db.Update(func(tx *badger.Txn) error { - keyPair, err := crypto.ImportKeyFromJSON(jsonStr, passphrase) +func (keybase *badgerKeybase) ImportFromJSON(jsonStr, passphrase string) (keyPair crypto.KeyPair, err error) { + err = keybase.db.Update(func(tx *badger.Txn) (err error) { + keyPair, err = crypto.ImportKeyFromJSON(jsonStr, passphrase) if err != nil { return err } @@ -132,8 +136,11 @@ func (keybase *badgerKeybase) ImportFromJSON(jsonStr, passphrase string) error { return tx.Set(addrKey, keypairBz) }) + if err != nil { + return nil, err + } - return err + return keyPair, nil } // Returns a KeyPair struct provided the address was found in the DB @@ -235,15 +242,6 @@ func (keybase *badgerKeybase) GetAll() (addresses []string, keyPairs []crypto.Ke return addresses, keyPairs, nil } -// Check whether an address is currently stored in the DB -func (keybase *badgerKeybase) Exists(address string) (bool, error) { - val, err := keybase.Get(address) - if err != nil { - return false, err - } - return val != nil, nil -} - // Export the Private Key string of the given address func (keybase *badgerKeybase) ExportPrivString(address, passphrase string) (string, error) { kp, err := keybase.Get(address) @@ -341,23 +339,3 @@ func badgerOptions(path string) badger.Options { opts.Logger = nil // Badger logger is very noisy return opts } - -// Check directory exists and creates path if it doesn't exist -func dirExists(path string) (bool, error) { - stat, err := os.Stat(path) - if err == nil { - // Exists but not directory - if !stat.IsDir() { - return false, fmt.Errorf("Keybase path is not a directory: %s", path) - } - return true, nil - } - if errors.Is(err, fs.ErrNotExist) { - // Create directories in path recursively - if err := os.MkdirAll(path, os.ModePerm); err != nil { - return false, fmt.Errorf("Error creating directory at path: %s, (%v)", path, err.Error()) - } - return true, nil - } - return false, err -} diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 53b5e45e3f..9734517297 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.0.0.32] - 2023-02-23 + +- Add file utility functions for checking, reading and writing to files + ## [0.0.0.31] - 2023-02-22 - Export consensus module's ConsensusDebugModule interface. diff --git a/shared/converters/file_utils.go b/shared/converters/file_utils.go new file mode 100644 index 0000000000..bfc0f9d1db --- /dev/null +++ b/shared/converters/file_utils.go @@ -0,0 +1,77 @@ +package converters + +import ( + "errors" + "fmt" + "io/fs" + "os" +) + +// Check directory exists and creates path if it doesn't exist +func DirExists(path string) (bool, error) { + stat, err := os.Stat(path) + if err == nil { + // Exists but not directory + if !stat.IsDir() { + return false, fmt.Errorf("Path exists but is not a directory: %s", path) + } + return true, nil + } + if errors.Is(err, fs.ErrNotExist) { + // Create directories in path recursively + if err := os.MkdirAll(path, os.ModePerm); err != nil { + return false, fmt.Errorf("Error creating directory at path: %s, (%v)", path, err.Error()) + } + return true, nil + } + return false, err +} + +// Check file at the given path exists +func FileExists(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if errors.Is(err, fs.ErrNotExist) { + return false, nil + } + return false, err +} + +func WriteOutput(msg any, outputFile string) error { + if outputFile == "" { + fmt.Println(msg) + return nil + } + file, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) + if err != nil { + return err + } + switch m := msg.(type) { + case string: + if _, err := file.WriteString(m); err != nil { + return err + } + case []byte: + if _, err := file.Write(m); err != nil { + return err + } + } + return file.Close() +} + +func ReadInput(inputFile string) ([]byte, error) { + exists, err := FileExists(inputFile) + if err != nil { + return []byte{}, fmt.Errorf("Error checking input file: %v\n", err) + } + if !exists { + return []byte{}, fmt.Errorf("Input file not found: %v\n", inputFile) + } + rawBz, err := os.ReadFile(inputFile) + if err != nil { + return []byte{}, err + } + return rawBz, nil +} From 27cfe0504a1ea35e36d5e4b325b01b28fa153e96 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Thu, 23 Feb 2023 14:50:31 +0000 Subject: [PATCH 2/2] feat(tooling): return failed tests full output --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 559d351091..d6f62e0c2c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,7 +63,7 @@ jobs: - name: Output test failures # Makes it easier to find failed tests so no need to scroll through the whole log. if: ${{ failure() && env.TARGET_GOLANG_VERSION == matrix.go }} - run: cat test_results.json | jq 'select(.Action == "fail")' + run: jq --argjson fail_tests "$(jq -c -r 'select(.Action == "fail") | select(.Test) | .Test' test_results.json | jq -R -s -c 'split("\n") | map(select(length>0))')" 'select(.Test as $t | ($fail_tests | arrays)[] | select($t == .))' test_results.json - name: Upload test results if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }} uses: actions/upload-artifact@v3