HomePhabricator
Diffusion Comm 62dfab9a7bb1

Introduce methods in CommCoreModule to initialize olm session for notifications.

Description

Introduce methods in CommCoreModule to initialize olm session for notifications. Refactor method to get one time keys for primary olm account

Summary:
This differential introduces methods in CommCoreModule to initialize olm session with keyserver one time keys and prekey for notifications olm account. Additionally method for primary olm account to generate one time keys is
refactored. The refactor gives us control on how many one time keys are generated (previously we were restricted to the default value in CryptoModule.h). Refactored method returns JS
object of type OLMOneTimeKeys. Note that getUserOneTimeKeys` returned raw string previously.
This differential seems to be broad but only changes in CommCoreModule.cpp matter. The rest is boilerplate.

Test Plan:
To test refactored getUserOneTimeKeys(<number>) method:
In account-selectors place the following code under commCoreModule.initializeCryptoAccount():

const userOneTimeKeys = await commCoreModule.getUserOneTimeKeys(10);
console.log(userOneTimeKeys);

Build the app, log-in and examine content of keys logged to the console.

To test new methods for notifications identity:
In account-selectors place the following code under commCoreModule.initializeCryptoAccount():

if (!(await commCoreModule.isNotificationsSessionInitialized())) {
    await commCoreModule.initializeNotificationsSession(
         '{"curve25519":"o+tfILWz+bAo5j1q1uRIkJPTgOU499Ib93B8olZW31s","ed25519":"15gDzUxPx5DntkgmAcLrZcnS4kkMQKDtw/wfna4EMPE"}',
         '{"curve25519":{"AAAAAQ":"A/sCRbBRsOwtYBFCJ9H0o/9opVM5wcAHKvpr43aiYnA"}}',
         '{"curve25519":{"AAAAAQ":"MXeHR/2J5zCdF8gsFzaMksNo9hx5QADUOSlYdctyyX8"}}',
    );
 }
const encryptedMessage = await commCoreModule.generateInitialNotificationsEncryptedMessage();
console.log(encryptedMessage);

Build the app, log-in and examine content of message logged to the console.

I created the keys above using olm JS bindings on the keyserver.

Reviewers: tomek, atul, bartek, jon

Reviewed By: atul

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D7395