From 11522c84262ad84dc7b679c2748a535a7295e13b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Sep 2025 16:09:45 -0500 Subject: [PATCH] Use NIP98Client from Nostrify --- package-lock.json | 24 ++++++++++++------------ package.json | 4 ++-- src/lib/NIP98Client.ts | 15 --------------- src/lib/ai-client.ts | 6 +++--- src/lib/deploy.ts | 4 ++-- 5 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 src/lib/NIP98Client.ts diff --git a/package-lock.json b/package-lock.json index 9e7f99a6..06347710 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,8 +13,8 @@ "@hookform/resolvers": "^3.9.0", "@isomorphic-git/lightning-fs": "^4.6.2", "@mozilla/readability": "^0.6.0", - "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.4", - "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.8", + "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.5", + "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.9", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-aspect-ratio": "^1.1.0", @@ -1223,9 +1223,9 @@ } }, "node_modules/@jsr/nostrify__nostrify": { - "version": "0.46.4", - "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.46.4.tgz", - "integrity": "sha512-bYuYkw9+jnHIDEJD6i+w0p8xV1oBLr1RF5rS3qF2yTz1b8i50dXKMO2cLObjalAAO3RYbnib3l85t1ZgWLCzAA==", + "version": "0.46.5", + "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.46.5.tgz", + "integrity": "sha512-l81N0o1A4WKAnOhq600ASDLxZbwzFZzUjhAkARPNFbWkXmEssVvXEQXyyoy1s7lboK45iZCijW0Bia7NHXmSug==", "dependencies": { "@jsr/nostrify__types": "^0.36.0", "@jsr/scure__base": "^1.2.4", @@ -1353,9 +1353,9 @@ }, "node_modules/@nostrify/nostrify": { "name": "@jsr/nostrify__nostrify", - "version": "0.46.4", - "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.46.4.tgz", - "integrity": "sha512-bYuYkw9+jnHIDEJD6i+w0p8xV1oBLr1RF5rS3qF2yTz1b8i50dXKMO2cLObjalAAO3RYbnib3l85t1ZgWLCzAA==", + "version": "0.46.5", + "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__nostrify/0.46.5.tgz", + "integrity": "sha512-l81N0o1A4WKAnOhq600ASDLxZbwzFZzUjhAkARPNFbWkXmEssVvXEQXyyoy1s7lboK45iZCijW0Bia7NHXmSug==", "dependencies": { "@jsr/nostrify__types": "^0.36.0", "@jsr/scure__base": "^1.2.4", @@ -1368,11 +1368,11 @@ }, "node_modules/@nostrify/react": { "name": "@jsr/nostrify__react", - "version": "0.2.8", - "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__react/0.2.8.tgz", - "integrity": "sha512-9sCsMm1uwuGWU+NhgFf6LS/4JzeRXnGOz+ocA5X3/ncvxZhidPOEAU39QyygRLFo/JYG8OC5wlyH8w0Uejq+VQ==", + "version": "0.2.9", + "resolved": "https://npm.jsr.io/~/11/@jsr/nostrify__react/0.2.9.tgz", + "integrity": "sha512-S19YP9adasszJbxgdIeC/4KXtZsAs9nf8I/2ptjr7pipyZWx8HykjjFE5pahj2TNMFc0/pEErcYpxGBg5t2n6Q==", "dependencies": { - "@jsr/nostrify__nostrify": "^0.46.4", + "@jsr/nostrify__nostrify": "^0.46.5", "nostr-tools": "^2.13.0", "react": "^18.0.0" } diff --git a/package.json b/package.json index 467fa267..450dc089 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "@hookform/resolvers": "^3.9.0", "@isomorphic-git/lightning-fs": "^4.6.2", "@mozilla/readability": "^0.6.0", - "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.4", - "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.8", + "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.5", + "@nostrify/react": "npm:@jsr/nostrify__react@^0.2.9", "@radix-ui/react-accordion": "^1.2.0", "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-aspect-ratio": "^1.1.0", diff --git a/src/lib/NIP98Client.ts b/src/lib/NIP98Client.ts deleted file mode 100644 index 14a5640e..00000000 --- a/src/lib/NIP98Client.ts +++ /dev/null @@ -1,15 +0,0 @@ -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 diff --git a/src/lib/ai-client.ts b/src/lib/ai-client.ts index 64b7e1e2..cf8580f0 100644 --- a/src/lib/ai-client.ts +++ b/src/lib/ai-client.ts @@ -1,5 +1,5 @@ import OpenAI from 'openai'; -import { NIP98Client } from './NIP98Client'; +import { NIP98Client } from '@nostrify/nostrify'; import type { AIConnection } from '@/contexts/AISettingsContext'; import type { NUser } from '@nostrify/react/login'; @@ -17,8 +17,8 @@ export function createAIClient(connection: AIConnection, user?: NUser): OpenAI { // If Nostr authentication is required and we have a user, use NIP-98 if (connection.nostr && user?.signer) { - const nip98Client = new NIP98Client(user.signer); - + const nip98Client = new NIP98Client({ signer: user.signer }); + return new OpenAI({ ...baseConfig, fetch: (input, init) => nip98Client.fetch(input, init), diff --git a/src/lib/deploy.ts b/src/lib/deploy.ts index 584d9c84..bfa1e12a 100644 --- a/src/lib/deploy.ts +++ b/src/lib/deploy.ts @@ -1,5 +1,5 @@ import JSZip from 'jszip'; -import { NIP98Client } from './NIP98Client'; +import { NIP98Client } from '@nostrify/nostrify'; import type { NostrSigner } from '@nostrify/nostrify'; import type { JSRuntimeFS } from './JSRuntime'; @@ -56,7 +56,7 @@ export async function deployProject(options: DeployOptions): Promise