diff --git a/native/native_rust_library/Cargo.lock b/native/native_rust_library/Cargo.lock --- a/native/native_rust_library/Cargo.lock +++ b/native/native_rust_library/Cargo.lock @@ -40,6 +40,28 @@ "password-hash 0.5.0", ] +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + [[package]] name = "async-trait" version = "0.1.68" @@ -190,7 +212,7 @@ dependencies = [ "argon2 0.4.1", "log", - "opaque-ke 2.0.0", + "opaque-ke", "rand", "tonic", "wasm-bindgen", @@ -202,12 +224,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "convert_case" version = "0.4.0" @@ -230,7 +246,7 @@ checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" dependencies = [ "generic-array", - "rand_core 0.6.4", + "rand_core", "subtle", "zeroize", ] @@ -245,29 +261,6 @@ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "curve25519-dalek" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", - "subtle", - "zeroize", -] - [[package]] name = "curve25519-dalek" version = "4.0.0-pre.1" @@ -276,7 +269,7 @@ dependencies = [ "byteorder", "digest 0.9.0", - "rand_core 0.6.4", + "rand_core", "subtle", "zeroize", ] @@ -408,7 +401,7 @@ "ff", "generic-array", "group", - "rand_core 0.6.4", + "rand_core", "sec1", "subtle", "zeroize", @@ -429,7 +422,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" dependencies = [ - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -513,10 +506,22 @@ checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ "ff", - "rand_core 0.6.4", + "rand_core", "subtle", ] +[[package]] +name = "grpc_clients" +version = "0.1.0" +dependencies = [ + "derive_more", + "prost", + "tonic", + "tonic-build", + "tracing", + "tracing-subscriber", +] + [[package]] name = "h2" version = "0.3.17" @@ -557,33 +562,13 @@ "libc", ] -[[package]] -name = "hkdf" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01706d578d5c281058480e673ae4086a9f4710d8df1ad80a5b03e39ece5f886b" -dependencies = [ - "digest 0.9.0", - "hmac 0.11.0", -] - [[package]] name = "hkdf" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" dependencies = [ - "hmac 0.12.1", -] - -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac", - "digest 0.9.0", + "hmac", ] [[package]] @@ -699,6 +684,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -729,6 +723,15 @@ "cfg-if", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "matchit" version = "0.7.0" @@ -774,20 +777,27 @@ "cxx", "cxx-build", "derive_more", + "grpc_clients", "lazy_static", - "opaque-ke 1.2.0", - "prost", "rand", "regex", "serde", "serde_json", "tokio", - "tokio-stream", "tonic", - "tonic-build", "tracing", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -804,24 +814,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" -[[package]] -name = "opaque-ke" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25e5f1be61b7a94f388368a24739318fe4edd2b841d20d7077a422a5391e22f" -dependencies = [ - "constant_time_eq", - "curve25519-dalek 3.2.0", - "digest 0.9.0", - "displaydoc", - "generic-array", - "hkdf 0.11.0", - "hmac 0.11.0", - "rand", - "subtle", - "zeroize", -] - [[package]] name = "opaque-ke" version = "2.0.0" @@ -829,14 +821,14 @@ checksum = "76d410412d23781909d90c3900c5783e830586765f2277bccc78167da8af81a5" dependencies = [ "argon2 0.4.1", - "curve25519-dalek 4.0.0-pre.1", + "curve25519-dalek", "derive-where", "digest 0.10.5", "displaydoc", "elliptic-curve", "generic-array", - "hkdf 0.12.3", - "hmac 0.12.1", + "hkdf", + "hmac", "rand", "serde", "subtle", @@ -844,6 +836,12 @@ "zeroize", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "password-hash" version = "0.4.2" @@ -851,7 +849,7 @@ checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -862,7 +860,7 @@ checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" dependencies = [ "base64ct", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -1010,7 +1008,7 @@ dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1020,15 +1018,9 @@ checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" - [[package]] name = "rand_core" version = "0.6.4" @@ -1058,6 +1050,15 @@ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.27" @@ -1073,6 +1074,21 @@ "winapi", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "rustc_version" version = "0.4.0" @@ -1082,6 +1098,37 @@ "semver", ] +[[package]] +name = "rustls" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +dependencies = [ + "base64", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -1100,6 +1147,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "sec1" version = "0.3.0" @@ -1161,6 +1218,15 @@ "digest 0.10.5", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "slab" version = "0.4.7" @@ -1170,6 +1236,12 @@ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" + [[package]] name = "socket2" version = "0.4.7" @@ -1180,6 +1252,12 @@ "winapi", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "subtle" version = "2.4.1" @@ -1249,6 +1327,16 @@ "winapi-util", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tokio" version = "1.24.2" @@ -1288,6 +1376,16 @@ "syn 1.0.99", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.9" @@ -1319,6 +1417,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" dependencies = [ + "async-stream", "async-trait", "axum", "base64", @@ -1333,7 +1432,9 @@ "percent-encoding", "pin-project", "prost", + "rustls-pemfile", "tokio", + "tokio-rustls", "tokio-stream", "tower", "tower-layer", @@ -1411,11 +1512,41 @@ [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" dependencies = [ + "matchers", + "nu-ansi-term", "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -1448,6 +1579,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" @@ -1460,13 +1603,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "081acbe8fcf05d5e8e2aad8ef3d40e02eddeaec07c75a9770d862a0fc0874322" dependencies = [ - "curve25519-dalek 4.0.0-pre.1", + "curve25519-dalek", "derive-where", "digest 0.10.5", "displaydoc", "elliptic-curve", "generic-array", - "rand_core 0.6.4", + "rand_core", "serde", "sha2", "subtle", @@ -1491,9 +1634,9 @@ [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1501,24 +1644,24 @@ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.99", + "syn 2.0.15", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1526,22 +1669,32 @@ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.99", + "syn 2.0.15", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "which" diff --git a/native/native_rust_library/Cargo.toml b/native/native_rust_library/Cargo.toml --- a/native/native_rust_library/Cargo.toml +++ b/native/native_rust_library/Cargo.toml @@ -9,12 +9,9 @@ [dependencies] cxx = "1.0" tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } -tokio-stream = "0.1" tonic = "0.9.1" -prost = "0.11" lazy_static = "1.4" rand = "0.8" -opaque-ke = "1.2" tracing = "0.1" regex = "1.6" comm-opaque2 = {path = "../../shared/comm-opaque2"} @@ -22,10 +19,11 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" argon2 = "0.5.1" +grpc_clients = {path = "../../shared/grpc_clients"} [build-dependencies] cxx-build = "1.0" -tonic-build = "0.9.1" +regex = "1" [lib] crate-type = ["staticlib"] diff --git a/native/native_rust_library/build.rs b/native/native_rust_library/build.rs --- a/native/native_rust_library/build.rs +++ b/native/native_rust_library/build.rs @@ -1,13 +1,51 @@ +use regex::Regex; +use std::env; +use std::fs; +use std::path::Path; + fn main() { - tonic_build::configure() - .build_server(false) - .compile( - &["../../shared/protos/identity_client.proto"], - &["../../shared/protos"], - ) - .unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e)); let _cxx_build = cxx_build::bridge("src/lib.rs").flag_if_supported("-std=c++17"); + const HEADER_PATH: &str = "../cpp/CommonCpp/NativeModules/CommCoreModule.h"; + let header_path = Path::new(HEADER_PATH); + + let content = + fs::read_to_string(header_path).expect("Failed to read CommCoreModule.h"); + + let version_line = content + .lines() + .find(|line| line.contains("const int codeVersion")) + .expect("Failed to find codeVersion line"); + println!("Version line: {}", version_line); + + // The regex searches for the string "const int codeVersion", followed by any + // number of whitespace characters, an escaped opening curly brace, more + // optional whitespace, a series of one or more digits (which it captures), + // some more optional whitespace, an escaped closing curly brace, and finally + // a semicolon. + let re = Regex::new(r"const int codeVersion\s*\{\s*(\d+)\s*\};").unwrap(); + let version: u64 = re + .captures(version_line) + .and_then(|cap| cap.get(1)) + .map_or_else( + || panic!("Failed to capture version number"), + |m| { + m.as_str() + .parse::() + .expect("Failed to parse version number") + }, + ); + + let out_dir = env::var("OUT_DIR").unwrap(); + let rust_path = Path::new(&out_dir).join("version.rs"); + + fs::write( + rust_path, + format!("pub const CODE_VERSION: u64 = {};", version), + ) + .expect("Failed to write version.rs"); + println!("cargo:rerun-if-changed=src/lib.rs"); + println!("cargo:rerun-if-changed={}", HEADER_PATH); } diff --git a/native/native_rust_library/src/identity_client.rs b/native/native_rust_library/src/identity_client.rs deleted file mode 100644 --- a/native/native_rust_library/src/identity_client.rs +++ /dev/null @@ -1,36 +0,0 @@ -use tonic::Status; - -use crate::IdentityClient; - -// User could be logging in from new device, need to resend device information -pub async fn login_user_pake( - mut _client: Box, - _username: String, - _password: String, - _key_payload: String, - _key_payload_signature: String, - _identity_prekey: String, - _identity_prekey_signature: String, - _notif_prekey: String, - _notif_prekey_signature: String, - _identity_one_time_keys: Vec, - _notif_one_time_keys: Vec, -) -> Result { - unimplemented!(); -} - -pub async fn login_user_wallet( - mut _client: Box, - _siwe_message: String, - _siwe_signature: String, - _key_payload: String, - _key_payload_signature: String, - _identity_prekey: String, - _identity_prekey_signature: String, - _notif_prekey: String, - _notif_prekey_signature: String, - _identity_one_time_keys: Vec, - _notif_one_time_keys: Vec, -) -> Result { - unimplemented!(); -} diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -1,31 +1,33 @@ use crate::ffi::{string_callback, void_callback}; -use crate::identity::Empty; use comm_opaque2::client::{Login, Registration}; use comm_opaque2::grpc::opaque_error_to_grpc_status as handle_error; +use grpc_clients::identity::get_unauthenticated_client; +use grpc_clients::identity::protos::client::{ + DeviceKeyUpload, DeviceType, Empty, IdentityKeyInfo, + OpaqueLoginFinishRequest, OpaqueLoginStartRequest, PreKey, + RegistrationFinishRequest, RegistrationStartRequest, + UpdateUserPasswordFinishRequest, UpdateUserPasswordStartRequest, + WalletLoginRequest, +}; use lazy_static::lazy_static; use serde::Serialize; use std::sync::Arc; use tokio::runtime::{Builder, Runtime}; -use tonic::{transport::Channel, Status}; +use tonic::Status; use tracing::instrument; mod argon2_tools; mod crypto_tools; -mod identity_client; - -mod identity { - tonic::include_proto!("identity.client"); -} use argon2_tools::compute_backup_key; use crypto_tools::generate_device_id; -use identity::identity_client_service_client::IdentityClientServiceClient; -use identity::{ - DeviceKeyUpload, DeviceType, IdentityKeyInfo, OpaqueLoginFinishRequest, - OpaqueLoginStartRequest, PreKey, RegistrationFinishRequest, - RegistrationStartRequest, UpdateUserPasswordFinishRequest, - UpdateUserPasswordStartRequest, WalletLoginRequest, -}; + +mod generated { + // We get the CODE_VERSION from this generated file + include!(concat!(env!("OUT_DIR"), "/version.rs")); +} + +pub use generated::CODE_VERSION; #[cfg(not(feature = "android"))] pub const DEVICE_TYPE: DeviceType = DeviceType::Ios; @@ -53,12 +55,6 @@ } extern "Rust" { - // Identity Service Client - type IdentityClient; - - #[cxx_name = "identityInitializeClient"] - fn initialize_identity_client(addr: String) -> Box; - #[cxx_name = "identityRegisterUser"] fn register_user( username: String, @@ -166,8 +162,12 @@ } async fn fetch_nonce() -> Result { - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054").await?; + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + CODE_VERSION, + DEVICE_TYPE.as_str_name().to_lowercase(), + ) + .await?; let nonce = identity_client .generate_nonce(Empty {}) .await? @@ -176,19 +176,6 @@ Ok(nonce) } -#[derive(Debug)] -pub struct IdentityClient { - identity_client: IdentityClientServiceClient, -} - -fn initialize_identity_client(addr: String) -> Box { - Box::new(IdentityClient { - identity_client: RUNTIME - .block_on(IdentityClientServiceClient::connect(addr)) - .unwrap(), - }) -} - #[instrument] fn register_user( username: String, @@ -272,8 +259,12 @@ }), }; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054").await?; + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + CODE_VERSION, + DEVICE_TYPE.as_str_name().to_lowercase(), + ) + .await?; let registration_start_response = identity_client .register_password_user_start(registration_start_request) .await? @@ -363,8 +354,13 @@ }), }; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054").await?; + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + CODE_VERSION, + DEVICE_TYPE.as_str_name().to_lowercase(), + ) + .await?; + let login_start_response = identity_client .login_password_user_start(login_start_request) .await? @@ -463,8 +459,13 @@ }), }; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054").await?; + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + CODE_VERSION, + DEVICE_TYPE.as_str_name().to_lowercase(), + ) + .await?; + let login_response = identity_client .login_wallet_user(login_request) .await? @@ -516,8 +517,13 @@ user_id: update_password_info.user_id, device_id_key: update_password_info.device_id, }; - let mut identity_client = - IdentityClientServiceClient::connect("http://127.0.0.1:50054").await?; + let mut identity_client = get_unauthenticated_client( + "http://127.0.0.1:50054", + CODE_VERSION, + DEVICE_TYPE.as_str_name().to_lowercase(), + ) + .await?; + let update_password_start_respone = identity_client .update_user_password_start(update_password_start_request) .await? @@ -548,7 +554,17 @@ #[display(...)] TonicGRPC(Status), #[display(...)] - TonicTransport(tonic::transport::Error), - #[display(...)] SerdeJson(serde_json::Error), + #[display(...)] + GRPClient(grpc_clients::error::Error), +} + +#[cfg(test)] +mod tests { + use super::CODE_VERSION; + + #[test] + fn test_code_version_exists() { + assert!(CODE_VERSION > 0); + } }