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

23
server/verify.js Normal file
View File

@@ -0,0 +1,23 @@
// server/verify.js
const { decrypt } = require('./utils/crypto');
const { hashLicenseKey } = require('./keygen');
const { getLicense } = require('./models/license');
const verifyLicenseKey = async (userId, token) => {
try {
const payload = decrypt(token);
if (payload.userId !== userId) return false;
const storedLicense = await getLicense(userId);
const hashed = hashLicenseKey(payload.rawKey);
if (storedLicense.hashed_key !== hashed) return false;
if (storedLicense.license_type !== 'one-time' && storedLicense.valid_until && new Date(storedLicense.valid_until) < new Date()) return false;
return true;
} catch (err) {
return false;
}
};
module.exports = { verifyLicenseKey };