From a3ac294902a86c3c4f45033e04d28d5787f79254 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 19 May 2021 17:16:48 +0300 Subject: [PATCH] [#505] morph/container: Do not parse public key in Put event parser Morph event structures defined in `pkg/morph/event` should only carry notification values without any additional interpretation. All logical work should be concentrated on app-side. Change data type of `Put.PublicKey` return to byte slice. `ParsePut` doesn't unmarshal public key from now. Signed-off-by: Leonard Lyubich --- .../processors/container/process_container.go | 2 +- pkg/morph/event/container/put.go | 13 +++---------- pkg/morph/event/container/put_test.go | 13 +++---------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index 03c7c1b53..0b929589f 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -44,7 +44,7 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) { err := cp.morphClient.NotaryInvoke(cp.containerContract, cp.feeProvider.SideChainFee(), putContainerMethod, cnrData, put.Signature(), - put.PublicKey().Bytes()) + put.PublicKey()) if err != nil { cp.log.Error("can't invoke new container", zap.Error(err)) } diff --git a/pkg/morph/event/container/put.go b/pkg/morph/event/container/put.go index 094dc77a8..9bf7ee35e 100644 --- a/pkg/morph/event/container/put.go +++ b/pkg/morph/event/container/put.go @@ -1,10 +1,8 @@ package container import ( - "crypto/elliptic" "fmt" - "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" @@ -14,7 +12,7 @@ import ( type Put struct { rawContainer []byte signature []byte - publicKey *keys.PublicKey + publicKey []byte } // MorphEvent implements Neo:Morph Event interface. @@ -27,7 +25,7 @@ func (p Put) Container() []byte { return p.rawContainer } func (p Put) Signature() []byte { return p.signature } // PublicKey of container owner. -func (p Put) PublicKey() *keys.PublicKey { return p.publicKey } +func (p Put) PublicKey() []byte { return p.publicKey } // ParsePut from notification into container event structure. func ParsePut(params []stackitem.Item) (event.Event, error) { @@ -53,15 +51,10 @@ func ParsePut(params []stackitem.Item) (event.Event, error) { } // parse public key - key, err := client.BytesFromStackItem(params[2]) + ev.publicKey, err = client.BytesFromStackItem(params[2]) if err != nil { return nil, fmt.Errorf("could not get public key: %w", err) } - ev.publicKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256()) - if err != nil { - return nil, fmt.Errorf("could not parse public key: %w", err) - } - return ev, nil } diff --git a/pkg/morph/event/container/put_test.go b/pkg/morph/event/container/put_test.go index 5f3638501..75bce11e9 100644 --- a/pkg/morph/event/container/put_test.go +++ b/pkg/morph/event/container/put_test.go @@ -1,14 +1,10 @@ package container import ( - "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-node/pkg/morph/event" - "github.com/nspcc-dev/neofs-node/pkg/util/test" "github.com/stretchr/testify/require" ) @@ -16,7 +12,7 @@ func TestParsePut(t *testing.T) { var ( containerData = []byte("containerData") signature = []byte("signature") - publicKey = &test.DecodeKey(-1).PublicKey + publicKey = []byte("pubkey") ) t.Run("wrong number of parameters", func(t *testing.T) { @@ -60,17 +56,14 @@ func TestParsePut(t *testing.T) { ev, err := ParsePut([]stackitem.Item{ stackitem.NewByteArray(containerData), stackitem.NewByteArray(signature), - stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)), + stackitem.NewByteArray(publicKey), }) require.NoError(t, err) - expectedKey, err := keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKey), elliptic.P256()) - require.NoError(t, err) - require.Equal(t, Put{ rawContainer: containerData, signature: signature, - publicKey: expectedKey, + publicKey: publicKey, }, ev) }) }