import { nostrService } from '../nostr' import type { ArticleDraft } from '../articlePublisher' import { writeOrchestrator } from '../writeOrchestrator' export function ensureKeys(authorPubkey: string, authorPrivateKey?: string): void { nostrService.setPublicKey(authorPubkey) if (authorPrivateKey) { nostrService.setPrivateKey(authorPrivateKey) } else if (!nostrService.getPrivateKey()) { throw new Error('Private key required for signing. Connect a wallet that can sign.') } } export function requireCategory(category?: ArticleDraft['category']): asserts category is NonNullable { if (category !== 'science-fiction' && category !== 'scientific-research') { throw new Error('Vous devez sélectionner une catégorie (science-fiction ou recherche scientifique).') } } export async function ensurePresentation(authorPubkey: string): Promise { const { articlePublisher } = await import('../articlePublisher') const presentation = await articlePublisher.getAuthorPresentation(authorPubkey) if (!presentation) { throw new Error('Vous devez créer un article de présentation avant de publier des articles.') } return presentation.id } export function mapDraftCategoryToTag(category: NonNullable): 'sciencefiction' | 'research' { return category === 'science-fiction' ? 'sciencefiction' : 'research' } export function getPrivateKeyForSigning(authorPrivateKey: string | undefined): string { const privateKey = authorPrivateKey ?? nostrService.getPrivateKey() if (!privateKey) { throw new Error('Private key required for signing') } writeOrchestrator.setPrivateKey(privateKey) return privateKey }