diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index d14efd4..03ee993 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -410,7 +410,7 @@ export const CreatePage = () => { type: 'application/sigit' }) - const fileUrl = await uploadToFileStorage(file, nostrController) + const fileUrl = await uploadToFileStorage(file) .then((url) => { toast.success('files.zip uploaded to file storage') return url diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 7e59df4..148f75b 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -2,6 +2,7 @@ import axios from 'axios' import { Event, EventTemplate, + finalizeEvent, generateSecretKey, getPublicKey, nip04, @@ -14,6 +15,7 @@ import store from '../store/store' import { CreateSignatureEventContent, Meta } from '../types' import { hexToNpub, now } from './nostr' import { parseJson } from './string' +import { hexToBytes } from '@noble/hashes/utils' /** * Uploads a file to a file storage service. @@ -21,10 +23,7 @@ import { parseJson } from './string' * @param nostrController The NostrController instance for handling authentication. * @returns The URL of the uploaded file. */ -export const uploadToFileStorage = async ( - file: File, - nostrController: NostrController -) => { +export const uploadToFileStorage = async (file: File) => { // Define event metadata for authorization const event: EventTemplate = { kind: 24242, @@ -38,8 +37,15 @@ export const uploadToFileStorage = async ( ] } - // Sign the authorization event using the NostrController - const authEvent = await nostrController.signEvent(event) + const key = store.getState().userAppData?.keyPair?.private + if (!key) { + throw new Error( + 'Key to interact with blossom server is not defined in user app data' + ) + } + + // Sign the authorization event using the dedicated key stored in user app data + const authEvent = finalizeEvent(event, hexToBytes(key)) // URL of the file storage service const FILE_STORAGE_URL = 'https://blossom.sigit.io' // REFACTOR: should be an env