import{c as C}from"./space-DBcSn32d.js";import{bR as U,b7 as l,bC as y,bB as w,bw as M,bn as d,ct as f}from"./index-6Jqoo2rk.js";const H=32,S=16,h=1e5;async function m(t,e){const o=new TextEncoder().encode(t);t="";const n=await crypto.subtle.importKey("raw",o,{name:"PBKDF2"},!1,["deriveBits"]),p=await crypto.subtle.deriveBits({name:"PBKDF2",salt:e,iterations:h,hash:"SHA-256"},n,256);return new Uint8Array(p)}async function b(t,e){const o=new TextEncoder().encode(t);t="";const n=await crypto.subtle.importKey("raw",o,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:e,iterations:h,hash:"SHA-256"},n,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}async function P(t){const e=crypto.getRandomValues(new Uint8Array(S)),r=crypto.getRandomValues(new Uint8Array(S)),o=await b(t,e),n=await m(t,r);return t="",{verificationHash:n,verificationSalt:r,encryptionSalt:e,encryptionKey:o}}function T(){const{rootScope:t,apiManagerProxy:e}=U();async function r(){d.temporarilyToggle(!1),await e.invoke("toggleCacheStorage",!1),await e.serviceMessagePort.invoke("toggleCacheStorage",!1)}async function o(){d.temporarilyToggle(!0),await e.invoke("toggleCacheStorage",!0),await e.serviceMessagePort.invoke("toggleCacheStorage",!0)}async function n(){await d.clearEncryptableStorages(),d.resetOpenEncryptableCacheStorages(),await Promise.all([e.invoke("resetEncryptableCacheStorages",void 0),e.serviceMessagePort.invoke("resetEncryptableCacheStorages",void 0)])}async function p(a){const{verificationHash:s,verificationSalt:i,encryptionSalt:u,encryptionKey:c}=await P(a);a="",await l.set({passcode:{verificationHash:s,verificationSalt:i,encryptionSalt:u}});const[,g]=f();await g("passcode","enabled",!0),await r(),await n();const v={isUsingPasscode:!0,encryptionKey:c};await e.invoke("toggleUsingPasscode",v),await e.serviceMessagePort.invoke("toggleUsingPasscode",{type:"full",...v}),t.dispatchEvent("toggle_using_passcode",!0),w.resolveDeferred(!0),y.save(c),await o(),await M.updateStorageForLegacy(null)}async function E(a){const s=await l.get("passcode",!1);if(!s?.verificationHash||!s?.verificationSalt)return!1;const i=await m(a,s.verificationSalt);return a="",C(i,s.verificationHash)}async function k(){const[,a]=f();await a("passcode","enabled",!1),t.dispatchEvent("toggle_using_passcode",!1),await r(),await n(),await e.invoke("toggleUsingPasscode",{isUsingPasscode:!1}),await e.serviceMessagePort.invoke("toggleUsingPasscode",{type:"full",isUsingPasscode:!1}),y.save(null),w.resolveDeferred(!1),await o(),l.delete("passcode")}async function K(a){const{verificationHash:s,verificationSalt:i,encryptionSalt:u,encryptionKey:c}=await P(a);a="";const g={verificationHash:s,verificationSalt:i,encryptionSalt:u};await r(),await n(),await e.invoke("changePasscode",{toStore:g,encryptionKey:c}),await e.serviceMessagePort.invoke("saveEncryptionKey",c),y.save(c),await o(),await l.set({passcode:g},!0)}async function A(a){const s=await l.get("passcode",!1);if(!s?.encryptionSalt)throw new Error("No encryption salt found in storage");const i=await b(a,s.encryptionSalt);a="",y.save(i),await e.invoke("saveEncryptionKey",i),await e.serviceMessagePort.invoke("toggleUsingPasscode",{type:"full",isUsingPasscode:!0,encryptionKey:i}),e.invokeVoid("toggleLockOthers",!1)}return{enablePasscode:p,isMyPasscode:E,disablePasscode:k,changePasscode:K,unlockWithPasscode:A}}export{H as M,T as u};
//# sourceMappingURL=actions-D_EjVM7_.js.map
