File

src/crypto/key/entities/keys.entity.ts

Index

Properties

Properties

certificates
Type : CertEntity[]
Decorators :
@OneToMany(undefined, cert => cert.key)

Certificates associated with this key.

createdAt
Type : Date
Decorators :
@CreateDateColumn()

The timestamp when the key was created.

Optional description
Type : string
Decorators :
@IsString()
@IsOptional()
@Column('varchar', {nullable: true})

Description of the key.

id
Type : string
Decorators :
@IsString()
@Column('varchar', {primary: true})

Unique identifier for the key.

key
Type : JWK
Decorators :
@Column('text', {transformer: EncryptedJsonTransformer})

The key material. Encrypted at rest using AES-256-GCM.

tenant
Type : TenantEntity
Decorators :
@ManyToOne(undefined, {cascade: true, onDelete: 'CASCADE'})

The tenant that owns this object.

tenantId
Type : string
Decorators :
@Column('varchar', {primary: true})

Tenant ID for the key.

updatedAt
Type : Date
Decorators :
@UpdateDateColumn()

The timestamp when the key was last updated.

usage
Type : KeyUsage
Decorators :
@Column('varchar', {default: 'sign'})

The usage type of the key.

import { IsOptional, IsString } from "class-validator";
import { JWK } from "jose";
import {
    Column,
    CreateDateColumn,
    Entity,
    ManyToOne,
    OneToMany,
    UpdateDateColumn,
} from "typeorm";
import { TenantEntity } from "../../../auth/tenant/entitites/tenant.entity";
import { EncryptedJsonTransformer } from "../../../shared/utils/encryption";
import { CertEntity } from "./cert.entity";

/**
 * Key usage types.
 */
export type KeyUsage = "sign" | "encrypt";

@Entity()
export class KeyEntity {
    /**
     * Unique identifier for the key.
     */
    @IsString()
    @Column("varchar", { primary: true })
    id!: string;

    /**
     * Description of the key.
     */
    @IsString()
    @IsOptional()
    @Column("varchar", { nullable: true })
    description?: string;

    /**
     * Tenant ID for the key.
     */
    @Column("varchar", { primary: true })
    tenantId!: string;

    /**
     * The tenant that owns this object.
     */
    @ManyToOne(() => TenantEntity, { cascade: true, onDelete: "CASCADE" })
    tenant!: TenantEntity;

    /**
     * The key material.
     * Encrypted at rest using AES-256-GCM.
     */
    @Column("text", { transformer: EncryptedJsonTransformer })
    key!: JWK;

    /**
     * The usage type of the key.
     */
    @Column("varchar", { default: "sign" })
    usage!: KeyUsage;

    /**
     * Certificates associated with this key.
     */
    @OneToMany(
        () => CertEntity,
        (cert) => cert.key,
    )
    certificates: CertEntity[];

    /**
     * The timestamp when the key was created.
     */
    @CreateDateColumn()
    createdAt!: Date;

    /**
     * The timestamp when the key was last updated.
     */
    @UpdateDateColumn()
    updatedAt!: Date;
}

results matching ""

    No results matching ""