-
Notifications
You must be signed in to change notification settings - Fork 661
/
Copy pathactions-O9QOCban.js
2 lines (2 loc) · 3.29 KB
/
actions-O9QOCban.js
1
2
import{T as A,o as l,bU as f,eT as v,eV as y,q as M,f5 as u}from"./index-BisvWswr.js";const B=12,w=16;function b(a,e){return a.length===e.length&&a.every((n,t)=>n===e[t])}const h=1e5;async function P(a,e){const t=new TextEncoder().encode(a);a="";const i=await crypto.subtle.importKey("raw",t,{name:"PBKDF2"},!1,["deriveBits"]),d=await crypto.subtle.deriveBits({name:"PBKDF2",salt:e,iterations:h,hash:"SHA-256"},i,256);return new Uint8Array(d)}async function m(a,e){const t=new TextEncoder().encode(a);a="";const i=await crypto.subtle.importKey("raw",t,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:e,iterations:h,hash:"SHA-256"},i,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}async function S(a){const e=crypto.getRandomValues(new Uint8Array(w)),n=crypto.getRandomValues(new Uint8Array(w)),t=await m(a,e),i=await P(a,n);return a="",{verificationHash:i,verificationSalt:n,encryptionSalt:e,encryptionKey:t}}function D(){const{rootScope:a,apiManagerProxy:e}=A();async function n(){u.temporarilyToggle(!1),await e.invoke("toggleCacheStorage",!1),await e.serviceMessagePort.invoke("toggleCacheStorage",!1)}async function t(){u.temporarilyToggle(!0),await e.invoke("toggleCacheStorage",!0),await e.serviceMessagePort.invoke("toggleCacheStorage",!0)}async function i(){await u.clearEncryptableStorages()}async function d(s){const{verificationHash:o,verificationSalt:r,encryptionSalt:p,encryptionKey:c}=await S(s);s="",await l.set({passcode:{verificationHash:o,verificationSalt:r,encryptionSalt:p}}),await a.managers.appStateManager.setByKey(f("settings","passcode","enabled"),!0),await n(),await i();const g={isUsingPasscode:!0,encryptionKey:c};await e.invoke("toggleUsingPasscode",g),await e.serviceMessagePort.invoke("toggleUsingPasscode",g),a.dispatchEvent("toggle_using_passcode",!0),v.resolveDeferred(!0),y.save(c),await t(),await M.updateStorageForLegacy(null)}async function K(s){const o=await l.get("passcode",!1);if(!o?.verificationHash||!o?.verificationSalt)return!1;const r=await P(s,o.verificationSalt);return s="",b(r,o.verificationHash)}async function k(){a.managers.appStateManager.setByKey(f("settings","passcode","enabled"),!1),a.dispatchEvent("toggle_using_passcode",!1),await n(),await i(),await e.invoke("toggleUsingPasscode",{isUsingPasscode:!1}),await e.serviceMessagePort.invoke("toggleUsingPasscode",{isUsingPasscode:!1}),y.save(null),v.resolveDeferred(!1),await t(),l.delete("passcode")}async function E(s){const{verificationHash:o,verificationSalt:r,encryptionSalt:p,encryptionKey:c}=await S(s);s="";const g={verificationHash:o,verificationSalt:r,encryptionSalt:p};await n(),await i(),await e.invoke("changePasscode",{toStore:g,encryptionKey:c}),await e.serviceMessagePort.invoke("saveEncryptionKey",c),y.save(c),await t(),await l.set({passcode:g},!0)}async function U(s){const o=await l.get("passcode",!1);if(!o?.encryptionSalt)throw new Error("No encryption salt found in storage");const r=await m(s,o.encryptionSalt);s="",y.save(r),await e.invoke("saveEncryptionKey",r),await e.serviceMessagePort.invoke("toggleUsingPasscode",{isUsingPasscode:!0,encryptionKey:r}),e.invokeVoid("toggleLockOthers",!1),a.dispatchEvent("toggle_locked",!1)}return{enablePasscode:d,isMyPasscode:K,disablePasscode:k,changePasscode:E,unlockWithPasscode:U}}export{B as M,D as u};
//# sourceMappingURL=actions-O9QOCban.js.map