diff --git a/web/grpc/identity-service-client-wrapper.js b/web/grpc/identity-service-client-wrapper.js --- a/web/grpc/identity-service-client-wrapper.js +++ b/web/grpc/identity-service-client-wrapper.js @@ -1,10 +1,14 @@ // @flow import identityServiceConfig from 'lib/facts/identity-service.js'; -import type { IdentityServiceAuthLayer } from 'lib/types/identity-service-types.js'; +import type { + IdentityServiceAuthLayer, + OutboundKeyInfoResponse, +} from 'lib/types/identity-service-types.js'; import { VersionInterceptor, AuthInterceptor } from './interceptor.js'; import * as IdentityAuthClient from '../protobufs/identity-auth-client.cjs'; +import * as IdentityAuthStructs from '../protobufs/identity-auth-structs.cjs'; import { Empty } from '../protobufs/identity-unauth-structs.cjs'; import * as IdentityClient from '../protobufs/identity-unauth.cjs'; @@ -85,6 +89,55 @@ throw new Error('Identity service client is not initialized'); } }; + + async getKeyserverKeys( + userID: string, + deviceID: string, + accessToken: string, + keyserverID: string, + ): Promise { + if (!this.authClient) { + const authLayer: IdentityServiceAuthLayer = { + userID, + deviceID, + commServicesAccessToken: accessToken, + }; + await this.initAuthClient(authLayer); + } + + const client = this.authClient; + if (!client) { + throw new Error('Identity service client is not initialized'); + } + + const request = new IdentityAuthStructs.OutboundKeysForUserRequest(); + request.setUserId(keyserverID); + const response = await client.getKeyserverKeys(request); + const keyserverInfo = response.getKeyserverInfo(); + if (!response.hasKeyserverInfo() || !keyserverInfo) { + return null; + } + + const identityInfo = keyserverInfo.getIdentityInfo(); + const contentPreKey = keyserverInfo.getContentPrekey(); + const notifPreKey = keyserverInfo.getNotifPrekey(); + + if (!identityInfo || !contentPreKey || !notifPreKey) { + return null; + } + + return { + payload: identityInfo.getPayload(), + payloadSignature: identityInfo.getPayloadSignature(), + socialProof: identityInfo.getSocialProof(), + contentPrekey: contentPreKey.getPrekey(), + contentPrekeySignature: contentPreKey.getPrekeySignature(), + notifPrekey: notifPreKey.getPrekey(), + notifPrekeySignature: notifPreKey.getPrekeySignature(), + oneTimeContentPrekey: keyserverInfo.getOneTimeContentPrekey(), + oneTimeNotifPrekey: keyserverInfo.getOneTimeNotifPrekey(), + }; + } } export { IdentityServiceClientWrapper };