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 @@ -112,6 +112,13 @@ TEXT: 1, }); +export type OlmEncryptedMessageTypes = $Values; + +export type EncryptedData = { + +message: string, + +messageType: OlmEncryptedMessageTypes, +}; + export type ClientPublicKeys = { +primaryIdentityPublicKeys: { +ed25519: string, @@ -128,7 +135,7 @@ export type OlmAPI = { +initializeCryptoAccount: () => Promise, +getUserPublicKey: () => Promise, - +encrypt: (content: string, deviceID: string) => Promise, + +encrypt: (content: string, deviceID: string) => Promise, +decrypt: (encryptedContent: string, deviceID: string) => Promise, +contentInboundSessionCreator: ( contentIdentityKeys: OLMIdentityKeys, 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 @@ -2,10 +2,12 @@ import { getOneTimeKeyValues } from 'lib/shared/crypto-utils.js'; import { type AuthMetadata } from 'lib/shared/identity-client-context.js'; -import type { - OneTimeKeysResultValues, - OlmAPI, - OLMIdentityKeys, +import { + type OneTimeKeysResultValues, + type OlmAPI, + type OLMIdentityKeys, + type EncryptedData, + olmEncryptedMessageTypes, } from 'lib/types/crypto-types.js'; import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; @@ -16,7 +18,13 @@ await commCoreModule.initializeCryptoAccount(); }, getUserPublicKey: commCoreModule.getUserPublicKey, - encrypt: commCoreModule.encrypt, + async encrypt(content: string, deviceID: string): Promise { + const encryptedContent = await commCoreModule.encrypt(content, deviceID); + return { + message: encryptedContent, + messageType: olmEncryptedMessageTypes.TEXT, + }; + }, decrypt: commCoreModule.decrypt, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, diff --git a/native/profile/tunnelbroker-menu.react.js b/native/profile/tunnelbroker-menu.react.js --- a/native/profile/tunnelbroker-menu.react.js +++ b/native/profile/tunnelbroker-menu.react.js @@ -29,6 +29,7 @@ +navigation: ProfileNavigationProp<'TunnelbrokerMenu'>, +route: NavigationRoute<'TunnelbrokerMenu'>, }; + // eslint-disable-next-line no-unused-vars function TunnelbrokerMenu(props: Props): React.Node { const styles = useStyles(unboundStyles); @@ -84,7 +85,7 @@ return; } await olmAPI.initializeCryptoAccount(); - const encrypted = await olmAPI.encrypt( + const { message: encrypted } = await olmAPI.encrypt( `Encrypted message to ${recipient}`, recipient, ); diff --git a/web/settings/tunnelbroker-test.react.js b/web/settings/tunnelbroker-test.react.js --- a/web/settings/tunnelbroker-test.react.js +++ b/web/settings/tunnelbroker-test.react.js @@ -61,7 +61,7 @@ setLoading(true); try { await olmAPI.initializeCryptoAccount(); - const encrypted = await olmAPI.encrypt( + const { message: encrypted } = await olmAPI.encrypt( `Encrypted message to ${recipient}`, recipient, ); 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 @@ -16,6 +16,7 @@ type OneTimeKeysResultValues, type ClientPublicKeys, type NotificationsOlmDataType, + type EncryptedData, } from 'lib/types/crypto-types.js'; import type { IdentityNewDeviceKeyUpload, @@ -365,7 +366,7 @@ signature, }; }, - async encrypt(content: string, deviceID: string): Promise { + async encrypt(content: string, deviceID: string): Promise { if (!cryptoStore) { throw new Error('Crypto account not initialized'); } @@ -373,11 +374,14 @@ if (!session) { throw new Error(`No session for deviceID: ${deviceID}`); } - const { body } = session.encrypt(content); + const encryptedContent = session.encrypt(content); persistCryptoStore(); - return body; + return { + message: encryptedContent.body, + messageType: encryptedContent.type, + }; }, async decrypt(encryptedContent: string, deviceID: string): Promise { if (!cryptoStore) {