Skip to content

Commit

Permalink
test_group_mutable_data successfully updating metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Apr 6, 2024
1 parent 27bccea commit ec554c3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
35 changes: 25 additions & 10 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ use openmls::{
UnknownExtension,
},
group::{
CommitToPendingProposalsError, MlsGroupCreateConfig, MlsGroupJoinConfig, ProposalError,
CommitToPendingProposalsError, MergePendingCommitError, MlsGroupCreateConfig,
MlsGroupJoinConfig, ProposalError,
},
prelude::{
CredentialWithKey, CryptoConfig, Error as TlsCodecError, GroupId, MlsGroup as OpenMlsGroup,
StagedWelcome, Welcome as MlsWelcome, WireFormatPolicy,
Capabilities, CredentialWithKey, CryptoConfig, Error as TlsCodecError, GroupId,
MlsGroup as OpenMlsGroup, StagedWelcome, Welcome as MlsWelcome, WireFormatPolicy,
},
};
use openmls_traits::OpenMlsProvider;
Expand Down Expand Up @@ -140,6 +141,8 @@ pub enum GroupError {
ProposalError(#[from] ProposalError<()>),
#[error("commit to pending proposal error: {0}")]
CommitToPendingProposalsError(#[from] CommitToPendingProposalsError<StorageError>),
#[error("merge pending commit error: {0}")]
MergePendingCommitError(#[from] MergePendingCommitError<StorageError>),
}

impl RetryableError for GroupError {
Expand Down Expand Up @@ -533,18 +536,30 @@ fn build_group_config(
protected_metadata_extension: Extension,
mutable_metadata_extension: Extension,
) -> Result<MlsGroupCreateConfig, GroupError> {
let mut extensions = Extensions::single(protected_metadata_extension);
extensions.add(mutable_metadata_extension)?;

let rc_extensions = &[ExtensionType::Unknown(0xff11)];
let required_extension_types = &[
ExtensionType::Unknown(0xff11),
ExtensionType::ImmutableMetadata,
ExtensionType::LastResort,
ExtensionType::ApplicationId,
];

let capabilities = Capabilities::new(None, None, Some(required_extension_types), None, None);
let proposals = &[];
let credentials = &[CredentialType::Basic];
let required_capabilities =
RequiredCapabilitiesExtension::new(rc_extensions, proposals, credentials);

let _ = extensions.add(Extension::RequiredCapabilities(required_capabilities))?;
let required_capabilities = Extension::RequiredCapabilities(
RequiredCapabilitiesExtension::new(required_extension_types, proposals, credentials),
);

let extensions = Extensions::from_vec(vec![
protected_metadata_extension,
mutable_metadata_extension,
required_capabilities,
])?;

Ok(MlsGroupCreateConfig::builder()
.with_group_context_extensions(extensions)?
.capabilities(capabilities)
.crypto_config(CryptoConfig::with_default_version(CIPHERSUITE))
.wire_format_policy(WireFormatPolicy::default())
.max_past_epochs(3) // Trying with 3 max past epochs for now
Expand Down
4 changes: 3 additions & 1 deletion xmtp_mls/src/groups/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use super::{
intents::{
AddMembersIntentData, AddressesOrInstallationIds, Installation, PostCommitAction,
RemoveMembersIntentData, SendMessageIntentData, SendWelcomesAction,
UpdateMetadataIntentData,
},
members::GroupMember,
GroupError, MlsGroup,
Expand Down Expand Up @@ -659,8 +660,9 @@ where
Ok((commit.tls_serialize_detached()?, None))
}
IntentKind::MetadataUpdate => {
let metadata_intent = UpdateMetadataIntentData::from_bytes(intent.data.as_slice())?;
let mutable_metadata = build_mutable_metadata_extension(
"New Group".to_string(),
metadata_intent.group_name,
vec![self.client.account_address().clone()],
)?;
let mut extensions = openmls_group.extensions().clone();
Expand Down
14 changes: 11 additions & 3 deletions xmtp_mls/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ use openmls::{
credentials::{
errors::{BasicCredentialError, CredentialError},
BasicCredential,
}, extensions::{errors::InvalidExtensionError, ApplicationIdExtension, LastResortExtension}, messages::proposals::ProposalType, prelude::{
},
extensions::{errors::InvalidExtensionError, ApplicationIdExtension, LastResortExtension},
prelude::{
tls_codec::{Error as TlsCodecError, Serialize},
Capabilities, Credential as OpenMlsCredential, CredentialWithKey, CryptoConfig, Extension,
ExtensionType, Extensions, KeyPackage, KeyPackageNewError, Lifetime,
}, versions::ProtocolVersion
},
versions::ProtocolVersion,
};
use openmls_basic_credential::SignatureKeyPair;
use openmls_traits::{types::CryptoError, OpenMlsProvider};
Expand Down Expand Up @@ -195,7 +198,12 @@ impl Identity {
let capabilities = Capabilities::new(
None,
Some(&[CIPHERSUITE]),
Some(&[ExtensionType::LastResort, ExtensionType::ApplicationId, ExtensionType::Unknown(0xff11), ExtensionType::ImmutableMetadata]),
Some(&[
ExtensionType::LastResort,
ExtensionType::ApplicationId,
ExtensionType::Unknown(0xff11),
ExtensionType::ImmutableMetadata,
]),
None,
None,
);
Expand Down

0 comments on commit ec554c3

Please sign in to comment.