From 7221b5f2033e76096655500e9760e8a2af3cca33 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 29 May 2024 16:14:21 -0500 Subject: [PATCH] grant_type nostr -> nostr_bunker, connections -> nip46_tokens --- src/controllers/api/oauth.ts | 8 ++++---- src/db/DittoTables.ts | 4 ++-- .../{023_add_connections.ts => 023_add_nip46_tokens.ts} | 4 ++-- src/middleware/signerMiddleware.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) rename src/db/migrations/{023_add_connections.ts => 023_add_nip46_tokens.ts} (87%) diff --git a/src/controllers/api/oauth.ts b/src/controllers/api/oauth.ts index f4e68e1..242646b 100644 --- a/src/controllers/api/oauth.ts +++ b/src/controllers/api/oauth.ts @@ -25,7 +25,7 @@ const credentialsGrantSchema = z.object({ }); const nostrGrantSchema = z.object({ - grant_type: z.literal('nostr'), + grant_type: z.literal('nostr_bunker'), pubkey: n.id(), relays: z.string().url().array().optional(), secret: z.string().optional(), @@ -47,7 +47,7 @@ const createTokenController: AppController = async (c) => { } switch (result.data.grant_type) { - case 'nostr': + case 'nostr_bunker': return c.json({ access_token: await getToken(result.data), token_type: 'Bearer', @@ -90,13 +90,13 @@ async function getToken( const signer = new NConnectSigner({ pubkey, signer: new NSecSigner(serverSeckey), - relay: await Storages.pubsub(), + relay: await Storages.pubsub(), // TODO: Use the relays from the request. timeout: 60_000, }); await signer.connect(secret); - await kysely.insertInto('connections').values({ + await kysely.insertInto('nip46_tokens').values({ api_token: token, user_pubkey: pubkey, server_seckey: serverSeckey, diff --git a/src/db/DittoTables.ts b/src/db/DittoTables.ts index 31d8542..65bc426 100644 --- a/src/db/DittoTables.ts +++ b/src/db/DittoTables.ts @@ -2,7 +2,7 @@ export interface DittoTables { nostr_events: EventRow; nostr_tags: TagRow; nostr_fts5: EventFTSRow; - connections: ConnectionRow; + nip46_tokens: NIP46TokenRow; unattached_media: UnattachedMediaRow; author_stats: AuthorStatsRow; event_stats: EventStatsRow; @@ -45,7 +45,7 @@ interface TagRow { value: string; } -interface ConnectionRow { +interface NIP46TokenRow { api_token: string; user_pubkey: string; server_seckey: Uint8Array; diff --git a/src/db/migrations/023_add_connections.ts b/src/db/migrations/023_add_nip46_tokens.ts similarity index 87% rename from src/db/migrations/023_add_connections.ts rename to src/db/migrations/023_add_nip46_tokens.ts index e734916..144bd1e 100644 --- a/src/db/migrations/023_add_connections.ts +++ b/src/db/migrations/023_add_nip46_tokens.ts @@ -2,7 +2,7 @@ import { Kysely, sql } from 'kysely'; export async function up(db: Kysely): Promise { await db.schema - .createTable('connections') + .createTable('nip46_tokens') .addColumn('api_token', 'text', (col) => col.primaryKey().unique().notNull()) .addColumn('user_pubkey', 'text', (col) => col.notNull()) .addColumn('server_seckey', 'bytea', (col) => col.notNull()) @@ -13,5 +13,5 @@ export async function up(db: Kysely): Promise { } export async function down(db: Kysely): Promise { - await db.schema.dropTable('connections').execute(); + await db.schema.dropTable('nip46_tokens').execute(); } diff --git a/src/middleware/signerMiddleware.ts b/src/middleware/signerMiddleware.ts index f52aa20..5ea4235 100644 --- a/src/middleware/signerMiddleware.ts +++ b/src/middleware/signerMiddleware.ts @@ -23,7 +23,7 @@ export const signerMiddleware: AppMiddleware = async (c, next) => { const kysely = await DittoDB.getInstance(); const { user_pubkey, server_seckey, relays } = await kysely - .selectFrom('connections') + .selectFrom('nip46_tokens') .select(['user_pubkey', 'server_seckey', 'relays']) .where('api_token', '=', bech32) .executeTakeFirstOrThrow();