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 @@ -147,6 +147,11 @@ +getUserPublicKey: () => Promise, +encrypt: (content: string, deviceID: string) => Promise, +decrypt: (encryptedData: EncryptedData, deviceID: string) => Promise, + +decryptSequential: ( + encryptedData: EncryptedData, + deviceID: string, + messageID: string, + ) => Promise, +contentInboundSessionCreator: ( contentIdentityKeys: OLMIdentityKeys, initialEncryptedData: EncryptedData, diff --git a/lib/utils/__mocks__/config.js b/lib/utils/__mocks__/config.js --- a/lib/utils/__mocks__/config.js +++ b/lib/utils/__mocks__/config.js @@ -17,6 +17,7 @@ getUserPublicKey: jest.fn(), encrypt: jest.fn(), decrypt: jest.fn(), + decryptSequential: jest.fn(), contentInboundSessionCreator: jest.fn(), contentOutboundSessionCreator: jest.fn(), notificationsSessionCreator: jest.fn(), 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 @@ -20,6 +20,7 @@ getUserPublicKey: commCoreModule.getUserPublicKey, encrypt: commCoreModule.encrypt, decrypt: commCoreModule.decrypt, + decryptSequential: commCoreModule.decryptSequential, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, initialEncryptedData: EncryptedData, diff --git a/web/crypto/olm-api.js b/web/crypto/olm-api.js --- a/web/crypto/olm-api.js +++ b/web/crypto/olm-api.js @@ -46,6 +46,7 @@ getUserPublicKey: proxyToWorker('getUserPublicKey'), encrypt: proxyToWorker('encrypt'), decrypt: proxyToWorker('decrypt'), + decryptSequential: proxyToWorker('decryptSequential'), contentInboundSessionCreator: proxyToWorker('contentInboundSessionCreator'), contentOutboundSessionCreator: proxyToWorker('contentOutboundSessionCreator'), notificationsSessionCreator: proxyToWorker('notificationsSessionCreator'), 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 @@ -452,6 +452,30 @@ return result; }, + async decryptSequential( + encryptedData: EncryptedData, + deviceID: string, + // eslint-disable-next-line no-unused-vars + messageID: string, + ): Promise { + if (!cryptoStore) { + throw new Error('Crypto account not initialized'); + } + + const { session } = cryptoStore.contentSessions[deviceID]; + if (!session) { + throw new Error(`No session for deviceID: ${deviceID}`); + } + + const result = session.decrypt_sequential( + encryptedData.messageType, + encryptedData.message, + ); + + persistCryptoStore(); + + return result; + }, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, initialEncryptedData: EncryptedData,