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 @@ -58,6 +58,7 @@ jsi::Value setNotifyToken(jsi::Runtime &rt, const jsi::String &token) override; jsi::Value clearNotifyToken(jsi::Runtime &rt) override; + jsi::String getDeviceID(jsi::Runtime &rt, const jsi::String &type) override; public: CommCoreModule(std::shared_ptr jsInvoker); 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 @@ -14,6 +14,8 @@ #include #include +#include "../CryptoTools/Tools.h" + namespace comm { using namespace facebook::react; @@ -955,4 +957,24 @@ }); }; +jsi::String +CommCoreModule::getDeviceID(jsi::Runtime &rt, const jsi::String &jsType) { + std::string id = ""; + std::string type = jsType.utf8(rt); + if (type == "KEYSERVER") { + id = "ks-"; + } else if (type == "WEB") { + id = "web-"; + } else if (type == "MOBILE") { + id = "mobile-"; + } else { + throw jsi::JSError( + rt, + "getDeviceID: incorrect string. Must be one of: KEYSERVER, WEB, " + "MOBILE."); + } + id += crypto::Tools::generateRandomHexString(64); + return jsi::String::createFromUtf8(rt, id); +} + } // namespace comm 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 @@ -38,6 +38,7 @@ virtual double getCodeVersion(jsi::Runtime &rt) = 0; virtual jsi::Value setNotifyToken(jsi::Runtime &rt, const jsi::String &token) = 0; virtual jsi::Value clearNotifyToken(jsi::Runtime &rt) = 0; +virtual jsi::String getDeviceID(jsi::Runtime &rt, const jsi::String &jsType) = 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 @@ -72,6 +72,9 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->clearNotifyToken(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, args[0].getString(rt)); +} CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) : TurboModule("CommTurboModule", jsInvoker) { @@ -95,6 +98,7 @@ methodMap_["getCodeVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion}; methodMap_["setNotifyToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setNotifyToken}; methodMap_["clearNotifyToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken}; + methodMap_["getDeviceID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID}; } diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -48,6 +48,7 @@ +getCodeVersion: () => number; +setNotifyToken: (token: string) => Promise; +clearNotifyToken: () => Promise; + +getDeviceID: (jsType: string) => string; } export default (TurboModuleRegistry.getEnforcing(