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 * as IdentityClient from '../protobufs/identity-client.cjs'; import { Empty } from '../protobufs/identity-structs.cjs'; @@ -81,6 +85,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 };