diff --git a/native/cpp/CommonCpp/NativeModules/CommRustModule.h b/native/cpp/CommonCpp/NativeModules/CommRustModule.h --- a/native/cpp/CommonCpp/NativeModules/CommRustModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommRustModule.h @@ -62,8 +62,10 @@ jsi::String accessToken) override; virtual jsi::Value getOutboundKeysForUserDevice( jsi::Runtime &rt, - jsi::String identifierType, - jsi::String identifierValue, + jsi::String authUserID, + jsi::String authDeviceID, + jsi::String authAccessToken, + jsi::String userID, jsi::String deviceID) override; virtual jsi::Value versionSupported(jsi::Runtime &rt) override; diff --git a/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp b/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp @@ -225,8 +225,10 @@ jsi::Value CommRustModule::getOutboundKeysForUserDevice( jsi::Runtime &rt, - jsi::String identifierType, - jsi::String identifierValue, + jsi::String authUserID, + jsi::String authDeviceID, + jsi::String authAccessToken, + jsi::String userID, jsi::String deviceID) { return createPromiseAsJSIValue( rt, @@ -237,8 +239,10 @@ auto currentID = RustPromiseManager::instance.addPromise( promise, this->jsInvoker_, innerRt); identityGetOutboundKeysForUserDevice( - jsiStringToRustString(identifierType, innerRt), - jsiStringToRustString(identifierValue, innerRt), + jsiStringToRustString(authUserID, innerRt), + jsiStringToRustString(authDeviceID, innerRt), + jsiStringToRustString(authAccessToken, innerRt), + jsiStringToRustString(userID, innerRt), jsiStringToRustString(deviceID, innerRt), currentID); } catch (const std::exception &e) { diff --git a/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp b/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp @@ -31,7 +31,7 @@ return static_cast(&turboModule)->deleteUser(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt)); } static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_getOutboundKeysForUserDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getOutboundKeysForUserDevice(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt)); + return static_cast(&turboModule)->getOutboundKeysForUserDevice(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt), args[4].asString(rt)); } static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_versionSupported(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->versionSupported(rt); @@ -45,7 +45,7 @@ methodMap_["loginWalletUser"] = MethodMetadata {11, __hostFunction_CommRustModuleSchemaCxxSpecJSI_loginWalletUser}; methodMap_["updatePassword"] = MethodMetadata {4, __hostFunction_CommRustModuleSchemaCxxSpecJSI_updatePassword}; methodMap_["deleteUser"] = MethodMetadata {3, __hostFunction_CommRustModuleSchemaCxxSpecJSI_deleteUser}; - methodMap_["getOutboundKeysForUserDevice"] = MethodMetadata {3, __hostFunction_CommRustModuleSchemaCxxSpecJSI_getOutboundKeysForUserDevice}; + methodMap_["getOutboundKeysForUserDevice"] = MethodMetadata {5, __hostFunction_CommRustModuleSchemaCxxSpecJSI_getOutboundKeysForUserDevice}; methodMap_["versionSupported"] = MethodMetadata {0, __hostFunction_CommRustModuleSchemaCxxSpecJSI_versionSupported}; } diff --git a/native/cpp/CommonCpp/_generated/rustJSI.h b/native/cpp/CommonCpp/_generated/rustJSI.h --- a/native/cpp/CommonCpp/_generated/rustJSI.h +++ b/native/cpp/CommonCpp/_generated/rustJSI.h @@ -26,7 +26,7 @@ virtual jsi::Value loginWalletUser(jsi::Runtime &rt, jsi::String siweMessage, jsi::String siweSignature, jsi::String keyPayload, jsi::String keyPayloadSignature, jsi::String contentPrekey, jsi::String contentPrekeySignature, jsi::String notifPrekey, jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys, jsi::String socialProof) = 0; virtual jsi::Value updatePassword(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken, jsi::String password) = 0; virtual jsi::Value deleteUser(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken) = 0; - virtual jsi::Value getOutboundKeysForUserDevice(jsi::Runtime &rt, jsi::String identifierType, jsi::String identifierValue, jsi::String deviceID) = 0; + virtual jsi::Value getOutboundKeysForUserDevice(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::String userID, jsi::String deviceID) = 0; virtual jsi::Value versionSupported(jsi::Runtime &rt) = 0; }; @@ -97,13 +97,13 @@ return bridging::callFromJs( rt, &T::deleteUser, jsInvoker_, instance_, std::move(userID), std::move(deviceID), std::move(accessToken)); } - jsi::Value getOutboundKeysForUserDevice(jsi::Runtime &rt, jsi::String identifierType, jsi::String identifierValue, jsi::String deviceID) override { + jsi::Value getOutboundKeysForUserDevice(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::String userID, jsi::String deviceID) override { static_assert( - bridging::getParameterCount(&T::getOutboundKeysForUserDevice) == 4, - "Expected getOutboundKeysForUserDevice(...) to have 4 parameters"); + bridging::getParameterCount(&T::getOutboundKeysForUserDevice) == 6, + "Expected getOutboundKeysForUserDevice(...) to have 6 parameters"); return bridging::callFromJs( - rt, &T::getOutboundKeysForUserDevice, jsInvoker_, instance_, std::move(identifierType), std::move(identifierValue), std::move(deviceID)); + rt, &T::getOutboundKeysForUserDevice, jsInvoker_, instance_, std::move(authUserID), std::move(authDeviceID), std::move(authAccessToken), std::move(userID), std::move(deviceID)); } jsi::Value versionSupported(jsi::Runtime &rt) override { static_assert( 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 @@ -2,13 +2,14 @@ use comm_opaque2::client::{Login, Registration}; use comm_opaque2::grpc::opaque_error_to_grpc_status as handle_error; use grpc_clients::identity::protos::authenticated::{ - UpdateUserPasswordFinishRequest, UpdateUserPasswordStartRequest, + OutboundKeysForUserRequest, UpdateUserPasswordFinishRequest, + UpdateUserPasswordStartRequest, }; use grpc_clients::identity::protos::client::{ outbound_keys_for_user_request::Identifier, DeviceKeyUpload, DeviceType, Empty, IdentityKeyInfo, OpaqueLoginFinishRequest, OpaqueLoginStartRequest, - OutboundKeyInfo, OutboundKeysForUserRequest, PreKey, - RegistrationFinishRequest, RegistrationStartRequest, WalletLoginRequest, + OutboundKeyInfo, PreKey, RegistrationFinishRequest, RegistrationStartRequest, + WalletLoginRequest, }; use grpc_clients::identity::{get_auth_client, get_unauthenticated_client}; use lazy_static::lazy_static; @@ -114,8 +115,10 @@ #[cxx_name = "identityGetOutboundKeysForUserDevice"] fn get_outbound_keys_for_user_device( - identifier_type: String, - identifier_value: String, + auth_user_id: String, + auth_device_id: String, + auth_access_token: String, + user_id: String, device_id: String, promise_id: u32, ); @@ -637,8 +640,7 @@ } struct GetOutboundKeysRequestInfo { - identifier_type: String, - identifier_value: String, + user_id: String, device_id: String, } @@ -705,50 +707,47 @@ } fn get_outbound_keys_for_user_device( - identifier_type: String, - identifier_value: String, + auth_user_id: String, + auth_device_id: String, + auth_access_token: String, + user_id: String, device_id: String, promise_id: u32, ) { RUNTIME.spawn(async move { - let get_outbound_keys_request_info = GetOutboundKeysRequestInfo { - identifier_type, - identifier_value, - device_id, + let get_outbound_keys_request_info = + GetOutboundKeysRequestInfo { user_id, device_id }; + let auth_info = AuthInfo { + access_token: auth_access_token, + user_id: auth_user_id, + device_id: auth_device_id, }; - let result = - get_outbound_keys_for_user_device_helper(get_outbound_keys_request_info) - .await; + let result = get_outbound_keys_for_user_device_helper( + get_outbound_keys_request_info, + auth_info, + ) + .await; handle_string_result_as_callback(result, promise_id); }); } async fn get_outbound_keys_for_user_device_helper( get_outbound_keys_request_info: GetOutboundKeysRequestInfo, + auth_info: AuthInfo, ) -> Result { - let identifier = match get_outbound_keys_request_info.identifier_type.as_str() - { - "walletAddress" => Some(Identifier::WalletAddress( - get_outbound_keys_request_info.identifier_value, - )), - "username" => Some(Identifier::Username( - get_outbound_keys_request_info.identifier_value, - )), - _ => { - return Err(Error::TonicGRPC(tonic::Status::invalid_argument( - "invalid identifier", - ))) - } - }; - - let mut identity_client = get_unauthenticated_client( + let mut identity_client = get_auth_client( "http://127.0.0.1:50054", + auth_info.user_id, + auth_info.device_id, + auth_info.access_token, CODE_VERSION, DEVICE_TYPE.as_str_name().to_lowercase(), ) .await?; let mut response = identity_client - .get_outbound_keys_for_user(OutboundKeysForUserRequest { identifier }) + .get_outbound_keys_for_user(OutboundKeysForUserRequest { + user_id: get_outbound_keys_request_info.user_id, + }) .await? .into_inner(); diff --git a/native/schema/CommRustModuleSchema.js b/native/schema/CommRustModuleSchema.js --- a/native/schema/CommRustModuleSchema.js +++ b/native/schema/CommRustModuleSchema.js @@ -56,8 +56,10 @@ accessToken: string, ) => Promise; +getOutboundKeysForUserDevice: ( - identifierType: string, - identifierValue: string, + authUserID: string, + authDeviceID: string, + authAccessToken: string, + userID: string, deviceID: string, ) => Promise; +versionSupported: () => Promise;