[#562] pkg/morph: remove neofs-crypto uses

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-05-31 11:55:40 +03:00 committed by Alex Vanin
parent fcdef227e4
commit 5cab0026c3
6 changed files with 30 additions and 52 deletions

View file

@ -30,7 +30,7 @@ func initMorphComponents(c *cfg) {
}) })
for i := range addresses { for i := range addresses {
cli, err := client.New(&c.key.PrivateKey, addresses[i], client.WithDialTimeout(dialTimeout)) cli, err := client.New(c.key, addresses[i], client.WithDialTimeout(dialTimeout))
if err == nil { if err == nil {
c.log.Info("neo RPC connection established", c.log.Info("neo RPC connection established",
zap.String("endpoint", addresses[i])) zap.String("endpoint", addresses[i]))

View file

@ -742,7 +742,7 @@ func createListener(ctx context.Context, p *chainParams) (event.Listener, error)
func createClient(ctx context.Context, p *chainParams) (*client.Client, error) { func createClient(ctx context.Context, p *chainParams) (*client.Client, error) {
return client.New( return client.New(
&p.key.PrivateKey, p.key,
p.cfg.GetString(p.name+".endpoint.client"), p.cfg.GetString(p.name+".endpoint.client"),
client.WithContext(ctx), client.WithContext(ctx),
client.WithLogger(p.log), client.WithLogger(p.log),

View file

@ -4,10 +4,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
auditAPI "github.com/nspcc-dev/neofs-api-go/pkg/audit" auditAPI "github.com/nspcc-dev/neofs-api-go/pkg/audit"
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper" auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -21,11 +21,9 @@ func TestAuditResults(t *testing.T) {
sAuditHash := "cdfb3dab86e6d60e8a143d9e2ecb0b188f3dc2eb" sAuditHash := "cdfb3dab86e6d60e8a143d9e2ecb0b188f3dc2eb"
irKeyWIF := "L3o221BojgcCPYgdbXsm6jn7ayTZ72xwREvBHXKknR8VJ3G4WmjB" irKeyWIF := "L3o221BojgcCPYgdbXsm6jn7ayTZ72xwREvBHXKknR8VJ3G4WmjB"
key, err := crypto.WIFDecode(irKeyWIF) key, err := keys.NewPrivateKeyFromWIF(irKeyWIF)
require.NoError(t, err) require.NoError(t, err)
pubKey := crypto.MarshalPublicKey(&key.PublicKey)
auditHash, err := util.Uint160DecodeStringLE(sAuditHash) auditHash, err := util.Uint160DecodeStringLE(sAuditHash)
require.NoError(t, err) require.NoError(t, err)
@ -39,7 +37,7 @@ func TestAuditResults(t *testing.T) {
auditRes := auditAPI.NewResult() auditRes := auditAPI.NewResult()
auditRes.SetAuditEpoch(epoch) auditRes.SetAuditEpoch(epoch)
auditRes.SetPublicKey(pubKey) auditRes.SetPublicKey(key.PublicKey().Bytes())
auditRes.SetContainerID(id) auditRes.SetContainerID(id)
require.NoError(t, auditClientWrapper.PutAuditResult(auditRes)) require.NoError(t, auditClientWrapper.PutAuditResult(auditRes))

View file

@ -2,7 +2,6 @@ package client
import ( import (
"context" "context"
"crypto/ecdsa"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
@ -10,7 +9,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/client"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neo-go/pkg/wallet"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -47,7 +45,7 @@ func defaultConfig() *cfg {
// New creates, initializes and returns the Client instance. // New creates, initializes and returns the Client instance.
// //
// If private key is nil, crypto.ErrEmptyPrivateKey is returned. // If private key is nil, it panics.
// //
// Other values are set according to provided options, or by default: // Other values are set according to provided options, or by default:
// * client context: Background; // * client context: Background;
@ -58,22 +56,12 @@ func defaultConfig() *cfg {
// If desired option satisfies the default value, it can be omitted. // If desired option satisfies the default value, it can be omitted.
// If multiple options of the same config value are supplied, // If multiple options of the same config value are supplied,
// the option with the highest index in the arguments will be used. // the option with the highest index in the arguments will be used.
func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error) { func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error) {
if key == nil { if key == nil {
return nil, crypto.ErrEmptyPrivateKey panic("empty private key")
} }
privKeyBytes := crypto.MarshalPrivateKey(key) account := wallet.NewAccountFromPrivateKey(key)
wif, err := keys.WIFEncode(privKeyBytes, keys.WIFVersion, true)
if err != nil {
return nil, err
}
account, err := wallet.NewAccountFromWIF(wif)
if err != nil {
return nil, err
}
// build default configuration // build default configuration
cfg := defaultConfig() cfg := defaultConfig()

View file

@ -1,24 +1,26 @@
package neofs package neofs
import ( import (
"crypto/ecdsa"
"crypto/elliptic"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func genKey(t *testing.T) *keys.PrivateKey {
priv, err := keys.NewPrivateKey()
require.NoError(t, err)
return priv
}
func TestParseUpdateInnerRing(t *testing.T) { func TestParseUpdateInnerRing(t *testing.T) {
var ( var (
publicKeys = []*ecdsa.PublicKey{ publicKeys = []*keys.PublicKey{
&test.DecodeKey(1).PublicKey, genKey(t).PublicKey(),
&test.DecodeKey(2).PublicKey, genKey(t).PublicKey(),
&test.DecodeKey(3).PublicKey, genKey(t).PublicKey(),
} }
) )
@ -43,22 +45,15 @@ func TestParseUpdateInnerRing(t *testing.T) {
t.Run("correct", func(t *testing.T) { t.Run("correct", func(t *testing.T) {
ev, err := ParseUpdateInnerRing([]stackitem.Item{ ev, err := ParseUpdateInnerRing([]stackitem.Item{
stackitem.NewArray([]stackitem.Item{ stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])), stackitem.NewByteArray(publicKeys[0].Bytes()),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])), stackitem.NewByteArray(publicKeys[1].Bytes()),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])), stackitem.NewByteArray(publicKeys[2].Bytes()),
}), }),
}) })
require.NoError(t, err) require.NoError(t, err)
expKeys := make([]*keys.PublicKey, len(publicKeys))
for i := range publicKeys {
expKeys[i], err = keys.NewPublicKeyFromBytes(
crypto.MarshalPublicKey(publicKeys[i]), elliptic.P256())
require.NoError(t, err)
}
require.Equal(t, UpdateInnerRing{ require.Equal(t, UpdateInnerRing{
keys: expKeys, keys: publicKeys,
}, ev) }, ev)
}) })
} }

View file

@ -1,22 +1,22 @@
package netmap package netmap
import ( import (
"crypto/elliptic"
"math/big" "math/big"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestParseUpdatePeer(t *testing.T) { func TestParseUpdatePeer(t *testing.T) {
priv, err := keys.NewPrivateKey()
require.NoError(t, err)
var ( var (
publicKey = &test.DecodeKey(-1).PublicKey publicKey = priv.PublicKey()
state = netmap.NodeStateOffline state = netmap.NodeStateOffline
) )
@ -39,7 +39,7 @@ func TestParseUpdatePeer(t *testing.T) {
t.Run("wrong second parameter type", func(t *testing.T) { t.Run("wrong second parameter type", func(t *testing.T) {
_, err := ParseUpdatePeer([]stackitem.Item{ _, err := ParseUpdatePeer([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)), stackitem.NewByteArray(publicKey.Bytes()),
stackitem.NewMap(), stackitem.NewMap(),
}) })
@ -49,15 +49,12 @@ func TestParseUpdatePeer(t *testing.T) {
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseUpdatePeer([]stackitem.Item{ ev, err := ParseUpdatePeer([]stackitem.Item{
stackitem.NewBigInteger(new(big.Int).SetInt64(int64(state.ToV2()))), stackitem.NewBigInteger(new(big.Int).SetInt64(int64(state.ToV2()))),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)), stackitem.NewByteArray(publicKey.Bytes()),
}) })
require.NoError(t, err) require.NoError(t, err)
expectedKey, err := keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKey), elliptic.P256())
require.NoError(t, err)
require.Equal(t, UpdatePeer{ require.Equal(t, UpdatePeer{
publicKey: expectedKey, publicKey: publicKey,
status: state, status: state,
}, ev) }, ev)
}) })