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';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { id } from '../id.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { User } from './User.js';
|
2019-07-03 11:18:07 +00:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
export class UserSecurityKey {
|
|
|
|
@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())
|
|
|
|
public userId: User['id'];
|
|
|
|
|
|
|
|
@ManyToOne(type => User, {
|
2021-12-09 14:58:30 +00:00
|
|
|
onDelete: 'CASCADE',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
@JoinColumn()
|
|
|
|
public user: User | null;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column('varchar', {
|
|
|
|
comment:
|
2021-12-09 14:58:30 +00:00
|
|
|
'Variable-length public key used to verify attestations (hex-encoded).',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
public publicKey: string;
|
|
|
|
|
|
|
|
@Column('timestamp with time zone', {
|
|
|
|
comment:
|
2021-12-09 14:58:30 +00:00
|
|
|
'The date of the last time the UserSecurityKey was successfully validated.',
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
public lastUsed: Date;
|
|
|
|
|
|
|
|
@Column('varchar', {
|
|
|
|
comment: 'User-defined name for this key',
|
2021-12-09 14:58:30 +00:00
|
|
|
length: 30,
|
2019-07-03 11:18:07 +00:00
|
|
|
})
|
|
|
|
public name: string;
|
|
|
|
|
|
|
|
constructor(data: Partial<UserSecurityKey>) {
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(data)) {
|
|
|
|
(this as any)[k] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|