Skip to content

Commit

Permalink
fix: VC / VP hash
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 6, 2020
1 parent f7e8b5b commit d4fa78f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 59 deletions.
37 changes: 14 additions & 23 deletions examples/send-vc/test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import {
Identity,
Key,
OMessage,
MessageMetaData,
Credential,
Presentation,
Claim,
Action,
Message,
} from 'daf-core'
import { Identity, Key, OMessage, MessageMetaData, Credential, Presentation, Claim } from 'daf-core'
import { core } from './setup'
import { createConnection, Like } from 'typeorm'

const main = async () => {
await createConnection({
// Sqlite
// "type": "sqlite",
// "database": "database.sqlite",
type: 'sqlite',
database: 'database.sqlite',

//Postgres
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'simonas',
password: '',
database: 'simonas',
// type: 'postgres',
// host: 'localhost',
// port: 5432,
// username: 'simonas',
// password: '',
// database: 'simonas',

synchronize: true,
logging: true,
entities: [Key, Identity, OMessage, MessageMetaData, Credential, Presentation, Claim, Action],
entities: [Key, Identity, OMessage, MessageMetaData, Credential, Presentation, Claim],
})

let identity1: Identity
Expand All @@ -53,9 +43,9 @@ const main = async () => {
vc.issuer = identity1
vc.subject = identity2
vc.issuedAt = new Date()
vc.raw = 'JWTvc2'
vc.context = ['https://www.w3.org/2018/credentials/v1323', 'https://www.w3.org/2020/demo/4342323']
vc.type = ['VerifiableCredential', 'PublicProfile']
vc.setRaw('JWTvc2')
vc.setCredentialSubject({
name: 'Jonas',
// profilePicture: 'https://simons.com/a.png',
Expand All @@ -72,13 +62,14 @@ const main = async () => {
vp.context = ['https://www.w3.org/2018/credentials/v1323']
vp.type = ['VerifiablePresentation', 'KYC']
vp.credentials = [vc]
vp.raw = 'JWTvp2'
vp.setRaw('JWTvp2')

const m = new OMessage()
m.id = 'aaaaaaabbb'
m.from = identity1
m.to = [identity2]
m.type = 'w3c.vp'
m.raw = 'JWTvp2'
m.raw = 'JWTvp3333'
m.presentations = [vp]
m.credentials = [vc]

Expand Down
23 changes: 0 additions & 23 deletions packages/daf-core/src/entities/action.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class Credential extends BaseEntity {
@PrimaryColumn()
hash: string

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

Expand Down
7 changes: 0 additions & 7 deletions packages/daf-core/src/entities/identity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Entity, Column, PrimaryColumn, BaseEntity, OneToMany, ManyToMany } from 'typeorm'
import { Key } from './key'
import { Action } from './action'
import { Message } from './message'
import { Presentation } from './presentation'
import { Credential } from './credential'
Expand All @@ -20,12 +19,6 @@ export class Identity extends BaseEntity {
)
keys: Key[]

@OneToMany(
type => Action,
action => action.identity,
)
actions: Action[]

@OneToMany(
type => Message,
message => message.from,
Expand Down
2 changes: 1 addition & 1 deletion packages/daf-core/src/entities/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Credential } from './credential'

@Entity()
export class Message extends BaseEntity {
@PrimaryGeneratedColumn()
@PrimaryGeneratedColumn('uuid')
id: string

@CreateDateColumn()
Expand Down
5 changes: 3 additions & 2 deletions packages/daf-core/src/entities/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export class Presentation extends BaseEntity {
@PrimaryColumn()
hash: string

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

@ManyToOne(
type => Identity,
identity => identity.issuedPresentations,
Expand Down
2 changes: 1 addition & 1 deletion packages/daf-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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 { Action } from './types'
export { Claim } from './entities/claim'
export { Credential } from './entities/credential'
export { Presentation } from './entities/presentation'

0 comments on commit d4fa78f

Please sign in to comment.