Skip to content

Commit

Permalink
Merge remote-tracking branch 'pokt/main' into chore/libp2p-1
Browse files Browse the repository at this point in the history
* pokt/main:
  [Tooling] SLIP-0010 HD Child Key Generation (#510)
  • Loading branch information
bryanchriswhite committed Feb 28, 2023
2 parents ef27909 + feadb65 commit f2d2c78
Show file tree
Hide file tree
Showing 59 changed files with 812 additions and 85 deletions.
62 changes: 62 additions & 0 deletions app/client/cli/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/pokt-network/pocket/shared/crypto"
utilTypes "github.com/pokt-network/pocket/utility/types"
"path/filepath"
"strconv"
"strings"

"github.com/pokt-network/pocket/app/client/keybase"
Expand All @@ -23,6 +24,9 @@ var (
importAs string
hint string
newPwd string
storeChild bool
childPwd string
childHint string
)

func init() {
Expand All @@ -45,6 +49,7 @@ func NewKeysCommand() *cobra.Command {
importCmds := keysImportCommands()
signMsgCmds := keysSignMsgCommands()
signTxCmds := keysSignTxCommands()
slipCmds := keysSlipCommands()

// Add --pwd and --hint flags
applySubcommandOptions(createCmds, attachPwdFlagToSubcommands())
Expand Down Expand Up @@ -77,6 +82,12 @@ func NewKeysCommand() *cobra.Command {
applySubcommandOptions(signTxCmds, attachInputFlagToSubcommands())
applySubcommandOptions(signTxCmds, attachOutputFlagToSubcommands())

// Add --pwd, --store_child, --child_pwd, --child_hint flags
applySubcommandOptions(slipCmds, attachPwdFlagToSubcommands())
applySubcommandOptions(slipCmds, attachStoreChildFlagToSubcommands())
applySubcommandOptions(slipCmds, attachChildPwdFlagToSubcommands())
applySubcommandOptions(slipCmds, attachChildHintFlagToSubcommands())

cmd.AddCommand(createCmds...)
cmd.AddCommand(updateCmds...)
cmd.AddCommand(deleteCmds...)
Expand All @@ -85,6 +96,7 @@ func NewKeysCommand() *cobra.Command {
cmd.AddCommand(importCmds...)
cmd.AddCommand(signMsgCmds...)
cmd.AddCommand(signTxCmds...)
cmd.AddCommand(slipCmds...)

return cmd
}
Expand Down Expand Up @@ -680,3 +692,53 @@ func keysSignTxCommands() []*cobra.Command {
}
return cmds
}

func keysSlipCommands() []*cobra.Command {
cmds := []*cobra.Command{
{
Use: "DeriveChild <parentAddrHex> <index>",
Short: "Derive the child key at the given index from a parent key",
Long: "Derive the child key at <index> from the parent key provided optionally store it in the keybase with [--store_child]",
Aliases: []string{"derivechild"},
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
// Unpack CLI args
parentAddr := args[0]
idx64, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return err
}
index := uint32(idx64)

// 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.DeriveChildFromKey(parentAddr, pwd, index, childPwd, childHint, storeChild)
if err != nil {
return err
}

if err := kb.Stop(); err != nil {
return err
}

logger.Global.Info().Str("address", kp.GetAddressString()).Str("parent", parentAddr).Uint32("index", index).Bool("stored", storeChild).Msg("Child key derived")

return nil
},
},
}
return cmds
}
18 changes: 18 additions & 0 deletions app/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ func attachHintFlagToSubcommands() []cmdOption {
}}
}

func attachStoreChildFlagToSubcommands() []cmdOption {
return []cmdOption{func(c *cobra.Command) {
c.Flags().BoolVar(&storeChild, "store_child", true, "store the derived child key in the keybase")
}}
}

func attachChildHintFlagToSubcommands() []cmdOption {
return []cmdOption{func(c *cobra.Command) {
c.Flags().StringVar(&childHint, "child_hint", "", "hint for the passphrase of the derived child's private key")
}}
}

func attachChildPwdFlagToSubcommands() []cmdOption {
return []cmdOption{func(c *cobra.Command) {
c.Flags().StringVar(&childPwd, "child_pwd", "", "passphrase for the derived child's private key")
}}
}

func unableToConnectToRpc(err error) error {
fmt.Printf("❌ Unable to connect to the RPC @ %s\n\nError: %s", boldText(remoteCLIURL), err)
return nil
Expand Down
5 changes: 5 additions & 0 deletions app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.18] - 2023-02-28

- Implement SLIP-0010 HD child key derivation with the keybase
- Add CLI endpoints to derive child keys by index

## [0.0.0.17] - 2023-02-23

- Add CLI endpoints to interact with the keybase
Expand Down
2 changes: 1 addition & 1 deletion app/client/doc/commands/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The CLI is meant to be an user but also a machine friendly way for interacting w
* [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 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Account specific commands
* [client](client.md) - Pocket Network Command Line Interface (CLI)
* [client Account Send](client_Account_Send.md) - Send <fromAddr> <to> <amount>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Account_Send.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Account Send <fromAddr> <to> <amount> [flags]

* [client Account](client_Account.md) - Account specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Application actor specific commands
* [client Application Unpause](client_Application_Unpause.md) - Unpause <fromAddr>
* [client Application Unstake](client_Application_Unstake.md) - Unstake <fromAddr>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_EditStake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Application EditStake <fromAddr> <amount> <relayChainIDs> <serviceURI> [f

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_Stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ client Application Stake <fromAddr> <amount> <relayChainIDs> <serviceURI> [flags

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_Unpause.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Application Unpause <fromAddr> [flags]

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_Unstake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Application Unstake <fromAddr> [flags]

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_Height.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus Height [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_Round.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus Round [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_State.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus State [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_Step.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus Step [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Fisherman.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Fisherman actor specific commands
* [client Fisherman Unpause](client_Fisherman_Unpause.md) - Unpause <fromAddr>
* [client Fisherman Unstake](client_Fisherman_Unstake.md) - Unstake <fromAddr>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Fisherman_EditStake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Fisherman EditStake <fromAddr> <amount> <relayChainIDs> <serviceURI> [fla

* [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Fisherman_Stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ client Fisherman Stake <fromAddr> <amount> <relayChainIDs> <serviceURI> [flags]

* [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Fisherman_Unpause.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Fisherman Unpause <fromAddr> [flags]

* [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Fisherman_Unstake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Fisherman Unstake <fromAddr> [flags]

* [client Fisherman](client_Fisherman.md) - Fisherman actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Governance specific commands
* [client](client.md) - Pocket Network Command Line Interface (CLI)
* [client Governance ChangeParameter](client_Governance_ChangeParameter.md) - ChangeParameter <owner> <key> <value>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Governance ChangeParameter <owner> <key> <value> [flags]

* [client Governance](client_Governance.md) - Governance specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
3 changes: 2 additions & 1 deletion app/client/doc/commands/client_Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Key specific commands
* [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 DeriveChild](client_Keys_DeriveChild.md) - Derive the child key at the given index from a parent key
* [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
Expand All @@ -31,4 +32,4 @@ Key specific commands
* [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
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Create.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ client Keys Create [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Keys Delete <addrHex> [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
35 changes: 35 additions & 0 deletions app/client/doc/commands/client_Keys_DeriveChild.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## client Keys DeriveChild

Derive the child key at the given index from a parent key

### Synopsis

Derive the child key at <index> from the parent key provided optionally store it in the keybase with [--store_child]

```
client Keys DeriveChild <parentAddrHex> <index> [flags]
```

### Options

```
--child_hint string hint for the passphrase of the derived child's private key
--child_pwd string passphrase for the derived child's private key
-h, --help help for DeriveChild
--pwd string passphrase used by the cmd, non empty usage bypass interactive prompt
--store_child store the derived child key in the keybase (default true)
```

### 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 <protocol>://<host> (uses RPC Port) (default "http://localhost:50832")
```

### SEE ALSO

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Export.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ client Keys Export <addrHex> [--export_format] [--output_file] [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Get.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Keys Get <addrHex> [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Import.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ client Keys Import [privateKeyString] [--input_file] [--import_format] [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_List.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Keys List [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Sign.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Keys Sign <addrHex> <messageHex> [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_SignTx.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ client Keys SignTx <addrHex> [--input_file] [--output_file] [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ client Keys Update <addrHex> [--pwd] [--new_pwd] [--hint] [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_Verify.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Keys Verify <addrHex> <messageHex> <signatureHex> [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Keys_VerifyTx.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ client Keys VerifyTx <addrHex> [--input_file] [flags]

* [client Keys](client_Keys.md) - Key specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Servicer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Servicer actor specific commands
* [client Servicer Unpause](client_Servicer_Unpause.md) - Unpause <fromAddr>
* [client Servicer Unstake](client_Servicer_Unstake.md) - Unstake <fromAddr>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Servicer_EditStake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Servicer EditStake <fromAddr> <amount> <relayChainIDs> <serviceURI> [flag

* [client Servicer](client_Servicer.md) - Servicer actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Servicer_Stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ client Servicer Stake <fromAddr> <amount> <relayChainIDs> <serviceURI> [flags]

* [client Servicer](client_Servicer.md) - Servicer actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Servicer_Unpause.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Servicer Unpause <fromAddr> [flags]

* [client Servicer](client_Servicer.md) - Servicer actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
Loading

0 comments on commit f2d2c78

Please sign in to comment.