Skip to content

Commit

Permalink
fix: W3C VP subject is aud
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Dec 2, 2019
1 parent f1439a8 commit 991e64b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 69 deletions.
81 changes: 18 additions & 63 deletions packages/daf-data-store/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -38,91 +35,50 @@ 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) => {
return dataStore.findMessages({ iss: identity.did, sub: identity.did })
},
},
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),
},
}

Expand Down Expand Up @@ -158,7 +114,6 @@ export const typeDefs = `
extend type Message {
iss: Identity!
sub: Identity
aud: Identity
jwt: String!
data: String!
iat: Int
Expand Down
9 changes: 3 additions & 6 deletions packages/daf-w3c/src/payload-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@ export const MessageTypes = {
}

export class PayloadValidator implements DidJwtPayloadValidator {
async validate(
verifiedJwt: any,
didResolver: Resolver,
): Promise<Types.PreValidatedMessage> {
async validate(verifiedJwt: any, didResolver: Resolver): Promise<Types.PreValidatedMessage> {
try {
validatePresentationAttributes(verifiedJwt.payload)

debug('JWT is', MessageTypes.vp)

const vc = await Promise.all(
verifiedJwt.payload.vp.verifiableCredential.map((vcJwt: string) =>
verifyCredential(vcJwt, didResolver ),
verifyCredential(vcJwt, didResolver),
),
)

return {
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: {
Expand Down

0 comments on commit 991e64b

Please sign in to comment.