Page MenuHomePhabricator

D7653.id.diff
No OneTemporary

D7653.id.diff

diff --git a/native/utils/crypto-utils.js b/native/utils/crypto-utils.js
new file mode 100644
--- /dev/null
+++ b/native/utils/crypto-utils.js
@@ -0,0 +1,47 @@
+// @flow
+
+import * as React from 'react';
+
+import {
+ getOlmSessionInitializationData,
+ getOlmSessionInitializationDataActionTypes,
+} from 'lib/actions/user-actions.js';
+import {
+ useServerCall,
+ useDispatchActionPromise,
+} from 'lib/utils/action-utils.js';
+
+import { commCoreModule } from '../native-modules.js';
+
+function useInitialNotificationsEncryptedMessage(): () => Promise<string> {
+ const callGetOlmSessionInitializationData = useServerCall(
+ getOlmSessionInitializationData,
+ );
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(async () => {
+ const olmSessionDataPromise = callGetOlmSessionInitializationData();
+
+ dispatchActionPromise(
+ getOlmSessionInitializationDataActionTypes,
+ olmSessionDataPromise,
+ );
+
+ const { signedIdentityKeysBlob, notifInitializationInfo } =
+ await olmSessionDataPromise;
+
+ const { notificationIdentityPublicKeys } = JSON.parse(
+ signedIdentityKeysBlob.payload,
+ );
+
+ const { prekey, prekeySignature, oneTimeKey } = notifInitializationInfo;
+ return await commCoreModule.initializeNotificationsSession(
+ JSON.stringify(notificationIdentityPublicKeys),
+ prekey,
+ prekeySignature,
+ oneTimeKey,
+ );
+ }, [callGetOlmSessionInitializationData, dispatchActionPromise]);
+}
+
+export { useInitialNotificationsEncryptedMessage };

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 2, 3:15 AM (1 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2606592
Default Alt Text
D7653.id.diff (1 KB)

Event Timeline