2019-07-03 13:18:07 +02:00
|
|
|
import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne, Index } from 'typeorm';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { User } from './user.js';
|
|
|
|
import { id } from '../id.js';
|
2019-07-03 13:18:07 +02:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
export class AttestationChallenge {
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@PrimaryColumn(id())
|
|
|
|
public userId: User['id'];
|
|
|
|
|
|
|
|
@ManyToOne(type => User, {
|
2021-12-09 15:58:30 +01:00
|
|
|
onDelete: 'CASCADE',
|
2019-07-03 13:18:07 +02:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public user: User | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
length: 64,
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'Hex-encoded sha256 hash of the challenge.',
|
2019-07-03 13:18:07 +02:00
|
|
|
})
|
|
|
|
public challenge: string;
|
|
|
|
|
|
|
|
@Column('timestamp with time zone', {
|
2021-12-09 15:58:30 +01:00
|
|
|
comment: 'The date challenge was created for expiry purposes.',
|
2019-07-03 13:18:07 +02:00
|
|
|
})
|
|
|
|
public createdAt: Date;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
comment:
|
|
|
|
'Indicates that the challenge is only for registration purposes if true to prevent the challenge for being used as authentication.',
|
2021-12-09 15:58:30 +01:00
|
|
|
default: false,
|
2019-07-03 13:18:07 +02:00
|
|
|
})
|
|
|
|
public registrationChallenge: boolean;
|
|
|
|
|
|
|
|
constructor(data: Partial<AttestationChallenge>) {
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(data)) {
|
|
|
|
(this as any)[k] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|