Skip to content

Commit

Permalink
feat: Added credentialType to the Claim
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 30, 2020
1 parent d940429 commit 45a4da2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
34 changes: 21 additions & 13 deletions packages/daf-core/src/entities/claim.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Entity,
Column,
BaseEntity,
ManyToOne,
PrimaryColumn,
} from 'typeorm'
import { Entity, Column, BaseEntity, ManyToOne, PrimaryColumn } from 'typeorm'
import { Identity } from './identity'
import { Credential } from './credential'

Expand All @@ -15,17 +9,19 @@ export class Claim extends BaseEntity {

@ManyToOne(
type => Identity,
identity => identity.issuedPresentations, {
eager: true
}
identity => identity.issuedPresentations,
{
eager: true,
},
)
issuer: Identity

@ManyToOne(
type => Identity,
identity => identity.receivedPresentations, {
eager: true
}
identity => identity.receivedPresentations,
{
eager: true,
},
)
subject: Identity

Expand All @@ -35,6 +31,18 @@ export class Claim extends BaseEntity {
)
credential: Credential

@Column()
issuanceDate: Date

@Column({ nullable: true })
expirationDate?: Date

@Column('simple-array')
context: string[]

@Column('simple-array')
credentialType: string[]

@Column()
type: string

Expand Down
24 changes: 11 additions & 13 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { blake2bHex } from 'blakejs'
import {
Entity,
Column,
BaseEntity,
ManyToOne,
PrimaryColumn,
OneToMany,
ManyToMany,
} from 'typeorm'
import { Entity, Column, BaseEntity, ManyToOne, PrimaryColumn, OneToMany, ManyToMany } from 'typeorm'
import { Identity } from './identity'
import { Message } from './message'
import { Presentation } from './presentation'
Expand Down Expand Up @@ -51,6 +43,10 @@ export class Credential extends BaseEntity {
claim.isObj = isObj
claim.issuer = this.issuer
claim.subject = this.subject
claim.expirationDate = this.expirationDate
claim.issuanceDate = this.issuanceDate
claim.credentialType = this.type
claim.context = this.context
this.claims.push(claim)
}
}
Expand All @@ -61,20 +57,22 @@ export class Credential extends BaseEntity {
identity => identity.issuedCredentials,
{
cascade: ['insert'],
eager: true
eager: true,
},
)
issuer: Identity

// Subject can be null https://w3c.github.io/vc-data-model/#credential-uniquely-identifies-a-subject
@ManyToOne(
type => Identity,
identity => identity.receivedCredentials,
{
cascade: ['insert'],
eager: true
eager: true,
nullable: true,
},
)
subject: Identity
subject?: Identity

@Column()
issuanceDate: Date
Expand Down Expand Up @@ -105,7 +103,7 @@ export class Credential extends BaseEntity {

@ManyToMany(
type => Message,
message => message.credentials
message => message.credentials,
)
messages: Message[]
}

0 comments on commit 45a4da2

Please sign in to comment.