Skip to content

Commit

Permalink
Add xmtp_xid (#591)
Browse files Browse the repository at this point in the history
* add xmtp_id crate
  • Loading branch information
insipx authored Mar 25, 2024
1 parent 204b35a commit d0bcb73
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 389 deletions.
380 changes: 20 additions & 360 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"xmtp_user_preferences",
"xmtp_v2",
"xmtp_mls",
"xmtp_id"
]

exclude = [
Expand All @@ -28,16 +29,24 @@ ethers-core = "2.0.4"
futures = "0.3.30"
futures-core = "0.3.30"
hex = "0.4.3"
log = "0.4.20"
log = "0.4"
tracing = "0.1"
openmls = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
openmls_basic_credential = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
openmls_rust_crypto = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
openmls_traits = { git = "https://github.com/xmtp/openmls", rev = "0da7dcb" }
prost = "^0.12"
prost-types = "^0.12"
rand = "0.8.5"
serde = "1.0.195"
thiserror = "1.0.56"
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
tls_codec = "0.4.0"
tokio = { version = "1.35.1", features = ["macros"] }
tonic = "^0.11"
chrono = "0.4"

# Internal Crate Dependencies
xmtp_cryptography = { path = "xmtp_cryptography" }
xmtp_mls = { path = "xmtp_mls" }
xmtp_proto = { path = "xmtp_proto" }
2 changes: 1 addition & 1 deletion bindings_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["lib", "cdylib", "staticlib"]
[dependencies]
futures = "0.3.28"
log = { version = "0.4", features = ["std"] }
thiserror = "1.0.56"
thiserror = "1.0"
tokio = { version = "1.28.1", features = ["macros"] }
uniffi = { version = "0.25.3", features = ["tokio", "cli"] }
uniffi_macros = "0.25.3"
Expand Down
6 changes: 3 additions & 3 deletions examples/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ femme = "2.2.1"
futures = "0.3.28"
hex = "0.4.3"
kv-log-macro = "1.0.7"
log = { version = "0.4.17", features = [
log = { workspace = true, features = [
"kv_unstable",
"std",
"kv_unstable_serde",
] }
prost.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0.114"
thiserror = "1.0.40"
serde_json.workspace = true
thiserror.workspace = true
timeago = "0.4.1"
tokio = "1.28.1"
url = "2.3.1"
Expand Down
6 changes: 3 additions & 3 deletions xmtp_api_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ futures = "0.3.29"
hex.workspace = true
http-body = "0.4.5"
hyper = "0.14.26"
log = { version = "0.4", features = ["std"] }
log = { workspace = true, features = ["std"] }
pbjson = "0.5.1"
pbjson-types = "0.5.1"
prost = { workspace = true, features = ["prost-derive"] }
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0"
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
tonic = { workspace = true, features = [
"tls",
Expand Down
21 changes: 21 additions & 0 deletions xmtp_id/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "xmtp_id"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log.workspace = true
tracing.workspace = true
thiserror.workspace = true
xmtp_cryptography.workspace = true
xmtp_mls.workspace = true
xmtp_proto.workspace = true
openmls_traits.workspace = true
openmls.workspace = true
openmls_basic_credential.workspace = true
prost.workspace = true
tls_codec.workspace = true
chrono.workspace = true
serde.workspace = true
13 changes: 13 additions & 0 deletions xmtp_id/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use openmls_traits::types::CryptoError;
use thiserror::Error;
use xmtp_mls::credential::AssociationError;

#[derive(Debug, Error)]
pub enum IdentityError {
#[error("bad association: {0}")]
BadAssocation(#[from] AssociationError),
#[error("generating key-pairs: {0}")]
KeyGenerationError(#[from] CryptoError),
#[error("uninitialized identity")]
UninitializedIdentity,
}
63 changes: 63 additions & 0 deletions xmtp_id/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pub mod error;

use std::sync::RwLock;

use openmls::prelude::Credential as OpenMlsCredential;
use openmls_basic_credential::SignatureKeyPair;
use xmtp_mls::{
configuration::CIPHERSUITE, credential::UnsignedGrantMessagingAccessData, types::Address,
utils::time::now_ns,
};

use crate::error::IdentityError;

pub struct Identity {
#[allow(dead_code)]
pub(crate) account_address: Address,
#[allow(dead_code)]
pub(crate) installation_keys: SignatureKeyPair,
pub(crate) credential: RwLock<Option<OpenMlsCredential>>,
pub(crate) unsigned_association_data: Option<UnsignedGrantMessagingAccessData>,
}

impl Identity {
// Creates a credential that is not yet wallet signed. Implementors should sign the payload returned by 'text_to_sign'
// and call 'register' with the signature.
#[allow(dead_code)]
pub(crate) fn create_to_be_signed(account_address: String) -> Result<Self, IdentityError> {
let signature_keys = SignatureKeyPair::new(CIPHERSUITE.signature_algorithm())?;
let unsigned_association_data = UnsignedGrantMessagingAccessData::new(
account_address.clone(),
signature_keys.to_public_vec(),
now_ns() as u64,
)?;
let identity = Self {
account_address,
installation_keys: signature_keys,
credential: RwLock::new(None),
unsigned_association_data: Some(unsigned_association_data),
};

Ok(identity)
}

pub fn text_to_sign(&self) -> Option<String> {
if self.credential().is_ok() {
return None;
}
self.unsigned_association_data
.clone()
.map(|data| data.text())
}

fn credential(&self) -> Result<OpenMlsCredential, IdentityError> {
self.credential
.read()
.unwrap_or_else(|err| err.into_inner())
.clone()
.ok_or(IdentityError::UninitializedIdentity)
}
}

#[cfg(test)]
mod tests {}
32 changes: 15 additions & 17 deletions xmtp_mls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,35 @@ native = ["libsqlite3-sys/bundled-sqlcipher-vendored-openssl"]
types = []

[dependencies]
anyhow = "1.0.71"
async-trait = "0.1.68"
chrono = "0.4.31"
diesel = { version = "2.1.3", features = [
"sqlite",
"r2d2",
"returning_clauses_for_sqlite_3_35",
] }
diesel_migrations = { version = "2.1.0", features = ["sqlite"] }
ethers = "2.0.4"
ethers-core = "2.0.4"
futures = "0.3.28"
hex = "0.4.3"
libsqlite3-sys = { version = "0.26.0", optional = true }
log = "0.4.17"
async-trait.workspace = true
ethers.workspace = true
ethers-core.workspace = true
futures.workspace = true
hex.workspace = true
log.workspace = true
openmls = { workspace = true, features = ["test-utils"] }
openmls_basic_credential = { workspace = true }
openmls_rust_crypto = { workspace = true }
openmls_traits = { workspace = true }
prost = { version = "^0.12", features = ["prost-derive"] }
prost = { workspace = true, features = ["prost-derive"] }
rand = { workspace = true }
serde = "1.0.160"
serde_json = "1.0.96"
smart-default = "0.7.1"
serde = { workspace = true }
serde_json.workspace = true
thiserror = { workspace = true }
tls_codec = { workspace = true }
tokio = { workspace = true }
toml = "0.7.4"
tracing = "0.1.37"
xmtp_cryptography = { path = "../xmtp_cryptography" }
xmtp_proto = { path = "../xmtp_proto", features = ["proto_full"] }
chrono = { workspace = true }
libsqlite3-sys = { version = "0.26.0", optional = true }
smart-default = "0.7.1"
toml = "0.8.4"
xmtp_proto = { workspace = true, features = ["proto_full"] }
xmtp_cryptography = { workspace = true }
xmtp_v2 = { path = "../xmtp_v2" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion xmtp_mls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod api_client_wrapper;
pub mod builder;
pub mod client;
pub mod codecs;
mod configuration;
pub mod configuration;
pub mod credential;
pub mod groups;
mod hpke;
Expand Down
2 changes: 1 addition & 1 deletion xmtp_v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rust-version = "1.64"

[dependencies]
aes-gcm = "0.10.1"
chrono = "0.4.23"
chrono = { workspace = true }
ecdsa = "0.15.1"
ethers-core = { workspace = true }
generic-array = "0.14.6"
Expand Down

0 comments on commit d0bcb73

Please sign in to comment.