A secure Web3 authentication and wallet management API built with Node.js, Express, and PostgreSQL. Features encrypted private key storage, smart account integration, and comprehensive user management.
- ๐ Secure Authentication - JWT-based auth with email verification
- ๐ Smart Wallet Management - Auto-generated wallets with Circle smart accounts
- ๐ก๏ธ Private Key Encryption - AES-256-GCM encryption with scrypt key derivation
- ๐ง Email Services - Professional email templates with SMTP support
- โ Input Validation - Comprehensive validation with detailed error messages
- ๐ Blockchain Integration - Base network support with Viem and Ethers.js
- ๐ Standardized Responses - Consistent API response format
- ๐๏ธ Clean Architecture - Separation of concerns with service layer pattern
- Backend: Node.js, Express.js
- Database: PostgreSQL with Sequelize ORM
- Authentication: JWT, bcrypt
- Blockchain: Ethers.js, Viem, Circle Modular Wallets
- Encryption: Node.js Crypto (AES-256-GCM + scrypt)
- Email: Nodemailer
- Validation: Custom validation service
- Environment: ES Modules
- Node.js 16+
- PostgreSQL 12+
- SMTP email service (Gmail, Outlook, etc.)
- Base network RPC endpoint
git clone https://github.com/Kaluubaa/kaluuba-api-js.git
cd kaluuba-api-js
npm installcp .env.example .env
# Edit .env with your configuration# Create PostgreSQL database
createdb kaluuba# Generate JWT secret
echo "JWT_SECRET=$(openssl rand -base64 32)" >> .env
# Generate encryption secret
echo "ENCRYPTION_SECRET=$(openssl rand -base64 32)" >> .envnpm run dev
# Run migrations (if migrations dont run automatically)
npx sequelize-cli db:migrateServer runs on: http://localhost:3030/api/v1
# Server Configuration
BASE_URL=http://localhost:3030/api
PORT=3030
NODE_ENV=development
API_VERSION=v1
# Database (PostgreSQL)
DB_DIALECT=postgres
DB_HOST=localhost
DB_PORT=5432
DB_NAME=kaluuba
DB_USER=postgres
DB_PASSWORD=your_strong_password
# Security (Generate with OpenSSL)
JWT_SECRET=your_jwt_secret_here
ENCRYPTION_SECRET=your_encryption_secret_here
JWT_EXPIRES_IN=24h
# Email Service (SMTP)
[email protected]
EMAIL_PASSWORD=your_app_specific_password
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
# Blockchain
RPC_URL=https://sepolia.base.org# Database Connection Pool
DB_SSL=false
DB_MIN_CONNECTIONS=2
DB_MAX_CONNECTIONS=20
DB_IDLE_TIMEOUT=30000
DB_CONNECTION_TIMEOUT=10000
# API Settings
API_RATE_LIMIT=100
LOG_LEVEL=info
EMAIL_SECURE=465http://localhost:3030/api/v1
https://solanadevs.postman.co/workspace/kaluuba~b96c0838-b583-4dba-9765-b63b377c9eae/request/20323840-bc0b8f23-1b87-46bf-9d55-036b2bc4bef7?action=share&source=copy-link&creator=20323840
kaluuba-api/
โโโ controllers/ # Route handlers
โ โโโ AuthController.js
โ โโโ WalletController.js
โโโ models/ # Database models
โ โโโ index.js
โ โโโ user.js
โโโ services/ # Business logic
โ โโโ EmailService.js
โ โโโ EncryptionService.js
โ โโโ SmartAccountService.js
โ โโโ UserService.js
โ โโโ ValidationService.js
โโโ routes/ # API routes
โ โโโ auth.js
โโโ utils/ # Utility functions
โ โโโ ApiResponse.js
โโโ config/ # Configuration
โ โโโ config.js
โโโ migrations/ # Database migrations
โโโ app.js # Express application
- AES-256-GCM encryption with authenticated encryption
- Scrypt key derivation with unique salts per user
- Multi-layer security (user password + user ID + environment secret)
- Secure key rotation support
- bcrypt password hashing (12 rounds)
- JWT tokens with configurable expiration
- Email verification required for activation
- Input validation and sanitization
- Rate limiting support
- Unique constraints on email and username
- Input validation at model level
- Connection pooling with timeout controls
- SSL support for production databases
npm installnpm run dev # Start with nodemon
npm start # Start production server
npm run lint # Code linting (if configured)# Generate migration
npx sequelize-cli migration:generate --name migration-name
# Run migrations
npx sequelize-cli db:migrate
# Rollback migration
npx sequelize-cli db:migrate:undoNODE_ENV=production
DB_SSL=true
# Use strong, unique secrets
JWT_SECRET=$(openssl rand -base64 64)
ENCRYPTION_SECRET=$(openssl rand -base64 32)- Use HTTPS in production
- Enable database SSL
- Set up proper CORS policies
- Implement rate limiting
- Use environment-specific RPC URLs
- Enable comprehensive logging
- Set up monitoring and alerts
- Regular security audits
- Database: PostgreSQL with connection pooling
- Reverse Proxy: Nginx with SSL termination
- Process Manager: PM2 for Node.js clustering
- Monitoring: Winston + external monitoring service
- Caching: Redis for session storage
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the GitHub repository
- Check existing documentation
- Review the security recommendations
- Multi-factor authentication (2FA)
- Hardware wallet integration
- Advanced wallet operations
- Comprehensive test suite
- GraphQL API option
- Multi-chain support
Built with โค๏ธ for secure Web3 applications