// server/index.js const express = require('express'); const { generateLicenseKey, hashLicenseKey } = require('./keygen'); const { saveLicense } = require('./models/license'); const { verifyLicenseKey } = require('./verify'); const app = express(); app.use(express.json()); app.post('/generate-license', async (req, res) => { const { userId, licenseType, tier, validUntil } = req.body; const licenseKey = generateLicenseKey(userId, licenseType, tier); const hashedKey = hashLicenseKey(JSON.parse(Buffer.from(licenseKey.split('.')[1], 'base64')).rawKey); await saveLicense(userId, hashedKey, licenseType, tier, validUntil); res.json({ licenseKey }); }); app.post('/validate-license', async (req, res) => { const { userId, licenseKey } = req.body; const valid = await verifyLicenseKey(userId, licenseKey); res.json({ valid }); }); app.listen(3000, () => console.log('License server running on port 3000'));