From f1c7d2f399241be126dc6436cb3808832f9e9d0c Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 3 Apr 2024 11:48:30 -0700 Subject: [PATCH] added propose_group_context_extensions from openmls fork --- Cargo.lock | 10 +++++----- Cargo.toml | 8 ++++---- bindings_ffi/Cargo.lock | 10 +++++----- xmtp_mls/src/groups/mod.rs | 20 +++++++++++--------- xmtp_mls/src/groups/sync.rs | 26 ++++++++++++++++++-------- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e61ecdd96..c0f08f986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2823,7 +2823,7 @@ dependencies = [ [[package]] name = "openmls" version = "0.5.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "backtrace", "itertools 0.10.5", @@ -2845,7 +2845,7 @@ dependencies = [ [[package]] name = "openmls_basic_credential" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "ed25519-dalek", "openmls_traits", @@ -2858,7 +2858,7 @@ dependencies = [ [[package]] name = "openmls_memory_keystore" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "openmls_traits", "serde_json", @@ -2868,7 +2868,7 @@ dependencies = [ [[package]] name = "openmls_rust_crypto" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "aes-gcm", "chacha20poly1305", @@ -2892,7 +2892,7 @@ dependencies = [ [[package]] name = "openmls_traits" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "serde", "tls_codec 0.4.2-pre.1", diff --git a/Cargo.toml b/Cargo.toml index 20bed97a2..9c8e95319 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,10 +31,10 @@ futures = "0.3.30" futures-core = "0.3.30" hex = "0.4.3" log = "0.4" -openmls = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" } -openmls_basic_credential = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" } -openmls_rust_crypto = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" } -openmls_traits = { git = "https://github.com/xmtp/openmls", rev = "4eee1fc" } +openmls = { git = "https://github.com/xmtp/openmls", rev = "fa33f5e" } +openmls_basic_credential = { git = "https://github.com/xmtp/openmls", rev = "fa33f5e" } +openmls_rust_crypto = { git = "https://github.com/xmtp/openmls", rev = "fa33f5e" } +openmls_traits = { git = "https://github.com/xmtp/openmls", rev = "fa33f5e" } prost = "^0.12" prost-types = "^0.12" rand = "0.8.5" diff --git a/bindings_ffi/Cargo.lock b/bindings_ffi/Cargo.lock index ce3dade1a..c2443c31f 100644 --- a/bindings_ffi/Cargo.lock +++ b/bindings_ffi/Cargo.lock @@ -2566,7 +2566,7 @@ dependencies = [ [[package]] name = "openmls" version = "0.5.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "backtrace", "itertools 0.10.5", @@ -2588,7 +2588,7 @@ dependencies = [ [[package]] name = "openmls_basic_credential" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "ed25519-dalek", "openmls_traits", @@ -2601,7 +2601,7 @@ dependencies = [ [[package]] name = "openmls_memory_keystore" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "openmls_traits", "serde_json", @@ -2611,7 +2611,7 @@ dependencies = [ [[package]] name = "openmls_rust_crypto" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "aes-gcm", "chacha20poly1305", @@ -2635,7 +2635,7 @@ dependencies = [ [[package]] name = "openmls_traits" version = "0.2.0" -source = "git+https://github.com/xmtp/openmls?rev=4eee1fc#4eee1fc51acd70d267e7d208ed69f47dd32db115" +source = "git+https://github.com/xmtp/openmls?rev=fa33f5e#fa33f5ef12a7c3eec98c8527f21d355c472a1576" dependencies = [ "serde", "tls_codec 0.4.2-pre.1", diff --git a/xmtp_mls/src/groups/mod.rs b/xmtp_mls/src/groups/mod.rs index 5db0e930a..798520118 100644 --- a/xmtp_mls/src/groups/mod.rs +++ b/xmtp_mls/src/groups/mod.rs @@ -10,7 +10,7 @@ pub mod validated_commit; use intents::SendMessageIntentData; use openmls::{ extensions::{Extension, Extensions, Metadata, UnknownExtension}, - group::{MlsGroupCreateConfig, MlsGroupJoinConfig}, + group::{MlsGroupCreateConfig, MlsGroupJoinConfig, ProposalError}, prelude::{ CredentialWithKey, CryptoConfig, Error as TlsCodecError, GroupId, MlsGroup as OpenMlsGroup, StagedWelcome, Welcome as MlsWelcome, WireFormatPolicy, @@ -120,6 +120,8 @@ pub enum GroupError { Identity(#[from] IdentityError), #[error("serialization error: {0}")] EncodeError(#[from] prost::EncodeError), + #[error("group context extension proposal error: {0}")] + ProposalError(#[from] ProposalError<()>), } impl RetryableError for GroupError { @@ -498,7 +500,7 @@ fn build_protected_metadata_extension( Ok(Extension::ImmutableMetadata(protected_metadata)) } -fn build_mutable_metadata_extension( +pub fn build_mutable_metadata_extension( group_name: String, allow_list_account_addresses: Vec, ) -> Result { @@ -1013,15 +1015,15 @@ mod tests { assert!(group_mutable_metadata.group_name.eq("New Group")); // Update group name - // amal_group - // .update_group_metadata("New Group Name 1".to_string()) - // .await - // .unwrap(); + amal_group + .update_group_metadata("New Group Name 1".to_string()) + .await + .unwrap(); - // amal_group.sync().await.unwrap(); + amal_group.sync().await.unwrap(); - // group_mutable_metadata = amal_group.mutable_metadata().unwrap(); - // assert!(group_mutable_metadata.group_name.eq("New Group Name 1")); + group_mutable_metadata = amal_group.mutable_metadata().unwrap(); + assert!(group_mutable_metadata.group_name.eq("New Group Name 1")); } #[tokio::test] diff --git a/xmtp_mls/src/groups/sync.rs b/xmtp_mls/src/groups/sync.rs index 18c2b1453..fb2ca4741 100644 --- a/xmtp_mls/src/groups/sync.rs +++ b/xmtp_mls/src/groups/sync.rs @@ -2,11 +2,7 @@ use std::{collections::HashMap, mem::discriminant}; use log::debug; use openmls::{ - credentials::BasicCredential, - framing::ProtocolMessage, - group::MergePendingCommitError, - messages::proposals::GroupContextExtensionProposal, - prelude::{ + credentials::BasicCredential, extensions::Extensions, framing::ProtocolMessage, group::MergePendingCommitError, messages::proposals::GroupContextExtensionProposal, prelude::{ tls_codec::{Deserialize, Serialize}, LeafNodeIndex, MlsGroup as OpenMlsGroup, MlsMessageBodyIn, MlsMessageIn, PrivateMessageIn, ProcessedMessage, ProcessedMessageContent, Sender, @@ -44,7 +40,7 @@ use crate::{ client::MessageProcessingError, codecs::{membership_change::GroupMembershipChangeCodec, ContentCodec}, configuration::{MAX_INTENT_PUBLISH_ATTEMPTS, UPDATE_INSTALLATIONS_INTERVAL_NS}, - groups::validated_commit::ValidatedCommit, + groups::{build_mutable_metadata_extension, validated_commit::ValidatedCommit}, hpke::{encrypt_welcome, HpkeError}, identity::Identity, retry, @@ -658,10 +654,24 @@ where // TODO: Not implemented let intent_data = UpdateMetadataIntentData::from_bytes(intent.data.as_slice())?; println!("Trying to process Update metadata intent data: {}", intent_data.group_name); + let mutable_metadata = build_mutable_metadata_extension( + "New Group".to_string(), + vec![self.client.account_address().clone()], + )?; + let (commit, _) = openmls_group.propose_group_context_extensions( + provider, + Extensions::single(mutable_metadata), + &self.client.identity.installation_keys, + )?; - + if let Some(staged_commit) = openmls_group.pending_commit() { + // Validate the commit, even if it's from yourself + ValidatedCommit::from_staged_commit(staged_commit, openmls_group)?; + } - Ok((vec![], None)) + let commit_bytes = commit.tls_serialize_detached()?; + + Ok((commit_bytes, None)) } } }