40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { nostrService } from './nostr'
|
|
import type { ArticleDraft } from './articlePublisherTypes'
|
|
|
|
export function prepareAuthorKeys(authorPubkey: string, authorPrivateKey?: string): { success: boolean; error?: string } {
|
|
nostrService.setPublicKey(authorPubkey)
|
|
|
|
if (authorPrivateKey) {
|
|
nostrService.setPrivateKey(authorPrivateKey)
|
|
return { success: true }
|
|
}
|
|
|
|
const existingPrivateKey = nostrService.getPrivateKey()
|
|
if (!existingPrivateKey) {
|
|
return {
|
|
success: false,
|
|
error:
|
|
'Private key required for signing. Please connect with a Nostr wallet that provides signing capabilities.',
|
|
}
|
|
}
|
|
|
|
return { success: true }
|
|
}
|
|
|
|
export function isValidCategory(category?: ArticleDraft['category']): category is NonNullable<ArticleDraft['category']> {
|
|
return category === 'science-fiction' || category === 'scientific-research'
|
|
}
|
|
|
|
export interface ValidationResult {
|
|
success: false
|
|
error: string
|
|
}
|
|
|
|
export interface ValidationSuccess {
|
|
success: true
|
|
authorPrivateKeyForEncryption: string
|
|
category: NonNullable<ArticleDraft['category']>
|
|
}
|
|
|
|
export type PublishValidationResult = ValidationResult | ValidationSuccess
|