Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3521554
D10752.id35907.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10752.id35907.diff
View Options
diff --git a/lib/shared/olm-session-creator-context.js b/lib/shared/olm-session-creator-context.js
--- a/lib/shared/olm-session-creator-context.js
+++ b/lib/shared/olm-session-creator-context.js
@@ -12,6 +12,10 @@
notificationsInitializationInfo: OlmSessionInitializationInfo,
keyserverID: string,
) => Promise<string>,
+ +contentSessionCreator: (
+ contentIdentityKeys: OLMIdentityKeys,
+ contentInitializationInfo: OlmSessionInitializationInfo,
+ ) => Promise<string>,
};
const OlmSessionCreatorContext: React.Context<?OlmSessionCreatorContextType> =
diff --git a/native/account/account-hooks.js b/native/account/account-hooks.js
--- a/native/account/account-hooks.js
+++ b/native/account/account-hooks.js
@@ -6,7 +6,10 @@
import type { OLMIdentityKeys } from 'lib/types/crypto-types.js';
import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js';
-import { nativeNotificationsSessionCreator } from '../utils/crypto-utils.js';
+import {
+ nativeNotificationsSessionCreator,
+ nativeOutboundContentSessionCreator,
+} from '../utils/crypto-utils.js';
type Props = {
+children: React.Node,
@@ -25,8 +28,20 @@
);
}
+function contentSessionCreator(
+ contentIdentityKeys: OLMIdentityKeys,
+ contentInitializationInfo: OlmSessionInitializationInfo,
+) {
+ return nativeOutboundContentSessionCreator(
+ contentIdentityKeys,
+ contentInitializationInfo,
+ contentIdentityKeys.ed25519,
+ );
+}
+
const contextValue = {
notificationsSessionCreator,
+ contentSessionCreator,
};
function OlmSessionCreatorProvider(props: Props): React.Node {
diff --git a/native/utils/crypto-utils.js b/native/utils/crypto-utils.js
--- a/native/utils/crypto-utils.js
+++ b/native/utils/crypto-utils.js
@@ -177,4 +177,5 @@
nativeNotificationsSessionCreator,
nativeInboundContentSessionCreator,
createOlmSessionsWithOwnDevices,
+ nativeOutboundContentSessionCreator,
};
diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js
--- a/web/account/account-hooks.js
+++ b/web/account/account-hooks.js
@@ -260,6 +260,44 @@
[getOrCreateCryptoStore],
);
+ const createNewContentSession = React.useCallback(
+ async (
+ contentIdentityKeys: OLMIdentityKeys,
+ contentInitializationInfo: OlmSessionInitializationInfo,
+ ) => {
+ const [{ primaryAccount }] = await Promise.all([
+ getOrCreateCryptoStore(),
+ initOlm(),
+ ]);
+
+ const account = new olm.Account();
+ const { picklingKey, pickledAccount } = primaryAccount;
+ account.unpickle(picklingKey, pickledAccount);
+
+ const contentPrekey = getPrekeyValueFromBlob(
+ contentInitializationInfo.prekey,
+ );
+ const [contentOneTimeKey] = getOneTimeKeyValuesFromBlob(
+ contentInitializationInfo.oneTimeKey,
+ );
+
+ const session = new olm.Session();
+ session.create_outbound(
+ account,
+ contentIdentityKeys.curve25519,
+ contentIdentityKeys.ed25519,
+ contentPrekey,
+ contentInitializationInfo.prekeySignature,
+ contentOneTimeKey,
+ );
+ const { body: initialContentEncryptedMessage } = session.encrypt(
+ JSON.stringify(initialEncryptedMessageContent),
+ );
+ return initialContentEncryptedMessage;
+ },
+ [getOrCreateCryptoStore],
+ );
+
const notificationsSessionPromise = React.useRef<?Promise<string>>(null);
const createNotificationsSession = React.useCallback(
async (
@@ -302,8 +340,9 @@
const contextValue = React.useMemo(
() => ({
notificationsSessionCreator: createNotificationsSession,
+ contentSessionCreator: createNewContentSession,
}),
- [createNotificationsSession],
+ [createNewContentSession, createNotificationsSession],
);
return (
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 3:56 AM (12 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698215
Default Alt Text
D10752.id35907.diff (3 KB)
Attached To
Mode
D10752: [web][native] implement creating outbound session in `OlmSessionCreatorContext`
Attached
Detach File
Event Timeline
Log In to Comment