diff --git a/keyserver/src/utils/identity-utils.js b/keyserver/src/utils/identity-utils.js --- a/keyserver/src/utils/identity-utils.js +++ b/keyserver/src/utils/identity-utils.js @@ -89,10 +89,41 @@ ); } +async function publishPrekeys( + deviceID: string, + contentPrekey: string, + contentPrekeySignature: string, + notifPrekey: string, + notifPrekeySignature: string, +): Promise { + const [rustAPI, identityInfo] = await Promise.all([ + getRustAPI(), + verifyUserLoggedIn(), + ]); + + if (!identityInfo) { + console.warn( + 'Attempted to refresh prekeys before registering with Identity service', + ); + return; + } + + await rustAPI.publishPrekeys( + identityInfo.userId, + deviceID, + identityInfo.accessToken, + contentPrekey, + contentPrekeySignature, + notifPrekey, + notifPrekeySignature, + ); +} + export { findUserIdentities, privilegedDeleteUsers, privilegedResetUserPassword, syncPlatformDetails, uploadOneTimeKeys, + publishPrekeys, }; 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 @@ -7,7 +7,6 @@ Session as OlmSession, } from '@commapp/olm'; import invariant from 'invariant'; -import { getRustAPI } from 'rust-node-addon'; import uuid from 'uuid'; import { getOneTimeKeyValuesFromBlob } from 'lib/shared/crypto-utils.js'; @@ -21,7 +20,7 @@ retrieveAccountKeysSet, } from 'lib/utils/olm-utils.js'; -import { uploadOneTimeKeys } from './identity-utils.js'; +import { publishPrekeys, uploadOneTimeKeys } from './identity-utils.js'; import { fetchCallUpdateOlmAccount, fetchOlmAccount, @@ -274,8 +273,6 @@ contentAccount: OlmAccount, notifAccount: OlmAccount, ): Promise { - const rustAPIPromise = getRustAPI(); - const verifyUserLoggedInPromise = verifyUserLoggedIn(); const deviceID = JSON.parse(contentAccount.identity_keys()).ed25519; const { prekey: contentPrekey, prekeySignature: contentPrekeySignature } = @@ -288,22 +285,8 @@ return; } - const [rustAPI, identityInfo] = await Promise.all([ - rustAPIPromise, - verifyUserLoggedInPromise, - ]); - - if (!identityInfo) { - console.warn( - 'Attempted to refresh prekeys before registering with Identity service', - ); - return; - } - - await rustAPI.publishPrekeys( - identityInfo.userId, + await publishPrekeys( deviceID, - identityInfo.accessToken, contentPrekey, contentPrekeySignature, notifPrekey,