diff --git a/lib/handlers/peer-to-peer-message-handler.js b/lib/handlers/peer-to-peer-message-handler.js --- a/lib/handlers/peer-to-peer-message-handler.js +++ b/lib/handlers/peer-to-peer-message-handler.js @@ -1,5 +1,6 @@ // @flow +import { olmEncryptedMessageTypes } from '../types/crypto-types.js'; import type { IdentityServiceClient, DeviceOlmInboundKeys, @@ -49,7 +50,10 @@ try { await olmAPI.initializeCryptoAccount(); const decrypted = await olmAPI.decrypt( - message.encryptedContent, + { + messageType: olmEncryptedMessageTypes.TEXT, + message: message.encryptedContent, + }, message.senderInfo.deviceID, ); console.log( diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js --- a/lib/types/crypto-types.js +++ b/lib/types/crypto-types.js @@ -136,7 +136,7 @@ +initializeCryptoAccount: () => Promise, +getUserPublicKey: () => Promise, +encrypt: (content: string, deviceID: string) => Promise, - +decrypt: (encryptedContent: string, deviceID: string) => Promise, + +decrypt: (encryptedData: EncryptedData, deviceID: string) => Promise, +contentInboundSessionCreator: ( contentIdentityKeys: OLMIdentityKeys, initialEncryptedContent: string, 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,6 +6,7 @@ type OneTimeKeysResultValues, type OlmAPI, type OLMIdentityKeys, + type EncryptedData, } from 'lib/types/crypto-types.js'; import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; @@ -17,7 +18,12 @@ }, getUserPublicKey: commCoreModule.getUserPublicKey, encrypt: commCoreModule.encrypt, - decrypt: commCoreModule.decrypt, + async decrypt( + encryptedData: EncryptedData, + deviceID: string, + ): Promise { + return commCoreModule.decrypt(encryptedData.message, deviceID); + }, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, initialEncryptedContent: string, diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js --- a/web/shared-worker/worker/worker-crypto.js +++ b/web/shared-worker/worker/worker-crypto.js @@ -383,7 +383,10 @@ messageType: encryptedContent.type, }; }, - async decrypt(encryptedContent: string, deviceID: string): Promise { + async decrypt( + encryptedData: EncryptedData, + deviceID: string, + ): Promise { if (!cryptoStore) { throw new Error('Crypto account not initialized'); } @@ -394,8 +397,8 @@ } const result = session.decrypt( - olmEncryptedMessageTypes.TEXT, - encryptedContent, + encryptedData.messageType, + encryptedData.message, ); persistCryptoStore();