@igor-lemon/secure-electron-license-keys
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -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={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; | ||
"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||e&&a.existsSync(e)){var g=c.publicKey||a.readFileSync(e);if(g&&(d.publicKeyExists=!0),a.existsSync(f)){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.1", | ||
"version": "1.2.2", | ||
"description": "Create and implement offline license key verification for your Electron apps.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -43,3 +43,3 @@ const path = require("path"); | ||
// Validate files exist | ||
if ((options.publicKey || fs.existsSync(publicKeyPath)) && fs.existsSync(licenseDataPath)) { | ||
if (options.publicKey || (publicKeyPath && fs.existsSync(publicKeyPath))) { | ||
const publicKey = options.publicKey || fs.readFileSync(publicKeyPath); | ||
@@ -51,13 +51,15 @@ | ||
const licenseData = fs.readFileSync(licenseDataPath); | ||
if (fs.existsSync(licenseDataPath)) { | ||
const licenseData = fs.readFileSync(licenseDataPath); | ||
if (licenseData) { | ||
validationResult.licenseExists = true; | ||
} | ||
if (licenseData) { | ||
validationResult.licenseExists = true; | ||
} | ||
// Attempt to read license data with the public key | ||
const decrypted = crypto.publicDecrypt(publicKey, licenseData); | ||
// Attempt to read license data with the public key | ||
const decrypted = crypto.publicDecrypt(publicKey, licenseData); | ||
validationResult.data = JSON.parse(decrypted.toString("utf8")); | ||
validationResult.valid = true; | ||
validationResult.data = JSON.parse(decrypted.toString("utf8")); | ||
validationResult.valid = true; | ||
} | ||
} else { | ||
@@ -64,0 +66,0 @@ validationResult.publicKeyExists = false; |
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
15861
105