"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;