diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -61,6 +61,9 @@ jsi::Value setCurrentUserID(jsi::Runtime &rt, const jsi::String &userID) override; jsi::Value getCurrentUserID(jsi::Runtime &rt) override; + jsi::Value + setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) override; + jsi::Value getDeviceID(jsi::Runtime &rt) override; jsi::Value clearSensitiveData(jsi::Runtime &rt) override; public: diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -1,4 +1,5 @@ #include "CommCoreModule.h" +#include "../CryptoTools/DeviceID.h" #include "DatabaseManager.h" #include "GRPCStreamHostObject.h" #include "InternalModules/GlobalDBSingleton.h" @@ -995,6 +996,27 @@ }); } +jsi::Value +CommCoreModule::setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) { + std::string type = deviceType.utf8(rt); + std::string deviceID; + try { + deviceID = generateDeviceID(type); + } catch (std::invalid_argument &e) { + throw jsi::JSError( + rt, + "setDeviceID: incorrect function argument. Must be one of: " + "KEYSERVER, WEB, MOBILE."); + } + DatabaseManager::getQueryExecutor().setDeviceID(deviceID); + return jsi::String::createFromUtf8(rt, deviceID); +} + +jsi::Value CommCoreModule::getDeviceID(jsi::Runtime &rt) { + return jsi::String::createFromUtf8( + rt, DatabaseManager::getQueryExecutor().getDeviceID()); +} + jsi::Value CommCoreModule::clearSensitiveData(jsi::Runtime &rt) { return createPromiseAsJSIValue( rt, [this](jsi::Runtime &innerRt, std::shared_ptr promise) { diff --git a/native/cpp/CommonCpp/_generated/NativeModules.h b/native/cpp/CommonCpp/_generated/NativeModules.h --- a/native/cpp/CommonCpp/_generated/NativeModules.h +++ b/native/cpp/CommonCpp/_generated/NativeModules.h @@ -40,6 +40,8 @@ virtual jsi::Value clearNotifyToken(jsi::Runtime &rt) = 0; virtual jsi::Value setCurrentUserID(jsi::Runtime &rt, const jsi::String &userID) = 0; virtual jsi::Value getCurrentUserID(jsi::Runtime &rt) = 0; +virtual jsi::Value setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) = 0; +virtual jsi::Value getDeviceID(jsi::Runtime &rt) = 0; virtual jsi::Value clearSensitiveData(jsi::Runtime &rt) = 0; }; diff --git a/native/cpp/CommonCpp/_generated/NativeModules.cpp b/native/cpp/CommonCpp/_generated/NativeModules.cpp --- a/native/cpp/CommonCpp/_generated/NativeModules.cpp +++ b/native/cpp/CommonCpp/_generated/NativeModules.cpp @@ -80,6 +80,12 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getCurrentUserID(rt); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->setDeviceID(rt, args[0].getString(rt)); +} +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->getDeviceID(rt); +} static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->clearSensitiveData(rt); } @@ -108,6 +114,8 @@ methodMap_["clearNotifyToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken}; methodMap_["setCurrentUserID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCurrentUserID}; methodMap_["getCurrentUserID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID}; + methodMap_["setDeviceID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID}; + methodMap_["getDeviceID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID}; methodMap_["clearSensitiveData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData}; } diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -50,6 +50,8 @@ +clearNotifyToken: () => Promise; +setCurrentUserID: (userID: string) => Promise; +getCurrentUserID: () => Promise; + +setDeviceID: (deviceType: string) => Promise; + +getDeviceID: () => Promise; +clearSensitiveData: () => Promise; }