From 991e64b3189405ddf2c3a43acc15c2ffe652380a Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Mon, 2 Dec 2019 16:24:32 +0200 Subject: [PATCH] fix: W3C VP subject is aud --- packages/daf-data-store/src/graphql.ts | 81 +++++------------------ packages/daf-w3c/src/payload-validator.ts | 9 +-- 2 files changed, 21 insertions(+), 69 deletions(-) diff --git a/packages/daf-data-store/src/graphql.ts b/packages/daf-data-store/src/graphql.ts index f2cdaae11..f71fd6773 100644 --- a/packages/daf-data-store/src/graphql.ts +++ b/packages/daf-data-store/src/graphql.ts @@ -6,16 +6,13 @@ interface Context { export const resolvers = { Message: { - vc: async (message: any, {}, { dataStore }: Context) => - dataStore.credentialsForMessageHash(message.hash), + vc: async (message: any, {}, { dataStore }: Context) => dataStore.credentialsForMessageHash(message.hash), }, VerifiableClaim: { - fields: async (vc: any, {}, { dataStore }: Context) => - dataStore.credentialsFieldsForClaimHash(vc.hash), + fields: async (vc: any, {}, { dataStore }: Context) => dataStore.credentialsFieldsForClaimHash(vc.hash), }, Identity: { - shortId: async (identity: any, {}, { dataStore }: Context) => - dataStore.shortId(identity.did), + shortId: async (identity: any, {}, { dataStore }: Context) => dataStore.shortId(identity.did), firstName: async (identity: any, {}, { dataStore }: Context) => dataStore.popularClaimForDid(identity.did, 'firstName'), lastName: async (identity: any, {}, { dataStore }: Context) => @@ -38,40 +35,21 @@ export const resolvers = { dataStore.popularClaimForDid(identity.did, 'url'), description: async (identity: any, {}, { dataStore }: Context) => dataStore.popularClaimForDid(identity.did, 'description'), - interactionCount: async ( - identity: any, - { did }: { did: string }, - { dataStore }: Context, - ) => dataStore.interactionCount(identity.did, did), - credentialsIssued: async ( - identity: any, - args: any, - { dataStore }: Context, - ) => { + interactionCount: async (identity: any, { did }: { did: string }, { dataStore }: Context) => + dataStore.interactionCount(identity.did, did), + credentialsIssued: async (identity: any, args: any, { dataStore }: Context) => { return dataStore.findCredentials({ iss: identity.did }) }, - credentialsReceived: async ( - identity: any, - args: any, - { dataStore }: Context, - ) => { + credentialsReceived: async (identity: any, args: any, { dataStore }: Context) => { return dataStore.findCredentials({ sub: identity.did }) }, - credentialsAll: async ( - identity: any, - args: any, - { dataStore }: Context, - ) => { + credentialsAll: async (identity: any, args: any, { dataStore }: Context) => { return dataStore.findCredentials({ iss: identity.did, sub: identity.did }) }, messagesSent: async (identity: any, args: any, { dataStore }: Context) => { return dataStore.findMessages({ iss: identity.did }) }, - messagesReceived: async ( - identity: any, - args: any, - { dataStore }: Context, - ) => { + messagesReceived: async (identity: any, args: any, { dataStore }: Context) => { return dataStore.findMessages({ sub: identity.did }) }, messagesAll: async (identity: any, args: any, { dataStore }: Context) => { @@ -79,50 +57,28 @@ export const resolvers = { }, }, Query: { - identity: async ( - _: any, - { did }: { did: string }, - { dataStore }: Context, - ) => dataStore.findIdentityByDid(did), - identities: async ( - _: any, - { dids }: { dids: string[] }, - { dataStore }: Context, - ) => { + identity: async (_: any, { did }: { did: string }, { dataStore }: Context) => + dataStore.findIdentityByDid(did), + identities: async (_: any, { dids }: { dids: string[] }, { dataStore }: Context) => { return dids ? dids.map(did => ({ did })) : dataStore.allIdentities() }, messages: async ( _: any, - { - iss, - sub, - tag, - limit, - }: { iss: string; sub: string; tag: string; limit: number }, + { iss, sub, tag, limit }: { iss: string; sub: string; tag: string; limit: number }, { dataStore }: Context, ) => { return dataStore.findMessages({ iss, sub, tag, limit }) }, - message: async ( - _: any, - { hash }: { hash: string }, - { dataStore }: Context, - ) => dataStore.findMessage(hash), - credentials: async ( - _: any, - { iss, sub }: { iss: string; sub: string }, - { dataStore }: Context, - ) => { + message: async (_: any, { hash }: { hash: string }, { dataStore }: Context) => + dataStore.findMessage(hash), + credentials: async (_: any, { iss, sub }: { iss: string; sub: string }, { dataStore }: Context) => { const res = await dataStore.findCredentials({ iss, sub }) return res }, }, Mutation: { - deleteMessage: async ( - _: any, - { hash }: { hash: string }, - { dataStore }: Context, - ) => dataStore.deleteMessage(hash), + deleteMessage: async (_: any, { hash }: { hash: string }, { dataStore }: Context) => + dataStore.deleteMessage(hash), }, } @@ -158,7 +114,6 @@ export const typeDefs = ` extend type Message { iss: Identity! sub: Identity - aud: Identity jwt: String! data: String! iat: Int diff --git a/packages/daf-w3c/src/payload-validator.ts b/packages/daf-w3c/src/payload-validator.ts index a2c6a1394..667ea2cc1 100644 --- a/packages/daf-w3c/src/payload-validator.ts +++ b/packages/daf-w3c/src/payload-validator.ts @@ -15,10 +15,7 @@ export const MessageTypes = { } export class PayloadValidator implements DidJwtPayloadValidator { - async validate( - verifiedJwt: any, - didResolver: Resolver, - ): Promise { + async validate(verifiedJwt: any, didResolver: Resolver): Promise { try { validatePresentationAttributes(verifiedJwt.payload) @@ -26,7 +23,7 @@ export class PayloadValidator implements DidJwtPayloadValidator { const vc = await Promise.all( verifiedJwt.payload.vp.verifiableCredential.map((vcJwt: string) => - verifyCredential(vcJwt, didResolver ), + verifyCredential(vcJwt, didResolver), ), ) @@ -34,7 +31,7 @@ export class PayloadValidator implements DidJwtPayloadValidator { type: MessageTypes.vp, raw: verifiedJwt.jwt, issuer: verifiedJwt.payload.iss, - subject: verifiedJwt.payload.sub, + subject: verifiedJwt.payload.aud, time: verifiedJwt.payload.nbf || verifiedJwt.payload.iat, verified: verifiedJwt, custom: {