Skip to content

Commit

Permalink
added propose_group_context_extensions from openmls fork
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Apr 3, 2024
1 parent 2a28f6f commit f1c7d2f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions bindings_ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String>,
) -> Result<Extension, GroupError> {
Expand Down Expand Up @@ -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]
Expand Down
26 changes: 18 additions & 8 deletions xmtp_mls/src/groups/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{

Check warning on line 5 in xmtp_mls/src/groups/sync.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `messages::proposals::GroupContextExtensionProposal`

Check warning on line 5 in xmtp_mls/src/groups/sync.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `messages::proposals::GroupContextExtensionProposal`

Check warning on line 5 in xmtp_mls/src/groups/sync.rs

View workflow job for this annotation

GitHub Actions / workspace

unused import: `messages::proposals::GroupContextExtensionProposal`

warning: unused import: `messages::proposals::GroupContextExtensionProposal` --> xmtp_mls/src/groups/sync.rs:5:117 | 5 | ...lMessage, group::MergePendingCommitError, messages::proposals::GroupContextExtensionProposal, prelude::{ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
tls_codec::{Deserialize, Serialize},
LeafNodeIndex, MlsGroup as OpenMlsGroup, MlsMessageBodyIn, MlsMessageIn, PrivateMessageIn,
ProcessedMessage, ProcessedMessageContent, Sender,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit f1c7d2f

Please sign in to comment.