- Correction toutes erreurs TypeScript : - Variables non utilisées supprimées - Types optionnels corrigés (exactOptionalPropertyTypes) - Imports corrigés (PLATFORM_BITCOIN_ADDRESS depuis platformConfig) - Gestion correcte des propriétés optionnelles - Suppression fichiers obsolètes : - code-cleanup-summary.md (redondant) - todo-implementation*.md (todos obsolètes) - corrections-completed.md, fallbacks-found.md (corrections faites) - implementation-summary.md (redondant) - documentation-plan.md (plan, pas documentation) - Suppression scripts temporaires : - add-ssh-key.sh - add-ssh-key-plink.sh - Réorganisation documentation dans docs/ : - architecture.md (nouveau) - commissions.md (nouveau) - implementation-summary.md - remaining-tasks.md - split-and-transfer.md - commission-system.md - commission-implementation.md - content-delivery-verification.md Toutes erreurs TypeScript corrigées, documentation centralisée.
102 lines
2.5 KiB
TypeScript
102 lines
2.5 KiB
TypeScript
import { nostrService } from './nostr'
|
|
import type { NostrProfile } from '@/types/nostr'
|
|
|
|
/**
|
|
* Lightning address service
|
|
* Retrieves Lightning addresses from Nostr profiles
|
|
*
|
|
* Supports:
|
|
* - lud16: Lightning address format (user@domain.com)
|
|
* - lud06: LNURL format
|
|
*/
|
|
export class LightningAddressService {
|
|
private addressCache: Map<string, string | null> = new Map()
|
|
|
|
/**
|
|
* Get Lightning address from Nostr profile
|
|
* Checks lud16 first, then lud06
|
|
*/
|
|
async getLightningAddress(pubkey: string): Promise<string | null> {
|
|
// Check cache first
|
|
const cached = this.addressCache.get(pubkey)
|
|
if (cached !== undefined) {
|
|
return cached
|
|
}
|
|
|
|
try {
|
|
const profile = await nostrService.getProfile(pubkey)
|
|
if (!profile) {
|
|
this.addressCache.set(pubkey, null)
|
|
return null
|
|
}
|
|
|
|
const address = this.extractLightningAddress(profile)
|
|
this.addressCache.set(pubkey, address)
|
|
return address
|
|
} catch (error) {
|
|
console.error('Error getting Lightning address', {
|
|
pubkey,
|
|
error: error instanceof Error ? error.message : 'Unknown error',
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
this.addressCache.set(pubkey, null)
|
|
return null
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Extract Lightning address from profile
|
|
* Checks lud16 first, then lud06
|
|
*/
|
|
private extractLightningAddress(profile: NostrProfile): string | null {
|
|
// Check if profile has extended fields (lud16, lud06)
|
|
const extendedProfile = profile as NostrProfile & {
|
|
lud16?: string
|
|
lud06?: string
|
|
}
|
|
|
|
// Prefer lud16 (Lightning address format)
|
|
if (extendedProfile.lud16) {
|
|
return extendedProfile.lud16
|
|
}
|
|
|
|
// Fallback to lud06 (LNURL format)
|
|
if (extendedProfile.lud06) {
|
|
return extendedProfile.lud06
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
/**
|
|
* Clear cache for a specific pubkey
|
|
*/
|
|
clearCache(pubkey: string): void {
|
|
this.addressCache.delete(pubkey)
|
|
}
|
|
|
|
/**
|
|
* Clear all cache
|
|
*/
|
|
clearAllCache(): void {
|
|
this.addressCache.clear()
|
|
}
|
|
|
|
/**
|
|
* Get Lightning addresses for multiple pubkeys
|
|
*/
|
|
async getLightningAddresses(pubkeys: string[]): Promise<Map<string, string | null>> {
|
|
const addresses = new Map<string, string | null>()
|
|
|
|
const promises = pubkeys.map(async (pubkey) => {
|
|
const address = await this.getLightningAddress(pubkey)
|
|
addresses.set(pubkey, address)
|
|
})
|
|
|
|
await Promise.all(promises)
|
|
return addresses
|
|
}
|
|
}
|
|
|
|
export const lightningAddressService = new LightningAddressService()
|