import { getAlbyService } from './alby' import type { AlbyInvoice } from '@/types/alby' import type { ArticleDraft } from './articlePublisher' /** * Create Lightning invoice for article * Requires Alby/WebLN to be available and enabled */ export async function createArticleInvoice(draft: ArticleDraft): Promise { const alby = getAlbyService() await alby.enable() // Request permission const invoice = await alby.createInvoice({ amount: draft.zapAmount, description: `Payment for article: ${draft.title}`, expiry: 86400, // 24 hours }) return invoice } /** * Create preview event with invoice tags */ export function createPreviewEvent( draft: ArticleDraft, invoice: AlbyInvoice, authorPresentationId?: string ): { kind: 1 created_at: number tags: string[][] content: string } { const tags: string[][] = [ ['title', draft.title], ['preview', draft.preview], ['zap', draft.zapAmount.toString()], ['content-type', 'article'], ['invoice', invoice.invoice], ['payment_hash', invoice.paymentHash], ] // Add category if specified if (draft.category) { tags.push(['category', draft.category]) } // Add author presentation ID if provided if (authorPresentationId) { tags.push(['author_presentation_id', authorPresentationId]) } return { kind: 1 as const, created_at: Math.floor(Date.now() / 1000), tags, content: draft.preview, } }