"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{a(o.next(t))}catch(t){r(t)}}function l(t){try{a(o.throw(t))}catch(t){r(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,l)}a((o=o.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isHostAllowed=void 0;const utils_1=require("./utils");function promisifyIECryptoRes(t){return"then"in t?t:new Promise((e=>{t.oncomplete=t=>{e(t.target.result)}}))}function str2ab(t){const e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let e=0,o=t.length;e<o;e++)n[e]=t.charCodeAt(e);return e}const getKey=()=>{const t=str2ab(atob("undefined"!=typeof REDOCLY_PUBLIC_KEY?REDOCLY_PUBLIC_KEY:"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMHjNir5fXx/ZXoaEeXQ5XyxbNJ4YJYczoCRdSkL6NLzw1FHnng5Vfcgk5+bvox9QRYRbuk84mA4f2NhywDbXKECAwEAAQ=="));return promisifyIECryptoRes(null===utils_1.cryptoLib||void 0===utils_1.cryptoLib?void 0:utils_1.cryptoLib.subtle.importKey("spki",t,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!0,["verify"]))};function textEncode(t){if(window.TextEncoder)return(new TextEncoder).encode(t);const e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n}function verify(t,e){return __awaiter(this,void 0,void 0,(function*(){return promisifyIECryptoRes(null===utils_1.cryptoLib||void 0===utils_1.cryptoLib?void 0:utils_1.cryptoLib.subtle.verify({name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},yield getKey(),str2ab(atob(e)),textEncode(t)))}))}function isHostAllowed(t,e){return!0===e||!(!Array.isArray(e)||"undefined"==typeof window)&&(!("localhost"!==t&&"127.0.0.1"!==t&&!t.endsWith(".localhost")&&!e.find((e=>e===t||t.endsWith("."+e))))||!!e.find((e=>{if(e.indexOf("*")!==e.lastIndexOf("*"))return;const[n,o]=e.split("*");return o&&t.startsWith(n)&&t.endsWith(o)&&o.split(".").length>2})))}function parse(t){return __awaiter(this,void 0,void 0,(function*(){if("development"===process.env.NODE_ENV)return{valid:!0,allowed:!0};const e=window.location.hostname;if(!t)return"localhost"===e||"127.0.0.1"===e||e.endsWith(".localhost")?{local:!0}:{};const[n,o]=t.split(".");let i;try{if(!(yield verify(atob(n),o)))return{valid:!1};i=JSON.parse(atob(n))}catch(t){return{valid:!1,cryptoMissing:!0}}return i.valid=!0,(!i.e||Date.now()/1e3>i.e)&&(i.expired=!0),i.allowed=isHostAllowed(e,i.h),i}))}exports.isHostAllowed=isHostAllowed,exports.default=parse;
//# sourceMappingURL=check.js.map