Files
LightningLotto/back_end/src/utils/validation.ts
Michilis d3bf8080b6 Initial commit: Lightning Lottery - Bitcoin Lightning Network powered lottery
Features:
- Lightning Network payments via LNbits integration
- Provably fair draws using CSPRNG
- Random ticket number generation
- Automatic payouts with retry/redraw logic
- Nostr authentication (NIP-07)
- Multiple draw cycles (hourly, daily, weekly, monthly)
- PostgreSQL and SQLite database support
- Real-time countdown and payment animations
- Swagger API documentation
- Docker support

Stack:
- Backend: Node.js, TypeScript, Express
- Frontend: Next.js, React, TailwindCSS, Redux
- Payments: LNbits
2025-11-27 22:13:37 +00:00

71 lines
1.4 KiB
TypeScript

/**
* 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);
}