44 RequestPayload ,
55 IssuedChallenge ,
66 VerifiableCredentialRecord ,
7+ VerifiableCredential ,
78} from "@gitcoinco/passport-sdk-types" ;
9+ import { CredentialProvider } from "../../../types" ;
810
911export type { VerifiableCredential } from "@gitcoinco/passport-sdk-types" ;
1012
@@ -37,6 +39,8 @@ export enum ClientType {
3739}
3840
3941export 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
5256export 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