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