Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3344918
D11111.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11111.diff
View Options
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
@@ -121,3 +121,9 @@
PREKEY: 0,
TEXT: 1,
});
+
+export type OlmAPI = {
+ +initializeCryptoAccount: () => Promise<void>,
+ +encrypt: (content: string, deviceID: string) => Promise<string>,
+ +decrypt: (encryptedContent: string, deviceID: string) => Promise<string>,
+};
diff --git a/lib/utils/config.js b/lib/utils/config.js
--- a/lib/utils/config.js
+++ b/lib/utils/config.js
@@ -9,6 +9,7 @@
} from '../keyserver-conn/keyserver-conn-types.js';
import type { InitialNotifMessageOptions } from '../shared/crypto-utils.js';
import type { LogInActionSource } from '../types/account-types.js';
+import type { OlmAPI } from '../types/crypto-types.js';
import type { PlatformDetails } from '../types/device-types.js';
export type Config = {
@@ -27,6 +28,7 @@
+calendarRangeInactivityLimit: ?number,
+platformDetails: PlatformDetails,
+authoritativeKeyserverID: string,
+ +olmAPI: OlmAPI,
};
let registeredConfig: ?Config = null;
diff --git a/native/config.js b/native/config.js
--- a/native/config.js
+++ b/native/config.js
@@ -6,6 +6,7 @@
import { resolveKeyserverSessionInvalidationUsingNativeCredentials } from './account/legacy-recover-keyserver-session.js';
import { authoritativeKeyserverID } from './authoritative-keyserver.js';
+import { olmAPI } from './crypto/olm-api.js';
import { persistConfig, codeVersion } from './redux/persist.js';
registerConfig({
@@ -18,4 +19,5 @@
stateVersion: persistConfig.version,
},
authoritativeKeyserverID,
+ olmAPI,
});
diff --git a/native/crypto/olm-api.js b/native/crypto/olm-api.js
new file mode 100644
--- /dev/null
+++ b/native/crypto/olm-api.js
@@ -0,0 +1,15 @@
+// @flow
+
+import type { OlmAPI } from 'lib/types/crypto-types';
+
+import { commCoreModule } from '../native-modules.js';
+
+const olmAPI: OlmAPI = {
+ async initializeCryptoAccount(): Promise<void> {
+ await commCoreModule.initializeCryptoAccount();
+ },
+ encrypt: commCoreModule.encrypt,
+ decrypt: commCoreModule.decrypt,
+};
+
+export { olmAPI };
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -45,6 +45,7 @@
import { EditModalProvider } from './chat/edit-message-provider.js';
import { MemberListSidebarProvider } from './chat/member-list-sidebar/member-list-sidebar-provider.react.js';
import NavigationArrows from './components/navigation-arrows.react.js';
+import { olmAPI } from './crypto/olm-api.js';
import { initOpaque } from './crypto/opaque-utils.js';
import { getDatabaseModule } from './database/database-module-provider.js';
import electron from './electron.js';
@@ -104,6 +105,7 @@
...desktopDetails,
},
authoritativeKeyserverID,
+ olmAPI,
});
const versionBroadcast = new BroadcastChannel('comm_version');
diff --git a/web/crypto/olm-api.js b/web/crypto/olm-api.js
new file mode 100644
--- /dev/null
+++ b/web/crypto/olm-api.js
@@ -0,0 +1,47 @@
+// @flow
+
+import olm from '@commapp/olm';
+import type { Account, Session } from '@commapp/olm';
+
+import {
+ type OlmAPI,
+ olmEncryptedMessageTypes,
+} 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();
+}
+// eslint-disable-next-line no-unused-vars
+function getOlmSession(deviceID: string): Session {
+ return new olm.Session();
+}
+// eslint-disable-next-line no-unused-vars
+function storeOlmAccount(account: Account): void {}
+// eslint-disable-next-line no-unused-vars
+function storeOlmSession(session: Session): void {}
+
+const olmAPI: OlmAPI = {
+ async initializeCryptoAccount(): Promise<void> {
+ await olm.init();
+ },
+ async encrypt(content: string, deviceID: string): Promise<string> {
+ const session = getOlmSession(deviceID);
+ const { body } = session.encrypt(content);
+ storeOlmSession(session);
+ return body;
+ },
+ async decrypt(encryptedContent: string, deviceID: string): Promise<string> {
+ const session = getOlmSession(deviceID);
+ const result = session.decrypt(
+ olmEncryptedMessageTypes.TEXT,
+ encryptedContent,
+ );
+ storeOlmSession(session);
+ return result;
+ },
+};
+
+export { olmAPI };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 4:53 AM (17 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2568974
Default Alt Text
D11111.diff (4 KB)
Attached To
Mode
D11111: [lib] introduce stateless `olm` API
Attached
Detach File
Event Timeline
Log In to Comment