forked from TrueCloudLab/frostfs-node
[#562] pkg/morph: remove neofs-crypto uses
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
fcdef227e4
commit
5cab0026c3
6 changed files with 30 additions and 52 deletions
|
@ -30,7 +30,7 @@ func initMorphComponents(c *cfg) {
|
|||
})
|
||||
|
||||
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 {
|
||||
c.log.Info("neo RPC connection established",
|
||||
zap.String("endpoint", addresses[i]))
|
||||
|
|
|
@ -742,7 +742,7 @@ func createListener(ctx context.Context, p *chainParams) (event.Listener, error)
|
|||
|
||||
func createClient(ctx context.Context, p *chainParams) (*client.Client, error) {
|
||||
return client.New(
|
||||
&p.key.PrivateKey,
|
||||
p.key,
|
||||
p.cfg.GetString(p.name+".endpoint.client"),
|
||||
client.WithContext(ctx),
|
||||
client.WithLogger(p.log),
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
auditAPI "github.com/nspcc-dev/neofs-api-go/pkg/audit"
|
||||
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"
|
||||
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -21,11 +21,9 @@ func TestAuditResults(t *testing.T) {
|
|||
sAuditHash := "cdfb3dab86e6d60e8a143d9e2ecb0b188f3dc2eb"
|
||||
irKeyWIF := "L3o221BojgcCPYgdbXsm6jn7ayTZ72xwREvBHXKknR8VJ3G4WmjB"
|
||||
|
||||
key, err := crypto.WIFDecode(irKeyWIF)
|
||||
key, err := keys.NewPrivateKeyFromWIF(irKeyWIF)
|
||||
require.NoError(t, err)
|
||||
|
||||
pubKey := crypto.MarshalPublicKey(&key.PublicKey)
|
||||
|
||||
auditHash, err := util.Uint160DecodeStringLE(sAuditHash)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -39,7 +37,7 @@ func TestAuditResults(t *testing.T) {
|
|||
|
||||
auditRes := auditAPI.NewResult()
|
||||
auditRes.SetAuditEpoch(epoch)
|
||||
auditRes.SetPublicKey(pubKey)
|
||||
auditRes.SetPublicKey(key.PublicKey().Bytes())
|
||||
auditRes.SetContainerID(id)
|
||||
|
||||
require.NoError(t, auditClientWrapper.PutAuditResult(auditRes))
|
||||
|
|
|
@ -2,7 +2,6 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"time"
|
||||
|
||||
"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/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -47,7 +45,7 @@ func defaultConfig() *cfg {
|
|||
|
||||
// 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:
|
||||
// * client context: Background;
|
||||
|
@ -58,22 +56,12 @@ func defaultConfig() *cfg {
|
|||
// If desired option satisfies the default value, it can be omitted.
|
||||
// If multiple options of the same config value are supplied,
|
||||
// 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 {
|
||||
return nil, crypto.ErrEmptyPrivateKey
|
||||
panic("empty private key")
|
||||
}
|
||||
|
||||
privKeyBytes := crypto.MarshalPrivateKey(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
|
||||
}
|
||||
account := wallet.NewAccountFromPrivateKey(key)
|
||||
|
||||
// build default configuration
|
||||
cfg := defaultConfig()
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
package neofs
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"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/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) {
|
||||
var (
|
||||
publicKeys = []*ecdsa.PublicKey{
|
||||
&test.DecodeKey(1).PublicKey,
|
||||
&test.DecodeKey(2).PublicKey,
|
||||
&test.DecodeKey(3).PublicKey,
|
||||
publicKeys = []*keys.PublicKey{
|
||||
genKey(t).PublicKey(),
|
||||
genKey(t).PublicKey(),
|
||||
genKey(t).PublicKey(),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -43,22 +45,15 @@ func TestParseUpdateInnerRing(t *testing.T) {
|
|||
t.Run("correct", func(t *testing.T) {
|
||||
ev, err := ParseUpdateInnerRing([]stackitem.Item{
|
||||
stackitem.NewArray([]stackitem.Item{
|
||||
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[0])),
|
||||
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[1])),
|
||||
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKeys[2])),
|
||||
stackitem.NewByteArray(publicKeys[0].Bytes()),
|
||||
stackitem.NewByteArray(publicKeys[1].Bytes()),
|
||||
stackitem.NewByteArray(publicKeys[2].Bytes()),
|
||||
}),
|
||||
})
|
||||
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{
|
||||
keys: expKeys,
|
||||
keys: publicKeys,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
package netmap
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"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/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseUpdatePeer(t *testing.T) {
|
||||
priv, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
var (
|
||||
publicKey = &test.DecodeKey(-1).PublicKey
|
||||
publicKey = priv.PublicKey()
|
||||
state = netmap.NodeStateOffline
|
||||
)
|
||||
|
||||
|
@ -39,7 +39,7 @@ func TestParseUpdatePeer(t *testing.T) {
|
|||
|
||||
t.Run("wrong second parameter type", func(t *testing.T) {
|
||||
_, err := ParseUpdatePeer([]stackitem.Item{
|
||||
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
|
||||
stackitem.NewByteArray(publicKey.Bytes()),
|
||||
stackitem.NewMap(),
|
||||
})
|
||||
|
||||
|
@ -49,15 +49,12 @@ func TestParseUpdatePeer(t *testing.T) {
|
|||
t.Run("correct behavior", func(t *testing.T) {
|
||||
ev, err := ParseUpdatePeer([]stackitem.Item{
|
||||
stackitem.NewBigInteger(new(big.Int).SetInt64(int64(state.ToV2()))),
|
||||
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
|
||||
stackitem.NewByteArray(publicKey.Bytes()),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedKey, err := keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKey), elliptic.P256())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, UpdatePeer{
|
||||
publicKey: expectedKey,
|
||||
publicKey: publicKey,
|
||||
status: state,
|
||||
}, ev)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue