From c172fcc11f96e97e00a402a942f378ddeddac7a6 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 15 Jun 2021 18:56:05 +0300 Subject: [PATCH] [#610] neofs-cli: replace `--key` flag with `--wif` Signed-off-by: Evgenii Stratonikov --- cmd/neofs-cli/modules/root.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index b148c9206..19db6432f 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -85,8 +85,8 @@ func init() { rootCmd.PersistentFlags().StringP("binary-key", "", "", "path to the raw private key file") _ = viper.BindPFlag("binary-key", rootCmd.PersistentFlags().Lookup("binary-key")) - rootCmd.PersistentFlags().StringP("key", "k", "", "private key in hex, WIF, NEP-2 or filepath") - _ = viper.BindPFlag("key", rootCmd.PersistentFlags().Lookup("key")) + rootCmd.PersistentFlags().StringP("wif", "", "", "WIF or NEP-2") + _ = viper.BindPFlag("wif", rootCmd.PersistentFlags().Lookup("wif")) rootCmd.PersistentFlags().StringP("wallet", "w", "", "path to the wallet") _ = viper.BindPFlag("wallet", rootCmd.PersistentFlags().Lookup("wallet")) @@ -161,12 +161,17 @@ func getKey() (*ecdsa.PrivateKey, error) { return getKeyFromWallet(w, viper.GetString("address")) } - privateKey := viper.GetString("key") - if len(privateKey) == nep2Base58Length { - return getKeyFromNEP2(privateKey) + wif := viper.GetString("wif") + if len(wif) == nep2Base58Length { + return getKeyFromNEP2(wif) } - return nil, errInvalidKey + priv, err := keys.NewPrivateKeyFromWIF(wif) + if err != nil { + return nil, fmt.Errorf("%w: %v", errInvalidKey, err) + } + + return &priv.PrivateKey, nil } func getKeyFromFile(keyPath string) (*ecdsa.PrivateKey, error) {