mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Use NIP98Client from Nostrify
This commit is contained in:
5 files changed
+19
-34
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
+2
-2
@@ -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<DeployResul
|
||||
formData.append('file', zipBlob, `${projectId}.zip`);
|
||||
|
||||
// Create NIP-98 authenticated client and deploy
|
||||
const nip98Client = new NIP98Client(signer);
|
||||
const nip98Client = new NIP98Client({ signer });
|
||||
const response = await nip98Client.fetch(deployUrl, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
|
||||
Reference in new issue
Block a user