+nip98.unpackEventFromToken +nip98.validateEvent

This commit is contained in:
Airtune
2023-08-07 22:16:23 -04:00
parent 3368e8c00e
commit 16c7ae2a70
3 changed files with 60 additions and 13 deletions

View File

@@ -65,6 +65,13 @@ export async function validateToken(
url: string,
method: string
): Promise<boolean> {
const event = await unpackEventFromToken(token).catch((error) => { throw(error) })
const valid = await validateEvent(event, url, method).catch((error) => { throw(error) })
return valid
}
export async function unpackEventFromToken(token: string): Promise<Event> {
if (!token) {
throw new Error('Missing token')
}
@@ -76,6 +83,15 @@ export async function validateToken(
}
const event = JSON.parse(eventB64) as Event
return event
}
export async function validateEvent(
event: Event,
url: string,
method: string
): Promise<boolean> {
if (!event) {
throw new Error('Invalid nostr event')
}