chore(communities)_: mv `unmarshalCommunityDescriptionMessage` to
manager
This commit is contained in:
parent
084a6e3c5c
commit
9ba44651c7
|
@ -1,14 +1,12 @@
|
||||||
package communities
|
package communities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
|
||||||
"errors"
|
"errors"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"go.uber.org/zap"
|
"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/common"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
)
|
)
|
||||||
|
@ -313,38 +311,3 @@ func (o *Community) toCommunityEventsMessage() *CommunityEventsMessage {
|
||||||
Events: o.config.EventsData.Events,
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -5259,3 +5259,38 @@ func (m *Manager) updateEncryptionKeysRequests(communityID types.HexBytes, chann
|
||||||
func (m *Manager) UpdateEncryptionKeysRequests(communityID types.HexBytes, channelIDs []string) error {
|
func (m *Manager) UpdateEncryptionKeysRequests(communityID types.HexBytes, channelIDs []string) error {
|
||||||
return m.updateEncryptionKeysRequests(communityID, channelIDs, time.Now().UnixMilli())
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue