Skip to content

Commit

Permalink
do the fmt w/ rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Nov 2, 2023
1 parent 4df8393 commit 6a8d96f
Show file tree
Hide file tree
Showing 51 changed files with 337 additions and 284 deletions.
27 changes: 15 additions & 12 deletions examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ extern crate ethers;
extern crate log;
extern crate xmtp;

use std::{fs, path::PathBuf, time::Duration};

use clap::{Parser, Subcommand};
use log::{error, info};
use std::fs;
use std::path::PathBuf;
use std::time::Duration;
use thiserror::Error;
use xmtp::builder::{AccountStrategy, ClientBuilderError};
use xmtp::client::ClientError;
use xmtp::conversation::{Conversation, ConversationError, ListMessagesOptions};
use xmtp::conversations::Conversations;
use xmtp::storage::{
now, EncryptedMessageStore, EncryptionKey, MessageState, StorageError, StorageOption,
use xmtp::{
builder::{AccountStrategy, ClientBuilderError},
client::ClientError,
conversation::{Conversation, ConversationError, ListMessagesOptions},
conversations::Conversations,
storage::{
now, EncryptedMessageStore, EncryptionKey, MessageState, StorageError, StorageOption,
},
InboxOwner,
};
use xmtp::InboxOwner;
use xmtp_api_grpc::grpc_api_helper::Client as ApiClient;
use xmtp_cryptography::signature::{RecoverableSignature, SignatureError};
use xmtp_cryptography::utils::{rng, seeded_rng, LocalWallet};
use xmtp_cryptography::{
signature::{RecoverableSignature, SignatureError},
utils::{rng, seeded_rng, LocalWallet},
};
use xmtp_proto::api_client::XmtpApiClient;
type Client = xmtp::client::Client<ApiClient>;
type ClientBuilder = xmtp::builder::ClientBuilder<ApiClient, Wallet>;
Expand Down
13 changes: 7 additions & 6 deletions mls_validation_service/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use openmls_rust_crypto::OpenMlsRustCrypto;
use openmls_traits::OpenMlsProvider;
use tonic::{Request, Response, Status};

use openmls::{
prelude::{KeyPackageIn, MlsMessageIn, ProtocolMessage, TlsDeserializeTrait},
versions::ProtocolVersion,
};
use openmls_rust_crypto::OpenMlsRustCrypto;
use openmls_traits::OpenMlsProvider;
use tonic::{Request, Response, Status};
use xmtp_proto::xmtp::mls_validation::v1::{
validate_group_messages_response::ValidationResponse as ValidateGroupMessageValidationResponse,
validate_key_packages_response::ValidationResponse as ValidateKeyPackageValidationResponse,
Expand Down Expand Up @@ -97,7 +96,8 @@ 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
// 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()),
epoch: private_message.epoch().as_u64(),
})
Expand Down Expand Up @@ -136,7 +136,6 @@ fn validate_key_package(key_package_bytes: Vec<u8>) -> Result<ValidateKeyPackage

#[cfg(test)]
mod tests {
use super::*;
use ethers::signers::LocalWallet;
use openmls::{
prelude::{
Expand All @@ -156,6 +155,8 @@ mod tests {
v3::message_contents::Eip191Association as Eip191AssociationProto,
};

use super::*;

const CIPHERSUITE: Ciphersuite = Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519;

fn generate_identity() -> (Vec<u8>, SignatureKeyPair, String) {
Expand Down
2 changes: 1 addition & 1 deletion mls_validation_service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use clap::Parser;
use config::Args;
use env_logger::Env;
use handlers::ValidationService;
use tokio::signal::unix::{signal, SignalKind};
use tokio::{
signal::unix::{signal, SignalKind},
spawn,
sync::oneshot::{self, Sender},
};
Expand Down
3 changes: 1 addition & 2 deletions mls_validation_service/src/validation_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use xmtp_mls::association::Eip191Association;

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 {
Expand Down
48 changes: 29 additions & 19 deletions xmtp/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
use std::fmt;
use std::sync::{Mutex, MutexGuard};

use crate::{
association::{AssociationError, Eip191Association},
contact::Contact,
types::Address,
vmac_protos::ProtoWrapper,
Signable,
use std::{
fmt,
sync::{Mutex, MutexGuard},
};

use serde::{Deserialize, Serialize};
use thiserror::Error;
use vodozemac::olm::{
Account as OlmAccount, AccountPickle as OlmAccountPickle, IdentityKeys, InboundCreationResult,
PreKeyMessage, Session as OlmSession, SessionConfig, SessionCreationError,
use vodozemac::{
olm::{
Account as OlmAccount, AccountPickle as OlmAccountPickle, IdentityKeys,
InboundCreationResult, PreKeyMessage, Session as OlmSession, SessionConfig,
SessionCreationError,
},
Ed25519Signature,
};
use vodozemac::Ed25519Signature;
use xmtp_cryptography::signature::SignatureError;
use xmtp_proto::xmtp::v3::message_contents::{
installation_contact_bundle::Version, vmac_account_linked_key::Association as AssociationProto,
InstallationContactBundle, VmacAccountLinkedKey, VmacInstallationLinkedKey,
VmacInstallationPublicKeyBundleV1, VmacUnsignedPublicKey,
};

use crate::{
association::{AssociationError, Eip191Association},
contact::Contact,
types::Address,
vmac_protos::ProtoWrapper,
Signable,
};

#[derive(Debug, Error)]
pub enum AccountError {
#[error("session creation")]
Expand Down Expand Up @@ -200,14 +206,18 @@ impl Account {
#[cfg(test)]
pub(crate) mod tests {

use crate::association::AssociationError;
use ethers::{
core::rand::thread_rng,
signers::{LocalWallet, Signer},
};
use ethers_core::{
types::{Address as EthAddress, Signature},
utils::hex,
};
use serde_json::json;

use super::{Account, Eip191Association};
use ethers::core::rand::thread_rng;
use ethers::signers::{LocalWallet, Signer};
use ethers_core::types::{Address as EthAddress, Signature};
use ethers_core::utils::hex;
use serde_json::json;
use crate::association::AssociationError;

pub fn test_wallet_signer(pub_key: Vec<u8>) -> Result<Eip191Association, AssociationError> {
Eip191Association::test(pub_key)
Expand Down
23 changes: 14 additions & 9 deletions xmtp/src/association.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::types::Address;
use crate::InboxOwner;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use xmtp_cryptography::signature::{RecoverableSignature, SignatureError};
use xmtp_cryptography::utils::generate_local_wallet;
use xmtp_proto::xmtp::v3::message_contents::Eip191Association as Eip191AssociationProto;
use xmtp_proto::xmtp::v3::message_contents::RecoverableEcdsaSignature as RecoverableEcdsaSignatureProto;
use xmtp_cryptography::{
signature::{RecoverableSignature, SignatureError},
utils::generate_local_wallet,
};
use xmtp_proto::xmtp::v3::message_contents::{
Eip191Association as Eip191AssociationProto,
RecoverableEcdsaSignature as RecoverableEcdsaSignatureProto,
};

use crate::{types::Address, InboxOwner};

#[derive(Debug, Error)]
pub enum AssociationError {
Expand Down Expand Up @@ -103,9 +107,10 @@ impl From<Eip191Association> for Eip191AssociationProto {
}
}

/// AssociationText represents the string which was signed by the authorizing blockchain account. A valid AssociationText must
/// contain the address of the blockchain account and a representation of the XMTP installation public key. Different standards may
/// choose how this information is encoded, as well as adding extra requirements for increased security.
/// AssociationText represents the string which was signed by the authorizing blockchain account. A
/// valid AssociationText must contain the address of the blockchain account and a representation of
/// the XMTP installation public key. Different standards may choose how this information is
/// encoded, as well as adding extra requirements for increased security.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub enum AssociationText {
Static {
Expand Down
3 changes: 2 additions & 1 deletion xmtp/src/bin/update-schema.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
extern crate toml;
extern crate xmtp;
use rand::distributions::{Alphanumeric, DistString};
use std::{
env,
fs::{self, File},
io::{Read, Write},
process::Command,
};

use rand::distributions::{Alphanumeric, DistString};
use toml::Table;
use xmtp::storage::{EncryptedMessageStore, StorageOption};

Expand Down
13 changes: 6 additions & 7 deletions xmtp/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use log::info;
use thiserror::Error;
use xmtp_proto::api_client::XmtpApiClient;

use crate::{
account::{Account, AccountError},
association::{AssociationError, AssociationText, Eip191Association},
client::{Client, Network},
storage::{now, EncryptedMessageStore, StoredUser},
types::Address,
InboxOwner, Store,
Fetch, InboxOwner, StorageError, Store,
};
use crate::{Fetch, StorageError};
use log::info;
use thiserror::Error;
use xmtp_proto::api_client::XmtpApiClient;

#[derive(Error, Debug)]
pub enum ClientBuilderError {
Expand Down Expand Up @@ -191,13 +191,12 @@ mod tests {
use tempfile::TempPath;
use xmtp_cryptography::utils::generate_local_wallet;

use super::ClientBuilder;
use crate::{
mock_xmtp_api_client::MockXmtpApiClient,
storage::{EncryptedMessageStore, StorageOption},
};

use super::ClientBuilder;

impl ClientBuilder<MockXmtpApiClient, LocalWallet> {
pub fn new_test() -> Self {
let wallet = generate_local_wallet();
Expand Down
24 changes: 13 additions & 11 deletions xmtp/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use core::fmt;
use std::fmt::Formatter;
use std::{collections::HashMap, fmt::Formatter};

use diesel::Connection;
use log::{debug, info};
use thiserror::Error;
use vodozemac::olm::PreKeyMessage;
use xmtp_proto::{
api_client::XmtpApiClient,
xmtp::message_api::v1::{Envelope, PublishRequest, QueryRequest},
};

use crate::{
account::Account,
Expand All @@ -19,9 +23,6 @@ use crate::{
utils::{build_envelope, build_user_contact_topic, key_fingerprint},
Store,
};
use std::collections::HashMap;
use xmtp_proto::api_client::XmtpApiClient;
use xmtp_proto::xmtp::message_api::v1::{Envelope, PublishRequest, QueryRequest};

const INSTALLATION_REFRESH_INTERVAL_NS: i64 = 0;

Expand Down Expand Up @@ -170,7 +171,7 @@ impl<ApiClient> Client<ApiClient> {

if let Err(e) = session.store(conn) {
match e {
StorageError::DieselResult(_) => log::warn!("Session Already exists"), // TODO: Some thought is needed here, is this a critical error which should unroll?
StorageError::DieselResult(_) => log::warn!("Session Already exists"), /* TODO: Some thought is needed here, is this a critical error which should unroll? */
other_error => return Err(other_error.into()),
}
}
Expand Down Expand Up @@ -307,7 +308,8 @@ where
Ok(())
}

/// Fetch Installations from the Network and create uninitialized sessions for newly discovered contacts
/// Fetch Installations from the Network and create uninitialized sessions for newly discovered
/// contacts
// TODO: Reduce Visibility
pub async fn refresh_user_installations(&self, user_address: &str) -> Result<(), ClientError> {
// Store the timestamp of when the refresh process begins
Expand Down Expand Up @@ -372,12 +374,12 @@ where

#[cfg(test)]
mod tests {
use xmtp_proto::xmtp::v3::message_contents::installation_contact_bundle::Version;
use xmtp_proto::xmtp::v3::message_contents::vmac_unsigned_public_key::Union::Curve25519;
use xmtp_proto::xmtp::v3::message_contents::vmac_unsigned_public_key::VodozemacCurve25519;
use xmtp_proto::xmtp::v3::message_contents::{
installation_contact_bundle::Version,
vmac_unsigned_public_key::{Union::Curve25519, VodozemacCurve25519},
};

use crate::test_utils::test_utils::gen_test_client;
use crate::ClientBuilder;
use crate::{test_utils::test_utils::gen_test_client, ClientBuilder};

#[tokio::test]
async fn registration() {
Expand Down
4 changes: 3 additions & 1 deletion xmtp/src/codecs/text.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::{CodecError, ContentCodec};
use std::collections::HashMap;

use xmtp_proto::xmtp::message_contents::{ContentTypeId, EncodedContent};

use super::{CodecError, ContentCodec};

pub struct TextCodec {}
impl TextCodec {
const AUTHORITY_ID: &str = "xmtp.org";
Expand Down
7 changes: 3 additions & 4 deletions xmtp/src/contact.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use prost::{DecodeError, EncodeError, Message};
use thiserror::Error;

use vodozemac::Curve25519PublicKey;
use xmtp_proto::xmtp::v3::message_contents::{
installation_contact_bundle::Version as ContactBundleVersionProto,
Expand Down Expand Up @@ -42,7 +41,8 @@ impl Contact {
wallet_address,
};
// .association() will return an error if it fails to validate
// If you try and create with a wallet address that doesn't match the signature, this will fail
// If you try and create with a wallet address that doesn't match the signature, this will
// fail
contact.association()?;

Ok(contact)
Expand Down Expand Up @@ -170,9 +170,8 @@ fn extract_proto_association(

#[cfg(test)]
mod tests {
use crate::account::{tests::test_wallet_signer, Account};

use super::Contact;
use crate::account::{tests::test_wallet_signer, Account};

#[test]
fn serialize_round_trip() {
Expand Down
10 changes: 5 additions & 5 deletions xmtp/src/conversation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use prost::{DecodeError, Message};
// use async_trait::async_trait;
use thiserror::Error;
use xmtp_proto::api_client::XmtpApiClient;

use crate::{
client::ClientError,
codecs::{text::TextCodec, CodecError, ContentCodec},
Expand All @@ -11,11 +16,6 @@ use crate::{
types::Address,
Client, Store,
};
use xmtp_proto::api_client::XmtpApiClient;

use prost::{DecodeError, Message};
// use async_trait::async_trait;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ConversationError {
Expand Down
Loading

0 comments on commit 6a8d96f

Please sign in to comment.