Add a UUID to auth tokens for private websocket event signing

This commit is contained in:
Alex Gleason
2023-05-20 14:34:13 -05:00
parent 9500ceee7c
commit f3e42cc6a7
6 changed files with 42 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
import { getAuthor } from '@/client.ts';
import { Context, getPublicKey, nip19, parseFormData } from '@/deps.ts';
import { nip19, parseFormData } from '@/deps.ts';
import { type Event } from '@/event.ts';
import { lookupNip05Cached } from '@/nip05.ts';
@@ -9,30 +9,6 @@ const nostrNow = () => Math.floor(new Date().getTime() / 1000);
/** Pass to sort() to sort events by date. */
const eventDateComparator = (a: Event, b: Event) => b.created_at - a.created_at;
function getKeys(c: Context) {
const auth = c.req.headers.get('Authorization') || '';
if (auth.startsWith('Bearer ')) {
const privatekey = auth.split('Bearer ')[1];
const pubkey = getPublicKey(privatekey);
return {
privatekey,
pubkey,
};
}
}
/** Return true if the value is a bech32 string, eg for use with NIP-19. */
function isBech32(value: unknown): value is string {
return typeof value === 'string' && nip19.BECH32_REGEX.test(value);
}
/** Return true if the value is a Nostr pubkey, private key, or event ID. */
function isNostrId(value: unknown): value is string {
return typeof value === 'string' && /^[0-9a-f]{64}$/.test(value);
}
/** Get pubkey from bech32 string, if applicable. */
function bech32ToPubkey(bech32: string): string | undefined {
try {
@@ -99,15 +75,4 @@ async function parseBody(req: Request): Promise<unknown> {
}
}
export {
bech32ToPubkey,
eventDateComparator,
getKeys,
isBech32,
isNostrId,
lookupAccount,
type Nip05,
nostrNow,
parseBody,
parseNip05,
};
export { bech32ToPubkey, eventDateComparator, lookupAccount, type Nip05, nostrNow, parseBody, parseNip05 };