diff --git a/packages/daf-core/src/entities/action.ts b/packages/daf-core/src/entities/action.ts new file mode 100644 index 000000000..4532a9004 --- /dev/null +++ b/packages/daf-core/src/entities/action.ts @@ -0,0 +1,23 @@ +import { Entity, Column, BaseEntity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm' +import { Identity } from './identity' + +@Entity() +export class Action extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + type: string + + @ManyToOne( + type => Identity, + identity => identity.actions, + ) + identity: Identity + + @Column() + timestamp: number + + @Column() + data: string +} diff --git a/packages/daf-core/src/entities/claim.ts b/packages/daf-core/src/entities/claim.ts new file mode 100644 index 000000000..4efa9302c --- /dev/null +++ b/packages/daf-core/src/entities/claim.ts @@ -0,0 +1,45 @@ +import { + Entity, + Column, + BaseEntity, + ManyToOne, + JoinTable, + PrimaryGeneratedColumn, + OneToMany, + ManyToMany, +} from 'typeorm' +import { Identity } from './identity' +import { Credential } from './credential' + +@Entity() +export class Claim extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @ManyToOne( + type => Identity, + identity => identity.issuedPresentations, + ) + issuer: Identity + + @ManyToOne( + type => Identity, + identity => identity.receivedPresentations, + ) + subject: Identity + + @ManyToOne( + type => Credential, + credential => credential.claims, + ) + credential: Credential + + @Column() + type: string + + @Column() + value: string + + @Column() + isObj: boolean +} diff --git a/packages/daf-core/src/entities/credential-context.ts b/packages/daf-core/src/entities/credential-context.ts new file mode 100644 index 000000000..32312dc8e --- /dev/null +++ b/packages/daf-core/src/entities/credential-context.ts @@ -0,0 +1,10 @@ +import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm' + +@Entity() +export class CredentialContext extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + context: string +} diff --git a/packages/daf-core/src/entities/credential-type.ts b/packages/daf-core/src/entities/credential-type.ts new file mode 100644 index 000000000..0cf961fda --- /dev/null +++ b/packages/daf-core/src/entities/credential-type.ts @@ -0,0 +1,10 @@ +import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm' + +@Entity() +export class CredentialType extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + type: string +} diff --git a/packages/daf-core/src/entities/credential.ts b/packages/daf-core/src/entities/credential.ts new file mode 100644 index 000000000..125bee4cc --- /dev/null +++ b/packages/daf-core/src/entities/credential.ts @@ -0,0 +1,72 @@ +import { + Entity, + Column, + BaseEntity, + ManyToOne, + JoinTable, + PrimaryColumn, + OneToMany, + ManyToMany, +} from 'typeorm' +import { Identity } from './identity' +import { Message } from './message' +import { Presentation } from './presentation' +import { CredentialContext } from './credential-context' +import { CredentialType } from './credential-type' +import { Claim } from './claim' + +@Entity() +export class Credential extends BaseEntity { + @PrimaryColumn() + hash: string + + @ManyToOne( + type => Identity, + identity => identity.issuedCredentials, + ) + issuer: Identity + + @ManyToOne( + type => Identity, + identity => identity.receivedCredentials, + ) + subject: Identity + + @Column() + issuedAt: number + + @Column() + notBefore: number + + @Column() + expiresAt: number + + @Column() + raw: string + + @ManyToMany(type => CredentialContext) + @JoinTable() + context: CredentialContext[] + + @ManyToMany(type => CredentialType) + @JoinTable() + type: CredentialType[] + + @OneToMany( + type => Claim, + claim => claim.credential, + ) + claims: Claim[] + + @ManyToMany( + type => Presentation, + presentation => presentation.credentials, + ) + presentations: Presentation[] + + @ManyToMany( + type => Message, + message => message.presentations, + ) + messages: Message[] +} diff --git a/packages/daf-core/src/entities/identity.ts b/packages/daf-core/src/entities/identity.ts index 0abd88660..601c3e27f 100644 --- a/packages/daf-core/src/entities/identity.ts +++ b/packages/daf-core/src/entities/identity.ts @@ -1,5 +1,10 @@ import { Entity, Column, PrimaryColumn, BaseEntity, OneToMany } from 'typeorm' import { Key } from './key' +import { Action } from './action' +import { Message } from './message' +import { Presentation } from './presentation' +import { Credential } from './credential' +import { Claim } from './claim' @Entity() export class Identity extends BaseEntity { @@ -14,4 +19,58 @@ export class Identity extends BaseEntity { key => key.identity, ) keys: Key[] + + @OneToMany( + type => Action, + action => action.identity, + ) + actions: Action[] + + @OneToMany( + type => Message, + message => message.sender, + ) + sentMessages: Message[] + + @OneToMany( + type => Message, + message => message.receiver, + ) + receivedMessages: Message[] + + @OneToMany( + type => Presentation, + presentation => presentation.issuer, + ) + issuedPresentations: Presentation[] + + @OneToMany( + type => Presentation, + presentation => presentation.audience, + ) + receivedPresentations: Presentation[] + + @OneToMany( + type => Credential, + credential => credential.issuer, + ) + issuedCredentials: Credential[] + + @OneToMany( + type => Credential, + credential => credential.subject, + ) + receivedCredentials: Credential[] + + @OneToMany( + type => Claim, + claim => claim.issuer, + ) + issuedClaims: Claim[] + + @OneToMany( + type => Claim, + claim => claim.subject, + ) + receivedClaims: Claim[] } diff --git a/packages/daf-core/src/entities/message-meta-data.ts b/packages/daf-core/src/entities/message-meta-data.ts new file mode 100644 index 000000000..3174ef88b --- /dev/null +++ b/packages/daf-core/src/entities/message-meta-data.ts @@ -0,0 +1,23 @@ +import { Entity, Column, BaseEntity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm' +import { Message } from './message' + +@Entity() +export class MessageMetaData extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + type: string + + @Column() + value: string + + @ManyToOne( + type => Message, + message => message.metaData, + ) + message: Message + + @Column() + timestamp: number +} diff --git a/packages/daf-core/src/entities/message.ts b/packages/daf-core/src/entities/message.ts new file mode 100644 index 000000000..2d0da27d5 --- /dev/null +++ b/packages/daf-core/src/entities/message.ts @@ -0,0 +1,67 @@ +import { + Entity, + Column, + BaseEntity, + ManyToOne, + ManyToMany, + PrimaryGeneratedColumn, + OneToMany, + JoinTable, +} from 'typeorm' +import { Identity } from './identity' +import { MessageMetaData } from './message-meta-data' +import { Presentation } from './presentation' +import { Credential } from './credential' + +@Entity() +export class Message extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + threadId: string + + @Column() + type: string + + @ManyToOne( + type => Identity, + identity => identity.sentMessages, + ) + sender: Identity + + @ManyToOne( + type => Identity, + identity => identity.receivedMessages, + ) + receiver: Identity + + @Column() + timestamp: number + + @Column() + raw: string + + @Column() + data: string + + @OneToMany( + type => MessageMetaData, + messageMetaData => messageMetaData.message, + ) + metaData: MessageMetaData[] + + @ManyToMany( + type => Presentation, + presentation => presentation.messages, + ) + @JoinTable() + presentations: Presentation[] + + @ManyToMany( + type => Credential, + credential => credential.messages, + ) + @JoinTable() + credentials: Credential[] +} diff --git a/packages/daf-core/src/entities/presentation-context.ts b/packages/daf-core/src/entities/presentation-context.ts new file mode 100644 index 000000000..ecfa9da06 --- /dev/null +++ b/packages/daf-core/src/entities/presentation-context.ts @@ -0,0 +1,10 @@ +import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm' + +@Entity() +export class PresentationContext extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + context: string +} diff --git a/packages/daf-core/src/entities/presentation-type.ts b/packages/daf-core/src/entities/presentation-type.ts new file mode 100644 index 000000000..482ffb88e --- /dev/null +++ b/packages/daf-core/src/entities/presentation-type.ts @@ -0,0 +1,10 @@ +import { Entity, Column, PrimaryGeneratedColumn, BaseEntity } from 'typeorm' + +@Entity() +export class PresentationType extends BaseEntity { + @PrimaryGeneratedColumn() + id: string + + @Column() + type: string +} diff --git a/packages/daf-core/src/entities/presentation.ts b/packages/daf-core/src/entities/presentation.ts new file mode 100644 index 000000000..ca1632c9f --- /dev/null +++ b/packages/daf-core/src/entities/presentation.ts @@ -0,0 +1,66 @@ +import { + Entity, + Column, + BaseEntity, + ManyToOne, + JoinTable, + PrimaryColumn, + OneToMany, + ManyToMany, +} from 'typeorm' +import { Identity } from './identity' +import { Message } from './message' +import { PresentationContext } from './presentation-context' +import { PresentationType } from './presentation-type' +import { Credential } from './credential' + +@Entity() +export class Presentation extends BaseEntity { + @PrimaryColumn() + hash: string + + @ManyToOne( + type => Identity, + identity => identity.issuedPresentations, + ) + issuer: Identity + + @ManyToOne( + type => Identity, + identity => identity.receivedPresentations, + ) + audience: Identity + + @Column() + issuedAt: number + + @Column() + notBefore: number + + @Column() + expiresAt: number + + @Column() + raw: string + + @ManyToMany(type => PresentationContext) + @JoinTable() + context: PresentationContext[] + + @ManyToMany(type => PresentationType) + @JoinTable() + type: PresentationType[] + + @ManyToMany( + type => Credential, + credential => credential.presentations, + ) + @JoinTable() + credentials: Credential[] + + @ManyToMany( + type => Message, + message => message.presentations, + ) + messages: Message[] +} diff --git a/packages/daf-core/src/index.ts b/packages/daf-core/src/index.ts index f3359e85d..f10a54d41 100644 --- a/packages/daf-core/src/index.ts +++ b/packages/daf-core/src/index.ts @@ -15,7 +15,17 @@ export { AbstractMessageValidator } from './message/abstract-message-validator' export { Message } from './message/message' export { ServiceManager, LastMessageTimestampForInstance, ServiceEventTypes } from './service/service-manager' export { AbstractServiceController } from './service/abstract-service-controller' -export { Action } from './types' export { Gql } from './graphql/index' export { Key, KeyType } from './entities/key' export { Identity } from './entities/identity' +import { Message as OMessage } from './entities/message' +export { OMessage } +export { MessageMetaData } from './entities/message-meta-data' +export { Action } from './entities/action' +export { Claim } from './entities/claim' +export { Credential } from './entities/credential' +export { CredentialContext } from './entities/credential-context' +export { CredentialType } from './entities/credential-type' +export { Presentation } from './entities/presentation' +export { PresentationContext } from './entities/presentation-context' +export { PresentationType } from './entities/presentation-type'