2023-07-27 05:31:52 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2019-07-03 11:18:07 +00:00
|
|
|
import { PrimaryColumn, Entity, JoinColumn, Column, ManyToOne, Index } from 'typeorm';
|
2023-09-20 02:33:36 +00:00
|
|
|
import { id } from './util/id.js';
|
2023-08-16 08:51:28 +00:00
|
|
|
import { MiUser } from './User.js';
|
2019-07-03 11:18:07 +00:00
|
|
|
|
2023-08-16 08:51:28 +00:00
|
|
|
@Entity('user_security_key')
|
|
|
|
export class MiUserSecurityKey {
|
2019-07-03 11:18:07 +00:00
|
|
|
@PrimaryColumn('varchar', {
|
2021-12-09 14:58:30 +00:00
|
|
|
comment: 'Variable-length id given to navigator.credentials.get()',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
public id: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column(id())
|
2023-08-16 08:51:28 +00:00
|
|
|
public userId: MiUser['id'];
|
2019-07-03 11:18:07 +00:00
|
|
|
|
2023-08-16 08:51:28 +00:00
|
|
|
@ManyToOne(type => MiUser, {
|
2021-12-09 14:58:30 +00:00
|
|
|
onDelete: 'CASCADE',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
2023-08-16 08:51:28 +00:00
|
|
|
public user: MiUser | null;
|
2019-07-03 11:18:07 +00:00
|
|
|
|
2023-09-08 05:05:03 +00:00
|
|
|
@Column('varchar', {
|
|
|
|
comment: 'User-defined name for this key',
|
|
|
|
length: 30,
|
|
|
|
})
|
|
|
|
public name: string;
|
|
|
|
|
2019-07-03 11:18:07 +00:00
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
2023-09-08 05:05:03 +00:00
|
|
|
comment: 'The public key of the UserSecurityKey, hex-encoded.',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
public publicKey: string;
|
|
|
|
|
2023-09-08 05:05:03 +00:00
|
|
|
@Column('bigint', {
|
|
|
|
comment: 'The number of times the UserSecurityKey was validated.',
|
|
|
|
default: 0,
|
|
|
|
})
|
|
|
|
public counter: number;
|
|
|
|
|
2019-07-03 11:18:07 +00:00
|
|
|
@Column('timestamp with time zone', {
|
2023-09-08 05:05:03 +00:00
|
|
|
comment: 'Timestamp of the last time the UserSecurityKey was used.',
|
|
|
|
default: () => 'now()',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
public lastUsed: Date;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
2023-09-08 05:05:03 +00:00
|
|
|
comment: 'The type of Backup Eligibility in authenticator data',
|
|
|
|
length: 32, nullable: true,
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
2023-09-08 05:05:03 +00:00
|
|
|
public credentialDeviceType: string | null;
|
|
|
|
|
|
|
|
@Column('boolean', {
|
|
|
|
comment: 'Whether or not the credential has been backed up',
|
|
|
|
nullable: true,
|
|
|
|
})
|
|
|
|
public credentialBackedUp: boolean | null;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
comment: 'The type of the credential returned by the browser',
|
|
|
|
length: 32, array: true, nullable: true,
|
|
|
|
})
|
|
|
|
public transports: string[] | null;
|
2019-07-03 11:18:07 +00:00
|
|
|
|
2023-08-16 08:51:28 +00:00
|
|
|
constructor(data: Partial<MiUserSecurityKey>) {
|
2019-07-03 11:18:07 +00:00
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(data)) {
|
|
|
|
(this as any)[k] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|