diff --git a/Cargo.lock b/Cargo.lock index 1530a43ab..13cc1e670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -319,15 +319,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" -[[package]] -name = "beef" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" -dependencies = [ - "serde", -] - [[package]] name = "bit-set" version = "0.5.3" @@ -2309,178 +2300,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpsee" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579d0ca9fb30da026bac2f0f7d9576ec93489aeb7cd4971dd5b4617d82c79b2" -dependencies = [ - "jsonrpsee-core 0.21.0", - "jsonrpsee-proc-macros 0.21.0", - "jsonrpsee-server 0.21.0", - "jsonrpsee-types 0.21.0", - "tokio", - "tracing", -] - -[[package]] -name = "jsonrpsee" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a95f7cc23d5fab0cdeeaf6bad8c8f5e7a3aa7f0d211957ea78232b327ab27b0" -dependencies = [ - "jsonrpsee-core 0.22.0", - "jsonrpsee-proc-macros 0.22.0", - "jsonrpsee-server 0.22.0", - "jsonrpsee-types 0.22.0", - "tokio", - "tracing", -] - -[[package]] -name = "jsonrpsee-core" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "776d009e2f591b78c038e0d053a796f94575d66ca4e77dd84bfc5e81419e436c" -dependencies = [ - "anyhow", - "async-trait", - "beef", - "futures-util", - "hyper 0.14.28", - "jsonrpsee-types 0.21.0", - "parking_lot", - "rand", - "rustc-hash", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "jsonrpsee-core" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82030d038658974732103e623ba2e0abec03bbbe175b39c0a2fafbada60c5868" -dependencies = [ - "anyhow", - "async-trait", - "beef", - "futures-util", - "hyper 0.14.28", - "jsonrpsee-types 0.22.0", - "parking_lot", - "rand", - "rustc-hash", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "jsonrpsee-proc-macros" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d94b7505034e2737e688e1153bf81e6f93ad296695c43958d6da2e4321f0a990" -dependencies = [ - "heck", - "proc-macro-crate 2.0.0", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "jsonrpsee-proc-macros" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fc56131589f82e57805f7338b87023db4aafef813555708b159787e34ad6bc" -dependencies = [ - "heck", - "proc-macro-crate 3.0.0", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "jsonrpsee-server" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc7c6d1a2c58f6135810284a390d9f823d0f508db74cd914d8237802de80f98" -dependencies = [ - "futures-util", - "http 0.2.11", - "hyper 0.14.28", - "jsonrpsee-core 0.21.0", - "jsonrpsee-types 0.21.0", - "pin-project", - "route-recognizer", - "serde", - "serde_json", - "soketto", - "thiserror", - "tokio", - "tokio-stream", - "tokio-util", - "tower", - "tracing", -] - -[[package]] -name = "jsonrpsee-server" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d85be77fe5b2a94589e3164fb780017f7aff7d646b49278c0d0346af16975c8e" -dependencies = [ - "futures-util", - "http 0.2.11", - "hyper 0.14.28", - "jsonrpsee-core 0.22.0", - "jsonrpsee-types 0.22.0", - "pin-project", - "route-recognizer", - "serde", - "serde_json", - "soketto", - "thiserror", - "tokio", - "tokio-stream", - "tokio-util", - "tower", - "tracing", -] - -[[package]] -name = "jsonrpsee-types" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3266dfb045c9174b24c77c2dfe0084914bb23a6b2597d70c9dc6018392e1cd1b" -dependencies = [ - "anyhow", - "beef", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "jsonrpsee-types" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a48fdc1202eafc51c63e00406575e59493284ace8b8b61aa16f3a6db5d64f1a" -dependencies = [ - "anyhow", - "beef", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "jsonwebtoken" version = "8.3.0" @@ -2575,57 +2394,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lib-didethresolver" -version = "0.1.0" -source = "git+https://github.com/xmtp/didethresolver?branch=main#05b7e66372fdac703bebc51d01afcbce0e460908" -dependencies = [ - "async-trait", - "base64 0.21.6", - "bs58", - "chrono", - "ethers", - "hex", - "jsonrpsee 0.21.0", - "log", - "peg", - "percent-encoding", - "rand", - "rustc-hex", - "serde", - "sha3", - "smart-default", - "thiserror", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "lib-xps" -version = "0.1.0" -source = "git+https://github.com/xmtp/xps-gateway?branch=main#d01fe2b34a2f85b2c2f6493e6e1538ac4bbb0669" -dependencies = [ - "anyhow", - "async-trait", - "ctor", - "ethers", - "hex", - "jsonrpsee 0.22.0", - "lib-didethresolver", - "log", - "messaging", - "rand", - "registry", - "serde", - "thiserror", - "tokio", - "tokio-stream", - "tracing", - "tracing-subscriber", - "xps-types", -] - [[package]] name = "libc" version = "0.2.152" @@ -2766,21 +2534,6 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" -[[package]] -name = "messaging" -version = "0.1.0" -source = "git+https://github.com/xmtp/xps-gateway?branch=main#d01fe2b34a2f85b2c2f6493e6e1538ac4bbb0669" -dependencies = [ - "async-trait", - "ethers", - "log", - "serde", - "thiserror", - "tokio", - "tracing", - "xps-types", -] - [[package]] name = "migrations_internals" version = "2.1.0" @@ -3353,33 +3106,6 @@ dependencies = [ "hmac 0.12.1", ] -[[package]] -name = "peg" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "400bcab7d219c38abf8bd7cc2054eb9bbbd4312d66f6a5557d572a203f646f61" -dependencies = [ - "peg-macros", - "peg-runtime", -] - -[[package]] -name = "peg-macros" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46e61cce859b76d19090f62da50a9fe92bab7c2a5f09e183763559a2ac392c90" -dependencies = [ - "peg-runtime", - "proc-macro2", - "quote", -] - -[[package]] -name = "peg-runtime" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36bae92c60fa2398ce4678b98b2c4b5a7c61099961ca1fa305aec04a9ad28922" - [[package]] name = "pem" version = "1.1.1" @@ -3993,22 +3719,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "registry" -version = "0.1.0" -source = "git+https://github.com/xmtp/xps-gateway?branch=main#d01fe2b34a2f85b2c2f6493e6e1538ac4bbb0669" -dependencies = [ - "async-trait", - "ethers", - "lib-didethresolver", - "log", - "rustc-hex", - "thiserror", - "tokio", - "tracing", - "xps-types", -] - [[package]] name = "reqwest" version = "0.11.23" @@ -4130,12 +3840,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "route-recognizer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" - [[package]] name = "rstest" version = "0.16.0" @@ -4179,12 +3883,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc-hex" version = "2.1.0" @@ -4547,19 +4245,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha-1" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "sha1" version = "0.10.6" @@ -4687,22 +4372,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "soketto" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" -dependencies = [ - "base64 0.13.1", - "bytes", - "futures", - "http 0.2.11", - "httparse", - "log", - "rand", - "sha-1", -] - [[package]] name = "solang-parser" version = "0.3.3" @@ -5182,7 +4851,6 @@ dependencies = [ "futures-core", "pin-project-lite", "tokio", - "tokio-util", ] [[package]] @@ -5208,7 +4876,6 @@ checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -5538,7 +5205,6 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", - "serde", ] [[package]] @@ -6097,11 +5763,29 @@ dependencies = [ "tokio", ] +[[package]] +name = "xmtp_id" +version = "0.1.0" +dependencies = [ + "chrono", + "log", + "openmls", + "openmls_basic_credential", + "openmls_traits", + "prost 0.12.3", + "serde", + "thiserror", + "tls_codec", + "tracing", + "xmtp_cryptography", + "xmtp_mls", + "xmtp_proto", +] + [[package]] name = "xmtp_mls" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "chrono", "ctor", @@ -6128,8 +5812,7 @@ dependencies = [ "thiserror", "tls_codec", "tokio", - "toml 0.7.8", - "tracing", + "toml 0.8.8", "tracing-subscriber", "xmtp_api_grpc", "xmtp_cryptography", @@ -6189,29 +5872,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "xps-client" -version = "0.1.0" -dependencies = [ - "futures", - "lib-xps", - "log", - "xmtp_proto", - "xps-types", -] - -[[package]] -name = "xps-types" -version = "0.1.0" -source = "git+https://github.com/xmtp/xps-gateway?branch=main#d01fe2b34a2f85b2c2f6493e6e1538ac4bbb0669" -dependencies = [ - "ethers", - "jsonrpsee 0.22.0", - "lib-didethresolver", - "serde", - "thiserror", -] - [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 04e96725b..afe1fd182 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "xmtp_user_preferences", "xmtp_v2", "xmtp_mls", + "xmtp_id" ] exclude = [ @@ -28,7 +29,8 @@ 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" } @@ -36,8 +38,15 @@ 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" } diff --git a/bindings_ffi/Cargo.toml b/bindings_ffi/Cargo.toml index d85f4f0d1..89bbbdda1 100644 --- a/bindings_ffi/Cargo.toml +++ b/bindings_ffi/Cargo.toml @@ -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" diff --git a/examples/cli/Cargo.toml b/examples/cli/Cargo.toml index 37aef147f..7125b718a 100644 --- a/examples/cli/Cargo.toml +++ b/examples/cli/Cargo.toml @@ -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" diff --git a/xmtp_api_grpc/Cargo.toml b/xmtp_api_grpc/Cargo.toml index ea2afb6bc..a07c00769 100644 --- a/xmtp_api_grpc/Cargo.toml +++ b/xmtp_api_grpc/Cargo.toml @@ -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", diff --git a/xmtp_id/Cargo.toml b/xmtp_id/Cargo.toml new file mode 100644 index 000000000..bebdac9a2 --- /dev/null +++ b/xmtp_id/Cargo.toml @@ -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 diff --git a/xmtp_id/src/error.rs b/xmtp_id/src/error.rs new file mode 100644 index 000000000..ff5ad71c6 --- /dev/null +++ b/xmtp_id/src/error.rs @@ -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, +} diff --git a/xmtp_id/src/lib.rs b/xmtp_id/src/lib.rs new file mode 100644 index 000000000..be029b8a2 --- /dev/null +++ b/xmtp_id/src/lib.rs @@ -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>, + pub(crate) unsigned_association_data: Option, +} + +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 { + 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 { + if self.credential().is_ok() { + return None; + } + self.unsigned_association_data + .clone() + .map(|data| data.text()) + } + + fn credential(&self) -> Result { + self.credential + .read() + .unwrap_or_else(|err| err.into_inner()) + .clone() + .ok_or(IdentityError::UninitializedIdentity) + } +} + +#[cfg(test)] +mod tests {} diff --git a/xmtp_mls/Cargo.toml b/xmtp_mls/Cargo.toml index 63dcf6903..73c2bc0d5 100644 --- a/xmtp_mls/Cargo.toml +++ b/xmtp_mls/Cargo.toml @@ -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] diff --git a/xmtp_mls/src/lib.rs b/xmtp_mls/src/lib.rs index 7f24b51d4..c567d5512 100644 --- a/xmtp_mls/src/lib.rs +++ b/xmtp_mls/src/lib.rs @@ -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; diff --git a/xmtp_v2/Cargo.toml b/xmtp_v2/Cargo.toml index e11ec1e32..ccbf2378a 100644 --- a/xmtp_v2/Cargo.toml +++ b/xmtp_v2/Cargo.toml @@ -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"