diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01bdd3ba3..f39c922bb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,11 +35,11 @@ jobs: toolchain: stable override: true - - uses: Swatinem/rust-cache@v2 - with: - workspaces: | - . - bindings_ffi + # - uses: Swatinem/rust-cache@v2 + # with: + # workspaces: | + # . + # bindings_ffi - name: Run cargo test on main workspace uses: actions-rs/cargo@v1 diff --git a/xmtp_mls/src/groups/mod.rs b/xmtp_mls/src/groups/mod.rs index a45039b90..45a1fe5b3 100644 --- a/xmtp_mls/src/groups/mod.rs +++ b/xmtp_mls/src/groups/mod.rs @@ -47,6 +47,8 @@ pub enum GroupError { RemoveMembers(#[from] openmls::prelude::RemoveMembersError), #[error("group create: {0}")] GroupCreate(#[from] openmls::prelude::NewGroupError), + #[error("self update: {0}")] + SelfUpdate(#[from] openmls::group::SelfUpdateError), #[error("client: {0}")] Client(#[from] ClientError), #[error("generic: {0}")] @@ -151,6 +153,16 @@ where Ok(()) } + pub async fn key_update(&self) -> Result<(), GroupError> { + let mut conn = self.client.store.conn()?; + let intent = NewGroupIntent::new(IntentKind::KeyUpdate, self.group_id.clone(), vec![]); + intent.store(&mut conn)?; + + self.publish_intents(&mut conn).await?; + + Ok(()) + } + pub(crate) async fn publish_intents(&self, conn: &mut DbConnection) -> Result<(), GroupError> { let provider = self.client.mls_provider(); let mut openmls_group = self.load_mls_group(&provider)?; @@ -275,7 +287,12 @@ where Ok((commit_bytes, None)) } - _ => Err(GroupError::Generic("invalid intent kind".to_string())), + IntentKind::KeyUpdate => { + let (commit, _, _) = + openmls_group.self_update(provider, &self.client.identity.installation_keys)?; + + Ok((commit.tls_serialize_detached()?, None)) + } } } @@ -410,4 +427,23 @@ mod tests { assert_eq!(messages_after_second_try.len(), 2) } + + #[tokio::test] + async fn test_key_update() { + let client = ClientBuilder::new_test_client(generate_local_wallet().into()).await; + let group = client.create_group().expect("create group"); + + group.key_update().await.unwrap(); + + let messages = client + .api_client + .read_topic(group.topic().as_str(), 0) + .await + .unwrap(); + assert_eq!(messages.len(), 1); + + let mls_group = group.load_mls_group(&client.mls_provider()).unwrap(); + let pending_commit = mls_group.pending_commit(); + assert!(pending_commit.is_some()); + } }