Skip to content

Commit

Permalink
Add ggt utils mnemonic-addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJohnnyGault committed May 11, 2023
1 parent 1944bcf commit 9efeef4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
65 changes: 65 additions & 0 deletions cmd/utilscmd/mnemonic_addrs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package utilscmd

import (
"fmt"

"github.com/multisig-labs/gogotools/pkg/hd"

"github.com/spf13/cobra"
"github.com/tyler-smith/go-bip39"
)

func newMnemonicAddrsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mnemonic-addrs [mnemonic] [hrp]",
Short: "Show public addresses for a BIP39 mnemonic",
Long: ``,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if ok := bip39.IsMnemonicValid(args[0]); !ok {
return fmt.Errorf("invaid mnemonic")
}

hrp := "avax"
if len(args) > 1 {
hrp = args[1]
}

fmt.Printf("=== C-Chain [%s] ===\n", hrp)

hdkeys, err := hd.DeriveHDKeys(args[0], hd.EthDerivationPath, 10)
if err != nil {
return fmt.Errorf("error deriving keys: %s", err)
}

for _, k := range hdkeys {
fmt.Printf("%s %s\n", k.EthAddr(), k.Path)
}

fmt.Printf("=== X-Chain [%s] ===\n", hrp)

hdkeys, err = hd.DeriveHDKeys(args[0], hd.AvaDerivationPath, 10)
if err != nil {
return fmt.Errorf("error deriving keys: %s", err)
}

for _, k := range hdkeys {
fmt.Printf("%s %s\n", k.AvaAddr("X", hrp), k.Path)
}

fmt.Printf("=== P-Chain [%s] ===\n", hrp)

hdkeys, err = hd.DeriveHDKeys(args[0], hd.AvaDerivationPath, 10)
if err != nil {
return fmt.Errorf("error deriving keys: %s", err)
}

for _, k := range hdkeys {
fmt.Printf("%s %s\n", k.AvaAddr("P", hrp), k.Path)
}

return nil
},
}
return cmd
}
4 changes: 2 additions & 2 deletions cmd/utilscmd/mnemonic_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newMnemonicKeysCmd() *cobra.Command {
fmt.Printf("%s %s %s\n", k.EthAddr(), k.EthPrivKey(), k.Path)
}

fmt.Println("=== X-Chain ===")
fmt.Printf("=== X-Chain [%s] ===\n", hrp)

hdkeys, err = hd.DeriveHDKeys(args[0], hd.AvaDerivationPath, 10)
if err != nil {
Expand All @@ -47,7 +47,7 @@ func newMnemonicKeysCmd() *cobra.Command {
fmt.Printf("%s %s %s\n", k.AvaAddr("X", hrp), k.AvaPrivKey(), k.Path)
}

fmt.Println("=== P-Chain ===")
fmt.Printf("=== P-Chain [%s] ===\n", hrp)

hdkeys, err = hd.DeriveHDKeys(args[0], hd.AvaDerivationPath, 10)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/utilscmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewCmd(injectedApp *application.GoGoTools) *cobra.Command {
cmd.AddCommand(newAddrVariantsCmd())
cmd.AddCommand(newMnemonicCmd())
cmd.AddCommand(newMnemonicKeysCmd())
cmd.AddCommand(newMnemonicAddrsCmd())
cmd.AddCommand(newPortFwdCmd())

return cmd
Expand Down

0 comments on commit 9efeef4

Please sign in to comment.