credential-verify-request.entity.ts 1.06 KB
Newer Older
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  Generated,
  ManyToOne,
} from 'typeorm';
import { CredentialRequest } from './credential-request.interface';
import { Organization } from '../organizations/organization.entity';

export interface CredentialVerifyRequestData {
  iss: string;
  type: string;
  callbackUrl: string; // the REST api of the verifier where to deliver the credential data
}

@Entity()
export class CredentialVerifyRequest implements CredentialRequest {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  callbackUrl: string;

  @Column()
  type: string;

  @Column()
  @Generated('uuid')
  uuid: string;

  @ManyToOne(
    () => Organization,
    organization => organization.verifyRequests,
  )
  requestor: Organization;

38 39
  static requestType: 'credential-verify-request';

Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
40
  get requestId() {
41 42 43 44 45
    return `${CredentialVerifyRequest.requestType}:${this.uuid}`;
  }

  get iss() {
    return this.requestor?.uuid;
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
46 47 48 49 50 51 52 53 54 55
  }

  get verifier() {
    return this.requestor;
  }

  set verifier(verifier: Organization) {
    this.requestor = verifier;
  }
}