@igor-lemon/secure-electron-license-keys
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.clearMainBindings=exports.mainBindings=exports.preloadBindings=exports.validateLicenseResponse=exports.validateLicenseRequest=void 0;function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var path=require("path"),validateLicenseRequest="ValidateLicense-Request";exports.validateLicenseRequest=validateLicenseRequest;var validateLicenseResponse="ValidateLicense-Response";exports.validateLicenseResponse="ValidateLicense-Response";var parseVersion=function(a){if(!a||5>a.length)return console.warn("Could not parse version since ".concat(a," doesn't seem to follow semver specifications.")),a;var b=a.split(".");return 3===b.length?{major:b[0],minor:b[1],patch:b[2]}:a},validate=function(a,b,c){var d={success:!1,appVersion:parseVersion(c.version)},e=path.join(c.root,"public.key"),f=path.join(c.root,"license.data");try{if(a.existsSync(e)&&a.existsSync(f)){var g=a.readFileSync(e),h=a.readFileSync(f),i=b.publicDecrypt(g,h);Object.assign(d,JSON.parse(i.toString("utf8"))),d.success=!0}}catch(a){console.error(a)}return d},preloadBindings=function(a){return{send:function send(b){[validateLicenseRequest].includes(b)&&a.send(b)},onReceive:function onReceive(b,c){[validateLicenseResponse].includes(b)&&a.on(b,function(a,b){return c(b)})},clearRendererBindings:function clearRendererBindings(){a.removeAllListeners(validateLicenseResponse)}}};exports.preloadBindings=preloadBindings;var mainBindings=function(a,b,c,d,e){if(!e)throw"options must be defined in order for license key validation to work!";else if("undefined"==typeof e.root)throw"options must contain a value for 'root'. We suggest 'process.cwd()'.";else"undefined"==typeof e.version&&console.warn("By not passing a 'version' property, the client side code will not be able to make determinations based on this value. We suggest 'app.getVersion()'.");a.on(validateLicenseRequest,function(){var a=validate(c,d,e);b.webContents.send(validateLicenseResponse,a)})};exports.mainBindings=mainBindings;var clearMainBindings=function(a){a.removeAllListeners(validateLicenseRequest)};exports.clearMainBindings=clearMainBindings;var SecureElectronLicenseKeys=function a(){_classCallCheck(this,a)},_default=SecureElectronLicenseKeys;exports["default"]=_default; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.clearMainBindings=exports.mainBindings=exports.preloadBindings=exports.validateLicenseResponse=exports.validateLicenseRequest=void 0;function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var path=require("path"),validateLicenseRequest="ValidateLicense-Request";exports.validateLicenseRequest=validateLicenseRequest;var validateLicenseResponse="ValidateLicense-Response";exports.validateLicenseResponse="ValidateLicense-Response";var parseVersion=function(a){if(!a||5>a.length)return console.warn("Could not parse version since ".concat(a," doesn't seem to follow semver specifications.")),a;var b=a.split(".");return 3===b.length?{major:b[0],minor:b[1],patch:b[2]}:a},validate=function(a,b,c){var d={data:{},error:"",inlinePublicKey:!!c.publicKey,publicKeyExists:!1,licenseExists:!1,valid:!1,appVersion:parseVersion(c.version)},e=c.publicKey||c.publicKeyPath||path.join(c.root,"public.key"),f=c.licensePath||path.join(c.root,"license.data");try{if((c.publicKey||a.existsSync(e))&&a.existsSync(f)){var g=c.publicKey||a.readFileSync(e);g&&(d.publicKeyExists=!0);var h=a.readFileSync(f);h&&(d.licenseExists=!0);var i=b.publicDecrypt(g,h);d.data=JSON.parse(i.toString("utf8")),d.valid=!0}else d.publicKeyExists=!1}catch(a){d.error=a.message,console.error(a)}return d},preloadBindings=function(a){return{send:function send(b){[validateLicenseRequest].includes(b)&&a.send(b)},onReceive:function onReceive(b,c){[validateLicenseResponse].includes(b)&&a.on(b,function(a,b){return c(b)})},clearRendererBindings:function clearRendererBindings(){a.removeAllListeners(validateLicenseResponse)}}};exports.preloadBindings=preloadBindings;var mainBindings=function(a,b,c,d,e){if(!e)throw"options must be defined in order for license key validation to work!";else if("undefined"==typeof e.root)throw"options must contain a value for 'root'. We suggest 'process.cwd()'.";else"undefined"==typeof e.version&&console.warn("By not passing a 'version' property, the client side code will not be able to make determinations based on this value. We suggest 'app.getVersion()'.");a.on(validateLicenseRequest,function(){var a=validate(c,d,e);b.webContents.send(validateLicenseResponse,a)})};exports.mainBindings=mainBindings;var clearMainBindings=function(a){a.removeAllListeners(validateLicenseRequest)};exports.clearMainBindings=clearMainBindings;var SecureElectronLicenseKeys=function a(){_classCallCheck(this,a)},_default=SecureElectronLicenseKeys;exports["default"]=_default; |
{ | ||
"name": "@igor-lemon/secure-electron-license-keys", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Create and implement offline license key verification for your Electron apps.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -28,2 +28,7 @@ const path = require("path"); | ||
let validationResult = { | ||
data: {}, | ||
error: '', | ||
inlinePublicKey: !!options.publicKey, | ||
publicKeyExists: false, | ||
licenseExists: false, | ||
valid: false, | ||
@@ -41,11 +46,23 @@ appVersion: parseVersion(options.version) | ||
const publicKey = options.publicKey || fs.readFileSync(publicKeyPath); | ||
if (publicKey) { | ||
validationResult.publicKeyExists = true; | ||
} | ||
const licenseData = fs.readFileSync(licenseDataPath); | ||
if (licenseData) { | ||
validationResult.licenseExists = true; | ||
} | ||
// Attempt to read license data with the public key | ||
const decrypted = crypto.publicDecrypt(publicKey, licenseData); | ||
Object.assign(validationResult, JSON.parse(decrypted.toString("utf8"))); | ||
validationResult.data = JSON.parse(decrypted.toString("utf8")); | ||
validationResult.valid = true; | ||
} else { | ||
validationResult.publicKeyExists = false; | ||
} | ||
} catch (error) { | ||
validationResult.error = error.message; | ||
console.error(error); | ||
@@ -52,0 +69,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15777
103