-
Notifications
You must be signed in to change notification settings - Fork 28
/
group.go
43 lines (33 loc) · 1.28 KB
/
group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package weshnet
import (
"github.com/libp2p/go-libp2p/core/crypto"
"berty.tech/weshnet/pkg/errcode"
"berty.tech/weshnet/pkg/protocoltypes"
)
const CurrentGroupVersion = 1
// NewGroupMultiMember creates a new Group object and an invitation to be used by
// the first member of the group
func NewGroupMultiMember() (*protocoltypes.Group, crypto.PrivKey, error) {
return protocoltypes.NewGroupMultiMember()
}
func getAndFilterGroupAddDeviceChainKeyPayload(m *protocoltypes.GroupMetadata, localMemberPublicKey crypto.PubKey) (crypto.PubKey, []byte, error) {
if m == nil || m.EventType != protocoltypes.EventTypeGroupDeviceChainKeyAdded {
return nil, nil, errcode.ErrInvalidInput
}
s := &protocoltypes.GroupAddDeviceChainKey{}
if err := s.Unmarshal(m.Payload); err != nil {
return nil, nil, errcode.ErrDeserialization.Wrap(err)
}
senderDevicePubKey, err := crypto.UnmarshalEd25519PublicKey(s.DevicePK)
if err != nil {
return nil, nil, errcode.ErrDeserialization.Wrap(err)
}
destMemberPubKey, err := crypto.UnmarshalEd25519PublicKey(s.DestMemberPK)
if err != nil {
return nil, nil, errcode.ErrDeserialization.Wrap(err)
}
if !localMemberPublicKey.Equals(destMemberPubKey) {
return nil, nil, errcode.ErrGroupSecretOtherDestMember
}
return senderDevicePubKey, s.Payload, nil
}