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,7 @@ } 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 { validateInput } from '../utils/validation-utils.js'; const subscriptionUpdateRequestInputValidator = tShape({ @@ -342,8 +342,7 @@ signedIdentityKeysBlob.payload, ); - await olm.init(); - const olmUtil = new olm.Utility(); + const olmUtil = 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 };