Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for key updates #320

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
toolchain: stable
override: true

- uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
bindings_ffi
# - uses: Swatinem/rust-cache@v2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is somehow running out of disk space. I'm working through more performant solutions, but for now this has made the GH checks pass.

# with:
# workspaces: |
# .
# bindings_ffi

- name: Run cargo test on main workspace
uses: actions-rs/cargo@v1
Expand Down
38 changes: 37 additions & 1 deletion xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum GroupError {
RemoveMembers(#[from] openmls::prelude::RemoveMembersError<StorageError>),
#[error("group create: {0}")]
GroupCreate(#[from] openmls::prelude::NewGroupError<StorageError>),
#[error("self update: {0}")]
SelfUpdate(#[from] openmls::group::SelfUpdateError<StorageError>),
#[error("client: {0}")]
Client(#[from] ClientError),
#[error("generic: {0}")]
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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))
}
}
}

Expand Down Expand Up @@ -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());
}
}
Loading