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 @@ -275,6 +275,20 @@ jsi::String threadID, double limit, double offset) override; + virtual jsi::Value restoreUser( + jsi::Runtime &rt, + jsi::String userID, + std::optional siweSocialProofMessage, + std::optional siweSocialProofSignature, + 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 deviceList) 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 @@ -3382,4 +3382,71 @@ }); } +jsi::Value CommCoreModule::restoreUser( + jsi::Runtime &rt, + jsi::String userID, + std::optional siweSocialProofMessage, + std::optional siweSocialProofSignature, + 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 deviceList) { + rust::String siweSocialProofMessageRust = ""; + if (siweSocialProofMessage.has_value()) { + siweSocialProofMessageRust = + jsiStringToRustString(siweSocialProofMessage.value(), rt); + } + rust::String siweSocialProofSignatureRust = ""; + if (siweSocialProofSignature.has_value()) { + siweSocialProofSignatureRust = + jsiStringToRustString(siweSocialProofSignature.value(), rt); + } + auto userIDRust = jsiStringToRustString(userID, rt); + auto keyPayloadRust = jsiStringToRustString(keyPayload, rt); + auto keyPayloadSignatureRust = jsiStringToRustString(keyPayloadSignature, rt); + auto contentPrekeyRust = jsiStringToRustString(contentPrekey, rt); + auto contentPrekeySignatureRust = + jsiStringToRustString(contentPrekeySignature, rt); + auto notifPrekeyRust = jsiStringToRustString(notifPrekey, rt); + auto notifPrekeySignatureRust = + jsiStringToRustString(notifPrekeySignature, rt); + auto contentOneTimeKeysRust = jsiStringArrayToRustVec(contentOneTimeKeys, rt); + auto notifOneTimeKeysRust = jsiStringArrayToRustVec(notifOneTimeKeys, rt); + auto deviceListRust = jsiStringToRustString(deviceList, rt); + + return createPromiseAsJSIValue( + rt, [=, this](jsi::Runtime &innerRt, std::shared_ptr promise) { + std::string error; + try { + auto currentID = RustPromiseManager::instance.addPromise( + {promise, this->jsInvoker_, innerRt}); + identityRestoreUser( + userIDRust, + siweSocialProofMessageRust, + siweSocialProofSignatureRust, + keyPayloadRust, + keyPayloadSignatureRust, + contentPrekeyRust, + contentPrekeySignatureRust, + notifPrekeyRust, + notifPrekeySignatureRust, + contentOneTimeKeysRust, + notifOneTimeKeysRust, + deviceListRust, + currentID); + } catch (const std::exception &e) { + error = e.what(); + }; + if (!error.empty()) { + this->jsInvoker_->invokeAsync( + [error, promise]() { promise->reject(error); }); + } + }); +} + } // namespace comm 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 @@ -79,20 +79,7 @@ jsi::String notifPrekeySignature, jsi::Array contentOneTimeKeys, jsi::Array notifOneTimeKeys) override; - virtual jsi::Value restoreUser( - jsi::Runtime &rt, - jsi::String userID, - std::optional siweSocialProofMessage, - std::optional siweSocialProofSignature, - 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 deviceList) override; + virtual jsi::Value updatePassword( jsi::Runtime &rt, jsi::String userID, 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 @@ -317,73 +317,6 @@ }); } -jsi::Value CommRustModule::restoreUser( - jsi::Runtime &rt, - jsi::String userID, - std::optional siweSocialProofMessage, - std::optional siweSocialProofSignature, - 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 deviceList) { - rust::String siweSocialProofMessageRust = ""; - if (siweSocialProofMessage.has_value()) { - siweSocialProofMessageRust = - jsiStringToRustString(siweSocialProofMessage.value(), rt); - } - rust::String siweSocialProofSignatureRust = ""; - if (siweSocialProofSignature.has_value()) { - siweSocialProofSignatureRust = - jsiStringToRustString(siweSocialProofSignature.value(), rt); - } - auto userIDRust = jsiStringToRustString(userID, rt); - auto keyPayloadRust = jsiStringToRustString(keyPayload, rt); - auto keyPayloadSignatureRust = jsiStringToRustString(keyPayloadSignature, rt); - auto contentPrekeyRust = jsiStringToRustString(contentPrekey, rt); - auto contentPrekeySignatureRust = - jsiStringToRustString(contentPrekeySignature, rt); - auto notifPrekeyRust = jsiStringToRustString(notifPrekey, rt); - auto notifPrekeySignatureRust = - jsiStringToRustString(notifPrekeySignature, rt); - auto contentOneTimeKeysRust = jsiStringArrayToRustVec(contentOneTimeKeys, rt); - auto notifOneTimeKeysRust = jsiStringArrayToRustVec(notifOneTimeKeys, rt); - auto deviceListRust = jsiStringToRustString(deviceList, rt); - - return createPromiseAsJSIValue( - rt, [=, this](jsi::Runtime &innerRt, std::shared_ptr promise) { - std::string error; - try { - auto currentID = RustPromiseManager::instance.addPromise( - {promise, this->jsInvoker_, innerRt}); - identityRestoreUser( - userIDRust, - siweSocialProofMessageRust, - siweSocialProofSignatureRust, - keyPayloadRust, - keyPayloadSignatureRust, - contentPrekeyRust, - contentPrekeySignatureRust, - notifPrekeyRust, - notifPrekeySignatureRust, - contentOneTimeKeysRust, - notifOneTimeKeysRust, - deviceListRust, - currentID); - } catch (const std::exception &e) { - error = e.what(); - }; - if (!error.empty()) { - this->jsInvoker_->invokeAsync( - [error, promise]() { promise->reject(error); }); - } - }); -} - jsi::Value CommRustModule::updatePassword( jsi::Runtime &rt, jsi::String userID, diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -247,6 +247,9 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_fetchMessages(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->fetchMessages(rt, args[0].asString(rt), args[1].asNumber(), args[2].asNumber()); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreUser(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->restoreUser(rt, args[0].asString(rt), args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asString(rt)), args[3].asString(rt), args[4].asString(rt), args[5].asString(rt), args[6].asString(rt), args[7].asString(rt), args[8].asString(rt), args[9].asObject(rt).asArray(rt), args[10].asObject(rt).asArray(rt), args[11].asString(rt)); +} CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) : TurboModule("CommTurboModule", jsInvoker) { @@ -326,6 +329,7 @@ methodMap_["getRelatedMessages"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getRelatedMessages}; methodMap_["searchMessages"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_searchMessages}; methodMap_["fetchMessages"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_fetchMessages}; + methodMap_["restoreUser"] = MethodMetadata {12, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreUser}; } diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -96,6 +96,7 @@ virtual jsi::Value getRelatedMessages(jsi::Runtime &rt, jsi::String messageID) = 0; virtual jsi::Value searchMessages(jsi::Runtime &rt, jsi::String query, jsi::String threadID, std::optional timestampCursor, std::optional messageIDCursor) = 0; virtual jsi::Value fetchMessages(jsi::Runtime &rt, jsi::String threadID, double limit, double offset) = 0; + virtual jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional siweSocialProofMessage, std::optional siweSocialProofSignature, 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 deviceList) = 0; }; @@ -725,6 +726,14 @@ return bridging::callFromJs( rt, &T::fetchMessages, jsInvoker_, instance_, std::move(threadID), std::move(limit), std::move(offset)); } + jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional siweSocialProofMessage, std::optional siweSocialProofSignature, 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 deviceList) override { + static_assert( + bridging::getParameterCount(&T::restoreUser) == 13, + "Expected restoreUser(...) to have 13 parameters"); + + return bridging::callFromJs( + rt, &T::restoreUser, jsInvoker_, instance_, std::move(userID), std::move(siweSocialProofMessage), std::move(siweSocialProofSignature), std::move(keyPayload), std::move(keyPayloadSignature), std::move(contentPrekey), std::move(contentPrekeySignature), std::move(notifPrekey), std::move(notifPrekeySignature), std::move(contentOneTimeKeys), std::move(notifOneTimeKeys), std::move(deviceList)); + } private: T *instance_; 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 @@ -30,9 +30,6 @@ static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_logInWalletUser(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->logInWalletUser(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt), args[4].asString(rt), args[5].asString(rt), args[6].asString(rt), args[7].asString(rt), args[8].asObject(rt).asArray(rt), args[9].asObject(rt).asArray(rt)); } -static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_restoreUser(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->restoreUser(rt, args[0].asString(rt), args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)), args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asString(rt)), args[3].asString(rt), args[4].asString(rt), args[5].asString(rt), args[6].asString(rt), args[7].asString(rt), args[8].asString(rt), args[9].asObject(rt).asArray(rt), args[10].asObject(rt).asArray(rt), args[11].asString(rt)); -} 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), args[4].asString(rt)); } @@ -111,7 +108,6 @@ methodMap_["logInPasswordUser"] = MethodMetadata {10, __hostFunction_CommRustModuleSchemaCxxSpecJSI_logInPasswordUser}; methodMap_["registerWalletUser"] = MethodMetadata {12, __hostFunction_CommRustModuleSchemaCxxSpecJSI_registerWalletUser}; methodMap_["logInWalletUser"] = MethodMetadata {10, __hostFunction_CommRustModuleSchemaCxxSpecJSI_logInWalletUser}; - methodMap_["restoreUser"] = MethodMetadata {12, __hostFunction_CommRustModuleSchemaCxxSpecJSI_restoreUser}; methodMap_["updatePassword"] = MethodMetadata {5, __hostFunction_CommRustModuleSchemaCxxSpecJSI_updatePassword}; methodMap_["deletePasswordUser"] = MethodMetadata {4, __hostFunction_CommRustModuleSchemaCxxSpecJSI_deletePasswordUser}; methodMap_["deleteWalletUser"] = MethodMetadata {3, __hostFunction_CommRustModuleSchemaCxxSpecJSI_deleteWalletUser}; 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,6 @@ 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 registerWalletUser(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 farcasterID, jsi::String initialDeviceList) = 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) = 0; - virtual jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional siweSocialProofMessage, std::optional siweSocialProofSignature, 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 deviceList) = 0; virtual jsi::Value updatePassword(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken, jsi::String oldPassword, jsi::String newPassword) = 0; virtual jsi::Value deletePasswordUser(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken, jsi::String password) = 0; virtual jsi::Value deleteWalletUser(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken) = 0; @@ -119,14 +118,6 @@ return bridging::callFromJs( rt, &T::logInWalletUser, jsInvoker_, instance_, std::move(siweMessage), std::move(siweSignature), std::move(keyPayload), std::move(keyPayloadSignature), std::move(contentPrekey), std::move(contentPrekeySignature), std::move(notifPrekey), std::move(notifPrekeySignature), std::move(contentOneTimeKeys), std::move(notifOneTimeKeys)); } - jsi::Value restoreUser(jsi::Runtime &rt, jsi::String userID, std::optional siweSocialProofMessage, std::optional siweSocialProofSignature, 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 deviceList) override { - static_assert( - bridging::getParameterCount(&T::restoreUser) == 13, - "Expected restoreUser(...) to have 13 parameters"); - - return bridging::callFromJs( - rt, &T::restoreUser, jsInvoker_, instance_, std::move(userID), std::move(siweSocialProofMessage), std::move(siweSocialProofSignature), std::move(keyPayload), std::move(keyPayloadSignature), std::move(contentPrekey), std::move(contentPrekeySignature), std::move(notifPrekey), std::move(notifPrekeySignature), std::move(contentOneTimeKeys), std::move(notifOneTimeKeys), std::move(deviceList)); - } jsi::Value updatePassword(jsi::Runtime &rt, jsi::String userID, jsi::String deviceID, jsi::String accessToken, jsi::String oldPassword, jsi::String newPassword) override { static_assert( bridging::getParameterCount(&T::updatePassword) == 6, diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -564,7 +564,7 @@ commCoreModule.getOneTimeKeys(ONE_TIME_KEYS_NUMBER), commCoreModule.validateAndGetPrekeys(), ]); - const restoreResult = await commRustModule.restoreUser( + const restoreResult = await commCoreModule.restoreUser( userID, siweSocialProof?.message, siweSocialProof?.signature, diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -218,6 +218,20 @@ limit: number, offset: number, ) => Promise>; + +restoreUser: ( + userID: string, + siweSocialProofMessage: ?string, + siweSocialProofSignature: ?string, + keyPayload: string, + keyPayloadSignature: string, + contentPrekey: string, + contentPrekeySignature: string, + notifPrekey: string, + notifPrekeySignature: string, + contentOneTimeKeys: $ReadOnlyArray, + notifOneTimeKeys: $ReadOnlyArray, + deviceList: string, + ) => Promise; } export interface CoreModuleSpec extends Spec { diff --git a/native/schema/CommRustModuleSchema.js b/native/schema/CommRustModuleSchema.js --- a/native/schema/CommRustModuleSchema.js +++ b/native/schema/CommRustModuleSchema.js @@ -74,20 +74,6 @@ contentOneTimeKeys: $ReadOnlyArray, notifOneTimeKeys: $ReadOnlyArray, ) => Promise; - +restoreUser: ( - userID: string, - siweSocialProofMessage: ?string, - siweSocialProofSignature: ?string, - keyPayload: string, - keyPayloadSignature: string, - contentPrekey: string, - contentPrekeySignature: string, - notifPrekey: string, - notifPrekeySignature: string, - contentOneTimeKeys: $ReadOnlyArray, - notifOneTimeKeys: $ReadOnlyArray, - deviceList: string, - ) => Promise; +updatePassword: ( userID: string, deviceID: string,