From 2289b1295d52468006b67c6034383fdc5fc8b416 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 d6dbbdf2a..a535ccaa2 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -5252,3 +5252,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 +}