diff --git a/packages/daf-w3c/src/graphql.ts b/packages/daf-w3c/src/graphql.ts index 585560695..58e2f3626 100644 --- a/packages/daf-w3c/src/graphql.ts +++ b/packages/daf-w3c/src/graphql.ts @@ -1,6 +1,6 @@ import { Core } from 'daf-core' -import { ActionTypes, ActionSignW3cVc } from './action-handler' -import { PresentationPayload, VerifiableCredentialPayload, VC } from 'did-jwt-vc/src/types' +import { ActionTypes, ActionSignW3cVc, ActionSignW3cVp } from './action-handler' +import { PresentationPayload, VerifiableCredentialPayload, VC, VP } from 'did-jwt-vc/src/types' interface Context { core: Core @@ -14,6 +14,14 @@ interface VerifiableCredentialInput extends VerifiableCredentialPayload { vc: VCInput } +interface VPInput extends VP { + context: [string] +} + +interface VerifiablePresentationInput extends PresentationPayload { + vp: VPInput +} + const actionSignVc = async ( _: any, args: { @@ -23,6 +31,7 @@ const actionSignVc = async ( ctx: Context, ) => { const { data } = args + // This is needed because it is not possible to pass '@context' as gql input const payload: VerifiableCredentialPayload = { sub: data.sub, nbf: data.nbf, @@ -41,9 +50,37 @@ const actionSignVc = async ( } as ActionSignW3cVc) } +const actionSignVp = async ( + _: any, + args: { + did: string + data: VerifiablePresentationInput + }, + ctx: Context, +) => { + const { data } = args + // This is needed because it is not possible to pass '@context' as gql input + const payload: PresentationPayload = { + nbf: data.nbf, + jti: data.jti, + aud: data.aud, + vp: { + type: data.vp.type, + '@context': data.vp.context, + verifiableCredential: data.vp.verifiableCredential, + }, + } + return await ctx.core.handleAction({ + type: ActionTypes.signVp, + did: args.did, + data: payload, + } as ActionSignW3cVp) +} + export const resolvers = { Mutation: { actionSignVc, + actionSignVp, }, } @@ -62,10 +99,25 @@ export const typeDefs = ` aud: String exp: Int jti: String - vc: VC + vc: VC! + } + + input VP { + context: [String]! + type: [String]! + verifiableCredential: [String]! + } + + input VerifiablePresentationInput { + nbf: Int + aud: String + exp: Int + jti: String + vp: VP! } extend type Mutation { actionSignVc(did: String!, data: VerifiableCredentialInput!): String + actionSignVp(did: String!, data: VerifiablePresentationInput!): String } `