Skip to content

Commit

Permalink
move content types to new crate
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 11, 2024
1 parent c306959 commit c87f599
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 38 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions examples/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ valuable = { version = "0.1", features = ["derive"] }
valuable-serde = "0.1"
xmtp_api_grpc = { path = "../../xmtp_api_grpc" }
xmtp_cryptography = { path = "../../xmtp_cryptography" }
xmtp_content_types = { path = "../../xmtp_content_types" }
xmtp_id = { path = "../../xmtp_id" }
xmtp_mls = { path = "../../xmtp_mls" }
xmtp_proto = { path = "../../xmtp_proto", features = ["proto_full"] }
2 changes: 1 addition & 1 deletion examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use tracing_subscriber::{
use valuable::Valuable;
use xmtp_api_grpc::grpc_api_helper::Client as ClientV3;
use xmtp_api_grpc::replication_client::ClientV4;
use xmtp_content_types::{text::TextCodec, ContentCodec};
use xmtp_cryptography::{
signature::{RecoverableSignature, SignatureError},
utils::rng,
Expand All @@ -47,7 +48,6 @@ use xmtp_mls::XmtpApi;
use xmtp_mls::{
builder::ClientBuilderError,
client::ClientError,
codecs::{text::TextCodec, ContentCodec},
groups::{device_sync::MessageHistoryUrls, GroupMetadataOptions},
identity::IdentityStrategy,
storage::{
Expand Down
8 changes: 2 additions & 6 deletions examples/cli/serializable.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use prost::Message;
use serde::Serialize;
use valuable::Valuable;
use xmtp_mls::{
codecs::{text::TextCodec, ContentCodec},
groups::MlsGroup,
storage::group_message::StoredGroupMessage,
XmtpApi,
};
use xmtp_content_types::{text::TextCodec, ContentCodec};
use xmtp_mls::{groups::MlsGroup, storage::group_message::StoredGroupMessage, XmtpApi};
use xmtp_proto::xmtp::mls::message_contents::EncodedContent;

#[derive(Serialize, Debug, Valuable)]
Expand Down
11 changes: 9 additions & 2 deletions xmtp_content_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[package]
name = "xmtp_content_types"
edition = "2021"
license.workspace = true
name = "xmtp_content_types"
version.workspace = true
license.workspace = true

[dependencies]
thiserror = { workspace = true }
prost = { workspace = true, features = ["prost-derive"] }
rand = { workspace = true }
tonic = { version = "0.12", features = ["transport"] }

# XMTP/Local
xmtp_proto = { workspace = true, features = ["convert"] }
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) mod tests {

use xmtp_proto::xmtp::mls::message_contents::{group_updated::Inbox, GroupUpdated};

use crate::utils::test::rand_string;
use crate::test_utils::rand_string;

use super::*;

Expand Down
29 changes: 28 additions & 1 deletion xmtp_content_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
// TODO: move content types here
pub mod group_updated;
pub mod membership_change;
#[cfg(test)]
mod test_utils;
pub mod text;

use thiserror::Error;
use xmtp_proto::xmtp::mls::message_contents::{ContentTypeId, EncodedContent};

pub enum ContentType {
GroupMembershipChange,
GroupUpdated,
Text,
}

#[derive(Debug, Error)]
pub enum CodecError {
#[error("encode error {0}")]
Encode(String),
#[error("decode error {0}")]
Decode(String),
}

pub trait ContentCodec<T> {
fn content_type() -> ContentTypeId;
fn encode(content: T) -> Result<EncodedContent, CodecError>;
fn decode(content: EncodedContent) -> Result<T, CodecError>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) mod tests {

use xmtp_proto::xmtp::mls::message_contents::MembershipChange;

use crate::utils::test::{rand_string, rand_vec};
use crate::test_utils::{rand_string, rand_vec};

use super::*;

Expand Down
15 changes: 15 additions & 0 deletions xmtp_content_types/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[cfg(test)]
use rand::{
distributions::{Alphanumeric, DistString},
Rng,
};

#[cfg(test)]
pub(crate) fn rand_string() -> String {
Alphanumeric.sample_string(&mut rand::thread_rng(), 24)
}

#[cfg(test)]
pub(crate) fn rand_vec() -> Vec<u8> {
rand::thread_rng().gen::<[u8; 24]>().to_vec()
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) mod tests {
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker);

use crate::codecs::{text::TextCodec, ContentCodec};
use crate::{text::TextCodec, ContentCodec};

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
Expand Down
1 change: 1 addition & 0 deletions xmtp_mls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ web-time.workspace = true
zeroize.workspace = true

# XMTP/Local
xmtp_content_types = { path = "../xmtp_content_types" }
xmtp_cryptography = { workspace = true }
xmtp_id = { path = "../xmtp_id" }
xmtp_proto = { workspace = true, features = ["convert"] }
Expand Down
21 changes: 0 additions & 21 deletions xmtp_mls/src/codecs/mod.rs

This file was deleted.

4 changes: 2 additions & 2 deletions xmtp_mls/src/groups/mls_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use super::{
GroupError, HmacKey, IntentError, MlsGroup, ScopedGroupClient,
};
use crate::{
codecs::{group_updated::GroupUpdatedCodec, ContentCodec},
configuration::{
GRPC_DATA_LIMIT, HMAC_SALT, MAX_GROUP_SIZE, MAX_INTENT_PUBLISH_ATTEMPTS, MAX_PAST_EPOCHS,
SYNC_UPDATE_INSTALLATIONS_INTERVAL_NS,
Expand Down Expand Up @@ -64,6 +63,7 @@ use std::{
ops::RangeInclusive,
};
use thiserror::Error;
use xmtp_content_types::{group_updated::GroupUpdatedCodec, CodecError, ContentCodec};
use xmtp_id::{InboxId, InboxIdRef};
use xmtp_proto::xmtp::mls::{
api::v1::{
Expand Down Expand Up @@ -122,7 +122,7 @@ pub enum GroupMessageProcessingError {
#[error(transparent)]
Intent(#[from] IntentError),
#[error(transparent)]
Codec(#[from] crate::codecs::CodecError),
Codec(#[from] CodecError),
#[error("wrong credential type")]
WrongCredentialType(#[from] BasicCredentialError),
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,14 +1609,14 @@ pub(crate) mod tests {
use openmls::prelude::Member;
use prost::Message;
use std::sync::Arc;
use xmtp_content_types::{group_updated::GroupUpdatedCodec, ContentCodec};
use xmtp_cryptography::utils::generate_local_wallet;
use xmtp_proto::xmtp::mls::api::v1::group_message::Version;
use xmtp_proto::xmtp::mls::message_contents::EncodedContent;

use crate::{
assert_err,
builder::ClientBuilder,
codecs::{group_updated::GroupUpdatedCodec, ContentCodec},
groups::{
build_dm_protected_metadata_extension, build_mutable_metadata_extension_default,
build_protected_metadata_extension,
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
pub mod api;
pub mod builder;
pub mod client;
pub mod codecs;
pub mod configuration;
pub mod groups;
mod hpke;
Expand Down

0 comments on commit c87f599

Please sign in to comment.