Skip to content

Commit

Permalink
Add Verification methods in client
Browse files Browse the repository at this point in the history
Add Verification methods in client
  • Loading branch information
Shreyaschorge authored Oct 27, 2023
2 parents 3132e15 + 40e72e7 commit 681a686
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 179 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "0.0.6",
"version": "0.0.7",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
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
Loading

0 comments on commit 681a686

Please sign in to comment.