Skip to content

Commit

Permalink
Feat/oyd 01 (#209)
Browse files Browse the repository at this point in the history
* feat: Add event(log) system needed for notifications
* feat: VCI Holder signing
* feat: Add event manager support
  • Loading branch information
nklomp authored Jun 13, 2024
1 parent 5d2fa69 commit 170b81f
Show file tree
Hide file tree
Showing 67 changed files with 3,098 additions and 2,506 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
"@veramo/url-handler": "4.2.0",
"@sphereon/ssi-types": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/oid4vci-common": "0.10.4-next.25",
"@sphereon/oid4vci-client": "0.10.4-next.25",
"@sphereon/oid4vci-issuer": "0.10.4-next.25",
"@noble/hashes": "1.2.0",
"did-jwt": "6.11.6",
"did-jwt-vc": "3.1.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/contact-manager-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"dependencies": {
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.key-manager": "0.19.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.19.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.20.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.20.0",
"@sphereon/ssi-sdk.agent-config": "workspace:*",
"@sphereon/ssi-sdk.contact-manager": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerEntities } from '../index'
import { DataStoreEventLoggerMigrations } from '../migrations/generic'
import { ActionType, InitiatorType, LogLevel, PartyCorrelationType, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-sdk.core'
import { auditEventEntityFrom, AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
import { NonPersistedAuditLoggingEvent } from '../types'

Expand Down
12 changes: 2 additions & 10 deletions packages/data-store/src/__tests__/eventLogger.store.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerMigrations } from '../migrations/generic'
import { DataStoreEventLoggerEntities } from '../index'
import {
ActionType,
AuditLoggingEvent,
InitiatorType,
LogLevel,
PartyCorrelationType,
SubSystem,
System,
SystemCorrelationIdType,
} from '@sphereon/ssi-sdk.core'
import { AuditLoggingEvent, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { EventLoggerStore } from '../eventLogger/EventLoggerStore'
import { GetAuditEventsArgs, NonPersistedAuditLoggingEvent } from '../types'

Expand Down
4 changes: 2 additions & 2 deletions packages/data-store/src/entities/contact/ConnectionEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export class ConnectionEntity extends BaseEntity {
@Column('simple-enum', { name: 'type', enum: ConnectionType, nullable: false })
type!: ConnectionType

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@OneToOne(() => BaseConfigEntity, (config: OpenIdConfigEntity | DidAuthConfigEntity) => config.connection, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class CorrelationIdentifierEntity extends BaseEntity {
@IsNotEmpty({ message: 'Blank correlation ids are not allowed' })
correlationId!: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@OneToOne(() => IdentityEntity, (identity: IdentityEntity) => identity.identifier, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class DidAuthConfigEntity extends BaseConfigEntity {
@Column({ name: 'session_id', length: 255, nullable: false })
sessionId!: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export class ElectronicAddressEntity extends BaseEntity {
@Column({ name: 'partyId', nullable: true })
partyId?: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@CreateDateColumn({ name: 'created_at', nullable: false })
Expand Down
3 changes: 2 additions & 1 deletion packages/data-store/src/entities/contact/IMetadataEntity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface IMetadataEntity { // TODO move to types
interface IMetadataEntity {
// TODO move to types
label: string
stringValue?: string
numberValue?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class NaturalPersonEntity extends BaseContactEntity {
@IsNotEmpty({ message: 'Blank display names are not allowed' })
displayName!: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@BeforeInsert()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class OpenIdConfigEntity extends BaseConfigEntity {
@Column('text', { name: 'client_auth_method', nullable: false })
clientAuthMethod!: 'basic' | 'post' | undefined

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class OrganizationEntity extends BaseContactEntity {
@IsNotEmpty({ message: 'Blank display names are not allowed' })
displayName!: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@OneToOne(() => PartyEntity)
Expand Down
4 changes: 2 additions & 2 deletions packages/data-store/src/entities/contact/PartyEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export class PartyEntity extends BaseEntity {
@Column({ name: 'uri', length: 255, nullable: true })
uri?: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@OneToMany(() => IdentityEntity, (identity: IdentityEntity) => identity.party, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class PartyRelationshipEntity {
@Column({ name: 'right_id', nullable: false })
rightId!: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@CreateDateColumn({ name: 'created_at', nullable: false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export class PhysicalAddressEntity extends BaseEntity {
@Validate(IsNonEmptyStringConstraint, { message: 'Blank building names are not allowed' })
buildingName?: string

@Column({name: 'owner_id', nullable: true})
@Column({ name: 'owner_id', nullable: true })
ownerId?: string

@Column({name: 'tenant_id', nullable: true})
@Column({ name: 'tenant_id', nullable: true })
tenantId?: string

@ManyToOne(() => PartyEntity, (party: PartyEntity) => party.physicalAddresses, {
Expand Down
12 changes: 2 additions & 10 deletions packages/data-store/src/entities/eventLogger/AuditEventEntity.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { ActionSubType, ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import {
ActionType,
InitiatorType,
LogLevel,
PartyCorrelationType,
SubSystem,
System,
SystemCorrelationIdType,
ActionSubType,
} from '@sphereon/ssi-sdk.core'
import { PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { NonPersistedAuditLoggingEvent } from '../../types'

@Entity('AuditEvents')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DatabaseType, MigrationInterface, QueryRunner } from 'typeorm'
import Debug from 'debug'
import {CreateContacts1710438363001} from "../postgres/1710438363001-CreateContacts";
import {CreateContacts1710438363002} from "../sqlite/1710438363002-CreateContacts";
import { CreateContacts1710438363001 } from '../postgres/1710438363001-CreateContacts'
import { CreateContacts1710438363002 } from '../sqlite/1710438363002-CreateContacts'

const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:migrations')

Expand Down Expand Up @@ -31,7 +31,7 @@ export class CreateContacts1708525189000 implements MigrationInterface {
}
default:
return Promise.reject(
`Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
`Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
)
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ export class CreateContacts1708525189000 implements MigrationInterface {
}
default:
return Promise.reject(
`Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`
`Migrations are currently only supported for sqlite, react-native, expo and postgres. Was ${dbType}. Please run your database without migrations and with 'migrationsRun: false' and 'synchronize: true' for now`,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ export class CreateAuditEvents1701634812183 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TYPE "public"."Level_enum" AS ENUM('0', '1', '2', '3')`)
await queryRunner.query(
`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`
`CREATE TYPE "public"."System_enum" AS ENUM('general', 'kms', 'identity', 'oid4vci', 'credentials', 'web3', 'profile', 'contact')`,
)
await queryRunner.query(
`CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')`
`CREATE TYPE "public"."Subsystem_type_enum" AS ENUM('key', 'did_provider', 'did_resolver', 'oid4vp_op', 'oid4vci_client', 'siopv2_op', 'contact_manager', 'vc_issuer', 'vc_verifier', 'vc_persistence', 'transport', 'profile')`,
)
await queryRunner.query(`CREATE TYPE "public"."Action_type_enum" AS ENUM('create', 'read', 'update', 'delete', 'execute')`)
await queryRunner.query(`CREATE TYPE "public"."Initiator_type_enum" AS ENUM('user', 'system', 'external')`)
await queryRunner.query(`CREATE TYPE "public"."System_correlation_id_type_enum" AS ENUM('did', 'email', 'hostname', 'phone', 'user')`)
await queryRunner.query(`CREATE TYPE "public"."Party_correlation_type_enum" AS ENUM('did', 'email', 'hostname', 'phone')`)
await queryRunner.query(
`CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`
`CREATE TABLE "AuditEvents" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "timestamp" TIMESTAMP NOT NULL, "level" "public"."Level_enum" NOT NULL, "correlationId" TEXT NOT NULL, "system" "public"."System_enum" NOT NULL, "subSystemType" "public"."Subsystem_type_enum" NOT NULL, "actionType" "public"."Action_type_enum" NOT NULL, "actionSubType" TEXT NOT NULL, "initiatorType" "public"."Initiator_type_enum" NOT NULL, "systemCorrelationIdType" "public"."System_correlation_id_type_enum", "systemCorrelationId" TEXT, "systemAlias" TEXT, "partyCorrelationType" "public"."Party_correlation_type_enum", "partyCorrelationId" TEXT, "partyAlias" TEXT, "description" TEXT NOT NULL, "data" TEXT, "diagnosticData" TEXT, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_AuditEvents_id" PRIMARY KEY ("id"))`,
)
}

Expand Down
14 changes: 4 additions & 10 deletions packages/data-store/src/utils/contact/MappingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
Party,
PartyRelationship,
PartyType,
PhysicalAddress
PhysicalAddress,
} from '../../types'
import { PartyEntity } from '../../entities/contact/PartyEntity'
import { IdentityEntity } from '../../entities/contact/IdentityEntity'
Expand Down Expand Up @@ -240,9 +240,7 @@ export const identityEntityFrom = (entity: NonPersistedIdentity): IdentityEntity
identityEntity.identifier = correlationIdentifierEntityFrom(entity.identifier)
identityEntity.connection = entity.connection ? connectionEntityFrom(entity.connection) : undefined
identityEntity.metadata = entity.metadata
? entity.metadata
.map(identityMetadataItemEntityFrom)
.filter((entity): entity is IdentityMetadataItemEntity => entity !== undefined)
? entity.metadata.map(identityMetadataItemEntityFrom).filter((entity): entity is IdentityMetadataItemEntity => entity !== undefined)
: []
return identityEntity
}
Expand Down Expand Up @@ -343,9 +341,7 @@ export const naturalPersonEntityFrom = (naturalPerson: NonPersistedNaturalPerson
naturalPersonEntity.ownerId = naturalPerson.ownerId
naturalPersonEntity.tenantId = naturalPerson.tenantId
naturalPersonEntity.metadata = naturalPerson.metadata
? naturalPerson.metadata
.map(contactMetadataItemEntityFrom)
.filter((entity): entity is ContactMetadataItemEntity => entity !== undefined)
? naturalPerson.metadata.map(contactMetadataItemEntityFrom).filter((entity): entity is ContactMetadataItemEntity => entity !== undefined)
: []

return naturalPersonEntity
Expand Down Expand Up @@ -388,9 +384,7 @@ export const organizationEntityFrom = (organization: NonPersistedOrganization):
organizationEntity.ownerId = organization.ownerId
organizationEntity.tenantId = organization.tenantId
organizationEntity.metadata = organization.metadata
? organization.metadata
.map(contactMetadataItemEntityFrom)
.filter((entity): entity is ContactMetadataItemEntity => entity !== undefined)
? organization.metadata.map(contactMetadataItemEntityFrom).filter((entity): entity is ContactMetadataItemEntity => entity !== undefined)
: []

return organizationEntity
Expand Down
12 changes: 2 additions & 10 deletions packages/event-logger/__tests__/shared/eventLoggerAgentLogic.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { ActionType, InitiatorType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { TAgent } from '@veramo/core'
import {
ActionType,
AuditLoggingEvent,
InitiatorType,
LogLevel,
PartyCorrelationType,
SubSystem,
System,
SystemCorrelationIdType,
} from '@sphereon/ssi-sdk.core'
import { AuditLoggingEvent, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { GetAuditEventsArgs, IEventLogger, NonPersistedAuditLoggingEvent } from '../../src'

type ConfiguredAgent = TAgent<IEventLogger>
Expand Down
1 change: 1 addition & 0 deletions packages/event-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@sphereon/ssi-sdk.data-store": "workspace:*",
"@sphereon/ssi-types": "workspace:*",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 170b81f

Please sign in to comment.