fix: use dedicated key from nip78 in auth event for uploading files.zip

This commit is contained in:
SwiftHawk 2024-07-09 00:01:03 +05:00
parent 6b135ac54d
commit 8eaf9cb61c
2 changed files with 13 additions and 7 deletions

View File

@ -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

View File

@ -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