Skip to content

Commit

Permalink
fix: Selective disclosure gql resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Nov 30, 2019
1 parent b0b5b70 commit f4ec808
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/daf-selective-disclosure/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ const actionSignSDR = async (
}

const sdr = async (message: any, { sub }: { sub: string }, { dataStore }: Context) => {
const { payload } = (await decodeJWT(message.jwt)) as any
const { payload }: { payload: SDRInput } = (await decodeJWT(message.jwt)) as any
const result: any = []
const subject = sub || message.sub.did
for (const credentialRequest of payload.claims) {
const credentials = await dataStore.findCredentialsByFields({
iss: credentialRequest.iss && credentialRequest.iss.map((iss: any) => iss.did),
sub: [subject],
claim_type: credentialRequest.claimType,
})
const subject = sub || message.sub?.did
if (payload.claims) {
for (const credentialRequest of payload.claims) {
const iss: any =
credentialRequest.iss !== undefined ? credentialRequest.iss.map((iss: any) => iss.did) : []
const credentials = await dataStore.findCredentialsByFields({
iss,
sub: subject ? [subject] : [],
claim_type: credentialRequest.claimType,
})

result.push({
...credentialRequest,
vc: credentials.map((credential: any) => ({
...credential,
__typename: 'VerifiableClaim',
})),
})
result.push({
...credentialRequest,
iss: credentialRequest.iss?.map(item => ({ url: item.url, did: { did: item.did } })),
vc: credentials.map((credential: any) => ({ ...credential, __typename: 'VerifiableClaim' })),
})
}
}

return result
Expand Down Expand Up @@ -77,7 +79,7 @@ export const typeDefs = `
}
type Issuer {
did: String
did: Identity
url: String
}
Expand Down

0 comments on commit f4ec808

Please sign in to comment.