Page MenuHomePhabricator

D6901.id23189.diff
No OneTemporary

D6901.id23189.diff

diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js
--- a/keyserver/src/keyserver.js
+++ b/keyserver/src/keyserver.js
@@ -1,5 +1,6 @@
// @flow
+import olm from '@matrix-org/olm';
import cluster from 'cluster';
import cookieParser from 'cookie-parser';
import express from 'express';
@@ -38,6 +39,7 @@
} from './utils/urls.js';
(async () => {
+ await olm.init();
await prefetchAllURLFacts();
const squadCalBaseRoutePath = getSquadCalURLFacts()?.baseRoutePath;
diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js
--- a/keyserver/src/responders/user-responders.js
+++ b/keyserver/src/responders/user-responders.js
@@ -1,6 +1,5 @@
// @flow
-import olm from '@matrix-org/olm';
import invariant from 'invariant';
import { ErrorTypes, SiweMessage } from 'siwe';
import t from 'tcomb';
@@ -94,6 +93,8 @@
} from '../updaters/account-updaters.js';
import { userSubscriptionUpdater } from '../updaters/user-subscription-updaters.js';
import { viewerAcknowledgmentUpdater } from '../updaters/viewer-acknowledgment-updater.js';
+import { getOLMUtility } from '../utils/olm-utils.js';
+import type { OLMUtility } from '../utils/olm-utils.js';
import { validateInput } from '../utils/validation-utils.js';
const subscriptionUpdateRequestInputValidator = tShape({
@@ -342,8 +343,7 @@
signedIdentityKeysBlob.payload,
);
- await olm.init();
- const olmUtil = new olm.Utility();
+ const olmUtil: OLMUtility = getOLMUtility();
try {
olmUtil.ed25519_verify(
identityKeys.primaryIdentityPublicKeys.ed25519,
diff --git a/keyserver/src/utils/olm-utils.js b/keyserver/src/utils/olm-utils.js
--- a/keyserver/src/utils/olm-utils.js
+++ b/keyserver/src/utils/olm-utils.js
@@ -1,5 +1,6 @@
// @flow
+import olm from '@matrix-org/olm';
import invariant from 'invariant';
import { importJSON } from './import-json.js';
@@ -25,4 +26,13 @@
) => void,
};
-export { getOlmConfig };
+let cachedOLMUtility: OLMUtility;
+function getOLMUtility(): OLMUtility {
+ if (cachedOLMUtility) {
+ return cachedOLMUtility;
+ }
+ cachedOLMUtility = new olm.Utility();
+ return cachedOLMUtility;
+}
+
+export { getOlmConfig, getOLMUtility };

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 9:47 PM (19 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2695423
Default Alt Text
D6901.id23189.diff (2 KB)

Event Timeline