11package keys
22
33import (
4+ "encoding/base64"
5+ "encoding/hex"
6+ "encoding/json"
47 "errors"
58 "fmt"
69
@@ -20,7 +23,8 @@ const (
2023 // FlagAddress is the flag for the user's address on the command line.
2124 FlagAddress = "address"
2225 // FlagPublicKey represents the user's public key on the command line.
23- FlagPublicKey = "pubkey"
26+ FlagPublicKey = "pubkey"
27+ FlagPublicKeyHex = "pubkeyhex"
2428 // FlagBechPrefix defines a desired Bech32 prefix encoding for a key.
2529 FlagBechPrefix = "bech"
2630 // FlagDevice indicates that the information should be shown in the device
@@ -44,6 +48,7 @@ consisting of all the keys provided by name and multisig threshold.`,
4448 f .String (FlagBechPrefix , sdk .PrefixAccount , "The Bech32 prefix encoding for a key (acc|val|cons)" )
4549 f .BoolP (FlagAddress , "a" , false , "Output the address only (overrides --output)" )
4650 f .BoolP (FlagPublicKey , "p" , false , "Output the public key only (overrides --output)" )
51+ f .BoolP (FlagPublicKeyHex , "" , false , "Output the public key hex only (overrides --output)" )
4752 f .BoolP (FlagDevice , "d" , false , "Output the address in a ledger device" )
4853 f .Int (flagMultiSigThreshold , 1 , "K out of N required signatures" )
4954
@@ -93,6 +98,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
9398 isShowAddr , _ := cmd .Flags ().GetBool (FlagAddress )
9499 isShowPubKey , _ := cmd .Flags ().GetBool (FlagPublicKey )
95100 isShowDevice , _ := cmd .Flags ().GetBool (FlagDevice )
101+ isShowPubKeyHex , _ := cmd .Flags ().GetBool (FlagPublicKeyHex )
96102
97103 isOutputSet := false
98104 tmp := cmd .Flag (cli .OutputFlag )
@@ -119,7 +125,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
119125 }
120126
121127 switch {
122- case isShowAddr , isShowPubKey :
128+ case isShowAddr , isShowPubKey , isShowPubKeyHex :
123129 ko , err := bechKeyOut (k )
124130 if err != nil {
125131 return err
@@ -128,6 +134,12 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
128134 if isShowPubKey {
129135 out = ko .PubKey
130136 }
137+ if isShowPubKeyHex {
138+ var key Key
139+ json .Unmarshal ([]byte (ko .PubKey ), & key )
140+ bz , _ := base64 .StdEncoding .DecodeString (key .Key )
141+ out = hex .EncodeToString (bz )
142+ }
131143
132144 if _ , err := fmt .Fprintln (cmd .OutOrStdout (), out ); err != nil {
133145 return err
@@ -209,3 +221,8 @@ func getBechKeyOut(bechPrefix string) (bechKeyOutFn, error) {
209221
210222 return nil , fmt .Errorf ("invalid Bech32 prefix encoding provided: %s" , bechPrefix )
211223}
224+
225+ type Key struct {
226+ Types string `json:"@type" yaml:"@type"`
227+ Key string
228+ }
0 commit comments