summaryrefslogtreecommitdiff
path: root/packages/backend/src/models/entities/UserSecurityKey.ts
blob: 368d03c16845cc4e203b29c2b0cfcc9dab88523e (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * SPDX-FileCopyrightText: syuilo and other misskey contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne, Index } from 'typeorm';
import { id } from '../id.js';
import { User } from './User.js';

@Entity()
export class UserSecurityKey {
	@PrimaryColumn('varchar', {
		comment: 'Variable-length id given to navigator.credentials.get()',
	})
	public id: string;

	@Index()
	@Column(id())
	public userId: User['id'];

	@ManyToOne(type => User, {
		onDelete: 'CASCADE',
	})
	@JoinColumn()
	public user: User | null;

	@Index()
	@Column('varchar', {
		comment:
			'Variable-length public key used to verify attestations (hex-encoded).',
	})
	public publicKey: string;

	@Column('timestamp with time zone', {
		comment:
			'The date of the last time the UserSecurityKey was successfully validated.',
	})
	public lastUsed: Date;

	@Column('varchar', {
		comment: 'User-defined name for this key',
		length: 30,
	})
	public name: string;

	constructor(data: Partial<UserSecurityKey>) {
		if (data == null) return;

		for (const [k, v] of Object.entries(data)) {
			(this as any)[k] = v;
		}
	}
}