Skip to content

Commit

Permalink
feat: Added actionSignVp mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Nov 27, 2019
1 parent 46c5963 commit 7cedec1
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions packages/daf-w3c/src/graphql.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: {
Expand All @@ -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,
Expand All @@ -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,
},
}

Expand All @@ -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
}
`

0 comments on commit 7cedec1

Please sign in to comment.