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 @@ -89,7 +89,7 @@ +walletAddress?: ?string, }; -type FarcasterUser = { +export type FarcasterUser = { +userID: string, +username: string, +farcasterID: string, @@ -157,12 +157,10 @@ userID: string, nonceChallengeResponse: SignedMessage, ) => Promise; - // getFarcasterUsers is only implemented on native at the moment - +getFarcasterUsers?: ( + +getFarcasterUsers: ( farcasterIDs: $ReadOnlyArray, ) => Promise<$ReadOnlyArray>; - // linkFarcasterAccount is only implemented on native at the moment - +linkFarcasterAccount?: (farcasterID: string) => Promise; + +linkFarcasterAccount: (farcasterID: string) => Promise; } export type IdentityServiceAuthLayer = { 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 @@ -26,7 +26,9 @@ type DeviceOlmInboundKeys, deviceOlmInboundKeysValidator, userDeviceOlmInboundKeysValidator, + type FarcasterUser, } from 'lib/types/identity-service-types.js'; +import { farcasterUsersValidator } from 'lib/types/identity-service-types.js'; import { getMessageForException } from 'lib/utils/errors.js'; import { assertWithValidator } from 'lib/utils/validation-utils.js'; @@ -42,6 +44,7 @@ Prekey, WalletAuthRequest, SecondaryDeviceKeysUploadRequest, + GetFarcasterUsersRequest, } from '../protobufs/identity-unauth-structs.cjs'; import * as IdentityUnauthClient from '../protobufs/identity-unauth.cjs'; import { initOpaque } from '../shared-worker/utils/opaque-utils.js'; @@ -525,6 +528,50 @@ signedDeviceListHistoryValidator, ); }; + + getFarcasterUsers: ( + farcasterIDs: $ReadOnlyArray, + ) => Promise<$ReadOnlyArray> = async farcasterIDs => { + const getFarcasterUsersRequest = new GetFarcasterUsersRequest(); + getFarcasterUsersRequest.setFarcasterIdsList([...farcasterIDs]); + + let getFarcasterUsersResponse; + try { + getFarcasterUsersResponse = await this.unauthClient.getFarcasterUsers( + getFarcasterUsersRequest, + ); + } catch (e) { + console.log('Error calling getFarcasterUsers:', e); + throw new Error(getMessageForException(e) ?? 'unknown'); + } + + const farcasterUsersList = + getFarcasterUsersResponse.getFarcasterUsersList(); + + const returnList = []; + + for (const user of farcasterUsersList) { + returnList.push({ + userID: user.getUserId(), + username: user.getUsername(), + farcasterID: user.getFarcasterId(), + }); + } + + return assertWithValidator(returnList, farcasterUsersValidator); + }; + + linkFarcasterAccount: (farcasterID: string) => Promise = + async farcasterID => { + const client = this.authClient; + if (!client) { + throw new Error('Identity service client is not initialized'); + } + const linkFarcasterAccountRequest = + new IdentityAuthStructs.LinkFarcasterAccountRequest(); + linkFarcasterAccountRequest.setFarcasterId(farcasterID); + await client.linkFarcasterAccount(linkFarcasterAccountRequest); + }; } function authNewDeviceKeyUpload( diff --git a/web/grpc/identity-service-context-provider.react.js b/web/grpc/identity-service-context-provider.react.js --- a/web/grpc/identity-service-context-provider.react.js +++ b/web/grpc/identity-service-context-provider.react.js @@ -133,6 +133,8 @@ getDeviceListHistoryForUser: proxyMethodToWorker( 'getDeviceListHistoryForUser', ), + getFarcasterUsers: proxyMethodToWorker('getFarcasterUsers'), + linkFarcasterAccount: proxyMethodToWorker('linkFarcasterAccount'), }; }, [proxyMethodToWorker]);