- **Motivations :** Assurer passage du lint strict et clarifier la logique paiements/publications. - **Root causes :** Fonctions trop longues, promesses non gérées et typages WebLN/Nostr incomplets. - **Correctifs :** Refactor PaymentModal (handlers void), extraction helpers articlePublisher, simplification polling sponsoring/zap, corrections curly et awaits. - **Evolutions :** Nouveau module articlePublisherHelpers pour présentation/aiguillage contenu privé. - **Page affectées :** components/PaymentModal.tsx, lib/articlePublisher.ts, lib/articlePublisherHelpers.ts, lib/paymentPolling.ts, lib/sponsoring.ts, lib/nostrZapVerification.ts et dépendances liées.
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import type { EventTemplate, Event } from 'nostr-tools'
|
|
import { getEventHash, signEvent } from 'nostr-tools'
|
|
import { nostrConnectService } from './nostrconnect'
|
|
import { nostrService } from './nostr'
|
|
|
|
/**
|
|
* Remote signer using NostrConnect
|
|
* Supports both direct signing (if private key available) and remote signing via bridge
|
|
*/
|
|
export class NostrRemoteSigner {
|
|
/**
|
|
* Sign an event template
|
|
* Requires private key to be available
|
|
*/
|
|
signEvent(eventTemplate: EventTemplate): Event | null {
|
|
// Get the event hash first
|
|
const eventId = getEventHash(eventTemplate)
|
|
|
|
// Try to get private key from nostrService (if available from NostrConnect)
|
|
const privateKey = nostrService.getPrivateKey()
|
|
|
|
if (!privateKey) {
|
|
throw new Error(
|
|
'Private key required for signing. ' +
|
|
'Please use a NostrConnect wallet that provides signing capabilities, ' +
|
|
'or ensure your wallet is properly connected.'
|
|
)
|
|
}
|
|
|
|
const event = {
|
|
...eventTemplate,
|
|
id: eventId,
|
|
sig: signEvent(eventTemplate, privateKey),
|
|
} as Event
|
|
|
|
return event
|
|
}
|
|
|
|
/**
|
|
* Check if remote signing is available
|
|
*/
|
|
isAvailable(): boolean {
|
|
const state = nostrConnectService.getState()
|
|
return state.connected && !!state.pubkey
|
|
}
|
|
|
|
/**
|
|
* Check if direct signing (with private key) is available
|
|
*/
|
|
isDirectSigningAvailable(): boolean {
|
|
return !!nostrService.getPrivateKey()
|
|
}
|
|
}
|
|
|
|
export const nostrRemoteSigner = new NostrRemoteSigner()
|