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 }) console.log('Invoice created by author:', invoice) return invoice } /** * Create preview event with invoice tags */ export function createPreviewEvent(draft: ArticleDraft, invoice: AlbyInvoice): { kind: 1 created_at: number tags: string[][] content: string } { return { kind: 1 as const, created_at: Math.floor(Date.now() / 1000), tags: [ ['title', draft.title], ['preview', draft.preview], ['zap', draft.zapAmount.toString()], ['content-type', 'article'], ['invoice', invoice.invoice], ['payment_hash', invoice.paymentHash], ], content: draft.preview, } }