v.1.0.0. initial push of license-lib

This commit is contained in:
2025-03-19 09:37:30 -05:00
commit b22a1c973c
20 changed files with 433 additions and 0 deletions

26
server/index.js Normal file
View File

@@ -0,0 +1,26 @@
// 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'));