diff --git a/src/middleware/auth98.ts b/src/middleware/auth98.ts index 8eb73b5..0520010 100644 --- a/src/middleware/auth98.ts +++ b/src/middleware/auth98.ts @@ -91,7 +91,7 @@ function withProof( async function obtainProof(c: AppContext, opts?: ParseAuthRequestOpts) { const req = localRequest(c); const reqEvent = await buildAuthEventTemplate(req, opts); - const resEvent = await signEvent(reqEvent, c); + const resEvent = await signEvent(reqEvent, c, opts); const result = await validateAuthEvent(req, resEvent, opts); if (result.success) { diff --git a/src/sign.ts b/src/sign.ts index 14c192f..b5bbd33 100644 --- a/src/sign.ts +++ b/src/sign.ts @@ -8,13 +8,22 @@ import { Sub } from '@/subs.ts'; import { eventMatchesTemplate, Time } from '@/utils.ts'; import { createAdminEvent } from '@/utils/web.ts'; +interface SignEventOpts { + /** Target proof-of-work difficulty for the signed event. */ + pow?: number; +} + /** * Sign Nostr event using the app context. * * - If a secret key is provided, it will be used to sign the event. * - If `X-Nostr-Sign` is passed, it will use NIP-46 to sign the event. */ -async function signEvent(event: EventTemplate, c: AppContext): Promise> { +async function signEvent( + event: EventTemplate, + c: AppContext, + opts: SignEventOpts = {}, +): Promise> { const seckey = c.get('seckey'); const header = c.req.headers.get('x-nostr-sign'); @@ -23,7 +32,7 @@ async function signEvent(event: EventTemplate, c: } if (header) { - return await signNostrConnect(event, c); + return await signNostrConnect(event, c, opts); } throw new HTTPException(400, { @@ -32,7 +41,11 @@ async function signEvent(event: EventTemplate, c: } /** Sign event with NIP-46, waiting in the background for the signed event. */ -async function signNostrConnect(event: EventTemplate, c: AppContext): Promise> { +async function signNostrConnect( + event: EventTemplate, + c: AppContext, + opts: SignEventOpts = {}, +): Promise> { const pubkey = c.get('pubkey'); if (!pubkey) { @@ -48,7 +61,9 @@ async function signNostrConnect(event: EventTemplate< JSON.stringify({ id: messageId, method: 'sign_event', - params: [event], + params: [event, { + pow: opts.pow, + }], }), ), tags: [['p', pubkey]],