From fd9aa5b683bd16fc4f5ab1a1c655725577801a43 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 7 Sep 2025 17:41:39 -0500 Subject: [PATCH] Add NIP98Client --- src/lib/NIP98Client.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/lib/NIP98Client.ts diff --git a/src/lib/NIP98Client.ts b/src/lib/NIP98Client.ts new file mode 100644 index 00000000..14a5640e --- /dev/null +++ b/src/lib/NIP98Client.ts @@ -0,0 +1,15 @@ +import { NostrSigner, NIP98 } from "@nostrify/nostrify"; +import { N64 } from "@nostrify/nostrify/utils"; + +export class NIP98Client { + constructor(private signer: NostrSigner) {} + + async fetch(input: string | URL | Request, init?: RequestInit) { + const request = new Request(input, init); + const template = await NIP98.template(request); + const event = await this.signer.signEvent(template); + const token = N64.encodeEvent(event); + request.headers.set("Authorization", `Nostr ${token}`); + return fetch(request); + } +} \ No newline at end of file