@@ -172,8 +172,8 @@ pub struct XmtpMlsLocalContext {
172
172
173
173
impl XmtpMlsLocalContext {
174
174
/// The installation public key is the primary identifier for an installation
175
- pub fn installation_public_key ( & self ) -> Vec < u8 > {
176
- self . identity . installation_keys . public_slice ( ) . to_vec ( )
175
+ pub fn installation_public_key ( & self ) -> & [ u8 ; 32 ] {
176
+ self . identity . installation_keys . public_bytes ( )
177
177
}
178
178
179
179
/// Get the account address of the blockchain account associated with this client
@@ -259,7 +259,7 @@ where
259
259
V : SmartContractSignatureVerifier ,
260
260
{
261
261
/// Retrieves the client's installation public key, sometimes also called `installation_id`
262
- pub fn installation_public_key ( & self ) -> Vec < u8 > {
262
+ pub fn installation_public_key ( & self ) -> & [ u8 ; 32 ] {
263
263
self . context . installation_public_key ( )
264
264
}
265
265
/// Retrieves the client's inbox ID
@@ -560,20 +560,25 @@ where
560
560
Ok ( group)
561
561
}
562
562
563
- pub ( crate ) fn create_sync_group ( & self ) -> Result < MlsGroup < Self > , ClientError > {
563
+ pub ( crate ) fn create_sync_group (
564
+ & self ,
565
+ provider : & XmtpOpenMlsProvider ,
566
+ ) -> Result < MlsGroup < Self > , ClientError > {
564
567
tracing:: info!( "creating sync group" ) ;
565
- let sync_group = MlsGroup :: create_and_insert_sync_group ( Arc :: new ( self . clone ( ) ) ) ?;
568
+ let sync_group = MlsGroup :: create_and_insert_sync_group ( Arc :: new ( self . clone ( ) ) , provider ) ?;
566
569
567
570
Ok ( sync_group)
568
571
}
569
572
570
- /**
571
- * Look up a group by its ID
572
- *
573
- * Returns a [`MlsGroup`] if the group exists, or an error if it does not
574
- */
575
- pub fn group ( & self , group_id : Vec < u8 > ) -> Result < MlsGroup < Self > , ClientError > {
576
- let conn = & mut self . store ( ) . conn ( ) ?;
573
+ /// Look up a group by its ID
574
+ ///
575
+ /// Returns a [`MlsGroup`] if the group exists, or an error if it does not
576
+ ///
577
+ pub fn group_with_conn (
578
+ & self ,
579
+ conn : & DbConnection ,
580
+ group_id : Vec < u8 > ,
581
+ ) -> Result < MlsGroup < Self > , ClientError > {
577
582
let stored_group: Option < StoredGroup > = conn. fetch ( & group_id) ?;
578
583
match stored_group {
579
584
Some ( group) => Ok ( MlsGroup :: new ( self . clone ( ) , group. id , group. created_at_ns ) ) ,
@@ -584,6 +589,15 @@ where
584
589
}
585
590
}
586
591
592
+ /// Look up a group by its ID
593
+ ///
594
+ /// Returns a [`MlsGroup`] if the group exists, or an error if it does not
595
+ ///
596
+ pub fn group ( & self , group_id : Vec < u8 > ) -> Result < MlsGroup < Self > , ClientError > {
597
+ let conn = & mut self . store ( ) . conn ( ) ?;
598
+ self . group_with_conn ( conn, group_id)
599
+ }
600
+
587
601
/**
588
602
* Look up a DM group by the target's inbox_id.
589
603
*
@@ -697,7 +711,7 @@ where
697
711
conn : & DbConnection ,
698
712
) -> Result < Vec < WelcomeMessage > , ClientError > {
699
713
let installation_id = self . installation_public_key ( ) ;
700
- let id_cursor = conn. get_last_cursor_for_id ( & installation_id, EntityKind :: Welcome ) ?;
714
+ let id_cursor = conn. get_last_cursor_for_id ( installation_id, EntityKind :: Welcome ) ?;
701
715
702
716
let welcomes = self
703
717
. api_client
@@ -747,7 +761,7 @@ where
747
761
( async {
748
762
let welcome_v1 = & welcome_v1;
749
763
self . intents. process_for_id(
750
- & id,
764
+ id,
751
765
EntityKind :: Welcome ,
752
766
welcome_v1. id,
753
767
|provider| async move {
@@ -1021,7 +1035,7 @@ pub(crate) mod tests {
1021
1035
1022
1036
// Get original KeyPackage.
1023
1037
let kp1 = client
1024
- . get_key_packages_for_installation_ids ( vec ! [ client. installation_public_key( ) ] )
1038
+ . get_key_packages_for_installation_ids ( vec ! [ client. installation_public_key( ) . to_vec ( ) ] )
1025
1039
. await
1026
1040
. unwrap ( ) ;
1027
1041
assert_eq ! ( kp1. len( ) , 1 ) ;
@@ -1031,7 +1045,7 @@ pub(crate) mod tests {
1031
1045
client. rotate_key_package ( ) . await . unwrap ( ) ;
1032
1046
1033
1047
let kp2 = client
1034
- . get_key_packages_for_installation_ids ( vec ! [ client. installation_public_key( ) ] )
1048
+ . get_key_packages_for_installation_ids ( vec ! [ client. installation_public_key( ) . to_vec ( ) ] )
1035
1049
. await
1036
1050
. unwrap ( ) ;
1037
1051
assert_eq ! ( kp2. len( ) , 1 ) ;
@@ -1299,9 +1313,9 @@ pub(crate) mod tests {
1299
1313
let bo_store = bo. store ( ) ;
1300
1314
1301
1315
let alix_original_init_key =
1302
- get_key_package_init_key ( & alix, & alix. installation_public_key ( ) ) . await ;
1316
+ get_key_package_init_key ( & alix, alix. installation_public_key ( ) ) . await ;
1303
1317
let bo_original_init_key =
1304
- get_key_package_init_key ( & bo, & bo. installation_public_key ( ) ) . await ;
1318
+ get_key_package_init_key ( & bo, bo. installation_public_key ( ) ) . await ;
1305
1319
1306
1320
// Bo's original key should be deleted
1307
1321
let bo_original_from_db = bo_store
@@ -1320,19 +1334,19 @@ pub(crate) mod tests {
1320
1334
1321
1335
bo. sync_welcomes ( & bo. store ( ) . conn ( ) . unwrap ( ) ) . await . unwrap ( ) ;
1322
1336
1323
- let bo_new_key = get_key_package_init_key ( & bo, & bo. installation_public_key ( ) ) . await ;
1337
+ let bo_new_key = get_key_package_init_key ( & bo, bo. installation_public_key ( ) ) . await ;
1324
1338
// Bo's key should have changed
1325
1339
assert_ne ! ( bo_original_init_key, bo_new_key) ;
1326
1340
1327
1341
bo. sync_welcomes ( & bo. store ( ) . conn ( ) . unwrap ( ) ) . await . unwrap ( ) ;
1328
- let bo_new_key_2 = get_key_package_init_key ( & bo, & bo. installation_public_key ( ) ) . await ;
1342
+ let bo_new_key_2 = get_key_package_init_key ( & bo, bo. installation_public_key ( ) ) . await ;
1329
1343
// Bo's key should not have changed syncing the second time.
1330
1344
assert_eq ! ( bo_new_key, bo_new_key_2) ;
1331
1345
1332
1346
alix. sync_welcomes ( & alix. store ( ) . conn ( ) . unwrap ( ) )
1333
1347
. await
1334
1348
. unwrap ( ) ;
1335
- let alix_key_2 = get_key_package_init_key ( & alix, & alix. installation_public_key ( ) ) . await ;
1349
+ let alix_key_2 = get_key_package_init_key ( & alix, alix. installation_public_key ( ) ) . await ;
1336
1350
// Alix's key should not have changed at all
1337
1351
assert_eq ! ( alix_original_init_key, alix_key_2) ;
1338
1352
0 commit comments