Skip to content

Commit

Permalink
Implement message decryption and storage - still need to tidy and write
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
richardhuaaa committed Nov 10, 2023
1 parent 6706885 commit b091059
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 135 deletions.
117 changes: 20 additions & 97 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 mls_validation_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ prost = { version = "0.11", features = ["prost-derive"] }
tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread", "full"] }
tonic = "^0.9"
xmtp_proto = { path = "../xmtp_proto", features = ["proto_full", "grpc", "tonic"] }
openmls = { git= "https://github.com/openmls/openmls", features = ["test-utils"] }
openmls_traits = { git= "https://github.com/openmls/openmls" }
openmls_basic_credential = { git= "https://github.com/openmls/openmls" }
openmls_rust_crypto = { git= "https://github.com/openmls/openmls" }
openmls = { git= "https://github.com/xmtp/openmls", features = ["test-utils"] }
openmls_traits = { git= "https://github.com/xmtp/openmls" }
openmls_basic_credential = { git= "https://github.com/xmtp/openmls" }
openmls_rust_crypto = { git= "https://github.com/xmtp/openmls" }
xmtp_mls = { path = "../xmtp_mls" }
serde = "1.0.189"
hex = "0.4.3"
Expand Down
7 changes: 3 additions & 4 deletions mls_validation_service/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use openmls::{
use openmls_rust_crypto::OpenMlsRustCrypto;
use openmls_traits::OpenMlsProvider;
use tonic::{Request, Response, Status};
use xmtp_mls::utils::topic::serialize_group_id;
use xmtp_proto::xmtp::mls_validation::v1::{
validate_group_messages_response::ValidationResponse as ValidateGroupMessageValidationResponse,
validate_key_packages_response::ValidationResponse as ValidateKeyPackageValidationResponse,
validation_api_server::ValidationApi, ValidateGroupMessagesRequest,
ValidateGroupMessagesResponse, ValidateKeyPackagesRequest, ValidateKeyPackagesResponse,
};

use crate::validation_helpers::{hex_encode, identity_to_wallet_address};
use crate::validation_helpers::identity_to_wallet_address;

#[derive(Debug, Default)]
pub struct ValidationService {}
Expand Down Expand Up @@ -93,9 +94,7 @@ fn validate_group_message(message: Vec<u8>) -> Result<ValidateGroupMessageResult
let private_message: ProtocolMessage = msg_result.into();

Ok(ValidateGroupMessageResult {
// TODO: I wonder if we really want to be base64 encoding this or if we can treat it as a
// slice
group_id: hex_encode(private_message.group_id().as_slice()),
group_id: serialize_group_id(private_message.group_id().as_slice()),
})
}

Expand Down
4 changes: 0 additions & 4 deletions mls_validation_service/src/validation_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use prost::Message;
use xmtp_mls::association::Eip191Association;
use xmtp_proto::xmtp::v3::message_contents::Eip191Association as Eip191AssociationProto;

pub fn hex_encode(key: &[u8]) -> String {
hex::encode(key)
}

pub fn identity_to_wallet_address(identity: &[u8], pub_key: &[u8]) -> Result<String, String> {
let proto_value = Eip191AssociationProto::decode(identity).map_err(|e| format!("{:?}", e))?;
let association = Eip191Association::from_proto_with_expected_address(
Expand Down
22 changes: 20 additions & 2 deletions xmtp_mls/src/api_client_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

use xmtp_proto::{
api_client::{
Envelope, Error as ApiError, ErrorKind, PagingInfo, QueryRequest, XmtpApiClient,
XmtpMlsClient,
BatchQueryRequest, BatchQueryResponse, Envelope, Error as ApiError, ErrorKind, PagingInfo,
QueryRequest, QueryResponse, SubscribeRequest, XmtpApiClient, XmtpMlsClient,
},
xmtp::{
message_api::{
Expand Down Expand Up @@ -36,6 +36,24 @@ where
Self { api_client }
}

pub async fn subscribe(
&self,
request: SubscribeRequest,
) -> Result<ApiClient::Subscription, ApiError> {
self.api_client.subscribe(request).await
}

pub async fn query(&self, request: QueryRequest) -> Result<QueryResponse, ApiError> {
self.api_client.query(request).await
}

pub async fn batch_query(
&self,
request: BatchQueryRequest,
) -> Result<BatchQueryResponse, ApiError> {
self.api_client.batch_query(request).await
}

pub async fn read_topic(
&self,
topic: &str,
Expand Down
4 changes: 2 additions & 2 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ impl From<&str> for ClientError {

#[derive(Debug)]
pub struct Client<ApiClient> {
pub api_client: ApiClientWrapper<ApiClient>,
pub(crate) api_client: ApiClientWrapper<ApiClient>,
pub(crate) _network: Network,
pub(crate) identity: Identity,
pub store: EncryptedMessageStore, // Temporarily exposed outside crate for CLI client
pub(crate) store: EncryptedMessageStore,
}

impl<ApiClient> Client<ApiClient>
Expand Down
Loading

0 comments on commit b091059

Please sign in to comment.