Skip to content

Commit

Permalink
feat: Added actionSignVc mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Nov 25, 2019
1 parent 47cd3d3 commit 4ef9a15
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/daf-cli/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApolloServer } from 'apollo-server'
import program from 'commander'
import * as Daf from 'daf-core'
import * as W3c from 'daf-w3c'
import * as DIDComm from 'daf-did-comm'
import * as TG from 'daf-trust-graph'
import { Gql as DataGql } from 'daf-data-store'
import merge from 'lodash.merge'
import { core, dataStore } from './setup'
Expand All @@ -19,14 +19,14 @@ program
Daf.Gql.Core.typeDefs,
Daf.Gql.IdentityManager.typeDefs,
DataGql.typeDefs,
DIDComm.Gql.typeDefs,
TG.Gql.typeDefs,
W3c.Gql.typeDefs,
],
resolvers: merge(
Daf.Gql.Core.resolvers,
Daf.Gql.IdentityManager.resolvers,
DataGql.resolvers,
DIDComm.Gql.resolvers,
TG.Gql.resolvers,
W3c.Gql.resolvers,
),
context: () => ({ dataStore, core }),
Expand Down
37 changes: 37 additions & 0 deletions packages/daf-trust-graph/src/graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Core } from 'daf-core'
import { ActionTypes } from './action-handler'

interface Context {
core: Core
}

const actionSendJwt = async (
_: any,
args: {
from: string
to: string
jwt: string
},
ctx: Context,
) => {
return await ctx.core.handleAction({
type: ActionTypes.sendJwt,
data: {
from: args.from,
to: args.to,
jwt: args.jwt,
},
})
}

export const resolvers = {
Mutation: {
actionSendJwt,
},
}

export const typeDefs = `
extend type Mutation {
actionSendJwt(from: String!, to: String!, jwt: String!): Boolean
}
`
2 changes: 2 additions & 0 deletions packages/daf-trust-graph/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { TrustGraphServiceController } from './service-controller'
export { ActionHandler, ActionSendJWT, ActionTypes } from './action-handler'
import * as Gql from './graphql'
export { Gql }
54 changes: 45 additions & 9 deletions packages/daf-w3c/src/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import { Core } from 'daf-core'
import { ActionTypes } from './action-handler'
import { ActionTypes, ActionSignW3cVc } from './action-handler'
import { PresentationPayload, VerifiableCredentialPayload, VC } from 'did-jwt-vc/src/types'

interface Context {
core: Core
}

interface VCInput extends VC {
context: [string]
}

interface VerifiableCredentialInput extends VerifiableCredentialPayload {
vc: VCInput
}

const actionSignVc = async (
_: any,
args: {
from: string
to: string
did: string
data: VerifiableCredentialInput
},
ctx: Context,
) => {
const { data } = args
const payload: VerifiableCredentialPayload = {
sub: data.sub,
nbf: data.nbf,
jti: data.jti,
aud: data.aud,
vc: {
type: data.vc.type,
'@context': data.vc.context,
credentialSubject: data.vc.credentialSubject,
},
}
return await ctx.core.handleAction({
type: ActionTypes.signVc,
data: {
from: args.from,
to: args.to,
},
})
did: args.did,
data: payload,
} as ActionSignW3cVc)
}

export const resolvers = {
Expand All @@ -29,7 +48,24 @@ export const resolvers = {
}

export const typeDefs = `
scalar CredentialSubject
input VC {
context: [String]!
type: [String]!
credentialSubject: CredentialSubject!
}
input VerifiableCredentialInput {
sub: String!
nbf: Int
aud: String
exp: Int
jti: String
vc: VC
}
extend type Mutation {
actionSignVc(from: String!, to: String!): Boolean
actionSignVc(did: String!, data: VerifiableCredentialInput!): String
}
`

0 comments on commit 4ef9a15

Please sign in to comment.