UNPKG

can-algorithm

Version:

Cortex Algorithm Numeral - Intelligent development automation tool

69 lines (57 loc) 1.94 kB
import crypto from 'crypto'; import os from 'os'; const LICENSE_PATTERN = /^CAN-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/; export function generateLicenseKey() { const segments = []; for (let i = 0; i < 3; i++) { const segment = crypto.randomBytes(2).toString('hex').toUpperCase(); segments.push(segment); } return `CAN-${segments.join('-')}`; } export async function validateLicense(key) { if (!LICENSE_PATTERN.test(key)) { return { valid: false, reason: 'Invalid license format' }; } return { valid: true, user: 'Licensed User', expiration: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), permissions: { commands: ['scan', 'ask', 'proj', 'crypt', 'custom'], max_requests_per_day: -1, enterprise_features: true } }; } export async function activateLicense(key, password) { if (password.length !== 12) { throw new Error('Password must be exactly 12 characters'); } if (!LICENSE_PATTERN.test(key)) { throw new Error('Invalid license format'); } return { success: true, user_id: crypto.randomBytes(8).toString('hex'), message: 'License activated successfully' }; } export async function deactivateLicense(key) { return { success: true, message: 'License deactivated' }; } function getMachineId() { const interfaces = os.networkInterfaces(); for (const name of Object.keys(interfaces)) { for (const iface of interfaces[name]) { if (iface.mac && iface.mac !== '00:00:00:00:00:00') { return crypto.createHash('sha256').update(iface.mac).digest('hex'); } } } return crypto.createHash('sha256').update(os.hostname()).digest('hex'); } export { LICENSE_PATTERN };