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 @@ -125,8 +125,10 @@ jsi::String deviceID) override; virtual jsi::Value encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override; - virtual jsi::Value - decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override; + virtual jsi::Value decrypt( + jsi::Runtime &rt, + jsi::Object encryptedDataJSI, + jsi::String deviceID) override; virtual jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) override; virtual void terminate(jsi::Runtime &rt) override; 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 @@ -1240,9 +1240,12 @@ jsi::Value CommCoreModule::decrypt( jsi::Runtime &rt, - jsi::String message, + jsi::Object encryptedDataJSI, jsi::String deviceID) { - auto messageCpp{message.utf8(rt)}; + size_t messageType = + std::lround(encryptedDataJSI.getProperty(rt, "messageType").asNumber()); + std::string message = + encryptedDataJSI.getProperty(rt, "message").asString(rt).utf8(rt); auto deviceIDCpp{deviceID.utf8(rt)}; return createPromiseAsJSIValue( rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { @@ -1251,8 +1254,8 @@ std::string decryptedMessage; try { crypto::EncryptedData encryptedData{ - std::vector(messageCpp.begin(), messageCpp.end()), - ENCRYPTED_MESSAGE_TYPE}; + std::vector(message.begin(), message.end()), + messageType}; decryptedMessage = this->contentCryptoModule->decrypt(deviceIDCpp, encryptedData); this->persistCryptoModules(true, false); 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 @@ -109,7 +109,7 @@ return static_cast(&turboModule)->encrypt(rt, args[0].asString(rt), args[1].asString(rt)); } static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_decrypt(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->decrypt(rt, args[0].asString(rt), args[1].asString(rt)); + return static_cast(&turboModule)->decrypt(rt, args[0].asObject(rt), args[1].asString(rt)); } static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_signMessage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->signMessage(rt, args[0].asString(rt)); 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 @@ -51,7 +51,7 @@ virtual jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKey, jsi::String deviceID) = 0; virtual jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String encryptedMessage, jsi::String deviceID) = 0; virtual jsi::Value encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0; - virtual jsi::Value decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0; + virtual jsi::Value decrypt(jsi::Runtime &rt, jsi::Object encryptedData, jsi::String deviceID) = 0; virtual jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) = 0; virtual double getCodeVersion(jsi::Runtime &rt) = 0; virtual void terminate(jsi::Runtime &rt) = 0; @@ -343,13 +343,13 @@ return bridging::callFromJs( rt, &T::encrypt, jsInvoker_, instance_, std::move(message), std::move(deviceID)); } - jsi::Value decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override { + jsi::Value decrypt(jsi::Runtime &rt, jsi::Object encryptedData, jsi::String deviceID) override { static_assert( bridging::getParameterCount(&T::decrypt) == 3, "Expected decrypt(...) to have 3 parameters"); return bridging::callFromJs( - rt, &T::decrypt, jsInvoker_, instance_, std::move(message), std::move(deviceID)); + rt, &T::decrypt, jsInvoker_, instance_, std::move(encryptedData), std::move(deviceID)); } jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) override { static_assert( diff --git a/native/crypto/olm-api.js b/native/crypto/olm-api.js --- a/native/crypto/olm-api.js +++ b/native/crypto/olm-api.js @@ -6,7 +6,6 @@ type OneTimeKeysResultValues, type OlmAPI, type OLMIdentityKeys, - type EncryptedData, } from 'lib/types/crypto-types.js'; import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; @@ -18,12 +17,7 @@ }, getUserPublicKey: commCoreModule.getUserPublicKey, encrypt: commCoreModule.encrypt, - async decrypt( - encryptedData: EncryptedData, - deviceID: string, - ): Promise { - return commCoreModule.decrypt(encryptedData.message, deviceID); - }, + decrypt: commCoreModule.decrypt, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, initialEncryptedContent: string, diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -109,7 +109,7 @@ deviceID: string, ) => Promise; +encrypt: (message: string, deviceID: string) => Promise; - +decrypt: (message: string, deviceID: string) => Promise; + +decrypt: (encryptedData: Object, deviceID: string) => Promise; +signMessage: (message: string) => Promise; +getCodeVersion: () => number; +terminate: () => void; @@ -147,6 +147,7 @@ password: string, backupID: string, ) => Promise; + +decrypt: (encryptedData: EncryptedData, deviceID: string) => Promise; } export default (TurboModuleRegistry.getEnforcing(