Skip to content

Commit

Permalink
cli: drop support for binary keys, use wallets
Browse files Browse the repository at this point in the history
Wallets were introduced way back when in 0.27.5 and that's the way keys should
be stored. We've had enough transition period for people to adjust to using
them. Binary keys are dangerous and inconvenient (NEP-6 is common for all of
the Neo tooling, everyone knows how to use it), therefore we shouldn't provide
support for them.

Related to #2136.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed May 24, 2023
1 parent a65293d commit d6dd127
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Changelog for NeoFS Node

### Removed
- Non-notary mode support for sidechain (#2321)
- Support for binary keys in the CLI ()

### Updated
- Update minimal supported Go version up to v1.18 (#2340)
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/internal/commonflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
WalletPath = "wallet"
WalletPathShorthand = "w"
WalletPathDefault = ""
WalletPathUsage = "Path to the wallet or binary key"
WalletPathUsage = "Path to the wallet"

Account = "address"
AccountShorthand = ""
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/internal/key/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Test_getOrGenerate(t *testing.T) {
})

t.Run("raw key", func(t *testing.T) {
checkKey(t, keyPath, rawKey)
checkKeyError(t, keyPath, ErrInvalidKey)
})

t.Run("generate", func(t *testing.T) {
Expand Down
18 changes: 7 additions & 11 deletions cmd/neofs-cli/internal/key/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ func Get(cmd *cobra.Command) *ecdsa.PrivateKey {

func get(cmd *cobra.Command) (*ecdsa.PrivateKey, error) {
keyDesc := viper.GetString(commonflags.WalletPath)
data, err := os.ReadFile(keyDesc)
w, err := wallet.NewWalletFromFile(keyDesc)
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrFs, err)
}

priv, err := keys.NewPrivateKeyFromBytes(data)
if err != nil {
w, err := wallet.NewWalletFromFile(keyDesc)
if err == nil {
return FromWallet(cmd, w, viper.GetString(commonflags.Account))
var perr = new(*os.PathError)
if errors.As(err, perr) {
return nil, fmt.Errorf("%w: %v", ErrFs, err)
} else {
return nil, fmt.Errorf("%w: %v", ErrInvalidKey, err)
}
return nil, fmt.Errorf("%w: %v", ErrInvalidKey, err)
}
return &priv.PrivateKey, nil
return FromWallet(cmd, w, viper.GetString(commonflags.Account))
}

// GetOrGenerate is similar to get but generates a new key if commonflags.GenerateKey is set.
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/internal/key/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// Key-related errors.
var (
ErrFs = errors.New("unable to read file from given path")
ErrInvalidKey = errors.New("provided key is incorrect, only wallet or binary key supported")
ErrInvalidKey = errors.New("provided wallet is incorrect")
ErrInvalidAddress = errors.New("--address option must be specified and valid")
ErrInvalidPassword = errors.New("invalid password for the encrypted key")
)
Expand Down

0 comments on commit d6dd127

Please sign in to comment.