UNPKG

@trap_stevo/devlock

Version:

Protect modern web applications from inspection, tampering, and unauthorized access through real-time detection, checksum enforcement, and customizable response strategies. Monitor developer tools, block key combinations, freeze console output, and enforc

545 lines 28.7 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _regeneratorRuntime from "@babel/runtime/regenerator"; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); } function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); } function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); } function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); } function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; } function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } var _options = /*#__PURE__*/new WeakMap(); var _active = /*#__PURE__*/new WeakMap(); var _frameDriftScanStarted = /*#__PURE__*/new WeakMap(); var _devToolsTriggered = /*#__PURE__*/new WeakMap(); var _devToolsOpen = /*#__PURE__*/new WeakMap(); var _devToolsRaf = /*#__PURE__*/new WeakMap(); var _originalConsole = /*#__PURE__*/new WeakMap(); var _redirectTimeout = /*#__PURE__*/new WeakMap(); var _lastCheckTime = /*#__PURE__*/new WeakMap(); var _el = /*#__PURE__*/new WeakMap(); var _lastHeight = /*#__PURE__*/new WeakMap(); var _lastWidth = /*#__PURE__*/new WeakMap(); var _DevLock_brand = /*#__PURE__*/new WeakSet(); var _onKeyDown = /*#__PURE__*/new WeakMap(); var _onContextMenu = /*#__PURE__*/new WeakMap(); var _onBeforePrint = /*#__PURE__*/new WeakMap(); var _onDragStart = /*#__PURE__*/new WeakMap(); export var DevLock = /*#__PURE__*/function () { function DevLock() { var _this = this, _classPrivateFieldGet10, _classPrivateFieldGet11, _classPrivateFieldGet12, _classPrivateFieldGet13, _classPrivateFieldGet14, _classPrivateFieldGet15, _classPrivateFieldGet16, _classPrivateFieldGet17, _classPrivateFieldGet18, _classPrivateFieldGet19, _classPrivateFieldGet20, _classPrivateFieldGet21, _classPrivateFieldGet22, _classPrivateFieldGet23, _classPrivateFieldGet24, _classPrivateFieldGet25, _classPrivateFieldGet26, _classPrivateFieldGet27, _classPrivateFieldGet28, _classPrivateFieldGet29; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, DevLock); _classPrivateMethodInitSpec(this, _DevLock_brand); _classPrivateFieldInitSpec(this, _options, void 0); _classPrivateFieldInitSpec(this, _active, false); _classPrivateFieldInitSpec(this, _frameDriftScanStarted, false); _classPrivateFieldInitSpec(this, _devToolsTriggered, false); _classPrivateFieldInitSpec(this, _devToolsOpen, false); _classPrivateFieldInitSpec(this, _devToolsRaf, null); _classPrivateFieldInitSpec(this, _originalConsole, {}); _classPrivateFieldInitSpec(this, _redirectTimeout, null); _classPrivateFieldInitSpec(this, _lastCheckTime, null); _classPrivateFieldInitSpec(this, _el, null); _classPrivateFieldInitSpec(this, _lastHeight, window.outerHeight); _classPrivateFieldInitSpec(this, _lastWidth, window.outerWidth); _classPrivateFieldInitSpec(this, _onKeyDown, function (e) { var key = e.key.toUpperCase(); var comboKey = "".concat(e.ctrlKey, "-").concat(e.shiftKey, "-").concat(key); var blockedCombos = ["true-true-I", "true-false-U", "true-false-S", "true-true-J", "true-true-C", "false-false-F12"]; if (blockedCombos.includes(comboKey)) { var _classPrivateFieldGet2, _classPrivateFieldGet3; e.preventDefault(); e.stopPropagation(); (_classPrivateFieldGet2 = (_classPrivateFieldGet3 = _classPrivateFieldGet(_options, _this)).onBlockedShortcut) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.call(_classPrivateFieldGet3, comboKey); _assertClassBrand(_DevLock_brand, _this, _handleViolation).call(_this); } }); _classPrivateFieldInitSpec(this, _onContextMenu, function (e) { var _classPrivateFieldGet4, _classPrivateFieldGet5; e.preventDefault(); (_classPrivateFieldGet4 = (_classPrivateFieldGet5 = _classPrivateFieldGet(_options, _this)).onRightClick) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.call(_classPrivateFieldGet5, e); }); _classPrivateFieldInitSpec(this, _onBeforePrint, function (e) { var _classPrivateFieldGet6, _classPrivateFieldGet7; (_classPrivateFieldGet6 = (_classPrivateFieldGet7 = _classPrivateFieldGet(_options, _this)).onBeforePrint) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.call(_classPrivateFieldGet7, e); }); _classPrivateFieldInitSpec(this, _onDragStart, function (e) { var _classPrivateFieldGet8, _classPrivateFieldGet9; e.preventDefault(); (_classPrivateFieldGet8 = (_classPrivateFieldGet9 = _classPrivateFieldGet(_options, _this)).onDragStart) === null || _classPrivateFieldGet8 === void 0 || _classPrivateFieldGet8.call(_classPrivateFieldGet9, e); }); _classPrivateFieldSet(_options, this, options); (_classPrivateFieldGet11 = (_classPrivateFieldGet10 = _classPrivateFieldGet(_options, this)).devMode) !== null && _classPrivateFieldGet11 !== void 0 ? _classPrivateFieldGet11 : _classPrivateFieldGet10.devMode = false; (_classPrivateFieldGet13 = (_classPrivateFieldGet12 = _classPrivateFieldGet(_options, this)).redirectDebounce) !== null && _classPrivateFieldGet13 !== void 0 ? _classPrivateFieldGet13 : _classPrivateFieldGet12.redirectDebounce = 250; (_classPrivateFieldGet15 = (_classPrivateFieldGet14 = _classPrivateFieldGet(_options, this)).violationMethod) !== null && _classPrivateFieldGet15 !== void 0 ? _classPrivateFieldGet15 : _classPrivateFieldGet14.violationMethod = "redirect"; (_classPrivateFieldGet17 = (_classPrivateFieldGet16 = _classPrivateFieldGet(_options, this)).useTimingDetection) !== null && _classPrivateFieldGet17 !== void 0 ? _classPrivateFieldGet17 : _classPrivateFieldGet16.useTimingDetection = true; (_classPrivateFieldGet19 = (_classPrivateFieldGet18 = _classPrivateFieldGet(_options, this)).overlayMessage) !== null && _classPrivateFieldGet19 !== void 0 ? _classPrivateFieldGet19 : _classPrivateFieldGet18.overlayMessage = "⚠️ Unauthorized action detected."; (_classPrivateFieldGet21 = (_classPrivateFieldGet20 = _classPrivateFieldGet(_options, this)).overlayConfigurationSettings) !== null && _classPrivateFieldGet21 !== void 0 ? _classPrivateFieldGet21 : _classPrivateFieldGet20.overlayConfigurationSettings = {}; (_classPrivateFieldGet23 = (_classPrivateFieldGet22 = _classPrivateFieldGet(_options, this)).overlayNode) !== null && _classPrivateFieldGet23 !== void 0 ? _classPrivateFieldGet23 : _classPrivateFieldGet22.overlayNode = null; (_classPrivateFieldGet25 = (_classPrivateFieldGet24 = _classPrivateFieldGet(_options, this)).frameDrift) !== null && _classPrivateFieldGet25 !== void 0 ? _classPrivateFieldGet25 : _classPrivateFieldGet24.frameDrift = {}; (_classPrivateFieldGet27 = (_classPrivateFieldGet26 = _classPrivateFieldGet(_options, this).frameDrift).frameDriftDetections) !== null && _classPrivateFieldGet27 !== void 0 ? _classPrivateFieldGet27 : _classPrivateFieldGet26.frameDriftDetections = 5; var currentBrowser = _assertClassBrand(_DevLock_brand, this, _getBrowserType).call(this); (_classPrivateFieldGet29 = (_classPrivateFieldGet28 = _classPrivateFieldGet(_options, this)).sizeThresholds) !== null && _classPrivateFieldGet29 !== void 0 ? _classPrivateFieldGet29 : _classPrivateFieldGet28.sizeThresholds = { height: currentBrowser === "safari" ? 250 : 160, width: 250 }; if (!_classPrivateFieldGet(_options, this).externalURL || typeof _classPrivateFieldGet(_options, this).externalURL !== "string") { _classPrivateFieldGet(_options, this).externalURL = _assertClassBrand(_DevLock_brand, this, _getBrowserSafeHomepage).call(this); } } return _createClass(DevLock, [{ key: "start", value: function start() { var _this2 = this; if (_classPrivateFieldGet(_options, this).devMode) { return; } if (_classPrivateFieldGet(_active, this)) { return; } _classPrivateFieldSet(_active, this, true); _assertClassBrand(_DevLock_brand, this, _bindListeners).call(this, true); _assertClassBrand(_DevLock_brand, this, _watchDevTools).call(this, true); requestAnimationFrame(function () { setTimeout(function () { _assertClassBrand(_DevLock_brand, _this2, _detectDevTools).call(_this2, true); }, 100); }); if (_classPrivateFieldGet(_options, this).freezeConsole) { _assertClassBrand(_DevLock_brand, this, _freezeConsole).call(this); } if (_classPrivateFieldGet(_options, this).verifyChecksum) { _assertClassBrand(_DevLock_brand, this, _verifyChecksums).call(this); } } }, { key: "stop", value: function stop() { if (!_classPrivateFieldGet(_active, this)) { return; } _classPrivateFieldSet(_active, this, false); _assertClassBrand(_DevLock_brand, this, _bindListeners).call(this, false); if (_classPrivateFieldGet(_options, this).freezeConsole) { _assertClassBrand(_DevLock_brand, this, _restoreConsole).call(this); } cancelAnimationFrame(_classPrivateFieldGet(_devToolsRaf, this)); clearTimeout(_classPrivateFieldGet(_redirectTimeout, this)); } }, { key: "status", value: function status() { return { active: _classPrivateFieldGet(_active, this), devToolsOpen: _classPrivateFieldGet(_devToolsOpen, this) }; } }, { key: "checkNow", value: function checkNow() { _assertClassBrand(_DevLock_brand, this, _detectDevTools).call(this, true); } }, { key: "runViolationMethods", value: function runViolationMethods(methodString) { var methods = methodString.split(","); var _iterator = _createForOfIteratorHelper(methods), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var method = _step.value; var m = method.trim(); if (m === "redirect" && _classPrivateFieldGet(_options, this).redirectURL && _classPrivateFieldGet(_devToolsOpen, this)) { window.location.href = _classPrivateFieldGet(_options, this).redirectURL; } else if (m === "replace" && _classPrivateFieldGet(_devToolsOpen, this)) { window.location.replace("about:blank"); } else if (m === "blank" && _classPrivateFieldGet(_devToolsOpen, this)) { document.documentElement.innerHTML = ""; } else if (m === "close" && window.opener && _classPrivateFieldGet(_devToolsOpen, this)) { window.close(); } else if (m === "overlay" && _classPrivateFieldGet(_devToolsOpen, this)) { var overlay = void 0; if (_classPrivateFieldGet(_options, this).overlayNode instanceof HTMLElement) { overlay = _classPrivateFieldGet(_options, this).overlayNode.cloneNode(true); } else if (typeof _classPrivateFieldGet(_options, this).overlayNode === "string") { var wrapper = document.createElement("div"); wrapper.innerHTML = _classPrivateFieldGet(_options, this).overlayNode; overlay = wrapper.firstElementChild; } else { overlay = document.createElement("div"); overlay.style.position = "fixed"; overlay.style.display = "flex"; overlay.style.justifyContent = "center"; overlay.style.alignItems = "center"; overlay.style.overflow = "hidden"; overlay.style.pointerEvents = "all"; overlay.style.fontSize = "24px"; overlay.innerText = _classPrivateFieldGet(_options, this).overlayMessage; overlay.style.background = "black"; overlay.style.color = "white"; overlay.style.inset = 0; overlay.style.zIndex = 999999; overlay.style.padding = 0; overlay.style.bottom = 0; overlay.style.right = 0; overlay.style.left = 0; overlay.style.top = 0; overlay.style.margin = 0; for (var _i = 0, _Object$entries = Object.entries(_classPrivateFieldGet(_options, this).overlayConfigurationSettings); _i < _Object$entries.length; _i++) { var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1]; overlay.style[key] = value; } } if (overlay) { document.body.appendChild(overlay); } } else if (m === "external" && _classPrivateFieldGet(_devToolsOpen, this)) { var target = _classPrivateFieldGet(_options, this).externalURL; window.location.replace(target); } else if (m === "lockStorage" && _classPrivateFieldGet(_devToolsOpen, this)) { try { Object.defineProperty(window, "localStorage", { get: function get() { throw new Error("localStorage access blocked."); } }); Object.defineProperty(window, "sessionStorage", { get: function get() { throw new Error("sessionStorage access blocked."); } }); } catch (e) { console.warn("Did not apply storage lock ~", e); } } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } }]); }(); function _getBrowserType() { var ua = navigator.userAgent.toLowerCase(); if (ua.includes("safari") && !ua.includes("chrome") && !ua.includes("chromium")) { return "safari"; } return "other"; } function _getBrowserSafeHomepage() { var ua = navigator.userAgent; if (ua.includes("DuckDuckGo/")) { return "https://duckduckgo.com"; } if (ua.includes("OPR") || ua.includes("Opera")) { return "https://www.opera.com"; } if (ua.includes("Vivaldi")) { return "https://vivaldi.com"; } if (ua.includes("Brave")) { return "https://brave.com"; } if (ua.includes("SamsungBrowser")) { return "https://www.samsung.com"; } if (ua.includes("UCBrowser")) { return "https://www.ucweb.com"; } if (ua.includes("Edg")) { return "https://www.bing.com"; } if (ua.includes("Firefox")) { return "https://www.mozilla.org"; } if (ua.includes("Chrome")) { return "https://www.google.com"; } if (ua.includes("Safari")) { return "https://www.apple.com"; } return "https://example.com"; } function _bindListeners(enable) { var method = enable ? "addEventListener" : "removeEventListener"; document[method]("keydown", _classPrivateFieldGet(_onKeyDown, this)); document[method]("contextmenu", _classPrivateFieldGet(_onContextMenu, this)); document[method]("beforeprint", _classPrivateFieldGet(_onBeforePrint, this)); document[method]("dragstart", _classPrivateFieldGet(_onDragStart, this)); } function _watchDevTools() { var _this3 = this; var immediateCheck = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; if (immediateCheck) { _assertClassBrand(_DevLock_brand, this, _detectDevTools).call(this, true); } var _loop = function loop() { _assertClassBrand(_DevLock_brand, _this3, _detectDevTools).call(_this3); _classPrivateFieldSet(_devToolsRaf, _this3, requestAnimationFrame(function () { if (!_classPrivateFieldGet(_devToolsOpen, _this3)) { var _classPrivateFieldGet30, _classPrivateFieldGet31; (_classPrivateFieldGet30 = (_classPrivateFieldGet31 = _classPrivateFieldGet(_options, _this3)).onDevToolsClosed) === null || _classPrivateFieldGet30 === void 0 || _classPrivateFieldGet30.call(_classPrivateFieldGet31); } _loop(); })); }; _loop(); } function _startFrameDriftMonitor() { var _classPrivateFieldGet32, _this4 = this; var _ref = (_classPrivateFieldGet32 = _classPrivateFieldGet(_options, this).frameDrift) !== null && _classPrivateFieldGet32 !== void 0 ? _classPrivateFieldGet32 : {}, _ref$tolerance = _ref.tolerance, tolerance = _ref$tolerance === void 0 ? 200 : _ref$tolerance, _ref$consecutiveRequi = _ref.consecutiveRequired, consecutiveRequired = _ref$consecutiveRequi === void 0 ? 6 : _ref$consecutiveRequi, _ref$historyWindow = _ref.historyWindow, historyWindow = _ref$historyWindow === void 0 ? 20 : _ref$historyWindow, _ref$frameDriftDetect = _ref.frameDriftDetections, frameDriftDetections = _ref$frameDriftDetect === void 0 ? Infinity : _ref$frameDriftDetect, _ref$requiredHighDelt = _ref.requiredHighDeltas, requiredHighDeltas = _ref$requiredHighDelt === void 0 ? 6 : _ref$requiredHighDelt, _ref$enableDebugLog = _ref.enableDebugLog, enableDebugLog = _ref$enableDebugLog === void 0 ? false : _ref$enableDebugLog; var lastTime = performance.now(); var driftHistory = []; var consecutive = 0; var detections = 0; var _loop2 = function loop() { if (!_classPrivateFieldGet(_active, _this4)) { return; } var now = performance.now(); var delta = now - lastTime - 16; lastTime = now; detections++; driftHistory.push(delta); if (driftHistory.length > historyWindow) { driftHistory.shift(); } var highDriftCount = driftHistory.filter(function (d) { return d > tolerance; }).length; if (delta > tolerance) { consecutive++; } else { consecutive = 0; } if (enableDebugLog) { console.log("[DevLock] ~ Drift:", delta.toFixed(2), "| Highs:", highDriftCount, "| Consec:", consecutive); } if (highDriftCount >= requiredHighDeltas || consecutive >= consecutiveRequired) { _classPrivateFieldSet(_frameDriftScanStarted, _this4, false); _assertClassBrand(_DevLock_brand, _this4, _triggerDevToolsOpen).call(_this4); return; } if (detections >= frameDriftDetections) { var _classPrivateFieldGet33, _classPrivateFieldGet34; _classPrivateFieldSet(_frameDriftScanStarted, _this4, false); if (enableDebugLog) { console.log("[DevLock] ~ Frame drift detection limit reached."); } (_classPrivateFieldGet33 = (_classPrivateFieldGet34 = _classPrivateFieldGet(_options, _this4)).onFrameDriftTimeout) === null || _classPrivateFieldGet33 === void 0 || _classPrivateFieldGet33.call(_classPrivateFieldGet34); return; } requestAnimationFrame(_loop2); }; requestAnimationFrame(_loop2); } function _devToolsOpenBySize() { var _classPrivateFieldGet35 = _classPrivateFieldGet(_options, this).sizeThresholds, height = _classPrivateFieldGet35.height, width = _classPrivateFieldGet35.width; var heightGap = window.outerHeight - window.innerHeight; var widthGap = window.outerWidth - window.innerWidth; return widthGap > width || heightGap > height; } function _detectDevTools() { var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var suspiciousSize = _assertClassBrand(_DevLock_brand, this, _devToolsOpenBySize).call(this); var timingSuspicious = false; if (_classPrivateFieldGet(_options, this).useTimingDetection !== false) { var _classPrivateFieldGet36, _classPrivateFieldGet37; var now = performance.now(); var timeDelta = now - ((_classPrivateFieldGet36 = _classPrivateFieldGet(_lastCheckTime, this)) !== null && _classPrivateFieldGet36 !== void 0 ? _classPrivateFieldGet36 : now); _classPrivateFieldSet(_lastCheckTime, this, now); var timingThreshold = (_classPrivateFieldGet37 = _classPrivateFieldGet(_options, this).timingThreshold) !== null && _classPrivateFieldGet37 !== void 0 ? _classPrivateFieldGet37 : 200; timingSuspicious = timeDelta > timingThreshold; if (_classPrivateFieldGet(_options, this).devMode) { console.log("[DevLock] ~ Timing Check ~", { timeDelta: timeDelta, threshold: timingThreshold, timingSuspicious: timingSuspicious }); } } var suspiciousNow = force || suspiciousSize || timingSuspicious && suspiciousSize; _classPrivateFieldSet(_devToolsOpen, this, suspiciousNow); if (suspiciousNow) { _assertClassBrand(_DevLock_brand, this, _triggerDevToolsOpen).call(this); return; } if (_classPrivateFieldGet(_options, this).useFrameDrift === true && _classPrivateFieldGet(_frameDriftScanStarted, this) !== true) { _classPrivateFieldSet(_frameDriftScanStarted, this, true); _assertClassBrand(_DevLock_brand, this, _startFrameDriftMonitor).call(this); } } function _triggerDevToolsOpen() { var _classPrivateFieldGet38, _classPrivateFieldGet39; _classPrivateFieldSet(_devToolsOpen, this, true); if (_classPrivateFieldGet(_devToolsTriggered, this)) { return; } _classPrivateFieldSet(_devToolsTriggered, this, true); (_classPrivateFieldGet38 = (_classPrivateFieldGet39 = _classPrivateFieldGet(_options, this)).onDevToolsOpen) === null || _classPrivateFieldGet38 === void 0 || _classPrivateFieldGet38.call(_classPrivateFieldGet39); _assertClassBrand(_DevLock_brand, this, _handleViolation).call(this); } function _handleViolation() { var _this5 = this; if (typeof _classPrivateFieldGet(_options, this).onViolation === "function") { _classPrivateFieldGet(_options, this).onViolation(this.status()); } clearTimeout(_classPrivateFieldGet(_redirectTimeout, this)); if (!_classPrivateFieldGet(_devToolsOpen, this)) { return; } var instant = (_classPrivateFieldGet(_options, this).violationMethod || "").includes("external"); var delay = instant ? 0 : _classPrivateFieldGet(_options, this).redirectDebounce; _classPrivateFieldSet(_redirectTimeout, this, setTimeout(function () { if (_classPrivateFieldGet(_devToolsOpen, _this5)) { _this5.runViolationMethods(_classPrivateFieldGet(_options, _this5).violationMethod || "redirect"); } }, delay)); } function _freezeConsole() { var _this6 = this; var noop = function noop() {}; ["log", "warn", "error", "info", "debug", "trace", "dir"].forEach(function (method) { _classPrivateFieldGet(_originalConsole, _this6)[method] = console[method]; console[method] = noop; }); } function _restoreConsole() { for (var method in _classPrivateFieldGet(_originalConsole, this)) { console[method] = _classPrivateFieldGet(_originalConsole, this)[method]; } } function _verifyChecksums() { return _verifyChecksums2.apply(this, arguments); } function _verifyChecksums2() { _verifyChecksums2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var _this7 = this; var scripts, mode, expected; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.prev = 0; scripts = _toConsumableArray(document.scripts).filter(function (s) { return s.src; }); mode = _classPrivateFieldGet(_options, this).checksumMode || "fixed"; expected = _classPrivateFieldGet(_options, this).expectedChecksums || {}; _context2.next = 6; return Promise.all(scripts.map(/*#__PURE__*/function () { var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(script) { var src, res, content, hashBuffer, hash, _classPrivateFieldGet40, _classPrivateFieldGet41, key, stored, _classPrivateFieldGet42, _classPrivateFieldGet43; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: src = new URL(script.src, window.location.href).href; _context.next = 3; return fetch(src, { cache: "no-store" }); case 3: res = _context.sent; _context.next = 6; return res.text(); case 6: content = _context.sent; _context.next = 9; return crypto.subtle.digest("SHA-256", new TextEncoder().encode(content)); case 9: hashBuffer = _context.sent; hash = _toConsumableArray(new Uint8Array(hashBuffer)).map(function (b) { return b.toString(16).padStart(2, "0"); }).join(""); if (mode === "fixed" && expected[src] && expected[src] !== hash) { (_classPrivateFieldGet40 = (_classPrivateFieldGet41 = _classPrivateFieldGet(_options, _this7)).onChecksumMismatch) === null || _classPrivateFieldGet40 === void 0 || _classPrivateFieldGet40.call(_classPrivateFieldGet41, { src: src, actual: hash, expected: expected[src] }); _assertClassBrand(_DevLock_brand, _this7, _handleViolation).call(_this7); } if (mode === "dynamic") { key = "devlock_checksum::".concat(src); stored = sessionStorage.getItem(key); if (!stored) { sessionStorage.setItem(key, hash); } else if (stored !== hash) { (_classPrivateFieldGet42 = (_classPrivateFieldGet43 = _classPrivateFieldGet(_options, _this7)).onChecksumMismatch) === null || _classPrivateFieldGet42 === void 0 || _classPrivateFieldGet42.call(_classPrivateFieldGet43, { src: src, actual: hash, expected: stored }); _assertClassBrand(_DevLock_brand, _this7, _handleViolation).call(_this7); } } case 13: case "end": return _context.stop(); } }, _callee); })); return function (_x) { return _ref2.apply(this, arguments); }; }())); case 6: _context2.next = 11; break; case 8: _context2.prev = 8; _context2.t0 = _context2["catch"](0); console.warn("Did not verify checksum ~", _context2.t0); case 11: case "end": return _context2.stop(); } }, _callee2, this, [[0, 8]]); })); return _verifyChecksums2.apply(this, arguments); } ;