mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
nip98: add explicit types to exported functions
This commit is contained in:
parent
26e87b3962
commit
6b1aadc24c
1 changed files with 11 additions and 2 deletions
|
|
@ -4,6 +4,8 @@ import { type EventTemplate, nip13 } from 'nostr-tools';
|
||||||
|
|
||||||
import { decode64Schema, signedEventSchema } from './schema.ts';
|
import { decode64Schema, signedEventSchema } from './schema.ts';
|
||||||
|
|
||||||
|
import type { z } from 'zod';
|
||||||
|
|
||||||
/** Decode a Nostr event from a base64 encoded string. */
|
/** Decode a Nostr event from a base64 encoded string. */
|
||||||
const decode64EventSchema = decode64Schema.pipe(n.json()).pipe(signedEventSchema);
|
const decode64EventSchema = decode64Schema.pipe(n.json()).pipe(signedEventSchema);
|
||||||
|
|
||||||
|
|
@ -18,7 +20,10 @@ interface ParseAuthRequestOpts {
|
||||||
|
|
||||||
/** Parse the auth event from a Request, returning a zod SafeParse type. */
|
/** Parse the auth event from a Request, returning a zod SafeParse type. */
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function parseAuthRequest(req: Request, opts: ParseAuthRequestOpts = {}) {
|
async function parseAuthRequest(
|
||||||
|
req: Request,
|
||||||
|
opts: ParseAuthRequestOpts = {},
|
||||||
|
): Promise<z.SafeParseReturnType<NostrEvent, NostrEvent> | z.SafeParseError<string>> {
|
||||||
const header = req.headers.get('authorization');
|
const header = req.headers.get('authorization');
|
||||||
const base64 = header?.match(/^Nostr (.+)$/)?.[1];
|
const base64 = header?.match(/^Nostr (.+)$/)?.[1];
|
||||||
const result = decode64EventSchema.safeParse(base64);
|
const result = decode64EventSchema.safeParse(base64);
|
||||||
|
|
@ -28,7 +33,11 @@ async function parseAuthRequest(req: Request, opts: ParseAuthRequestOpts = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compare the auth event with the request, returning a zod SafeParse type. */
|
/** Compare the auth event with the request, returning a zod SafeParse type. */
|
||||||
function validateAuthEvent(req: Request, event: NostrEvent, opts: ParseAuthRequestOpts = {}) {
|
function validateAuthEvent(
|
||||||
|
req: Request,
|
||||||
|
event: NostrEvent,
|
||||||
|
opts: ParseAuthRequestOpts = {},
|
||||||
|
): Promise<z.SafeParseReturnType<NostrEvent, NostrEvent>> {
|
||||||
const { maxAge = 60_000, validatePayload = true, pow = 0 } = opts;
|
const { maxAge = 60_000, validatePayload = true, pow = 0 } = opts;
|
||||||
|
|
||||||
const schema = signedEventSchema
|
const schema = signedEventSchema
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue