Skip to content

Commit

Permalink
feat: added activity logs to eventlogger, plus fixed a bug on deletin…
Browse files Browse the repository at this point in the history
…g parent of child credentials
  • Loading branch information
sksadjad committed Oct 1, 2024
1 parent bcf36bf commit 91ce056
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 45 deletions.
79 changes: 77 additions & 2 deletions packages/data-store/src/__tests__/digitalCredential.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { DataStoreDigitalCredentialMigrations } from '../migrations'
import { CredentialRole, DataStoreDigitalCredentialEntities } from '../index'
import { DigitalCredentialStore } from '../digitalCredential/DigitalCredentialStore'
import {
AddCredentialArgs,
CredentialCorrelationType,
CredentialDocumentFormat,
CredentialStateType,
DocumentType,
DigitalCredential,
} from '../types/digitalCredential/digitalCredential'
import { AddCredentialArgs, GetCredentialsArgs, GetCredentialsResponse } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
GetCredentialsArgs,
GetCredentialsResponse,
} from '../types'
import { IVerifiablePresentation } from '@sphereon/ssi-types'
import { createHash } from 'crypto'

Expand Down Expand Up @@ -247,6 +249,79 @@ describe('Database entities tests', (): void => {
expect(result).toEqual(true)
})

it('should delete stored digital credential with children', async (): Promise<void> => {
const rawCredential: string =
'eyJraWQiOiJkaWQ6a2V5Ono2TWtyaGt5M3B1c20yNk1laUZhWFUzbjJuZWtyYW13RlVtZ0dyZUdHa0RWNnpRaiN6Nk1rcmhreTNwdXNtMjZNZWlGYVhVM24ybmVrcmFtd0ZVbWdHcmVHR2tEVjZ6UWoiLCJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vc3BoZXJlb24tb3BlbnNvdXJjZS5naXRodWIuaW8vc3NpLW1vYmlsZS13YWxsZXQvY29udGV4dC9zcGhlcmVvbi13YWxsZXQtaWRlbnRpdHktdjEuanNvbmxkIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJTcGhlcmVvbldhbGxldElkZW50aXR5Q3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJmaXJzdE5hbWUiOiJTIiwibGFzdE5hbWUiOiJLIiwiZW1haWxBZGRyZXNzIjoic0BrIn19LCJzdWIiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJqdGkiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJuYmYiOjE3MDg0NDA4MDgsImlzcyI6ImRpZDprZXk6ejZNa3Joa3kzcHVzbTI2TWVpRmFYVTNuMm5la3JhbXdGVW1nR3JlR0drRFY2elFqIn0.G0M84XVAxSmzGY-NQuB9NBofNrINSn6lvxW6761Vlq6ypvYgtc2xNdpiRmw8ryVNfnpzrr4Z5cB1RlrC05rJAw'
const digitalCredential1: AddCredentialArgs = {
rawDocument: rawCredential,
kmsKeyRef: 'testRef',
identifierMethod: 'did',
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
credentialRole: CredentialRole.VERIFIER,
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
}

const parentCredential: DigitalCredential = await digitalCredentialStore.addCredential(digitalCredential1)

const digitalCredential2: AddCredentialArgs = {
rawDocument:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksiLCJraWQiOiJkaWQ6dmVsb2NpdHk6djI6MHhjMTY3MTUxNmMyMTQ1ZDcwYjM0MGY1NjBhYjFjYjU4Y2M0ZDhhMDUyOjE2Mzc4Mj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NklqRXROSGhMWjBwUGRGVnJiM1puUmpWcWNVYzFObUp4YW1sblQwSlRNV0ZPT0VkQk4xRXlhRGxSUm1zaWZRIiwiaWF0IjoxNjY3ODU2NTY5fQ.-SiM5d7UrYn1gdj2hU5T5LnLQzhIklOtoexbyebLMeha0K89vkujsbFN4HNFP2TSfRYFt0-jXwDaZ8RNKESwFA',
parentId: parentCredential.id,
kmsKeyRef: 'testRef',
identifierMethod: 'did',
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z1Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
credentialRole: CredentialRole.VERIFIER,
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
}
const savedDigitalCredential2: DigitalCredential = await digitalCredentialStore.addCredential(digitalCredential2)
let deleteResult: boolean = await digitalCredentialStore.removeCredential({ id: parentCredential.id })
expect(deleteResult).toEqual(true)
await expect(() => digitalCredentialStore.getCredential({ id: savedDigitalCredential2.id })).rejects.toThrowError('No credential found for arg:')
})

it('should not delete stored parent digital credential if a child gets deleted', async (): Promise<void> => {
const rawCredential: string =
'eyJraWQiOiJkaWQ6a2V5Ono2TWtyaGt5M3B1c20yNk1laUZhWFUzbjJuZWtyYW13RlVtZ0dyZUdHa0RWNnpRaiN6Nk1rcmhreTNwdXNtMjZNZWlGYVhVM24ybmVrcmFtd0ZVbWdHcmVHR2tEVjZ6UWoiLCJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vc3BoZXJlb24tb3BlbnNvdXJjZS5naXRodWIuaW8vc3NpLW1vYmlsZS13YWxsZXQvY29udGV4dC9zcGhlcmVvbi13YWxsZXQtaWRlbnRpdHktdjEuanNvbmxkIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJTcGhlcmVvbldhbGxldElkZW50aXR5Q3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJmaXJzdE5hbWUiOiJTIiwibGFzdE5hbWUiOiJLIiwiZW1haWxBZGRyZXNzIjoic0BrIn19LCJzdWIiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJqdGkiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJuYmYiOjE3MDg0NDA4MDgsImlzcyI6ImRpZDprZXk6ejZNa3Joa3kzcHVzbTI2TWVpRmFYVTNuMm5la3JhbXdGVW1nR3JlR0drRFY2elFqIn0.G0M84XVAxSmzGY-NQuB9NBofNrINSn6lvxW6761Vlq6ypvYgtc2xNdpiRmw8ryVNfnpzrr4Z5cB1RlrC05rJAw'
const digitalCredential1: AddCredentialArgs = {
rawDocument: rawCredential,
kmsKeyRef: 'testRef',
identifierMethod: 'did',
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
credentialRole: CredentialRole.VERIFIER,
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
}

const parentCredential: DigitalCredential = await digitalCredentialStore.addCredential(digitalCredential1)

const digitalCredential2: AddCredentialArgs = {
rawDocument:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksiLCJraWQiOiJkaWQ6dmVsb2NpdHk6djI6MHhjMTY3MTUxNmMyMTQ1ZDcwYjM0MGY1NjB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Vd0V0xXczFPR0ZITUZJMFNYaHpJaXdpZVNJNklqRXROSGhMWjBwUGRGVnJiM1puUmpWcWNVYzFObUp4YW1sblQwSlRNV0ZPT0VkQk4xRXlhRGxSUm1zaWZRIiwiaWF0IjoxNjY3ODU2NTY5fQ.-SiM5d7UrYn1gdj2hU5T5LnLQzhIklOtoexbyebLMeha0K89vkujsbFN4HNFP2TSfRYFt0-jXwDaZ8RNKESwFA',
parentId: parentCredential.id,
kmsKeyRef: 'testRef',
identifierMethod: 'did',
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z1Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
credentialRole: CredentialRole.VERIFIER,
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
}
const savedDigitalCredential2: DigitalCredential = await digitalCredentialStore.addCredential(digitalCredential2)
let deleteResult: boolean = await digitalCredentialStore.removeCredential({ id: savedDigitalCredential2.id })
expect(deleteResult).toEqual(true)
const fetchedCredential: DigitalCredential = await digitalCredentialStore.getCredential({ id: parentCredential.id })
expect(fetchedCredential.id).toEqual(parentCredential.id)
})

it('should not delete stored digital credential if id not found', async (): Promise<void> => {
const result = await digitalCredentialStore.removeCredential({ id: 'unknown_id' })
expect(result).toEqual(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerEntities } from '../index'
import { DataStoreEventLoggerMigrations } from '../migrations/generic'
import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
import { AuditEventEntity, auditEventEntityFrom } from '../entities/eventLogger/AuditEventEntity'
import { NonPersistedAuditLoggingEvent } from '../types'

describe('Database entities tests', (): void => {
Expand All @@ -31,6 +31,7 @@ describe('Database entities tests', (): void => {

it('should save audit event to database', async (): Promise<void> => {
const auditEvent: NonPersistedAuditLoggingEvent = {
type: LoggingEventType.AUDIT,
timestamp: new Date(),
level: LogLevel.DEBUG,
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
Expand Down
5 changes: 4 additions & 1 deletion packages/data-store/src/__tests__/eventLogger.store.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerMigrations } from '../migrations'
import { DataStoreEventLoggerEntities } from '../index'
Expand Down Expand Up @@ -33,6 +33,7 @@ describe('Database entities tests', (): void => {

it('should store audit event', async (): Promise<void> => {
const auditEvent: NonPersistedAuditLoggingEvent = {
type: LoggingEventType.AUDIT,
timestamp: new Date(),
level: LogLevel.DEBUG,
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
Expand All @@ -58,6 +59,7 @@ describe('Database entities tests', (): void => {

it('should get all audit events', async (): Promise<void> => {
const auditEvent: NonPersistedAuditLoggingEvent = {
type: LoggingEventType.AUDIT,
timestamp: new Date(),
level: LogLevel.DEBUG,
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
Expand Down Expand Up @@ -89,6 +91,7 @@ describe('Database entities tests', (): void => {

it('should get audit events by filter', async (): Promise<void> => {
const auditEvent: NonPersistedAuditLoggingEvent = {
type: LoggingEventType.AUDIT,
timestamp: new Date(),
level: LogLevel.DEBUG,
correlationId: 'b40b8474-58a2-4b23-9fde-bd6ee1902cdb',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ export class DigitalCredentialStore extends AbstractDigitalCredentialStore {
let affected: number = 0
const findResult = await dcRepo.findBy(query)
for (const dc of findResult) {
if (dc.parentId !== null && dc.parentId !== undefined) {
affected += await this.deleteTree(dcRepo, { id: dc.parentId })
}
affected += await this.deleteTree(dcRepo, { parentId: dc.id })
const result = await dcRepo.delete(dc.id)
if (result.affected) {
affected += result.affected
Expand Down
53 changes: 50 additions & 3 deletions packages/data-store/src/entities/eventLogger/AuditEventEntity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ActionSubType, ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { ActionSubType, ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { NonPersistedAuditLoggingEvent } from '../../types'
import { CredentialType, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { NonPersistedAuditLoggingEvent, NonPersistedActivityLoggingEvent } from '../../types'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'

//TODO this entity, also contains some optional fields that are related to another event type (Activity) later we might want to refactor and reorganize this.
// For now I've added a discriminator value called eventType that can be one of the three types of events: 1. General, 2. Audit, and 3. Activity
@Entity('AuditEvents')
export class AuditEventEntity extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
Expand All @@ -12,6 +14,9 @@ export class AuditEventEntity extends BaseEntity {
@Column({ name: 'timestamp', nullable: false, unique: false, type: typeOrmDateTime() })
timestamp!: Date

@Column('simple-enum', { name: 'eventType', enum: LoggingEventType, nullable: false, unique: false })
type!: LoggingEventType

@Column('simple-enum', { name: 'level', enum: LogLevel, nullable: false, unique: false })
level!: LogLevel

Expand Down Expand Up @@ -54,6 +59,18 @@ export class AuditEventEntity extends BaseEntity {
@Column('text', { name: 'description', nullable: false, unique: false })
description!: string

@Column('simple-enum', { name: 'credentialType', enum: CredentialType, nullable: true, unique: false })
credentialType?: CredentialType

@Column('text', { name: 'credentialHash', nullable: true, unique: false })
credentialHash?: string

@Column('text', { name: 'originalCredential', nullable: true, unique: false })
originalCredential?: string

@Column('text', { name: 'sharePurpose', nullable: true, unique: false })
sharePurpose?: string

@Column('text', { name: 'data', nullable: true, unique: false })
data?: string

Expand All @@ -69,6 +86,7 @@ export class AuditEventEntity extends BaseEntity {

export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): AuditEventEntity => {
const auditEventEntity: AuditEventEntity = new AuditEventEntity()
auditEventEntity.type = LoggingEventType.AUDIT
auditEventEntity.timestamp = args.timestamp
auditEventEntity.level = args.level
auditEventEntity.correlationId = args.correlationId
Expand All @@ -90,3 +108,32 @@ export const auditEventEntityFrom = (args: NonPersistedAuditLoggingEvent): Audit

return auditEventEntity
}

export const activityEventEntityFrom = (args: NonPersistedActivityLoggingEvent): AuditEventEntity => {
const activityEventEntity: AuditEventEntity = new AuditEventEntity()
activityEventEntity.type = LoggingEventType.ACTIVITY
activityEventEntity.timestamp = args.timestamp
activityEventEntity.level = args.level
activityEventEntity.correlationId = args.correlationId
activityEventEntity.system = args.system
activityEventEntity.subSystemType = args.subSystemType
activityEventEntity.actionType = args.actionType
activityEventEntity.actionSubType = args.actionSubType
activityEventEntity.initiatorType = args.initiatorType
activityEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
activityEventEntity.systemCorrelationId = args.systemCorrelationId
activityEventEntity.systemAlias = args.systemAlias
activityEventEntity.partyCorrelationType = args.partyCorrelationType
activityEventEntity.partyCorrelationId = args.partyCorrelationId
activityEventEntity.partyAlias = args.partyAlias
activityEventEntity.description = args.description
activityEventEntity.partyCorrelationType = args.partyCorrelationType
activityEventEntity.data = JSON.stringify(args.data)
activityEventEntity.sharePurpose = args.sharePurpose
activityEventEntity.credentialType = args.credentialType
activityEventEntity.originalCredential = args.originalCredential
activityEventEntity.credentialHash = args.credentialHash
activityEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)

return activityEventEntity
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { GetAuditEventsArgs, StoreAuditEventArgs } from '../types'
import { AuditLoggingEvent } from '@sphereon/ssi-sdk.core'
import { GetAuditEventsArgs, StoreActivityEventArgs, StoreAuditEventArgs } from '../types'
import { ActivityLoggingEvent, AuditLoggingEvent } from '@sphereon/ssi-sdk.core'

export abstract class AbstractEventLoggerStore {
abstract getAuditEvents(args: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>>
abstract getActivityEvents(args: GetAuditEventsArgs): Promise<Array<AuditLoggingEvent>>
abstract storeAuditEvent(args: StoreAuditEventArgs): Promise<AuditLoggingEvent>
abstract storeActivityEvent(args: StoreActivityEventArgs): Promise<ActivityLoggingEvent>
}
Loading

0 comments on commit 91ce056

Please sign in to comment.