@@ -7,18 +7,10 @@ use nostr_mls_storage::groups::error::{GroupError, InvalidGroupState};
7
7
use nostr_mls_storage:: groups:: types:: * ;
8
8
use nostr_mls_storage:: groups:: GroupStorage ;
9
9
use nostr_mls_storage:: messages:: types:: Message ;
10
+ use openmls:: group:: GroupId ;
10
11
11
12
use crate :: NostrMlsMemoryStorage ;
12
13
13
- /// Creates a compound key from an MLS group ID and epoch
14
- ///
15
- /// The key is created by concatenating the MLS group ID and the epoch as bytes
16
- fn create_compound_key ( mls_group_id : & [ u8 ] , epoch : u64 ) -> Vec < u8 > {
17
- let mut key = mls_group_id. to_vec ( ) ;
18
- key. extend_from_slice ( & epoch. to_be_bytes ( ) ) ;
19
- key
20
- }
21
-
22
14
impl GroupStorage for NostrMlsMemoryStorage {
23
15
fn save_group ( & self , group : Group ) -> Result < ( ) , GroupError > {
24
16
// Store in the MLS group ID cache
@@ -30,7 +22,7 @@ impl GroupStorage for NostrMlsMemoryStorage {
30
22
// Store in the Nostr group ID cache
31
23
{
32
24
let mut cache = self . groups_by_nostr_id_cache . write ( ) ;
33
- cache. put ( group. nostr_group_id . clone ( ) , group) ;
25
+ cache. put ( group. nostr_group_id , group) ;
34
26
}
35
27
36
28
Ok ( ( ) )
@@ -43,20 +35,23 @@ impl GroupStorage for NostrMlsMemoryStorage {
43
35
Ok ( groups)
44
36
}
45
37
46
- fn find_group_by_mls_group_id ( & self , mls_group_id : & [ u8 ] ) -> Result < Option < Group > , GroupError > {
38
+ fn find_group_by_mls_group_id (
39
+ & self ,
40
+ mls_group_id : & GroupId ,
41
+ ) -> Result < Option < Group > , GroupError > {
47
42
let cache = self . groups_cache . read ( ) ;
48
43
Ok ( cache. peek ( mls_group_id) . cloned ( ) )
49
44
}
50
45
51
46
fn find_group_by_nostr_group_id (
52
47
& self ,
53
- nostr_group_id : & str ,
48
+ nostr_group_id : & [ u8 ; 32 ] ,
54
49
) -> Result < Option < Group > , GroupError > {
55
50
let cache = self . groups_by_nostr_id_cache . read ( ) ;
56
51
Ok ( cache. peek ( nostr_group_id) . cloned ( ) )
57
52
}
58
53
59
- fn messages ( & self , mls_group_id : & [ u8 ] ) -> Result < Vec < Message > , GroupError > {
54
+ fn messages ( & self , mls_group_id : & GroupId ) -> Result < Vec < Message > , GroupError > {
60
55
// Check if the group exists first
61
56
self . find_group_by_mls_group_id ( mls_group_id) ?;
62
57
@@ -68,14 +63,14 @@ impl GroupStorage for NostrMlsMemoryStorage {
68
63
}
69
64
}
70
65
71
- fn admins ( & self , mls_group_id : & [ u8 ] ) -> Result < BTreeSet < PublicKey > , GroupError > {
66
+ fn admins ( & self , mls_group_id : & GroupId ) -> Result < BTreeSet < PublicKey > , GroupError > {
72
67
match self . find_group_by_mls_group_id ( mls_group_id) ? {
73
68
Some ( group) => Ok ( group. admin_pubkeys ) ,
74
69
None => Err ( GroupError :: InvalidState ( InvalidGroupState :: NoAdmins ) ) ,
75
70
}
76
71
}
77
72
78
- fn group_relays ( & self , mls_group_id : & [ u8 ] ) -> Result < BTreeSet < GroupRelay > , GroupError > {
73
+ fn group_relays ( & self , mls_group_id : & GroupId ) -> Result < BTreeSet < GroupRelay > , GroupError > {
79
74
// Check if the group exists first
80
75
self . find_group_by_mls_group_id ( mls_group_id) ?;
81
76
@@ -114,16 +109,15 @@ impl GroupStorage for NostrMlsMemoryStorage {
114
109
115
110
fn get_group_exporter_secret (
116
111
& self ,
117
- mls_group_id : & [ u8 ] ,
112
+ mls_group_id : & GroupId ,
118
113
epoch : u64 ,
119
114
) -> Result < Option < GroupExporterSecret > , GroupError > {
120
115
// Check if the group exists first
121
116
self . find_group_by_mls_group_id ( mls_group_id) ?;
122
117
123
118
let cache = self . group_exporter_secrets_cache . read ( ) ;
124
- // Create a compound key from mls_group_id and epoch
125
- let key = create_compound_key ( mls_group_id, epoch) ;
126
- Ok ( cache. peek ( & key) . cloned ( ) )
119
+ // Use tuple (GroupId, epoch) as key
120
+ Ok ( cache. peek ( & ( mls_group_id. clone ( ) , epoch) ) . cloned ( ) )
127
121
}
128
122
129
123
fn save_group_exporter_secret (
@@ -134,9 +128,9 @@ impl GroupStorage for NostrMlsMemoryStorage {
134
128
self . find_group_by_mls_group_id ( & group_exporter_secret. mls_group_id ) ?;
135
129
136
130
let mut cache = self . group_exporter_secrets_cache . write ( ) ;
137
- // Create a compound key from mls_group_id and epoch
138
- let key = create_compound_key (
139
- & group_exporter_secret. mls_group_id ,
131
+ // Use tuple (GroupId, epoch) as key
132
+ let key = (
133
+ group_exporter_secret. mls_group_id . clone ( ) ,
140
134
group_exporter_secret. epoch ,
141
135
) ;
142
136
cache. put ( key, group_exporter_secret) ;
0 commit comments