grant_type nostr -> nostr_bunker, connections -> nip46_tokens
This commit is contained in:
parent
a617e32d65
commit
7221b5f203
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Kysely, sql } from 'kysely';
|
|||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
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<any>): Promise<void> {
|
|||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropTable('connections').execute();
|
||||
await db.schema.dropTable('nip46_tokens').execute();
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue