Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fixes/SPHEREON-118…
Browse files Browse the repository at this point in the history
…5_FIDS
  • Loading branch information
sanderPostma committed Nov 7, 2024
2 parents 8114196 + e02b30b commit 941c806
Show file tree
Hide file tree
Showing 55 changed files with 1,338 additions and 287 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ test/*.js
/packages/xstate-persistence/plugin.schema.json
/packages/credential-store/plugin.schema.json
/packages/pd-manager/plugin.schema.json
/packages/event-logger/plugin.schema.json
/packages/credential-validation/plugin.schema.json
/packages/oidf-client/plugin.schema.json

**/.env.energyshr
**/.env.local
/packages/web3-provider-headless/__tests__/config.json
/packages/event-logger/plugin.schema.json

/packages/public-key-hosting/__tests__/database/test.sqlite
/__tests__/database/test.sqlite

.nx/cache
.nx/workspace-data
63 changes: 59 additions & 4 deletions packages/data-store/src/__tests__/contact.store.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
import { DataSource } from 'typeorm'
import { DataStoreContactEntities, DataStoreMigrations, IdentityOrigin, MetadataItem, MetadataTypes, PartyOrigin } from '../index'
import {
ConnectionType,
DataStoreContactEntities,
DataStoreMigrations,
IdentityOrigin,
MetadataItem,
MetadataTypes,
PartyOrigin
} from '../index'
import { ContactStore } from '../contact/ContactStore'
import {
CorrelationIdentifierType,
Expand Down Expand Up @@ -367,6 +375,27 @@ describe('Contact store tests', (): void => {
correlationId: 'example_did3',
},
},
{
alias: 'test_alias4',
origin: IdentityOrigin.EXTERNAL,
roles: [CredentialRole.FEDERATION_TRUST_ANCHOR],
connection: {
type: ConnectionType.OPENID_CONNECT,
config: {
clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01',
clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0',
scopes: ['auth'],
issuer: 'https://example.com/app-test',
redirectUrl: 'app:/callback',
dangerouslyAllowInsecureHttpRequests: true,
clientAuthMethod: <const>'post',
},
},
identifier: {
type: CorrelationIdentifierType.URL,
correlationId: 'example_url4',
},
},
],
electronicAddresses: [
{
Expand All @@ -391,7 +420,7 @@ describe('Contact store tests', (): void => {
}
const result: Array<Party> = await contactStore.getParties(args)

expect(result[0].identities.length).toEqual(3)
expect(result[0].identities.length).toEqual(4)
expect(result[0].electronicAddresses.length).toEqual(1)
})

Expand Down Expand Up @@ -1208,15 +1237,41 @@ describe('Contact store tests', (): void => {
correlationId: 'example_did3',
},
},
{
alias: 'test_alias4',
origin: IdentityOrigin.EXTERNAL,
roles: [CredentialRole.FEDERATION_TRUST_ANCHOR],
connection: {
type: ConnectionType.OPENID_CONNECT,
config: {
clientId: '138d7bf8-c930-4c6e-b928-97d3a4928b01',
clientSecret: '03b3955f-d020-4f2a-8a27-4e452d4e27a0',
scopes: ['auth'],
issuer: 'https://example.com/app-test',
redirectUrl: 'app:/callback',
dangerouslyAllowInsecureHttpRequests: true,
clientAuthMethod: <const>'post',
},
},
identifier: {
type: CorrelationIdentifierType.URL,
correlationId: 'example_url4',
},
},
],
}

const savedParty: Party = await contactStore.addParty(party)
const result: Party = await contactStore.getParty({ partyId: savedParty.id })

expect(result.roles).toBeDefined()
expect(result.roles.length).toEqual(3)
expect(result.roles).toEqual([CredentialRole.VERIFIER, CredentialRole.ISSUER, CredentialRole.HOLDER])
expect(result.roles.length).toEqual(4)
expect(result.roles).toEqual([
CredentialRole.VERIFIER,
CredentialRole.ISSUER,
CredentialRole.HOLDER,
CredentialRole.FEDERATION_TRUST_ANCHOR
])
})

it('should add relationship', async (): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { DataSource } from 'typeorm'
import { CredentialRole, DataStoreDigitalCredentialEntities } from '../index'
import { DataStoreDigitalCredentialMigrations } from '../migrations'
import { DigitalCredentialEntity } from '../entities/digitalCredential/DigitalCredentialEntity'
import { computeEntryHash } from '@veramo/utils'
import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'
import { createHash } from 'crypto'
import {
AddCredentialArgs,
CredentialCorrelationType,
CredentialDocumentFormat,
DocumentType,
NonPersistedDigitalCredential,
} from '../types/digitalCredential/digitalCredential'
import { computeEntryHash } from '@veramo/utils'
import { AddCredentialArgs } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'
import { createHash } from 'crypto'
} from '../types'

describe('Database entities tests', (): void => {
let dbConnection: DataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
DocumentType,
DigitalCredential,
GetCredentialsArgs,
GetCredentialsResponse,
GetCredentialsResponse
} from '../types'

describe('Database entities tests', (): void => {
Expand Down
48 changes: 24 additions & 24 deletions packages/data-store/src/__tests__/eventLogger.entities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, Syste
import { DataSource } from 'typeorm'
import { DataStoreEventLoggerEntities } from '../index'
import { DataStoreEventLoggerMigrations } from '../migrations'
import {
activityEventEntityFrom,
auditEventEntityFrom,
AuditEventEntity
} from '../entities/eventLogger/AuditEventEntity'
import { AuditEventEntity } from '../entities/eventLogger/AuditEventEntity'
import { NonPersistedAuditLoggingEvent, NonPersistedActivityLoggingEvent } from '../types'
import { activityEventEntityFrom, auditEventEntityFrom } from '../utils/eventLogger/MappingUtils'

describe('Database entities tests', (): void => {
let dbConnection: DataSource
Expand Down Expand Up @@ -80,7 +77,7 @@ describe('Database entities tests', (): void => {
})

it('should save activity event to database', async (): Promise<void> => {
const auditEvent: NonPersistedActivityLoggingEvent = {
const activityEvent: NonPersistedActivityLoggingEvent = {
timestamp: new Date(),
level: LogLevel.DEBUG,
originalCredential: 'test_credential_string',
Expand All @@ -104,28 +101,31 @@ describe('Database entities tests', (): void => {
diagnosticData: { data: 'test_data_string' },
}

const activityEventEntity: AuditEventEntity = activityEventEntityFrom(auditEvent)
const activityEventEntity: AuditEventEntity = activityEventEntityFrom(activityEvent)
const fromDb: AuditEventEntity = await dbConnection.getRepository(AuditEventEntity).save(activityEventEntity)

expect(fromDb).toBeDefined()
expect(fromDb?.id).not.toBeNull()
expect(fromDb?.type).toEqual(LoggingEventType.ACTIVITY)
expect(fromDb?.timestamp).toEqual(auditEvent.timestamp)
expect(fromDb?.level).toEqual(auditEvent.level)
expect(fromDb?.correlationId).toEqual(auditEvent.correlationId)
expect(fromDb?.system).toEqual(auditEvent.system)
expect(fromDb?.subSystemType).toEqual(auditEvent.subSystemType)
expect(fromDb?.actionType).toEqual(auditEvent.actionType)
expect(fromDb?.actionSubType).toEqual(auditEvent.actionSubType)
expect(fromDb?.initiatorType).toEqual(auditEvent.initiatorType)
expect(fromDb?.systemCorrelationIdType).toEqual(auditEvent.systemCorrelationIdType)
expect(fromDb?.systemCorrelationId).toEqual(auditEvent.systemCorrelationId)
expect(fromDb?.systemAlias).toEqual(auditEvent.systemAlias)
expect(fromDb?.partyCorrelationType).toEqual(auditEvent.partyCorrelationType)
expect(fromDb?.partyCorrelationId).toEqual(auditEvent.partyCorrelationId)
expect(fromDb?.partyAlias).toEqual(auditEvent.partyAlias)
expect(fromDb?.description).toEqual(auditEvent.description)
expect(fromDb?.data).toEqual(JSON.stringify(auditEvent.data))
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(auditEvent.diagnosticData))
expect(fromDb?.timestamp).toEqual(activityEvent.timestamp)
expect(fromDb?.level).toEqual(activityEvent.level)
expect(fromDb?.correlationId).toEqual(activityEvent.correlationId)
expect(fromDb?.system).toEqual(activityEvent.system)
expect(fromDb?.subSystemType).toEqual(activityEvent.subSystemType)
expect(fromDb?.actionType).toEqual(activityEvent.actionType)
expect(fromDb?.actionSubType).toEqual(activityEvent.actionSubType)
expect(fromDb?.initiatorType).toEqual(activityEvent.initiatorType)
expect(fromDb?.systemCorrelationIdType).toEqual(activityEvent.systemCorrelationIdType)
expect(fromDb?.systemCorrelationId).toEqual(activityEvent.systemCorrelationId)
expect(fromDb?.systemAlias).toEqual(activityEvent.systemAlias)
expect(fromDb?.partyCorrelationType).toEqual(activityEvent.partyCorrelationType)
expect(fromDb?.partyCorrelationId).toEqual(activityEvent.partyCorrelationId)
expect(fromDb?.partyAlias).toEqual(activityEvent.partyAlias)
expect(fromDb?.description).toEqual(activityEvent.description)
expect(fromDb?.data).toEqual(JSON.stringify(activityEvent.data))
expect(fromDb?.diagnosticData).toEqual(JSON.stringify(activityEvent.diagnosticData))
expect(fromDb?.credentialHash).toEqual(activityEvent.credentialHash)
expect(fromDb?.parentCredentialHash).toEqual(activityEvent.parentCredentialHash)
expect(fromDb?.credentialType).toEqual(activityEvent.credentialType)
})
})

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { typeormDate, typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import {
CredentialCorrelationType,
Expand All @@ -8,7 +9,6 @@ import {
DocumentType,
RegulationType,
} from '../../types'
import { typeormDate, typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'

@Entity('DigitalCredential')
export class DigitalCredentialEntity extends BaseEntity implements DigitalCredential {
Expand Down
58 changes: 1 addition & 57 deletions packages/data-store/src/entities/eventLogger/AuditEventEntity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ActionSubType, ActionType, InitiatorType, LoggingEventType, LogLevel, SubSystem, System, SystemCorrelationIdType } from '@sphereon/ssi-types'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import { CredentialType, PartyCorrelationType } from '@sphereon/ssi-sdk.core'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { NonPersistedAuditLoggingEvent, NonPersistedActivityLoggingEvent } from '../../types'
import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'

//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
Expand Down Expand Up @@ -86,58 +85,3 @@ export class AuditEventEntity extends BaseEntity {
@UpdateDateColumn({ name: 'last_updated_at', nullable: false, type: typeOrmDateTime() })
lastUpdatedAt!: Date
}

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
auditEventEntity.system = args.system
auditEventEntity.subSystemType = args.subSystemType
auditEventEntity.actionType = args.actionType
auditEventEntity.actionSubType = args.actionSubType
auditEventEntity.initiatorType = args.initiatorType
auditEventEntity.systemCorrelationIdType = args.systemCorrelationIdType
auditEventEntity.systemCorrelationId = args.systemCorrelationId
auditEventEntity.systemAlias = args.systemAlias
auditEventEntity.partyCorrelationType = args.partyCorrelationType
auditEventEntity.partyCorrelationId = args.partyCorrelationId
auditEventEntity.partyAlias = args.partyAlias
auditEventEntity.description = args.description
auditEventEntity.partyCorrelationType = args.partyCorrelationType
auditEventEntity.data = JSON.stringify(args.data)
auditEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)

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.parentCredentialHash = args.parentCredentialHash
activityEventEntity.diagnosticData = JSON.stringify(args.diagnosticData)

return activityEventEntity
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BaseEntity, BeforeInsert, BeforeUpdate, Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm'
import { IBasicBackgroundAttributes } from '../../types'
import { ImageAttributesEntity, imageAttributesEntityFrom } from './ImageAttributesEntity'
import { ImageAttributesEntity } from './ImageAttributesEntity'
import { validate, Validate, ValidationError } from 'class-validator'
import { isEmptyString, IsNonEmptyStringConstraint } from '../validators'
import { IsNonEmptyStringConstraint } from '../validators'

@Entity('BackgroundAttributes')
export class BackgroundAttributesEntity extends BaseEntity {
Expand Down Expand Up @@ -32,11 +31,3 @@ export class BackgroundAttributesEntity extends BaseEntity {
return
}
}

export const backgroundAttributesEntityFrom = (args: IBasicBackgroundAttributes): BackgroundAttributesEntity => {
const backgroundAttributesEntity: BackgroundAttributesEntity = new BackgroundAttributesEntity()
backgroundAttributesEntity.color = isEmptyString(args.color) ? undefined : args.color
backgroundAttributesEntity.image = args.image ? imageAttributesEntityFrom(args.image) : undefined

return backgroundAttributesEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from 'typeorm'
import { ArrayMinSize, IsNotEmpty, validate, ValidationError } from 'class-validator'
import { typeOrmDateTime } from '@sphereon/ssi-sdk.agent-config'
import { CredentialLocaleBrandingEntity, credentialLocaleBrandingEntityFrom } from './CredentialLocaleBrandingEntity'
import { IBasicCredentialBranding, IBasicCredentialLocaleBranding } from '../../types'
import { CredentialLocaleBrandingEntity } from './CredentialLocaleBrandingEntity'

@Entity('CredentialBranding')
@Index('IDX_CredentialBrandingEntity_vcHash', ['vcHash'])
Expand Down Expand Up @@ -66,14 +65,3 @@ export class CredentialBrandingEntity extends BaseEntity {
return
}
}

export const credentialBrandingEntityFrom = (args: IBasicCredentialBranding): CredentialBrandingEntity => {
const credentialBrandingEntity: CredentialBrandingEntity = new CredentialBrandingEntity()
credentialBrandingEntity.issuerCorrelationId = args.issuerCorrelationId
credentialBrandingEntity.vcHash = args.vcHash
credentialBrandingEntity.localeBranding = args.localeBranding.map((localeBranding: IBasicCredentialLocaleBranding) =>
credentialLocaleBrandingEntityFrom(localeBranding),
)

return credentialBrandingEntity
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ChildEntity, Column, JoinColumn, ManyToOne, Index } from 'typeorm'
import { IBasicCredentialLocaleBranding } from '../../types'
import { backgroundAttributesEntityFrom } from './BackgroundAttributesEntity'
import { CredentialBrandingEntity } from './CredentialBrandingEntity'
import { imageAttributesEntityFrom } from './ImageAttributesEntity'
import { BaseLocaleBrandingEntity } from './BaseLocaleBrandingEntity'
import { textAttributesEntityFrom } from './TextAttributesEntity'
import { isEmptyString } from '../validators'

@ChildEntity('CredentialLocaleBranding')
@Index('IDX_CredentialLocaleBrandingEntity_credentialBranding_locale', ['credentialBranding', 'locale'], { unique: true })
Expand All @@ -19,15 +14,3 @@ export class CredentialLocaleBrandingEntity extends BaseLocaleBrandingEntity {
@Column('text', { name: 'credentialBrandingId', nullable: false })
credentialBrandingId!: string
}

export const credentialLocaleBrandingEntityFrom = (args: IBasicCredentialLocaleBranding): CredentialLocaleBrandingEntity => {
const credentialLocaleBrandingEntity: CredentialLocaleBrandingEntity = new CredentialLocaleBrandingEntity()
credentialLocaleBrandingEntity.alias = isEmptyString(args.alias) ? undefined : args.alias
credentialLocaleBrandingEntity.locale = args.locale ? args.locale : ''
credentialLocaleBrandingEntity.logo = args.logo ? imageAttributesEntityFrom(args.logo) : undefined
credentialLocaleBrandingEntity.description = isEmptyString(args.description) ? undefined : args.description
credentialLocaleBrandingEntity.background = args.background ? backgroundAttributesEntityFrom(args.background) : undefined
credentialLocaleBrandingEntity.text = args.text ? textAttributesEntityFrom(args.text) : undefined

return credentialLocaleBrandingEntity
}
Loading

0 comments on commit 941c806

Please sign in to comment.