diff --git a/keyserver/src/utils/farcaster-utils.js b/keyserver/src/utils/farcaster-utils.js new file mode 100644 --- /dev/null +++ b/keyserver/src/utils/farcaster-utils.js @@ -0,0 +1,26 @@ +// @flow + +import { getRustAPI } from 'rust-node-addon'; + +import { verifyUserIDs } from '../fetchers/user-fetchers.js'; + +async function getVerifiedUserIDForFID(fid: string): Promise { + const rustAPI = await getRustAPI(); + const farcasterUsers = await rustAPI.getFarcasterUsers([fid]); + + const validUserIDs = await verifyUserIDs( + farcasterUsers.map(user => user.userID), + ); + + const validFarcasterUsers = farcasterUsers.filter(user => + validUserIDs.includes(user.userID), + ); + + if (validFarcasterUsers.length === 0) { + return null; + } + + return validFarcasterUsers[0].userID; +} + +export { getVerifiedUserIDForFID };