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 @@ -126,4 +126,8 @@ +initializeCryptoAccount: () => Promise, +encrypt: (content: string, deviceID: string) => Promise, +decrypt: (encryptedContent: string, deviceID: string) => Promise, + +contentInboundSessionCreator: ( + contentIdentityKeys: OLMIdentityKeys, + initialEncryptedContent: string, + ) => Promise, }; 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 @@ -1,6 +1,6 @@ // @flow -import type { OlmAPI } from 'lib/types/crypto-types'; +import type { OlmAPI, OLMIdentityKeys } from 'lib/types/crypto-types'; import { commCoreModule } from '../native-modules.js'; @@ -14,6 +14,20 @@ async decrypt(encryptedContent: string, deviceID: string): Promise { return await commCoreModule.decrypt(encryptedContent, deviceID); }, + async contentInboundSessionCreator( + contentIdentityKeys: OLMIdentityKeys, + initialEncryptedContent: string, + ): Promise { + const identityKeys = JSON.stringify({ + curve25519: contentIdentityKeys.curve25519, + ed25519: contentIdentityKeys.ed25519, + }); + return commCoreModule.initializeContentInboundSession( + identityKeys, + initialEncryptedContent, + contentIdentityKeys.ed25519, + ); + }, }; export { olmAPI }; 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 @@ -6,11 +6,12 @@ import { type OlmAPI, olmEncryptedMessageTypes, + type OLMIdentityKeys, } from 'lib/types/crypto-types.js'; // methods below are just mocks to SQLite API // implement proper methods tracked in ENG-6462 -// eslint-disable-next-line no-unused-vars + function getOlmAccount(): Account { return new olm.Account(); } @@ -42,6 +43,27 @@ storeOlmSession(session); return result; }, + async contentInboundSessionCreator( + contentIdentityKeys: OLMIdentityKeys, + initialEncryptedContent: string, + ): Promise { + const account = getOlmAccount(); + const session = new olm.Session(); + session.create_inbound_from( + account, + contentIdentityKeys.curve25519, + initialEncryptedContent, + ); + + account.remove_one_time_keys(session); + const initialEncryptedMessage = session.decrypt( + olmEncryptedMessageTypes.PREKEY, + initialEncryptedContent, + ); + storeOlmAccount(account); + storeOlmSession(session); + return initialEncryptedMessage; + }, }; export { olmAPI };