forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 3
/
group_context.go
72 lines (57 loc) · 1.85 KB
/
group_context.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package bertyprotocol
import (
"encoding/base64"
"fmt"
"github.com/libp2p/go-libp2p-core/crypto"
"go.uber.org/zap"
"berty.tech/berty/v2/go/internal/cryptoutil"
"berty.tech/berty/v2/go/internal/logutil"
"berty.tech/berty/v2/go/pkg/protocoltypes"
)
type GroupContext struct {
group *protocoltypes.Group
metadataStore *MetadataStore
messageStore *MessageStore
messageKeystore *cryptoutil.MessageKeystore
memberDevice *cryptoutil.OwnMemberDevice
logger *zap.Logger
}
func (gc *GroupContext) MessageKeystore() *cryptoutil.MessageKeystore {
return gc.messageKeystore
}
func (gc *GroupContext) getMemberPrivKey() crypto.PrivKey {
return gc.memberDevice.PrivateMember()
}
func (gc *GroupContext) MessageStore() *MessageStore {
return gc.messageStore
}
func (gc *GroupContext) MetadataStore() *MetadataStore {
return gc.metadataStore
}
func (gc *GroupContext) Group() *protocoltypes.Group {
return gc.group
}
func (gc *GroupContext) MemberPubKey() crypto.PubKey {
return gc.memberDevice.PrivateMember().GetPublic()
}
func (gc *GroupContext) DevicePubKey() crypto.PubKey {
return gc.memberDevice.PrivateDevice().GetPublic()
}
func (gc *GroupContext) Close() error {
gc.metadataStore.Close()
gc.messageStore.Close()
return nil
}
func NewContextGroup(group *protocoltypes.Group, metadataStore *MetadataStore, messageStore *MessageStore, messageKeystore *cryptoutil.MessageKeystore, memberDevice *cryptoutil.OwnMemberDevice, logger *zap.Logger) *GroupContext {
if logger == nil {
logger = zap.NewNop()
}
return &GroupContext{
group: group,
metadataStore: metadataStore,
messageStore: messageStore,
messageKeystore: messageKeystore,
memberDevice: memberDevice,
logger: logger.With(logutil.PrivateString("group-id", fmt.Sprintf("%.6s", base64.StdEncoding.EncodeToString(group.PublicKey)))),
}
}