diff --git a/packages/ozone/src/context.ts b/packages/ozone/src/context.ts index a2fed060a5f..0a18feda86a 100644 --- a/packages/ozone/src/context.ts +++ b/packages/ozone/src/context.ts @@ -16,6 +16,7 @@ import { } from './communication-service/template' import { AuthVerifier } from './auth-verifier' import { ImageInvalidator } from './image-invalidator' +import { getSigningKeyId } from './util' export type AppContextOptions = { db: Database @@ -48,6 +49,7 @@ export class AppContext { poolIdleTimeoutMs: cfg.db.poolIdleTimeoutMs, }) const signingKey = await Secp256k1Keypair.import(secrets.signingKeyHex) + const signingKeyId = await getSigningKeyId(db, signingKey.did()) const appviewAgent = new AtpAgent({ service: cfg.appview.url }) const pdsAgent = cfg.pds ? new AtpAgent({ service: cfg.pds.url }) @@ -72,6 +74,7 @@ export class AppContext { const modService = ModerationService.creator( signingKey, + signingKeyId, cfg, backgroundQueue, idResolver, @@ -195,5 +198,4 @@ export class AppContext { } } } - export default AppContext diff --git a/packages/ozone/src/daemon/context.ts b/packages/ozone/src/daemon/context.ts index c915f26abc0..0217b9a7bf3 100644 --- a/packages/ozone/src/daemon/context.ts +++ b/packages/ozone/src/daemon/context.ts @@ -8,6 +8,7 @@ import { EventReverser } from './event-reverser' import { ModerationService, ModerationServiceCreator } from '../mod-service' import { BackgroundQueue } from '../background' import { IdResolver } from '@atproto/identity' +import { getSigningKeyId } from '../util' export type DaemonContextOptions = { db: Database @@ -31,6 +32,7 @@ export class DaemonContext { schema: cfg.db.postgresSchema, }) const signingKey = await Secp256k1Keypair.import(secrets.signingKeyHex) + const signingKeyId = await getSigningKeyId(db, signingKey.did()) const appviewAgent = new AtpAgent({ service: cfg.appview.url }) const createAuthHeaders = (aud: string) => @@ -52,6 +54,7 @@ export class DaemonContext { const modService = ModerationService.creator( signingKey, + signingKeyId, cfg, backgroundQueue, idResolver, diff --git a/packages/ozone/src/db/migrations/20240228T003647759Z-add-label-sigs.ts b/packages/ozone/src/db/migrations/20240228T003647759Z-add-label-sigs.ts index ae5f281bbf9..59e859faab6 100644 --- a/packages/ozone/src/db/migrations/20240228T003647759Z-add-label-sigs.ts +++ b/packages/ozone/src/db/migrations/20240228T003647759Z-add-label-sigs.ts @@ -8,11 +8,17 @@ export async function up(db: Kysely): Promise { .execute() await db.schema .alterTable('label') - .addColumn('signingKey', 'varchar') + .addColumn('signingKeyId', 'integer') + .execute() + await db.schema + .createTable('signing_key') + .addColumn('id', 'serial', (col) => col.primaryKey()) + .addColumn('key', 'varchar', (col) => col.notNull().unique()) .execute() } export async function down(db: Kysely): Promise { + await db.schema.dropTable('signing_key') await db.schema.alterTable('label').dropColumn('exp').execute() await db.schema.alterTable('label').dropColumn('sig').execute() await db.schema.alterTable('label').dropColumn('signingKey').execute() diff --git a/packages/ozone/src/db/schema/index.ts b/packages/ozone/src/db/schema/index.ts index b522a75ef9f..48e3f15cdc5 100644 --- a/packages/ozone/src/db/schema/index.ts +++ b/packages/ozone/src/db/schema/index.ts @@ -5,11 +5,13 @@ import * as repoPushEvent from './repo_push_event' import * as recordPushEvent from './record_push_event' import * as blobPushEvent from './blob_push_event' import * as label from './label' +import * as signingKey from './signing_key' import * as communicationTemplate from './communication_template' export type DatabaseSchemaType = modEvent.PartialDB & modSubjectStatus.PartialDB & label.PartialDB & + signingKey.PartialDB & repoPushEvent.PartialDB & recordPushEvent.PartialDB & blobPushEvent.PartialDB & diff --git a/packages/ozone/src/db/schema/label.ts b/packages/ozone/src/db/schema/label.ts index 75bcd0adf52..58042478c8d 100644 --- a/packages/ozone/src/db/schema/label.ts +++ b/packages/ozone/src/db/schema/label.ts @@ -12,7 +12,7 @@ export interface Label { cts: string exp: string | null sig: Buffer | null - signingKey: string | null + signingKeyId: number | null } export type LabelRow = Selectable