From 9ba44651c7a32360a01489c0ebbe3b792f869312 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Wed, 25 Sep 2024 16:08:16 +0200 Subject: [PATCH] chore(communities)_: mv `unmarshalCommunityDescriptionMessage` to manager --- .../community_events_processing.go | 37 ------------------- protocol/communities/manager.go | 35 ++++++++++++++++++ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/protocol/communities/community_events_processing.go b/protocol/communities/community_events_processing.go index 147f63ae6..4fe962b45 100644 --- a/protocol/communities/community_events_processing.go +++ b/protocol/communities/community_events_processing.go @@ -1,14 +1,12 @@ package communities import ( - "crypto/ecdsa" "errors" "sort" "github.com/golang/protobuf/proto" "go.uber.org/zap" - utils "github.com/status-im/status-go/common" "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/protobuf" ) @@ -313,38 +311,3 @@ func (o *Community) toCommunityEventsMessage() *CommunityEventsMessage { Events: o.config.EventsData.Events, } } - -func unmarshalCommunityDescriptionMessage(signedDescription []byte, signerPubkey *ecdsa.PublicKey) (*protobuf.CommunityDescription, error) { - metadata := &protobuf.ApplicationMetadataMessage{} - - err := proto.Unmarshal(signedDescription, metadata) - if err != nil { - return nil, err - } - - if metadata.Type != protobuf.ApplicationMetadataMessage_COMMUNITY_DESCRIPTION { - return nil, ErrInvalidMessage - } - - signer, err := utils.RecoverKey(metadata) - if err != nil { - return nil, err - } - - if signer == nil { - return nil, errors.New("CommunityDescription does not contain the control node signature") - } - - if !signer.Equal(signerPubkey) { - return nil, errors.New("CommunityDescription was not signed by an owner") - } - - description := &protobuf.CommunityDescription{} - - err = proto.Unmarshal(metadata.Payload, description) - if err != nil { - return nil, err - } - - return description, nil -} diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index a5f371f6f..d15691c14 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -5259,3 +5259,38 @@ func (m *Manager) updateEncryptionKeysRequests(communityID types.HexBytes, chann func (m *Manager) UpdateEncryptionKeysRequests(communityID types.HexBytes, channelIDs []string) error { return m.updateEncryptionKeysRequests(communityID, channelIDs, time.Now().UnixMilli()) } + +func unmarshalCommunityDescriptionMessage(signedDescription []byte, signerPubkey *ecdsa.PublicKey) (*protobuf.CommunityDescription, error) { + metadata := &protobuf.ApplicationMetadataMessage{} + + err := proto.Unmarshal(signedDescription, metadata) + if err != nil { + return nil, err + } + + if metadata.Type != protobuf.ApplicationMetadataMessage_COMMUNITY_DESCRIPTION { + return nil, ErrInvalidMessage + } + + signer, err := utils.RecoverKey(metadata) + if err != nil { + return nil, err + } + + if signer == nil { + return nil, errors.New("CommunityDescription does not contain the control node signature") + } + + if !signer.Equal(signerPubkey) { + return nil, errors.New("CommunityDescription was not signed by an owner") + } + + description := &protobuf.CommunityDescription{} + + err = proto.Unmarshal(metadata.Payload, description) + if err != nil { + return nil, err + } + + return description, nil +}