Skip to content

Commit 04ff59a

Browse files
authored
fix: twitter verification (#3772)
* fix: twitter verification * fix: lint issue
1 parent 2b48afe commit 04ff59a

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

packages/builder/src/components/providers/identity/__tests__/credentials.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("Fetch Credentials", () => {
2121
const payload: GHOrgRequestPayload = {
2222
address: "0x0",
2323
type: "Simple",
24+
types: [],
2425
version: "Test-Case-1",
2526
org: "gitcoinco",
2627
};
@@ -71,7 +72,7 @@ describe("Fetch Credentials", () => {
7172

7273
if (url.includes("verify")) {
7374
return {
74-
data: MOCK_VERIFY_RESPONSE_BODY,
75+
data: [MOCK_VERIFY_RESPONSE_BODY],
7576
};
7677
}
7778

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

103104
it("will not attempt to sign if not provided a challenge in the challenge credential", async () => {
104105
jest.spyOn(axios, "post").mockResolvedValueOnce({
105-
data: {
106-
credential: {
107-
credentialSubject: {
108-
challenge: null,
106+
data: [
107+
{
108+
credential: {
109+
credentialSubject: {
110+
challenge: null,
111+
},
109112
},
110113
},
111-
},
114+
],
112115
});
113116

114117
await expect(

packages/builder/src/components/providers/identity/credentials.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
RequestPayload,
55
IssuedChallenge,
66
VerifiableCredentialRecord,
7+
VerifiableCredential,
78
} from "@gitcoinco/passport-sdk-types";
9+
import { CredentialProvider } from "../../../types";
810

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

@@ -37,6 +39,8 @@ export enum ClientType {
3739
}
3840

3941
export type GHOrgRequestPayload = RequestPayload & {
42+
type: string;
43+
types: CredentialProvider[];
4044
requestedClient?: ClientType.GrantHub;
4145
org?: string;
4246
};
@@ -51,7 +55,7 @@ export class VerificationError extends Error {
5155
// Fetch a verifiableCredential
5256
export const fetchVerifiableCredential = async (
5357
iamUrl: string,
54-
payload: any,
58+
payload: GHOrgRequestPayload,
5559
signer: { signMessage: (message: string) => Promise<string> }
5660
): Promise<VerifiableCredentialRecord> => {
5761
// first pull a challenge that can be signed by the user
@@ -74,20 +78,29 @@ export const fetchVerifiableCredential = async (
7478
payload.proofs = { ...payload.proofs, ...{ signature } };
7579

7680
// fetch a credential from the API that fits the version, payload and passes the signature message challenge
77-
const response = await axios.post(
81+
const response = (await axios.post(
7882
`${iamUrl.replace(/\/*?$/, "")}/v${payload.version}/verify`,
7983
{
8084
payload,
8185
challenge,
8286
}
83-
);
87+
)) as {
88+
data: {
89+
record: VerifiableCredentialRecord["record"];
90+
credential: VerifiableCredential;
91+
}[];
92+
};
93+
94+
if (response.data.length === 0) {
95+
throw new VerificationError("No credential found");
96+
}
8497

8598
// return everything that was used to create the credential (along with the credential)
8699
return {
87100
signature,
88101
challenge,
89-
record: response?.data.record,
90-
credential: response?.data.credential,
102+
record: response.data[0].record,
103+
credential: response.data[0].credential,
91104
} as VerifiableCredentialRecord;
92105
};
93106

0 commit comments

Comments
 (0)