diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -59,7 +59,7 @@ username: string, password: string, ) => Promise; - +getOutboundKeysForUser?: ( + +getOutboundKeysForUser: ( userID: string, ) => Promise; } diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -5,12 +5,17 @@ import { getOneTimeKeyArray } from 'lib/shared/crypto-utils.js'; import { IdentityClientContext } from 'lib/shared/identity-client-context.js'; import { - type IdentityServiceClient, - type UserLoginResponse, + type IdentityKeysBlob, + identityKeysBlobValidator, +} from 'lib/types/crypto-types.js'; +import { type DeviceOlmOutboundKeys, deviceOlmOutboundKeysValidator, + type IdentityServiceClient, + ONE_TIME_KEYS_NUMBER, + type UserDevicesOlmOutboundKeys, + type UserLoginResponse, } from 'lib/types/identity-service-types.js'; -import { ONE_TIME_KEYS_NUMBER } from 'lib/types/identity-service-types.js'; import { assertWithValidator } from 'lib/utils/validation-utils.js'; import { getCommServicesAuthMetadataEmitter } from '../event-emitters/csa-auth-metadata-emitter.js'; @@ -111,6 +116,83 @@ deviceOlmOutboundKeysValidator, ); }, + getOutboundKeysForUser: async ( + targetUserID: string, + ): Promise => { + const { + deviceID: authDeviceID, + userID, + accessToken, + } = await getAuthMetadata(); + const result = await commRustModule.getOutboundKeysForUser( + userID, + authDeviceID, + accessToken, + targetUserID, + ); + const resultArray = JSON.parse(result); + + return resultArray + .map(outboundKeysInfo => { + try { + const payload = outboundKeysInfo?.payload; + const identityKeysBlob: IdentityKeysBlob = assertWithValidator( + payload ? JSON.parse(payload) : null, + identityKeysBlobValidator, + ); + const deviceID = + identityKeysBlob.primaryIdentityPublicKeys.ed25519; + + if ( + !outboundKeysInfo.oneTimeContentPrekey || + !outboundKeysInfo.oneTimeNotifPrekey + ) { + console.log(`Missing one time key for device ${deviceID}`); + return { + deviceID, + keys: null, + }; + } + + const deviceKeys = { + identityKeysBlob, + contentInitializationInfo: { + prekey: outboundKeysInfo?.contentPrekey, + prekeySignature: outboundKeysInfo?.contentPrekeySignature, + oneTimeKey: outboundKeysInfo?.oneTimeContentPrekey, + }, + notifInitializationInfo: { + prekey: outboundKeysInfo?.notifPrekey, + prekeySignature: outboundKeysInfo?.notifPrekeySignature, + oneTimeKey: outboundKeysInfo?.oneTimeNotifPrekey, + }, + payloadSignature: outboundKeysInfo?.payloadSignature, + socialProof: outboundKeysInfo?.socialProof, + }; + + try { + const validatedKeys = assertWithValidator( + deviceKeys, + deviceOlmOutboundKeysValidator, + ); + return { + deviceID, + keys: validatedKeys, + }; + } catch (e) { + console.log(e); + return { + deviceID, + keys: null, + }; + } + } catch (e) { + console.log(e); + return null; + } + }) + .filter(Boolean); + }, registerUser: async (username: string, password: string) => { await commCoreModule.initializeCryptoAccount(); const [