diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -10,7 +10,10 @@ } from '../keyserver-conn/keyserver-call-utils.js'; import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js'; import { preRequestUserStateSelector } from '../selectors/account-selectors.js'; -import { getOneTimeKeyValuesFromBlob } from '../shared/crypto-utils.js'; +import { + getOneTimeKeyValuesFromBlob, + getPrekeyValueFromBlob, +} from '../shared/crypto-utils.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import threadWatcher from '../shared/thread-watcher.js'; import type { @@ -762,12 +765,18 @@ oneTimeKey: getOneTimeKeyValuesFromBlob( olmInitData.contentInitializationInfo.oneTimeKey, )[0], + prekey: getPrekeyValueFromBlob( + olmInitData.contentInitializationInfo.prekey, + ), }, notifInitializationInfo: { ...olmInitData.notifInitializationInfo, oneTimeKey: getOneTimeKeyValuesFromBlob( olmInitData.notifInitializationInfo.oneTimeKey, )[0], + prekey: getPrekeyValueFromBlob( + olmInitData.notifInitializationInfo.prekey, + ), }, }; }; diff --git a/lib/shared/crypto-utils.js b/lib/shared/crypto-utils.js --- a/lib/shared/crypto-utils.js +++ b/lib/shared/crypto-utils.js @@ -107,7 +107,6 @@ export { getOneTimeKeyValues, - getPrekeyValue, getOneTimeKeyValuesFromBlob, getPrekeyValueFromBlob, initialEncryptedMessageContent, diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js --- a/lib/types/crypto-types.js +++ b/lib/types/crypto-types.js @@ -17,8 +17,7 @@ export type OLMPrekey = { +curve25519: { - +id: string, - +key: string, + +[key: string]: string, }, }; diff --git a/lib/utils/olm-utils.js b/lib/utils/olm-utils.js --- a/lib/utils/olm-utils.js +++ b/lib/utils/olm-utils.js @@ -2,8 +2,10 @@ import type { Account as OlmAccount } from '@commapp/olm'; -import { values } from './objects.js'; -import { getOneTimeKeyValuesFromBlob } from '../shared/crypto-utils.js'; +import { + getOneTimeKeyValuesFromBlob, + getPrekeyValueFromBlob, +} from '../shared/crypto-utils.js'; import { ONE_TIME_KEYS_NUMBER } from '../types/identity-service-types.js'; const maxPublishedPrekeyAge = 30 * 24 * 60 * 60 * 1000; @@ -69,8 +71,7 @@ +prekey: string, +prekeySignature: ?string, } { - const prekeyMap = JSON.parse(account.prekey()).curve25519; - const [prekey] = values(prekeyMap); + const prekey = getPrekeyValueFromBlob(account.prekey()); const prekeySignature = account.prekey_signature(); return { prekey, prekeySignature }; } diff --git a/native/cpp/CommonCpp/CryptoTools/Session.cpp b/native/cpp/CommonCpp/CryptoTools/Session.cpp --- a/native/cpp/CommonCpp/CryptoTools/Session.cpp +++ b/native/cpp/CommonCpp/CryptoTools/Session.cpp @@ -35,7 +35,7 @@ KEYSIZE, idKeys.data() + SIGNING_KEYS_PREFIX_OFFSET, KEYSIZE, - preKeys.data() + PRE_KEY_PREFIX_OFFSET, + preKeys.data(), KEYSIZE, preKeySignature.data(), SIGNATURESIZE, diff --git a/native/cpp/CommonCpp/CryptoTools/Tools.h b/native/cpp/CommonCpp/CryptoTools/Tools.h --- a/native/cpp/CommonCpp/CryptoTools/Tools.h +++ b/native/cpp/CommonCpp/CryptoTools/Tools.h @@ -10,7 +10,6 @@ #define ID_KEYS_PREFIX_OFFSET 15 #define SIGNING_KEYS_PREFIX_OFFSET 71 -#define PRE_KEY_PREFIX_OFFSET 25 #define ENCRYPTED_MESSAGE_TYPE 1 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 @@ -6,10 +6,7 @@ import * as React from 'react'; import uuid from 'uuid'; -import { - initialEncryptedMessageContent, - getPrekeyValueFromBlob, -} from 'lib/shared/crypto-utils.js'; +import { initialEncryptedMessageContent } from 'lib/shared/crypto-utils.js'; import { OlmSessionCreatorContext } from 'lib/shared/olm-session-creator-context.js'; import type { SignedIdentityKeysBlob, @@ -258,9 +255,7 @@ const { picklingKey, pickledAccount } = notificationAccount; account.unpickle(picklingKey, pickledAccount); - const notificationsPrekey = getPrekeyValueFromBlob( - notificationsInitializationInfo.prekey, - ); + const notificationsPrekey = notificationsInitializationInfo.prekey; const session = new olm.Session(); session.create_outbound( @@ -334,9 +329,7 @@ const { picklingKey, pickledAccount } = primaryAccount; account.unpickle(picklingKey, pickledAccount); - const contentPrekey = getPrekeyValueFromBlob( - contentInitializationInfo.prekey, - ); + const contentPrekey = contentInitializationInfo.prekey; const session = new olm.Session(); session.create_outbound(