From e3dfc2f9a76fbe15ebb4cd2741d8ff580836408f Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Thu, 9 Apr 2020 15:46:15 +0300 Subject: [PATCH] feat: Agent dbConnection constructor option --- docs/Docs.md | 29 ++-- packages/daf-cli/src/cli.ts | 8 +- packages/daf-cli/src/setup.ts | 22 +-- packages/daf-core/src/agent.ts | 8 +- packages/daf-core/src/entities/identity.ts | 5 +- packages/daf-core/src/graphql/graphql-core.ts | 161 +++++++++++++----- .../daf-core/src/identity/identity-store.ts | 19 ++- packages/daf-core/src/identity/key-store.ts | 13 +- .../daf-selective-disclosure/src/graphql.ts | 15 +- .../daf-selective-disclosure/src/helper.ts | 10 +- packages/daf-w3c/src/action-handler.ts | 6 +- 11 files changed, 194 insertions(+), 102 deletions(-) diff --git a/docs/Docs.md b/docs/Docs.md index d35a7b2a2..159fb271b 100644 --- a/docs/Docs.md +++ b/docs/Docs.md @@ -7,12 +7,23 @@ DAF can be used by using Typescript API directly, or by using remote GraphQL api ## Typescript ```typescript +// Setting up the database connection +import { Entities } from 'daf-core' +import { createConnection } from 'typeorm' +// https://typeorm.io/#/connection-options +const dbConnection = createConnection({ + type: 'sqlite', + database: 'database.sqlite', + synchronize: true, + entities: [...Entities], +}) + // We will be using 'did:ethr' identities import { IdentityProvider } from 'daf-ethr-did' // Storing key pairs in the database import { KeyStore } from 'daf-core' -const keyStore = new KeyStore() +const keyStore = new KeyStore(dbConnection) // KeyManagementSystem is responsible for managing encryption and signing keys import { KeyManagementSystem } from 'daf-libsodium' @@ -20,7 +31,7 @@ const kms = new KeyManagementSystem(keyStore) // Storing managed identities in the database import { IdentityStore } from 'daf-core' -const identityStore = new IdentityStore('unique-store-name') +const identityStore = new IdentityStore('unique-store-name', dbConnection) // Infura is being used to access Ethereum blockchain. https://infura.io const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c' @@ -62,22 +73,12 @@ actionHandler.setNext(new SdrActionHandler()).setNext(new DIDCommActionHandler() import { Agent } from 'daf-core' // we need defaultIdentityProvider = 'rinkeby-ethr-did' const agent = new Agent({ + dbConnection, didResolver, identityProviders: [rinkebyIdentityProvider], actionHandler, messageHandler, }) - -// Setting up the database connection -import { Entities } from 'daf-core' -import { createConnection } from 'typeorm' -// https://typeorm.io/#/connection-options -await createConnection({ - type: 'sqlite', - database: 'database.sqlite', - synchronize: true, - entities: [...Entities], -}) ``` ## GraphQL Server @@ -368,7 +369,7 @@ query claims($input: ClaimsInput) { ```typescript import { findCredentialsForSdr } from 'daf-selective-disclosure' -const result = await findCredentialsForSdr(sdr, 'did:example:1234') +const result = await findCredentialsForSdr(agent.dbConnection, sdr, 'did:example:1234') console.log(result) ``` diff --git a/packages/daf-cli/src/cli.ts b/packages/daf-cli/src/cli.ts index d8a21526f..e83c0ccf0 100644 --- a/packages/daf-cli/src/cli.ts +++ b/packages/daf-cli/src/cli.ts @@ -7,15 +7,9 @@ import './data-explorer' import './graphql' import './sdr' import './msg' -import { initializeDb } from './setup' - -const main = async () => { - await initializeDb() - program.parse(process.argv) -} if (!process.argv.slice(2).length) { program.outputHelp() } else { - main().catch(e => console.log(e.message)) + program.parse(process.argv) } diff --git a/packages/daf-cli/src/setup.ts b/packages/daf-cli/src/setup.ts index b01098287..1cbfc8477 100644 --- a/packages/daf-cli/src/setup.ts +++ b/packages/daf-cli/src/setup.ts @@ -43,10 +43,18 @@ if (process.env.DAF_TG_URI) TrustGraphServiceController.defaultUri = process.env if (process.env.DAF_TG_WSURI) TrustGraphServiceController.defaultWsUri = process.env.DAF_TG_WSURI TrustGraphServiceController.webSocketImpl = ws +const dbConnection = createConnection({ + type: 'sqlite', + database: dataStoreFilename, + synchronize: true, + logging: process.env.DEBUG_DAF_DB ? true : false, + entities: [...Daf.Entities], +}) + const identityProviders = [ new EthrDid.IdentityProvider({ - identityStore: new Daf.IdentityStore('rinkeby-ethr'), - kms: new DafLibSodium.KeyManagementSystem(new Daf.KeyStore()), + identityStore: new Daf.IdentityStore('rinkeby-ethr', dbConnection), + kms: new DafLibSodium.KeyManagementSystem(new Daf.KeyStore(dbConnection)), network: 'rinkeby', rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId, }), @@ -67,6 +75,7 @@ actionHandler .setNext(new SdrActionHandler()) export const agent = new Daf.Agent({ + dbConnection, identityProviders, serviceControllers, didResolver, @@ -74,13 +83,4 @@ export const agent = new Daf.Agent({ actionHandler, }) -export const initializeDb = async () => { - await createConnection({ - type: 'sqlite', - database: dataStoreFilename, - synchronize: true, - logging: process.env.DEBUG_DAF_DB ? true : false, - entities: [...Daf.Entities], - }) -} export const dataStore = new DataStore() diff --git a/packages/daf-core/src/agent.ts b/packages/daf-core/src/agent.ts index 6ff5c2f6c..8c9d0f087 100644 --- a/packages/daf-core/src/agent.ts +++ b/packages/daf-core/src/agent.ts @@ -4,10 +4,11 @@ import { IdentityManager } from './identity/identity-manager' import { AbstractIdentityProvider } from './identity/abstract-identity-provider' import { ServiceManager, LastMessageTimestampForInstance, ServiceEventTypes } from './service/service-manager' import { ServiceControllerDerived } from './service/abstract-service-controller' -import { MessageHandler, unsupportedMessageTypeError } from './message/abstract-message-handler' +import { MessageHandler } from './message/abstract-message-handler' import { ActionHandler } from './action/action-handler' import { Action } from './types' import { Message, MetaData } from './entities/message' +import { Connection } from 'typeorm' import Debug from 'debug' const debug = Debug('daf:agent') @@ -23,6 +24,7 @@ export interface Resolver { } interface Config { + dbConnection?: Promise didResolver: Resolver identityProviders: AbstractIdentityProvider[] serviceControllers?: ServiceControllerDerived[] @@ -31,6 +33,7 @@ interface Config { } export class Agent extends EventEmitter { + readonly dbConnection: Promise public identityManager: IdentityManager public didResolver: Resolver private serviceManager: ServiceManager @@ -39,6 +42,7 @@ export class Agent extends EventEmitter { constructor(config: Config) { super() + this.dbConnection = config.dbConnection || null this.identityManager = new IdentityManager({ identityProviders: config.identityProviders, @@ -110,7 +114,7 @@ export class Agent extends EventEmitter { debug('Validated message %o', message) if (save) { - await message.save() + await (await this.dbConnection).getRepository(Message).save(message) debug('Emitting event', EventTypes.savedMessage) this.emit(EventTypes.savedMessage, message) } diff --git a/packages/daf-core/src/entities/identity.ts b/packages/daf-core/src/entities/identity.ts index 1ead0dbc2..b75a1e756 100644 --- a/packages/daf-core/src/entities/identity.ts +++ b/packages/daf-core/src/entities/identity.ts @@ -4,6 +4,7 @@ import { Message } from './message' import { Presentation } from './presentation' import { Credential } from './credential' import { Claim } from './claim' +import { Connection } from 'typeorm' @Entity() export class Identity extends BaseEntity { @@ -77,8 +78,8 @@ export class Identity extends BaseEntity { * * @param where */ - async getLatestClaimValue(where: { type: string }): Promise { - const claim = await Claim.findOne({ + async getLatestClaimValue(dbConnection: Promise, where: { type: string }): Promise { + const claim = await (await dbConnection).getRepository(Claim).findOne({ where: { ...where, subject: this.did, diff --git a/packages/daf-core/src/graphql/graphql-core.ts b/packages/daf-core/src/graphql/graphql-core.ts index ed0d75360..5ededa384 100644 --- a/packages/daf-core/src/graphql/graphql-core.ts +++ b/packages/daf-core/src/graphql/graphql-core.ts @@ -28,6 +28,7 @@ const messages = async ( threadId?: string[] } }, + ctx: Context, ) => { const options = { where: {}, @@ -40,7 +41,7 @@ const messages = async ( if (input?.options?.skip) options['skip'] = input.options.skip if (input?.options?.take) options['take'] = input.options.take - return Message.find(options) + return (await ctx.agent.dbConnection).getRepository(Message).find(options) } const presentations = async ( @@ -56,6 +57,7 @@ const presentations = async ( context?: string[] } }, + ctx: Context, ) => { const options = { where: {}, @@ -68,7 +70,7 @@ const presentations = async ( if (input?.options?.skip) options['skip'] = input.options.skip if (input?.options?.take) options['take'] = input.options.take - return Presentation.find(options) + return (await ctx.agent.dbConnection).getRepository(Presentation).find(options) } const credentials = async ( @@ -84,6 +86,7 @@ const credentials = async ( context?: string[] } }, + ctx: Context, ) => { const options = { where: {}, @@ -96,7 +99,7 @@ const credentials = async ( if (input?.options?.skip) options['skip'] = input.options.skip if (input?.options?.take) options['take'] = input.options.take - return Credential.find(options) + return (await ctx.agent.dbConnection).getRepository(Credential).find(options) } const claims = async ( @@ -112,6 +115,7 @@ const claims = async ( value?: string[] } }, + ctx: Context, ) => { const options = { relations: ['credential'], @@ -125,7 +129,7 @@ const claims = async ( if (input?.options?.skip) options['skip'] = input.options.skip if (input?.options?.take) options['take'] = input.options.take - return Claim.find(options) + return (await ctx.agent.dbConnection).getRepository(Claim).find(options) } export const resolvers = { @@ -138,63 +142,134 @@ export const resolvers = { }, Query: { - identity: async (_: any, { did }) => Identity.findOne(did), - identities: async (_: any, { input }) => Identity.find({ ...input?.options }), - message: async (_: any, { id }) => Message.findOne(id), + identity: async (_: any, { did }, ctx: Context) => + (await ctx.agent.dbConnection).getRepository(Identity).findOne(did), + identities: async (_: any, { input }, ctx: Context) => + (await ctx.agent.dbConnection).getRepository(Identity).find({ ...input?.options }), + message: async (_: any, { id }, ctx: Context) => + (await ctx.agent.dbConnection).getRepository(Message).findOne(id), messages, - presentation: async (_: any, { hash }) => Presentation.findOne(hash), + presentation: async (_: any, { hash }, ctx: Context) => + (await ctx.agent.dbConnection).getRepository(Presentation).findOne(hash), presentations, - credential: async (_: any, { hash }) => Credential.findOne(hash), + credential: async (_: any, { hash }, ctx: Context) => + (await ctx.agent.dbConnection).getRepository(Credential).findOne(hash), credentials, - claim: async (_: any, { hash }) => Claim.findOne(hash, { relations: ['credential'] }), + claim: async (_: any, { hash }, ctx: Context) => + (await ctx.agent.dbConnection).getRepository(Claim).findOne(hash, { relations: ['credential'] }), claims, }, Identity: { - shortDid: async (identity: Identity) => (await Identity.findOne(identity.did)).shortDid(), - latestClaimValue: async (identity: Identity, args: { type: string }) => - (await Identity.findOne(identity.did)).getLatestClaimValue({ type: args.type }), - sentMessages: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['sentMessages'] })).sentMessages, - receivedMessages: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['receivedMessages'] })).receivedMessages, - issuedPresentations: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['issuedPresentations'] })).issuedPresentations, - receivedPresentations: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['receivedPresentations'] })).receivedPresentations, - issuedCredentials: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['issuedCredentials'] })).issuedCredentials, - receivedCredentials: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['receivedCredentials'] })).receivedCredentials, - issuedClaims: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['issuedClaims'] })).issuedClaims, - receivedClaims: async (identity: Identity) => - (await Identity.findOne(identity.did, { relations: ['receivedClaims'] })).receivedClaims, + shortDid: async (identity: Identity, args, ctx: Context) => + (await (await ctx.agent.dbConnection).getRepository(Identity).findOne(identity.did)).shortDid(), + latestClaimValue: async (identity: Identity, args: { type: string }, ctx: Context) => + ( + await (await ctx.agent.dbConnection).getRepository(Identity).findOne(identity.did) + ).getLatestClaimValue(ctx.agent.dbConnection, { type: args.type }), + sentMessages: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['sentMessages'] }) + ).sentMessages, + receivedMessages: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['receivedMessages'] }) + ).receivedMessages, + issuedPresentations: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['issuedPresentations'] }) + ).issuedPresentations, + receivedPresentations: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['receivedPresentations'] }) + ).receivedPresentations, + issuedCredentials: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['issuedCredentials'] }) + ).issuedCredentials, + receivedCredentials: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['receivedCredentials'] }) + ).receivedCredentials, + issuedClaims: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['issuedClaims'] }) + ).issuedClaims, + receivedClaims: async (identity: Identity, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Identity) + .findOne(identity.did, { relations: ['receivedClaims'] }) + ).receivedClaims, }, Credential: { - claims: async (credential: Credential) => - credential.claims || (await Credential.findOne(credential.hash, { relations: ['claims'] })).claims, - messages: async (credential: Credential) => - (await Credential.findOne(credential.hash, { relations: ['messages'] })).messages, - presentations: async (credential: Credential) => - (await Credential.findOne(credential.hash, { relations: ['presentations'] })).presentations, + claims: async (credential: Credential, args, ctx: Context) => + credential.claims || + ( + await (await ctx.agent.dbConnection) + .getRepository(Credential) + .findOne(credential.hash, { relations: ['claims'] }) + ).claims, + messages: async (credential: Credential, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Credential) + .findOne(credential.hash, { relations: ['messages'] }) + ).messages, + presentations: async (credential: Credential, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Credential) + .findOne(credential.hash, { relations: ['presentations'] }) + ).presentations, }, Presentation: { - credentials: async (presentation: Presentation) => + credentials: async (presentation: Presentation, args, ctx: Context) => presentation.credentials || - (await Presentation.findOne(presentation.hash, { relations: ['credentials'] })).credentials, - messages: async (presentation: Presentation) => - (await Presentation.findOne(presentation.hash, { relations: ['messages'] })).messages, + ( + await (await ctx.agent.dbConnection) + .getRepository(Presentation) + .findOne(presentation.hash, { relations: ['credentials'] }) + ).credentials, + messages: async (presentation: Presentation, args, ctx: Context) => + ( + await (await ctx.agent.dbConnection) + .getRepository(Presentation) + .findOne(presentation.hash, { relations: ['messages'] }) + ).messages, }, Message: { - presentations: async (message: Message) => + presentations: async (message: Message, args, ctx: Context) => message.presentations || - (await Message.findOne(message.id, { relations: ['presentations'] })).presentations, - credentials: async (message: Message) => - message.credentials || (await Message.findOne(message.id, { relations: ['credentials'] })).credentials, + ( + await (await ctx.agent.dbConnection) + .getRepository(Message) + .findOne(message.id, { relations: ['presentations'] }) + ).presentations, + credentials: async (message: Message, args, ctx: Context) => + message.credentials || + ( + await (await ctx.agent.dbConnection) + .getRepository(Message) + .findOne(message.id, { relations: ['credentials'] }) + ).credentials, }, } diff --git a/packages/daf-core/src/identity/identity-store.ts b/packages/daf-core/src/identity/identity-store.ts index 42d3fbdfe..c374c8ece 100644 --- a/packages/daf-core/src/identity/identity-store.ts +++ b/packages/daf-core/src/identity/identity-store.ts @@ -1,6 +1,7 @@ import { AbstractIdentityStore, SerializedIdentity } from '../identity/abstract-identity-store' import { Identity } from '../entities/identity' import { Key } from '../entities/key' +import { Connection } from 'typeorm' import Debug from 'debug' const debug = Debug('daf:identity-store') @@ -9,8 +10,9 @@ export class IdentityStore extends AbstractIdentityStore { /** * * @param provider Can be any string. It will be saved next to the Identity + * @param dbConnection Promise that resolves to Typeorm database Connection */ - constructor(private provider: string) { + constructor(private provider: string, private dbConnection: Promise) { super() } @@ -19,7 +21,9 @@ export class IdentityStore extends AbstractIdentityStore { * @param did DID address. String */ async get(did: string) { - const identity = await Identity.findOne(did, { relations: ['keys'] }) + const identity = await (await this.dbConnection) + .getRepository(Identity) + .findOne(did, { relations: ['keys'] }) if (!identity) throw Error('Identity not found') return identity } @@ -29,10 +33,11 @@ export class IdentityStore extends AbstractIdentityStore { * @param did DID address. String */ async delete(did: string) { - const identity = await Identity.findOne(did) + const identity = await (await this.dbConnection).getRepository(Identity).findOne(did) if (!identity) throw Error('Identity not found') debug('Deleting', did) - await identity.remove() + await (await this.dbConnection).getRepository(Identity).remove(identity) + return true } @@ -53,7 +58,7 @@ export class IdentityStore extends AbstractIdentityStore { key.kid = sKey.kid identity.keys.push(key) } - await identity.save() + await (await this.dbConnection).getRepository(Identity).save(identity) debug('Saving', did) return true @@ -63,7 +68,9 @@ export class IdentityStore extends AbstractIdentityStore { * List dids */ async listDids() { - const identities = await Identity.find({ where: { provider: this.provider } }) + const identities = await (await this.dbConnection) + .getRepository(Identity) + .find({ where: { provider: this.provider } }) return identities.map(identity => identity.did) } } diff --git a/packages/daf-core/src/identity/key-store.ts b/packages/daf-core/src/identity/key-store.ts index 8cda43973..b84a187db 100644 --- a/packages/daf-core/src/identity/key-store.ts +++ b/packages/daf-core/src/identity/key-store.ts @@ -1,5 +1,6 @@ import { SerializedKey } from './abstract-key-management-system' import { AbstractKeyStore } from './abstract-key-store' +import { Connection } from 'typeorm' import { Key } from '../entities/key' @@ -7,17 +8,21 @@ import Debug from 'debug' const debug = Debug('daf:key-store') export class KeyStore extends AbstractKeyStore { + constructor(private dbConnection: Promise) { + super() + } + async get(kid: string) { - const key = await Key.findOne(kid) + const key = await (await this.dbConnection).getRepository(Key).findOne(kid) if (!key) throw Error('Key not found') return key } async delete(kid: string) { - const key = await Key.findOne(kid) + const key = await (await this.dbConnection).getRepository(Key).findOne(kid) if (!key) throw Error('Key not found') debug('Deleting key', kid) - await key.remove() + await (await this.dbConnection).getRepository(Key).remove(key) return true } @@ -28,7 +33,7 @@ export class KeyStore extends AbstractKeyStore { key.publicKeyHex = serializedKey.publicKeyHex key.type = serializedKey.type debug('Saving key', kid) - await key.save() + await (await this.dbConnection).getRepository(Key).save(key) return true } } diff --git a/packages/daf-selective-disclosure/src/graphql.ts b/packages/daf-selective-disclosure/src/graphql.ts index bfb89401b..0e50d1110 100644 --- a/packages/daf-selective-disclosure/src/graphql.ts +++ b/packages/daf-selective-disclosure/src/graphql.ts @@ -1,12 +1,10 @@ import { Agent, Message, Presentation } from 'daf-core' -import { DataStore } from 'daf-data-store' import { ActionTypes, ActionSignSdr, SelectiveDisclosureRequest } from './action-handler' import { findCredentialsForSdr, validatePresentationAgainstSdr } from './helper' import { MessageTypes } from './message-handler' interface Context { agent: Agent - dataStore: DataStore } const signSdrJwt = async (_: any, args: { data: SelectiveDisclosureRequest }, ctx: Context) => @@ -15,9 +13,9 @@ const signSdrJwt = async (_: any, args: { data: SelectiveDisclosureRequest }, ct data: args.data, } as ActionSignSdr) -const sdr = async (message: Message, { did }: { did: string }) => { +const sdr = async (message: Message, { did }: { did: string }, ctx: Context) => { if (message.type == MessageTypes.sdr) { - return findCredentialsForSdr(message.data, did) + return findCredentialsForSdr(ctx.agent.dbConnection, message.data, did) } return [] } @@ -25,10 +23,13 @@ const sdr = async (message: Message, { did }: { did: string }) => { const validateAgainstSdr = async ( presentation: Presentation, { sdr }: { sdr: SelectiveDisclosureRequest }, + ctx: Context, ) => { - const fullPresentation = await Presentation.findOne(presentation.hash, { - relations: ['credentials', 'credentials.claims'], - }) + const fullPresentation = await (await ctx.agent.dbConnection) + .getRepository(Presentation) + .findOne(presentation.hash, { + relations: ['credentials', 'credentials.claims'], + }) return validatePresentationAgainstSdr(fullPresentation, sdr) } diff --git a/packages/daf-selective-disclosure/src/helper.ts b/packages/daf-selective-disclosure/src/helper.ts index 964f8de6f..43baa266c 100644 --- a/packages/daf-selective-disclosure/src/helper.ts +++ b/packages/daf-selective-disclosure/src/helper.ts @@ -1,8 +1,12 @@ import { Claim, Presentation } from 'daf-core' import { SelectiveDisclosureRequest } from './action-handler' -import { In, Like } from 'typeorm' +import { In, Like, Connection } from 'typeorm' -export const findCredentialsForSdr = async (sdr: SelectiveDisclosureRequest, did?: string) => { +export const findCredentialsForSdr = async ( + dbConnection: Promise, + sdr: SelectiveDisclosureRequest, + did?: string, +) => { const result = [] for (const credentialRequest of sdr.claims) { const where = {} @@ -30,7 +34,7 @@ export const findCredentialsForSdr = async (sdr: SelectiveDisclosureRequest, did where['subject'] = did || sdr.subject } - const claims = await Claim.find({ where, relations: ['credential'] }) + const claims = await (await dbConnection).getRepository(Claim).find({ where, relations: ['credential'] }) result.push({ ...credentialRequest, credentials: claims.map(c => c.credential), diff --git a/packages/daf-w3c/src/action-handler.ts b/packages/daf-w3c/src/action-handler.ts index 756f9f339..d7906db2c 100644 --- a/packages/daf-w3c/src/action-handler.ts +++ b/packages/daf-w3c/src/action-handler.ts @@ -1,4 +1,4 @@ -import { Agent, AbstractActionHandler, Action, Credential } from 'daf-core' +import { Agent, AbstractActionHandler, Action, Credential, Presentation } from 'daf-core' import { createVerifiableCredential, createPresentation as createVerifiablePresentation, @@ -51,7 +51,7 @@ export class W3cActionHandler extends AbstractActionHandler { const decoded = decodeJWT(jwt) const presentation = createPresentation(decoded.payload as PresentationPayload, jwt, credentials) if (save) { - await presentation.save() + await (await agent.dbConnection).getRepository(Presentation).save(presentation) } return presentation } catch (error) { @@ -72,7 +72,7 @@ export class W3cActionHandler extends AbstractActionHandler { const decoded = decodeJWT(jwt) const credential = createCredential(decoded.payload as VerifiableCredentialPayload, jwt) if (save) { - await credential.save() + await (await agent.dbConnection).getRepository(Credential).save(credential) } return credential } catch (error) {