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 @@ -55,6 +55,11 @@ jsi::String deviceID, jsi::String accessToken, jsi::String password) override; + virtual jsi::Value deleteUser( + jsi::Runtime &rt, + jsi::String userID, + jsi::String deviceID, + jsi::String accessToken) override; virtual jsi::Value getOutboundKeysForUserDevice( jsi::Runtime &rt, jsi::String identifierType, 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 @@ -199,6 +199,30 @@ }); } +jsi::Value CommRustModule::deleteUser( + jsi::Runtime &rt, + jsi::String userID, + jsi::String deviceID, + jsi::String accessToken) { + return createPromiseAsJSIValue( + rt, + [this, &userID, &deviceID, &accessToken]( + jsi::Runtime &innerRt, std::shared_ptr promise) { + std::string error; + try { + auto currentID = RustPromiseManager::instance.addPromise( + promise, this->jsInvoker_, innerRt); + identityDeleteUser( + jsiStringToRustString(userID, innerRt), + jsiStringToRustString(deviceID, innerRt), + jsiStringToRustString(accessToken, innerRt), + currentID); + } catch (const std::exception &e) { + error = e.what(); + }; + }); +} + jsi::Value CommRustModule::getOutboundKeysForUserDevice( jsi::Runtime &rt, jsi::String identifierType, 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 @@ -27,6 +27,9 @@ static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_updatePassword(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->updatePassword(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt)); } +static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_deleteUser(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + 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)); } @@ -38,6 +41,7 @@ methodMap_["loginPasswordUser"] = MethodMetadata {10, __hostFunction_CommRustModuleSchemaCxxSpecJSI_loginPasswordUser}; 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}; } 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 @@ -25,6 +25,7 @@ virtual jsi::Value loginPasswordUser(jsi::Runtime &rt, jsi::String username, jsi::String password, jsi::String keyPayload, jsi::String keyPayloadSignature, jsi::String contentPrekey, jsi::String contentPrekeySignature, jsi::String notifPrekey, jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys) = 0; 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; }; @@ -87,6 +88,14 @@ return bridging::callFromJs( rt, &T::updatePassword, jsInvoker_, instance_, std::move(userID), std::move(deviceID), std::move(accessToken), std::move(password)); } + jsi::Value deleteUser(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken) override { + static_assert( + bridging::getParameterCount(&T::deleteUser) == 4, + "Expected deleteUser(...) to have 4 parameters"); + + 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 { static_assert( bridging::getParameterCount(&T::getOutboundKeysForUserDevice) == 4, 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,6 +2,7 @@ use crate::identity::Empty; use comm_opaque2::client::{Login, Registration}; use comm_opaque2::grpc::opaque_error_to_grpc_status as handle_error; +use identity::DeleteUserRequest; use lazy_static::lazy_static; use serde::Serialize; use std::sync::Arc; @@ -116,6 +117,14 @@ promise_id: u32, ); + #[cxx_name = "identityDeleteUser"] + fn delete_user( + user_id: String, + device_id: String, + access_token: String, + promise_id: u32, + ); + #[cxx_name = "identityGetOutboundKeysForUserDevice"] fn get_outbound_keys_for_user_device( identifier_type: String, @@ -186,6 +195,12 @@ Ok(nonce) } +struct AuthInfo { + user_id: String, + device_id: String, + access_token: String, +} + #[derive(Debug)] pub struct IdentityClient { identity_client: IdentityClientServiceClient, @@ -551,6 +566,36 @@ Ok(()) } +fn delete_user( + user_id: String, + device_id: String, + access_token: String, + promise_id: u32, +) { + RUNTIME.spawn(async move { + let auth_info = AuthInfo { + access_token, + user_id, + device_id, + }; + let result = delete_user_helper(auth_info).await; + handle_void_result_as_callback(result, promise_id); + }); +} + +async fn delete_user_helper(auth_info: AuthInfo) -> Result<(), Error> { + let delete_user_request = DeleteUserRequest { + access_token: auth_info.access_token, + user_id: auth_info.user_id, + device_id_key: auth_info.device_id, + }; + let mut identity_client = + IdentityClientServiceClient::connect("http://127.0.0.1:50054").await?; + identity_client.delete_user(delete_user_request).await?; + + Ok(()) +} + struct GetOutboundKeysRequestInfo { identifier_type: String, identifier_value: String, diff --git a/native/schema/CommRustModuleSchema.js b/native/schema/CommRustModuleSchema.js --- a/native/schema/CommRustModuleSchema.js +++ b/native/schema/CommRustModuleSchema.js @@ -50,6 +50,11 @@ accessToken: string, password: string, ) => Promise; + +deleteUser: ( + userID: string, + deviceID: string, + accessToken: string, + ) => Promise; +getOutboundKeysForUserDevice: ( identifierType: string, identifierValue: string,