mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 08:38:50 +00:00
+nip98.unpackEventFromToken +nip98.validateEvent
This commit is contained in:
16
nip98.ts
16
nip98.ts
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user