Files
LightningLotto/back_end/src/routes/user.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

153 lines
3.6 KiB
TypeScript

import { Router } from 'express';
import {
nostrAuth,
getProfile,
updateLightningAddress,
getUserTickets,
getUserWins
} from '../controllers/user';
import { verifyToken } from '../middleware/auth';
const router = Router();
/**
* @swagger
* /auth/nostr:
* post:
* summary: Authenticate with Nostr
* tags: [User]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - nostr_pubkey
* - signed_message
* - nonce
* properties:
* nostr_pubkey:
* type: string
* description: Nostr public key (hex or npub)
* signed_message:
* type: string
* description: Signature of the nonce
* nonce:
* type: string
* description: Random nonce for signature verification
* responses:
* 200:
* description: Authentication successful
* content:
* application/json:
* schema:
* type: object
* properties:
* version:
* type: string
* data:
* type: object
* properties:
* token:
* type: string
* description: JWT token
* user:
* type: object
* 400:
* description: Invalid public key or signature
*/
router.post('/auth/nostr', nostrAuth);
/**
* @swagger
* /me:
* get:
* summary: Get user profile
* tags: [User]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: User profile and statistics
* 401:
* description: Unauthorized
*/
router.get('/me', verifyToken, getProfile);
/**
* @swagger
* /me/lightning-address:
* patch:
* summary: Update user's Lightning Address
* tags: [User]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - lightning_address
* properties:
* lightning_address:
* type: string
* example: "user@getalby.com"
* responses:
* 200:
* description: Lightning Address updated
* 400:
* description: Invalid Lightning Address
* 401:
* description: Unauthorized
*/
router.patch('/me/lightning-address', verifyToken, updateLightningAddress);
/**
* @swagger
* /me/tickets:
* get:
* summary: Get user's ticket purchases
* tags: [User]
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: limit
* schema:
* type: integer
* default: 50
* - in: query
* name: offset
* schema:
* type: integer
* default: 0
* responses:
* 200:
* description: User's ticket purchase history
* 401:
* description: Unauthorized
*/
router.get('/me/tickets', verifyToken, getUserTickets);
/**
* @swagger
* /me/wins:
* get:
* summary: Get user's wins and payouts
* tags: [User]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: User's wins
* 401:
* description: Unauthorized
*/
router.get('/me/wins', verifyToken, getUserWins);
export default router;