Skip to content

Commit

Permalink
fix: Removing context entities
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 6, 2020
1 parent 134a812 commit 1a5c4c9
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 95 deletions.
82 changes: 47 additions & 35 deletions examples/send-vc/test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import {
Identity,
Key,
OMessage,
MessageMetaData,
Credential,
Presentation,
CredentialContext,
CredentialType,
PresentationContext,
PresentationType,
Claim,
Action,
} from 'daf-core'
import { Identity, Key, OMessage, MessageMetaData, Credential, Presentation, Claim, Action } from 'daf-core'
import { core } from './setup'
import { createConnection } from 'typeorm'
import { createConnection, Like } from 'typeorm'

const main = async () => {
await createConnection({
Expand All @@ -29,22 +16,9 @@ const main = async () => {
password: '',
database: 'simonas',

synchronize: false,
synchronize: true,
logging: true,
entities: [
Key,
Identity,
OMessage,
MessageMetaData,
Credential,
PresentationType,
PresentationContext,
Presentation,
CredentialType,
CredentialContext,
Claim,
Action,
],
entities: [Key, Identity, OMessage, MessageMetaData, Credential, Presentation, Claim, Action],
})

let identity1: Identity
Expand All @@ -59,12 +33,50 @@ const main = async () => {
identity2 = ((await core.identityManager.createIdentity(identityProviders[0].type)) as any) as Identity
}

console.log(identity1)
console.log(identity2)
// console.log(identity1)
// console.log(identity2)

const vc = new Credential()
vc.issuer = identity1
vc.subject = identity2
// const vc = new Credential()
// vc.issuer = identity1
// vc.subject = identity2
// vc.issuedAt = 1235456
// vc.notBefore = 1232424
// vc.expiresAt = 32423423
// vc.raw = '4123123123'
// vc.context = ['https://www.w3.org/2018/credentials/v1323', 'https://www.w3.org/2020/demo/4342323']
// vc.type = ['VerifiableCredential', 'PublicProfile']
// vc.setCredentialSubject({
// name: 'Simonas',
// profilePicture: 'https://simons.com/a.png',
// address: {
// street: 'some',
// house: 1
// }
// })

// try {
// await vc.save()
// } catch(e) {
// console.log(e.message)
// }

// console.log(vc)

// const res = await Claim.find({
// relations: ['issuer', 'subject', 'credential'],
// where: {
// issuer: identity1,
// type: 'name'
// }
// })

const res = await Credential.find({
where: {
type: Like('%Public%'),
},
})

console.dir(res, { depth: 10 })
}

main().catch(console.log)
1 change: 1 addition & 0 deletions packages/daf-core/src/entities/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PrimaryGeneratedColumn,
OneToMany,
ManyToMany,
BeforeInsert,
} from 'typeorm'
import { Identity } from './identity'
import { Credential } from './credential'
Expand Down
10 changes: 0 additions & 10 deletions packages/daf-core/src/entities/credential-context.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/daf-core/src/entities/credential-type.ts

This file was deleted.

45 changes: 37 additions & 8 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { blake2bHex } from 'blakejs'
import {
Entity,
Column,
Expand All @@ -7,19 +8,43 @@ import {
PrimaryColumn,
OneToMany,
ManyToMany,
BeforeInsert,
AfterInsert,
} 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

@BeforeInsert()
async updateHash() {
this.hash = blake2bHex(this.raw)
}

setCredentialSubject(credentialSubject: object) {
this.credentialSubject = credentialSubject
this.claims = []
for (const type in this.credentialSubject) {
if (this.credentialSubject.hasOwnProperty(type)) {
const value = this.credentialSubject[type]
const isObj = typeof value === 'function' || (typeof value === 'object' && !!value)
const claim = new Claim()
claim.type = type
claim.value = value
claim.isObj = isObj
claim.issuer = this.issuer
claim.subject = this.subject
claim.credential = this
this.claims.push(claim)
}
}
}

@ManyToOne(
type => Identity,
identity => identity.issuedCredentials,
Expand All @@ -44,17 +69,21 @@ export class Credential extends BaseEntity {
@Column()
raw: string

@ManyToMany(type => CredentialContext)
@JoinTable()
context: CredentialContext[]
@Column('simple-array')
context: string[]

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

@ManyToMany(type => CredentialType)
@JoinTable()
type: CredentialType[]
@Column('simple-json')
credentialSubject: object

@OneToMany(
type => Claim,
claim => claim.credential,
{
cascade: true,
},
)
claims: Claim[]

Expand Down
10 changes: 0 additions & 10 deletions packages/daf-core/src/entities/presentation-context.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/daf-core/src/entities/presentation-type.ts

This file was deleted.

10 changes: 2 additions & 8 deletions packages/daf-core/src/entities/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
} 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()
Expand Down Expand Up @@ -43,13 +41,9 @@ export class Presentation extends BaseEntity {
@Column()
raw: string

@ManyToMany(type => PresentationContext)
@JoinTable()
context: PresentationContext[]
context: string[]

@ManyToMany(type => PresentationType)
@JoinTable()
type: PresentationType[]
type: string[]

@ManyToMany(
type => Credential,
Expand Down
4 changes: 0 additions & 4 deletions packages/daf-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@ 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'

0 comments on commit 1a5c4c9

Please sign in to comment.