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

Mutable Metadata via new UpdateMetadata intent kind #603

Closed
wants to merge 11 commits into from
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 = "8c58f21" }
openmls_basic_credential = { git = "https://github.com/xmtp/openmls", rev = "8c58f21" }
openmls_rust_crypto = { git = "https://github.com/xmtp/openmls", rev = "8c58f21" }
openmls_traits = { git = "https://github.com/xmtp/openmls", rev = "8c58f21" }
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.

2 changes: 1 addition & 1 deletion dev/gen_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if ! cargo install --list | grep "protoc-gen-prost-crate" > /dev/null; then
fi
fi

if ! buf generate https://github.com/xmtp/proto.git#branch=main,subdir=proto; then
if ! buf generate https://github.com/xmtp/proto.git#branch=cv/mutable-metadata,subdir=proto; then
echo "Failed to generate protobuf definitions"
exit 1
fi
Expand Down
21 changes: 18 additions & 3 deletions mls_validation_service/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ fn validate_key_package(key_package_bytes: Vec<u8>) -> Result<ValidateKeyPackage
mod tests {
use ethers::signers::LocalWallet;
use openmls::{
extensions::{ApplicationIdExtension, Extension, Extensions},
extensions::{ApplicationIdExtension, Extension, ExtensionType, Extensions},
messages::proposals::ProposalType,
prelude::{
tls_codec::Serialize, Ciphersuite, Credential as OpenMlsCredential, CredentialWithKey,
CryptoConfig,
tls_codec::Serialize, Capabilities, Ciphersuite, Credential as OpenMlsCredential,
CredentialWithKey, CryptoConfig,
},
prelude_test::KeyPackage,
versions::ProtocolVersion,
Expand Down Expand Up @@ -177,7 +178,21 @@ mod tests {
let application_id =
Extension::ApplicationId(ApplicationIdExtension::new(account_address.as_bytes()));

let capabilities = Capabilities::new(
None,
Some(&[CIPHERSUITE]),
Some(&[
ExtensionType::LastResort,
ExtensionType::ApplicationId,
ExtensionType::Unknown(0xff11),
ExtensionType::ImmutableMetadata,
]),
Some(&[ProposalType::GroupContextExtensions]),
None,
);

let kp = KeyPackage::builder()
.leaf_node_capabilities(capabilities)
.leaf_node_extensions(Extensions::single(application_id))
.build(
CryptoConfig {
Expand Down
101 changes: 101 additions & 0 deletions xmtp_mls/src/groups/group_mutable_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use openmls::{
extensions::{Extension, UnknownExtension},
group::MlsGroup as OpenMlsGroup,
};
use prost::Message;
use thiserror::Error;

use xmtp_proto::xmtp::mls::message_contents::GroupMutableMetadataV1 as GroupMutableMetadataProto;

#[derive(Debug, Error)]
pub enum GroupMutableMetadataError {
#[error("serialization: {0}")]
Serialization(#[from] prost::EncodeError),
#[error("deserialization: {0}")]
Deserialization(#[from] prost::DecodeError),
#[error("missing extension")]
MissingExtension,
}

#[derive(Debug, Clone, PartialEq)]
pub struct GroupMutableMetadata {
pub group_name: String,
pub allow_list_account_addresses: Vec<String>,
}

impl GroupMutableMetadata {
pub fn new(group_name: String, allow_list_account_addresses: Vec<String>) -> Self {
Self {
group_name,
allow_list_account_addresses,
}
}

pub(crate) fn from_proto(
proto: GroupMutableMetadataProto,
) -> Result<Self, GroupMutableMetadataError> {
Ok(Self::new(
proto.group_name.clone(),
proto.allow_list_account_addresses.clone(),
))
}

pub(crate) fn to_proto(&self) -> Result<GroupMutableMetadataProto, GroupMutableMetadataError> {
Ok(GroupMutableMetadataProto {
group_name: self.group_name.clone(),
allow_list_account_addresses: self.allow_list_account_addresses.clone(),
})
}
}

impl TryFrom<GroupMutableMetadata> for Vec<u8> {
type Error = GroupMutableMetadataError;

fn try_from(value: GroupMutableMetadata) -> Result<Self, Self::Error> {
let mut buf = Vec::new();
let proto_val = value.to_proto()?;
proto_val.encode(&mut buf)?;

Ok(buf)
}
}

impl TryFrom<&Vec<u8>> for GroupMutableMetadata {
type Error = GroupMutableMetadataError;

fn try_from(value: &Vec<u8>) -> Result<Self, Self::Error> {
let proto_val = GroupMutableMetadataProto::decode(value.as_slice())?;
Self::from_proto(proto_val)
}
}

impl TryFrom<GroupMutableMetadataProto> for GroupMutableMetadata {
type Error = GroupMutableMetadataError;

fn try_from(value: GroupMutableMetadataProto) -> Result<Self, Self::Error> {
Self::from_proto(value)
}
}

pub fn extract_group_mutable_metadata(
group: &OpenMlsGroup,
) -> Result<GroupMutableMetadata, GroupMutableMetadataError> {
let extensions = group.export_group_context().extensions();
for extension in extensions.iter() {
// TODO: Replace with Constant
if let Extension::Unknown(0xff11, UnknownExtension(meta_data)) = extension {
return GroupMutableMetadata::try_from(meta_data);
}
}
Err(GroupMutableMetadataError::MissingExtension)
}

#[cfg(test)]
mod tests {

use super::*;

Check warning on line 96 in xmtp_mls/src/groups/group_mutable_metadata.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `super::*`
#[test]
fn test_preconfigured_mutable_metadata() {
// TODO add test here
}
}
Loading
Loading