|  | 
| 4 | 4 | 	"context" | 
| 5 | 5 | 	"encoding/base64" | 
| 6 | 6 | 	"encoding/hex" | 
|  | 7 | +	"fmt" | 
| 7 | 8 | 	"strings" | 
| 8 | 9 | 
 | 
| 9 | 10 | 	k1 "github.com/cometbft/cometbft/crypto/secp256k1" | 
| @@ -35,6 +36,7 @@ func newKeyCmds() *cobra.Command { | 
| 35 | 36 | 		newKeyConvertCmd(), | 
| 36 | 37 | 		newKeyGenPrivKeyJSONCmd(), | 
| 37 | 38 | 		newKeyEncryptCmd(), | 
|  | 39 | +		newKeyShowEncryptedCmd(), | 
| 38 | 40 | 	) | 
| 39 | 41 | 
 | 
| 40 | 42 | 	return cmd | 
| @@ -104,6 +106,29 @@ func newKeyEncryptCmd() *cobra.Command { | 
| 104 | 106 | 	return cmd | 
| 105 | 107 | } | 
| 106 | 108 | 
 | 
|  | 109 | +func newKeyShowEncryptedCmd() *cobra.Command { | 
|  | 110 | +	var cfg showEncryptedConfig | 
|  | 111 | + | 
|  | 112 | +	cmd := &cobra.Command{ | 
|  | 113 | +		Use:   "show-encrypted", | 
|  | 114 | +		Short: "Show the encrypted private key after decryption", | 
|  | 115 | +		Args:  cobra.NoArgs, | 
|  | 116 | +		PreRunE: func(_ *cobra.Command, _ []string) error { | 
|  | 117 | +			return nil | 
|  | 118 | +		}, | 
|  | 119 | +		RunE: runValidatorCommand( | 
|  | 120 | +			func(_ *cobra.Command) error { | 
|  | 121 | +				return validateShowEncryptedFlags(&cfg) | 
|  | 122 | +			}, | 
|  | 123 | +			func(_ context.Context) error { return showEncryptedKey(cfg) }, | 
|  | 124 | +		), | 
|  | 125 | +	} | 
|  | 126 | + | 
|  | 127 | +	bindKeyShowEncryptedFlags(cmd, &cfg) | 
|  | 128 | + | 
|  | 129 | +	return cmd | 
|  | 130 | +} | 
|  | 131 | + | 
| 107 | 132 | func convertKey(_ context.Context, cfg keyConfig) error { | 
| 108 | 133 | 	var compressedPubKeyBytes []byte | 
| 109 | 134 | 	var err error | 
| @@ -191,3 +216,26 @@ func encryptPrivKey(cfg baseConfig) error { | 
| 191 | 216 | 
 | 
| 192 | 217 | 	return nil | 
| 193 | 218 | } | 
|  | 219 | + | 
|  | 220 | +func showEncryptedKey(cfg showEncryptedConfig) error { | 
|  | 221 | +	encPrivKeyFile := cfg.EncPrivKeyFile() | 
|  | 222 | +	pv, err := app.LoadEncryptedPrivKey(encPrivKeyFile) | 
|  | 223 | +	if err != nil { | 
|  | 224 | +		return errors.Wrap(err, "failed to load encrypted private key") | 
|  | 225 | +	} | 
|  | 226 | + | 
|  | 227 | +	cmpPubKeyBytes, err := privKeyToCmpPubKey(pv.PrivKey.Bytes()) | 
|  | 228 | +	if err != nil { | 
|  | 229 | +		return errors.Wrap(err, "failed to get compressed public key from private key") | 
|  | 230 | +	} | 
|  | 231 | + | 
|  | 232 | +	if err := printKeyFormats(cmpPubKeyBytes); err != nil { | 
|  | 233 | +		return errors.Wrap(err, "failed to print key formats") | 
|  | 234 | +	} | 
|  | 235 | + | 
|  | 236 | +	if cfg.ShowPrivate { | 
|  | 237 | +		fmt.Println("Private Key (hex):", hex.EncodeToString(pv.PrivKey.Bytes())) | 
|  | 238 | +	} | 
|  | 239 | + | 
|  | 240 | +	return nil | 
|  | 241 | +} | 
0 commit comments