(()=>{var e={"./node_modules/loglevel/lib/loglevel.js":function(e,t,n){var o,r;!function(){"use strict";o=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"],r={},i=null;function a(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function c(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function l(o){return"debug"===o&&(o="log"),typeof console!==t&&("trace"===o&&n?c:void 0!==console[o]?a(console,o):void 0!==console.log?a(console,"log"):e)}function s(){for(var n=this.getLevel(),r=0;r=0&&t<=u.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?f+=":"+e:"symbol"==typeof e&&(f=void 0),u.name=e,u.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},u.methodFactory=n||d,u.getLevel=function(){return null!=l?l:null!=c?c:a},u.setLevel=function(e,t){return l=v(e),!1!==t&&p(l),s.call(u)},u.setDefaultLevel=function(e){c=v(e),y()||u.setLevel(e,!1)},u.resetLevel=function(){l=null,w(),s.call(u)},u.enableAll=function(e){u.setLevel(u.levels.TRACE,e)},u.disableAll=function(e){u.setLevel(u.levels.SILENT,e)},u.rebuild=function(){if(i!==u&&(a=v(i.getLevel())),s.call(u),i===u)for(var e in r)r[e].rebuild()},a=v(i?i.getLevel():"WARN");var g=y();null!=g&&(l=v(g)),s.call(u)}(i=new f).getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=r[e];return t||(t=r[e]=new f(e,i.methodFactory)),t};var p=typeof window!==t?window.log:void 0;return i.noConflict=function(){return typeof window!==t&&window.log===i&&(window.log=p),i},i.getLoggers=function(){return r},i.default=i,i},void 0===(r="function"==typeof o?o.call(t,n,t,e):o)||(e.exports=r)}()}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{if(void 0!==n){var e=n.u,t=n.e,o={},r={};n.u=function(t){return e(t)+(o.hasOwnProperty(t)?"?"+o[t]:"")},n.e=function(i){return t(i).catch(function(t){var a=r.hasOwnProperty(i)?r[i]:3;if(a<1){var c=e(i);throw t.message="Loading chunk "+i+" failed after 3 retries.\n("+c+")",t.request=c,t}return new Promise(function(e){setTimeout(function(){var t=Date.now();o[i]=t,r[i]=a-1,e(n.e(i))},500)})})}}})(),(()=>{"use strict";function e(){try{var e;return null!==(e=self)&&void 0!==e&&e.indexedDB?self.indexedDB:window.indexedDB}catch{}}let t=null;async function o(){if(!e())throw new Error("IndexedDB not available");t=await new Promise((t,n)=>{const o=e().open("matrix-react-sdk",1);o.onerror=n,o.onsuccess=()=>{t(o.result)},o.onupgradeneeded=()=>{const e=o.result;e.createObjectStore("pickleKey"),e.createObjectStore("account")}})}async function r(e,n,r){return t||await o(),new Promise((o,i)=>{const a=t.transaction([e],n);a.onerror=i;const c=a.objectStore(e),l=r(c);l.onerror=i,l.onsuccess=()=>{o(l.result)}})}async function i(e,n){return t||await o(),r(e,"readonly",e=>e.get(n))}var a=n("./node_modules/loglevel/lib/loglevel.js"),c=n.n(a);c().methodFactory=function(e,t,n){return function(...t){this.prefix&&t.unshift(this.prefix);return"error"===e||"warn"===e||"trace"===e||"info"===e||"debug"===e?console[e](...t):console.log(...t)}};const l=function e(t){const n="matrix"+(void 0===t?"":`-${t}`),o=c().getLogger(n);return void 0===o.getChild&&(o.prefix=t,o.getChild=n=>{const r=e((null!=t?t:"")+n);return r.methodFactory=o.methodFactory,r.rebuild(),r},o.setLevel(c().levels.DEBUG,!1)),o}();function s(e,t){if("function"==typeof e.toBase64)return e.toBase64(t);let n=btoa(e.reduce((e,t)=>e+String.fromCharCode(t),""));return t.omitPadding&&(n=n.replace(/={1,2}$/,"")),"base64url"===t.alphabet&&(n=n.replace(/\+/g,"-").replace(/\//g,"_")),n}function u(e){return function(e,t){return"function"==typeof Uint8Array.fromBase64?Uint8Array.fromBase64(e,t):Uint8Array.from(atob(e),e=>e.charCodeAt(0))}(e.replace(/-/g,"+").replace(/_/g,"/"),{alphabet:"base64",lastChunkHandling:"loose"})}const d=new Uint8Array(8);async function f(e,t,n){const[o,r]=await async function(e,t){const n=await globalThis.crypto.subtle.importKey("raw",e,{name:"HKDF"},!1,["deriveBits"]),o=await globalThis.crypto.subtle.deriveBits({name:"HKDF",salt:d,info:(new TextEncoder).encode(t),hash:"SHA-256"},n,512),r=o.slice(0,32),i=o.slice(32),a=globalThis.crypto.subtle.importKey("raw",r,{name:"AES-CTR"},!1,["encrypt","decrypt"]),c=globalThis.crypto.subtle.importKey("raw",i,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]);return Promise.all([a,c])}(t,n),i=u(e.ciphertext);if(!await globalThis.crypto.subtle.verify({name:"HMAC"},r,u(e.mac),i))throw new Error(`Error decrypting secret ${n}: bad MAC`);const a=await globalThis.crypto.subtle.decrypt({name:"AES-CTR",counter:u(e.iv),length:64},o,i);return(new TextDecoder).decode(new Uint8Array(a))}const p="access_token";async function y(e){const t=new Uint8Array(e.length);for(let n=0;n{e.waitUntil(skipWaiting())}),n.g.addEventListener("activate",e=>{e.waitUntil(clients.claim())}),n.g.addEventListener("fetch",e=>{if("GET"!==e.request.method)return;const t=new URL(e.request.url);(t.pathname.startsWith("/_matrix/media/v3/download")||t.pathname.startsWith("/_matrix/media/v3/thumbnail"))&&e.respondWith((async o=>{let r;try{const o=t.origin;await new Promise(e=>setTimeout(()=>e(),10*Math.random()));const a=await n.g.clients.get(e.clientId);r=await async function(e){const t=await i("account","mx_access_token"),{userId:o,deviceId:r,homeserver:a}=await async function(e){return new Promise((t,o)=>{const r=setTimeout(()=>o(new Error("timeout in postMessage")),1e3),i=Math.random().toString(36),a=e=>{var o;(null===(o=e.data)||void 0===o?void 0:o.responseKey)===i&&(clearTimeout(r),t(e.data),n.g.removeEventListener("message",a))};n.g.addEventListener("message",a),e.postMessage({responseKey:i,type:"userinfo"})})}(e),c=await i("pickleKey",[o,r]);if(c&&(!c.encrypted||!c.iv||!c.cryptoKey))throw new Error("SW: Invalid pickle key loaded - ignoring");try{const e=await v(c,o,r),n=await async function(e,t,n){if("string"==typeof t)return t;if(!e)throw new Error(`Error decrypting secret ${n}: no pickle key found.`);const o=await y(e),r=await f(t,o,n);return o.fill(0),r}(e,t,p);return{accessToken:n,homeserver:a}}catch(e){throw new Error("SW: Error decrypting access token.",{cause:e})}}(a);if(!(t.origin===new URL(r.homeserver).origin))throw new Error("Request appears to be for media endpoint but wrong homeserver!");await async function(e,t){var n,o;if((null===(n=g[e])||void 0===n?void 0:n.cacheExpiryTimeMs)>(new Date).getTime())return;const r=h(t),i=await(await fetch(`${e}/_matrix/client/versions`,r)).json();console.log(`[ServiceWorker] /versions response for '${e}': ${JSON.stringify(i)}`),g[e]={supportsAuthedMedia:Boolean(null==i||null===(o=i.versions)||void 0===o?void 0:o.includes("v1.11")),cacheExpiryTimeMs:(new Date).getTime()+72e5},console.log(`[ServiceWorker] serverSupportMap update for '${e}': ${JSON.stringify(g[e])}`)}(o,r.accessToken),g[o].supportsAuthedMedia&&r.accessToken&&(t.href=t.href.replace(/\/media\/v3\/(.*)\//,"/client/v1/media/$1/"))}catch(e){r=void 0,console.error("SW: Error in request rewrite.",e)}return fetch(t,h(null===(o=r)||void 0===o?void 0:o.accessToken))})())})})()})(); //# sourceMappingURL=sw.js.map