4
4
RequestPayload ,
5
5
IssuedChallenge ,
6
6
VerifiableCredentialRecord ,
7
+ VerifiableCredential ,
7
8
} from "@gitcoinco/passport-sdk-types" ;
9
+ import { CredentialProvider } from "../../../types" ;
8
10
9
11
export type { VerifiableCredential } from "@gitcoinco/passport-sdk-types" ;
10
12
@@ -37,6 +39,8 @@ export enum ClientType {
37
39
}
38
40
39
41
export type GHOrgRequestPayload = RequestPayload & {
42
+ type : string ;
43
+ types : CredentialProvider [ ] ;
40
44
requestedClient ?: ClientType . GrantHub ;
41
45
org ?: string ;
42
46
} ;
@@ -51,7 +55,7 @@ export class VerificationError extends Error {
51
55
// Fetch a verifiableCredential
52
56
export const fetchVerifiableCredential = async (
53
57
iamUrl : string ,
54
- payload : any ,
58
+ payload : GHOrgRequestPayload ,
55
59
signer : { signMessage : ( message : string ) => Promise < string > }
56
60
) : Promise < VerifiableCredentialRecord > => {
57
61
// first pull a challenge that can be signed by the user
@@ -74,20 +78,29 @@ export const fetchVerifiableCredential = async (
74
78
payload . proofs = { ...payload . proofs , ...{ signature } } ;
75
79
76
80
// 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 (
78
82
`${ iamUrl . replace ( / \/ * ?$ / , "" ) } /v${ payload . version } /verify` ,
79
83
{
80
84
payload,
81
85
challenge,
82
86
}
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
+ }
84
97
85
98
// return everything that was used to create the credential (along with the credential)
86
99
return {
87
100
signature,
88
101
challenge,
89
- record : response ? .data . record ,
90
- credential : response ? .data . credential ,
102
+ record : response . data [ 0 ] . record ,
103
+ credential : response . data [ 0 ] . credential ,
91
104
} as VerifiableCredentialRecord ;
92
105
} ;
93
106
0 commit comments