organization.entity.ts 1.07 KB
Newer Older
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
1 2 3 4 5 6
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  OneToMany,
7
  Generated,
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
8
} from 'typeorm';
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
9
import { randomBytes } from 'crypto';
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
10 11 12
import { JolocomWallet } from '../connectors/jolocom/jolocom-wallet.entity';
import { CredentialVerifyRequest } from 'src/requests/credential-verify-request.entity';
import { CredentialIssueRequest } from 'src/requests/credential-issue-request.entity';
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26

const JWT_SECRET_BITS = 32;

@Entity()
export class Organization {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  sharedSecret: string;

27 28 29 30
  @Column()
  @Generated('uuid')
  uuid: string;

Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  @OneToOne(
    () => JolocomWallet,
    wallet => wallet.organization,
  )
  jolocomWallet: JolocomWallet;

  @OneToMany(
    () => CredentialVerifyRequest,
    request => request.requestor,
  )
  verifyRequests: CredentialVerifyRequest[];

  @OneToMany(
    () => CredentialIssueRequest,
    request => request.requestor,
  )
  issueRequests: CredentialIssueRequest[];

Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
49 50 51 52
  static randomSecret(): string {
    return randomBytes(JWT_SECRET_BITS).toString('hex');
  }
}