Skip to content

fix: twitter verification #3772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("Fetch Credentials", () => {
const payload: GHOrgRequestPayload = {
address: "0x0",
type: "Simple",
types: [],
version: "Test-Case-1",
org: "gitcoinco",
};
Expand Down Expand Up @@ -71,7 +72,7 @@ describe("Fetch Credentials", () => {

if (url.includes("verify")) {
return {
data: MOCK_VERIFY_RESPONSE_BODY,
data: [MOCK_VERIFY_RESPONSE_BODY],
};
}

Expand Down Expand Up @@ -102,13 +103,15 @@ describe("Fetch Credentials", () => {

it("will not attempt to sign if not provided a challenge in the challenge credential", async () => {
jest.spyOn(axios, "post").mockResolvedValueOnce({
data: {
credential: {
credentialSubject: {
challenge: null,
data: [
{
credential: {
credentialSubject: {
challenge: null,
},
},
},
},
],
});

await expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
RequestPayload,
IssuedChallenge,
VerifiableCredentialRecord,
VerifiableCredential,
} from "@gitcoinco/passport-sdk-types";
import { CredentialProvider } from "../../../types";

export type { VerifiableCredential } from "@gitcoinco/passport-sdk-types";

Expand Down Expand Up @@ -37,6 +39,8 @@ export enum ClientType {
}

export type GHOrgRequestPayload = RequestPayload & {
type: string;
types: CredentialProvider[];
requestedClient?: ClientType.GrantHub;
org?: string;
};
Expand All @@ -51,7 +55,7 @@ export class VerificationError extends Error {
// Fetch a verifiableCredential
export const fetchVerifiableCredential = async (
iamUrl: string,
payload: any,
payload: GHOrgRequestPayload,
signer: { signMessage: (message: string) => Promise<string> }
): Promise<VerifiableCredentialRecord> => {
// first pull a challenge that can be signed by the user
Expand All @@ -74,20 +78,29 @@ export const fetchVerifiableCredential = async (
payload.proofs = { ...payload.proofs, ...{ signature } };

// fetch a credential from the API that fits the version, payload and passes the signature message challenge
const response = await axios.post(
const response = (await axios.post(
`${iamUrl.replace(/\/*?$/, "")}/v${payload.version}/verify`,
{
payload,
challenge,
}
);
)) as {
data: {
record: VerifiableCredentialRecord["record"];
credential: VerifiableCredential;
}[];
};

if (response.data.length === 0) {
throw new VerificationError("No credential found");
}

// return everything that was used to create the credential (along with the credential)
return {
signature,
challenge,
record: response?.data.record,
credential: response?.data.credential,
record: response.data[0].record,
credential: response.data[0].credential,
} as VerifiableCredentialRecord;
};

Expand Down
Loading