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 @@ -1,6 +1,6 @@ // @flow -import t, { type TInterface, type TList } from 'tcomb'; +import t, { type TInterface, type TList, type TDict } from 'tcomb'; import { identityKeysBlobValidator, @@ -157,6 +157,9 @@ userID: string, sinceTimestamp?: number, ) => Promise<$ReadOnlyArray>; + +getDeviceListsForUsers?: ( + userIDs: $ReadOnlyArray, + ) => Promise; // updating device list is possible only on Native // web cannot be a primary device, so there's no need to expose it to JS +updateDeviceList?: (newDeviceList: SignedDeviceList) => Promise; @@ -229,6 +232,12 @@ export const signedDeviceListHistoryValidator: TList> = t.list(signedDeviceListValidator); +export type UsersSignedDeviceLists = { + +[userID: string]: SignedDeviceList, +}; +export const usersSignedDeviceListsValidator: TDict = + t.dict(t.String, signedDeviceListValidator); + export type SignedNonce = { +nonce: string, +nonceSignature: string, 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 @@ -10,21 +10,23 @@ type OneTimeKeysResultValues, } from 'lib/types/crypto-types.js'; import { - type SignedDeviceList, - signedDeviceListHistoryValidator, - type SignedNonce, + type DeviceOlmInboundKeys, + deviceOlmInboundKeysValidator, type DeviceOlmOutboundKeys, deviceOlmOutboundKeysValidator, + farcasterUsersValidator, + identityAuthResultValidator, type IdentityServiceClient, - type UserDevicesOlmOutboundKeys, - type UserAuthMetadata, ONE_TIME_KEYS_NUMBER, - identityAuthResultValidator, - type DeviceOlmInboundKeys, - type UserDevicesOlmInboundKeys, - deviceOlmInboundKeysValidator, + type SignedDeviceList, + signedDeviceListHistoryValidator, + type SignedNonce, + type UserAuthMetadata, userDeviceOlmInboundKeysValidator, - farcasterUsersValidator, + type UserDevicesOlmInboundKeys, + type UserDevicesOlmOutboundKeys, + type UsersSignedDeviceLists, + usersSignedDeviceListsValidator, } from 'lib/types/identity-service-types.js'; import { getContentSigningKey } from 'lib/utils/crypto-utils.js'; import { assertWithValidator } from 'lib/utils/validation-utils.js'; @@ -545,6 +547,33 @@ signedDeviceListHistoryValidator, ); }, + getDeviceListsForUsers: async (userIDs: $ReadOnlyArray) => { + const { + deviceID: authDeviceID, + userID: authUserID, + accessToken: token, + } = await getAuthMetadata(); + const result = await commRustModule.getDeviceListsForUsers( + authUserID, + authDeviceID, + token, + userIDs, + ); + const rawPayloads: { +[userID: string]: string } = JSON.parse(result); + + let usersDeviceLists: UsersSignedDeviceLists = {}; + for (const userID in rawPayloads) { + usersDeviceLists = { + ...usersDeviceLists, + [userID]: JSON.parse(rawPayloads[userID]), + }; + } + + return assertWithValidator( + usersDeviceLists, + usersSignedDeviceListsValidator, + ); + }, updateDeviceList: async (newDeviceList: SignedDeviceList) => { const { deviceID: authDeviceID,