/** * Validates a Lightning Address format */ export function validateLightningAddress(address: string): boolean { if (!address || typeof address !== 'string') { return false; } // Must contain @ symbol if (!address.includes('@')) { return false; } // Basic email-like format check const parts = address.split('@'); if (parts.length !== 2) { return false; } const [username, domain] = parts; // Username and domain must not be empty if (!username || !domain) { return false; } // Length check if (address.length > 255) { return false; } return true; } /** * Validates Nostr public key (hex or npub format) */ export function validateNostrPubkey(pubkey: string): boolean { if (!pubkey || typeof pubkey !== 'string') { return false; } // Hex format: 64 characters if (/^[0-9a-f]{64}$/i.test(pubkey)) { return true; } // npub format (bech32) if (pubkey.startsWith('npub1') && pubkey.length === 63) { return true; } return false; } /** * Validates number of tickets */ export function validateTicketCount(count: number, max: number = 100): boolean { return Number.isInteger(count) && count > 0 && count <= max; } /** * Sanitizes input string */ export function sanitizeString(input: string, maxLength: number = 255): string { if (!input) return ''; return input.trim().substring(0, maxLength); }