Skip to content

Commit

Permalink
Add Verification methods in the client
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyaschorge committed Oct 27, 2023
1 parent 5c503f3 commit 9554f2c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class NeynarV1APIClient {
user: UserApi;
cast: CastApi;
follows: FollowsApi;
verification: VerificationApi;
};

/**
Expand Down Expand Up @@ -73,6 +74,7 @@ export class NeynarV1APIClient {
user: new UserApi(config, undefined, axiosInstance),
cast: new CastApi(config, undefined, axiosInstance),
follows: new FollowsApi(config, undefined, axiosInstance),
verification: new VerificationApi(config, undefined, axiosInstance),
};
}

Expand Down Expand Up @@ -294,6 +296,45 @@ export class NeynarV1APIClient {
}
}

// ------------ Verification ------------

/**
* Gets all known verifications of a user.
* See [Neynar documentation](https://docs.neynar.com/reference/verifications-v1)
*
*/
public async fetchUserVerifications(
fid: number
): Promise<VerificationResponseResult | null> {
const response = await this.apis.verification.verifications({ fid });
return response.data.result;
}

/**
* Checks if a given Ethereum address has a Farcaster user associated with it.
* Note: if an address is associated with multiple users, the API will return
* the user who most recently published a verification with the address
* (based on when Warpcast received the proof, not a self-reported timestamp).
* See [Neynar documentation](https://docs.neynar.com/reference/user-by-verification-v1)
*
*/
public async lookupUserByVerification(address: string): Promise<User | null> {
try {
const response = await this.apis.verification.userByVerification({
address,
});
return response.data.result.user;
} catch (error) {
if (NeynarV1APIClient.isApiErrorResponse(error)) {
const status = error.response.status;
if (status === 404) {
return null;
}
}
throw error;
}
}

// ------------ Follow ------------

/**
Expand Down

0 comments on commit 9554f2c

Please sign in to comment.