internxt-crypto 0.0.8-alpha → 0.0.10-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/asymmetric-crypto.d.mts +41 -0
- package/dist/asymmetric-crypto.d.ts +41 -0
- package/dist/asymmetric-crypto.js +92 -0
- package/dist/asymmetric-crypto.js.map +1 -0
- package/dist/asymmetric-crypto.mjs +85 -0
- package/dist/asymmetric-crypto.mjs.map +1 -0
- package/dist/constants.d.mts +39 -0
- package/dist/constants.d.ts +39 -0
- package/dist/constants.js +80 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +42 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/derive-key.d.mts +91 -0
- package/dist/derive-key.d.ts +91 -0
- package/dist/derive-key.js +795 -0
- package/dist/derive-key.js.map +1 -0
- package/dist/derive-key.mjs +784 -0
- package/dist/derive-key.mjs.map +1 -0
- package/dist/email-crypto.d.mts +106 -0
- package/dist/email-crypto.d.ts +106 -0
- package/dist/email-crypto.js +1409 -0
- package/dist/email-crypto.js.map +1 -0
- package/dist/email-crypto.mjs +1381 -0
- package/dist/email-crypto.mjs.map +1 -0
- package/dist/email-search.d.mts +228 -0
- package/dist/email-search.d.ts +228 -0
- package/dist/email-search.js +605 -0
- package/dist/email-search.js.map +1 -0
- package/dist/email-search.mjs +580 -0
- package/dist/email-search.mjs.map +1 -0
- package/dist/email-service.d.mts +38 -0
- package/dist/email-service.d.ts +38 -0
- package/dist/email-service.js +154 -0
- package/dist/email-service.js.map +1 -0
- package/dist/email-service.mjs +147 -0
- package/dist/email-service.mjs.map +1 -0
- package/dist/hash.d.mts +59 -0
- package/dist/hash.d.ts +59 -0
- package/dist/hash.js +95 -0
- package/dist/hash.js.map +1 -0
- package/dist/hash.mjs +85 -0
- package/dist/hash.mjs.map +1 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +2697 -2054
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2138 -8187
- package/dist/index.mjs.map +1 -1
- package/dist/keystore-crypto.d.mts +66 -0
- package/dist/keystore-crypto.d.ts +66 -0
- package/dist/keystore-crypto.js +530 -0
- package/dist/keystore-crypto.js.map +1 -0
- package/dist/keystore-crypto.mjs +501 -0
- package/dist/keystore-crypto.mjs.map +1 -0
- package/dist/keystore-service.d.mts +82 -0
- package/dist/keystore-service.d.ts +82 -0
- package/dist/keystore-service.js +349 -0
- package/dist/keystore-service.js.map +1 -0
- package/dist/keystore-service.mjs +342 -0
- package/dist/keystore-service.mjs.map +1 -0
- package/dist/kyber768-B87rMQ7u.d.mts +30 -0
- package/dist/kyber768-B87rMQ7u.d.ts +30 -0
- package/dist/post-quantum-crypto.d.mts +72 -0
- package/dist/post-quantum-crypto.d.ts +72 -0
- package/dist/post-quantum-crypto.js +96 -0
- package/dist/post-quantum-crypto.js.map +1 -0
- package/dist/post-quantum-crypto.mjs +90 -0
- package/dist/post-quantum-crypto.mjs.map +1 -0
- package/dist/storage-service.d.mts +53 -0
- package/dist/storage-service.d.ts +53 -0
- package/dist/storage-service.js +70 -0
- package/dist/storage-service.js.map +1 -0
- package/dist/storage-service.mjs +67 -0
- package/dist/storage-service.mjs.map +1 -0
- package/dist/symmetric-crypto.d.mts +56 -0
- package/dist/symmetric-crypto.d.ts +56 -0
- package/dist/symmetric-crypto.js +142 -0
- package/dist/symmetric-crypto.js.map +1 -0
- package/dist/symmetric-crypto.mjs +134 -0
- package/dist/symmetric-crypto.mjs.map +1 -0
- package/dist/types.d.mts +102 -0
- package/dist/types.d.ts +102 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +12 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils-BDaK_d6T.d.ts +114 -0
- package/dist/utils-v34IRTIx.d.mts +114 -0
- package/dist/utils.d.mts +140 -0
- package/dist/utils.d.ts +140 -0
- package/dist/utils.js +313 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +273 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +83 -7
- package/dist/__vite-browser-external-Dyvby5gX.js +0 -2
- package/dist/__vite-browser-external-Dyvby5gX.js.map +0 -1
- package/dist/__vite-browser-external-l0sNRNKZ.mjs +0 -2
- package/dist/__vite-browser-external-l0sNRNKZ.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2055 +1,2698 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const je=require("hash-wasm"),Gt=require("buffer"),Di=require("uuid");var vr=typeof document<"u"?document.currentScript:null;const Le="AES-GCM",V=256,Ks=128,Os=16,Xt="AES-KW",De="raw",Rs="CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets",lt="X25519",Cs="CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore",Is="CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore",Ps="CRYPTO library 2025-07-30 16:20:00 key for account recovery",js="CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices",Bs="CRYPTO library 2025-08-27 17:08:00 derive one key from two keys",jr="CRYPTO library 2025-08-28 18:27:00 ratchet media key",Fs="CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys",Mi="CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys",Ui="CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys",Ns=3,Ls=4,Ds=65536,Ms=16,Us=32,nn="Identity keystore",sn="Encryption keystore",on="Key recovery keystroe",Hi="Current encrypted indices",zi=800,$i=1632,Yi=1184,Vi=2400,Ji=1568,Gi=3168,Xi=64,ut=256,Hs=6e8,Br=100,q="email",zs=1;async function cn(e,t){try{const r=await crypto.subtle.deriveBits({name:lt,public:e},t,V);return new Uint8Array(r)}catch(r){throw new Error("Failed to derive elliptic curve secret key",{cause:r})}}async function qt(){try{return await crypto.subtle.generateKey({name:lt},!0,["deriveBits"])}catch(e){throw new Error("Failed to generate elliptic curve key pair",{cause:e})}}async function Wt(e){try{const t=await crypto.subtle.exportKey("spki",e);return new Uint8Array(t)}catch(t){throw new Error("Failed to export public key",{cause:t})}}async function Zt(e){try{return await crypto.subtle.importKey("spki",e,{name:lt},!0,[])}catch(t){throw new Error("Failed to import public key",{cause:t})}}async function an(e){try{const t=await crypto.subtle.exportKey("pkcs8",e);return new Uint8Array(t)}catch(t){throw new Error("Failed to export private key",{cause:t})}}async function ln(e){try{return await crypto.subtle.importKey("pkcs8",e,{name:lt},!0,["deriveBits"])}catch(t){throw new Error("Failed to import private key",{cause:t})}}const qi=Object.freeze(Object.defineProperty({__proto__:null,deriveSecretKey:cn,exportPrivateKey:an,exportPublicKey:Wt,generateEccKeys:qt,importPrivateKey:ln,importPublicKey:Zt},Symbol.toStringTag,{value:"Module"}));function Qe(e){return Gt.Buffer.from(e).toString("hex")}function Qt(e){return new TextEncoder().encode(e)}function un(e){return new TextDecoder().decode(e)}function jt(e){return new Uint8Array(Gt.Buffer.from(e,"hex"))}function U(e){return Gt.Buffer.from(e).toString("base64")}function D(e){return new Uint8Array(Gt.Buffer.from(e,"base64"))}function _e(e){try{const t=U(e.iv),r=U(e.ciphertext),n=JSON.stringify({ciphertext:r,iv:t});return btoa(n)}catch(t){throw new Error("Failed to convert ciphertext to base64",{cause:t})}}function er(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.iv);return{ciphertext:D(r.ciphertext),iv:n}}catch(t){throw new Error("Failed to convert base64 to ciphertext",{cause:t})}}async function $s(e){try{const t=await Wt(e.userPublicKey),r=await an(e.userPrivateKey),n=JSON.stringify({userPublicKey:U(t),userPrivateKey:U(r)});return btoa(n)}catch(t){throw new Error("Failed to convert identity keys to base64",{cause:t})}}async function Ys(e){try{const t=await Wt(e.userPublicKey),r=await an(e.userPrivateKey),n=JSON.stringify({userPublicKey:U(t),userPrivateKey:U(r),userPublicKyberKey:U(e.userPublicKyberKey),userPrivateKyberKey:U(e.userPrivateKyberKey)});return btoa(n)}catch(t){throw new Error("Failed to convert identity keys to base64",{cause:t})}}function Vs(e){try{const t=_e(e.encryptedKeys),r=JSON.stringify({userID:e.userID,type:e.type.toString(),encryptedKeys:t});return btoa(r)}catch(t){throw new Error("Failed to convert encrypted keystore to base64",{cause:t})}}async function Js(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.userPublicKey),s=D(r.userPrivateKey),o=await Zt(n),i=await ln(s);return{userPublicKey:o,userPrivateKey:i}}catch(t){throw new Error("Failed convert base64 to idenity key",{cause:t})}}async function hn(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.userPublicKey),s=D(r.userPrivateKey),o=await Zt(n),i=await ln(s),c=D(r.userPublicKyberKey),a=D(r.userPrivateKyberKey);return{userPublicKey:o,userPrivateKey:i,userPublicKyberKey:c,userPrivateKyberKey:a}}catch(t){throw new Error("Failed to convert base64 to encryption key",{cause:t})}}function Gs(e){try{const t=atob(e),r=JSON.parse(t),n=er(r.encryptedKeys);return{userID:r.userID,type:r.type,encryptedKeys:n}}catch(t){throw new Error("Failed to convert base64 to encrypted keystore",{cause:t})}}function Xs(e){try{const t=JSON.stringify({olmKey:U(e.olmKey),pqKey:U(e.pqKey),index:e.index.toString(),userID:e.userID});return btoa(t)}catch(t){throw new Error("Failed to convert media keys to base64",{cause:t})}}async function Wi(e){try{const t=atob(e),r=JSON.parse(t);return{olmKey:D(r.olmKey),pqKey:D(r.pqKey),index:Number(r.index),userID:r.userID}}catch(t){throw new Error("Failed convert base64 to media keys",{cause:t})}}const Oe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Zi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Fr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Se(e,...t){if(!Zi(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Bt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function qs(e,t){Se(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ws(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function et(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function se(e,t){return e<<32-t|e>>>t}const Qi=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ec(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function tc(e){for(let t=0;t<e.length;t++)e[t]=ec(e[t]);return e}const $n=Qi?e=>e:tc,rc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ce={_0:48,_9:57,A:65,F:70,a:97,f:102};function Yn(e){if(e>=ce._0&&e<=ce._9)return e-ce._0;if(e>=ce.A&&e<=ce.F)return e-(ce.A-10);if(e>=ce.a&&e<=ce.f)return e-(ce.a-10)}function X(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(rc)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){const i=Yn(e.charCodeAt(o)),c=Yn(e.charCodeAt(o+1));if(i===void 0||c===void 0){const a=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+o)}n[s]=i*16+c}return n}function nc(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function tr(e){return typeof e=="string"&&(e=nc(e)),Se(e),e}class Zs{}function Qs(e){const t=n=>e().update(tr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function sc(e){const t=(n,s)=>e(s).update(tr(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}function eo(e=32){if(Oe&&typeof Oe.getRandomValues=="function")return Oe.getRandomValues(new Uint8Array(e));if(Oe&&typeof Oe.randomBytes=="function")return Uint8Array.from(Oe.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function oc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const s=BigInt(32),o=BigInt(4294967295),i=Number(r>>s&o),c=Number(r&o),a=n?4:0,l=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+l,c,n)}function ic(e,t,r){return e&t^~e&r}function cc(e,t,r){return e&t^e&r^t&r}class ac extends Zs{constructor(t,r,n,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Sr(this.buffer)}update(t){Bt(this),t=tr(t),Se(t);const{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){const c=Math.min(s-this.pos,o-i);if(c===s){const a=Sr(t);for(;s<=o-i;i+=s)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Bt(this),qs(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:s,isLE:o}=this;let{pos:i}=this;r[i++]=128,et(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let h=i;h<s;h++)r[h]=0;oc(n,s-8,BigInt(this.length*8),o),this.process(n,0);const c=Sr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<l;h++)c.setUint32(4*h,u[h],o)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=c,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}}const he=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),bt=BigInt(2**32-1),Vn=BigInt(32);function lc(e,t=!1){return t?{h:Number(e&bt),l:Number(e>>Vn&bt)}:{h:Number(e>>Vn&bt)|0,l:Number(e&bt)|0}}function uc(e,t=!1){const r=e.length;let n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){const{h:i,l:c}=lc(e[o],t);[n[o],s[o]]=[i,c]}return[n,s]}const hc=(e,t,r)=>e<<r|t>>>32-r,fc=(e,t,r)=>t<<r|e>>>32-r,dc=(e,t,r)=>t<<r-32|e>>>64-r,pc=(e,t,r)=>e<<r-32|t>>>64-r,yc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),fe=new Uint32Array(64);class mc extends ac{constructor(t=32){super(64,t,8,!1),this.A=he[0]|0,this.B=he[1]|0,this.C=he[2]|0,this.D=he[3]|0,this.E=he[4]|0,this.F=he[5]|0,this.G=he[6]|0,this.H=he[7]|0}get(){const{A:t,B:r,C:n,D:s,E:o,F:i,G:c,H:a}=this;return[t,r,n,s,o,i,c,a]}set(t,r,n,s,o,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let h=0;h<16;h++,r+=4)fe[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const m=fe[h-15],y=fe[h-2],p=se(m,7)^se(m,18)^m>>>3,f=se(y,17)^se(y,19)^y>>>10;fe[h]=f+fe[h-7]+p+fe[h-16]|0}let{A:n,B:s,C:o,D:i,E:c,F:a,G:l,H:u}=this;for(let h=0;h<64;h++){const m=se(c,6)^se(c,11)^se(c,25),y=u+m+ic(c,a,l)+yc[h]+fe[h]|0,f=(se(n,2)^se(n,13)^se(n,22))+cc(n,s,o)|0;u=l,l=a,a=c,c=i+y|0,i=o,o=s,s=n,n=y+f|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,s,o,i,c,a,l,u)}roundClean(){et(fe)}destroy(){this.set(0,0,0,0,0,0,0,0),et(this.buffer)}}const gc=Qs(()=>new mc);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ft(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function to(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(r=>typeof r=="string"):t.every(r=>Number.isSafeInteger(r)):!1}function wc(e){if(typeof e!="function")throw new Error("function expected");return!0}function Nt(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Me(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Lt(e){if(!Array.isArray(e))throw new Error("array expected")}function Dt(e,t){if(!to(!0,t))throw new Error(`${e}: array of strings expected`)}function ro(e,t){if(!to(!1,t))throw new Error(`${e}: array of numbers expected`)}function bc(...e){const t=o=>o,r=(o,i)=>c=>o(i(c)),n=e.map(o=>o.encode).reduceRight(r,t),s=e.map(o=>o.decode).reduce(r,t);return{encode:n,decode:s}}function Ec(e){const t=typeof e=="string"?e.split(""):e,r=t.length;Dt("alphabet",t);const n=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(Lt(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(Lt(s),s.map(o=>{Nt("alphabet.decode",o);const i=n.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function xc(e=""){return Nt("join",e),{encode:t=>(Dt("join.decode",t),t.join(e)),decode:t=>(Nt("join.decode",t),t.split(e))}}function kc(e,t="="){return Me(e),Nt("padding",t),{encode(r){for(Dt("padding.encode",r);r.length*e%8;)r.push(t);return r},decode(r){Dt("padding.decode",r);let n=r.length;if(n*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if((n-1)*e%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function Nr(e,t,r){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Lt(e),!e.length)return[];let n=0;const s=[],o=Array.from(e,c=>{if(Me(c),c<0||c>=t)throw new Error(`invalid integer: ${c}`);return c}),i=o.length;for(;;){let c=0,a=!0;for(let l=n;l<i;l++){const u=o[l],h=t*c,m=h+u;if(!Number.isSafeInteger(m)||h/t!==c||m-u!==h)throw new Error("convertRadix: carry overflow");const y=m/r;c=m%r;const p=Math.floor(y);if(o[l]=p,!Number.isSafeInteger(p)||p*r+c!==m)throw new Error("convertRadix: carry overflow");if(a)p?a=!1:n=l;else continue}if(s.push(c),a)break}for(let c=0;c<e.length-1&&e[c]===0;c++)s.push(0);return s.reverse()}const no=(e,t)=>t===0?e:no(t,e%t),Mt=(e,t)=>e+(t-no(e,t)),Tr=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Lr(e,t,r,n){if(Lt(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Mt(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${Mt(t,r)}`);let s=0,o=0;const i=Tr[t],c=Tr[r]-1,a=[];for(const l of e){if(Me(l),l>=i)throw new Error(`convertRadix2: invalid data word=${l} from=${t}`);if(s=s<<t|l,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=r;o-=r)a.push((s>>o-r&c)>>>0);const u=Tr[o];if(u===void 0)throw new Error("invalid carry");s&=u-1}if(s=s<<r-o&c,!n&&o>=t)throw new Error("Excess padding");if(!n&&s>0)throw new Error(`Non-zero padding: ${s}`);return n&&o>0&&a.push(s>>>0),a}function vc(e){Me(e);const t=2**8;return{encode:r=>{if(!Ft(r))throw new Error("radix.encode input should be Uint8Array");return Nr(Array.from(r),t,e)},decode:r=>(ro("radix.decode",r),Uint8Array.from(Nr(r,e,t)))}}function Sc(e,t=!1){if(Me(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Mt(8,e)>32||Mt(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Ft(r))throw new Error("radix2.encode input should be Uint8Array");return Lr(Array.from(r),8,e,!t)},decode:r=>(ro("radix2.decode",r),Uint8Array.from(Lr(r,e,8,t)))}}function Tc(e,t){return Me(e),wc(t),{encode(r){if(!Ft(r))throw new Error("checksum.encode: input should be Uint8Array");const n=t(r).slice(0,e),s=new Uint8Array(r.length+e);return s.set(r),s.set(n,r.length),s},decode(r){if(!Ft(r))throw new Error("checksum.decode: input should be Uint8Array");const n=r.slice(0,-e),s=r.slice(-e),o=t(n).slice(0,e);for(let i=0;i<e;i++)if(o[i]!==s[i])throw new Error("Invalid checksum");return n}}}const Et={alphabet:Ec,chain:bc,checksum:Tc,convertRadix:Nr,convertRadix2:Lr,radix:vc,radix2:Sc,join:xc,padding:kc};/*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const Ac=e=>e[0]==="あいこくしん";function _c(e){Se(e,16,20,24,28,32)}function Kc(e,t=128){if(Fr(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return Cc(eo(t/8),e)}const Oc=e=>{const t=8-e.length/4;return new Uint8Array([gc(e)[0]>>t<<t])};function Rc(e){if(!Array.isArray(e)||e.length!==2048||typeof e[0]!="string")throw new Error("Wordlist: expected array of 2048 strings");return e.forEach(t=>{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),Et.chain(Et.checksum(1,Oc),Et.radix2(11,!0),Et.alphabet(e))}function Cc(e,t){return _c(e),Rc(t).encode(e).join(Ac(t)?" ":" ")}const Ic=`abandon
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
catch
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
key
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
`);function so(e){return Kc(Ic,e)}const Pc=Object.freeze(Object.defineProperty({__proto__:null,UTF8ToUint8:Qt,base64ToCiphertext:er,base64ToEncryptedKeystore:Gs,base64ToEncryptionKeys:hn,base64ToIdentityKeys:Js,base64ToMediaKeys:Wi,base64ToUint8Array:D,ciphertextToBase64:_e,encryptedKeystoreToBase64:Vs,encryptionKeysToBase64:Ys,genMnemonic:so,hexToUint8Array:jt,identityKeysToBase64:$s,mediaKeysToBase64:Xs,uint8ArrayToBase64:U,uint8ArrayToHex:Qe,uint8ToUTF8:un},Symbol.toStringTag,{value:"Module"}));async function fn(e,t){try{const r=await je.createBLAKE3(e);r.init();for(const n of t)r.update(n);return r}catch(r){throw new Error("Failed to compute hash",{cause:r})}}async function jc(e,t,r){try{const n=await je.createBLAKE3(e,t);n.init();for(const s of r)n.update(s);return n}catch(n){throw new Error("Failed to compute keyed hash",{cause:n})}}async function Bc(e){try{return(await fn(ut,e)).digest()}catch(t){throw new Error("Failed to compute hash",{cause:t})}}async function oo(e,t){try{return(await fn(e,t)).digest("binary")}catch(r){throw new Error("Failed to get bits from data",{cause:r})}}async function Ue(e,t){try{return(await fn(e,[t])).digest("binary")}catch(r){throw new Error("Failed to get bits from string",{cause:r})}}async function Fc(e){try{const t=Xs(e),r=await oo(ut,[Fs,t]);return Qe(r)}catch(t){throw new Error("Failed to compute commitment to media keys",{cause:t})}}async function Nc(e,t){try{const r=await Ue(V,e);return(await jc(ut,r,t)).digest()}catch(r){throw new Error("Failed to compute mac",{cause:r})}}const Lc=Object.freeze(Object.defineProperty({__proto__:null,comitToMediaKey:Fc,computeMac:Nc,getBitsFromData:oo,getBitsFromString:Ue,hashData:Bc},Symbol.toStringTag,{value:"Module"}));async function rr(e){return crypto.subtle.importKey(De,new Uint8Array(e),{name:Le,length:V},!0,["encrypt","decrypt"])}async function Dc(e){try{const t=await crypto.subtle.exportKey(De,e);return new Uint8Array(t)}catch(t){throw new Error("Failed to export symmetric CryptoKey",{cause:t})}}async function dn(){return crypto.subtle.generateKey({name:Le,length:V},!0,["encrypt","decrypt"])}function Mc(){try{const e=new Uint8Array(V/8);return crypto.getRandomValues(e),e}catch(e){throw new Error("Failed to generate symmetric key",{cause:e})}}async function Uc(e){try{const t=await Ue(V,e);return rr(t)}catch(t){throw new Error("Failed to derive CryptoKey from the given key material",{cause:t})}}const Hc=BigInt(0),Je=BigInt(1),zc=BigInt(2),$c=BigInt(7),Yc=BigInt(256),Vc=BigInt(113),io=[],co=[],ao=[];for(let e=0,t=Je,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],io.push(2*(5*n+r)),co.push((e+1)*(e+2)/2%64);let s=Hc;for(let o=0;o<7;o++)t=(t<<Je^(t>>$c)*Vc)%Yc,t&zc&&(s^=Je<<(Je<<BigInt(o))-Je);ao.push(s)}const lo=uc(ao,!0),Jc=lo[0],Gc=lo[1],Jn=(e,t,r)=>r>32?dc(e,t,r):hc(e,t,r),Gn=(e,t,r)=>r>32?pc(e,t,r):fc(e,t,r);function Xc(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let i=0;i<10;i++)r[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const c=(i+8)%10,a=(i+2)%10,l=r[a],u=r[a+1],h=Jn(l,u,1)^r[c],m=Gn(l,u,1)^r[c+1];for(let y=0;y<50;y+=10)e[i+y]^=h,e[i+y+1]^=m}let s=e[2],o=e[3];for(let i=0;i<24;i++){const c=co[i],a=Jn(s,o,c),l=Gn(s,o,c),u=io[i];s=e[u],o=e[u+1],e[u]=a,e[u+1]=l}for(let i=0;i<50;i+=10){for(let c=0;c<10;c++)r[c]=e[i+c];for(let c=0;c<10;c++)e[i+c]^=~r[(c+2)%10]&r[(c+4)%10]}e[0]^=Jc[n],e[1]^=Gc[n]}et(r)}class nr extends Zs{constructor(t,r,n,s=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=r,this.outputLen=n,this.enableXOF=s,this.rounds=o,Fr(n),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Ws(this.state)}clone(){return this._cloneInto()}keccak(){$n(this.state32),Xc(this.state32,this.rounds),$n(this.state32),this.posOut=0,this.pos=0}update(t){Bt(this),t=tr(t),Se(t);const{blockLen:r,state:n}=this,s=t.length;for(let o=0;o<s;){const i=Math.min(r-this.pos,s-o);for(let c=0;c<i;c++)n[this.pos++]^=t[o++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:r,pos:n,blockLen:s}=this;t[n]^=r,(r&128)!==0&&n===s-1&&this.keccak(),t[s-1]^=128,this.keccak()}writeInto(t){Bt(this,!1),Se(t),this.finish();const r=this.state,{blockLen:n}=this;for(let s=0,o=t.length;s<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-s);t.set(r.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Fr(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(qs(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,et(this.state)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:s,rounds:o,enableXOF:i}=this;return t||(t=new nr(r,n,s,i,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=n,t.outputLen=s,t.enableXOF=i,t.destroyed=this.destroyed,t}}const uo=(e,t,r)=>Qs(()=>new nr(t,e,r)),qc=uo(6,136,256/8),Wc=uo(6,72,512/8),ho=(e,t,r)=>sc((n={})=>new nr(t,e,n.dkLen===void 0?r:n.dkLen,!0)),Zc=ho(31,168,128/8),fo=ho(31,136,256/8);/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */const le=Se,Ut=eo;function Xn(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function At(...e){const t=n=>typeof n=="number"?n:n.bytesLen,r=e.reduce((n,s)=>n+t(s),0);return{bytesLen:r,encode:n=>{const s=new Uint8Array(r);for(let o=0,i=0;o<e.length;o++){const c=e[o],a=t(c),l=typeof c=="number"?n[o]:c.encode(n[o]);le(l,a),s.set(l,i),typeof c!="number"&&l.fill(0),i+=a}return s},decode:n=>{le(n,r);const s=[];for(const o of e){const i=t(o),c=n.subarray(0,i);s.push(typeof o=="number"?c:o.decode(c)),n=n.subarray(i)}return s}}}function Ar(e,t){const r=t*e.bytesLen;return{bytesLen:r,encode:n=>{if(n.length!==t)throw new Error(`vecCoder.encode: wrong length=${n.length}. Expected: ${t}`);const s=new Uint8Array(r);for(let o=0,i=0;o<n.length;o++){const c=e.encode(n[o]);s.set(c,i),c.fill(0),i+=c.length}return s},decode:n=>{le(n,r);const s=[];for(let o=0;o<n.length;o+=e.bytesLen)s.push(e.decode(n.subarray(o,o+e.bytesLen)));return s}}}function xe(...e){for(const t of e)if(Array.isArray(t))for(const r of t)r.fill(0);else t.fill(0)}function qn(e){return(1<<e)-1}X("0609608648016503040201"),X("0609608648016503040202"),X("0609608648016503040203"),X("0609608648016503040204"),X("0609608648016503040205"),X("0609608648016503040206"),X("0609608648016503040207"),X("0609608648016503040208"),X("0609608648016503040209"),X("060960864801650304020A"),X("060960864801650304020B"),X("060960864801650304020C");async function Qc(e){try{if(!e)return Ut(Os);const t=new Uint8Array(16),r=Ut(12);t.set(r,0);const n=await Ue(32,e);return t.set(n,12),t}catch(t){throw new Error("Failed to create IV",{cause:t})}}async function po(e){return Ue(Ks,e)}async function ea(e,t,r,n){try{const s=await crypto.subtle.encrypt({name:Le,iv:r,additionalData:n},t,e);return new Uint8Array(s)}catch(s){throw new Error("Failed to encrypt symmetrically",{cause:s})}}async function ta(e,t,r,n){try{const s=await crypto.subtle.decrypt({name:Le,iv:t,additionalData:n},r,e);return new Uint8Array(s)}catch(s){throw new Error("Failed to decrypt symmetrically",{cause:s})}}async function sr(e,t,r,n){try{const s=await Qc(n),o=await po(r);return{ciphertext:await ea(t,e,s,o),iv:s}}catch(s){throw new Error("Failed to encrypt symmetrically",{cause:s})}}async function tt(e,t,r){try{const n=await po(r);return await ta(t.ciphertext,t.iv,e,n)}catch(n){throw new Error("Failed to decrypt symmetrically",{cause:n})}}const ra=Object.freeze(Object.defineProperty({__proto__:null,decryptSymmetrically:tt,deriveSymmetricCryptoKey:Uc,encryptSymmetrically:sr,exportSymmetricCryptoKey:Dc,genSymmetricCryptoKey:dn,genSymmetricKey:Mc,importSymmetricCryptoKey:rr},Symbol.toStringTag,{value:"Module"}));async function rt(e,t){try{const r=await je.blake3(e),n=jt(r),s=await je.blake3(t,V,n);return jt(s)}catch(r){throw new Error("Failed to derive key from base key and context",{cause:r})}}async function ht(e,t){try{if(t.length!=V/8)throw new Error(`Base key length must be exactly ${V/8} bytes`);if(!e)throw new Error("Context is empry");const r=await rt(e,t);return await rr(r)}catch(r){throw new Error("Failed to derive CryptoKey from base key and context",{cause:r})}}async function yo(e,t,r=Ns,n=Ls,s=Ds,o=Us){return je.argon2id({password:e,salt:t,parallelism:r,iterations:n,memorySize:s,hashLength:o,outputType:"binary"})}function na(){try{const e=new Uint8Array(Ms);return crypto.getRandomValues(e),e}catch(e){throw new Error("Failed to sample salt",{cause:e})}}async function mo(e,t,r){try{if(t.length!=V/8||e.length!=V/8)throw new Error(`Input key length must be exactly ${V/8} bytes`);const n=await je.blake3(e,ut,t);return await rt(r,n)}catch(n){throw new Error("Failed to derive symmetric key from two keys",{cause:n})}}async function pn(e){try{if(!e)throw new Error("No password given");const t=na();return{key:await yo(e,t),salt:t}}catch(t){throw new Error("Failed to derive key from password",{cause:t})}}async function yn(e,t){try{if(!t.length)throw new Error("No salt given");if(!e)throw new Error("No password given");return await yo(e,t)}catch(r){throw new Error("Failed to derive key from password and salt",{cause:r})}}async function sa(e){try{const{key:t,salt:r}=await pn(e);return{keyHex:Qe(t),saltHex:Qe(r)}}catch(t){throw new Error("Failed to derive key from password",{cause:t})}}async function go(e,t){try{const r=jt(t),n=await yn(e,r);return Qe(n)}catch(r){throw new Error("Failed to derive key from password and salt",{cause:r})}}async function oa(e,t,r){const n=await go(e,t);return r===n}async function wo(e,t){return await mo(e,t,Bs)}async function ia(e,t){try{const r=await wo(e,t);return await rr(r)}catch(r){throw new Error("Failed to derive symmetric CryptoKey from two keys",{cause:r})}}async function ca(e){try{const t=await rt(jr,e.olmKey),r=await rt(jr,e.pqKey),n=e.index+1,s=e.userID;return{olmKey:t,pqKey:r,index:n,userID:s}}catch(t){throw new Error("Failed to ratchet media key",{cause:t})}}const aa=Object.freeze(Object.defineProperty({__proto__:null,deriveSymmetricCryptoKeyFromContext:ht,deriveSymmetricCryptoKeyFromTwoKeys:ia,deriveSymmetricKeyFromContext:rt,deriveSymmetricKeyFromTwoKeys:wo,getKeyFromPassword:pn,getKeyFromPasswordAndSalt:yn,getKeyFromPasswordAndSaltHex:go,getKeyFromPasswordHex:sa,ratchetMediaKey:ca,verifyKeyFromPasswordHex:oa},Symbol.toStringTag,{value:"Module"}));function _t(e){try{const t=JSON.stringify(e);return btoa(t)}catch(t){throw new Error("Failed to convert User to base64",{cause:t})}}function Kt(e){try{const t=atob(e);return JSON.parse(t)}catch(t){throw new Error("Failed to convert base64 to User",{cause:t})}}function bo(e){try{const t=JSON.stringify(e);return Qt(t)}catch(t){throw new Error("Failed to convert EmailBody to Uint8Array",{cause:t})}}function mn(e){try{const t=un(e);return JSON.parse(t)}catch(t){throw new Error("Failed to convert Uint8Array to EmailBody",{cause:t})}}async function Eo(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.eccPublicKey),s=await Zt(n),o=D(r.kyberPublicKey);return{eccPublicKey:s,kyberPublicKey:o}}catch(t){throw new Error("Failed to convert base64 to PublicKeys",{cause:t})}}async function la(e){try{const t=await Wt(e.eccPublicKey),r=JSON.stringify({eccPublicKey:U(t),kyberPublicKey:U(e.kyberPublicKey)});return btoa(r)}catch(t){throw new Error("Failed to convert key of the type PublicKeys to base64",{cause:t})}}function xo(e){try{const t=JSON.stringify({kyberCiphertext:U(e.kyberCiphertext),encryptedKey:U(e.encryptedKey)});return btoa(t)}catch(t){throw new Error("Failed to convert hybrid key to base64",{cause:t})}}function ua(e){try{const t=atob(e),r=JSON.parse(t);return{encryptedKey:D(r.encryptedKey),kyberCiphertext:D(r.kyberCiphertext)}}catch(t){throw new Error("Failed to convert base64 to hybrid key",{cause:t})}}function ko(e){try{const t=JSON.stringify({encryptedKey:U(e.encryptedKey),salt:U(e.salt)});return btoa(t)}catch(t){throw new Error("Failed to convert password-protected key to base64",{cause:t})}}function ha(e){try{const t=atob(e),r=JSON.parse(t);return{encryptedKey:D(r.encryptedKey),salt:D(r.salt)}}catch(t){throw new Error("Failed to convert base64 to password-protected key",{cause:t})}}function fa(e){try{const t=JSON.stringify({...e,sender:_t(e.sender),recipient:_t(e.recipient),recipients:e.recipients?.map(_t)});return btoa(t)}catch(t){throw new Error("Failed to convert email public parameters to base64",{cause:t})}}function da(e){try{const t=atob(e),r=JSON.parse(t);return{...r,sender:Kt(r.sender),recipient:Kt(r.recipient),recipients:r.recipients?.map(Kt)}}catch(t){throw new Error("Failed to convert base64 to email params",{cause:t})}}function vo(e){try{const t=JSON.stringify({encryptedKey:xo(e.encryptedKey),enc:_e(e.enc),recipientID:e.recipientID});return btoa(t)}catch(t){throw new Error("Failed to convert hybrid email to base64",{cause:t})}}function So(e){try{const t=JSON.stringify({encryptedKey:ko(e.encryptedKey),enc:_e(e.enc)});return btoa(t)}catch(t){throw new Error("Failed to convert pwd protected email to base64",{cause:t})}}function To(e){try{const t=JSON.stringify(e);return Qt(t)}catch(t){throw new Error("Failed to convert EmailBody to Uint8Array",{cause:t})}}/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */function pa(e,t=8){const s=e.toString(2).padStart(8,"0").slice(-t).padStart(7,"0").split("").reverse().join("");return Number.parseInt(s,2)}const ya=e=>{const{newPoly:t,N:r,Q:n,F:s,ROOT_OF_UNITY:o,brvBits:i}=e,c=(f,d=n)=>{const b=f%d|0;return(b>=0?b|0:d+b|0)|0},a=(f,d=n)=>{const b=c(f,d)|0;return(b>d>>1?b-d|0:b)|0};function l(){const f=t(r);for(let d=0;d<r;d++){const b=pa(d,i),w=BigInt(o)**BigInt(b)%BigInt(n);f[d]=Number(w)|0}return f}const u=l(),h=128,m=1;return{mod:c,smod:a,nttZetas:u,NTT:{encode:f=>{for(let d=1,b=128;b>m;b>>=1)for(let w=0;w<r;w+=2*b){const E=u[d++];for(let x=w;x<w+b;x++){const k=c(E*f[x+b]);f[x+b]=c(f[x]-k)|0,f[x]=c(f[x]+k)|0}}return f},decode:f=>{for(let d=h-1,b=1+m;b<h+m;b<<=1)for(let w=0;w<r;w+=2*b){const E=u[d--];for(let x=w;x<w+b;x++){const k=f[x];f[x]=c(k+f[x+b]),f[x+b]=c(E*(f[x+b]-k))}}for(let d=0;d<f.length;d++)f[d]=c(s*f[d]);return f}},bitsCoder:(f,d)=>{const b=qn(f),w=f*(r/8);return{bytesLen:w,encode:E=>{const x=new Uint8Array(w);for(let k=0,v=0,S=0,T=0;k<E.length;k++)for(v|=(d.encode(E[k])&b)<<S,S+=f;S>=8;S-=8,v>>=8)x[T++]=v&qn(S);return x},decode:E=>{const x=t(r);for(let k=0,v=0,S=0,T=0;k<E.length;k++)for(v|=E[k]<<S,S+=8;S>=f;S-=f,v>>=f)x[T++]=d.decode(v&b);return x}}}}},ma=e=>(t,r)=>{r||(r=e.blockLen);const n=new Uint8Array(t.length+2);n.set(t);const s=t.length,o=new Uint8Array(r);let i=e.create({}),c=0,a=0;return{stats:()=>({calls:c,xofs:a}),get:(l,u)=>(n[s+0]=l,n[s+1]=u,i.destroy(),i=e.create({}).update(n),c++,()=>(a++,i.xofInto(o))),clean:()=>{i.destroy(),o.fill(0),n.fill(0)}}},ga=ma(Zc);/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */const Y=256,ue=3329,wa=3303,ba=17,{mod:nt,nttZetas:Ea,NTT:we,bitsCoder:xa}=ya({N:Y,Q:ue,F:wa,ROOT_OF_UNITY:ba,newPoly:e=>new Uint16Array(e),brvBits:7}),gn={512:{N:Y,Q:ue,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128},768:{N:Y,Q:ue,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192},1024:{N:Y,Q:ue,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256}},ka=e=>{if(e>=12)return{encode:r=>r,decode:r=>r};const t=2**(e-1);return{encode:r=>((r<<e)+ue/2)/ue,decode:r=>r*ue+t>>>e}},Ge=e=>xa(e,ka(e));function be(e,t){for(let r=0;r<Y;r++)e[r]=nt(e[r]+t[r])}function va(e,t){for(let r=0;r<Y;r++)e[r]=nt(e[r]-t[r])}function Sa(e,t,r,n,s){const o=nt(t*n*s+e*r),i=nt(e*n+t*r);return{c0:o,c1:i}}function xt(e,t){for(let r=0;r<Y/2;r++){let n=Ea[64+(r>>1)];r&1&&(n=-n);const{c0:s,c1:o}=Sa(e[2*r+0],e[2*r+1],t[2*r+0],t[2*r+1],n);e[2*r+0]=s,e[2*r+1]=o}return e}function Wn(e){const t=new Uint16Array(Y);for(let r=0;r<Y;){const n=e();if(n.length%3)throw new Error("SampleNTT: unaligned block");for(let s=0;r<Y&&s+3<=n.length;s+=3){const o=(n[s+0]>>0|n[s+1]<<8)&4095,i=(n[s+1]>>4|n[s+2]<<4)&4095;o<ue&&(t[r++]=o),r<Y&&i<ue&&(t[r++]=i)}}return t}function Xe(e,t,r,n){const s=e(n*Y/4,t,r),o=new Uint16Array(Y),i=Ws(s);let c=0;for(let a=0,l=0,u=0,h=0;a<i.length;a++){let m=i[a];for(let y=0;y<32;y++)u+=m&1,m>>=1,c+=1,c===n?(h=u,u=0):c===2*n&&(o[l++]=nt(h-u),u=0,c=0)}if(c)throw new Error(`sampleCBD: leftover bits: ${c}`);return o}const Ta=e=>{const{K:t,PRF:r,XOF:n,HASH512:s,ETA1:o,ETA2:i,du:c,dv:a}=e,l=Ge(1),u=Ge(a),h=Ge(c),m=At(Ar(Ge(12),t),32),y=Ar(Ge(12),t),p=At(Ar(h,t),u),f=At(32,32);return{secretCoder:y,secretKeyLen:y.bytesLen,publicKeyLen:m.bytesLen,cipherTextLen:p.bytesLen,keygen:d=>{le(d,32);const b=new Uint8Array(33);b.set(d),b[32]=t;const w=s(b),[E,x]=f.decode(w),k=[],v=[];for(let _=0;_<t;_++)k.push(we.encode(Xe(r,x,_,o)));const S=n(E);for(let _=0;_<t;_++){const C=we.encode(Xe(r,x,t+_,o));for(let O=0;O<t;O++){const j=Wn(S.get(O,_));be(C,xt(j,k[O]))}v.push(C)}S.clean();const T={publicKey:m.encode([v,E]),secretKey:y.encode(k)};return xe(E,x,k,v,b,w),T},encrypt:(d,b,w)=>{const[E,x]=m.decode(d),k=[];for(let O=0;O<t;O++)k.push(we.encode(Xe(r,w,O,o)));const v=n(x),S=new Uint16Array(Y),T=[];for(let O=0;O<t;O++){const j=Xe(r,w,t+O,i),L=new Uint16Array(Y);for(let M=0;M<t;M++){const B=Wn(v.get(O,M));be(L,xt(B,k[M]))}be(j,we.decode(L)),T.push(j),be(S,xt(E[O],k[O])),L.fill(0)}v.clean();const _=Xe(r,w,2*t,i);be(_,we.decode(S));const C=l.decode(b);return be(C,_),xe(E,k,S,_),p.encode([T,C])},decrypt:(d,b)=>{const[w,E]=p.decode(d),x=y.decode(b),k=new Uint16Array(Y);for(let v=0;v<t;v++)be(k,xt(x[v],we.encode(w[v])));return va(E,we.decode(k)),xe(k,x,w),l.encode(E)}}};function wn(e){const t=Ta(e),{HASH256:r,HASH512:n,KDF:s}=e,{secretCoder:o,cipherTextLen:i}=t,c=t.publicKeyLen,a=At(t.secretKeyLen,t.publicKeyLen,32,32),l=a.bytesLen,u=32;return{publicKeyLen:c,msgLen:u,keygen:(h=Ut(64))=>{le(h,64);const{publicKey:m,secretKey:y}=t.keygen(h.subarray(0,32)),p=r(m),f=a.encode([y,m,p,h.subarray(32)]);return xe(y,p),{publicKey:m,secretKey:f}},encapsulate:(h,m=Ut(32))=>{le(h,c),le(m,u);const y=h.subarray(0,384*e.K),p=o.encode(o.decode(y.slice()));if(!Xn(p,y))throw xe(p),new Error("ML-KEM.encapsulate: wrong publicKey modulus");xe(p);const f=n.create().update(m).update(r(h)).digest(),d=t.encrypt(h,m,f.subarray(32,64));return f.subarray(32).fill(0),{cipherText:d,sharedSecret:f.subarray(0,32)}},decapsulate:(h,m)=>{le(m,l),le(h,i);const[y,p,f,d]=a.decode(m),b=t.decrypt(h,y),w=n.create().update(b).update(f).digest(),E=w.subarray(0,32),x=t.encrypt(p,b,w.subarray(32,64)),k=Xn(h,x),v=s.create({dkLen:32}).update(d).update(h).digest();return xe(b,x,k?v:E),k?E:v}}}function Aa(e,t,r){return fo.create({dkLen:e}).update(t).update(new Uint8Array([r])).digest()}const bn={HASH256:qc,HASH512:Wc,KDF:fo,XOF:ga,PRF:Aa},En=wn({...bn,...gn[512]}),xn=wn({...bn,...gn[768]}),kn=wn({...bn,...gn[1024]});function vn(e){try{return xn.keygen(e)}catch(t){throw new Error("Failed to generate Kyber keys",{cause:t})}}function Ao(e){try{return xn.encapsulate(e)}catch(t){throw new Error("Failed to encapsulate",{cause:t})}}function _o(e,t){try{return xn.decapsulate(e,t)}catch(r){throw new Error("Failed to decapsulate",{cause:r})}}function _a(e){try{return En.keygen(e)}catch(t){throw new Error("Failed to generate Kyber keys",{cause:t})}}function Ka(e){try{return En.encapsulate(e)}catch(t){throw new Error("Failed to encapsulate",{cause:t})}}function Oa(e,t){try{return En.decapsulate(e,t)}catch(r){throw new Error("Failed to decapsulate",{cause:r})}}const Ra=Object.freeze(Object.defineProperty({__proto__:null,decapsulateKyber:Oa,encapsulateKyber:Ka,generateKyberKeys:_a},Symbol.toStringTag,{value:"Module"}));function Ca(e){try{return kn.keygen(e)}catch(t){throw new Error("Failed to generate Kyber keys",{cause:t})}}function Ia(e){try{return kn.encapsulate(e)}catch(t){throw new Error("Failed to encapsulate",{cause:t})}}function Pa(e,t){try{return kn.decapsulate(e,t)}catch(r){throw new Error("Failed to decapsulate",{cause:r})}}const ja=Object.freeze(Object.defineProperty({__proto__:null,decapsulateKyber:Pa,encapsulateKyber:Ia,generateKyberKeys:Ca},Symbol.toStringTag,{value:"Module"})),Ba=Object.freeze(Object.defineProperty({__proto__:null,decapsulateKyber:_o,encapsulateKyber:Ao,generateKyberKeys:vn,kyber1024:ja,kyber512:Ra},Symbol.toStringTag,{value:"Module"}));async function or(e){try{return await crypto.subtle.importKey(De,e,Xt,!1,["wrapKey","unwrapKey"])}catch(t){throw new Error("Failed to import wrapping key",{cause:t})}}async function Sn(e,t){try{if(e.length!==t.length)throw new Error("secrets must have equal length");const r=await mo(e,t,Rs);return await or(r)}catch(r){throw new Error("Failed to derive wrapping key",{cause:r})}}async function Tn(e,t){try{return await crypto.subtle.unwrapKey(De,e,t,Xt,Le,!1,["encrypt","decrypt"])}catch(r){throw new Error("Failed to unwrap key",{cause:r})}}async function An(e,t){try{const r=await crypto.subtle.wrapKey(De,e,t,Xt);return new Uint8Array(r)}catch(r){throw new Error("Failed to wrap key",{cause:r})}}const Fa=Object.freeze(Object.defineProperty({__proto__:null,deriveWrappingKey:Sn,importWrappingKey:or,unwrapKey:Tn,wrapKey:An},Symbol.toStringTag,{value:"Module"}));async function _n(e,t,r){try{const n=await dn();return{enc:await ir(e,n,t,r),encryptionKey:n}}catch(n){throw new Error("Failed to symmetrically encrypt email",{cause:n})}}async function Kn(e,t,r,n){try{const s=await dn(),o=await ir(e,s,r,n),i=Qt(t),c=await sr(s,i,r);return{enc:o,encryptionKey:s,subjectEnc:c}}catch(s){throw new Error("Failed to symmetrically encrypt email and subject",{cause:s})}}async function Ko(e,t,r,n){try{const s=await tt(r,e,n),o=await tt(r,t,n);return{body:mn(s),subject:un(o)}}catch(s){throw new Error("Failed to symmetrically decrypt email and subject",{cause:s})}}async function ir(e,t,r,n){try{const s=bo(e);return await sr(t,s,r,n)}catch(s){throw new Error("Failed to symmetrically encrypt email with the given key",{cause:s})}}async function cr(e,t,r){try{const n=await tt(t,e,r);return mn(n)}catch(n){throw new Error("Failed to symmetrically decrypt email",{cause:n})}}async function ar(e,t,r){try{const n=await cn(t.eccPublicKey,r.eccPrivateKey),{cipherText:s,sharedSecret:o}=Ao(t.kyberPublicKey),i=await Sn(n,o);return{encryptedKey:await An(e,i),kyberCiphertext:s}}catch(n){throw new Error("Failed to encrypt email key using hybrid encryption",{cause:n})}}async function Oo(e,t,r){try{const n=await cn(t.eccPublicKey,r.eccPrivateKey),s=_o(e.kyberCiphertext,r.kyberPrivateKey),o=await Sn(n,s);return await Tn(e.encryptedKey,o)}catch(n){throw new Error("Failed to decrypt email key encrypted via hybrid encryption",{cause:n})}}async function Ro(e,t){try{const{key:r,salt:n}=await pn(t),s=await or(r);return{encryptedKey:await An(e,s),salt:n}}catch(r){throw new Error("Failed to password-protect email key",{cause:r})}}async function Co(e,t){try{const r=await yn(t,e.salt),n=await or(r);return await Tn(e.encryptedKey,n)}catch(r){throw new Error("Failed to remove password-protection from email key",{cause:r})}}function ie(e){try{const{subject:t,replyToEmailID:r,sender:n,recipients:s}=e;return JSON.stringify({subject:t,replyToEmailID:r,sender:n,recipients:s})}catch(t){throw new Error("Failed to create aux",{cause:t})}}function He(e){try{const{replyToEmailID:t,sender:r,recipients:n}=e;return JSON.stringify({replyToEmailID:t,sender:r,recipients:n})}catch(t){throw new Error("Failed to create aux without subject",{cause:t})}}function Na(){return Di.v4()}async function La(e,t,r){try{const n=ie(e.params),{enc:s,encryptionKey:o}=await _n(e.body,n,e.params.id),i=await ar(o,t.publicKeys,r);return{enc:s,encryptedKey:i,recipientID:t.id,params:e.params}}catch(n){throw new Error("Failed to encrypt email with hybrid encryption",{cause:n})}}async function Da(e,t,r){try{const n=ie(e.params),{enc:s,encryptionKey:o}=await _n(e.body,n,e.params.id),i=[];for(const c of t){const a=await ar(o,c.publicKeys,r);i.push({enc:s,encryptedKey:a,recipientID:c.id,params:e.params})}return i}catch(n){throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption",{cause:n})}}async function Ma(e,t,r){try{const n=ie(e.params),s=await Oo(e.encryptedKey,t,r);return{body:await cr(e.enc,s,n),params:e.params}}catch(n){throw new Error("Failed to decrypt email with hybrid encryption",{cause:n})}}async function Ua(e,t,r){try{const n=He(e.params),{enc:s,encryptionKey:o,subjectEnc:i}=await Kn(e.body,e.params.subject,n,e.params.id),c=_e(i),a=await ar(o,t.publicKeys,r),l={...e.params,subject:c};return{enc:s,encryptedKey:a,recipientID:t.id,params:l}}catch(n){throw new Error("Failed to encrypt the email and its subject with hybrid encryption",{cause:n})}}async function Ha(e,t,r){try{const n=He(e.params),{enc:s,encryptionKey:o,subjectEnc:i}=await Kn(e.body,e.params.subject,n,e.params.id),c=_e(i),a=[];for(const l of t){const u=await ar(o,l.publicKeys,r),h={...e.params,subject:c};a.push({enc:s,encryptedKey:u,recipientID:l.id,params:h})}return a}catch(n){throw new Error("Failed to encrypt the email and its subject to multiple recipients with hybrid encryption",{cause:n})}}async function za(e,t,r){try{const n=He(e.params),s=await Oo(e.encryptedKey,t,r),o=er(e.params.subject),{body:i,subject:c}=await Ko(e.enc,o,s,n),a={...e.params,subject:c};return{body:i,params:a}}catch(n){throw new Error("Failed to decrypt the email and its subject with hybrid encryption",{cause:n})}}async function $a(e,t){try{if(!e?.body||!e.params)throw new Error("Failed to password-protect email: Invalid email structure");const r=ie(e.params),{enc:n,encryptionKey:s}=await _n(e.body,r,e.params.id),o=await Ro(s,t);return{enc:n,encryptedKey:o,params:e.params}}catch(r){throw new Error("Failed to password-protect email",{cause:r})}}async function Ya(e,t){try{const r=ie(e.params),n=await Co(e.encryptedKey,t);return{body:await cr(e.enc,n,r),params:e.params}}catch(r){throw new Error("Failed to decrypt password-protect email",{cause:r})}}async function Va(e,t){try{if(!e?.body||!e.params)throw new Error("Failed to password-protect email and subject: Invalid email structure");const r=He(e.params),{enc:n,encryptionKey:s,subjectEnc:o}=await Kn(e.body,e.params.subject,r,e.params.id),i=await Ro(s,t),c=_e(o),a={...e.params,subject:c};return{enc:n,encryptedKey:i,params:a}}catch(r){throw new Error("Failed to password-protect email and subject",{cause:r})}}async function Ja(e,t){try{const r=He(e.params),n=await Co(e.encryptedKey,t),s=er(e.params.subject),{body:o,subject:i}=await Ko(e.enc,s,n,r),c={...e.params,subject:i};return{body:o,params:c}}catch(r){throw new Error("Failed to decrypt password-protect email",{cause:r})}}async function Ga(){try{const e=vn(),t=await qt(),r={eccPrivateKey:t.privateKey,kyberPrivateKey:e.secretKey};return{publicKeys:{eccPublicKey:t.publicKey,kyberPublicKey:e.publicKey},privateKeys:r}}catch(e){throw new Error("Failed to generate keys for email service",{cause:e})}}const Xa=Object.freeze(Object.defineProperty({__proto__:null,base64ToEncHybridKey:ua,base64ToParams:da,base64ToPublicKey:Eo,base64ToPwdProtectedKey:ha,base64ToUser:Kt,binaryToEmailBody:mn,createPwdProtectedEmail:$a,createPwdProtectedEmailAndSubject:Va,decryptEmailAndSubjectHybrid:za,decryptEmailHybrid:Ma,decryptPwdProtectedEmail:Ya,decryptPwdProtectedEmailAndSubject:Ja,emailBodyToBinary:bo,emailToBinary:To,encHybridKeyToBase64:xo,encryptEmailAndSubjectHybrid:Ua,encryptEmailAndSubjectHybridForMultipleRecipients:Ha,encryptEmailHybrid:La,encryptEmailHybridForMultipleRecipients:Da,generateEmailID:Na,generateEmailKeys:Ga,getAux:ie,getAuxWithoutSubject:He,hybridEncyptedEmailToBase64:vo,paramsToBase64:fa,publicKeyToBase64:la,pwdProtectedEmailToBase64:So,pwdProtectedKeyToBase64:ko,userToBase64:_t},Symbol.toStringTag,{value:"Module"})),Dr=(e,t)=>t.some(r=>e instanceof r);let Zn,Qn;function qa(){return Zn||(Zn=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Wa(){return Qn||(Qn=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Mr=new WeakMap,_r=new WeakMap,lr=new WeakMap;function Za(e){const t=new Promise((r,n)=>{const s=()=>{e.removeEventListener("success",o),e.removeEventListener("error",i)},o=()=>{r(pe(e.result)),s()},i=()=>{n(e.error),s()};e.addEventListener("success",o),e.addEventListener("error",i)});return lr.set(t,e),t}function Qa(e){if(Mr.has(e))return;const t=new Promise((r,n)=>{const s=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",i),e.removeEventListener("abort",i)},o=()=>{r(),s()},i=()=>{n(e.error||new DOMException("AbortError","AbortError")),s()};e.addEventListener("complete",o),e.addEventListener("error",i),e.addEventListener("abort",i)});Mr.set(e,t)}let Ur={get(e,t,r){if(e instanceof IDBTransaction){if(t==="done")return Mr.get(e);if(t==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return pe(e[t])},set(e,t,r){return e[t]=r,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function Io(e){Ur=e(Ur)}function el(e){return Wa().includes(e)?function(...t){return e.apply(Hr(this),t),pe(this.request)}:function(...t){return pe(e.apply(Hr(this),t))}}function tl(e){return typeof e=="function"?el(e):(e instanceof IDBTransaction&&Qa(e),Dr(e,qa())?new Proxy(e,Ur):e)}function pe(e){if(e instanceof IDBRequest)return Za(e);if(_r.has(e))return _r.get(e);const t=tl(e);return t!==e&&(_r.set(e,t),lr.set(t,e)),t}const Hr=e=>lr.get(e);function rl(e,t,{blocked:r,upgrade:n,blocking:s,terminated:o}={}){const i=indexedDB.open(e,t),c=pe(i);return n&&i.addEventListener("upgradeneeded",a=>{n(pe(i.result),a.oldVersion,a.newVersion,pe(i.transaction),a)}),r&&i.addEventListener("blocked",a=>r(a.oldVersion,a.newVersion,a)),c.then(a=>{o&&a.addEventListener("close",()=>o()),s&&a.addEventListener("versionchange",l=>s(l.oldVersion,l.newVersion,l))}).catch(()=>{}),c}function nl(e,{blocked:t}={}){const r=indexedDB.deleteDatabase(e);return t&&r.addEventListener("blocked",n=>t(n.oldVersion,n)),pe(r).then(()=>{})}const sl=["get","getKey","getAll","getAllKeys","count"],ol=["put","add","delete","clear"],Kr=new Map;function es(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(Kr.get(t))return Kr.get(t);const r=t.replace(/FromIndex$/,""),n=t!==r,s=ol.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(s||sl.includes(r)))return;const o=async function(i,...c){const a=this.transaction(i,s?"readwrite":"readonly");let l=a.store;return n&&(l=l.index(c.shift())),(await Promise.all([l[r](...c),s&&a.done]))[0]};return Kr.set(t,o),o}Io(e=>({...e,get:(t,r,n)=>es(t,r)||e.get(t,r,n),has:(t,r)=>!!es(t,r)||e.has(t,r)}));const il=["continue","continuePrimaryKey","advance"],ts={},zr=new WeakMap,Po=new WeakMap,cl={get(e,t){if(!il.includes(t))return e[t];let r=ts[t];return r||(r=ts[t]=function(...n){zr.set(this,Po.get(this)[t](...n))}),r}};async function*al(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;const r=new Proxy(t,cl);for(Po.set(r,t),lr.set(r,Hr(t));t;)yield r,t=await(zr.get(r)||t.continue()),zr.delete(r)}function rs(e,t){return t===Symbol.asyncIterator&&Dr(e,[IDBIndex,IDBObjectStore,IDBCursor])||t==="iterate"&&Dr(e,[IDBIndex,IDBObjectStore])}Io(e=>({...e,get(t,r,n){return rs(t,r)?al:e.get(t,r,n)},has(t,r){return rs(t,r)||e.has(t,r)}}));const jo=e=>`ES:${e}:DB`,ll=async e=>{try{const t=jo(e);return rl(t,zs,{upgrade(r){r.objectStoreNames.contains(q)||r.createObjectStore(q,{keyPath:"params.id"}).createIndex("byTime","params.createdAt")}})}catch(t){throw new Error(`Cannot open a database for the user ${e}`,{cause:t})}},ul=e=>e.close(),hl=async e=>{const t=jo(e);return nl(t)},fl=async e=>ht(js,e),dl=async(e,t,r)=>{try{const n=ie(e.params),o={content:await ir(e.body,t,n,e.params.id),params:e.params};await r.put(q,o)}catch(n){throw new Error("Cannot encrypt and add the given email to the database",{cause:n})}},pl=async(e,t,r)=>{try{const n=await Promise.all(e.map(async o=>{const i=ie(o.params);return{content:await ir(o.body,t,i,o.params.id),params:o.params}})),s=r.transaction(q,"readwrite");await Promise.all([...n.map(o=>s.store.put(o)),s.done])}catch(n){throw new Error("Cannot encrypt and add emails to the database",{cause:n})}},On=async(e,t)=>{try{const r=ie(t.params);return{body:await cr(t.content,e,r),params:t.params}}catch(r){throw new Error("Cannot decrypt the given email",{cause:r})}},yl=async(e,t,r)=>{try{const n=await r.get(q,e);if(!n)throw new Error(`DB cannot find email with id ${e}`);return On(t,n)}catch(n){throw new Error(`Cannot fetch the email ${e} from the database`,{cause:n})}},ml=async(e,t)=>{try{const r=await t.getAll(q);return(await Promise.all(r.map(async s=>{const o=ie(s.params);return{body:await cr(s.content,e,o),params:s.params}}))).filter(s=>s!==null)}catch(r){throw new Error("Cannot fetch and decrypt all emails from the database",{cause:r})}},gl=async(e,t)=>{await t.delete(q,e)},Rn=async e=>await e.count(q),Bo=async(e,t)=>{try{const r=t.transaction(q,"readwrite");let s=await r.store.index("byTime").openCursor(),o=0;for(;s&&o<e;)await s.delete(),o++,s=await s.continue();await r.done}catch(r){throw new Error(`Cannot delete ${e} oldests emails from the database`,{cause:r})}},wl=async(e,t)=>{try{const r=await Rn(e);if(r<=t)return;await Bo(r-t,e)}catch(r){throw new Error(`Cannot enforce the maximum of ${t} emails on the database`,{cause:r})}},Fo=async(e,t,r)=>{try{const s=e.transaction(q,"readonly").store.index("byTime"),o=[];let i=await s.openCursor(null,r);for(;i;)o.push(i.value),i=await i.continue();return await Promise.all(o.map(a=>On(t,a)))}catch(n){throw new Error("Cannot fetch emails from database",{cause:n})}},No=async(e,t)=>Fo(e,t,"prev"),bl=async(e,t)=>Fo(e,t,"next"),Lo=async(e,t,r,n)=>{try{const o=e.transaction(q,"readonly").store.index("byTime"),i=[];let c;if(n){const h=IDBKeyRange.upperBound(n,!0);c=await o.openCursor(h,"prev")}else c=await o.openCursor(null,"prev");let a=0,l;for(;c&&a<r;)i.push(c.value),l=c.key,a++,c=await c.continue();return{emails:await Promise.all(i.map(h=>On(t,h))),nextCursor:a===r?l:void 0}}catch(s){throw new Error(`Cannot fetch email batch of ${r} from the database`,{cause:s})}};function Do(e){return To(e).byteLength}function El(){return{esCache:new Map,cacheSize:0,isCacheLimited:!1,isCacheReady:!0}}const xl=async(e,t)=>{const r=El();r.isCacheReady=!1;try{const n=await Rn(t);if(!n)return r.isCacheReady=!0,r;if(n<=Br){const s=await No(t,e);$r(s,r)}else{let s,o=!1;for(;!o;){const{emails:i,nextCursor:c}=await Lo(t,e,Br,s);if(!c||!i.length)break;s=c,$r(i,r)||(o=!0)}}return r}catch(n){throw new Error(`Email caching failed: ${n}`)}},Mo=async(e,t)=>{const r=t.esCache.get(e);if(!r)throw new Error(`Email not found in cache for ID: ${e}`);return r},kl=async(e,t)=>{try{const r=await Mo(e,t),n=Do(r);t.esCache.delete(e)&&(t.cacheSize-=n)}catch(r){throw new Error(`Failed to delete email with ID ${e}`,{cause:r})}};function $r(e,t){try{for(const r of e){const n=Uo(r,t);if(!n.success)return n}return{success:!0}}catch(r){throw new Error("Failed to add emails to the cache",{cause:r})}}const Uo=(e,t)=>{try{if(t.esCache.has(e.params.id))return{success:!1,reason:"email already exists in cache"};const r=Do(e);return t.cacheSize+r>Hs?(t.isCacheLimited=!0,{success:!1,reason:"hit cache limit"}):(t.esCache.set(e.params.id,e),t.cacheSize+=r,{success:!0})}catch(r){throw new Error("Failed to add email to the cache",{cause:r})}};var A;function H(e,t,r){const n=typeof r,s=typeof e;if(n!=="undefined"){if(s!=="undefined"){if(r){if(s==="function"&&n===s)return function(c){return e(r(c))};if(t=e.constructor,t===r.constructor){if(t===Array)return r.concat(e);if(t===Map){var o=new Map(r);for(var i of e)o.set(i[0],i[1]);return o}if(t===Set){i=new Set(r);for(o of e.values())i.add(o);return i}}}return e}return r}return s==="undefined"?t:e}function Re(e,t){return typeof e>"u"?t:e}function N(){return Object.create(null)}function Z(e){return typeof e=="string"}function st(e){return typeof e=="object"}function ot(e,t){if(Z(t))e=e[t];else for(let r=0;e&&r<t.length;r++)e=e[t[r]];return e}const vl=/[^\p{L}\p{N}]+/u,Sl=/(\d{3})/g,Tl=/(\D)(\d{3})/g,Al=/(\d{3})(\D)/g,ns=/[\u0300-\u036f]/g;function it(e={}){if(!this||this.constructor!==it)return new it(...arguments);if(arguments.length)for(e=0;e<arguments.length;e++)this.assign(arguments[e]);else this.assign(e)}A=it.prototype;A.assign=function(e){this.normalize=H(e.normalize,!0,this.normalize);let t=e.include,r=t||e.exclude||e.split,n;if(r||r===""){if(typeof r=="object"&&r.constructor!==RegExp){let s="";n=!t,t||(s+="\\p{Z}"),r.letter&&(s+="\\p{L}"),r.number&&(s+="\\p{N}",n=!!t),r.symbol&&(s+="\\p{S}"),r.punctuation&&(s+="\\p{P}"),r.control&&(s+="\\p{C}"),(r=r.char)&&(s+=typeof r=="object"?r.join(""):r);try{this.split=new RegExp("["+(t?"^":"")+s+"]+","u")}catch{this.split=/\s+/}}else this.split=r,n=r===!1||"a1a".split(r).length<2;this.numeric=H(e.numeric,n)}else{try{this.split=H(this.split,vl)}catch{this.split=/\s+/}this.numeric=H(e.numeric,H(this.numeric,!0))}if(this.prepare=H(e.prepare,null,this.prepare),this.finalize=H(e.finalize,null,this.finalize),r=e.filter,this.filter=typeof r=="function"?r:H(r&&new Set(r),null,this.filter),this.dedupe=H(e.dedupe,!0,this.dedupe),this.matcher=H((r=e.matcher)&&new Map(r),null,this.matcher),this.mapper=H((r=e.mapper)&&new Map(r),null,this.mapper),this.stemmer=H((r=e.stemmer)&&new Map(r),null,this.stemmer),this.replacer=H(e.replacer,null,this.replacer),this.minlength=H(e.minlength,1,this.minlength),this.maxlength=H(e.maxlength,1024,this.maxlength),this.rtl=H(e.rtl,!1,this.rtl),(this.cache=r=H(e.cache,!0,this.cache))&&(this.F=null,this.L=typeof r=="number"?r:2e5,this.B=new Map,this.D=new Map,this.I=this.H=128),this.h="",this.J=null,this.A="",this.K=null,this.matcher)for(const s of this.matcher.keys())this.h+=(this.h?"|":"")+s;if(this.stemmer)for(const s of this.stemmer.keys())this.A+=(this.A?"|":"")+s;return this};A.addStemmer=function(e,t){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(e,t),this.A+=(this.A?"|":"")+e,this.K=null,this.cache&&Te(this),this};A.addFilter=function(e){return typeof e=="function"?this.filter=e:(this.filter||(this.filter=new Set),this.filter.add(e)),this.cache&&Te(this),this};A.addMapper=function(e,t){return typeof e=="object"?this.addReplacer(e,t):e.length>1?this.addMatcher(e,t):(this.mapper||(this.mapper=new Map),this.mapper.set(e,t),this.cache&&Te(this),this)};A.addMatcher=function(e,t){return typeof e=="object"?this.addReplacer(e,t):e.length<2&&(this.dedupe||this.mapper)?this.addMapper(e,t):(this.matcher||(this.matcher=new Map),this.matcher.set(e,t),this.h+=(this.h?"|":"")+e,this.J=null,this.cache&&Te(this),this)};A.addReplacer=function(e,t){return typeof e=="string"?this.addMatcher(e,t):(this.replacer||(this.replacer=[]),this.replacer.push(e,t),this.cache&&Te(this),this)};A.encode=function(e,t){if(this.cache&&e.length<=this.H)if(this.F){if(this.B.has(e))return this.B.get(e)}else this.F=setTimeout(Te,50,this);this.normalize&&(typeof this.normalize=="function"?e=this.normalize(e):e=ns?e.normalize("NFKD").replace(ns,"").toLowerCase():e.toLowerCase()),this.prepare&&(e=this.prepare(e)),this.numeric&&e.length>3&&(e=e.replace(Tl,"$1 $2").replace(Al,"$1 $2").replace(Sl,"$1 "));const r=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let n=[],s=N(),o,i,c=this.split||this.split===""?e.split(this.split):[e];for(let l=0,u,h;l<c.length;l++)if((u=h=c[l])&&!(u.length<this.minlength||u.length>this.maxlength)){if(t){if(s[u])continue;s[u]=1}else{if(o===u)continue;o=u}if(r)n.push(u);else if(!this.filter||(typeof this.filter=="function"?this.filter(u):!this.filter.has(u))){if(this.cache&&u.length<=this.I)if(this.F){var a=this.D.get(u);if(a||a===""){a&&n.push(a);continue}}else this.F=setTimeout(Te,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+this.A+")$"));let m;for(;m!==u&&u.length>2;)m=u,u=u.replace(this.K,y=>this.stemmer.get(y))}if(u&&(this.mapper||this.dedupe&&u.length>1)){a="";for(let m=0,y="",p,f;m<u.length;m++)p=u.charAt(m),p===y&&this.dedupe||((f=this.mapper&&this.mapper.get(p))||f===""?f===y&&this.dedupe||!(y=f)||(a+=f):a+=y=p);u=a}if(this.matcher&&u.length>1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),u=u.replace(this.J,m=>this.matcher.get(m))),u&&this.replacer)for(a=0;u&&a<this.replacer.length;a+=2)u=u.replace(this.replacer[a],this.replacer[a+1]);if(this.cache&&h.length<=this.I&&(this.D.set(h,u),this.D.size>this.L&&(this.D.clear(),this.I=this.I/1.1|0)),u){if(u!==h)if(t){if(s[u])continue;s[u]=1}else{if(i===u)continue;i=u}n.push(u)}}}return this.finalize&&(n=this.finalize(n)||n),this.cache&&e.length<=this.H&&(this.B.set(e,n),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0)),n};function Te(e){e.F=null,e.B.clear(),e.D.clear()}function Cn(e,t,r){r||(t||typeof e!="object"?typeof t=="object"&&(r=t,t=0):r=e),r&&(e=r.query||e,t=r.limit||t);let n=""+(t||0);r&&(n+=(r.offset||0)+!!r.context+!!r.suggest+(r.resolve!==!1)+(r.resolution||this.resolution)+(r.boost||0)),e=(""+e).toLowerCase(),this.cache||(this.cache=new Ke);let s=this.cache.get(e+n);if(!s){const o=r&&r.cache;o&&(r.cache=!1),s=this.search(e,t,r),o&&(r.cache=o),this.cache.set(e+n,s)}return s}function Ke(e){this.limit=e&&e!==!0?e:1e3,this.cache=new Map,this.h=""}Ke.prototype.set=function(e,t){this.cache.set(this.h=e,t),this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};Ke.prototype.get=function(e){const t=this.cache.get(e);return t&&this.h!==e&&(this.cache.delete(e),this.cache.set(this.h=e,t)),t};Ke.prototype.remove=function(e){for(const t of this.cache){const r=t[0];t[1].includes(e)&&this.cache.delete(r)}};Ke.prototype.clear=function(){this.cache.clear(),this.h=""};const ss={normalize:!1,numeric:!1,dedupe:!1},kt={},Or=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]),os=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),is=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"],cs={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,ß:2,d:3,t:3,l:4,m:5,n:5,r:6};var Ho={Exact:ss,Default:kt,Normalize:kt,LatinBalance:{mapper:Or},LatinAdvanced:{mapper:Or,matcher:os,replacer:is},LatinExtra:{mapper:Or,replacer:is.concat([/(?!^)[aeo]/g,""]),matcher:os},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(e){for(let r=0;r<e.length;r++){var t=e[r];let n=t.charAt(0),s=cs[n];for(let o=1,i;o<t.length&&(i=t.charAt(o),i==="h"||i==="w"||!(i=cs[i])||i===s||(n+=i,s=i,n.length!==4));o++);e[r]=n}}},CJK:{split:""},LatinExact:ss,LatinDefault:kt,LatinSimple:kt};function as(e,t,r,n){let s=[];for(let o=0,i;o<e.index.length;o++)if(i=e.index[o],t>=i.length)t-=i.length;else{t=i[n?"splice":"slice"](t,r);const c=t.length;if(c&&(s=s.length?s.concat(t):t,r-=c,n&&(e.length-=c),!r))break;t=0}return s}function Be(e){if(!this||this.constructor!==Be)return new Be(e);this.index=e?[e]:[],this.length=e?e.length:0;const t=this;return new Proxy([],{get(r,n){if(n==="length")return t.length;if(n==="push")return function(s){t.index[t.index.length-1].push(s),t.length++};if(n==="pop")return function(){if(t.length)return t.length--,t.index[t.index.length-1].pop()};if(n==="indexOf")return function(s){let o=0;for(let i=0,c,a;i<t.index.length;i++){if(c=t.index[i],a=c.indexOf(s),a>=0)return o+a;o+=c.length}return-1};if(n==="includes")return function(s){for(let o=0;o<t.index.length;o++)if(t.index[o].includes(s))return!0;return!1};if(n==="slice")return function(s,o){return as(t,s||0,o||t.length,!1)};if(n==="splice")return function(s,o){return as(t,s||0,o||t.length,!0)};if(n==="constructor")return Array;if(typeof n!="symbol")return(r=t.index[n/2**31|0])&&r[n]},set(r,n,s){return r=n/2**31|0,(t.index[r]||(t.index[r]=[]))[n]=s,t.length++,!0}})}Be.prototype.clear=function(){this.index.length=0};Be.prototype.push=function(){};function Q(e=8){if(!this||this.constructor!==Q)return new Q(e);this.index=N(),this.h=[],this.size=0,e>32?(this.B=$o,this.A=BigInt(e)):(this.B=zo,this.A=e)}Q.prototype.get=function(e){const t=this.index[this.B(e)];return t&&t.get(e)};Q.prototype.set=function(e,t){var r=this.B(e);let n=this.index[r];n?(r=n.size,n.set(e,t),(r-=n.size)&&this.size++):(this.index[r]=n=new Map([[e,t]]),this.h.push(n),this.size++)};function ee(e=8){if(!this||this.constructor!==ee)return new ee(e);this.index=N(),this.h=[],this.size=0,e>32?(this.B=$o,this.A=BigInt(e)):(this.B=zo,this.A=e)}ee.prototype.add=function(e){var t=this.B(e);let r=this.index[t];r?(t=r.size,r.add(e),(t-=r.size)&&this.size++):(this.index[t]=r=new Set([e]),this.h.push(r),this.size++)};A=Q.prototype;A.has=ee.prototype.has=function(e){const t=this.index[this.B(e)];return t&&t.has(e)};A.delete=ee.prototype.delete=function(e){const t=this.index[this.B(e)];t&&t.delete(e)&&this.size--};A.clear=ee.prototype.clear=function(){this.index=N(),this.h=[],this.size=0};A.values=ee.prototype.values=function*(){for(let e=0;e<this.h.length;e++)for(let t of this.h[e].values())yield t};A.keys=ee.prototype.keys=function*(){for(let e=0;e<this.h.length;e++)for(let t of this.h[e].keys())yield t};A.entries=ee.prototype.entries=function*(){for(let e=0;e<this.h.length;e++)for(let t of this.h[e].entries())yield t};function zo(e){let t=2**this.A-1;if(typeof e=="number")return e&t;let r=0,n=this.A+1;for(let s=0;s<e.length;s++)r=(r*n^e.charCodeAt(s))&t;return this.A===32?r+2**31:r}function $o(e){let t=BigInt(2)**this.A-BigInt(1);var r=typeof e;if(r==="bigint")return e&t;if(r==="number")return BigInt(e)&t;r=BigInt(0);let n=this.A+BigInt(1);for(let s=0;s<e.length;s++)r=(r*n^BigInt(e.charCodeAt(s)))&t;return r}let Ce,qe;async function _l(e){e=e.data;var t=e.task;const r=e.id;let n=e.args;switch(t){case"init":qe=e.options||{},(t=e.factory)?(Function("return "+t)()(self),Ce=new self.FlexSearch.Index(qe),delete self.FlexSearch):Ce=new te(qe),postMessage({id:r});break;default:let s;t==="export"&&(n[1]?(n[0]=qe.export,n[2]=0,n[3]=1):n=null),t==="import"?n[0]&&(e=await qe.import.call(Ce,n[0]),Ce.import(n[0],e)):((s=n&&Ce[t].apply(Ce,n))&&s.then&&(s=await s),s&&s.await&&(s=await s.await),t==="search"&&s.result&&(s=s.result)),postMessage(t==="search"?{id:r,msg:s}:{id:r})}}function In(e){Ie.call(e,"add"),Ie.call(e,"append"),Ie.call(e,"search"),Ie.call(e,"update"),Ie.call(e,"remove"),Ie.call(e,"searchCache")}let Yr,ls,Ot;function Kl(){Yr=Ot=0}function Ie(e){this[e+"Async"]=function(){const t=arguments;var r=t[t.length-1];let n;if(typeof r=="function"&&(n=r,delete t[t.length-1]),Yr?Ot||(Ot=Date.now()-ls>=this.priority*this.priority*3):(Yr=setTimeout(Kl,0),ls=Date.now()),Ot){const o=this;return new Promise(i=>{setTimeout(function(){i(o[e+"Async"].apply(o,t))},0)})}const s=this[e].apply(this,t);return r=s.then?s:new Promise(o=>o(s)),n&&r.then(n),r}}let de=0;function Fe(e={},t){function r(c){function a(l){l=l.data||l;const u=l.id,h=u&&o.h[u];h&&(h(l.msg),delete o.h[u])}if(this.worker=c,this.h=N(),this.worker)return s?this.worker.on("message",a):this.worker.onmessage=a,e.config?new Promise(function(l){de>1e9&&(de=0),o.h[++de]=function(){l(o)},o.worker.postMessage({id:de,task:"init",factory:n,options:e})}):(this.priority=e.priority||4,this.encoder=t||null,this.worker.postMessage({task:"init",factory:n,options:e}),this)}if(!this||this.constructor!==Fe)return new Fe(e);let n=typeof self<"u"?self._factory:typeof window<"u"?window._factory:null;n&&(n=n.toString());const s=typeof window>"u",o=this,i=Ol(n,s,e.worker);return i.then?i.then(function(c){return r.call(o,c)}):r.call(this,i)}ye("add");ye("append");ye("search");ye("update");ye("remove");ye("clear");ye("export");ye("import");Fe.prototype.searchCache=Cn;In(Fe.prototype);function ye(e){Fe.prototype[e]=function(){const t=this,r=[].slice.call(arguments);var n=r[r.length-1];let s;return typeof n=="function"&&(s=n,r.pop()),n=new Promise(function(o){e==="export"&&typeof r[0]=="function"&&(r[0]=null),de>1e9&&(de=0),t.h[++de]=o,t.worker.postMessage({task:e,id:de,args:r})}),s?(n.then(s),this):n}}function Ol(e,t,r){return t?typeof module<"u"?new(require("worker_threads")).Worker(__dirname+"/worker/node.js"):Promise.resolve().then(()=>require("./__vite-browser-external-Dyvby5gX.js")).then(function(n){return new n.Worker("undefined/node/node.mjs")}):e?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+_l.toString()],{type:"text/javascript"}))):new window.Worker(typeof r=="string"?r:(typeof document>"u"?require("url").pathToFileURL(__filename).href:vr&&vr.tagName.toUpperCase()==="SCRIPT"&&vr.src||new URL("index.js",document.baseURI).href).replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js","module/worker/worker.js").replace("flexsearch.bundle.module.min.mjs","module/worker/worker.js"),{type:"module"})}Ne.prototype.add=function(e,t,r){if(st(e)&&(t=e,e=ot(t,this.key)),t&&(e||e===0)){if(!r&&this.reg.has(e))return this.update(e,t);for(let c=0,a;c<this.field.length;c++){a=this.B[c];var n=this.index.get(this.field[c]);if(typeof a=="function"){var s=a(t);s&&n.add(e,s,r,!0)}else s=a.G,(!s||s(t))&&(a.constructor===String?a=[""+a]:Z(a)&&(a=[a]),Jr(t,a,this.D,0,n,e,a[0],r))}if(this.tag)for(n=0;n<this.A.length;n++){var o=this.A[n];s=this.tag.get(this.F[n]);let c=N();if(typeof o=="function"){if(o=o(t),!o)continue}else{var i=o.G;if(i&&!i(t))continue;o.constructor===String&&(o=""+o),o=ot(t,o)}if(s&&o){Z(o)&&(o=[o]);for(let a=0,l,u;a<o.length;a++)if(l=o[a],!c[l]&&(c[l]=1,(i=s.get(l))?u=i:s.set(l,u=[]),!r||!u.includes(e))){if(u.length===2**31-1){if(i=new Be(u),this.fastupdate)for(let h of this.reg.values())h.includes(u)&&(h[h.indexOf(u)]=i);s.set(l,u=i)}u.push(e),this.fastupdate&&((i=this.reg.get(e))?i.push(u):this.reg.set(e,[u]))}}}if(this.store&&(!r||!this.store.has(e))){let c;if(this.h){c=N();for(let a=0,l;a<this.h.length;a++){if(l=this.h[a],(r=l.G)&&!r(t))continue;let u;if(typeof l=="function"){if(u=l(t),!u)continue;l=[l.O]}else if(Z(l)||l.constructor===String){c[l]=t[l];continue}Vr(t,c,l,0,l[0],u)}}this.store.set(e,c||t)}this.worker&&(this.fastupdate||this.reg.add(e))}return this};function Vr(e,t,r,n,s,o){if(e=e[s],n===r.length-1)t[s]=o||e;else if(e)if(e.constructor===Array)for(t=t[s]=Array(e.length),s=0;s<e.length;s++)Vr(e,t,r,n,s);else t=t[s]||(t[s]=N()),s=r[++n],Vr(e,t,r,n,s)}function Jr(e,t,r,n,s,o,i,c){if(e=e[i])if(n===t.length-1){if(e.constructor===Array){if(r[n]){for(t=0;t<e.length;t++)s.add(o,e[t],!0,!0);return}e=e.join(" ")}s.add(o,e,c,!0)}else if(e.constructor===Array)for(i=0;i<e.length;i++)Jr(e,t,r,n,s,o,i,c);else i=t[++n],Jr(e,t,r,n,s,o,i,c)}function Pn(e,t,r,n){if(!e.length)return e;if(e.length===1)return e=e[0],e=r||e.length>t?e.slice(r,r+t):e,n?Pe.call(this,e):e;let s=[];for(let o=0,i,c;o<e.length;o++)if((i=e[o])&&(c=i.length)){if(r){if(r>=c){r-=c;continue}i=i.slice(r,r+t),c=i.length,r=0}if(c>t&&(i=i.slice(0,t),c=t),!s.length&&c>=t)return n?Pe.call(this,i):i;if(s.push(i),t-=c,!t)break}return s=s.length>1?[].concat.apply([],s):s[0],n?Pe.call(this,s):s}function ur(e,t,r,n){var s=n[0];if(s[0]&&s[0].query)return e[t].apply(e,s);if(!(t!=="and"&&t!=="not"||e.result.length||e.await||s.suggest))return n.length>1&&(s=n[n.length-1]),(n=s.resolve)?e.await||e.result:e;let o=[],i=0,c=0,a,l,u,h,m;for(t=0;t<n.length;t++)if(s=n[t]){var y=void 0;if(s.constructor===P)y=s.await||s.result;else if(s.then||s.constructor===Array)y=s;else{i=s.limit||0,c=s.offset||0,u=s.suggest,l=s.resolve,a=((h=s.highlight||e.highlight)||s.enrich)&&l,y=s.queue;let p=s.async||y,f=s.index,d=s.query;if(f?e.index||(e.index=f):f=e.index,d||s.tag){const b=s.field||s.pluck;if(b&&(!d||e.query&&!h||(e.query=d,e.field=b,e.highlight=h),f=f.index.get(b)),y&&(m||e.await)){m=1;let w;const E=e.C.length,x=new Promise(function(k){w=k});(function(k,v){x.h=function(){v.index=null,v.resolve=!1;let S=p?k.searchAsync(v):k.search(v);return S.then?S.then(function(T){return e.C[E]=T=T.result||T,w(T),T}):(S=S.result||S,w(S),S)}})(f,Object.assign({},s)),e.C.push(x),o[t]=x;continue}else s.resolve=!1,s.index=null,y=p?f.searchAsync(s):f.search(s),s.resolve=l,s.index=f}else if(s.and)y=vt(s,"and",f);else if(s.or)y=vt(s,"or",f);else if(s.not)y=vt(s,"not",f);else if(s.xor)y=vt(s,"xor",f);else continue}y.await?(m=1,y=y.await):y.then?(m=1,y=y.then(function(p){return p.result||p})):y=y.result||y,o[t]=y}if(m&&!e.await&&(e.await=new Promise(function(p){e.return=p})),m){const p=Promise.all(o).then(function(f){for(let d=0;d<e.C.length;d++)if(e.C[d]===p){e.C[d]=function(){return r.call(e,f,i,c,a,l,u,h)};break}jn(e)});e.C.push(p)}else if(e.await)e.C.push(function(){return r.call(e,o,i,c,a,l,u,h)});else return r.call(e,o,i,c,a,l,u,h);return l?e.await||e.result:e}function vt(e,t,r){e=e[t];const n=e[0]||e;return n.index||(n.index=r),r=new P(n),e.length>1&&(r=r[t].apply(r,e.slice(1))),r}P.prototype.or=function(){return ur(this,"or",Rl,arguments)};function Rl(e,t,r,n,s,o,i){return e.length&&(this.result.length&&e.push(this.result),e.length<2?this.result=e[0]:(this.result=Yo(e,t,r,!1,this.h),r=0)),s&&(this.await=null),s?this.resolve(t,r,n,i):this}P.prototype.and=function(){return ur(this,"and",Cl,arguments)};function Cl(e,t,r,n,s,o,i){if(!o&&!this.result.length)return s?this.result:this;let c;if(e.length)if(this.result.length&&e.unshift(this.result),e.length<2)this.result=e[0];else{let a=0;for(let l=0,u,h;l<e.length;l++)if((u=e[l])&&(h=u.length))a<h&&(a=h);else if(!o){a=0;break}a?(this.result=Ht(e,a,t,r,o,this.h,s),c=!0):this.result=[]}else o||(this.result=e);return s&&(this.await=null),s?this.resolve(t,r,n,i,c):this}P.prototype.xor=function(){return ur(this,"xor",Il,arguments)};function Il(e,t,r,n,s,o,i){if(e.length)if(this.result.length&&e.unshift(this.result),e.length<2)this.result=e[0];else{e:{o=r;var c=this.h;const a=[],l=N();let u=0;for(let h=0,m;h<e.length;h++)if(m=e[h]){u<m.length&&(u=m.length);for(let y=0,p;y<m.length;y++)if(p=m[y])for(let f=0,d;f<p.length;f++)d=p[f],l[d]=l[d]?2:1}for(let h=0,m,y=0;h<u;h++)for(let p=0,f;p<e.length;p++)if((f=e[p])&&(m=f[h])){for(let d=0,b;d<m.length;d++)if(b=m[d],l[b]===1)if(o)o--;else if(s){if(a.push(b),a.length===t){e=a;break e}}else{const w=h+(p?c:0);if(a[w]||(a[w]=[]),a[w].push(b),++y===t){e=a;break e}}}e=a}this.result=e,c=!0}else o||(this.result=e);return s&&(this.await=null),s?this.resolve(t,r,n,i,c):this}P.prototype.not=function(){return ur(this,"not",Pl,arguments)};function Pl(e,t,r,n,s,o,i){if(!o&&!this.result.length)return s?this.result:this;if(e.length&&this.result.length){e:{o=r;var c=[];e=new Set(e.flat().flat());for(let a=0,l,u=0;a<this.result.length;a++)if(l=this.result[a]){for(let h=0,m;h<l.length;h++)if(m=l[h],!e.has(m)){if(o)o--;else if(s){if(c.push(m),c.length===t){e=c;break e}}else if(c[a]||(c[a]=[]),c[a].push(m),++u===t){e=c;break e}}}e=c}this.result=e,c=!0}return s&&(this.await=null),s?this.resolve(t,r,n,i,c):this}function Rt(e,t,r,n,s){let o,i,c;typeof s=="string"?(o=s,s=""):o=s.template,i=o.indexOf("$1"),c=o.substring(i+2),i=o.substring(0,i);let a=s&&s.boundary,l=!s||s.clip!==!1,u=s&&s.merge&&c&&i&&new RegExp(c+" "+i,"g");s=s&&s.ellipsis;var h=0;if(typeof s=="object"){var m=s.template;h=m.length-2,s=s.pattern}typeof s!="string"&&(s=s===!1?"":"..."),h&&(s=m.replace("$1",s)),m=s.length-h;let y,p;typeof a=="object"&&(y=a.before,y===0&&(y=-1),p=a.after,p===0&&(p=-1),a=a.total||9e5),h=new Map;for(let xr=0,ge,zn,Ye;xr<t.length;xr++){let Ve;if(n)Ve=t,Ye=n;else{var f=t[xr];if(Ye=f.field,!Ye)continue;Ve=f.result}zn=r.get(Ye),ge=zn.encoder,f=h.get(ge),typeof f!="string"&&(f=ge.encode(e),h.set(ge,f));for(let gt=0;gt<Ve.length;gt++){var d=Ve[gt].doc;if(!d||(d=ot(d,Ye),!d))continue;var b=d.trim().split(/\s+/);if(!b.length)continue;d="";var w=[];let wt=[];for(var E=-1,x=-1,k=0,v=0;v<b.length;v++){var S=b[v],T=ge.encode(S);T=T.length>1?T.join(" "):T[0];let K;if(T&&S){for(var _=S.length,C=(ge.split?S.replace(ge.split,""):S).length-T.length,O="",j=0,L=0;L<f.length;L++){var M=f[L];if(M){var B=M.length;B+=C<0?0:C,j&&B<=j||(M=T.indexOf(M),M>-1&&(O=(M?S.substring(0,M):"")+i+S.substring(M,M+B)+c+(M+B<_?S.substring(M+B):""),j=B,K=!0))}}O&&(a&&(E<0&&(E=d.length+(d?1:0)),x=d.length+(d?1:0)+O.length,k+=_,wt.push(w.length),w.push({match:O})),d+=(d?" ":"")+O)}if(!K)S=b[v],d+=(d?" ":"")+S,a&&w.push({text:S});else if(a&&k>=a)break}if(k=wt.length*(o.length-2),y||p||a&&d.length-k>a)if(k=a+k-m*2,v=x-E,y>0&&(v+=y),p>0&&(v+=p),v<=k)b=y?E-(y>0?y:0):E-((k-v)/2|0),w=p?x+(p>0?p:0):b+k,l||(b>0&&d.charAt(b)!==" "&&d.charAt(b-1)!==" "&&(b=d.indexOf(" ",b),b<0&&(b=0)),w<d.length&&d.charAt(w-1)!==" "&&d.charAt(w)!==" "&&(w=d.lastIndexOf(" ",w),w<x?w=x:++w)),d=(b?s:"")+d.substring(b,w)+(w<d.length?s:"");else{for(x=[],E={},k={},v={},S={},T={},O=C=_=0,L=j=1;;){var ne=void 0;for(let K=0,F;K<wt.length;K++){if(F=wt[K],O)if(C!==O){if(v[K+1])continue;if(F+=O,E[F]){_-=m,k[K+1]=1,v[K+1]=1;continue}if(F>=w.length-1){if(F>=w.length){v[K+1]=1,F>=b.length&&(k[K+1]=1);continue}_-=m}if(d=w[F].text,B=p&&T[K])if(B>0){if(d.length>B)if(v[K+1]=1,l)d=d.substring(0,B);else continue;(B-=d.length)||(B=-1),T[K]=B}else{v[K+1]=1;continue}if(_+d.length+1<=a)d=" "+d,x[K]+=d;else if(l)ne=a-_-1,ne>0&&(d=" "+d.substring(0,ne),x[K]+=d),v[K+1]=1;else{v[K+1]=1;continue}}else{if(v[K])continue;if(F-=C,E[F]){_-=m,v[K]=1,k[K]=1;continue}if(F<=0){if(F<0){v[K]=1,k[K]=1;continue}_-=m}if(d=w[F].text,B=y&&S[K])if(B>0){if(d.length>B)if(v[K]=1,l)d=d.substring(d.length-B);else continue;(B-=d.length)||(B=-1),S[K]=B}else{v[K]=1;continue}if(_+d.length+1<=a)d+=" ",x[K]=d+x[K];else if(l)ne=d.length+1-(a-_),ne>=0&&ne<d.length&&(d=d.substring(ne)+" ",x[K]=d+x[K]),v[K]=1;else{v[K]=1;continue}}else{d=w[F].match,y&&(S[K]=y),p&&(T[K]=p),K&&_++;let kr;if(F?!K&&m&&(_+=m):(k[K]=1,v[K]=1),F>=b.length-1||F<w.length-1&&w[F+1].match?kr=1:m&&(_+=m),_-=o.length-2,!K||_+d.length<=a)x[K]=d;else{ne=j=L=k[K]=0;break}kr&&(k[K+1]=1,v[K+1]=1)}_+=d.length,ne=E[F]=1}if(ne)C===O?O++:C++;else{if(C===O?j=0:L=0,!j&&!L)break;j?(C++,O=C):O++}}d="";for(let K=0,F;K<x.length;K++)F=(k[K]?K?" ":"":(K&&!s?" ":"")+s)+x[K],d+=F;s&&!k[x.length]&&(d+=s)}u&&(d=d.replace(u," ")),Ve[gt].highlight=d}if(n)break}return t}function P(e,t){if(!this||this.constructor!==P)return new P(e,t);let r=0,n,s,o,i,c,a;if(e&&e.index){const l=e;if(t=l.index,r=l.boost||0,s=l.query){o=l.field||l.pluck,i=l.highlight;const u=l.resolve;e=l.async||l.queue,l.resolve=!1,l.index=null,e=e?t.searchAsync(l):t.search(l),l.resolve=u,l.index=t,e=e.result||e}else e=[]}if(e&&e.then){const l=this;e=e.then(function(u){l.C[0]=l.result=u.result||u,jn(l)}),n=[e],e=[],c=new Promise(function(u){a=u})}this.index=t||null,this.result=e||[],this.h=r,this.C=n||[],this.await=c||null,this.return=a||null,this.highlight=i||null,this.query=s||"",this.field=o||""}A=P.prototype;A.limit=function(e){if(this.await){const t=this;this.C.push(function(){return t.limit(e).result})}else if(this.result.length){const t=[];for(let r=0,n;r<this.result.length;r++)if(n=this.result[r])if(n.length<=e){if(t[r]=n,e-=n.length,!e)break}else{t[r]=n.slice(0,e);break}this.result=t}return this};A.offset=function(e){if(this.await){const t=this;this.C.push(function(){return t.offset(e).result})}else if(this.result.length){const t=[];for(let r=0,n;r<this.result.length;r++)(n=this.result[r])&&(n.length<=e?e-=n.length:(t[r]=n.slice(e),e=0));this.result=t}return this};A.boost=function(e){if(this.await){const t=this;this.C.push(function(){return t.boost(e).result})}else this.h+=e;return this};function jn(e,t){let r=e.result;var n=e.await;e.await=null;for(let s=0,o;s<e.C.length;s++)if(o=e.C[s]){if(typeof o=="function")r=o(),e.C[s]=r=r.result||r,s--;else if(o.h)r=o.h(),e.C[s]=r=r.result||r,s--;else if(o.then)return e.await=n}return n=e.return,e.C=[],e.return=null,t||n(r),r}A.resolve=function(e,t,r,n,s){let o=this.await?jn(this,!0):this.result;if(o.then){const i=this;return o.then(function(){return i.resolve(e,t,r,n,s)})}return o.length&&(typeof e=="object"?(n=e.highlight||this.highlight,r=!!n||e.enrich,t=e.offset,e=e.limit):(n=n||this.highlight,r=!!n||r),o=s?r?Pe.call(this.index,o):o:Pn.call(this.index,o,e||100,t,r)),this.finalize(o,n)};A.finalize=function(e,t){if(e.then){const n=this;return e.then(function(s){return n.finalize(s,t)})}t&&e.length&&this.query&&(e=Rt(this.query,e,this.index.index,this.field,t));const r=this.return;return this.highlight=this.index=this.result=this.C=this.await=this.return=null,this.query=this.field="",r&&r(e),e};function Ht(e,t,r,n,s,o,i){const c=e.length;let a=[],l,u;l=N();for(let h=0,m,y,p,f;h<t;h++)for(let d=0;d<c;d++)if(p=e[d],h<p.length&&(m=p[h]))for(let b=0;b<m.length;b++){if(y=m[b],(u=l[y])?l[y]++:(u=0,l[y]=1),f=a[u]||(a[u]=[]),!i){let w=h+(d||!s?0:o||0);f=f[w]||(f[w]=[])}if(f.push(y),i&&r&&u===c-1&&f.length-n===r)return n?f.slice(n):f}if(e=a.length)if(s)a=a.length>1?Yo(a,r,n,i,o):(a=a[0])&&r&&a.length>r||n?a.slice(n,r+n):a;else{if(e<c)return[];if(a=a[e-1],r||n)if(i)(a.length>r||n)&&(a=a.slice(n,r+n));else{s=[];for(let h=0,m;h<a.length;h++)if(m=a[h]){if(n&&m.length>n)n-=m.length;else if((r&&m.length>r||n)&&(m=m.slice(n,r+n),r-=m.length,n&&(n-=m.length)),s.push(m),!r)break}a=s}}return a}function Yo(e,t,r,n,s){const o=[],i=N();let c;var a=e.length;let l;if(n){for(s=a-1;s>=0;s--)if(l=(n=e[s])&&n.length){for(a=0;a<l;a++)if(c=n[a],!i[c]){if(i[c]=1,r)r--;else if(o.push(c),o.length===t)return o}}}else for(let u=a-1,h,m=0;u>=0;u--){h=e[u];for(let y=0;y<h.length;y++)if(l=(n=h[y])&&n.length){for(let p=0;p<l;p++)if(c=n[p],!i[c])if(i[c]=1,r)r--;else{let f=(y+(u<a-1&&s||0))/(u+1)|0;if((o[f]||(o[f]=[])).push(c),++m===t)return o}}}return o}function jl(e,t,r,n,s){const o=N(),i=[];for(let c=0,a;c<t.length;c++){a=t[c];for(let l=0;l<a.length;l++)o[a[l]]=1}if(s){for(let c=0,a;c<e.length;c++)if(a=e[c],o[a]){if(n)n--;else if(i.push(a),o[a]=0,r&&--r===0)break}}else for(let c=0,a,l;c<e.result.length;c++)for(a=e.result[c],t=0;t<a.length;t++)l=a[t],o[l]&&((i[c]||(i[c]=[])).push(l),o[l]=0);return i}Ne.prototype.search=function(e,t,r,n){r||(!t&&st(e)?(r=e,e=""):st(t)&&(r=t,t=0));let s=[];var o=[];let i,c,a,l,u,h,m=0,y=!0,p;if(r){r.constructor===Array&&(r={index:r}),e=r.query||e,i=r.pluck,c=r.merge,l=r.boost,h=i||r.field||(h=r.index)&&(h.index?null:h);var f=this.tag&&r.tag;a=r.suggest,y=r.resolve!==!1,u=r.cache,p=y&&this.store&&r.highlight;var d=!!p||y&&this.store&&r.enrich;t=r.limit||t;var b=r.offset||0;if(t||(t=y?100:0),f&&(!this.db||!n)){f.constructor!==Array&&(f=[f]);var w=[];for(let S=0,T;S<f.length;S++)if(T=f[S],T.field&&T.tag){var E=T.tag;if(E.constructor===Array)for(var x=0;x<E.length;x++)w.push(T.field,E[x]);else w.push(T.field,E)}else{E=Object.keys(T);for(let _=0,C,O;_<E.length;_++)if(C=E[_],O=T[C],O.constructor===Array)for(x=0;x<O.length;x++)w.push(C,O[x]);else w.push(C,O)}if(f=w,!e){if(o=[],w.length)for(f=0;f<w.length;f+=2){if(this.db){if(n=this.index.get(w[f]),!n)continue;o.push(n=n.db.tag(w[f+1],t,b,d))}else n=Bl.call(this,w[f],w[f+1],t,b,d);s.push(y?{field:w[f],tag:w[f+1],result:n}:[n])}if(o.length){const S=this;return Promise.all(o).then(function(T){for(let _=0;_<T.length;_++)y?s[_].result=T[_]:s[_]=T[_];return y?s:new P(s.length>1?Ht(s,1,0,0,a,l):s[0],S)})}return y?s:new P(s.length>1?Ht(s,1,0,0,a,l):s[0],this)}}y||i||!(h=h||this.field)||(Z(h)?i=h:(h.constructor===Array&&h.length===1&&(h=h[0]),i=h.field||h.index)),h&&h.constructor!==Array&&(h=[h])}h||(h=this.field);let k;w=(this.worker||this.db)&&!n&&[];for(let S=0,T,_,C;S<h.length;S++){if(_=h[S],this.db&&this.tag&&!this.B[S])continue;let O;if(Z(_)||(O=_,_=O.field,e=O.query||e,t=Re(O.limit,t),b=Re(O.offset,b),a=Re(O.suggest,a),p=y&&this.store&&Re(O.highlight,p),d=!!p||y&&this.store&&Re(O.enrich,d),u=Re(O.cache,u)),n)T=n[S];else{E=O||r||{},x=E.enrich;var v=this.index.get(_);if(f&&(this.db&&(E.tag=f,E.field=h,k=v.db.support_tag_search),!k&&x&&(E.enrich=!1),k||(E.limit=0,E.offset=0)),T=u?v.searchCache(e,f&&!k?0:t,E):v.search(e,f&&!k?0:t,E),f&&!k&&(E.limit=t,E.offset=b),x&&(E.enrich=x),w){w[S]=T;continue}}if(C=(T=T.result||T)&&T.length,f&&C){if(E=[],x=0,this.db&&n){if(!k)for(v=h.length;v<n.length;v++){let j=n[v];if(j&&j.length)x++,E.push(j);else if(!a)return y?s:new P(s,this)}}else for(let j=0,L,M;j<f.length;j+=2){if(L=this.tag.get(f[j]),!L){if(a)continue;return y?s:new P(s,this)}if(M=(L=L&&L.get(f[j+1]))&&L.length)x++,E.push(L);else if(!a)return y?s:new P(s,this)}if(x){if(T=jl(T,E,t,b,y),C=T.length,!C&&!a)return y?T:new P(T,this);x--}}if(C)o[m]=_,s.push(T),m++;else if(h.length===1)return y?s:new P(s,this)}if(w){if(this.db&&f&&f.length&&!k)for(d=0;d<f.length;d+=2){if(o=this.index.get(f[d]),!o){if(a)continue;return y?s:new P(s,this)}w.push(o.db.tag(f[d+1],t,b,!1))}const S=this;return Promise.all(w).then(function(T){return r&&(r.resolve=y),T.length&&(T=S.search(e,t,r,T)),T})}if(!m)return y?s:new P(s,this);if(i&&(!d||!this.store))return s=s[0],y?s:new P(s,this);for(w=[],b=0;b<o.length;b++){if(f=s[b],d&&f.length&&typeof f[0].doc>"u"&&(this.db?w.push(f=this.index.get(this.field[0]).db.enrich(f)):f=Pe.call(this,f)),i)return y?p?Rt(e,f,this.index,i,p):f:new P(f,this);s[b]={field:o[b],result:f}}if(d&&this.db&&w.length){const S=this;return Promise.all(w).then(function(T){for(let _=0;_<T.length;_++)s[_].result=T[_];return p&&(s=Rt(e,s,S.index,i,p)),c?us(s):s})}return p&&(s=Rt(e,s,this.index,i,p)),c?us(s):s};function us(e){const t=[],r=N(),n=N();for(let s=0,o,i,c,a,l,u,h;s<e.length;s++){o=e[s],i=o.field,c=o.result;for(let m=0;m<c.length;m++)l=c[m],typeof l!="object"?l={id:a=l}:a=l.id,(u=r[a])?u.push(i):(l.field=r[a]=[i],t.push(l)),(h=l.highlight)&&(u=n[a],u||(n[a]=u={},l.highlight=u),u[i]=h)}return t}function Bl(e,t,r,n,s){return e=this.tag.get(e),e?(e=e.get(t),e?(t=e.length-n,t>0&&((r&&t>r||n)&&(e=e.slice(n,n+r)),s&&(e=Pe.call(this,e))),e):[]):[]}function Pe(e){if(!this||!this.store)return e;if(this.db)return this.index.get(this.field[0]).db.enrich(e);const t=Array(e.length);for(let r=0,n;r<e.length;r++)n=e[r],t[r]={id:n,doc:this.store.get(n)};return t}function Ne(e){if(!this||this.constructor!==Ne)return new Ne(e);const t=e.document||e.doc||e;let r,n;if(this.B=[],this.field=[],this.D=[],this.key=(r=t.key||t.id)&&zt(r,this.D)||"id",(n=e.keystore||0)&&(this.keystore=n),this.fastupdate=!!e.fastupdate,this.reg=!this.fastupdate||e.worker||e.db?n?new ee(n):new Set:n?new Q(n):new Map,this.h=(r=t.store||null)&&r&&r!==!0&&[],this.store=r?n?new Q(n):new Map:null,this.cache=(r=e.cache||null)&&new Ke(r),e.cache=!1,this.worker=e.worker||!1,this.priority=e.priority||4,this.index=Fl.call(this,e,t),this.tag=null,(r=t.tag)&&(typeof r=="string"&&(r=[r]),r.length)){this.tag=new Map,this.A=[],this.F=[];for(let s=0,o,i;s<r.length;s++){if(o=r[s],i=o.field||o,!i)throw Error("The tag field from the document descriptor is undefined.");o.custom?this.A[s]=o.custom:(this.A[s]=zt(i,this.D),o.filter&&(typeof this.A[s]=="string"&&(this.A[s]=new String(this.A[s])),this.A[s].G=o.filter)),this.F[s]=i,this.tag.set(i,new Map)}}if(this.worker){this.fastupdate=!1,e=[];for(const s of this.index.values())s.then&&e.push(s);if(e.length){const s=this;return Promise.all(e).then(function(o){let i=0;for(const c of s.index.entries()){const a=c[0];let l=c[1];l.then&&(l=o[i],s.index.set(a,l),i++)}return s})}}else e.db&&(this.fastupdate=!1,this.mount(e.db))}A=Ne.prototype;A.mount=function(e){let t=this.field;if(this.tag)for(let o=0,i;o<this.F.length;o++){i=this.F[o];var r=void 0;this.index.set(i,r=new te({},this.reg)),t===this.field&&(t=t.slice(0)),t.push(i),r.tag=this.tag.get(i)}r=[];const n={db:e.db,type:e.type,fastupdate:e.fastupdate};for(let o=0,i,c;o<t.length;o++){n.field=c=t[o],i=this.index.get(c);const a=new e.constructor(e.id,n);a.id=e.id,r[o]=a.mount(i),i.document=!0,o?i.bypass=!0:i.store=this.store}const s=this;return this.db=Promise.all(r).then(function(){s.db=!0})};A.commit=async function(){const e=[];for(const t of this.index.values())e.push(t.commit());await Promise.all(e),this.reg.clear()};A.destroy=function(){const e=[];for(const t of this.index.values())e.push(t.destroy());return Promise.all(e)};function Fl(e,t){const r=new Map;let n=t.index||t.field||t;Z(n)&&(n=[n]);for(let o=0,i,c;o<n.length;o++){if(i=n[o],Z(i)||(c=i,i=i.field),c=st(c)?Object.assign({},e,c):e,this.worker){var s=void 0;s=(s=c.encoder)&&s.encode?s:new it(typeof s=="string"?Ho[s]:s||{}),s=new Fe(c,s),r.set(i,s)}this.worker||r.set(i,new te(c,this.reg)),c.custom?this.B[o]=c.custom:(this.B[o]=zt(i,this.D),c.filter&&(typeof this.B[o]=="string"&&(this.B[o]=new String(this.B[o])),this.B[o].G=c.filter)),this.field[o]=i}if(this.h){e=t.store,Z(e)&&(e=[e]);for(let o=0,i,c;o<e.length;o++)i=e[o],c=i.field||i,i.custom?(this.h[o]=i.custom,i.custom.O=c):(this.h[o]=zt(c,this.D),i.filter&&(typeof this.h[o]=="string"&&(this.h[o]=new String(this.h[o])),this.h[o].G=i.filter))}return r}function zt(e,t){const r=e.split(":");let n=0;for(let s=0;s<r.length;s++)e=r[s],e[e.length-1]==="]"&&(e=e.substring(0,e.length-2))&&(t[n]=!0),e&&(r[n++]=e);return n<r.length&&(r.length=n),n>1?r:r[0]}A.append=function(e,t){return this.add(e,t,!0)};A.update=function(e,t){return this.remove(e).add(e,t)};A.remove=function(e){st(e)&&(e=ot(e,this.key));for(var t of this.index.values())t.remove(e,!0);if(this.reg.has(e)){if(this.tag&&!this.fastupdate)for(let r of this.tag.values())for(let n of r){t=n[0];const s=n[1],o=s.indexOf(e);o>-1&&(s.length>1?s.splice(o,1):r.delete(t))}this.store&&this.store.delete(e),this.reg.delete(e)}return this.cache&&this.cache.remove(e),this};A.clear=function(){const e=[];for(const t of this.index.values()){const r=t.clear();r.then&&e.push(r)}if(this.tag)for(const t of this.tag.values())t.clear();return this.store&&this.store.clear(),this.cache&&this.cache.clear(),e.length?Promise.all(e):this};A.contain=function(e){return this.db?this.index.get(this.field[0]).db.has(e):this.reg.has(e)};A.cleanup=function(){for(const e of this.index.values())e.cleanup();return this};A.get=function(e){return this.db?this.index.get(this.field[0]).db.enrich(e).then(function(t){return t[0]&&t[0].doc||null}):this.store.get(e)||null};A.set=function(e,t){return typeof e=="object"&&(t=e,e=ot(t,this.key)),this.store.set(e,t),this};A.searchCache=Cn;A.export=Nl;A.import=Ll;In(Ne.prototype);function Bn(e,t=0){let r=[],n=[];t&&(t=25e4/t*5e3|0);for(const s of e.entries())n.push(s),n.length===t&&(r.push(n),n=[]);return n.length&&r.push(n),r}function Fn(e,t){t||(t=new Map);for(let r=0,n;r<e.length;r++)n=e[r],t.set(n[0],n[1]);return t}function Vo(e,t=0){let r=[],n=[];t&&(t=25e4/t*1e3|0);for(const s of e.entries())n.push([s[0],Bn(s[1])[0]||[]]),n.length===t&&(r.push(n),n=[]);return n.length&&r.push(n),r}function Jo(e,t){t||(t=new Map);for(let r=0,n,s;r<e.length;r++)n=e[r],s=t.get(n[0]),t.set(n[0],Fn(n[1],s));return t}function Go(e){let t=[],r=[];for(const n of e.keys())r.push(n),r.length===25e4&&(t.push(r),r=[]);return r.length&&t.push(r),t}function Xo(e,t){t||(t=new Set);for(let r=0;r<e.length;r++)t.add(e[r]);return t}function $t(e,t,r,n,s,o,i=0){const c=n&&n.constructor===Array;var a=c?n.shift():n;if(!a)return this.export(e,t,s,o+1);if((a=e((t?t+".":"")+(i+1)+"."+r,JSON.stringify(a)))&&a.then){const l=this;return a.then(function(){return $t.call(l,e,t,r,c?n:null,s,o,i+1)})}return $t.call(this,e,t,r,c?n:null,s,o,i+1)}function Nl(e,t,r=0,n=0){if(r<this.field.length){const i=this.field[r];if((t=this.index.get(i).export(e,i,r,n=1))&&t.then){const c=this;return t.then(function(){return c.export(e,i,r+1)})}return this.export(e,i,r+1)}let s,o;switch(n){case 0:s="reg",o=Go(this.reg),t=null;break;case 1:s="tag",o=this.tag&&Vo(this.tag,this.reg.size),t=null;break;case 2:s="doc",o=this.store&&Bn(this.store),t=null;break;default:return}return $t.call(this,e,t,s,o||null,r,n)}function Ll(e,t){var r=e.split(".");r[r.length-1]==="json"&&r.pop();const n=r.length>2?r[0]:"";if(r=r.length>2?r[2]:r[1],this.worker&&n)return this.index.get(n).import(e);if(t){if(typeof t=="string"&&(t=JSON.parse(t)),n)return this.index.get(n).import(r,t);switch(r){case"reg":this.fastupdate=!1,this.reg=Xo(t,this.reg);for(let s=0,o;s<this.field.length;s++)o=this.index.get(this.field[s]),o.fastupdate=!1,o.reg=this.reg;if(this.worker){t=[];for(const s of this.index.values())t.push(s.import(e));return Promise.all(t)}break;case"tag":this.tag=Jo(t,this.tag);break;case"doc":this.store=Fn(t,this.store)}}}function hs(e,t){let r="";for(const n of e.entries()){e=n[0];const s=n[1];let o="";for(let i=0,c;i<s.length;i++){c=s[i]||[""];let a="";for(let l=0;l<c.length;l++)a+=(a?",":"")+(t==="string"?'"'+c[l]+'"':c[l]);a="["+a+"]",o+=(o?",":"")+a}o='["'+e+'",['+o+"]]",r+=(r?",":"")+o}return r}te.prototype.remove=function(e,t){const r=this.reg.size&&(this.fastupdate?this.reg.get(e):this.reg.has(e));if(r){if(this.fastupdate){for(let n=0,s,o;n<r.length;n++)if((s=r[n])&&(o=s.length))if(s[o-1]===e)s.pop();else{const i=s.indexOf(e);i>=0&&s.splice(i,1)}}else ct(this.map,e),this.depth&&ct(this.ctx,e);t||this.reg.delete(e)}return this.db&&(this.commit_task.push({del:e}),this.M&&qo(this)),this.cache&&this.cache.remove(e),this};function ct(e,t){let r=0;var n=typeof t>"u";if(e.constructor===Array){for(let s=0,o,i,c;s<e.length;s++)if((o=e[s])&&o.length){if(n)return 1;if(i=o.indexOf(t),i>=0){if(o.length>1)return o.splice(i,1),1;if(delete e[s],r)return 1;c=1}else{if(c)return 1;r++}}}else for(let s of e.entries())n=s[0],ct(s[1],t)?r++:e.delete(n);return r}const Dl={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};te.prototype.add=function(e,t,r,n){if(t&&(e||e===0)){if(!n&&!r&&this.reg.has(e))return this.update(e,t);n=this.depth,t=this.encoder.encode(t,!n);const l=t.length;if(l){const u=N(),h=N(),m=this.resolution;for(let y=0;y<l;y++){let p=t[this.rtl?l-1-y:y];var s=p.length;if(s&&(n||!h[p])){var o=this.score?this.score(t,p,y,null,0):St(m,l,y),i="";switch(this.tokenize){case"tolerant":if(ae(this,h,p,o,e,r),s>2){for(let f=1,d,b,w,E;f<s-1;f++)d=p.charAt(f),b=p.charAt(f+1),w=p.substring(0,f)+b,E=p.substring(f+2),i=w+d+E,ae(this,h,i,o,e,r),i=w+E,ae(this,h,i,o,e,r);ae(this,h,p.substring(0,p.length-1),o,e,r)}break;case"full":if(s>2){for(let f=0,d;f<s;f++)for(o=s;o>f;o--){i=p.substring(f,o),d=this.rtl?s-1-f:f;var c=this.score?this.score(t,p,y,i,d):St(m,l,y,s,d);ae(this,h,i,c,e,r)}break}case"bidirectional":case"reverse":if(s>1){for(c=s-1;c>0;c--){i=p[this.rtl?s-1-c:c]+i;var a=this.score?this.score(t,p,y,i,c):St(m,l,y,s,c);ae(this,h,i,a,e,r)}i=""}case"forward":if(s>1){for(c=0;c<s;c++)i+=p[this.rtl?s-1-c:c],ae(this,h,i,o,e,r);break}default:if(ae(this,h,p,o,e,r),n&&l>1&&y<l-1)for(s=this.N,i=p,o=Math.min(n+1,this.rtl?y+1:l-y),c=1;c<o;c++){p=t[this.rtl?l-1-y-c:y+c],a=this.bidirectional&&p>i;const f=this.score?this.score(t,i,y,p,c-1):St(s+(l/2>s?0:1),l,y,o-1,c-1);ae(this,u,a?i:p,f,e,r,a?p:i)}}}}this.fastupdate||this.reg.add(e)}}return this.db&&(this.commit_task.push(r?{ins:e}:{del:e}),this.M&&qo(this)),this};function ae(e,t,r,n,s,o,i){let c,a;if(!(c=t[r])||i&&!c[i]){if(i?(t=c||(t[r]=N()),t[i]=1,a=e.ctx,(c=a.get(i))?a=c:a.set(i,a=e.keystore?new Q(e.keystore):new Map)):(a=e.map,t[r]=1),(c=a.get(r))?a=c:a.set(r,a=c=[]),o){for(let l=0,u;l<c.length;l++)if((u=c[l])&&u.includes(s)){if(l<=n)return;u.splice(u.indexOf(s),1),e.fastupdate&&(t=e.reg.get(s))&&t.splice(t.indexOf(u),1);break}}if(a=a[n]||(a[n]=[]),a.push(s),a.length===2**31-1){if(t=new Be(a),e.fastupdate)for(let l of e.reg.values())l.includes(a)&&(l[l.indexOf(a)]=t);c[n]=a=t}e.fastupdate&&((n=e.reg.get(s))?n.push(a):e.reg.set(s,[a]))}}function St(e,t,r,n,s){return r&&e>1?t+(n||0)<=e?r+(s||0):(e-1)/(t+(n||0))*(r+(s||0))+1|0:0}te.prototype.search=function(e,t,r){if(r||(t||typeof e!="object"?typeof t=="object"&&(r=t,t=0):(r=e,e="")),r&&r.cache)return r.cache=!1,e=this.searchCache(e,t,r),r.cache=!0,e;let n=[],s,o,i,c=0,a,l,u,h,m;r&&(e=r.query||e,t=r.limit||t,c=r.offset||0,o=r.context,i=r.suggest,m=(a=r.resolve)&&r.enrich,u=r.boost,h=r.resolution,l=this.db&&r.tag),typeof a>"u"&&(a=this.resolve),o=this.depth&&o!==!1;let y=this.encoder.encode(e,!o);if(s=y.length,t=t||(a?100:0),s===1)return ds.call(this,y[0],"",t,c,a,m,l);if(s===2&&o&&!i)return ds.call(this,y[1],y[0],t,c,a,m,l);let p=N(),f=0,d;if(o&&(d=y[0],f=1),h||h===0||(h=d?this.N:this.resolution),this.db){if(this.db.search&&(r=this.db.search(this,y,t,c,i,a,m,l),r!==!1))return r;const b=this;return(async function(){for(let w,E;f<s;f++){if((E=y[f])&&!p[E]){if(p[E]=1,w=await Gr(b,E,d,0,0,!1,!1),w=ps(w,n,i,h)){n=w;break}d&&(i&&w&&n.length||(d=E))}i&&d&&f===s-1&&!n.length&&(h=b.resolution,d="",f=-1,p=N())}return fs(n,h,t,c,i,u,a)})()}for(let b,w;f<s;f++){if((w=y[f])&&!p[w]){if(p[w]=1,b=Gr(this,w,d,0,0,!1,!1),b=ps(b,n,i,h)){n=b;break}d&&(i&&b&&n.length||(d=w))}i&&d&&f===s-1&&!n.length&&(h=this.resolution,d="",f=-1,p=N())}return fs(n,h,t,c,i,u,a)};function fs(e,t,r,n,s,o,i){let c=e.length,a=e;if(c>1)a=Ht(e,t,r,n,s,o,i);else if(c===1)return i?Pn.call(null,e[0],r,n):new P(e[0],this);return i?a:new P(a,this)}function ds(e,t,r,n,s,o,i){return e=Gr(this,e,t,r,n,s,o,i),this.db?e.then(function(c){return s?c||[]:new P(c,this)}):e&&e.length?s?Pn.call(this,e,r,n):new P(e,this):s?[]:new P([],this)}function ps(e,t,r,n){let s=[];if(e&&e.length){if(e.length<=n){t.push(e);return}for(let o=0,i;o<n;o++)(i=e[o])&&(s[o]=i);if(s.length){t.push(s);return}}if(!r)return s}function Gr(e,t,r,n,s,o,i,c){let a;return r&&(a=e.bidirectional&&t>r)&&(a=r,r=t,t=a),e.db?e.db.get(t,r,n,s,o,i,c):(e=r?(e=e.ctx.get(r))&&e.get(t):e.map.get(t),e)}function te(e,t){if(!this||this.constructor!==te)return new te(e);if(e){var r=Z(e)?e:e.preset;r&&(e=Object.assign({},Dl[r],e))}else e={};r=e.context;const n=r===!0?{depth:1}:r||{},s=Z(e.encoder)?Ho[e.encoder]:e.encode||e.encoder||{};this.encoder=s.encode?s:typeof s=="object"?new it(s):{encode:s},this.resolution=e.resolution||9,this.tokenize=r=(r=e.tokenize)&&r!=="default"&&r!=="exact"&&r||"strict",this.depth=r==="strict"&&n.depth||0,this.bidirectional=n.bidirectional!==!1,this.fastupdate=!!e.fastupdate,this.score=e.score||null,(r=e.keystore||0)&&(this.keystore=r),this.map=r?new Q(r):new Map,this.ctx=r?new Q(r):new Map,this.reg=t||(this.fastupdate?r?new Q(r):new Map:r?new ee(r):new Set),this.N=n.resolution||3,this.rtl=s.rtl||e.rtl||!1,this.cache=(r=e.cache||null)&&new Ke(r),this.resolve=e.resolve!==!1,(r=e.db)&&(this.db=this.mount(r)),this.M=e.commit!==!1,this.commit_task=[],this.commit_timer=null,this.priority=e.priority||4}A=te.prototype;A.mount=function(e){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),e.mount(this)};A.commit=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this)};A.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};function qo(e){e.commit_timer||(e.commit_timer=setTimeout(function(){e.commit_timer=null,e.db.commit(e)},1))}A.clear=function(){return this.map.clear(),this.ctx.clear(),this.reg.clear(),this.cache&&this.cache.clear(),this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};A.append=function(e,t){return this.add(e,t,!0)};A.contain=function(e){return this.db?this.db.has(e):this.reg.has(e)};A.update=function(e,t){const r=this,n=this.remove(e);return n&&n.then?n.then(()=>r.add(e,t)):this.add(e,t)};A.cleanup=function(){return this.fastupdate?(ct(this.map),this.depth&&ct(this.ctx),this):this};A.searchCache=Cn;A.export=function(e,t,r=0,n=0){let s,o;switch(n){case 0:s="reg",o=Go(this.reg);break;case 1:s="cfg",o=null;break;case 2:s="map",o=Bn(this.map,this.reg.size);break;case 3:s="ctx",o=Vo(this.ctx,this.reg.size);break;default:return}return $t.call(this,e,t,s,o,r,n)};A.import=function(e,t){if(t)switch(typeof t=="string"&&(t=JSON.parse(t)),e=e.split("."),e[e.length-1]==="json"&&e.pop(),e.length===3&&e.shift(),e=e.length>1?e[1]:e[0],e){case"reg":this.fastupdate=!1,this.reg=Xo(t,this.reg);break;case"map":this.map=Fn(t,this.map);break;case"ctx":this.ctx=Jo(t,this.ctx)}};A.serialize=function(e=!0){let t="",r="",n="";if(this.reg.size){let o;for(var s of this.reg.keys())o||(o=typeof s),t+=(t?",":"")+(o==="string"?'"'+s+'"':s);t="index.reg=new Set(["+t+"]);",r=hs(this.map,o),r="index.map=new Map(["+r+"]);";for(const i of this.ctx.entries()){s=i[0];let c=hs(i[1],o);c="new Map(["+c+"])",c='["'+s+'",'+c+"]",n+=(n?",":"")+c}n="index.ctx=new Map(["+n+"]);"}return e?"function inject(index){"+t+r+n+"}":t+r+n};In(te.prototype);const Wo=typeof window<"u"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Yt=["map","ctx","tag","reg","cfg"],Ee=N();function Xr(e,t={}){if(!this||this.constructor!==Xr)return new Xr(e,t);typeof e=="object"&&(t=e,e=e.name),e||console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(e?":"+e.toLowerCase().replace(/[^a-z0-9_\-]/g,""):""),this.field=t.field?t.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"",this.type=t.type,this.fastupdate=this.support_tag_search=!1,this.db=null,this.h={}}A=Xr.prototype;A.mount=function(e){return e.index?e.mount(this):(e.db=this,this.open())};A.open=function(){if(this.db)return this.db;let e=this;navigator.storage&&navigator.storage.persist&&navigator.storage.persist(),Ee[e.id]||(Ee[e.id]=[]),Ee[e.id].push(e.field);const t=Wo.open(e.id,1);return t.onupgradeneeded=function(){const r=e.db=this.result;for(let n=0,s;n<Yt.length;n++){s=Yt[n];for(let o=0,i;o<Ee[e.id].length;o++)i=Ee[e.id][o],r.objectStoreNames.contains(s+(s!=="reg"&&i?":"+i:""))||r.createObjectStore(s+(s!=="reg"&&i?":"+i:""))}},e.db=me(t,function(r){e.db=r,e.db.onversionchange=function(){e.close()}})};A.close=function(){this.db&&this.db.close(),this.db=null};A.destroy=function(){const e=Wo.deleteDatabase(this.id);return me(e)};A.clear=function(){const e=[];for(let r=0,n;r<Yt.length;r++){n=Yt[r];for(let s=0,o;s<Ee[this.id].length;s++)o=Ee[this.id][s],e.push(n+(n!=="reg"&&o?":"+o:""))}const t=this.db.transaction(e,"readwrite");for(let r=0;r<e.length;r++)t.objectStore(e[r]).clear();return me(t)};A.get=function(e,t,r=0,n=0,s=!0,o=!1){e=this.db.transaction((t?"ctx":"map")+(this.field?":"+this.field:""),"readonly").objectStore((t?"ctx":"map")+(this.field?":"+this.field:"")).get(t?t+":"+e:e);const i=this;return me(e).then(function(c){let a=[];if(!c||!c.length)return a;if(s){if(!r&&!n&&c.length===1)return c[0];for(let l=0,u;l<c.length;l++)if((u=c[l])&&u.length){if(n>=u.length){n-=u.length;continue}const h=r?n+Math.min(u.length-n,r):u.length;for(let m=n;m<h;m++)a.push(u[m]);if(n=0,a.length===r)break}return o?i.enrich(a):a}return c})};A.tag=function(e,t=0,r=0,n=!1){e=this.db.transaction("tag"+(this.field?":"+this.field:""),"readonly").objectStore("tag"+(this.field?":"+this.field:"")).get(e);const s=this;return me(e).then(function(o){return!o||!o.length||r>=o.length?[]:!t&&!r?o:(o=o.slice(r,r+t),n?s.enrich(o):o)})};A.enrich=function(e){typeof e!="object"&&(e=[e]);const t=this.db.transaction("reg","readonly").objectStore("reg"),r=[];for(let n=0;n<e.length;n++)r[n]=me(t.get(e[n]));return Promise.all(r).then(function(n){for(let s=0;s<n.length;s++)n[s]={id:e[s],doc:n[s]?JSON.parse(n[s]):null};return n})};A.has=function(e){return e=this.db.transaction("reg","readonly").objectStore("reg").getKey(e),me(e).then(function(t){return!!t})};A.search=null;A.info=function(){};A.transaction=function(e,t,r){e+=e!=="reg"&&this.field?":"+this.field:"";let n=this.h[e+":"+t];if(n)return r.call(this,n);let s=this.db.transaction(e,t);this.h[e+":"+t]=n=s.objectStore(e);const o=r.call(this,n);return this.h[e+":"+t]=null,me(s).finally(function(){return o})};A.commit=async function(e){let t=e.commit_task,r=[];e.commit_task=[];for(let n=0,s;n<t.length;n++)s=t[n],s.del&&r.push(s.del);r.length&&await this.remove(r),e.reg.size&&(await this.transaction("map","readwrite",function(n){for(const s of e.map){const o=s[0],i=s[1];i.length&&(n.get(o).onsuccess=function(){let c=this.result;var a;if(c&&c.length){const l=Math.max(c.length,i.length);for(let u=0,h,m;u<l;u++)if((m=i[u])&&m.length){if((h=c[u])&&h.length)for(a=0;a<m.length;a++)h.push(m[a]);else c[u]=m;a=1}}else c=i,a=1;a&&n.put(c,o)})}}),await this.transaction("ctx","readwrite",function(n){for(const s of e.ctx){const o=s[0],i=s[1];for(const c of i){const a=c[0],l=c[1];l.length&&(n.get(o+":"+a).onsuccess=function(){let u=this.result;var h;if(u&&u.length){const m=Math.max(u.length,l.length);for(let y=0,p,f;y<m;y++)if((f=l[y])&&f.length){if((p=u[y])&&p.length)for(h=0;h<f.length;h++)p.push(f[h]);else u[y]=f;h=1}}else u=l,h=1;h&&n.put(u,o+":"+a)})}}}),e.store?await this.transaction("reg","readwrite",function(n){for(const s of e.store){const o=s[0],i=s[1];n.put(typeof i=="object"?JSON.stringify(i):1,o)}}):e.bypass||await this.transaction("reg","readwrite",function(n){for(const s of e.reg.keys())n.put(1,s)}),e.tag&&await this.transaction("tag","readwrite",function(n){for(const s of e.tag){const o=s[0],i=s[1];i.length&&(n.get(o).onsuccess=function(){let c=this.result;c=c&&c.length?c.concat(i):i,n.put(c,o)})}}),e.map.clear(),e.ctx.clear(),e.tag&&e.tag.clear(),e.store&&e.store.clear(),e.document||e.reg.clear())};function Rr(e,t,r){const n=e.value;let s,o=0;for(let i=0,c;i<n.length;i++){if(c=r?n:n[i]){for(let a=0,l,u;a<t.length;a++)if(u=t[a],l=c.indexOf(u),l>=0)if(s=1,c.length>1)c.splice(l,1);else{n[i]=[];break}o+=c.length}if(r)break}o?s&&e.update(n):e.delete(),e.continue()}A.remove=function(e){return typeof e!="object"&&(e=[e]),Promise.all([this.transaction("map","readwrite",function(t){t.openCursor().onsuccess=function(){const r=this.result;r&&Rr(r,e)}}),this.transaction("ctx","readwrite",function(t){t.openCursor().onsuccess=function(){const r=this.result;r&&Rr(r,e)}}),this.transaction("tag","readwrite",function(t){t.openCursor().onsuccess=function(){const r=this.result;r&&Rr(r,e,!0)}}),this.transaction("reg","readwrite",function(t){for(let r=0;r<e.length;r++)t.delete(e[r])})])};function me(e,t){return new Promise((r,n)=>{e.onsuccess=e.oncomplete=function(){t&&t(this.result),t=null,r(this.result)},e.onerror=e.onblocked=n,e=null})}const Tt=te,hr={preset:"match",tokenize:"forward",resolution:9,minlength:2,optimize:!0,fastupdate:!0,cache:!0},Ml={...hr,minlength:3,resolution:6},Ul={...hr,tokenize:"strict",minlength:1},Hl={...hr,tokenize:"strict",minlength:1},zl=()=>({subjectIndex:new Tt(hr),bodyIndex:new Tt(Ml),fromIndex:new Tt(Ul),toIndex:new Tt(Hl),isReady:!1}),Zo=(e,t)=>{try{const r=e.params.id;if(e.params.subject&&t.subjectIndex.add(r,e.params.subject),e.body?.text&&t.bodyIndex.add(r,e.body.text),e.params.sender){const o=`${e.params.sender.name||""} ${e.params.sender.email||""}`.trim();t.fromIndex.add(r,o)}const s=(e.params.recipients?.length?e.params.recipients:[e.params.recipient]).map(o=>`${o.name||""} ${o.email||""}`.trim()).join(" ");t.toIndex.add(r,s)}catch(r){throw new Error("Failed to add email to the search index",{cause:r})}},$l=(e,t)=>{try{t.subjectIndex.remove(e),t.bodyIndex.remove(e),t.fromIndex.remove(e),t.toIndex.remove(e)}catch(r){throw new Error(`Failed to remove email with ID ${e} from the search index`,{cause:r})}},Yl=async e=>{try{const t=zl();t.isReady=!1;for(const r of e.esCache.values())Zo(r,t);return t.isReady=!0,t}catch(t){throw new Error("Failed build an email search index from the cache",{cause:t})}},Vl=async(e,t,r,n={})=>{try{if(!r.isReady||!e.trim())return[];const{fields:s=["subject","body","from","to"],limit:o=50,boost:i={subject:3,body:1,from:2,to:2}}=n,c=new Map,a=s.map(async u=>{let h;switch(u){case"subject":h=await r.subjectIndex.searchAsync(e);break;case"body":h=await r.bodyIndex.searchAsync(e);break;case"from":h=await r.fromIndex.searchAsync(e);break;case"to":h=await r.toIndex.searchAsync(e);break;default:return}const m=i[u]||1;h.forEach(y=>{const p=c.get(String(y))||0;c.set(String(y),p+m)})});await Promise.all(a);const l=[];for(const[u,h]of c){const m=t.esCache.get(u);m&&l.push({email:m,score:h})}return l.sort((u,h)=>(h.score||0)-(u.score||0)),l.slice(0,o)}catch(s){throw new Error("Email search failed",{cause:s})}},Jl=Object.freeze(Object.defineProperty({__proto__:null,addEmailToCache:Uo,addEmailToSearchIndex:Zo,addEmailsToCache:$r,buildSearchIndexFromCache:Yl,closeDatabase:ul,createCacheFromDB:xl,deleteDatabase:hl,deleteEmail:gl,deleteEmailFromCache:kl,deleteOldestEmails:Bo,deriveIndexKey:fl,encryptAndStoreEmail:dl,encryptAndStoreManyEmail:pl,enforceMaxEmailNumber:wl,getAllEmailsSortedNewestFirst:No,getAllEmailsSortedOldestFirst:bl,getAndDecryptAllEmails:ml,getAndDecryptEmail:yl,getEmailBatch:Lo,getEmailCount:Rn,getEmailFromCache:Mo,openDatabase:ll,removeEmailFromSearchIndex:$l,searchEmails:Vl},Symbol.toStringTag,{value:"Module"}));function Qo(e,t){return function(){return e.apply(t,arguments)}}const{toString:Gl}=Object.prototype,{getPrototypeOf:Nn}=Object,{iterator:fr,toStringTag:ei}=Symbol,dr=(e=>t=>{const r=Gl.call(t);return e[r]||(e[r]=r.slice(8,-1).toLowerCase())})(Object.create(null)),re=e=>(e=e.toLowerCase(),t=>dr(t)===e),pr=e=>t=>typeof t===e,{isArray:ze}=Array,at=pr("undefined");function ft(e){return e!==null&&!at(e)&&e.constructor!==null&&!at(e.constructor)&&J(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const ti=re("ArrayBuffer");function Xl(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&ti(e.buffer),t}const ql=pr("string"),J=pr("function"),ri=pr("number"),dt=e=>e!==null&&typeof e=="object",Wl=e=>e===!0||e===!1,Ct=e=>{if(dr(e)!=="object")return!1;const t=Nn(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ei in e)&&!(fr in e)},Zl=e=>{if(!dt(e)||ft(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Ql=re("Date"),eu=re("File"),tu=re("Blob"),ru=re("FileList"),nu=e=>dt(e)&&J(e.pipe),su=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||J(e.append)&&((t=dr(e))==="formdata"||t==="object"&&J(e.toString)&&e.toString()==="[object FormData]"))},ou=re("URLSearchParams"),[iu,cu,au,lu]=["ReadableStream","Request","Response","Headers"].map(re),uu=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function pt(e,t,{allOwnKeys:r=!1}={}){if(e===null||typeof e>"u")return;let n,s;if(typeof e!="object"&&(e=[e]),ze(e))for(n=0,s=e.length;n<s;n++)t.call(null,e[n],n,e);else{if(ft(e))return;const o=r?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let c;for(n=0;n<i;n++)c=o[n],t.call(null,e[c],c,e)}}function ni(e,t){if(ft(e))return null;t=t.toLowerCase();const r=Object.keys(e);let n=r.length,s;for(;n-- >0;)if(s=r[n],t===s.toLowerCase())return s;return null}const ke=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:globalThis,si=e=>!at(e)&&e!==ke;function qr(){const{caseless:e}=si(this)&&this||{},t={},r=(n,s)=>{const o=e&&ni(t,s)||s;Ct(t[o])&&Ct(n)?t[o]=qr(t[o],n):Ct(n)?t[o]=qr({},n):ze(n)?t[o]=n.slice():t[o]=n};for(let n=0,s=arguments.length;n<s;n++)arguments[n]&&pt(arguments[n],r);return t}const hu=(e,t,r,{allOwnKeys:n}={})=>(pt(t,(s,o)=>{r&&J(s)?e[o]=Qo(s,r):e[o]=s},{allOwnKeys:n}),e),fu=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),du=(e,t,r,n)=>{e.prototype=Object.create(t.prototype,n),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),r&&Object.assign(e.prototype,r)},pu=(e,t,r,n)=>{let s,o,i;const c={};if(t=t||{},e==null)return t;do{for(s=Object.getOwnPropertyNames(e),o=s.length;o-- >0;)i=s[o],(!n||n(i,e,t))&&!c[i]&&(t[i]=e[i],c[i]=!0);e=r!==!1&&Nn(e)}while(e&&(!r||r(e,t))&&e!==Object.prototype);return t},yu=(e,t,r)=>{e=String(e),(r===void 0||r>e.length)&&(r=e.length),r-=t.length;const n=e.indexOf(t,r);return n!==-1&&n===r},mu=e=>{if(!e)return null;if(ze(e))return e;let t=e.length;if(!ri(t))return null;const r=new Array(t);for(;t-- >0;)r[t]=e[t];return r},gu=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Nn(Uint8Array)),wu=(e,t)=>{const n=(e&&e[fr]).call(e);let s;for(;(s=n.next())&&!s.done;){const o=s.value;t.call(e,o[0],o[1])}},bu=(e,t)=>{let r;const n=[];for(;(r=e.exec(t))!==null;)n.push(r);return n},Eu=re("HTMLFormElement"),xu=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(r,n,s){return n.toUpperCase()+s}),ys=(({hasOwnProperty:e})=>(t,r)=>e.call(t,r))(Object.prototype),ku=re("RegExp"),oi=(e,t)=>{const r=Object.getOwnPropertyDescriptors(e),n={};pt(r,(s,o)=>{let i;(i=t(s,o,e))!==!1&&(n[o]=i||s)}),Object.defineProperties(e,n)},vu=e=>{oi(e,(t,r)=>{if(J(e)&&["arguments","caller","callee"].indexOf(r)!==-1)return!1;const n=e[r];if(J(n)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+r+"'")})}})},Su=(e,t)=>{const r={},n=s=>{s.forEach(o=>{r[o]=!0})};return ze(e)?n(e):n(String(e).split(t)),r},Tu=()=>{},Au=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function _u(e){return!!(e&&J(e.append)&&e[ei]==="FormData"&&e[fr])}const Ku=e=>{const t=new Array(10),r=(n,s)=>{if(dt(n)){if(t.indexOf(n)>=0)return;if(ft(n))return n;if(!("toJSON"in n)){t[s]=n;const o=ze(n)?[]:{};return pt(n,(i,c)=>{const a=r(i,s+1);!at(a)&&(o[c]=a)}),t[s]=void 0,o}}return n};return r(e,0)},Ou=re("AsyncFunction"),Ru=e=>e&&(dt(e)||J(e))&&J(e.then)&&J(e.catch),ii=((e,t)=>e?setImmediate:t?((r,n)=>(ke.addEventListener("message",({source:s,data:o})=>{s===ke&&o===r&&n.length&&n.shift()()},!1),s=>{n.push(s),ke.postMessage(r,"*")}))(`axios@${Math.random()}`,[]):r=>setTimeout(r))(typeof setImmediate=="function",J(ke.postMessage)),Cu=typeof queueMicrotask<"u"?queueMicrotask.bind(ke):typeof process<"u"&&process.nextTick||ii,Iu=e=>e!=null&&J(e[fr]),g={isArray:ze,isArrayBuffer:ti,isBuffer:ft,isFormData:su,isArrayBufferView:Xl,isString:ql,isNumber:ri,isBoolean:Wl,isObject:dt,isPlainObject:Ct,isEmptyObject:Zl,isReadableStream:iu,isRequest:cu,isResponse:au,isHeaders:lu,isUndefined:at,isDate:Ql,isFile:eu,isBlob:tu,isRegExp:ku,isFunction:J,isStream:nu,isURLSearchParams:ou,isTypedArray:gu,isFileList:ru,forEach:pt,merge:qr,extend:hu,trim:uu,stripBOM:fu,inherits:du,toFlatObject:pu,kindOf:dr,kindOfTest:re,endsWith:yu,toArray:mu,forEachEntry:wu,matchAll:bu,isHTMLForm:Eu,hasOwnProperty:ys,hasOwnProp:ys,reduceDescriptors:oi,freezeMethods:vu,toObjectSet:Su,toCamelCase:xu,noop:Tu,toFiniteNumber:Au,findKey:ni,global:ke,isContextDefined:si,isSpecCompliantForm:_u,toJSONObject:Ku,isAsyncFn:Ou,isThenable:Ru,setImmediate:ii,asap:Cu,isIterable:Iu};function R(e,t,r,n,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),r&&(this.config=r),n&&(this.request=n),s&&(this.response=s,this.status=s.status?s.status:null)}g.inherits(R,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:g.toJSONObject(this.config),code:this.code,status:this.status}}});const ci=R.prototype,ai={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{ai[e]={value:e}});Object.defineProperties(R,ai);Object.defineProperty(ci,"isAxiosError",{value:!0});R.from=(e,t,r,n,s,o)=>{const i=Object.create(ci);return g.toFlatObject(e,i,function(a){return a!==Error.prototype},c=>c!=="isAxiosError"),R.call(i,e.message,t,r,n,s),i.cause=e,i.name=e.name,o&&Object.assign(i,o),i};const Pu=null;function Wr(e){return g.isPlainObject(e)||g.isArray(e)}function li(e){return g.endsWith(e,"[]")?e.slice(0,-2):e}function ms(e,t,r){return e?e.concat(t).map(function(s,o){return s=li(s),!r&&o?"["+s+"]":s}).join(r?".":""):t}function ju(e){return g.isArray(e)&&!e.some(Wr)}const Bu=g.toFlatObject(g,{},null,function(t){return/^is[A-Z]/.test(t)});function yr(e,t,r){if(!g.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,r=g.toFlatObject(r,{metaTokens:!0,dots:!1,indexes:!1},!1,function(f,d){return!g.isUndefined(d[f])});const n=r.metaTokens,s=r.visitor||u,o=r.dots,i=r.indexes,a=(r.Blob||typeof Blob<"u"&&Blob)&&g.isSpecCompliantForm(t);if(!g.isFunction(s))throw new TypeError("visitor must be a function");function l(p){if(p===null)return"";if(g.isDate(p))return p.toISOString();if(g.isBoolean(p))return p.toString();if(!a&&g.isBlob(p))throw new R("Blob is not supported. Use a Buffer instead.");return g.isArrayBuffer(p)||g.isTypedArray(p)?a&&typeof Blob=="function"?new Blob([p]):Buffer.from(p):p}function u(p,f,d){let b=p;if(p&&!d&&typeof p=="object"){if(g.endsWith(f,"{}"))f=n?f:f.slice(0,-2),p=JSON.stringify(p);else if(g.isArray(p)&&ju(p)||(g.isFileList(p)||g.endsWith(f,"[]"))&&(b=g.toArray(p)))return f=li(f),b.forEach(function(E,x){!(g.isUndefined(E)||E===null)&&t.append(i===!0?ms([f],x,o):i===null?f:f+"[]",l(E))}),!1}return Wr(p)?!0:(t.append(ms(d,f,o),l(p)),!1)}const h=[],m=Object.assign(Bu,{defaultVisitor:u,convertValue:l,isVisitable:Wr});function y(p,f){if(!g.isUndefined(p)){if(h.indexOf(p)!==-1)throw Error("Circular reference detected in "+f.join("."));h.push(p),g.forEach(p,function(b,w){(!(g.isUndefined(b)||b===null)&&s.call(t,b,g.isString(w)?w.trim():w,f,m))===!0&&y(b,f?f.concat(w):[w])}),h.pop()}}if(!g.isObject(e))throw new TypeError("data must be an object");return y(e),t}function gs(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(n){return t[n]})}function Ln(e,t){this._pairs=[],e&&yr(e,this,t)}const ui=Ln.prototype;ui.append=function(t,r){this._pairs.push([t,r])};ui.toString=function(t){const r=t?function(n){return t.call(this,n,gs)}:gs;return this._pairs.map(function(s){return r(s[0])+"="+r(s[1])},"").join("&")};function Fu(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function hi(e,t,r){if(!t)return e;const n=r&&r.encode||Fu;g.isFunction(r)&&(r={serialize:r});const s=r&&r.serialize;let o;if(s?o=s(t,r):o=g.isURLSearchParams(t)?t.toString():new Ln(t,r).toString(n),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class ws{constructor(){this.handlers=[]}use(t,r,n){return this.handlers.push({fulfilled:t,rejected:r,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){g.forEach(this.handlers,function(n){n!==null&&t(n)})}}const fi={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Nu=typeof URLSearchParams<"u"?URLSearchParams:Ln,Lu=typeof FormData<"u"?FormData:null,Du=typeof Blob<"u"?Blob:null,Mu={isBrowser:!0,classes:{URLSearchParams:Nu,FormData:Lu,Blob:Du},protocols:["http","https","file","blob","url","data"]},Dn=typeof window<"u"&&typeof document<"u",Zr=typeof navigator=="object"&&navigator||void 0,Uu=Dn&&(!Zr||["ReactNative","NativeScript","NS"].indexOf(Zr.product)<0),Hu=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",zu=Dn&&window.location.href||"http://localhost",$u=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Dn,hasStandardBrowserEnv:Uu,hasStandardBrowserWebWorkerEnv:Hu,navigator:Zr,origin:zu},Symbol.toStringTag,{value:"Module"})),$={...$u,...Mu};function Yu(e,t){return yr(e,new $.classes.URLSearchParams,{visitor:function(r,n,s,o){return $.isNode&&g.isBuffer(r)?(this.append(n,r.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)},...t})}function Vu(e){return g.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Ju(e){const t={},r=Object.keys(e);let n;const s=r.length;let o;for(n=0;n<s;n++)o=r[n],t[o]=e[o];return t}function di(e){function t(r,n,s,o){let i=r[o++];if(i==="__proto__")return!0;const c=Number.isFinite(+i),a=o>=r.length;return i=!i&&g.isArray(s)?s.length:i,a?(g.hasOwnProp(s,i)?s[i]=[s[i],n]:s[i]=n,!c):((!s[i]||!g.isObject(s[i]))&&(s[i]=[]),t(r,n,s[i],o)&&g.isArray(s[i])&&(s[i]=Ju(s[i])),!c)}if(g.isFormData(e)&&g.isFunction(e.entries)){const r={};return g.forEachEntry(e,(n,s)=>{t(Vu(n),s,r,0)}),r}return null}function Gu(e,t,r){if(g.isString(e))try{return(t||JSON.parse)(e),g.trim(e)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(e)}const yt={transitional:fi,adapter:["xhr","http","fetch"],transformRequest:[function(t,r){const n=r.getContentType()||"",s=n.indexOf("application/json")>-1,o=g.isObject(t);if(o&&g.isHTMLForm(t)&&(t=new FormData(t)),g.isFormData(t))return s?JSON.stringify(di(t)):t;if(g.isArrayBuffer(t)||g.isBuffer(t)||g.isStream(t)||g.isFile(t)||g.isBlob(t)||g.isReadableStream(t))return t;if(g.isArrayBufferView(t))return t.buffer;if(g.isURLSearchParams(t))return r.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return Yu(t,this.formSerializer).toString();if((c=g.isFileList(t))||n.indexOf("multipart/form-data")>-1){const a=this.env&&this.env.FormData;return yr(c?{"files[]":t}:t,a&&new a,this.formSerializer)}}return o||s?(r.setContentType("application/json",!1),Gu(t)):t}],transformResponse:[function(t){const r=this.transitional||yt.transitional,n=r&&r.forcedJSONParsing,s=this.responseType==="json";if(g.isResponse(t)||g.isReadableStream(t))return t;if(t&&g.isString(t)&&(n&&!this.responseType||s)){const i=!(r&&r.silentJSONParsing)&&s;try{return JSON.parse(t)}catch(c){if(i)throw c.name==="SyntaxError"?R.from(c,R.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:$.classes.FormData,Blob:$.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};g.forEach(["delete","get","head","post","put","patch"],e=>{yt.headers[e]={}});const Xu=g.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),qu=e=>{const t={};let r,n,s;return e&&e.split(`
|
|
2050
|
-
|
|
2051
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...r){const n=new this(t);return r.forEach(s=>n.set(s)),n}static accessor(t){const n=(this[bs]=this[bs]={accessors:{}}).accessors,s=this.prototype;function o(i){const c=We(i);n[c]||(eh(s,i),n[c]=!0)}return g.isArray(t)?t.forEach(o):o(t),this}};G.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);g.reduceDescriptors(G.prototype,({value:e},t)=>{let r=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(n){this[r]=n}}});g.freezeMethods(G);function Ir(e,t){const r=this||yt,n=t||r,s=G.from(n.headers);let o=n.data;return g.forEach(e,function(c){o=c.call(r,o,s.normalize(),t?t.status:void 0)}),s.normalize(),o}function pi(e){return!!(e&&e.__CANCEL__)}function $e(e,t,r){R.call(this,e??"canceled",R.ERR_CANCELED,t,r),this.name="CanceledError"}g.inherits($e,R,{__CANCEL__:!0});function yi(e,t,r){const n=r.config.validateStatus;!r.status||!n||n(r.status)?e(r):t(new R("Request failed with status code "+r.status,[R.ERR_BAD_REQUEST,R.ERR_BAD_RESPONSE][Math.floor(r.status/100)-4],r.config,r.request,r))}function th(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function rh(e,t){e=e||10;const r=new Array(e),n=new Array(e);let s=0,o=0,i;return t=t!==void 0?t:1e3,function(a){const l=Date.now(),u=n[o];i||(i=l),r[s]=a,n[s]=l;let h=o,m=0;for(;h!==s;)m+=r[h++],h=h%e;if(s=(s+1)%e,s===o&&(o=(o+1)%e),l-i<t)return;const y=u&&l-u;return y?Math.round(m*1e3/y):void 0}}function nh(e,t){let r=0,n=1e3/t,s,o;const i=(l,u=Date.now())=>{r=u,s=null,o&&(clearTimeout(o),o=null),e(...l)};return[(...l)=>{const u=Date.now(),h=u-r;h>=n?i(l,u):(s=l,o||(o=setTimeout(()=>{o=null,i(s)},n-h)))},()=>s&&i(s)]}const Vt=(e,t,r=3)=>{let n=0;const s=rh(50,250);return nh(o=>{const i=o.loaded,c=o.lengthComputable?o.total:void 0,a=i-n,l=s(a),u=i<=c;n=i;const h={loaded:i,total:c,progress:c?i/c:void 0,bytes:a,rate:l||void 0,estimated:l&&c&&u?(c-i)/l:void 0,event:o,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(h)},r)},Es=(e,t)=>{const r=e!=null;return[n=>t[0]({lengthComputable:r,total:e,loaded:n}),t[1]]},xs=e=>(...t)=>g.asap(()=>e(...t)),sh=$.hasStandardBrowserEnv?((e,t)=>r=>(r=new URL(r,$.origin),e.protocol===r.protocol&&e.host===r.host&&(t||e.port===r.port)))(new URL($.origin),$.navigator&&/(msie|trident)/i.test($.navigator.userAgent)):()=>!0,oh=$.hasStandardBrowserEnv?{write(e,t,r,n,s,o){const i=[e+"="+encodeURIComponent(t)];g.isNumber(r)&&i.push("expires="+new Date(r).toGMTString()),g.isString(n)&&i.push("path="+n),g.isString(s)&&i.push("domain="+s),o===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function ih(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ch(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function mi(e,t,r){let n=!ih(t);return e&&(n||r==!1)?ch(e,t):t}const ks=e=>e instanceof G?{...e}:e;function Ae(e,t){t=t||{};const r={};function n(l,u,h,m){return g.isPlainObject(l)&&g.isPlainObject(u)?g.merge.call({caseless:m},l,u):g.isPlainObject(u)?g.merge({},u):g.isArray(u)?u.slice():u}function s(l,u,h,m){if(g.isUndefined(u)){if(!g.isUndefined(l))return n(void 0,l,h,m)}else return n(l,u,h,m)}function o(l,u){if(!g.isUndefined(u))return n(void 0,u)}function i(l,u){if(g.isUndefined(u)){if(!g.isUndefined(l))return n(void 0,l)}else return n(void 0,u)}function c(l,u,h){if(h in t)return n(l,u);if(h in e)return n(void 0,l)}const a={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:c,headers:(l,u,h)=>s(ks(l),ks(u),h,!0)};return g.forEach(Object.keys({...e,...t}),function(u){const h=a[u]||s,m=h(e[u],t[u],u);g.isUndefined(m)&&h!==c||(r[u]=m)}),r}const gi=e=>{const t=Ae({},e);let{data:r,withXSRFToken:n,xsrfHeaderName:s,xsrfCookieName:o,headers:i,auth:c}=t;t.headers=i=G.from(i),t.url=hi(mi(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&i.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let a;if(g.isFormData(r)){if($.hasStandardBrowserEnv||$.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if((a=i.getContentType())!==!1){const[l,...u]=a?a.split(";").map(h=>h.trim()).filter(Boolean):[];i.setContentType([l||"multipart/form-data",...u].join("; "))}}if($.hasStandardBrowserEnv&&(n&&g.isFunction(n)&&(n=n(t)),n||n!==!1&&sh(t.url))){const l=s&&o&&oh.read(o);l&&i.set(s,l)}return t},ah=typeof XMLHttpRequest<"u",lh=ah&&function(e){return new Promise(function(r,n){const s=gi(e);let o=s.data;const i=G.from(s.headers).normalize();let{responseType:c,onUploadProgress:a,onDownloadProgress:l}=s,u,h,m,y,p;function f(){y&&y(),p&&p(),s.cancelToken&&s.cancelToken.unsubscribe(u),s.signal&&s.signal.removeEventListener("abort",u)}let d=new XMLHttpRequest;d.open(s.method.toUpperCase(),s.url,!0),d.timeout=s.timeout;function b(){if(!d)return;const E=G.from("getAllResponseHeaders"in d&&d.getAllResponseHeaders()),k={data:!c||c==="text"||c==="json"?d.responseText:d.response,status:d.status,statusText:d.statusText,headers:E,config:e,request:d};yi(function(S){r(S),f()},function(S){n(S),f()},k),d=null}"onloadend"in d?d.onloadend=b:d.onreadystatechange=function(){!d||d.readyState!==4||d.status===0&&!(d.responseURL&&d.responseURL.indexOf("file:")===0)||setTimeout(b)},d.onabort=function(){d&&(n(new R("Request aborted",R.ECONNABORTED,e,d)),d=null)},d.onerror=function(){n(new R("Network Error",R.ERR_NETWORK,e,d)),d=null},d.ontimeout=function(){let x=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const k=s.transitional||fi;s.timeoutErrorMessage&&(x=s.timeoutErrorMessage),n(new R(x,k.clarifyTimeoutError?R.ETIMEDOUT:R.ECONNABORTED,e,d)),d=null},o===void 0&&i.setContentType(null),"setRequestHeader"in d&&g.forEach(i.toJSON(),function(x,k){d.setRequestHeader(k,x)}),g.isUndefined(s.withCredentials)||(d.withCredentials=!!s.withCredentials),c&&c!=="json"&&(d.responseType=s.responseType),l&&([m,p]=Vt(l,!0),d.addEventListener("progress",m)),a&&d.upload&&([h,y]=Vt(a),d.upload.addEventListener("progress",h),d.upload.addEventListener("loadend",y)),(s.cancelToken||s.signal)&&(u=E=>{d&&(n(!E||E.type?new $e(null,e,d):E),d.abort(),d=null)},s.cancelToken&&s.cancelToken.subscribe(u),s.signal&&(s.signal.aborted?u():s.signal.addEventListener("abort",u)));const w=th(s.url);if(w&&$.protocols.indexOf(w)===-1){n(new R("Unsupported protocol "+w+":",R.ERR_BAD_REQUEST,e));return}d.send(o||null)})},uh=(e,t)=>{const{length:r}=e=e?e.filter(Boolean):[];if(t||r){let n=new AbortController,s;const o=function(l){if(!s){s=!0,c();const u=l instanceof Error?l:this.reason;n.abort(u instanceof R?u:new $e(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,o(new R(`timeout ${t} of ms exceeded`,R.ETIMEDOUT))},t);const c=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(l=>{l.unsubscribe?l.unsubscribe(o):l.removeEventListener("abort",o)}),e=null)};e.forEach(l=>l.addEventListener("abort",o));const{signal:a}=n;return a.unsubscribe=()=>g.asap(c),a}},hh=function*(e,t){let r=e.byteLength;if(r<t){yield e;return}let n=0,s;for(;n<r;)s=n+t,yield e.slice(n,s),n=s},fh=async function*(e,t){for await(const r of dh(e))yield*hh(r,t)},dh=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:r,value:n}=await t.read();if(r)break;yield n}}finally{await t.cancel()}},vs=(e,t,r,n)=>{const s=fh(e,t);let o=0,i,c=a=>{i||(i=!0,n&&n(a))};return new ReadableStream({async pull(a){try{const{done:l,value:u}=await s.next();if(l){c(),a.close();return}let h=u.byteLength;if(r){let m=o+=h;r(m)}a.enqueue(new Uint8Array(u))}catch(l){throw c(l),l}},cancel(a){return c(a),s.return()}},{highWaterMark:2})},mr=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",wi=mr&&typeof ReadableStream=="function",ph=mr&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),bi=(e,...t)=>{try{return!!e(...t)}catch{return!1}},yh=wi&&bi(()=>{let e=!1;const t=new Request($.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Ss=64*1024,Qr=wi&&bi(()=>g.isReadableStream(new Response("").body)),Jt={stream:Qr&&(e=>e.body)};mr&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!Jt[t]&&(Jt[t]=g.isFunction(e[t])?r=>r[t]():(r,n)=>{throw new R(`Response type '${t}' is not supported`,R.ERR_NOT_SUPPORT,n)})})})(new Response);const mh=async e=>{if(e==null)return 0;if(g.isBlob(e))return e.size;if(g.isSpecCompliantForm(e))return(await new Request($.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(g.isArrayBufferView(e)||g.isArrayBuffer(e))return e.byteLength;if(g.isURLSearchParams(e)&&(e=e+""),g.isString(e))return(await ph(e)).byteLength},gh=async(e,t)=>{const r=g.toFiniteNumber(e.getContentLength());return r??mh(t)},wh=mr&&(async e=>{let{url:t,method:r,data:n,signal:s,cancelToken:o,timeout:i,onDownloadProgress:c,onUploadProgress:a,responseType:l,headers:u,withCredentials:h="same-origin",fetchOptions:m}=gi(e);l=l?(l+"").toLowerCase():"text";let y=uh([s,o&&o.toAbortSignal()],i),p;const f=y&&y.unsubscribe&&(()=>{y.unsubscribe()});let d;try{if(a&&yh&&r!=="get"&&r!=="head"&&(d=await gh(u,n))!==0){let k=new Request(t,{method:"POST",body:n,duplex:"half"}),v;if(g.isFormData(n)&&(v=k.headers.get("content-type"))&&u.setContentType(v),k.body){const[S,T]=Es(d,Vt(xs(a)));n=vs(k.body,Ss,S,T)}}g.isString(h)||(h=h?"include":"omit");const b="credentials"in Request.prototype;p=new Request(t,{...m,signal:y,method:r.toUpperCase(),headers:u.normalize().toJSON(),body:n,duplex:"half",credentials:b?h:void 0});let w=await fetch(p,m);const E=Qr&&(l==="stream"||l==="response");if(Qr&&(c||E&&f)){const k={};["status","statusText","headers"].forEach(_=>{k[_]=w[_]});const v=g.toFiniteNumber(w.headers.get("content-length")),[S,T]=c&&Es(v,Vt(xs(c),!0))||[];w=new Response(vs(w.body,Ss,S,()=>{T&&T(),f&&f()}),k)}l=l||"text";let x=await Jt[g.findKey(Jt,l)||"text"](w,e);return!E&&f&&f(),await new Promise((k,v)=>{yi(k,v,{data:x,headers:G.from(w.headers),status:w.status,statusText:w.statusText,config:e,request:p})})}catch(b){throw f&&f(),b&&b.name==="TypeError"&&/Load failed|fetch/i.test(b.message)?Object.assign(new R("Network Error",R.ERR_NETWORK,e,p),{cause:b.cause||b}):R.from(b,b&&b.code,e,p)}}),en={http:Pu,xhr:lh,fetch:wh};g.forEach(en,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ts=e=>`- ${e}`,bh=e=>g.isFunction(e)||e===null||e===!1,Ei={getAdapter:e=>{e=g.isArray(e)?e:[e];const{length:t}=e;let r,n;const s={};for(let o=0;o<t;o++){r=e[o];let i;if(n=r,!bh(r)&&(n=en[(i=String(r)).toLowerCase()],n===void 0))throw new R(`Unknown adapter '${i}'`);if(n)break;s[i||"#"+o]=n}if(!n){const o=Object.entries(s).map(([c,a])=>`adapter ${c} `+(a===!1?"is not supported by the environment":"is not available in the build"));let i=t?o.length>1?`since :
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
`+o):n.stack=o}catch{}}throw n}}_request(t,r){typeof t=="string"?(r=r||{},r.url=t):r=t||{},r=Ae(this.defaults,r);const{transitional:n,paramsSerializer:s,headers:o}=r;n!==void 0&&Pt.assertOptions(n,{silentJSONParsing:oe.transitional(oe.boolean),forcedJSONParsing:oe.transitional(oe.boolean),clarifyTimeoutError:oe.transitional(oe.boolean)},!1),s!=null&&(g.isFunction(s)?r.paramsSerializer={serialize:s}:Pt.assertOptions(s,{encode:oe.function,serialize:oe.function},!0)),r.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?r.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:r.allowAbsoluteUrls=!0),Pt.assertOptions(r,{baseUrl:oe.spelling("baseURL"),withXsrfToken:oe.spelling("withXSRFToken")},!0),r.method=(r.method||this.defaults.method||"get").toLowerCase();let i=o&&g.merge(o.common,o[r.method]);o&&g.forEach(["delete","get","head","post","put","patch","common"],p=>{delete o[p]}),r.headers=G.concat(i,o);const c=[];let a=!0;this.interceptors.request.forEach(function(f){typeof f.runWhen=="function"&&f.runWhen(r)===!1||(a=a&&f.synchronous,c.unshift(f.fulfilled,f.rejected))});const l=[];this.interceptors.response.forEach(function(f){l.push(f.fulfilled,f.rejected)});let u,h=0,m;if(!a){const p=[As.bind(this),void 0];for(p.unshift(...c),p.push(...l),m=p.length,u=Promise.resolve(r);h<m;)u=u.then(p[h++],p[h++]);return u}m=c.length;let y=r;for(h=0;h<m;){const p=c[h++],f=c[h++];try{y=p(y)}catch(d){f.call(this,d);break}}try{u=As.call(this,y)}catch(p){return Promise.reject(p)}for(h=0,m=l.length;h<m;)u=u.then(l[h++],l[h++]);return u}getUri(t){t=Ae(this.defaults,t);const r=mi(t.baseURL,t.url,t.allowAbsoluteUrls);return hi(r,t.params,t.paramsSerializer)}};g.forEach(["delete","get","head","options"],function(t){ve.prototype[t]=function(r,n){return this.request(Ae(n||{},{method:t,url:r,data:(n||{}).data}))}});g.forEach(["post","put","patch"],function(t){function r(n){return function(o,i,c){return this.request(Ae(c||{},{method:t,headers:n?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}ve.prototype[t]=r(),ve.prototype[t+"Form"]=r(!0)});let xh=class ki{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(o){r=o});const n=this;this.promise.then(s=>{if(!n._listeners)return;let o=n._listeners.length;for(;o-- >0;)n._listeners[o](s);n._listeners=null}),this.promise.then=s=>{let o;const i=new Promise(c=>{n.subscribe(c),o=c}).then(s);return i.cancel=function(){n.unsubscribe(o)},i},t(function(o,i,c){n.reason||(n.reason=new $e(o,i,c),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const r=this._listeners.indexOf(t);r!==-1&&this._listeners.splice(r,1)}toAbortSignal(){const t=new AbortController,r=n=>{t.abort(n)};return this.subscribe(r),t.signal.unsubscribe=()=>this.unsubscribe(r),t.signal}static source(){let t;return{token:new ki(function(s){t=s}),cancel:t}}};function kh(e){return function(r){return e.apply(null,r)}}function vh(e){return g.isObject(e)&&e.isAxiosError===!0}const tn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(tn).forEach(([e,t])=>{tn[t]=e});function vi(e){const t=new ve(e),r=Qo(ve.prototype.request,t);return g.extend(r,ve.prototype,t,{allOwnKeys:!0}),g.extend(r,t,null,{allOwnKeys:!0}),r.create=function(s){return vi(Ae(e,s))},r}const I=vi(yt);I.Axios=ve;I.CanceledError=$e;I.CancelToken=xh;I.isCancel=pi;I.VERSION=xi;I.toFormData=yr;I.AxiosError=R;I.Cancel=I.CanceledError;I.all=function(t){return Promise.all(t)};I.spread=kh;I.isAxiosError=vh;I.mergeConfig=Ae;I.AxiosHeaders=G;I.formToJSON=e=>di(g.isHTMLForm(e)?new FormData(e):e);I.getAdapter=Ei.getAdapter;I.HttpStatusCode=tn;I.default=I;const{Axios:kf,AxiosError:vf,CanceledError:Sf,isCancel:Tf,CancelToken:Af,VERSION:_f,all:Kf,Cancel:Of,isAxiosError:Rf,spread:Cf,toFormData:If,AxiosHeaders:Pf,HttpStatusCode:jf,formToJSON:Bf,getAdapter:Ff,mergeConfig:Nf}=I;async function Sh(e){try{return(await I.get("/api/getPublicKeys",{params:{emails:e},withCredentials:!0,headers:{"Content-Type":"application/json"}})).data}catch(t){throw I.isAxiosError(t)?t.response?.status===401?new Error("Unauthorized: Invalid or expired token"):t.response?.status===403?new Error("Forbidden: Insufficient permissions"):t.response?.status===404?new Error("User is not found"):new Error("AxiosError:",t):new Error("Failed to retrieve public keys",{cause:t})}}async function Th(e){try{const t=await Sh(e),r=[];for(const n of t){const s=await Eo(n);r.push(s)}return r}catch(t){throw new Error("Failed to get recipients public keys",{cause:t})}}class mt{constructor(t=0,r="Network Error"){this.status=t,this.text=r}}const Ah=()=>{if(!(typeof localStorage>"u"))return{get:e=>Promise.resolve(localStorage.getItem(e)),set:(e,t)=>Promise.resolve(localStorage.setItem(e,t)),remove:e=>Promise.resolve(localStorage.removeItem(e))}},z={origin:"https://api.emailjs.com",blockHeadless:!1,storageProvider:Ah()},Mn=e=>e?typeof e=="string"?{publicKey:e}:e.toString()==="[object Object]"?e:{}:{},_h=(e,t="https://api.emailjs.com")=>{if(!e)return;const r=Mn(e);z.publicKey=r.publicKey,z.blockHeadless=r.blockHeadless,z.storageProvider=r.storageProvider,z.blockList=r.blockList,z.limitRate=r.limitRate,z.origin=r.origin||t},Si=async(e,t,r={})=>{const n=await fetch(z.origin+e,{method:"POST",headers:r,body:t}),s=await n.text(),o=new mt(n.status,s);if(n.ok)return o;throw o},Ti=(e,t,r)=>{if(!e||typeof e!="string")throw"The public key is required. Visit https://dashboard.emailjs.com/admin/account";if(!t||typeof t!="string")throw"The service ID is required. Visit https://dashboard.emailjs.com/admin";if(!r||typeof r!="string")throw"The template ID is required. Visit https://dashboard.emailjs.com/admin/templates"},Kh=e=>{if(e&&e.toString()!=="[object Object]")throw"The template params have to be the object. Visit https://www.emailjs.com/docs/sdk/send/"},Ai=e=>e.webdriver||!e.languages||e.languages.length===0,_i=()=>new mt(451,"Unavailable For Headless Browser"),Oh=(e,t)=>{if(!Array.isArray(e))throw"The BlockList list has to be an array";if(typeof t!="string")throw"The BlockList watchVariable has to be a string"},Rh=e=>!e.list?.length||!e.watchVariable,Ch=(e,t)=>e instanceof FormData?e.get(t):e[t],Ki=(e,t)=>{if(Rh(e))return!1;Oh(e.list,e.watchVariable);const r=Ch(t,e.watchVariable);return typeof r!="string"?!1:e.list.includes(r)},Oi=()=>new mt(403,"Forbidden"),Ih=(e,t)=>{if(typeof e!="number"||e<0)throw"The LimitRate throttle has to be a positive number";if(t&&typeof t!="string")throw"The LimitRate ID has to be a non-empty string"},Ph=async(e,t,r)=>{const n=Number(await r.get(e)||0);return t-Date.now()+n},Ri=async(e,t,r)=>{if(!t.throttle||!r)return!1;Ih(t.throttle,t.id);const n=t.id||e;return await Ph(n,t.throttle,r)>0?!0:(await r.set(n,Date.now().toString()),!1)},Ci=()=>new mt(429,"Too Many Requests"),jh=async(e,t,r,n)=>{const s=Mn(n),o=s.publicKey||z.publicKey,i=s.blockHeadless||z.blockHeadless,c=s.storageProvider||z.storageProvider,a={...z.blockList,...s.blockList},l={...z.limitRate,...s.limitRate};return i&&Ai(navigator)?Promise.reject(_i()):(Ti(o,e,t),Kh(r),r&&Ki(a,r)?Promise.reject(Oi()):await Ri(location.pathname,l,c)?Promise.reject(Ci()):Si("/api/v1.0/email/send",JSON.stringify({lib_version:"4.4.1",user_id:o,service_id:e,template_id:t,template_params:r}),{"Content-type":"application/json"}))},Bh=e=>{if(!e||e.nodeName!=="FORM")throw"The 3rd parameter is expected to be the HTML form element or the style selector of the form"},Fh=e=>typeof e=="string"?document.querySelector(e):e,Nh=async(e,t,r,n)=>{const s=Mn(n),o=s.publicKey||z.publicKey,i=s.blockHeadless||z.blockHeadless,c=z.storageProvider||s.storageProvider,a={...z.blockList,...s.blockList},l={...z.limitRate,...s.limitRate};if(i&&Ai(navigator))return Promise.reject(_i());const u=Fh(r);Ti(o,e,t),Bh(u);const h=new FormData(u);return Ki(a,h)?Promise.reject(Oi()):await Ri(location.pathname,l,c)?Promise.reject(Ci()):(h.append("lib_version","4.4.1"),h.append("service_id",e),h.append("template_id",t),h.append("user_id",o),Si("/api/v1.0/email/send-form",h))},Lh={init:_h,send:jh,sendForm:Nh,EmailJSResponseStatus:mt},Dh={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Ze={getVariable:Uh},Mh={serviceID:"VITE_SERVICE_ID",templateID:"VITE_TEMPLATE_ID",publicKey:"VITE_PUBLIC_KEY",baseUrl:"VITE_BASE_URL"};function Uh(e){const t=Mh[e];if(!t)throw new Error(`Unknown variable name: "${e}"`);const r=Dh[t];if(!r)throw new Error(`Variable "${e}" is empty`);return r}async function Ii(e,t){try{const r={from_email:t.sender.email,from_name:t.sender.name,to_email:t.recipient.email,to_name:t.recipient.name,email_subject:t.subject,email_body:e,timestamp:new Date().toISOString()},n=Ze.getVariable("serviceID"),s=Ze.getVariable("templateID"),o=Ze.getVariable("publicKey");await Lh.send(n,s,r,o).then(i=>{console.log("SUCCESS!",i.status,i.text)},i=>{throw new Error(`emailjs error: ${i}`)})}catch(r){throw new Error("Failed to send an email",{cause:r})}}async function Hh(e){try{if(e.recipientID!==e.params.recipient.id)throw new Error("Email is encrypted for another recipient");const t=vo(e);await Ii(t,e.params)}catch(t){throw new Error(`Failed to email to the recipient: ${t.message}`,{cause:t})}}async function zh(e){try{const t=So(e);await Ii(t,e.params)}catch(t){throw new Error("Failed to email to the recipient",{cause:t})}}const $h=Object.freeze(Object.defineProperty({__proto__:null,getRecipientsPublicKeys:Th,sendHybridEmail:Hh,sendPwdProtectedEmail:zh},Symbol.toStringTag,{value:"Module"}));var W=(e=>(e.IDENTITY="identity",e.ENCRYPTION="encryption",e.RECOVERY="recovery",e.INDEX="index",e))(W||{});function Yh(e){return sessionStorage.getItem(e)}function Vh(e,t){return sessionStorage.setItem(e,t)}function Jh(e){sessionStorage.removeItem(e)}function Gh(e){return!!sessionStorage.getItem(e)}function Xh(){sessionStorage.clear()}const Un={set:Vh,get:Yh,removeItem:Jh,exists:Gh,clear:Xh},qh=Object.freeze(Object.defineProperty({__proto__:null,default:Un},Symbol.toStringTag,{value:"Module"}));async function rn(e,t,r,n){try{const s=r+n,o=D(t);return await sr(e,o,s)}catch(s){throw new Error("Failed to encrypt keystore content",{cause:s})}}async function Hn(e,t,r,n){try{const s=r+n,o=await tt(e,t,s);return U(o)}catch(s){throw new Error("Failed to decrypt keystore content",{cause:s})}}function wr(){try{const e=Un.get("userID");if(!e)throw new Error("No UserID");return e}catch(e){throw new Error("Failed to get UserID from session storage",{cause:e})}}function br(){try{const e=Un.get("baseKey");if(!e)throw new Error("No base key");return D(e)}catch(e){throw new Error("Failed to get base key from session storage",{cause:e})}}async function Pi(e){return ht(Cs,e)}async function ji(e){const t=await Ue(V,e);return ht(Ps,t)}async function Bi(e){return ht(Is,e)}function Fi(){return so(V)}async function Ni(){try{const e=await qt(),t=vn();return{userPrivateKey:e.privateKey,userPublicKey:e.publicKey,userPublicKyberKey:t.publicKey,userPrivateKyberKey:t.secretKey}}catch(e){throw new Error("Failed to generate encryption keys",{cause:e})}}async function Wh(){try{const e=wr(),t=br(),r=await Ni(),n=await Ys(r),s=await Bi(t),o=await rn(s,n,e,sn),i={userID:e,type:W.ENCRYPTION,encryptedKeys:o},c=Fi(),a=await ji(c),l=await rn(a,n,e,on),u={userID:e,type:W.RECOVERY,encryptedKeys:l};return{encryptionKeystore:i,recoveryKeystore:u,recoveryCodes:c}}catch(e){throw new Error("Failed to create encryption and recovery keystores",{cause:e})}}async function Zh(e){try{if(e.type!=W.ENCRYPTION)throw new Error("Input is invalid");const t=br(),r=await Bi(t),n=await Hn(r,e.encryptedKeys,e.userID,sn);return await hn(n)}catch(t){throw new Error("Failed to open encryption keystore",{cause:t})}}async function Qh(e,t){try{if(t.type!=W.RECOVERY)throw new Error("Input is invalid");const r=await ji(e),n=await Hn(r,t.encryptedKeys,t.userID,on);return await hn(n)}catch(r){throw new Error("Failed to open recovery keystore",{cause:r})}}async function Li(){try{const e=await qt();return{userPrivateKey:e.privateKey,userPublicKey:e.publicKey}}catch(e){throw new Error("Failed to generate idenity keys",{cause:e})}}async function ef(){try{const e=W.IDENTITY,t=wr(),r=br(),n=await Li(),s=await $s(n),o=await Pi(r),i=await rn(o,s,t,nn);return{userID:t,type:e,encryptedKeys:i}}catch(e){throw new Error("Failed to create identity keystore",{cause:e})}}async function tf(e){try{if(e.type!=W.IDENTITY)throw new Error("Input is invalid");const t=br(),r=await Pi(t),n=await Hn(r,e.encryptedKeys,e.userID,nn);return await Js(n)}catch(t){throw new Error("Failed to open identity keystore",{cause:t})}}const rf=Object.freeze(Object.defineProperty({__proto__:null,createEncryptionAndRecoveryKeystores:Wh,createIdentityKeystore:ef,generateEncryptionKeys:Ni,generateIdentityKeys:Li,generateRecoveryCodes:Fi,openEncryptionKeystore:Zh,openIdentityKeystore:tf,openRecoveryKeystore:Qh},Symbol.toStringTag,{value:"Module"}));async function nf(e,t){try{const r=Ze.getVariable("baseUrl");return await I.post(r+`${t}`,{encryptedKeystore:e},{withCredentials:!0,headers:{"Content-Type":"application/json"}})}catch(r){throw I.isAxiosError(r)?r.response?.status===401?new Error("Unauthorized: Invalid or expired token"):r.response?.status===403?new Error("Forbidden: Insufficient permissions"):new Error("AxiosError:",r):new Error("Failed to send keystore",{cause:r})}}async function sf(e){try{const t=Ze.getVariable("baseUrl");return(await I.get(t+`${e}`,{withCredentials:!0,headers:{"Content-Type":"application/json"}})).data}catch(t){throw I.isAxiosError(t)?t.response?.status===401?new Error("Unauthorized: Invalid or expired token"):t.response?.status===403?new Error("Forbidden: Insufficient permissions"):t.response?.status===404?new Error("Keystore not found for the specified user"):new Error("AxiosError:",t):new Error("Failed to retrive keystore",{cause:t})}}async function of(e){try{const t=wr(),r=e.type,n=`/uploadKeystore/${t}/${r}`,s=Vs(e);return await nf(s,n)}catch(t){throw new Error("Failed to upload keystore to the server",{cause:t})}}async function cf(){return Er(W.ENCRYPTION)}async function af(){return Er(W.IDENTITY)}async function lf(){return Er(W.RECOVERY)}async function uf(){return Er(W.INDEX)}async function Er(e){try{const t=wr(),r=e.toString(),n=`/downloadKeystore/${t}/${r}`,s=await sf(n);return Gs(s)}catch(t){throw new Error("Failed to retrieve keystore from the server",{cause:t})}}const hf=Object.freeze(Object.defineProperty({__proto__:null,getEncryptionKeystoreFromServer:cf,getIdentityKeystoreFromServer:af,getIndexKeystoreFromServer:uf,getRecoveryKeystoreFromServer:lf,uploadKeystoreToServer:of},Symbol.toStringTag,{value:"Module"}));function ff(e){return localStorage.getItem(e)}function df(e,t){return localStorage.setItem(e,t)}function pf(e){localStorage.removeItem(e)}function yf(e){return!!localStorage.getItem(e)}function mf(){localStorage.clear()}const gf={set:df,get:ff,removeItem:pf,exists:yf,clear:mf},wf=Object.freeze(Object.defineProperty({__proto__:null,default:gf},Symbol.toStringTag,{value:"Module"})),bf=Object.freeze(Object.defineProperty({__proto__:null,localStorageService:wf,sessionStorageService:qh},Symbol.toStringTag,{value:"Module"}));exports.AES_ALGORITHM=Le;exports.AES_KEY_BIT_LENGTH=V;exports.ARGON2ID_ITERATIONS=Ls;exports.ARGON2ID_MEMORY_SIZE=Ds;exports.ARGON2ID_OUTPUT_BYTE_LENGTH=Us;exports.ARGON2ID_PARALLELISM=Ns;exports.ARGON2ID_SALT_BYTE_LENGTH=Ms;exports.AUX_LEN=Ks;exports.CONTEXT_DERIVE=Bs;exports.CONTEXT_ENC_KEYSTORE=Is;exports.CONTEXT_INDEX=js;exports.CONTEXT_LOGIN=Cs;exports.CONTEXT_RATCHET=jr;exports.CONTEXT_RECOVERY=Ps;exports.CONTEXT_WRAPPING=Rs;exports.DB_LABEL=q;exports.DB_VERSION=zs;exports.ECC_ALGORITHM=lt;exports.ENCRYPTION_KEYSTORE_TAG=sn;exports.HASH_BIT_LEN=ut;exports.IDENTITY_KEYSTORE_TAG=nn;exports.INDEX_KEYSTORE_TAG=Hi;exports.IV_LEN_BYTES=Os;exports.KEY_FORMAT=De;exports.KEY_WRAPPING_ALGORITHM=Xt;exports.KYBER1024_PUBLIC_KEY_LENGTH=Ji;exports.KYBER1024_SECRET_KEY_LENGTH=Gi;exports.KYBER512_PUBLIC_KEY_LENGTH=zi;exports.KYBER512_SECRET_KEY_LENGTH=$i;exports.KYBER768_PUBLIC_KEY_LENGTH=Yi;exports.KYBER768_SECRET_KEY_LENGTH=Vi;exports.KYBER_SEED_LENGTH=Xi;exports.KeystoreType=W;exports.MAX_CACHE_SIZE=Hs;exports.MAX_EMAIL_PER_BATCH=Br;exports.PREFIX_IDENTITY_KEY_COMMITMENT=Ui;exports.PREFIX_MEDIA_KEY_COMMITMENT=Fs;exports.PREFIX_PUBLIC_KEY_COMMITMENT=Mi;exports.RECOVERY_KEYSTORE_TAG=on;exports.asymmetric=qi;exports.deriveKey=aa;exports.emailCrypto=Xa;exports.emailSearch=Jl;exports.emailService=$h;exports.hash=Lc;exports.keyWrapper=Fa;exports.keystoreCrypto=rf;exports.keystoreService=hf;exports.pq=Ba;exports.storage=bf;exports.symmetric=ra;exports.utils=Pc;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var blake3_js = require('@noble/hashes/blake3.js');
|
|
4
|
+
var utils_js = require('@noble/hashes/utils.js');
|
|
5
|
+
var bip39 = require('@scure/bip39');
|
|
6
|
+
var english = require('@scure/bip39/wordlists/english');
|
|
7
|
+
var utils_js$1 = require('@noble/post-quantum/utils.js');
|
|
8
|
+
var mlKem_js = require('@noble/post-quantum/ml-kem.js');
|
|
9
|
+
var uuid = require('uuid');
|
|
10
|
+
var idb = require('idb');
|
|
11
|
+
var flexsearch = require('flexsearch');
|
|
12
|
+
var emailjs = require('@emailjs/browser');
|
|
13
|
+
var axios = require('axios');
|
|
14
|
+
|
|
15
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
|
|
17
|
+
function _interopNamespace(e) {
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n.default = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var bip39__namespace = /*#__PURE__*/_interopNamespace(bip39);
|
|
36
|
+
var emailjs__default = /*#__PURE__*/_interopDefault(emailjs);
|
|
37
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
38
|
+
|
|
39
|
+
// src/constants.ts
|
|
40
|
+
var AES_ALGORITHM = "AES-GCM";
|
|
41
|
+
var AES_KEY_BIT_LENGTH = 256;
|
|
42
|
+
var AUX_LEN = 128;
|
|
43
|
+
var IV_LEN_BYTES = 16;
|
|
44
|
+
var KEY_WRAPPING_ALGORITHM = "AES-KW";
|
|
45
|
+
var KEY_FORMAT = "raw";
|
|
46
|
+
var CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
|
|
47
|
+
var ECC_ALGORITHM = "X25519";
|
|
48
|
+
var CONTEXT_LOGIN = "CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore";
|
|
49
|
+
var CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
|
|
50
|
+
var CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
|
|
51
|
+
var CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
|
|
52
|
+
var CONTEXT_DERIVE = "CRYPTO library 2025-08-27 17:08:00 derive one key from two keys";
|
|
53
|
+
var PREFIX_MEDIA_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys";
|
|
54
|
+
var PREFIX_PUBLIC_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys";
|
|
55
|
+
var PREFIX_IDENTITY_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys";
|
|
56
|
+
var ARGON2ID_PARALLELISM = 3;
|
|
57
|
+
var ARGON2ID_ITERATIONS = 4;
|
|
58
|
+
var ARGON2ID_MEMORY_SIZE = 65536;
|
|
59
|
+
var ARGON2ID_SALT_BYTE_LENGTH = 16;
|
|
60
|
+
var ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
|
|
61
|
+
var IDENTITY_KEYSTORE_TAG = "Identity keystore";
|
|
62
|
+
var ENCRYPTION_KEYSTORE_TAG = "Encryption keystore";
|
|
63
|
+
var RECOVERY_KEYSTORE_TAG = "Key recovery keystroe";
|
|
64
|
+
var INDEX_KEYSTORE_TAG = "Current encrypted indices";
|
|
65
|
+
var KYBER512_PUBLIC_KEY_LENGTH = 800;
|
|
66
|
+
var KYBER512_SECRET_KEY_LENGTH = 1632;
|
|
67
|
+
var KYBER768_PUBLIC_KEY_LENGTH = 1184;
|
|
68
|
+
var KYBER768_SECRET_KEY_LENGTH = 2400;
|
|
69
|
+
var KYBER1024_PUBLIC_KEY_LENGTH = 1568;
|
|
70
|
+
var KYBER1024_SECRET_KEY_LENGTH = 3168;
|
|
71
|
+
var KYBER_SEED_LENGTH = 64;
|
|
72
|
+
var HASH_BIT_LEN = 256;
|
|
73
|
+
var MAX_CACHE_SIZE = 6e8;
|
|
74
|
+
var MAX_EMAIL_PER_BATCH = 100;
|
|
75
|
+
var DB_LABEL = "email";
|
|
76
|
+
var DB_VERSION = 1;
|
|
77
|
+
|
|
78
|
+
// src/asymmetric-crypto/ellipticCurve.ts
|
|
79
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
80
|
+
try {
|
|
81
|
+
const result = await crypto.subtle.deriveBits(
|
|
82
|
+
{
|
|
83
|
+
name: ECC_ALGORITHM,
|
|
84
|
+
public: otherUserPublicKey
|
|
85
|
+
},
|
|
86
|
+
ownPrivateKey,
|
|
87
|
+
AES_KEY_BIT_LENGTH
|
|
88
|
+
);
|
|
89
|
+
return new Uint8Array(result);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/asymmetric-crypto/keys.ts
|
|
96
|
+
async function generateEccKeys() {
|
|
97
|
+
try {
|
|
98
|
+
return await crypto.subtle.generateKey(
|
|
99
|
+
{
|
|
100
|
+
name: ECC_ALGORITHM
|
|
101
|
+
},
|
|
102
|
+
true,
|
|
103
|
+
["deriveBits"]
|
|
104
|
+
);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function exportPublicKey(key) {
|
|
110
|
+
try {
|
|
111
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
112
|
+
return new Uint8Array(result);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function importPublicKey(spkiKeyData) {
|
|
118
|
+
try {
|
|
119
|
+
return await crypto.subtle.importKey(
|
|
120
|
+
"spki",
|
|
121
|
+
spkiKeyData,
|
|
122
|
+
{
|
|
123
|
+
name: ECC_ALGORITHM
|
|
124
|
+
},
|
|
125
|
+
true,
|
|
126
|
+
[]
|
|
127
|
+
);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function exportPrivateKey(key) {
|
|
133
|
+
try {
|
|
134
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
135
|
+
return new Uint8Array(result);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
141
|
+
try {
|
|
142
|
+
return await crypto.subtle.importKey(
|
|
143
|
+
"pkcs8",
|
|
144
|
+
pkcs8KeyData,
|
|
145
|
+
{
|
|
146
|
+
name: ECC_ALGORITHM
|
|
147
|
+
},
|
|
148
|
+
true,
|
|
149
|
+
["deriveBits"]
|
|
150
|
+
);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function uint8ArrayToHex(array) {
|
|
156
|
+
return utils_js.bytesToHex(array);
|
|
157
|
+
}
|
|
158
|
+
function UTF8ToUint8(str) {
|
|
159
|
+
return new TextEncoder().encode(str);
|
|
160
|
+
}
|
|
161
|
+
function uint8ToUTF8(array) {
|
|
162
|
+
return new TextDecoder().decode(array);
|
|
163
|
+
}
|
|
164
|
+
function hexToUint8Array(hex) {
|
|
165
|
+
return utils_js.hexToBytes(hex);
|
|
166
|
+
}
|
|
167
|
+
function uint8ArrayToBase64(buffer) {
|
|
168
|
+
const array = Uint16Array.from(buffer);
|
|
169
|
+
const binaryString = new TextDecoder("UTF-16").decode(array);
|
|
170
|
+
return btoa(binaryString);
|
|
171
|
+
}
|
|
172
|
+
function base64ToUint8Array(str) {
|
|
173
|
+
const binaryString = atob(str);
|
|
174
|
+
const len = binaryString.length;
|
|
175
|
+
const array = new Uint8Array(len);
|
|
176
|
+
for (let i = 0; i < len; i++) {
|
|
177
|
+
array[i] = binaryString.charCodeAt(i);
|
|
178
|
+
}
|
|
179
|
+
return new Uint8Array(array.buffer);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/utils/aesConverters.ts
|
|
183
|
+
function ciphertextToBase64(encryptedMessage) {
|
|
184
|
+
try {
|
|
185
|
+
const ivBase64 = uint8ArrayToBase64(encryptedMessage.iv);
|
|
186
|
+
const ciphertextBase64 = uint8ArrayToBase64(encryptedMessage.ciphertext);
|
|
187
|
+
const json = JSON.stringify({ ciphertext: ciphertextBase64, iv: ivBase64 });
|
|
188
|
+
const base64 = btoa(json);
|
|
189
|
+
return base64;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
throw new Error("Failed to convert ciphertext to base64", { cause: error });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function base64ToCiphertext(base64) {
|
|
195
|
+
try {
|
|
196
|
+
const json = atob(base64);
|
|
197
|
+
const obj = JSON.parse(json);
|
|
198
|
+
const iv = base64ToUint8Array(obj.iv);
|
|
199
|
+
const ciphertext = base64ToUint8Array(obj.ciphertext);
|
|
200
|
+
const result = {
|
|
201
|
+
ciphertext,
|
|
202
|
+
iv
|
|
203
|
+
};
|
|
204
|
+
return result;
|
|
205
|
+
} catch (error) {
|
|
206
|
+
throw new Error("Failed to convert base64 to ciphertext", { cause: error });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/utils/keyConverters.ts
|
|
211
|
+
async function identityKeysToBase64(keys) {
|
|
212
|
+
try {
|
|
213
|
+
const pkArray = await exportPublicKey(keys.userPublicKey);
|
|
214
|
+
const skArray = await exportPrivateKey(keys.userPrivateKey);
|
|
215
|
+
const json = JSON.stringify({
|
|
216
|
+
userPublicKey: uint8ArrayToBase64(pkArray),
|
|
217
|
+
userPrivateKey: uint8ArrayToBase64(skArray)
|
|
218
|
+
});
|
|
219
|
+
const base64 = btoa(json);
|
|
220
|
+
return base64;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
throw new Error("Failed to convert identity keys to base64", { cause: error });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function encryptionKeysToBase64(keys) {
|
|
226
|
+
try {
|
|
227
|
+
const pkArray = await exportPublicKey(keys.userPublicKey);
|
|
228
|
+
const skArray = await exportPrivateKey(keys.userPrivateKey);
|
|
229
|
+
const json = JSON.stringify({
|
|
230
|
+
userPublicKey: uint8ArrayToBase64(pkArray),
|
|
231
|
+
userPrivateKey: uint8ArrayToBase64(skArray),
|
|
232
|
+
userPublicKyberKey: uint8ArrayToBase64(keys.userPublicKyberKey),
|
|
233
|
+
userPrivateKyberKey: uint8ArrayToBase64(keys.userPrivateKyberKey)
|
|
234
|
+
});
|
|
235
|
+
const base64 = btoa(json);
|
|
236
|
+
return base64;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
throw new Error("Failed to convert identity keys to base64", { cause: error });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function encryptedKeystoreToBase64(keystore) {
|
|
242
|
+
try {
|
|
243
|
+
const ciphertext = ciphertextToBase64(keystore.encryptedKeys);
|
|
244
|
+
const json = JSON.stringify({
|
|
245
|
+
userID: keystore.userID,
|
|
246
|
+
type: keystore.type.toString(),
|
|
247
|
+
encryptedKeys: ciphertext
|
|
248
|
+
});
|
|
249
|
+
const base64 = btoa(json);
|
|
250
|
+
return base64;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
throw new Error("Failed to convert encrypted keystore to base64", { cause: error });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async function base64ToIdentityKeys(base64) {
|
|
256
|
+
try {
|
|
257
|
+
const json = atob(base64);
|
|
258
|
+
const obj = JSON.parse(json);
|
|
259
|
+
const pkArray = base64ToUint8Array(obj.userPublicKey);
|
|
260
|
+
const skArray = base64ToUint8Array(obj.userPrivateKey);
|
|
261
|
+
const pkCryptoKey = await importPublicKey(pkArray);
|
|
262
|
+
const skCryptoKey = await importPrivateKey(skArray);
|
|
263
|
+
const result = {
|
|
264
|
+
userPublicKey: pkCryptoKey,
|
|
265
|
+
userPrivateKey: skCryptoKey
|
|
266
|
+
};
|
|
267
|
+
return result;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
throw new Error("Failed convert base64 to idenity key", { cause: error });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function base64ToEncryptionKeys(base64) {
|
|
273
|
+
try {
|
|
274
|
+
const json = atob(base64);
|
|
275
|
+
const obj = JSON.parse(json);
|
|
276
|
+
const pkArray = base64ToUint8Array(obj.userPublicKey);
|
|
277
|
+
const skArray = base64ToUint8Array(obj.userPrivateKey);
|
|
278
|
+
const pkCryptoKey = await importPublicKey(pkArray);
|
|
279
|
+
const skCryptoKey = await importPrivateKey(skArray);
|
|
280
|
+
const pkKyber = base64ToUint8Array(obj.userPublicKyberKey);
|
|
281
|
+
const skKyber = base64ToUint8Array(obj.userPrivateKyberKey);
|
|
282
|
+
const result = {
|
|
283
|
+
userPublicKey: pkCryptoKey,
|
|
284
|
+
userPrivateKey: skCryptoKey,
|
|
285
|
+
userPublicKyberKey: pkKyber,
|
|
286
|
+
userPrivateKyberKey: skKyber
|
|
287
|
+
};
|
|
288
|
+
return result;
|
|
289
|
+
} catch (error) {
|
|
290
|
+
throw new Error("Failed to convert base64 to encryption key", { cause: error });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function base64ToEncryptedKeystore(base64) {
|
|
294
|
+
try {
|
|
295
|
+
const json = atob(base64);
|
|
296
|
+
const obj = JSON.parse(json);
|
|
297
|
+
const ciphertext = base64ToCiphertext(obj.encryptedKeys);
|
|
298
|
+
const result = {
|
|
299
|
+
userID: obj.userID,
|
|
300
|
+
type: obj.type,
|
|
301
|
+
encryptedKeys: ciphertext
|
|
302
|
+
};
|
|
303
|
+
return result;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
throw new Error("Failed to convert base64 to encrypted keystore", { cause: error });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function mediaKeysToBase64(keys) {
|
|
309
|
+
try {
|
|
310
|
+
const json = JSON.stringify({
|
|
311
|
+
olmKey: uint8ArrayToBase64(keys.olmKey),
|
|
312
|
+
pqKey: uint8ArrayToBase64(keys.pqKey),
|
|
313
|
+
index: keys.index.toString(),
|
|
314
|
+
userID: keys.userID
|
|
315
|
+
});
|
|
316
|
+
const base64 = btoa(json);
|
|
317
|
+
return base64;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
throw new Error("Failed to convert media keys to base64", { cause: error });
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async function base64ToMediaKeys(base64) {
|
|
323
|
+
try {
|
|
324
|
+
const json = atob(base64);
|
|
325
|
+
const obj = JSON.parse(json);
|
|
326
|
+
const result = {
|
|
327
|
+
olmKey: base64ToUint8Array(obj.olmKey),
|
|
328
|
+
pqKey: base64ToUint8Array(obj.pqKey),
|
|
329
|
+
index: Number(obj.index),
|
|
330
|
+
userID: obj.userID
|
|
331
|
+
};
|
|
332
|
+
return result;
|
|
333
|
+
} catch (error) {
|
|
334
|
+
throw new Error("Failed convert base64 to media keys", { cause: error });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async function base64ToPublicKey(base64) {
|
|
338
|
+
try {
|
|
339
|
+
const json = atob(base64);
|
|
340
|
+
const obj = JSON.parse(json);
|
|
341
|
+
const eccPublicKeyBytes = base64ToUint8Array(obj.eccPublicKey);
|
|
342
|
+
const eccPublicKey = await importPublicKey(eccPublicKeyBytes);
|
|
343
|
+
const kyberPublicKey = base64ToUint8Array(obj.kyberPublicKey);
|
|
344
|
+
return {
|
|
345
|
+
eccPublicKey,
|
|
346
|
+
kyberPublicKey
|
|
347
|
+
};
|
|
348
|
+
} catch (error) {
|
|
349
|
+
throw new Error("Failed to convert base64 to PublicKeys", { cause: error });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
async function publicKeyToBase64(key) {
|
|
353
|
+
try {
|
|
354
|
+
const eccPublicKeyArray = await exportPublicKey(key.eccPublicKey);
|
|
355
|
+
const json = JSON.stringify({
|
|
356
|
+
eccPublicKey: uint8ArrayToBase64(eccPublicKeyArray),
|
|
357
|
+
kyberPublicKey: uint8ArrayToBase64(key.kyberPublicKey)
|
|
358
|
+
});
|
|
359
|
+
const base64 = btoa(json);
|
|
360
|
+
return base64;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
throw new Error("Failed to convert key of the type PublicKeys to base64", { cause: error });
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function genMnemonic(bits) {
|
|
366
|
+
return bip39__namespace.generateMnemonic(english.wordlist, bits);
|
|
367
|
+
}
|
|
368
|
+
function hashData(data) {
|
|
369
|
+
try {
|
|
370
|
+
const hasher = blake3_js.blake3.create();
|
|
371
|
+
for (const d of data) {
|
|
372
|
+
hasher.update(d);
|
|
373
|
+
}
|
|
374
|
+
return hasher.digest();
|
|
375
|
+
} catch (error) {
|
|
376
|
+
throw new Error("Failed to compute hash", { cause: error });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function keyedHash(hashKey, data) {
|
|
380
|
+
try {
|
|
381
|
+
const hasher = blake3_js.blake3.create({ key: hashKey });
|
|
382
|
+
for (const d of data) {
|
|
383
|
+
hasher.update(d);
|
|
384
|
+
}
|
|
385
|
+
return hasher.digest();
|
|
386
|
+
} catch (error) {
|
|
387
|
+
throw new Error("Failed to compute hash", { cause: error });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function getBytesFromData(bytes, data) {
|
|
391
|
+
try {
|
|
392
|
+
const hasher = blake3_js.blake3.create({ dkLen: bytes });
|
|
393
|
+
for (const chunk of data) {
|
|
394
|
+
hasher.update(chunk);
|
|
395
|
+
}
|
|
396
|
+
return hasher.digest();
|
|
397
|
+
} catch (error) {
|
|
398
|
+
throw new Error("Failed to get bytes from data", { cause: error });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function getBytesFromDataHex(bytes, data) {
|
|
402
|
+
try {
|
|
403
|
+
const hash = getBytesFromData(bytes, data);
|
|
404
|
+
return utils_js.bytesToHex(hash);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
throw new Error("Failed to get bytes from data", { cause: error });
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function getBytesFromString(bytes, value) {
|
|
410
|
+
return blake3_js.blake3(utils_js.utf8ToBytes(value), { dkLen: bytes });
|
|
411
|
+
}
|
|
412
|
+
function computeMac(keyMaterial, data) {
|
|
413
|
+
try {
|
|
414
|
+
const key = getBytesFromString(AES_KEY_BIT_LENGTH / 8, keyMaterial);
|
|
415
|
+
const hash = keyedHash(key, data);
|
|
416
|
+
return utils_js.bytesToHex(hash);
|
|
417
|
+
} catch (error) {
|
|
418
|
+
throw new Error("Failed to compute mac", { cause: error });
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/symmetric-crypto/keys.ts
|
|
423
|
+
async function importSymmetricCryptoKey(keyData) {
|
|
424
|
+
return crypto.subtle.importKey(
|
|
425
|
+
KEY_FORMAT,
|
|
426
|
+
new Uint8Array(keyData),
|
|
427
|
+
{
|
|
428
|
+
name: AES_ALGORITHM,
|
|
429
|
+
length: AES_KEY_BIT_LENGTH
|
|
430
|
+
},
|
|
431
|
+
true,
|
|
432
|
+
["encrypt", "decrypt"]
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
async function exportSymmetricCryptoKey(key) {
|
|
436
|
+
try {
|
|
437
|
+
const rawKey = await crypto.subtle.exportKey(KEY_FORMAT, key);
|
|
438
|
+
return new Uint8Array(rawKey);
|
|
439
|
+
} catch (error) {
|
|
440
|
+
throw new Error("Failed to export symmetric CryptoKey", { cause: error });
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async function genSymmetricCryptoKey() {
|
|
444
|
+
return crypto.subtle.generateKey(
|
|
445
|
+
{
|
|
446
|
+
name: AES_ALGORITHM,
|
|
447
|
+
length: AES_KEY_BIT_LENGTH
|
|
448
|
+
},
|
|
449
|
+
true,
|
|
450
|
+
["encrypt", "decrypt"]
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
function genSymmetricKey() {
|
|
454
|
+
try {
|
|
455
|
+
const key = new Uint8Array(AES_KEY_BIT_LENGTH / 8);
|
|
456
|
+
crypto.getRandomValues(key);
|
|
457
|
+
return key;
|
|
458
|
+
} catch (error) {
|
|
459
|
+
throw new Error("Failed to generate symmetric key", { cause: error });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
async function deriveSymmetricCryptoKey(keyMaterial) {
|
|
463
|
+
try {
|
|
464
|
+
const hashBuffer = await getBytesFromString(AES_KEY_BIT_LENGTH / 8, keyMaterial);
|
|
465
|
+
return importSymmetricCryptoKey(hashBuffer);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
throw new Error("Failed to derive CryptoKey from the given key material", { cause: error });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
async function createNISTbasedIV(freeField) {
|
|
471
|
+
try {
|
|
472
|
+
if (!freeField) {
|
|
473
|
+
return utils_js$1.randomBytes(IV_LEN_BYTES);
|
|
474
|
+
}
|
|
475
|
+
const iv = new Uint8Array(16);
|
|
476
|
+
const randFiled = utils_js$1.randomBytes(12);
|
|
477
|
+
iv.set(randFiled, 0);
|
|
478
|
+
const freeFiledFixedLength = await getBytesFromString(4, freeField);
|
|
479
|
+
iv.set(freeFiledFixedLength, 12);
|
|
480
|
+
return iv;
|
|
481
|
+
} catch (error) {
|
|
482
|
+
throw new Error("Failed to create IV", { cause: error });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
async function makeAuxFixedLength(aux) {
|
|
486
|
+
return getBytesFromString(AUX_LEN / 8, aux);
|
|
487
|
+
}
|
|
488
|
+
async function encryptMessage(message, encryptionKey, iv, additionalData) {
|
|
489
|
+
try {
|
|
490
|
+
const encrypted = await crypto.subtle.encrypt(
|
|
491
|
+
{ name: AES_ALGORITHM, iv, additionalData },
|
|
492
|
+
encryptionKey,
|
|
493
|
+
message
|
|
494
|
+
);
|
|
495
|
+
return new Uint8Array(encrypted);
|
|
496
|
+
} catch (error) {
|
|
497
|
+
throw new Error("Failed to encrypt symmetrically", { cause: error });
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async function decryptMessage(ciphertext, iv, encryptionKey, additionalData) {
|
|
501
|
+
try {
|
|
502
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
503
|
+
{ name: AES_ALGORITHM, iv, additionalData },
|
|
504
|
+
encryptionKey,
|
|
505
|
+
ciphertext
|
|
506
|
+
);
|
|
507
|
+
return new Uint8Array(decrypted);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
throw new Error("Failed to decrypt symmetrically", { cause: error });
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/symmetric-crypto/aes.ts
|
|
514
|
+
async function encryptSymmetrically(encryptionKey, message, aux, freeField) {
|
|
515
|
+
try {
|
|
516
|
+
const iv = await createNISTbasedIV(freeField);
|
|
517
|
+
const additionalData = await makeAuxFixedLength(aux);
|
|
518
|
+
const ciphertext = await encryptMessage(message, encryptionKey, iv, additionalData);
|
|
519
|
+
return { ciphertext, iv };
|
|
520
|
+
} catch (error) {
|
|
521
|
+
throw new Error("Failed to encrypt symmetrically", { cause: error });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
async function decryptSymmetrically(encryptionKey, encryptedMessage, aux) {
|
|
525
|
+
try {
|
|
526
|
+
const additionalData = await makeAuxFixedLength(aux);
|
|
527
|
+
const result = await decryptMessage(
|
|
528
|
+
encryptedMessage.ciphertext,
|
|
529
|
+
encryptedMessage.iv,
|
|
530
|
+
encryptionKey,
|
|
531
|
+
additionalData
|
|
532
|
+
);
|
|
533
|
+
return result;
|
|
534
|
+
} catch (error) {
|
|
535
|
+
throw new Error("Failed to decrypt symmetrically", { cause: error });
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/derive-key/deriveKeysFromKey.ts
|
|
540
|
+
function deriveSymmetricKeyFromContext(context, baseKey) {
|
|
541
|
+
return blake3_js.blake3(baseKey, { context: UTF8ToUint8(context) });
|
|
542
|
+
}
|
|
543
|
+
async function deriveSymmetricCryptoKeyFromContext(context, baseKey) {
|
|
544
|
+
try {
|
|
545
|
+
if (baseKey.length != AES_KEY_BIT_LENGTH / 8) {
|
|
546
|
+
throw new Error(`Base key length must be exactly ${AES_KEY_BIT_LENGTH / 8} bytes`);
|
|
547
|
+
}
|
|
548
|
+
if (!context) {
|
|
549
|
+
throw new Error("Context is empry");
|
|
550
|
+
}
|
|
551
|
+
const keyBytes = deriveSymmetricKeyFromContext(context, baseKey);
|
|
552
|
+
const key = await importSymmetricCryptoKey(keyBytes);
|
|
553
|
+
return key;
|
|
554
|
+
} catch (error) {
|
|
555
|
+
throw new Error("Failed to derive CryptoKey from base key and context", { cause: error });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function deriveSymmetricKeyFromTwoKeys(key1, key2) {
|
|
559
|
+
return deriveKeyFromTwoKeysAndContext(key1, key2, CONTEXT_DERIVE);
|
|
560
|
+
}
|
|
561
|
+
async function deriveSymmetricCryptoKeyFromTwoKeys(key1, key2) {
|
|
562
|
+
try {
|
|
563
|
+
const keyBytes = deriveSymmetricKeyFromTwoKeys(key1, key2);
|
|
564
|
+
const key = await importSymmetricCryptoKey(keyBytes);
|
|
565
|
+
return key;
|
|
566
|
+
} catch (error) {
|
|
567
|
+
throw new Error("Failed to derive symmetric CryptoKey from two keys", { cause: error });
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function deriveKeyFromTwoKeysAndContext(key1, key2, context) {
|
|
571
|
+
try {
|
|
572
|
+
if (key2.length != AES_KEY_BIT_LENGTH / 8 || key1.length != AES_KEY_BIT_LENGTH / 8) {
|
|
573
|
+
throw new Error(`Input key length must be exactly ${AES_KEY_BIT_LENGTH / 8} bytes`);
|
|
574
|
+
}
|
|
575
|
+
const key = blake3_js.blake3(key1, { key: key2 });
|
|
576
|
+
return blake3_js.blake3(key, { context: UTF8ToUint8(context) });
|
|
577
|
+
} catch (error) {
|
|
578
|
+
throw new Error("Failed to derive symmetric key from two keys and context", { cause: error });
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// node_modules/hash-wasm/dist/index.esm.js
|
|
583
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
584
|
+
function adopt(value) {
|
|
585
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
586
|
+
resolve(value);
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
590
|
+
function fulfilled(value) {
|
|
591
|
+
try {
|
|
592
|
+
step(generator.next(value));
|
|
593
|
+
} catch (e) {
|
|
594
|
+
reject(e);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function rejected(value) {
|
|
598
|
+
try {
|
|
599
|
+
step(generator["throw"](value));
|
|
600
|
+
} catch (e) {
|
|
601
|
+
reject(e);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function step(result) {
|
|
605
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
606
|
+
}
|
|
607
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
var Mutex = class {
|
|
611
|
+
constructor() {
|
|
612
|
+
this.mutex = Promise.resolve();
|
|
613
|
+
}
|
|
614
|
+
lock() {
|
|
615
|
+
let begin = () => {
|
|
616
|
+
};
|
|
617
|
+
this.mutex = this.mutex.then(() => new Promise(begin));
|
|
618
|
+
return new Promise((res) => {
|
|
619
|
+
begin = res;
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
dispatch(fn) {
|
|
623
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
624
|
+
const unlock = yield this.lock();
|
|
625
|
+
try {
|
|
626
|
+
return yield Promise.resolve(fn());
|
|
627
|
+
} finally {
|
|
628
|
+
unlock();
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
var _a;
|
|
634
|
+
function getGlobal() {
|
|
635
|
+
if (typeof globalThis !== "undefined")
|
|
636
|
+
return globalThis;
|
|
637
|
+
if (typeof self !== "undefined")
|
|
638
|
+
return self;
|
|
639
|
+
if (typeof window !== "undefined")
|
|
640
|
+
return window;
|
|
641
|
+
return global;
|
|
642
|
+
}
|
|
643
|
+
var globalObject = getGlobal();
|
|
644
|
+
var nodeBuffer = (_a = globalObject.Buffer) !== null && _a !== void 0 ? _a : null;
|
|
645
|
+
var textEncoder = globalObject.TextEncoder ? new globalObject.TextEncoder() : null;
|
|
646
|
+
function hexCharCodesToInt(a, b) {
|
|
647
|
+
return (a & 15) + (a >> 6 | a >> 3 & 8) << 4 | (b & 15) + (b >> 6 | b >> 3 & 8);
|
|
648
|
+
}
|
|
649
|
+
function writeHexToUInt8(buf, str) {
|
|
650
|
+
const size = str.length >> 1;
|
|
651
|
+
for (let i = 0; i < size; i++) {
|
|
652
|
+
const index = i << 1;
|
|
653
|
+
buf[i] = hexCharCodesToInt(str.charCodeAt(index), str.charCodeAt(index + 1));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function hexStringEqualsUInt8(str, buf) {
|
|
657
|
+
if (str.length !== buf.length * 2) {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
for (let i = 0; i < buf.length; i++) {
|
|
661
|
+
const strIndex = i << 1;
|
|
662
|
+
if (buf[i] !== hexCharCodesToInt(str.charCodeAt(strIndex), str.charCodeAt(strIndex + 1))) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
var alpha = "a".charCodeAt(0) - 10;
|
|
669
|
+
var digit = "0".charCodeAt(0);
|
|
670
|
+
function getDigestHex(tmpBuffer, input, hashLength) {
|
|
671
|
+
let p = 0;
|
|
672
|
+
for (let i = 0; i < hashLength; i++) {
|
|
673
|
+
let nibble = input[i] >>> 4;
|
|
674
|
+
tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
|
|
675
|
+
nibble = input[i] & 15;
|
|
676
|
+
tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
|
|
677
|
+
}
|
|
678
|
+
return String.fromCharCode.apply(null, tmpBuffer);
|
|
679
|
+
}
|
|
680
|
+
var getUInt8Buffer = nodeBuffer !== null ? (data) => {
|
|
681
|
+
if (typeof data === "string") {
|
|
682
|
+
const buf = nodeBuffer.from(data, "utf8");
|
|
683
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
|
|
684
|
+
}
|
|
685
|
+
if (nodeBuffer.isBuffer(data)) {
|
|
686
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.length);
|
|
687
|
+
}
|
|
688
|
+
if (ArrayBuffer.isView(data)) {
|
|
689
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
690
|
+
}
|
|
691
|
+
throw new Error("Invalid data type!");
|
|
692
|
+
} : (data) => {
|
|
693
|
+
if (typeof data === "string") {
|
|
694
|
+
return textEncoder.encode(data);
|
|
695
|
+
}
|
|
696
|
+
if (ArrayBuffer.isView(data)) {
|
|
697
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
698
|
+
}
|
|
699
|
+
throw new Error("Invalid data type!");
|
|
700
|
+
};
|
|
701
|
+
var base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
702
|
+
var base64Lookup = new Uint8Array(256);
|
|
703
|
+
for (let i = 0; i < base64Chars.length; i++) {
|
|
704
|
+
base64Lookup[base64Chars.charCodeAt(i)] = i;
|
|
705
|
+
}
|
|
706
|
+
function encodeBase64(data, pad = true) {
|
|
707
|
+
const len = data.length;
|
|
708
|
+
const extraBytes = len % 3;
|
|
709
|
+
const parts = [];
|
|
710
|
+
const len2 = len - extraBytes;
|
|
711
|
+
for (let i = 0; i < len2; i += 3) {
|
|
712
|
+
const tmp = (data[i] << 16 & 16711680) + (data[i + 1] << 8 & 65280) + (data[i + 2] & 255);
|
|
713
|
+
const triplet = base64Chars.charAt(tmp >> 18 & 63) + base64Chars.charAt(tmp >> 12 & 63) + base64Chars.charAt(tmp >> 6 & 63) + base64Chars.charAt(tmp & 63);
|
|
714
|
+
parts.push(triplet);
|
|
715
|
+
}
|
|
716
|
+
if (extraBytes === 1) {
|
|
717
|
+
const tmp = data[len - 1];
|
|
718
|
+
const a = base64Chars.charAt(tmp >> 2);
|
|
719
|
+
const b = base64Chars.charAt(tmp << 4 & 63);
|
|
720
|
+
parts.push(`${a}${b}`);
|
|
721
|
+
if (pad) {
|
|
722
|
+
parts.push("==");
|
|
723
|
+
}
|
|
724
|
+
} else if (extraBytes === 2) {
|
|
725
|
+
const tmp = (data[len - 2] << 8) + data[len - 1];
|
|
726
|
+
const a = base64Chars.charAt(tmp >> 10);
|
|
727
|
+
const b = base64Chars.charAt(tmp >> 4 & 63);
|
|
728
|
+
const c = base64Chars.charAt(tmp << 2 & 63);
|
|
729
|
+
parts.push(`${a}${b}${c}`);
|
|
730
|
+
if (pad) {
|
|
731
|
+
parts.push("=");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return parts.join("");
|
|
735
|
+
}
|
|
736
|
+
function getDecodeBase64Length(data) {
|
|
737
|
+
let bufferLength = Math.floor(data.length * 0.75);
|
|
738
|
+
const len = data.length;
|
|
739
|
+
if (data[len - 1] === "=") {
|
|
740
|
+
bufferLength -= 1;
|
|
741
|
+
if (data[len - 2] === "=") {
|
|
742
|
+
bufferLength -= 1;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return bufferLength;
|
|
746
|
+
}
|
|
747
|
+
function decodeBase64(data) {
|
|
748
|
+
const bufferLength = getDecodeBase64Length(data);
|
|
749
|
+
const len = data.length;
|
|
750
|
+
const bytes = new Uint8Array(bufferLength);
|
|
751
|
+
let p = 0;
|
|
752
|
+
for (let i = 0; i < len; i += 4) {
|
|
753
|
+
const encoded1 = base64Lookup[data.charCodeAt(i)];
|
|
754
|
+
const encoded2 = base64Lookup[data.charCodeAt(i + 1)];
|
|
755
|
+
const encoded3 = base64Lookup[data.charCodeAt(i + 2)];
|
|
756
|
+
const encoded4 = base64Lookup[data.charCodeAt(i + 3)];
|
|
757
|
+
bytes[p] = encoded1 << 2 | encoded2 >> 4;
|
|
758
|
+
p += 1;
|
|
759
|
+
bytes[p] = (encoded2 & 15) << 4 | encoded3 >> 2;
|
|
760
|
+
p += 1;
|
|
761
|
+
bytes[p] = (encoded3 & 3) << 6 | encoded4 & 63;
|
|
762
|
+
p += 1;
|
|
763
|
+
}
|
|
764
|
+
return bytes;
|
|
765
|
+
}
|
|
766
|
+
var MAX_HEAP = 16 * 1024;
|
|
767
|
+
var WASM_FUNC_HASH_LENGTH = 4;
|
|
768
|
+
var wasmMutex = new Mutex();
|
|
769
|
+
var wasmModuleCache = /* @__PURE__ */ new Map();
|
|
770
|
+
function WASMInterface(binary, hashLength) {
|
|
771
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
772
|
+
let wasmInstance = null;
|
|
773
|
+
let memoryView = null;
|
|
774
|
+
let initialized = false;
|
|
775
|
+
if (typeof WebAssembly === "undefined") {
|
|
776
|
+
throw new Error("WebAssembly is not supported in this environment!");
|
|
777
|
+
}
|
|
778
|
+
const writeMemory = (data, offset = 0) => {
|
|
779
|
+
memoryView.set(data, offset);
|
|
780
|
+
};
|
|
781
|
+
const getMemory = () => memoryView;
|
|
782
|
+
const getExports = () => wasmInstance.exports;
|
|
783
|
+
const setMemorySize = (totalSize) => {
|
|
784
|
+
wasmInstance.exports.Hash_SetMemorySize(totalSize);
|
|
785
|
+
const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
|
|
786
|
+
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
787
|
+
memoryView = new Uint8Array(memoryBuffer, arrayOffset, totalSize);
|
|
788
|
+
};
|
|
789
|
+
const getStateSize = () => {
|
|
790
|
+
const view = new DataView(wasmInstance.exports.memory.buffer);
|
|
791
|
+
const stateSize = view.getUint32(wasmInstance.exports.STATE_SIZE, true);
|
|
792
|
+
return stateSize;
|
|
793
|
+
};
|
|
794
|
+
const loadWASMPromise = wasmMutex.dispatch(() => __awaiter(this, void 0, void 0, function* () {
|
|
795
|
+
if (!wasmModuleCache.has(binary.name)) {
|
|
796
|
+
const asm = decodeBase64(binary.data);
|
|
797
|
+
const promise = WebAssembly.compile(asm);
|
|
798
|
+
wasmModuleCache.set(binary.name, promise);
|
|
799
|
+
}
|
|
800
|
+
const module = yield wasmModuleCache.get(binary.name);
|
|
801
|
+
wasmInstance = yield WebAssembly.instantiate(module, {
|
|
802
|
+
// env: {
|
|
803
|
+
// emscripten_memcpy_big: (dest, src, num) => {
|
|
804
|
+
// const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
805
|
+
// const memView = new Uint8Array(memoryBuffer, 0);
|
|
806
|
+
// memView.set(memView.subarray(src, src + num), dest);
|
|
807
|
+
// },
|
|
808
|
+
// print_memory: (offset, len) => {
|
|
809
|
+
// const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
810
|
+
// const memView = new Uint8Array(memoryBuffer, 0);
|
|
811
|
+
// console.log('print_int32', memView.subarray(offset, offset + len));
|
|
812
|
+
// },
|
|
813
|
+
// },
|
|
814
|
+
});
|
|
815
|
+
}));
|
|
816
|
+
const setupInterface = () => __awaiter(this, void 0, void 0, function* () {
|
|
817
|
+
if (!wasmInstance) {
|
|
818
|
+
yield loadWASMPromise;
|
|
819
|
+
}
|
|
820
|
+
const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
|
|
821
|
+
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
822
|
+
memoryView = new Uint8Array(memoryBuffer, arrayOffset, MAX_HEAP);
|
|
823
|
+
});
|
|
824
|
+
const init = (bits = null) => {
|
|
825
|
+
initialized = true;
|
|
826
|
+
wasmInstance.exports.Hash_Init(bits);
|
|
827
|
+
};
|
|
828
|
+
const updateUInt8Array = (data) => {
|
|
829
|
+
let read = 0;
|
|
830
|
+
while (read < data.length) {
|
|
831
|
+
const chunk = data.subarray(read, read + MAX_HEAP);
|
|
832
|
+
read += chunk.length;
|
|
833
|
+
memoryView.set(chunk);
|
|
834
|
+
wasmInstance.exports.Hash_Update(chunk.length);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
const update = (data) => {
|
|
838
|
+
if (!initialized) {
|
|
839
|
+
throw new Error("update() called before init()");
|
|
840
|
+
}
|
|
841
|
+
const Uint8Buffer = getUInt8Buffer(data);
|
|
842
|
+
updateUInt8Array(Uint8Buffer);
|
|
843
|
+
};
|
|
844
|
+
const digestChars = new Uint8Array(hashLength * 2);
|
|
845
|
+
const digest = (outputType, padding = null) => {
|
|
846
|
+
if (!initialized) {
|
|
847
|
+
throw new Error("digest() called before init()");
|
|
848
|
+
}
|
|
849
|
+
initialized = false;
|
|
850
|
+
wasmInstance.exports.Hash_Final(padding);
|
|
851
|
+
if (outputType === "binary") {
|
|
852
|
+
return memoryView.slice(0, hashLength);
|
|
853
|
+
}
|
|
854
|
+
return getDigestHex(digestChars, memoryView, hashLength);
|
|
855
|
+
};
|
|
856
|
+
const save = () => {
|
|
857
|
+
if (!initialized) {
|
|
858
|
+
throw new Error("save() can only be called after init() and before digest()");
|
|
859
|
+
}
|
|
860
|
+
const stateOffset = wasmInstance.exports.Hash_GetState();
|
|
861
|
+
const stateLength = getStateSize();
|
|
862
|
+
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
863
|
+
const internalState = new Uint8Array(memoryBuffer, stateOffset, stateLength);
|
|
864
|
+
const prefixedState = new Uint8Array(WASM_FUNC_HASH_LENGTH + stateLength);
|
|
865
|
+
writeHexToUInt8(prefixedState, binary.hash);
|
|
866
|
+
prefixedState.set(internalState, WASM_FUNC_HASH_LENGTH);
|
|
867
|
+
return prefixedState;
|
|
868
|
+
};
|
|
869
|
+
const load = (state) => {
|
|
870
|
+
if (!(state instanceof Uint8Array)) {
|
|
871
|
+
throw new Error("load() expects an Uint8Array generated by save()");
|
|
872
|
+
}
|
|
873
|
+
const stateOffset = wasmInstance.exports.Hash_GetState();
|
|
874
|
+
const stateLength = getStateSize();
|
|
875
|
+
const overallLength = WASM_FUNC_HASH_LENGTH + stateLength;
|
|
876
|
+
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
877
|
+
if (state.length !== overallLength) {
|
|
878
|
+
throw new Error(`Bad state length (expected ${overallLength} bytes, got ${state.length})`);
|
|
879
|
+
}
|
|
880
|
+
if (!hexStringEqualsUInt8(binary.hash, state.subarray(0, WASM_FUNC_HASH_LENGTH))) {
|
|
881
|
+
throw new Error("This state was written by an incompatible hash implementation");
|
|
882
|
+
}
|
|
883
|
+
const internalState = state.subarray(WASM_FUNC_HASH_LENGTH);
|
|
884
|
+
new Uint8Array(memoryBuffer, stateOffset, stateLength).set(internalState);
|
|
885
|
+
initialized = true;
|
|
886
|
+
};
|
|
887
|
+
const isDataShort = (data) => {
|
|
888
|
+
if (typeof data === "string") {
|
|
889
|
+
return data.length < MAX_HEAP / 4;
|
|
890
|
+
}
|
|
891
|
+
return data.byteLength < MAX_HEAP;
|
|
892
|
+
};
|
|
893
|
+
let canSimplify = isDataShort;
|
|
894
|
+
switch (binary.name) {
|
|
895
|
+
case "argon2":
|
|
896
|
+
case "scrypt":
|
|
897
|
+
canSimplify = () => true;
|
|
898
|
+
break;
|
|
899
|
+
case "blake2b":
|
|
900
|
+
case "blake2s":
|
|
901
|
+
canSimplify = (data, initParam) => initParam <= 512 && isDataShort(data);
|
|
902
|
+
break;
|
|
903
|
+
case "blake3":
|
|
904
|
+
canSimplify = (data, initParam) => initParam === 0 && isDataShort(data);
|
|
905
|
+
break;
|
|
906
|
+
case "xxhash64":
|
|
907
|
+
// cannot simplify
|
|
908
|
+
case "xxhash3":
|
|
909
|
+
case "xxhash128":
|
|
910
|
+
case "crc64":
|
|
911
|
+
canSimplify = () => false;
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
const calculate = (data, initParam = null, digestParam = null) => {
|
|
915
|
+
if (!canSimplify(data, initParam)) {
|
|
916
|
+
init(initParam);
|
|
917
|
+
update(data);
|
|
918
|
+
return digest("hex", digestParam);
|
|
919
|
+
}
|
|
920
|
+
const buffer = getUInt8Buffer(data);
|
|
921
|
+
memoryView.set(buffer);
|
|
922
|
+
wasmInstance.exports.Hash_Calculate(buffer.length, initParam, digestParam);
|
|
923
|
+
return getDigestHex(digestChars, memoryView, hashLength);
|
|
924
|
+
};
|
|
925
|
+
yield setupInterface();
|
|
926
|
+
return {
|
|
927
|
+
getMemory,
|
|
928
|
+
writeMemory,
|
|
929
|
+
getExports,
|
|
930
|
+
setMemorySize,
|
|
931
|
+
init,
|
|
932
|
+
update,
|
|
933
|
+
digest,
|
|
934
|
+
save,
|
|
935
|
+
load,
|
|
936
|
+
calculate,
|
|
937
|
+
hashLength
|
|
938
|
+
};
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
new Mutex();
|
|
942
|
+
var name$k = "argon2";
|
|
943
|
+
var data$k = "AGFzbQEAAAABKQVgAX8Bf2AAAX9gEH9/f39/f39/f39/f39/f38AYAR/f39/AGACf38AAwYFAAECAwQFBgEBAoCAAgYIAX8BQZCoBAsHQQQGbWVtb3J5AgASSGFzaF9TZXRNZW1vcnlTaXplAAAOSGFzaF9HZXRCdWZmZXIAAQ5IYXNoX0NhbGN1bGF0ZQAECvEyBVgBAn9BACEBAkAgAEEAKAKICCICRg0AAkAgACACayIAQRB2IABBgIB8cSAASWoiAEAAQX9HDQBB/wHADwtBACEBQQBBACkDiAggAEEQdK18NwOICAsgAcALcAECfwJAQQAoAoAIIgANAEEAPwBBEHQiADYCgAhBACgCiAgiAUGAgCBGDQACQEGAgCAgAWsiAEEQdiAAQYCAfHEgAElqIgBAAEF/Rw0AQQAPC0EAQQApA4gIIABBEHStfDcDiAhBACgCgAghAAsgAAvcDgECfiAAIAQpAwAiECAAKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAMIBAgDCkDAIVCIIkiEDcDACAIIBAgCCkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgBCAQIAQpAwCFQiiJIhA3AwAgACAQIAApAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIAwgECAMKQMAhUIwiSIQNwMAIAggECAIKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAEIBAgBCkDAIVCAYk3AwAgASAFKQMAIhAgASkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgDSAQIA0pAwCFQiCJIhA3AwAgCSAQIAkpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAUgECAFKQMAhUIoiSIQNwMAIAEgECABKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACANIBAgDSkDAIVCMIkiEDcDACAJIBAgCSkDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgBSAQIAUpAwCFQgGJNwMAIAIgBikDACIQIAIpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIA4gECAOKQMAhUIgiSIQNwMAIAogECAKKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAGIBAgBikDAIVCKIkiEDcDACACIBAgAikDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgDiAQIA4pAwCFQjCJIhA3AwAgCiAQIAopAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIAYgECAGKQMAhUIBiTcDACADIAcpAwAiECADKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAPIBAgDykDAIVCIIkiEDcDACALIBAgCykDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgByAQIAcpAwCFQiiJIhA3AwAgAyAQIAMpAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIA8gECAPKQMAhUIwiSIQNwMAIAsgECALKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAHIBAgBykDAIVCAYk3AwAgACAFKQMAIhAgACkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgDyAQIA8pAwCFQiCJIhA3AwAgCiAQIAopAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAUgECAFKQMAhUIoiSIQNwMAIAAgECAAKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAPIBAgDykDAIVCMIkiEDcDACAKIBAgCikDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgBSAQIAUpAwCFQgGJNwMAIAEgBikDACIQIAEpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAwgECAMKQMAhUIgiSIQNwMAIAsgECALKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACAGIBAgBikDAIVCKIkiEDcDACABIBAgASkDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgDCAQIAwpAwCFQjCJIhA3AwAgCyAQIAspAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIAYgECAGKQMAhUIBiTcDACACIAcpAwAiECACKQMAIhF8IBFCAYZC/v///x+DIBBC/////w+DfnwiEDcDACANIBAgDSkDAIVCIIkiEDcDACAIIBAgCCkDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgByAQIAcpAwCFQiiJIhA3AwAgAiAQIAIpAwAiEXwgEEL/////D4MgEUIBhkL+////H4N+fCIQNwMAIA0gECANKQMAhUIwiSIQNwMAIAggECAIKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAHIBAgBykDAIVCAYk3AwAgAyAEKQMAIhAgAykDACIRfCARQgGGQv7///8fgyAQQv////8Pg358IhA3AwAgDiAQIA4pAwCFQiCJIhA3AwAgCSAQIAkpAwAiEXwgEUIBhkL+////H4MgEEL/////D4N+fCIQNwMAIAQgECAEKQMAhUIoiSIQNwMAIAMgECADKQMAIhF8IBBC/////w+DIBFCAYZC/v///x+DfnwiEDcDACAOIBAgDikDAIVCMIkiEDcDACAJIBAgCSkDACIRfCAQQv////8PgyARQgGGQv7///8fg358IhA3AwAgBCAQIAQpAwCFQgGJNwMAC98aAQN/QQAhBEEAIAIpAwAgASkDAIU3A5AIQQAgAikDCCABKQMIhTcDmAhBACACKQMQIAEpAxCFNwOgCEEAIAIpAxggASkDGIU3A6gIQQAgAikDICABKQMghTcDsAhBACACKQMoIAEpAyiFNwO4CEEAIAIpAzAgASkDMIU3A8AIQQAgAikDOCABKQM4hTcDyAhBACACKQNAIAEpA0CFNwPQCEEAIAIpA0ggASkDSIU3A9gIQQAgAikDUCABKQNQhTcD4AhBACACKQNYIAEpA1iFNwPoCEEAIAIpA2AgASkDYIU3A/AIQQAgAikDaCABKQNohTcD+AhBACACKQNwIAEpA3CFNwOACUEAIAIpA3ggASkDeIU3A4gJQQAgAikDgAEgASkDgAGFNwOQCUEAIAIpA4gBIAEpA4gBhTcDmAlBACACKQOQASABKQOQAYU3A6AJQQAgAikDmAEgASkDmAGFNwOoCUEAIAIpA6ABIAEpA6ABhTcDsAlBACACKQOoASABKQOoAYU3A7gJQQAgAikDsAEgASkDsAGFNwPACUEAIAIpA7gBIAEpA7gBhTcDyAlBACACKQPAASABKQPAAYU3A9AJQQAgAikDyAEgASkDyAGFNwPYCUEAIAIpA9ABIAEpA9ABhTcD4AlBACACKQPYASABKQPYAYU3A+gJQQAgAikD4AEgASkD4AGFNwPwCUEAIAIpA+gBIAEpA+gBhTcD+AlBACACKQPwASABKQPwAYU3A4AKQQAgAikD+AEgASkD+AGFNwOICkEAIAIpA4ACIAEpA4AChTcDkApBACACKQOIAiABKQOIAoU3A5gKQQAgAikDkAIgASkDkAKFNwOgCkEAIAIpA5gCIAEpA5gChTcDqApBACACKQOgAiABKQOgAoU3A7AKQQAgAikDqAIgASkDqAKFNwO4CkEAIAIpA7ACIAEpA7AChTcDwApBACACKQO4AiABKQO4AoU3A8gKQQAgAikDwAIgASkDwAKFNwPQCkEAIAIpA8gCIAEpA8gChTcD2ApBACACKQPQAiABKQPQAoU3A+AKQQAgAikD2AIgASkD2AKFNwPoCkEAIAIpA+ACIAEpA+AChTcD8ApBACACKQPoAiABKQPoAoU3A/gKQQAgAikD8AIgASkD8AKFNwOAC0EAIAIpA/gCIAEpA/gChTcDiAtBACACKQOAAyABKQOAA4U3A5ALQQAgAikDiAMgASkDiAOFNwOYC0EAIAIpA5ADIAEpA5ADhTcDoAtBACACKQOYAyABKQOYA4U3A6gLQQAgAikDoAMgASkDoAOFNwOwC0EAIAIpA6gDIAEpA6gDhTcDuAtBACACKQOwAyABKQOwA4U3A8ALQQAgAikDuAMgASkDuAOFNwPIC0EAIAIpA8ADIAEpA8ADhTcD0AtBACACKQPIAyABKQPIA4U3A9gLQQAgAikD0AMgASkD0AOFNwPgC0EAIAIpA9gDIAEpA9gDhTcD6AtBACACKQPgAyABKQPgA4U3A/ALQQAgAikD6AMgASkD6AOFNwP4C0EAIAIpA/ADIAEpA/ADhTcDgAxBACACKQP4AyABKQP4A4U3A4gMQQAgAikDgAQgASkDgASFNwOQDEEAIAIpA4gEIAEpA4gEhTcDmAxBACACKQOQBCABKQOQBIU3A6AMQQAgAikDmAQgASkDmASFNwOoDEEAIAIpA6AEIAEpA6AEhTcDsAxBACACKQOoBCABKQOoBIU3A7gMQQAgAikDsAQgASkDsASFNwPADEEAIAIpA7gEIAEpA7gEhTcDyAxBACACKQPABCABKQPABIU3A9AMQQAgAikDyAQgASkDyASFNwPYDEEAIAIpA9AEIAEpA9AEhTcD4AxBACACKQPYBCABKQPYBIU3A+gMQQAgAikD4AQgASkD4ASFNwPwDEEAIAIpA+gEIAEpA+gEhTcD+AxBACACKQPwBCABKQPwBIU3A4ANQQAgAikD+AQgASkD+ASFNwOIDUEAIAIpA4AFIAEpA4AFhTcDkA1BACACKQOIBSABKQOIBYU3A5gNQQAgAikDkAUgASkDkAWFNwOgDUEAIAIpA5gFIAEpA5gFhTcDqA1BACACKQOgBSABKQOgBYU3A7ANQQAgAikDqAUgASkDqAWFNwO4DUEAIAIpA7AFIAEpA7AFhTcDwA1BACACKQO4BSABKQO4BYU3A8gNQQAgAikDwAUgASkDwAWFNwPQDUEAIAIpA8gFIAEpA8gFhTcD2A1BACACKQPQBSABKQPQBYU3A+ANQQAgAikD2AUgASkD2AWFNwPoDUEAIAIpA+AFIAEpA+AFhTcD8A1BACACKQPoBSABKQPoBYU3A/gNQQAgAikD8AUgASkD8AWFNwOADkEAIAIpA/gFIAEpA/gFhTcDiA5BACACKQOABiABKQOABoU3A5AOQQAgAikDiAYgASkDiAaFNwOYDkEAIAIpA5AGIAEpA5AGhTcDoA5BACACKQOYBiABKQOYBoU3A6gOQQAgAikDoAYgASkDoAaFNwOwDkEAIAIpA6gGIAEpA6gGhTcDuA5BACACKQOwBiABKQOwBoU3A8AOQQAgAikDuAYgASkDuAaFNwPIDkEAIAIpA8AGIAEpA8AGhTcD0A5BACACKQPIBiABKQPIBoU3A9gOQQAgAikD0AYgASkD0AaFNwPgDkEAIAIpA9gGIAEpA9gGhTcD6A5BACACKQPgBiABKQPgBoU3A/AOQQAgAikD6AYgASkD6AaFNwP4DkEAIAIpA/AGIAEpA/AGhTcDgA9BACACKQP4BiABKQP4BoU3A4gPQQAgAikDgAcgASkDgAeFNwOQD0EAIAIpA4gHIAEpA4gHhTcDmA9BACACKQOQByABKQOQB4U3A6APQQAgAikDmAcgASkDmAeFNwOoD0EAIAIpA6AHIAEpA6AHhTcDsA9BACACKQOoByABKQOoB4U3A7gPQQAgAikDsAcgASkDsAeFNwPAD0EAIAIpA7gHIAEpA7gHhTcDyA9BACACKQPAByABKQPAB4U3A9APQQAgAikDyAcgASkDyAeFNwPYD0EAIAIpA9AHIAEpA9AHhTcD4A9BACACKQPYByABKQPYB4U3A+gPQQAgAikD4AcgASkD4AeFNwPwD0EAIAIpA+gHIAEpA+gHhTcD+A9BACACKQPwByABKQPwB4U3A4AQQQAgAikD+AcgASkD+AeFNwOIEEGQCEGYCEGgCEGoCEGwCEG4CEHACEHICEHQCEHYCEHgCEHoCEHwCEH4CEGACUGICRACQZAJQZgJQaAJQagJQbAJQbgJQcAJQcgJQdAJQdgJQeAJQegJQfAJQfgJQYAKQYgKEAJBkApBmApBoApBqApBsApBuApBwApByApB0ApB2ApB4ApB6ApB8ApB+ApBgAtBiAsQAkGQC0GYC0GgC0GoC0GwC0G4C0HAC0HIC0HQC0HYC0HgC0HoC0HwC0H4C0GADEGIDBACQZAMQZgMQaAMQagMQbAMQbgMQcAMQcgMQdAMQdgMQeAMQegMQfAMQfgMQYANQYgNEAJBkA1BmA1BoA1BqA1BsA1BuA1BwA1ByA1B0A1B2A1B4A1B6A1B8A1B+A1BgA5BiA4QAkGQDkGYDkGgDkGoDkGwDkG4DkHADkHIDkHQDkHYDkHgDkHoDkHwDkH4DkGAD0GIDxACQZAPQZgPQaAPQagPQbAPQbgPQcAPQcgPQdAPQdgPQeAPQegPQfAPQfgPQYAQQYgQEAJBkAhBmAhBkAlBmAlBkApBmApBkAtBmAtBkAxBmAxBkA1BmA1BkA5BmA5BkA9BmA8QAkGgCEGoCEGgCUGoCUGgCkGoCkGgC0GoC0GgDEGoDEGgDUGoDUGgDkGoDkGgD0GoDxACQbAIQbgIQbAJQbgJQbAKQbgKQbALQbgLQbAMQbgMQbANQbgNQbAOQbgOQbAPQbgPEAJBwAhByAhBwAlByAlBwApByApBwAtByAtBwAxByAxBwA1ByA1BwA5ByA5BwA9ByA8QAkHQCEHYCEHQCUHYCUHQCkHYCkHQC0HYC0HQDEHYDEHQDUHYDUHQDkHYDkHQD0HYDxACQeAIQegIQeAJQegJQeAKQegKQeALQegLQeAMQegMQeANQegNQeAOQegOQeAPQegPEAJB8AhB+AhB8AlB+AlB8ApB+ApB8AtB+AtB8AxB+AxB8A1B+A1B8A5B+A5B8A9B+A8QAkGACUGICUGACkGICkGAC0GIC0GADEGIDEGADUGIDUGADkGIDkGAD0GID0GAEEGIEBACAkACQCADRQ0AA0AgACAEaiIDIAIgBGoiBSkDACABIARqIgYpAwCFIARBkAhqKQMAhSADKQMAhTcDACADQQhqIgMgBUEIaikDACAGQQhqKQMAhSAEQZgIaikDAIUgAykDAIU3AwAgBEEQaiIEQYAIRw0ADAILC0EAIQQDQCAAIARqIgMgAiAEaiIFKQMAIAEgBGoiBikDAIUgBEGQCGopAwCFNwMAIANBCGogBUEIaikDACAGQQhqKQMAhSAEQZgIaikDAIU3AwAgBEEQaiIEQYAIRw0ACwsL5QcMBX8BfgR/An4BfwF+AX8Bfgd/AX4DfwF+AkBBACgCgAgiAiABQQp0aiIDKAIIIAFHDQAgAygCDCEEIAMoAgAhBUEAIAMoAhQiBq03A7gQQQAgBK0iBzcDsBBBACAFIAEgBUECdG4iCGwiCUECdK03A6gQAkACQAJAAkAgBEUNAEF/IQogBUUNASAIQQNsIQsgCEECdCIErSEMIAWtIQ0gBkF/akECSSEOQgAhDwNAQQAgDzcDkBAgD6chEEIAIRFBACEBA0BBACARNwOgECAPIBGEUCIDIA5xIRIgBkEBRiAPUCITIAZBAkYgEUICVHFxciEUQX8gAUEBakEDcSAIbEF/aiATGyEVIAEgEHIhFiABIAhsIRcgA0EBdCEYQgAhGQNAQQBCADcDwBBBACAZNwOYECAYIQECQCASRQ0AQQBCATcDwBBBkBhBkBBBkCBBABADQZAYQZAYQZAgQQAQA0ECIQELAkAgASAITw0AIAQgGaciGmwgF2ogAWohAwNAIANBACAEIAEbQQAgEVAiGxtqQX9qIRwCQAJAIBQNAEEAKAKACCICIBxBCnQiHGohCgwBCwJAIAFB/wBxIgINAEEAQQApA8AQQgF8NwPAEEGQGEGQEEGQIEEAEANBkBhBkBhBkCBBABADCyAcQQp0IRwgAkEDdEGQGGohCkEAKAKACCECCyACIANBCnRqIAIgHGogAiAKKQMAIh1CIIinIAVwIBogFhsiHCAEbCABIAFBACAZIBytUSIcGyIKIBsbIBdqIAogC2ogExsgAUUgHHJrIhsgFWqtIB1C/////w+DIh0gHX5CIIggG61+QiCIfSAMgqdqQQp0akEBEAMgA0EBaiEDIAggAUEBaiIBRw0ACwsgGUIBfCIZIA1SDQALIBFCAXwiEachASARQgRSDQALIA9CAXwiDyAHUg0AC0EAKAKACCECCyAJQQx0QYB4aiEXIAVBf2oiCkUNAgwBC0EAQgM3A6AQQQAgBEF/aq03A5AQQYB4IRcLIAIgF2ohGyAIQQx0IQhBACEcA0AgCCAcQQFqIhxsQYB4aiEEQQAhAQNAIBsgAWoiAyADKQMAIAIgBCABamopAwCFNwMAIANBCGoiAyADKQMAIAIgBCABQQhyamopAwCFNwMAIAFBCGohAyABQRBqIQEgA0H4B0kNAAsgHCAKRw0ACwsgAiAXaiEbQXghAQNAIAIgAWoiA0EIaiAbIAFqIgRBCGopAwA3AwAgA0EQaiAEQRBqKQMANwMAIANBGGogBEEYaikDADcDACADQSBqIARBIGopAwA3AwAgAUEgaiIBQfgHSQ0ACwsL";
|
|
944
|
+
var hash$k = "e4cdc523";
|
|
945
|
+
var wasmJson$k = {
|
|
946
|
+
name: name$k,
|
|
947
|
+
data: data$k,
|
|
948
|
+
hash: hash$k
|
|
949
|
+
};
|
|
950
|
+
var name$j = "blake2b";
|
|
951
|
+
var data$j = "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";
|
|
952
|
+
var hash$j = "c6f286e6";
|
|
953
|
+
var wasmJson$j = {
|
|
954
|
+
name: name$j,
|
|
955
|
+
data: data$j,
|
|
956
|
+
hash: hash$j
|
|
957
|
+
};
|
|
958
|
+
new Mutex();
|
|
959
|
+
function validateBits$4(bits) {
|
|
960
|
+
if (!Number.isInteger(bits) || bits < 8 || bits > 512 || bits % 8 !== 0) {
|
|
961
|
+
return new Error("Invalid variant! Valid values: 8, 16, ..., 512");
|
|
962
|
+
}
|
|
963
|
+
return null;
|
|
964
|
+
}
|
|
965
|
+
function getInitParam$1(outputBits, keyBits) {
|
|
966
|
+
return outputBits | keyBits << 16;
|
|
967
|
+
}
|
|
968
|
+
function createBLAKE2b(bits = 512, key = null) {
|
|
969
|
+
if (validateBits$4(bits)) {
|
|
970
|
+
return Promise.reject(validateBits$4(bits));
|
|
971
|
+
}
|
|
972
|
+
let keyBuffer = null;
|
|
973
|
+
let initParam = bits;
|
|
974
|
+
if (key !== null) {
|
|
975
|
+
keyBuffer = getUInt8Buffer(key);
|
|
976
|
+
if (keyBuffer.length > 64) {
|
|
977
|
+
return Promise.reject(new Error("Max key length is 64 bytes"));
|
|
978
|
+
}
|
|
979
|
+
initParam = getInitParam$1(bits, keyBuffer.length);
|
|
980
|
+
}
|
|
981
|
+
const outputSize = bits / 8;
|
|
982
|
+
return WASMInterface(wasmJson$j, outputSize).then((wasm) => {
|
|
983
|
+
if (initParam > 512) {
|
|
984
|
+
wasm.writeMemory(keyBuffer);
|
|
985
|
+
}
|
|
986
|
+
wasm.init(initParam);
|
|
987
|
+
const obj = {
|
|
988
|
+
init: initParam > 512 ? () => {
|
|
989
|
+
wasm.writeMemory(keyBuffer);
|
|
990
|
+
wasm.init(initParam);
|
|
991
|
+
return obj;
|
|
992
|
+
} : () => {
|
|
993
|
+
wasm.init(initParam);
|
|
994
|
+
return obj;
|
|
995
|
+
},
|
|
996
|
+
update: (data) => {
|
|
997
|
+
wasm.update(data);
|
|
998
|
+
return obj;
|
|
999
|
+
},
|
|
1000
|
+
// biome-ignore lint/suspicious/noExplicitAny: Conflict with IHasher type
|
|
1001
|
+
digest: (outputType) => wasm.digest(outputType),
|
|
1002
|
+
save: () => wasm.save(),
|
|
1003
|
+
load: (data) => {
|
|
1004
|
+
wasm.load(data);
|
|
1005
|
+
return obj;
|
|
1006
|
+
},
|
|
1007
|
+
blockSize: 128,
|
|
1008
|
+
digestSize: outputSize
|
|
1009
|
+
};
|
|
1010
|
+
return obj;
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
function encodeResult(salt, options, res) {
|
|
1014
|
+
const parameters = [
|
|
1015
|
+
`m=${options.memorySize}`,
|
|
1016
|
+
`t=${options.iterations}`,
|
|
1017
|
+
`p=${options.parallelism}`
|
|
1018
|
+
].join(",");
|
|
1019
|
+
return `$argon2${options.hashType}$v=19$${parameters}$${encodeBase64(salt, false)}$${encodeBase64(res, false)}`;
|
|
1020
|
+
}
|
|
1021
|
+
var uint32View = new DataView(new ArrayBuffer(4));
|
|
1022
|
+
function int32LE(x) {
|
|
1023
|
+
uint32View.setInt32(0, x, true);
|
|
1024
|
+
return new Uint8Array(uint32View.buffer);
|
|
1025
|
+
}
|
|
1026
|
+
function hashFunc(blake512, buf, len) {
|
|
1027
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1028
|
+
if (len <= 64) {
|
|
1029
|
+
const blake = yield createBLAKE2b(len * 8);
|
|
1030
|
+
blake.update(int32LE(len));
|
|
1031
|
+
blake.update(buf);
|
|
1032
|
+
return blake.digest("binary");
|
|
1033
|
+
}
|
|
1034
|
+
const r = Math.ceil(len / 32) - 2;
|
|
1035
|
+
const ret = new Uint8Array(len);
|
|
1036
|
+
blake512.init();
|
|
1037
|
+
blake512.update(int32LE(len));
|
|
1038
|
+
blake512.update(buf);
|
|
1039
|
+
let vp = blake512.digest("binary");
|
|
1040
|
+
ret.set(vp.subarray(0, 32), 0);
|
|
1041
|
+
for (let i = 1; i < r; i++) {
|
|
1042
|
+
blake512.init();
|
|
1043
|
+
blake512.update(vp);
|
|
1044
|
+
vp = blake512.digest("binary");
|
|
1045
|
+
ret.set(vp.subarray(0, 32), i * 32);
|
|
1046
|
+
}
|
|
1047
|
+
const partialBytesNeeded = len - 32 * r;
|
|
1048
|
+
let blakeSmall;
|
|
1049
|
+
if (partialBytesNeeded === 64) {
|
|
1050
|
+
blakeSmall = blake512;
|
|
1051
|
+
blakeSmall.init();
|
|
1052
|
+
} else {
|
|
1053
|
+
blakeSmall = yield createBLAKE2b(partialBytesNeeded * 8);
|
|
1054
|
+
}
|
|
1055
|
+
blakeSmall.update(vp);
|
|
1056
|
+
vp = blakeSmall.digest("binary");
|
|
1057
|
+
ret.set(vp.subarray(0, partialBytesNeeded), r * 32);
|
|
1058
|
+
return ret;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function getHashType(type) {
|
|
1062
|
+
switch (type) {
|
|
1063
|
+
case "d":
|
|
1064
|
+
return 0;
|
|
1065
|
+
case "i":
|
|
1066
|
+
return 1;
|
|
1067
|
+
default:
|
|
1068
|
+
return 2;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
function argon2Internal(options) {
|
|
1072
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1073
|
+
var _a2;
|
|
1074
|
+
const { parallelism, iterations, hashLength } = options;
|
|
1075
|
+
const password = getUInt8Buffer(options.password);
|
|
1076
|
+
const salt = getUInt8Buffer(options.salt);
|
|
1077
|
+
const version = 19;
|
|
1078
|
+
const hashType = getHashType(options.hashType);
|
|
1079
|
+
const { memorySize } = options;
|
|
1080
|
+
const secret = getUInt8Buffer((_a2 = options.secret) !== null && _a2 !== void 0 ? _a2 : "");
|
|
1081
|
+
const [argon2Interface, blake512] = yield Promise.all([
|
|
1082
|
+
WASMInterface(wasmJson$k, 1024),
|
|
1083
|
+
createBLAKE2b(512)
|
|
1084
|
+
]);
|
|
1085
|
+
argon2Interface.setMemorySize(memorySize * 1024 + 1024);
|
|
1086
|
+
const initVector = new Uint8Array(24);
|
|
1087
|
+
const initVectorView = new DataView(initVector.buffer);
|
|
1088
|
+
initVectorView.setInt32(0, parallelism, true);
|
|
1089
|
+
initVectorView.setInt32(4, hashLength, true);
|
|
1090
|
+
initVectorView.setInt32(8, memorySize, true);
|
|
1091
|
+
initVectorView.setInt32(12, iterations, true);
|
|
1092
|
+
initVectorView.setInt32(16, version, true);
|
|
1093
|
+
initVectorView.setInt32(20, hashType, true);
|
|
1094
|
+
argon2Interface.writeMemory(initVector, memorySize * 1024);
|
|
1095
|
+
blake512.init();
|
|
1096
|
+
blake512.update(initVector);
|
|
1097
|
+
blake512.update(int32LE(password.length));
|
|
1098
|
+
blake512.update(password);
|
|
1099
|
+
blake512.update(int32LE(salt.length));
|
|
1100
|
+
blake512.update(salt);
|
|
1101
|
+
blake512.update(int32LE(secret.length));
|
|
1102
|
+
blake512.update(secret);
|
|
1103
|
+
blake512.update(int32LE(0));
|
|
1104
|
+
const segments = Math.floor(memorySize / (parallelism * 4));
|
|
1105
|
+
const lanes = segments * 4;
|
|
1106
|
+
const param = new Uint8Array(72);
|
|
1107
|
+
const H0 = blake512.digest("binary");
|
|
1108
|
+
param.set(H0);
|
|
1109
|
+
for (let lane = 0; lane < parallelism; lane++) {
|
|
1110
|
+
param.set(int32LE(0), 64);
|
|
1111
|
+
param.set(int32LE(lane), 68);
|
|
1112
|
+
let position = lane * lanes;
|
|
1113
|
+
let chunk = yield hashFunc(blake512, param, 1024);
|
|
1114
|
+
argon2Interface.writeMemory(chunk, position * 1024);
|
|
1115
|
+
position += 1;
|
|
1116
|
+
param.set(int32LE(1), 64);
|
|
1117
|
+
chunk = yield hashFunc(blake512, param, 1024);
|
|
1118
|
+
argon2Interface.writeMemory(chunk, position * 1024);
|
|
1119
|
+
}
|
|
1120
|
+
const C = new Uint8Array(1024);
|
|
1121
|
+
writeHexToUInt8(C, argon2Interface.calculate(new Uint8Array([]), memorySize));
|
|
1122
|
+
const res = yield hashFunc(blake512, C, hashLength);
|
|
1123
|
+
if (options.outputType === "hex") {
|
|
1124
|
+
const digestChars = new Uint8Array(hashLength * 2);
|
|
1125
|
+
return getDigestHex(digestChars, res, hashLength);
|
|
1126
|
+
}
|
|
1127
|
+
if (options.outputType === "encoded") {
|
|
1128
|
+
return encodeResult(salt, options, res);
|
|
1129
|
+
}
|
|
1130
|
+
return res;
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
var validateOptions$3 = (options) => {
|
|
1134
|
+
var _a2;
|
|
1135
|
+
if (!options || typeof options !== "object") {
|
|
1136
|
+
throw new Error("Invalid options parameter. It requires an object.");
|
|
1137
|
+
}
|
|
1138
|
+
if (!options.password) {
|
|
1139
|
+
throw new Error("Password must be specified");
|
|
1140
|
+
}
|
|
1141
|
+
options.password = getUInt8Buffer(options.password);
|
|
1142
|
+
if (options.password.length < 1) {
|
|
1143
|
+
throw new Error("Password must be specified");
|
|
1144
|
+
}
|
|
1145
|
+
if (!options.salt) {
|
|
1146
|
+
throw new Error("Salt must be specified");
|
|
1147
|
+
}
|
|
1148
|
+
options.salt = getUInt8Buffer(options.salt);
|
|
1149
|
+
if (options.salt.length < 8) {
|
|
1150
|
+
throw new Error("Salt should be at least 8 bytes long");
|
|
1151
|
+
}
|
|
1152
|
+
options.secret = getUInt8Buffer((_a2 = options.secret) !== null && _a2 !== void 0 ? _a2 : "");
|
|
1153
|
+
if (!Number.isInteger(options.iterations) || options.iterations < 1) {
|
|
1154
|
+
throw new Error("Iterations should be a positive number");
|
|
1155
|
+
}
|
|
1156
|
+
if (!Number.isInteger(options.parallelism) || options.parallelism < 1) {
|
|
1157
|
+
throw new Error("Parallelism should be a positive number");
|
|
1158
|
+
}
|
|
1159
|
+
if (!Number.isInteger(options.hashLength) || options.hashLength < 4) {
|
|
1160
|
+
throw new Error("Hash length should be at least 4 bytes.");
|
|
1161
|
+
}
|
|
1162
|
+
if (!Number.isInteger(options.memorySize)) {
|
|
1163
|
+
throw new Error("Memory size should be specified.");
|
|
1164
|
+
}
|
|
1165
|
+
if (options.memorySize < 8 * options.parallelism) {
|
|
1166
|
+
throw new Error("Memory size should be at least 8 * parallelism.");
|
|
1167
|
+
}
|
|
1168
|
+
if (options.outputType === void 0) {
|
|
1169
|
+
options.outputType = "hex";
|
|
1170
|
+
}
|
|
1171
|
+
if (!["hex", "binary", "encoded"].includes(options.outputType)) {
|
|
1172
|
+
throw new Error(`Insupported output type ${options.outputType}. Valid values: ['hex', 'binary', 'encoded']`);
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
function argon2id(options) {
|
|
1176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1177
|
+
validateOptions$3(options);
|
|
1178
|
+
return argon2Internal(Object.assign(Object.assign({}, options), { hashType: "id" }));
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
new Mutex();
|
|
1182
|
+
new Mutex();
|
|
1183
|
+
new Mutex();
|
|
1184
|
+
new Mutex();
|
|
1185
|
+
new Mutex();
|
|
1186
|
+
new Mutex();
|
|
1187
|
+
new Mutex();
|
|
1188
|
+
new Mutex();
|
|
1189
|
+
new Mutex();
|
|
1190
|
+
new Mutex();
|
|
1191
|
+
new Mutex();
|
|
1192
|
+
new Mutex();
|
|
1193
|
+
new Mutex();
|
|
1194
|
+
new Mutex();
|
|
1195
|
+
new Mutex();
|
|
1196
|
+
new Mutex();
|
|
1197
|
+
new Mutex();
|
|
1198
|
+
new Mutex();
|
|
1199
|
+
new Mutex();
|
|
1200
|
+
new Mutex();
|
|
1201
|
+
|
|
1202
|
+
// src/derive-key/core.ts
|
|
1203
|
+
async function argon2(password, salt, parallelism = ARGON2ID_PARALLELISM, iterations = ARGON2ID_ITERATIONS, memorySize = ARGON2ID_MEMORY_SIZE, hashLength = ARGON2ID_OUTPUT_BYTE_LENGTH) {
|
|
1204
|
+
return argon2id({
|
|
1205
|
+
password,
|
|
1206
|
+
salt,
|
|
1207
|
+
parallelism,
|
|
1208
|
+
iterations,
|
|
1209
|
+
memorySize,
|
|
1210
|
+
hashLength,
|
|
1211
|
+
outputType: "binary"
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
function sampleSalt() {
|
|
1215
|
+
try {
|
|
1216
|
+
const salt = new Uint8Array(ARGON2ID_SALT_BYTE_LENGTH);
|
|
1217
|
+
crypto.getRandomValues(salt);
|
|
1218
|
+
return salt;
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
throw new Error("Failed to sample salt", { cause: error });
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// src/derive-key/deriveKeysFromPassword.ts
|
|
1225
|
+
async function getKeyFromPassword(password) {
|
|
1226
|
+
try {
|
|
1227
|
+
if (!password) {
|
|
1228
|
+
throw new Error("No password given");
|
|
1229
|
+
}
|
|
1230
|
+
const salt = sampleSalt();
|
|
1231
|
+
const key = await argon2(password, salt);
|
|
1232
|
+
return { key, salt };
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
throw new Error("Failed to derive key from password", { cause: error });
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
async function getKeyFromPasswordAndSalt(password, salt) {
|
|
1238
|
+
try {
|
|
1239
|
+
if (!salt.length) {
|
|
1240
|
+
throw new Error("No salt given");
|
|
1241
|
+
}
|
|
1242
|
+
if (!password) {
|
|
1243
|
+
throw new Error("No password given");
|
|
1244
|
+
}
|
|
1245
|
+
return await argon2(password, salt);
|
|
1246
|
+
} catch (error) {
|
|
1247
|
+
throw new Error("Failed to derive key from password and salt", { cause: error });
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
async function getKeyFromPasswordHex(password) {
|
|
1251
|
+
try {
|
|
1252
|
+
const { key, salt } = await getKeyFromPassword(password);
|
|
1253
|
+
return { keyHex: uint8ArrayToHex(key), saltHex: uint8ArrayToHex(salt) };
|
|
1254
|
+
} catch (error) {
|
|
1255
|
+
throw new Error("Failed to derive key from password", { cause: error });
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
async function getKeyFromPasswordAndSaltHex(password, saltHex) {
|
|
1259
|
+
try {
|
|
1260
|
+
const salt = hexToUint8Array(saltHex);
|
|
1261
|
+
const key = await getKeyFromPasswordAndSalt(password, salt);
|
|
1262
|
+
return uint8ArrayToHex(key);
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
throw new Error("Failed to derive key from password and salt", { cause: error });
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
async function verifyKeyFromPasswordHex(password, saltHex, keyHex) {
|
|
1268
|
+
const result = await getKeyFromPasswordAndSaltHex(password, saltHex);
|
|
1269
|
+
return keyHex === result;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
// src/email-crypto/converters.ts
|
|
1273
|
+
function emailBodyToBinary(body) {
|
|
1274
|
+
try {
|
|
1275
|
+
const json = JSON.stringify(body);
|
|
1276
|
+
return UTF8ToUint8(json);
|
|
1277
|
+
} catch (error) {
|
|
1278
|
+
throw new Error("Failed to convert EmailBody to Uint8Array", { cause: error });
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
function binaryToEmailBody(array) {
|
|
1282
|
+
try {
|
|
1283
|
+
const json = uint8ToUTF8(array);
|
|
1284
|
+
const email = JSON.parse(json);
|
|
1285
|
+
return email;
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
throw new Error("Failed to convert Uint8Array to EmailBody", { cause: error });
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
function encHybridKeyToBase64(encHybridKey) {
|
|
1291
|
+
try {
|
|
1292
|
+
const json = JSON.stringify({
|
|
1293
|
+
kyberCiphertext: uint8ArrayToBase64(encHybridKey.kyberCiphertext),
|
|
1294
|
+
encryptedKey: uint8ArrayToBase64(encHybridKey.encryptedKey)
|
|
1295
|
+
});
|
|
1296
|
+
const base64 = btoa(json);
|
|
1297
|
+
return base64;
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
throw new Error("Failed to convert hybrid key to base64", { cause: error });
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
function pwdProtectedKeyToBase64(pwdProtectedKey) {
|
|
1303
|
+
try {
|
|
1304
|
+
const json = JSON.stringify({
|
|
1305
|
+
encryptedKey: uint8ArrayToBase64(pwdProtectedKey.encryptedKey),
|
|
1306
|
+
salt: uint8ArrayToBase64(pwdProtectedKey.salt)
|
|
1307
|
+
});
|
|
1308
|
+
const base64 = btoa(json);
|
|
1309
|
+
return base64;
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
throw new Error("Failed to convert password-protected key to base64", { cause: error });
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function hybridEncyptedEmailToBase64(email) {
|
|
1315
|
+
try {
|
|
1316
|
+
const json = JSON.stringify({
|
|
1317
|
+
encryptedKey: encHybridKeyToBase64(email.encryptedKey),
|
|
1318
|
+
enc: ciphertextToBase64(email.enc),
|
|
1319
|
+
recipientEmail: email.recipientEmail
|
|
1320
|
+
});
|
|
1321
|
+
const base64 = btoa(json);
|
|
1322
|
+
return base64;
|
|
1323
|
+
} catch (error) {
|
|
1324
|
+
throw new Error("Failed to convert hybrid email to base64", { cause: error });
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
function pwdProtectedEmailToBase64(email) {
|
|
1328
|
+
try {
|
|
1329
|
+
const json = JSON.stringify({
|
|
1330
|
+
encryptedKey: pwdProtectedKeyToBase64(email.encryptedKey),
|
|
1331
|
+
enc: ciphertextToBase64(email.enc)
|
|
1332
|
+
});
|
|
1333
|
+
const base64 = btoa(json);
|
|
1334
|
+
return base64;
|
|
1335
|
+
} catch (error) {
|
|
1336
|
+
throw new Error("Failed to convert pwd protected email to base64", { cause: error });
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
function emailToBinary(email) {
|
|
1340
|
+
try {
|
|
1341
|
+
const json = JSON.stringify(email);
|
|
1342
|
+
return UTF8ToUint8(json);
|
|
1343
|
+
} catch (error) {
|
|
1344
|
+
throw new Error("Failed to convert EmailBody to Uint8Array", { cause: error });
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
function generateKyberKeys(seed) {
|
|
1348
|
+
try {
|
|
1349
|
+
return mlKem_js.ml_kem768.keygen(seed);
|
|
1350
|
+
} catch (error) {
|
|
1351
|
+
throw new Error("Failed to generate Kyber keys", { cause: error });
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function encapsulateKyber(publicKey) {
|
|
1355
|
+
try {
|
|
1356
|
+
return mlKem_js.ml_kem768.encapsulate(publicKey);
|
|
1357
|
+
} catch (error) {
|
|
1358
|
+
throw new Error("Failed to encapsulate", { cause: error });
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
function decapsulateKyber(cipherText, secretKey) {
|
|
1362
|
+
try {
|
|
1363
|
+
return mlKem_js.ml_kem768.decapsulate(cipherText, secretKey);
|
|
1364
|
+
} catch (error) {
|
|
1365
|
+
throw new Error("Failed to decapsulate", { cause: error });
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/key-wrapper/aesWrapper.ts
|
|
1370
|
+
async function importWrappingKey(key) {
|
|
1371
|
+
try {
|
|
1372
|
+
return await crypto.subtle.importKey(KEY_FORMAT, key, KEY_WRAPPING_ALGORITHM, false, [
|
|
1373
|
+
"wrapKey",
|
|
1374
|
+
"unwrapKey"
|
|
1375
|
+
]);
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
throw new Error("Failed to import wrapping key", { cause: error });
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
async function deriveWrappingKey(eccSecret, kyberSecret) {
|
|
1381
|
+
try {
|
|
1382
|
+
if (eccSecret.length !== kyberSecret.length) {
|
|
1383
|
+
throw new Error("secrets must have equal length");
|
|
1384
|
+
}
|
|
1385
|
+
const key = await deriveKeyFromTwoKeysAndContext(eccSecret, kyberSecret, CONTEXT_WRAPPING);
|
|
1386
|
+
return await importWrappingKey(key);
|
|
1387
|
+
} catch (error) {
|
|
1388
|
+
throw new Error("Failed to derive wrapping key", { cause: error });
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
async function unwrapKey(encryptedKey, wrappingKey) {
|
|
1392
|
+
try {
|
|
1393
|
+
return await crypto.subtle.unwrapKey(
|
|
1394
|
+
KEY_FORMAT,
|
|
1395
|
+
encryptedKey,
|
|
1396
|
+
wrappingKey,
|
|
1397
|
+
KEY_WRAPPING_ALGORITHM,
|
|
1398
|
+
AES_ALGORITHM,
|
|
1399
|
+
false,
|
|
1400
|
+
["encrypt", "decrypt"]
|
|
1401
|
+
);
|
|
1402
|
+
} catch (error) {
|
|
1403
|
+
throw new Error("Failed to unwrap key", { cause: error });
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
async function wrapKey(encryptionKey, wrappingKey) {
|
|
1407
|
+
try {
|
|
1408
|
+
const result = await crypto.subtle.wrapKey(KEY_FORMAT, encryptionKey, wrappingKey, KEY_WRAPPING_ALGORITHM);
|
|
1409
|
+
return new Uint8Array(result);
|
|
1410
|
+
} catch (error) {
|
|
1411
|
+
throw new Error("Failed to wrap key", { cause: error });
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// src/email-crypto/core.ts
|
|
1416
|
+
async function encryptEmailContentSymmetrically(email, aux, emailID) {
|
|
1417
|
+
try {
|
|
1418
|
+
const encryptionKey = await genSymmetricCryptoKey();
|
|
1419
|
+
const enc = await encryptEmailContentSymmetricallyWithKey(email, encryptionKey, aux, emailID);
|
|
1420
|
+
return { enc, encryptionKey };
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
throw new Error("Failed to symmetrically encrypt email", { cause: error });
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
async function encryptEmailContentAndSubjectSymmetrically(email, subject, aux, emailID) {
|
|
1426
|
+
try {
|
|
1427
|
+
const encryptionKey = await genSymmetricCryptoKey();
|
|
1428
|
+
const enc = await encryptEmailContentSymmetricallyWithKey(email, encryptionKey, aux, emailID);
|
|
1429
|
+
const subjectBuff = UTF8ToUint8(subject);
|
|
1430
|
+
const subjectEnc = await encryptSymmetrically(encryptionKey, subjectBuff, aux);
|
|
1431
|
+
return { enc, encryptionKey, subjectEnc };
|
|
1432
|
+
} catch (error) {
|
|
1433
|
+
throw new Error("Failed to symmetrically encrypt email and subject", { cause: error });
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
async function decryptEmailAndSubjectSymmetrically(emailCiphertext, encSubject, encryptionKey, aux) {
|
|
1437
|
+
try {
|
|
1438
|
+
const binaryEmail = await decryptSymmetrically(encryptionKey, emailCiphertext, aux);
|
|
1439
|
+
const subject = await decryptSymmetrically(encryptionKey, encSubject, aux);
|
|
1440
|
+
const body = binaryToEmailBody(binaryEmail);
|
|
1441
|
+
return { body, subject: uint8ToUTF8(subject) };
|
|
1442
|
+
} catch (error) {
|
|
1443
|
+
throw new Error("Failed to symmetrically decrypt email and subject", { cause: error });
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
async function encryptEmailContentSymmetricallyWithKey(emailBody, encryptionKey, aux, emailID) {
|
|
1447
|
+
try {
|
|
1448
|
+
const binaryEmail = emailBodyToBinary(emailBody);
|
|
1449
|
+
const ciphertext = await encryptSymmetrically(encryptionKey, binaryEmail, aux, emailID);
|
|
1450
|
+
return ciphertext;
|
|
1451
|
+
} catch (error) {
|
|
1452
|
+
throw new Error("Failed to symmetrically encrypt email with the given key", { cause: error });
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
async function decryptEmailSymmetrically(emailCiphertext, encryptionKey, aux) {
|
|
1456
|
+
try {
|
|
1457
|
+
const binaryEmail = await decryptSymmetrically(encryptionKey, emailCiphertext, aux);
|
|
1458
|
+
const body = binaryToEmailBody(binaryEmail);
|
|
1459
|
+
return body;
|
|
1460
|
+
} catch (error) {
|
|
1461
|
+
throw new Error("Failed to symmetrically decrypt email", { cause: error });
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
async function encryptKeysHybrid(emailEncryptionKey, recipientPublicKey, senderPrivateKey) {
|
|
1465
|
+
try {
|
|
1466
|
+
const eccSecret = await deriveSecretKey(recipientPublicKey.eccPublicKey, senderPrivateKey.eccPrivateKey);
|
|
1467
|
+
const { cipherText: kyberCiphertext, sharedSecret: kyberSecret } = encapsulateKyber(
|
|
1468
|
+
recipientPublicKey.kyberPublicKey
|
|
1469
|
+
);
|
|
1470
|
+
const wrappingKey = await deriveWrappingKey(eccSecret, kyberSecret);
|
|
1471
|
+
const encryptedKey = await wrapKey(emailEncryptionKey, wrappingKey);
|
|
1472
|
+
return { encryptedKey, kyberCiphertext };
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
throw new Error("Failed to encrypt email key using hybrid encryption", { cause: error });
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
async function decryptKeysHybrid(encryptedKey, senderPublicKey, recipientPrivateKey) {
|
|
1478
|
+
try {
|
|
1479
|
+
const eccSecret = await deriveSecretKey(senderPublicKey.eccPublicKey, recipientPrivateKey.eccPrivateKey);
|
|
1480
|
+
const kyberSecret = decapsulateKyber(encryptedKey.kyberCiphertext, recipientPrivateKey.kyberPrivateKey);
|
|
1481
|
+
const wrappingKey = await deriveWrappingKey(eccSecret, kyberSecret);
|
|
1482
|
+
const encryptionKey = await unwrapKey(encryptedKey.encryptedKey, wrappingKey);
|
|
1483
|
+
return encryptionKey;
|
|
1484
|
+
} catch (error) {
|
|
1485
|
+
throw new Error("Failed to decrypt email key encrypted via hybrid encryption", { cause: error });
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
async function passwordProtectKey(emailEncryptionKey, password) {
|
|
1489
|
+
try {
|
|
1490
|
+
const { key, salt } = await getKeyFromPassword(password);
|
|
1491
|
+
const wrappingKey = await importWrappingKey(key);
|
|
1492
|
+
const encryptedKey = await wrapKey(emailEncryptionKey, wrappingKey);
|
|
1493
|
+
return { encryptedKey, salt };
|
|
1494
|
+
} catch (error) {
|
|
1495
|
+
throw new Error("Failed to password-protect email key", { cause: error });
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
async function removePasswordProtection(emailEncryptionKey, password) {
|
|
1499
|
+
try {
|
|
1500
|
+
const key = await getKeyFromPasswordAndSalt(password, emailEncryptionKey.salt);
|
|
1501
|
+
const wrappingKey = await importWrappingKey(key);
|
|
1502
|
+
const encryptionKey = await unwrapKey(emailEncryptionKey.encryptedKey, wrappingKey);
|
|
1503
|
+
return encryptionKey;
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
throw new Error("Failed to remove password-protection from email key", { cause: error });
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
function getAux(params) {
|
|
1509
|
+
try {
|
|
1510
|
+
const { subject, replyToEmailID, sender, recipients } = params;
|
|
1511
|
+
const aux = JSON.stringify({ subject, replyToEmailID, sender, recipients });
|
|
1512
|
+
return aux;
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
throw new Error("Failed to create aux", { cause: error });
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
function getAuxWithoutSubject(params) {
|
|
1518
|
+
try {
|
|
1519
|
+
const { replyToEmailID, sender, recipients } = params;
|
|
1520
|
+
const aux = JSON.stringify({ replyToEmailID, sender, recipients });
|
|
1521
|
+
return aux;
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
throw new Error("Failed to create aux without subject", { cause: error });
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
function generateEmailID() {
|
|
1527
|
+
return uuid.v4();
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// src/email-crypto/hybridEncyptedEmail.ts
|
|
1531
|
+
async function encryptEmailHybrid(email, recipient, senderPrivateKey) {
|
|
1532
|
+
try {
|
|
1533
|
+
const aux = getAux(email.params);
|
|
1534
|
+
const { enc, encryptionKey } = await encryptEmailContentSymmetrically(email.body, aux, email.id);
|
|
1535
|
+
const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);
|
|
1536
|
+
return { enc, encryptedKey, recipientEmail: recipient.email, params: email.params, id: email.id };
|
|
1537
|
+
} catch (error) {
|
|
1538
|
+
throw new Error("Failed to encrypt email with hybrid encryption", { cause: error });
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
async function encryptEmailHybridForMultipleRecipients(email, recipients, senderPrivateKey) {
|
|
1542
|
+
try {
|
|
1543
|
+
const aux = getAux(email.params);
|
|
1544
|
+
const { enc, encryptionKey } = await encryptEmailContentSymmetrically(email.body, aux, email.id);
|
|
1545
|
+
const encryptedEmails = [];
|
|
1546
|
+
for (const recipient of recipients) {
|
|
1547
|
+
const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);
|
|
1548
|
+
encryptedEmails.push({ enc, encryptedKey, recipientEmail: recipient.email, params: email.params, id: email.id });
|
|
1549
|
+
}
|
|
1550
|
+
return encryptedEmails;
|
|
1551
|
+
} catch (error) {
|
|
1552
|
+
throw new Error("Failed to encrypt email to multiple recipients with hybrid encryption", { cause: error });
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
async function decryptEmailHybrid(encryptedEmail, senderPublicKeys, recipientPrivateKeys) {
|
|
1556
|
+
try {
|
|
1557
|
+
const aux = getAux(encryptedEmail.params);
|
|
1558
|
+
const encryptionKey = await decryptKeysHybrid(encryptedEmail.encryptedKey, senderPublicKeys, recipientPrivateKeys);
|
|
1559
|
+
const body = await decryptEmailSymmetrically(encryptedEmail.enc, encryptionKey, aux);
|
|
1560
|
+
return { body, params: encryptedEmail.params, id: encryptedEmail.id };
|
|
1561
|
+
} catch (error) {
|
|
1562
|
+
throw new Error("Failed to decrypt email with hybrid encryption", { cause: error });
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// src/email-crypto/hybridEncyptedEmailAndSubject.ts
|
|
1567
|
+
async function encryptEmailAndSubjectHybrid(email, recipient, senderPrivateKey) {
|
|
1568
|
+
try {
|
|
1569
|
+
const aux = getAuxWithoutSubject(email.params);
|
|
1570
|
+
const { enc, encryptionKey, subjectEnc } = await encryptEmailContentAndSubjectSymmetrically(
|
|
1571
|
+
email.body,
|
|
1572
|
+
email.params.subject,
|
|
1573
|
+
aux,
|
|
1574
|
+
email.id
|
|
1575
|
+
);
|
|
1576
|
+
const encSubjectStr = ciphertextToBase64(subjectEnc);
|
|
1577
|
+
const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);
|
|
1578
|
+
const params = { ...email.params, subject: encSubjectStr };
|
|
1579
|
+
return { enc, encryptedKey, recipientEmail: recipient.email, params, id: email.id };
|
|
1580
|
+
} catch (error) {
|
|
1581
|
+
throw new Error("Failed to encrypt the email and its subject with hybrid encryption", { cause: error });
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
async function encryptEmailAndSubjectHybridForMultipleRecipients(email, recipients, senderPrivateKey) {
|
|
1585
|
+
try {
|
|
1586
|
+
const aux = getAuxWithoutSubject(email.params);
|
|
1587
|
+
const { enc, encryptionKey, subjectEnc } = await encryptEmailContentAndSubjectSymmetrically(
|
|
1588
|
+
email.body,
|
|
1589
|
+
email.params.subject,
|
|
1590
|
+
aux,
|
|
1591
|
+
email.id
|
|
1592
|
+
);
|
|
1593
|
+
const encSubjectStr = ciphertextToBase64(subjectEnc);
|
|
1594
|
+
const encryptedEmails = [];
|
|
1595
|
+
for (const recipient of recipients) {
|
|
1596
|
+
const encryptedKey = await encryptKeysHybrid(encryptionKey, recipient.publicKeys, senderPrivateKey);
|
|
1597
|
+
const params = { ...email.params, subject: encSubjectStr };
|
|
1598
|
+
encryptedEmails.push({ enc, encryptedKey, recipientEmail: recipient.email, params, id: email.id });
|
|
1599
|
+
}
|
|
1600
|
+
return encryptedEmails;
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
throw new Error("Failed to encrypt the email and its subject to multiple recipients with hybrid encryption", {
|
|
1603
|
+
cause: error
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
async function decryptEmailAndSubjectHybrid(encryptedEmail, senderPublicKeys, recipientPrivateKeys) {
|
|
1608
|
+
try {
|
|
1609
|
+
const aux = getAuxWithoutSubject(encryptedEmail.params);
|
|
1610
|
+
const encryptionKey = await decryptKeysHybrid(encryptedEmail.encryptedKey, senderPublicKeys, recipientPrivateKeys);
|
|
1611
|
+
const encSubject = base64ToCiphertext(encryptedEmail.params.subject);
|
|
1612
|
+
const { body, subject } = await decryptEmailAndSubjectSymmetrically(
|
|
1613
|
+
encryptedEmail.enc,
|
|
1614
|
+
encSubject,
|
|
1615
|
+
encryptionKey,
|
|
1616
|
+
aux
|
|
1617
|
+
);
|
|
1618
|
+
const params = { ...encryptedEmail.params, subject };
|
|
1619
|
+
return { body, params, id: encryptedEmail.id };
|
|
1620
|
+
} catch (error) {
|
|
1621
|
+
throw new Error("Failed to decrypt the email and its subject with hybrid encryption", { cause: error });
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// src/email-crypto/pwdProtectedEmail.ts
|
|
1626
|
+
async function createPwdProtectedEmail(email, password) {
|
|
1627
|
+
try {
|
|
1628
|
+
if (!email?.body || !email.params) {
|
|
1629
|
+
throw new Error("Failed to password-protect email: Invalid email structure");
|
|
1630
|
+
}
|
|
1631
|
+
const aux = getAux(email.params);
|
|
1632
|
+
const { enc, encryptionKey } = await encryptEmailContentSymmetrically(email.body, aux, email.id);
|
|
1633
|
+
const encryptedKey = await passwordProtectKey(encryptionKey, password);
|
|
1634
|
+
return { enc, encryptedKey, params: email.params, id: email.id };
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
throw new Error("Failed to password-protect email", { cause: error });
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
async function decryptPwdProtectedEmail(encryptedEmail, password) {
|
|
1640
|
+
try {
|
|
1641
|
+
const aux = getAux(encryptedEmail.params);
|
|
1642
|
+
const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);
|
|
1643
|
+
const body = await decryptEmailSymmetrically(encryptedEmail.enc, encryptionKey, aux);
|
|
1644
|
+
return { body, params: encryptedEmail.params, id: encryptedEmail.id };
|
|
1645
|
+
} catch (error) {
|
|
1646
|
+
throw new Error("Failed to decrypt password-protect email", { cause: error });
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
// src/email-crypto/pwdProtectedEmailAndSubject.ts
|
|
1651
|
+
async function createPwdProtectedEmailAndSubject(email, password) {
|
|
1652
|
+
try {
|
|
1653
|
+
if (!email?.body || !email.params) {
|
|
1654
|
+
throw new Error("Failed to password-protect email and subject: Invalid email structure");
|
|
1655
|
+
}
|
|
1656
|
+
const aux = getAuxWithoutSubject(email.params);
|
|
1657
|
+
const { enc, encryptionKey, subjectEnc } = await encryptEmailContentAndSubjectSymmetrically(
|
|
1658
|
+
email.body,
|
|
1659
|
+
email.params.subject,
|
|
1660
|
+
aux,
|
|
1661
|
+
email.id
|
|
1662
|
+
);
|
|
1663
|
+
const encryptedKey = await passwordProtectKey(encryptionKey, password);
|
|
1664
|
+
const encSubjectStr = ciphertextToBase64(subjectEnc);
|
|
1665
|
+
const params = { ...email.params, subject: encSubjectStr };
|
|
1666
|
+
return { enc, encryptedKey, params, id: email.id };
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
throw new Error("Failed to password-protect email and subject", { cause: error });
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
async function decryptPwdProtectedEmailAndSubject(encryptedEmail, password) {
|
|
1672
|
+
try {
|
|
1673
|
+
const aux = getAuxWithoutSubject(encryptedEmail.params);
|
|
1674
|
+
const encryptionKey = await removePasswordProtection(encryptedEmail.encryptedKey, password);
|
|
1675
|
+
const encSubject = base64ToCiphertext(encryptedEmail.params.subject);
|
|
1676
|
+
const { body, subject } = await decryptEmailAndSubjectSymmetrically(
|
|
1677
|
+
encryptedEmail.enc,
|
|
1678
|
+
encSubject,
|
|
1679
|
+
encryptionKey,
|
|
1680
|
+
aux
|
|
1681
|
+
);
|
|
1682
|
+
const params = { ...encryptedEmail.params, subject };
|
|
1683
|
+
return { body, params, id: encryptedEmail.id };
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
throw new Error("Failed to decrypt password-protect email", { cause: error });
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
var getDatabaseName = (userID) => {
|
|
1689
|
+
return `ES:${userID}:DB`;
|
|
1690
|
+
};
|
|
1691
|
+
var openDatabase = async (userID) => {
|
|
1692
|
+
try {
|
|
1693
|
+
const dbName = getDatabaseName(userID);
|
|
1694
|
+
return idb.openDB(dbName, DB_VERSION, {
|
|
1695
|
+
upgrade(db) {
|
|
1696
|
+
if (!db.objectStoreNames.contains(DB_LABEL)) {
|
|
1697
|
+
const store = db.createObjectStore(DB_LABEL, { keyPath: "id" });
|
|
1698
|
+
store.createIndex("byTime", "params.createdAt");
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
} catch (error) {
|
|
1703
|
+
throw new Error(`Cannot open a database for the user ${userID}`, { cause: error });
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
var closeDatabase = (esDB) => {
|
|
1707
|
+
return esDB.close();
|
|
1708
|
+
};
|
|
1709
|
+
var deriveIndexKey = async (baseKey) => {
|
|
1710
|
+
return deriveSymmetricCryptoKeyFromContext(CONTEXT_INDEX, baseKey);
|
|
1711
|
+
};
|
|
1712
|
+
var encryptAndStoreEmail = async (newEmailToStore, indexKey, esDB) => {
|
|
1713
|
+
try {
|
|
1714
|
+
const aux = getAux(newEmailToStore.params);
|
|
1715
|
+
const ciphertext = await encryptEmailContentSymmetricallyWithKey(
|
|
1716
|
+
newEmailToStore.body,
|
|
1717
|
+
indexKey,
|
|
1718
|
+
aux,
|
|
1719
|
+
newEmailToStore.id
|
|
1720
|
+
);
|
|
1721
|
+
const encryptedEmail = { content: ciphertext, params: newEmailToStore.params, id: newEmailToStore.id };
|
|
1722
|
+
await esDB.put(DB_LABEL, encryptedEmail);
|
|
1723
|
+
} catch (error) {
|
|
1724
|
+
throw new Error("Cannot encrypt and add the given email to the database", { cause: error });
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
var encryptAndStoreManyEmail = async (newEmailsToStore, indexKey, esDB) => {
|
|
1728
|
+
try {
|
|
1729
|
+
const encryptedEmails = await Promise.all(
|
|
1730
|
+
newEmailsToStore.map(async (email) => {
|
|
1731
|
+
const aux = getAux(email.params);
|
|
1732
|
+
const ciphertext = await encryptEmailContentSymmetricallyWithKey(email.body, indexKey, aux, email.id);
|
|
1733
|
+
return { content: ciphertext, params: email.params, id: email.id };
|
|
1734
|
+
})
|
|
1735
|
+
);
|
|
1736
|
+
const tr = esDB.transaction(DB_LABEL, "readwrite");
|
|
1737
|
+
await Promise.all([...encryptedEmails.map((encEmail) => tr.store.put(encEmail)), tr.done]);
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
throw new Error("Cannot encrypt and add emails to the database", { cause: error });
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
var decryptEmail = async (indexKey, encryptedEmail) => {
|
|
1743
|
+
try {
|
|
1744
|
+
const aux = getAux(encryptedEmail.params);
|
|
1745
|
+
const email = await decryptEmailSymmetrically(encryptedEmail.content, indexKey, aux);
|
|
1746
|
+
return { body: email, params: encryptedEmail.params, id: encryptedEmail.id };
|
|
1747
|
+
} catch (error) {
|
|
1748
|
+
throw new Error("Cannot decrypt the given email", { cause: error });
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
var getAndDecryptEmail = async (emailID, indexKey, esDB) => {
|
|
1752
|
+
try {
|
|
1753
|
+
const encryptedEmail = await esDB.get(DB_LABEL, emailID);
|
|
1754
|
+
if (!encryptedEmail) {
|
|
1755
|
+
throw new Error(`DB cannot find email with id ${emailID}`);
|
|
1756
|
+
}
|
|
1757
|
+
return decryptEmail(indexKey, encryptedEmail);
|
|
1758
|
+
} catch (error) {
|
|
1759
|
+
throw new Error(`Cannot fetch the email ${emailID} from the database`, { cause: error });
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
var getAndDecryptAllEmails = async (indexKey, esDB) => {
|
|
1763
|
+
try {
|
|
1764
|
+
const encryptedEmails = await esDB.getAll(DB_LABEL);
|
|
1765
|
+
const decryptedEmails = await Promise.all(
|
|
1766
|
+
encryptedEmails.map(async (encEmail) => {
|
|
1767
|
+
const aux = getAux(encEmail.params);
|
|
1768
|
+
const body = await decryptEmailSymmetrically(encEmail.content, indexKey, aux);
|
|
1769
|
+
return { body, params: encEmail.params, id: encEmail.id };
|
|
1770
|
+
})
|
|
1771
|
+
);
|
|
1772
|
+
return decryptedEmails.filter((email) => email !== null);
|
|
1773
|
+
} catch (error) {
|
|
1774
|
+
throw new Error("Cannot fetch and decrypt all emails from the database", { cause: error });
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
var deleteEmail = async (emailID, esDB) => {
|
|
1778
|
+
await esDB.delete(DB_LABEL, emailID);
|
|
1779
|
+
};
|
|
1780
|
+
var getEmailCount = async (esDB) => {
|
|
1781
|
+
return await esDB.count(DB_LABEL);
|
|
1782
|
+
};
|
|
1783
|
+
var deleteOldestEmails = async (emailsToDelete, esDB) => {
|
|
1784
|
+
try {
|
|
1785
|
+
const tx = esDB.transaction(DB_LABEL, "readwrite");
|
|
1786
|
+
const index = tx.store.index("byTime");
|
|
1787
|
+
let cursor = await index.openCursor();
|
|
1788
|
+
let deletedCount = 0;
|
|
1789
|
+
while (cursor && deletedCount < emailsToDelete) {
|
|
1790
|
+
await cursor.delete();
|
|
1791
|
+
deletedCount++;
|
|
1792
|
+
cursor = await cursor.continue();
|
|
1793
|
+
}
|
|
1794
|
+
await tx.done;
|
|
1795
|
+
} catch (error) {
|
|
1796
|
+
throw new Error(`Cannot delete ${emailsToDelete} oldests emails from the database`, { cause: error });
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
var enforceMaxEmailNumber = async (esDB, max) => {
|
|
1800
|
+
try {
|
|
1801
|
+
const currentCount = await getEmailCount(esDB);
|
|
1802
|
+
if (currentCount <= max) {
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
await deleteOldestEmails(currentCount - max, esDB);
|
|
1806
|
+
} catch (error) {
|
|
1807
|
+
throw new Error(`Cannot enforce the maximum of ${max} emails on the database`, { cause: error });
|
|
1808
|
+
}
|
|
1809
|
+
};
|
|
1810
|
+
var fetchEmails = async (esDB, indexKey, direction) => {
|
|
1811
|
+
try {
|
|
1812
|
+
const tx = esDB.transaction(DB_LABEL, "readonly");
|
|
1813
|
+
const index = tx.store.index("byTime");
|
|
1814
|
+
const encryptedEmails = [];
|
|
1815
|
+
let cursor = await index.openCursor(null, direction);
|
|
1816
|
+
while (cursor) {
|
|
1817
|
+
encryptedEmails.push(cursor.value);
|
|
1818
|
+
cursor = await cursor.continue();
|
|
1819
|
+
}
|
|
1820
|
+
const emails = await Promise.all(encryptedEmails.map((encryptedEmail) => decryptEmail(indexKey, encryptedEmail)));
|
|
1821
|
+
return emails;
|
|
1822
|
+
} catch (error) {
|
|
1823
|
+
throw new Error("Cannot fetch emails from database", { cause: error });
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
var getAllEmailsSortedNewestFirst = async (esDB, indexKey) => {
|
|
1827
|
+
return fetchEmails(esDB, indexKey, "prev");
|
|
1828
|
+
};
|
|
1829
|
+
var getAllEmailsSortedOldestFirst = async (esDB, indexKey) => {
|
|
1830
|
+
return fetchEmails(esDB, indexKey, "next");
|
|
1831
|
+
};
|
|
1832
|
+
var getEmailBatch = async (esDB, indexKey, batchSize, startCursor) => {
|
|
1833
|
+
try {
|
|
1834
|
+
const tx = esDB.transaction(DB_LABEL, "readonly");
|
|
1835
|
+
const index = tx.store.index("byTime");
|
|
1836
|
+
const encryptedEmails = [];
|
|
1837
|
+
let cursor;
|
|
1838
|
+
if (startCursor) {
|
|
1839
|
+
const range = IDBKeyRange.upperBound(startCursor, true);
|
|
1840
|
+
cursor = await index.openCursor(range, "prev");
|
|
1841
|
+
} else {
|
|
1842
|
+
cursor = await index.openCursor(null, "prev");
|
|
1843
|
+
}
|
|
1844
|
+
let count = 0;
|
|
1845
|
+
let nextCursor;
|
|
1846
|
+
while (cursor && count < batchSize) {
|
|
1847
|
+
encryptedEmails.push(cursor.value);
|
|
1848
|
+
nextCursor = cursor.key;
|
|
1849
|
+
count++;
|
|
1850
|
+
cursor = await cursor.continue();
|
|
1851
|
+
}
|
|
1852
|
+
const emails = await Promise.all(encryptedEmails.map((encryptedEmail) => decryptEmail(indexKey, encryptedEmail)));
|
|
1853
|
+
return {
|
|
1854
|
+
emails,
|
|
1855
|
+
nextCursor: count === batchSize ? nextCursor : void 0
|
|
1856
|
+
};
|
|
1857
|
+
} catch (error) {
|
|
1858
|
+
throw new Error(`Cannot fetch email batch of ${batchSize} from the database`, { cause: error });
|
|
1859
|
+
}
|
|
1860
|
+
};
|
|
1861
|
+
|
|
1862
|
+
// src/email-search/mailCache.ts
|
|
1863
|
+
function sizeOfEmail(email) {
|
|
1864
|
+
return emailToBinary(email).byteLength;
|
|
1865
|
+
}
|
|
1866
|
+
function createEmptyCache() {
|
|
1867
|
+
return {
|
|
1868
|
+
esCache: /* @__PURE__ */ new Map(),
|
|
1869
|
+
cacheSize: 0,
|
|
1870
|
+
isCacheLimited: false,
|
|
1871
|
+
isCacheReady: true
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
var createCacheFromDB = async (indexKey, esDB) => {
|
|
1875
|
+
const esCache = createEmptyCache();
|
|
1876
|
+
esCache.isCacheReady = false;
|
|
1877
|
+
try {
|
|
1878
|
+
const count = await getEmailCount(esDB);
|
|
1879
|
+
if (!count) {
|
|
1880
|
+
esCache.isCacheReady = true;
|
|
1881
|
+
return esCache;
|
|
1882
|
+
}
|
|
1883
|
+
if (count <= MAX_EMAIL_PER_BATCH) {
|
|
1884
|
+
const emails = await getAllEmailsSortedNewestFirst(esDB, indexKey);
|
|
1885
|
+
addEmailsToCache(emails, esCache);
|
|
1886
|
+
} else {
|
|
1887
|
+
let nextCursor = void 0;
|
|
1888
|
+
let cacheFull = false;
|
|
1889
|
+
while (!cacheFull) {
|
|
1890
|
+
const { emails, nextCursor: newCursor } = await getEmailBatch(
|
|
1891
|
+
esDB,
|
|
1892
|
+
indexKey,
|
|
1893
|
+
MAX_EMAIL_PER_BATCH,
|
|
1894
|
+
nextCursor
|
|
1895
|
+
);
|
|
1896
|
+
if (!newCursor || !emails.length) break;
|
|
1897
|
+
nextCursor = newCursor;
|
|
1898
|
+
const success = addEmailsToCache(emails, esCache);
|
|
1899
|
+
if (!success) cacheFull = true;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
return esCache;
|
|
1903
|
+
} catch (error) {
|
|
1904
|
+
throw new Error(`Email caching failed: ${error}`);
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
var getEmailFromCache = async (emailID, esCache) => {
|
|
1908
|
+
const email = esCache.esCache.get(emailID);
|
|
1909
|
+
if (!email) {
|
|
1910
|
+
throw new Error(`Email not found in cache for ID: ${emailID}`);
|
|
1911
|
+
}
|
|
1912
|
+
return email;
|
|
1913
|
+
};
|
|
1914
|
+
var deleteEmailFromCache = async (emailID, esCache) => {
|
|
1915
|
+
try {
|
|
1916
|
+
const email = await getEmailFromCache(emailID, esCache);
|
|
1917
|
+
const size = sizeOfEmail(email);
|
|
1918
|
+
const removed = esCache.esCache.delete(emailID);
|
|
1919
|
+
if (removed) esCache.cacheSize -= size;
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
throw new Error(`Failed to delete email with ID ${emailID}`, { cause: error });
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
function addEmailsToCache(emails, esCache) {
|
|
1925
|
+
try {
|
|
1926
|
+
for (const email of emails) {
|
|
1927
|
+
const result = addEmailToCache(email, esCache);
|
|
1928
|
+
if (!result.success) return result;
|
|
1929
|
+
}
|
|
1930
|
+
return { success: true };
|
|
1931
|
+
} catch (error) {
|
|
1932
|
+
throw new Error("Failed to add emails to the cache", { cause: error });
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
var addEmailToCache = (email, esCache) => {
|
|
1936
|
+
try {
|
|
1937
|
+
if (esCache.esCache.has(email.id)) {
|
|
1938
|
+
return { success: false, reason: "email already exists in cache" };
|
|
1939
|
+
}
|
|
1940
|
+
const emailSize = sizeOfEmail(email);
|
|
1941
|
+
if (esCache.cacheSize + emailSize > MAX_CACHE_SIZE) {
|
|
1942
|
+
esCache.isCacheLimited = true;
|
|
1943
|
+
return { success: false, reason: "hit cache limit" };
|
|
1944
|
+
}
|
|
1945
|
+
esCache.esCache.set(email.id, email);
|
|
1946
|
+
esCache.cacheSize += emailSize;
|
|
1947
|
+
return { success: true };
|
|
1948
|
+
} catch (error) {
|
|
1949
|
+
throw new Error("Failed to add email to the cache", { cause: error });
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
var SUBJECT_OPTIONS = {
|
|
1953
|
+
preset: "match",
|
|
1954
|
+
tokenize: "forward",
|
|
1955
|
+
resolution: 9,
|
|
1956
|
+
minlength: 2,
|
|
1957
|
+
optimize: true,
|
|
1958
|
+
fastupdate: true,
|
|
1959
|
+
cache: true
|
|
1960
|
+
};
|
|
1961
|
+
var BODY_OPTIONS = {
|
|
1962
|
+
...SUBJECT_OPTIONS,
|
|
1963
|
+
minlength: 3,
|
|
1964
|
+
resolution: 6
|
|
1965
|
+
};
|
|
1966
|
+
var FROM_OPTIONS = {
|
|
1967
|
+
...SUBJECT_OPTIONS,
|
|
1968
|
+
tokenize: "strict",
|
|
1969
|
+
minlength: 1
|
|
1970
|
+
};
|
|
1971
|
+
var TO_OPTIONS = {
|
|
1972
|
+
...SUBJECT_OPTIONS,
|
|
1973
|
+
tokenize: "strict",
|
|
1974
|
+
minlength: 1
|
|
1975
|
+
};
|
|
1976
|
+
var createSearchIndex = () => ({
|
|
1977
|
+
subjectIndex: new flexsearch.Index(SUBJECT_OPTIONS),
|
|
1978
|
+
bodyIndex: new flexsearch.Index(BODY_OPTIONS),
|
|
1979
|
+
fromIndex: new flexsearch.Index(FROM_OPTIONS),
|
|
1980
|
+
toIndex: new flexsearch.Index(TO_OPTIONS),
|
|
1981
|
+
isReady: false
|
|
1982
|
+
});
|
|
1983
|
+
var addEmailToSearchIndex = (email, searchIndex) => {
|
|
1984
|
+
try {
|
|
1985
|
+
const emailId = email.id;
|
|
1986
|
+
if (email.params.subject) {
|
|
1987
|
+
searchIndex.subjectIndex.add(emailId, email.params.subject);
|
|
1988
|
+
}
|
|
1989
|
+
if (email.body?.text) {
|
|
1990
|
+
searchIndex.bodyIndex.add(emailId, email.body.text);
|
|
1991
|
+
}
|
|
1992
|
+
if (email.params.sender) {
|
|
1993
|
+
const senderText = `${email.params.sender.name || ""} ${email.params.sender.email || ""}`.trim();
|
|
1994
|
+
searchIndex.fromIndex.add(emailId, senderText);
|
|
1995
|
+
}
|
|
1996
|
+
const recipientsList = email.params.recipients?.length ? email.params.recipients : [email.params.recipient];
|
|
1997
|
+
const recipientsText = recipientsList.map((recipient) => `${recipient.name || ""} ${recipient.email || ""}`.trim()).join(" ");
|
|
1998
|
+
searchIndex.toIndex.add(emailId, recipientsText);
|
|
1999
|
+
} catch (error) {
|
|
2000
|
+
throw new Error("Failed to add email to the search index", { cause: error });
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
var removeEmailFromSearchIndex = (emailID, searchIndex) => {
|
|
2004
|
+
try {
|
|
2005
|
+
searchIndex.subjectIndex.remove(emailID);
|
|
2006
|
+
searchIndex.bodyIndex.remove(emailID);
|
|
2007
|
+
searchIndex.fromIndex.remove(emailID);
|
|
2008
|
+
searchIndex.toIndex.remove(emailID);
|
|
2009
|
+
} catch (error) {
|
|
2010
|
+
throw new Error(`Failed to remove email with ID ${emailID} from the search index`, { cause: error });
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
var buildSearchIndexFromCache = async (esCache) => {
|
|
2014
|
+
try {
|
|
2015
|
+
const searchIndex = createSearchIndex();
|
|
2016
|
+
searchIndex.isReady = false;
|
|
2017
|
+
for (const email of esCache.esCache.values()) {
|
|
2018
|
+
addEmailToSearchIndex(email, searchIndex);
|
|
2019
|
+
}
|
|
2020
|
+
searchIndex.isReady = true;
|
|
2021
|
+
return searchIndex;
|
|
2022
|
+
} catch (error) {
|
|
2023
|
+
throw new Error("Failed build an email search index from the cache", { cause: error });
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
var searchEmails = async (query, esCache, searchIndex, options = {}) => {
|
|
2027
|
+
try {
|
|
2028
|
+
if (!searchIndex.isReady || !query.trim()) {
|
|
2029
|
+
return [];
|
|
2030
|
+
}
|
|
2031
|
+
const {
|
|
2032
|
+
fields = ["subject", "body", "from", "to"],
|
|
2033
|
+
limit = 50,
|
|
2034
|
+
boost = { subject: 3, body: 1, from: 2, to: 2 }
|
|
2035
|
+
} = options;
|
|
2036
|
+
const results = /* @__PURE__ */ new Map();
|
|
2037
|
+
const searchPromises = fields.map(async (field) => {
|
|
2038
|
+
let fieldResults;
|
|
2039
|
+
switch (field) {
|
|
2040
|
+
case "subject":
|
|
2041
|
+
fieldResults = await searchIndex.subjectIndex.searchAsync(query);
|
|
2042
|
+
break;
|
|
2043
|
+
case "body":
|
|
2044
|
+
fieldResults = await searchIndex.bodyIndex.searchAsync(query);
|
|
2045
|
+
break;
|
|
2046
|
+
case "from":
|
|
2047
|
+
fieldResults = await searchIndex.fromIndex.searchAsync(query);
|
|
2048
|
+
break;
|
|
2049
|
+
case "to":
|
|
2050
|
+
fieldResults = await searchIndex.toIndex.searchAsync(query);
|
|
2051
|
+
break;
|
|
2052
|
+
default:
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
const fieldBoost = boost[field] || 1;
|
|
2056
|
+
fieldResults.forEach((emailId) => {
|
|
2057
|
+
const currentScore = results.get(String(emailId)) || 0;
|
|
2058
|
+
results.set(String(emailId), currentScore + fieldBoost);
|
|
2059
|
+
});
|
|
2060
|
+
});
|
|
2061
|
+
await Promise.all(searchPromises);
|
|
2062
|
+
const emailResults = [];
|
|
2063
|
+
for (const [emailId, score] of results) {
|
|
2064
|
+
const email = esCache.esCache.get(emailId);
|
|
2065
|
+
if (email) {
|
|
2066
|
+
emailResults.push({ email, score });
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
emailResults.sort((a, b) => (b.score || 0) - (a.score || 0));
|
|
2070
|
+
return emailResults.slice(0, limit);
|
|
2071
|
+
} catch (error) {
|
|
2072
|
+
throw new Error("Email search failed", { cause: error });
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
var EmailServiceAPI = class {
|
|
2076
|
+
serviceId;
|
|
2077
|
+
templateId;
|
|
2078
|
+
publicKey;
|
|
2079
|
+
constructor(serviceId, templateId, publicKey) {
|
|
2080
|
+
this.serviceId = serviceId;
|
|
2081
|
+
this.templateId = templateId;
|
|
2082
|
+
this.publicKey = publicKey;
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* Sends an email to the server
|
|
2086
|
+
*
|
|
2087
|
+
* @param content - The email content (encrypted)
|
|
2088
|
+
* @param param - The email public parameters
|
|
2089
|
+
* @returns The server response
|
|
2090
|
+
*/
|
|
2091
|
+
async sendEmail(content, param) {
|
|
2092
|
+
try {
|
|
2093
|
+
const templateParams = {
|
|
2094
|
+
from_email: param.sender.email,
|
|
2095
|
+
from_name: param.sender.name,
|
|
2096
|
+
to_email: param.recipient.email,
|
|
2097
|
+
to_name: param.recipient.name,
|
|
2098
|
+
email_subject: param.subject,
|
|
2099
|
+
email_body: content,
|
|
2100
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2101
|
+
};
|
|
2102
|
+
await emailjs__default.default.send(this.serviceId, this.templateId, templateParams, this.publicKey);
|
|
2103
|
+
} catch (error) {
|
|
2104
|
+
throw new Error(`Failed to send an email ${error.message}`, { cause: error });
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Sends a hybridly encrypted email to a particular recipient recipient
|
|
2109
|
+
*
|
|
2110
|
+
* @param encryptedEmail - The hybridly encrypted email
|
|
2111
|
+
* @returns The server reply
|
|
2112
|
+
*/
|
|
2113
|
+
async sendHybridEmail(encryptedEmail) {
|
|
2114
|
+
try {
|
|
2115
|
+
if (encryptedEmail.recipientEmail !== encryptedEmail.params.recipient.email) {
|
|
2116
|
+
throw new Error("Email is encrypted for another recipient");
|
|
2117
|
+
}
|
|
2118
|
+
const body = hybridEncyptedEmailToBase64(encryptedEmail);
|
|
2119
|
+
await this.sendEmail(body, encryptedEmail.params);
|
|
2120
|
+
} catch (error) {
|
|
2121
|
+
throw new Error(`Failed to email to the recipient: ${error.message}`, { cause: error });
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Sends a password-protected email to a particular recipient
|
|
2126
|
+
*
|
|
2127
|
+
* @param protectedEmail - The password protected email
|
|
2128
|
+
* @param recipient - The email recipient
|
|
2129
|
+
* @returns The server reply
|
|
2130
|
+
*/
|
|
2131
|
+
async sendPwdProtectedEmail(protectedEmail) {
|
|
2132
|
+
try {
|
|
2133
|
+
const body = pwdProtectedEmailToBase64(protectedEmail);
|
|
2134
|
+
await this.sendEmail(body, protectedEmail.params);
|
|
2135
|
+
} catch (error) {
|
|
2136
|
+
throw new Error(`Failed to email to the recipient ${error.message}`, { cause: error });
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
};
|
|
2140
|
+
function getEmailServiceAPI(serviceId, templateId, publicKey) {
|
|
2141
|
+
return new EmailServiceAPI(serviceId, templateId, publicKey);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// src/types.ts
|
|
2145
|
+
var KeystoreType = /* @__PURE__ */ ((KeystoreType2) => {
|
|
2146
|
+
KeystoreType2["IDENTITY"] = "identity";
|
|
2147
|
+
KeystoreType2["ENCRYPTION"] = "encryption";
|
|
2148
|
+
KeystoreType2["RECOVERY"] = "recovery";
|
|
2149
|
+
KeystoreType2["INDEX"] = "index";
|
|
2150
|
+
return KeystoreType2;
|
|
2151
|
+
})(KeystoreType || {});
|
|
2152
|
+
|
|
2153
|
+
// src/storage-service/sessionStorageService.ts
|
|
2154
|
+
function get(key) {
|
|
2155
|
+
return sessionStorage.getItem(key);
|
|
2156
|
+
}
|
|
2157
|
+
function set(key, value) {
|
|
2158
|
+
return sessionStorage.setItem(key, value);
|
|
2159
|
+
}
|
|
2160
|
+
function removeItem(key) {
|
|
2161
|
+
sessionStorage.removeItem(key);
|
|
2162
|
+
}
|
|
2163
|
+
function exists(key) {
|
|
2164
|
+
return !!sessionStorage.getItem(key);
|
|
2165
|
+
}
|
|
2166
|
+
function clear() {
|
|
2167
|
+
sessionStorage.clear();
|
|
2168
|
+
}
|
|
2169
|
+
var sessionStorageService = {
|
|
2170
|
+
set,
|
|
2171
|
+
get,
|
|
2172
|
+
removeItem,
|
|
2173
|
+
exists,
|
|
2174
|
+
clear
|
|
2175
|
+
};
|
|
2176
|
+
var sessionStorageService_default = sessionStorageService;
|
|
2177
|
+
|
|
2178
|
+
// src/keystore-crypto/core.ts
|
|
2179
|
+
async function encryptKeystoreContent(secretKey, content, userID, tag) {
|
|
2180
|
+
try {
|
|
2181
|
+
const aux = userID + tag;
|
|
2182
|
+
const message = base64ToUint8Array(content);
|
|
2183
|
+
const result = await encryptSymmetrically(secretKey, message, aux);
|
|
2184
|
+
return result;
|
|
2185
|
+
} catch (error) {
|
|
2186
|
+
throw new Error("Failed to encrypt keystore content", { cause: error });
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
async function decryptKeystoreContent(secretKey, encryptedKeys, userID, tag) {
|
|
2190
|
+
try {
|
|
2191
|
+
const aux = userID + tag;
|
|
2192
|
+
const content = await decryptSymmetrically(secretKey, encryptedKeys, aux);
|
|
2193
|
+
const result = uint8ArrayToBase64(content);
|
|
2194
|
+
return result;
|
|
2195
|
+
} catch (error) {
|
|
2196
|
+
throw new Error("Failed to decrypt keystore content", { cause: error });
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
function getUserID() {
|
|
2200
|
+
try {
|
|
2201
|
+
const userID = sessionStorageService_default.get("userID");
|
|
2202
|
+
if (!userID) {
|
|
2203
|
+
throw new Error("No UserID");
|
|
2204
|
+
}
|
|
2205
|
+
return userID;
|
|
2206
|
+
} catch (error) {
|
|
2207
|
+
throw new Error("Failed to get UserID from session storage", { cause: error });
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
function getBaseKey() {
|
|
2211
|
+
try {
|
|
2212
|
+
const baseKeyBase64 = sessionStorageService_default.get("baseKey");
|
|
2213
|
+
if (!baseKeyBase64) {
|
|
2214
|
+
throw new Error("No base key");
|
|
2215
|
+
}
|
|
2216
|
+
return base64ToUint8Array(baseKeyBase64);
|
|
2217
|
+
} catch (error) {
|
|
2218
|
+
throw new Error("Failed to get base key from session storage", { cause: error });
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
async function deriveIdentityKeystoreKey(baseKey) {
|
|
2222
|
+
return deriveSymmetricCryptoKeyFromContext(CONTEXT_LOGIN, baseKey);
|
|
2223
|
+
}
|
|
2224
|
+
async function deriveRecoveryKey(recoveryCodes) {
|
|
2225
|
+
const recoveryCodesBuffer = await getBytesFromString(AES_KEY_BIT_LENGTH / 8, recoveryCodes);
|
|
2226
|
+
return deriveSymmetricCryptoKeyFromContext(CONTEXT_RECOVERY, recoveryCodesBuffer);
|
|
2227
|
+
}
|
|
2228
|
+
async function deriveEncryptionKeystoreKey(baseKey) {
|
|
2229
|
+
return deriveSymmetricCryptoKeyFromContext(CONTEXT_ENC_KEYSTORE, baseKey);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
// src/keystore-crypto/emailEncryptionKey.ts
|
|
2233
|
+
function generateRecoveryCodes() {
|
|
2234
|
+
return genMnemonic(AES_KEY_BIT_LENGTH);
|
|
2235
|
+
}
|
|
2236
|
+
async function generateEncryptionKeys() {
|
|
2237
|
+
try {
|
|
2238
|
+
const keyPair = await generateEccKeys();
|
|
2239
|
+
const keyPairKyber = generateKyberKeys();
|
|
2240
|
+
const result = {
|
|
2241
|
+
userPrivateKey: keyPair.privateKey,
|
|
2242
|
+
userPublicKey: keyPair.publicKey,
|
|
2243
|
+
userPublicKyberKey: keyPairKyber.publicKey,
|
|
2244
|
+
userPrivateKyberKey: keyPairKyber.secretKey
|
|
2245
|
+
};
|
|
2246
|
+
return result;
|
|
2247
|
+
} catch (error) {
|
|
2248
|
+
throw new Error("Failed to generate encryption keys", { cause: error });
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
async function createEncryptionAndRecoveryKeystores() {
|
|
2252
|
+
try {
|
|
2253
|
+
const userID = getUserID();
|
|
2254
|
+
const baseKey = getBaseKey();
|
|
2255
|
+
const keys = await generateEncryptionKeys();
|
|
2256
|
+
const content = await encryptionKeysToBase64(keys);
|
|
2257
|
+
const secretKey = await deriveEncryptionKeystoreKey(baseKey);
|
|
2258
|
+
const ciphertext = await encryptKeystoreContent(secretKey, content, userID, ENCRYPTION_KEYSTORE_TAG);
|
|
2259
|
+
const encryptionKeystore = {
|
|
2260
|
+
userID,
|
|
2261
|
+
type: "encryption" /* ENCRYPTION */,
|
|
2262
|
+
encryptedKeys: ciphertext
|
|
2263
|
+
};
|
|
2264
|
+
const recoveryCodes = generateRecoveryCodes();
|
|
2265
|
+
const recoveryKey = await deriveRecoveryKey(recoveryCodes);
|
|
2266
|
+
const encKeys = await encryptKeystoreContent(recoveryKey, content, userID, RECOVERY_KEYSTORE_TAG);
|
|
2267
|
+
const recoveryKeystore = {
|
|
2268
|
+
userID,
|
|
2269
|
+
type: "recovery" /* RECOVERY */,
|
|
2270
|
+
encryptedKeys: encKeys
|
|
2271
|
+
};
|
|
2272
|
+
return { encryptionKeystore, recoveryKeystore, recoveryCodes };
|
|
2273
|
+
} catch (error) {
|
|
2274
|
+
throw new Error("Failed to create encryption and recovery keystores", { cause: error });
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
async function openEncryptionKeystore(encryptedKeystore) {
|
|
2278
|
+
try {
|
|
2279
|
+
if (encryptedKeystore.type != "encryption" /* ENCRYPTION */) {
|
|
2280
|
+
throw new Error("Input is invalid");
|
|
2281
|
+
}
|
|
2282
|
+
const baseKey = getBaseKey();
|
|
2283
|
+
const secretKey = await deriveEncryptionKeystoreKey(baseKey);
|
|
2284
|
+
const json = await decryptKeystoreContent(
|
|
2285
|
+
secretKey,
|
|
2286
|
+
encryptedKeystore.encryptedKeys,
|
|
2287
|
+
encryptedKeystore.userID,
|
|
2288
|
+
ENCRYPTION_KEYSTORE_TAG
|
|
2289
|
+
);
|
|
2290
|
+
const keys = await base64ToEncryptionKeys(json);
|
|
2291
|
+
return keys;
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
throw new Error("Failed to open encryption keystore", { cause: error });
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
async function openRecoveryKeystore(recoveryCodes, encryptedKeystore) {
|
|
2297
|
+
try {
|
|
2298
|
+
if (encryptedKeystore.type != "recovery" /* RECOVERY */) {
|
|
2299
|
+
throw new Error("Input is invalid");
|
|
2300
|
+
}
|
|
2301
|
+
const recoveryKey = await deriveRecoveryKey(recoveryCodes);
|
|
2302
|
+
const json = await decryptKeystoreContent(
|
|
2303
|
+
recoveryKey,
|
|
2304
|
+
encryptedKeystore.encryptedKeys,
|
|
2305
|
+
encryptedKeystore.userID,
|
|
2306
|
+
RECOVERY_KEYSTORE_TAG
|
|
2307
|
+
);
|
|
2308
|
+
const keys = await base64ToEncryptionKeys(json);
|
|
2309
|
+
return keys;
|
|
2310
|
+
} catch (error) {
|
|
2311
|
+
throw new Error("Failed to open recovery keystore", { cause: error });
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
// src/keystore-crypto/userIdenityKey.ts
|
|
2316
|
+
async function generateIdentityKeys() {
|
|
2317
|
+
try {
|
|
2318
|
+
const keyPair = await generateEccKeys();
|
|
2319
|
+
const result = {
|
|
2320
|
+
userPrivateKey: keyPair.privateKey,
|
|
2321
|
+
userPublicKey: keyPair.publicKey
|
|
2322
|
+
};
|
|
2323
|
+
return result;
|
|
2324
|
+
} catch (error) {
|
|
2325
|
+
throw new Error("Failed to generate idenity keys", { cause: error });
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
async function createIdentityKeystore() {
|
|
2329
|
+
try {
|
|
2330
|
+
const type = "identity" /* IDENTITY */;
|
|
2331
|
+
const userID = getUserID();
|
|
2332
|
+
const baseKey = getBaseKey();
|
|
2333
|
+
const keys = await generateIdentityKeys();
|
|
2334
|
+
const content = await identityKeysToBase64(keys);
|
|
2335
|
+
const secretKey = await deriveIdentityKeystoreKey(baseKey);
|
|
2336
|
+
const encryptedKeys = await encryptKeystoreContent(secretKey, content, userID, IDENTITY_KEYSTORE_TAG);
|
|
2337
|
+
const result = {
|
|
2338
|
+
userID,
|
|
2339
|
+
type,
|
|
2340
|
+
encryptedKeys
|
|
2341
|
+
};
|
|
2342
|
+
return result;
|
|
2343
|
+
} catch (error) {
|
|
2344
|
+
throw new Error("Failed to create identity keystore", { cause: error });
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
async function openIdentityKeystore(encryptedKeystore) {
|
|
2348
|
+
try {
|
|
2349
|
+
if (encryptedKeystore.type != "identity" /* IDENTITY */) {
|
|
2350
|
+
throw new Error("Input is invalid");
|
|
2351
|
+
}
|
|
2352
|
+
const baseKey = getBaseKey();
|
|
2353
|
+
const secretKey = await deriveIdentityKeystoreKey(baseKey);
|
|
2354
|
+
const json = await decryptKeystoreContent(
|
|
2355
|
+
secretKey,
|
|
2356
|
+
encryptedKeystore.encryptedKeys,
|
|
2357
|
+
encryptedKeystore.userID,
|
|
2358
|
+
IDENTITY_KEYSTORE_TAG
|
|
2359
|
+
);
|
|
2360
|
+
const keys = await base64ToIdentityKeys(json);
|
|
2361
|
+
return keys;
|
|
2362
|
+
} catch (error) {
|
|
2363
|
+
throw new Error("Failed to open identity keystore", { cause: error });
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
var KeyServiceAPI = class {
|
|
2367
|
+
baseUrl;
|
|
2368
|
+
constructor(baseUrl) {
|
|
2369
|
+
this.baseUrl = baseUrl;
|
|
2370
|
+
}
|
|
2371
|
+
/**
|
|
2372
|
+
* Converts the specific client error into a proprietary error for our apps
|
|
2373
|
+
* @param error
|
|
2374
|
+
* @private
|
|
2375
|
+
*/
|
|
2376
|
+
normalizeError(error) {
|
|
2377
|
+
let errorMessage;
|
|
2378
|
+
if (error.response?.status === 401) {
|
|
2379
|
+
errorMessage = "Unauthorized: Invalid or expired token";
|
|
2380
|
+
} else if (error.response?.status === 403) {
|
|
2381
|
+
errorMessage = "Forbidden: Insufficient permissions";
|
|
2382
|
+
} else if (error.response?.status === 404) {
|
|
2383
|
+
errorMessage = "Keystore not found for the specified user";
|
|
2384
|
+
} else {
|
|
2385
|
+
errorMessage = "AxiosError:" + (error.message ?? "Unknown error");
|
|
2386
|
+
}
|
|
2387
|
+
throw new Error(errorMessage);
|
|
2388
|
+
}
|
|
2389
|
+
/**
|
|
2390
|
+
* Sends a user's encrypted keystore to the server
|
|
2391
|
+
* @param keystore - The encrypted keystore
|
|
2392
|
+
* @param url - The user specific part of the url
|
|
2393
|
+
* @returns Server response
|
|
2394
|
+
*/
|
|
2395
|
+
async sendEncryptedKeystoreToServer(encryptedKeystore, url) {
|
|
2396
|
+
try {
|
|
2397
|
+
const response = await axios__default.default.post(
|
|
2398
|
+
this.baseUrl + `${url}`,
|
|
2399
|
+
{ encryptedKeystore },
|
|
2400
|
+
{
|
|
2401
|
+
withCredentials: true,
|
|
2402
|
+
headers: {
|
|
2403
|
+
"Content-Type": "application/json"
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
);
|
|
2407
|
+
return response;
|
|
2408
|
+
} catch (error) {
|
|
2409
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
2410
|
+
this.normalizeError(error);
|
|
2411
|
+
}
|
|
2412
|
+
throw new Error("Failed to send keystore", { cause: error });
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* Requests a user's encrypted keystore from the server
|
|
2417
|
+
* @param url - The user-specific part of the url
|
|
2418
|
+
* @returns The user's encrypted keystore as base64 string
|
|
2419
|
+
*/
|
|
2420
|
+
async requestEncryptedKeystore(userID, keystoreType) {
|
|
2421
|
+
try {
|
|
2422
|
+
const url = `/downloadKeystore/${userID}/${keystoreType.toString()}`;
|
|
2423
|
+
const response = await axios__default.default.get(this.baseUrl + `${url}`, {
|
|
2424
|
+
withCredentials: true,
|
|
2425
|
+
headers: {
|
|
2426
|
+
"Content-Type": "application/json"
|
|
2427
|
+
}
|
|
2428
|
+
});
|
|
2429
|
+
return response.data;
|
|
2430
|
+
} catch (error) {
|
|
2431
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
2432
|
+
this.normalizeError(error);
|
|
2433
|
+
}
|
|
2434
|
+
throw new Error("Failed to retrive keystore", { cause: error });
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* Uploads encrypted keystore to the server
|
|
2439
|
+
*
|
|
2440
|
+
* @param encryptedKeystore - The encrypted keystore
|
|
2441
|
+
* @param type - The keystore's type
|
|
2442
|
+
* @returns Server response
|
|
2443
|
+
*/
|
|
2444
|
+
async uploadKeystoreToServer(encryptedKeystore) {
|
|
2445
|
+
try {
|
|
2446
|
+
const userID = getUserID();
|
|
2447
|
+
const keystoreType = encryptedKeystore.type;
|
|
2448
|
+
const url = `/uploadKeystore/${userID}/${keystoreType}`;
|
|
2449
|
+
const ciphertextBase64 = encryptedKeystoreToBase64(encryptedKeystore);
|
|
2450
|
+
const result = await this.sendEncryptedKeystoreToServer(ciphertextBase64, url);
|
|
2451
|
+
return result;
|
|
2452
|
+
} catch (error) {
|
|
2453
|
+
throw new Error("Failed to upload keystore to the server", { cause: error });
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Gets a user's encrypted keystore containing encryption keys from the server
|
|
2458
|
+
*
|
|
2459
|
+
* @returns Encrypted keystore containing encryption keys
|
|
2460
|
+
*/
|
|
2461
|
+
async getEncryptionKeystoreFromServer() {
|
|
2462
|
+
return this.getKeystoreFromServer("encryption" /* ENCRYPTION */);
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Gets a user's encrypted Identity Keystore from the server
|
|
2466
|
+
*
|
|
2467
|
+
* @returns Encrypted Identity Keystore
|
|
2468
|
+
*/
|
|
2469
|
+
async getIdentityKeystoreFromServer() {
|
|
2470
|
+
return this.getKeystoreFromServer("identity" /* IDENTITY */);
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Gets a user's encrypted Recovery Keystore from the server
|
|
2474
|
+
*
|
|
2475
|
+
* @returns Encrypted Recovery Keystore
|
|
2476
|
+
*/
|
|
2477
|
+
async getRecoveryKeystoreFromServer() {
|
|
2478
|
+
return this.getKeystoreFromServer("recovery" /* RECOVERY */);
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Gets a user's encrypted Index Keystore from the server
|
|
2482
|
+
*
|
|
2483
|
+
* @returns Encrypted Index Keytore
|
|
2484
|
+
*/
|
|
2485
|
+
async getIndexKeystoreFromServer() {
|
|
2486
|
+
return this.getKeystoreFromServer("index" /* INDEX */);
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* Gets a user's encrypted keystore from the server
|
|
2490
|
+
*
|
|
2491
|
+
* @param type - The requested keystore's type
|
|
2492
|
+
* @returns Encrypted Keytore
|
|
2493
|
+
*/
|
|
2494
|
+
async getKeystoreFromServer(type) {
|
|
2495
|
+
try {
|
|
2496
|
+
const userID = getUserID();
|
|
2497
|
+
const response = await this.requestEncryptedKeystore(userID, type);
|
|
2498
|
+
const result = base64ToEncryptedKeystore(response);
|
|
2499
|
+
return result;
|
|
2500
|
+
} catch (error) {
|
|
2501
|
+
throw new Error("Failed to retrieve keystore from the server", { cause: error });
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Obtains recipients public keys from the server
|
|
2506
|
+
*
|
|
2507
|
+
* @param emails - The recipients' emails
|
|
2508
|
+
* @returns The list of recipients' public keys
|
|
2509
|
+
*/
|
|
2510
|
+
async getRecipientsPublicKeysFromServer(emails) {
|
|
2511
|
+
try {
|
|
2512
|
+
const response = await axios__default.default.get("/api/getPublicKeys", {
|
|
2513
|
+
params: {
|
|
2514
|
+
emails
|
|
2515
|
+
},
|
|
2516
|
+
withCredentials: true,
|
|
2517
|
+
headers: {
|
|
2518
|
+
"Content-Type": "application/json"
|
|
2519
|
+
}
|
|
2520
|
+
});
|
|
2521
|
+
return response.data;
|
|
2522
|
+
} catch (error) {
|
|
2523
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
2524
|
+
this.normalizeError(error);
|
|
2525
|
+
}
|
|
2526
|
+
throw new Error("Failed to retrieve public keys", { cause: error });
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
/**
|
|
2530
|
+
* Obtains the recipient public keys from the server
|
|
2531
|
+
*
|
|
2532
|
+
* @param email - The recipients' emails
|
|
2533
|
+
* @returns The list of recipients' public keys
|
|
2534
|
+
*/
|
|
2535
|
+
async getRecipientsPublicKeys(emails) {
|
|
2536
|
+
try {
|
|
2537
|
+
const publicKeysBase64 = await this.getRecipientsPublicKeysFromServer(emails);
|
|
2538
|
+
const result = [];
|
|
2539
|
+
for (const keyBase64 of publicKeysBase64) {
|
|
2540
|
+
const publicKeys = await base64ToPublicKey(keyBase64);
|
|
2541
|
+
result.push(publicKeys);
|
|
2542
|
+
}
|
|
2543
|
+
return result;
|
|
2544
|
+
} catch (error) {
|
|
2545
|
+
throw new Error("Failed to get recipients public keys", { cause: error });
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
function getKeyServiceAPI(baseUrl) {
|
|
2550
|
+
return new KeyServiceAPI(baseUrl);
|
|
2551
|
+
}
|
|
2552
|
+
/*! Bundled license information:
|
|
2553
|
+
|
|
2554
|
+
hash-wasm/dist/index.esm.js:
|
|
2555
|
+
(*!
|
|
2556
|
+
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
|
|
2557
|
+
* (c) Dani Biro
|
|
2558
|
+
* @license MIT
|
|
2559
|
+
*)
|
|
2560
|
+
*/
|
|
2561
|
+
|
|
2562
|
+
exports.AES_ALGORITHM = AES_ALGORITHM;
|
|
2563
|
+
exports.AES_KEY_BIT_LENGTH = AES_KEY_BIT_LENGTH;
|
|
2564
|
+
exports.ARGON2ID_ITERATIONS = ARGON2ID_ITERATIONS;
|
|
2565
|
+
exports.ARGON2ID_MEMORY_SIZE = ARGON2ID_MEMORY_SIZE;
|
|
2566
|
+
exports.ARGON2ID_OUTPUT_BYTE_LENGTH = ARGON2ID_OUTPUT_BYTE_LENGTH;
|
|
2567
|
+
exports.ARGON2ID_PARALLELISM = ARGON2ID_PARALLELISM;
|
|
2568
|
+
exports.ARGON2ID_SALT_BYTE_LENGTH = ARGON2ID_SALT_BYTE_LENGTH;
|
|
2569
|
+
exports.AUX_LEN = AUX_LEN;
|
|
2570
|
+
exports.CONTEXT_DERIVE = CONTEXT_DERIVE;
|
|
2571
|
+
exports.CONTEXT_ENC_KEYSTORE = CONTEXT_ENC_KEYSTORE;
|
|
2572
|
+
exports.CONTEXT_INDEX = CONTEXT_INDEX;
|
|
2573
|
+
exports.CONTEXT_LOGIN = CONTEXT_LOGIN;
|
|
2574
|
+
exports.CONTEXT_RECOVERY = CONTEXT_RECOVERY;
|
|
2575
|
+
exports.CONTEXT_WRAPPING = CONTEXT_WRAPPING;
|
|
2576
|
+
exports.DB_LABEL = DB_LABEL;
|
|
2577
|
+
exports.DB_VERSION = DB_VERSION;
|
|
2578
|
+
exports.ECC_ALGORITHM = ECC_ALGORITHM;
|
|
2579
|
+
exports.ENCRYPTION_KEYSTORE_TAG = ENCRYPTION_KEYSTORE_TAG;
|
|
2580
|
+
exports.HASH_BIT_LEN = HASH_BIT_LEN;
|
|
2581
|
+
exports.IDENTITY_KEYSTORE_TAG = IDENTITY_KEYSTORE_TAG;
|
|
2582
|
+
exports.INDEX_KEYSTORE_TAG = INDEX_KEYSTORE_TAG;
|
|
2583
|
+
exports.IV_LEN_BYTES = IV_LEN_BYTES;
|
|
2584
|
+
exports.KEY_FORMAT = KEY_FORMAT;
|
|
2585
|
+
exports.KEY_WRAPPING_ALGORITHM = KEY_WRAPPING_ALGORITHM;
|
|
2586
|
+
exports.KYBER1024_PUBLIC_KEY_LENGTH = KYBER1024_PUBLIC_KEY_LENGTH;
|
|
2587
|
+
exports.KYBER1024_SECRET_KEY_LENGTH = KYBER1024_SECRET_KEY_LENGTH;
|
|
2588
|
+
exports.KYBER512_PUBLIC_KEY_LENGTH = KYBER512_PUBLIC_KEY_LENGTH;
|
|
2589
|
+
exports.KYBER512_SECRET_KEY_LENGTH = KYBER512_SECRET_KEY_LENGTH;
|
|
2590
|
+
exports.KYBER768_PUBLIC_KEY_LENGTH = KYBER768_PUBLIC_KEY_LENGTH;
|
|
2591
|
+
exports.KYBER768_SECRET_KEY_LENGTH = KYBER768_SECRET_KEY_LENGTH;
|
|
2592
|
+
exports.KYBER_SEED_LENGTH = KYBER_SEED_LENGTH;
|
|
2593
|
+
exports.KeystoreType = KeystoreType;
|
|
2594
|
+
exports.MAX_CACHE_SIZE = MAX_CACHE_SIZE;
|
|
2595
|
+
exports.MAX_EMAIL_PER_BATCH = MAX_EMAIL_PER_BATCH;
|
|
2596
|
+
exports.PREFIX_IDENTITY_KEY_COMMITMENT = PREFIX_IDENTITY_KEY_COMMITMENT;
|
|
2597
|
+
exports.PREFIX_MEDIA_KEY_COMMITMENT = PREFIX_MEDIA_KEY_COMMITMENT;
|
|
2598
|
+
exports.PREFIX_PUBLIC_KEY_COMMITMENT = PREFIX_PUBLIC_KEY_COMMITMENT;
|
|
2599
|
+
exports.RECOVERY_KEYSTORE_TAG = RECOVERY_KEYSTORE_TAG;
|
|
2600
|
+
exports.UTF8ToUint8 = UTF8ToUint8;
|
|
2601
|
+
exports.addEmailToCache = addEmailToCache;
|
|
2602
|
+
exports.addEmailToSearchIndex = addEmailToSearchIndex;
|
|
2603
|
+
exports.addEmailsToCache = addEmailsToCache;
|
|
2604
|
+
exports.base64ToCiphertext = base64ToCiphertext;
|
|
2605
|
+
exports.base64ToEncryptedKeystore = base64ToEncryptedKeystore;
|
|
2606
|
+
exports.base64ToEncryptionKeys = base64ToEncryptionKeys;
|
|
2607
|
+
exports.base64ToIdentityKeys = base64ToIdentityKeys;
|
|
2608
|
+
exports.base64ToMediaKeys = base64ToMediaKeys;
|
|
2609
|
+
exports.base64ToPublicKey = base64ToPublicKey;
|
|
2610
|
+
exports.base64ToUint8Array = base64ToUint8Array;
|
|
2611
|
+
exports.buildSearchIndexFromCache = buildSearchIndexFromCache;
|
|
2612
|
+
exports.ciphertextToBase64 = ciphertextToBase64;
|
|
2613
|
+
exports.closeDatabase = closeDatabase;
|
|
2614
|
+
exports.computeMac = computeMac;
|
|
2615
|
+
exports.createCacheFromDB = createCacheFromDB;
|
|
2616
|
+
exports.createEncryptionAndRecoveryKeystores = createEncryptionAndRecoveryKeystores;
|
|
2617
|
+
exports.createIdentityKeystore = createIdentityKeystore;
|
|
2618
|
+
exports.createPwdProtectedEmail = createPwdProtectedEmail;
|
|
2619
|
+
exports.createPwdProtectedEmailAndSubject = createPwdProtectedEmailAndSubject;
|
|
2620
|
+
exports.decapsulateKyber = decapsulateKyber;
|
|
2621
|
+
exports.decryptEmailAndSubjectHybrid = decryptEmailAndSubjectHybrid;
|
|
2622
|
+
exports.decryptEmailHybrid = decryptEmailHybrid;
|
|
2623
|
+
exports.decryptPwdProtectedEmail = decryptPwdProtectedEmail;
|
|
2624
|
+
exports.decryptPwdProtectedEmailAndSubject = decryptPwdProtectedEmailAndSubject;
|
|
2625
|
+
exports.decryptSymmetrically = decryptSymmetrically;
|
|
2626
|
+
exports.deleteEmail = deleteEmail;
|
|
2627
|
+
exports.deleteEmailFromCache = deleteEmailFromCache;
|
|
2628
|
+
exports.deleteOldestEmails = deleteOldestEmails;
|
|
2629
|
+
exports.deriveIndexKey = deriveIndexKey;
|
|
2630
|
+
exports.deriveSecretKey = deriveSecretKey;
|
|
2631
|
+
exports.deriveSymmetricCryptoKey = deriveSymmetricCryptoKey;
|
|
2632
|
+
exports.deriveSymmetricCryptoKeyFromContext = deriveSymmetricCryptoKeyFromContext;
|
|
2633
|
+
exports.deriveSymmetricCryptoKeyFromTwoKeys = deriveSymmetricCryptoKeyFromTwoKeys;
|
|
2634
|
+
exports.deriveSymmetricKeyFromContext = deriveSymmetricKeyFromContext;
|
|
2635
|
+
exports.deriveSymmetricKeyFromTwoKeys = deriveSymmetricKeyFromTwoKeys;
|
|
2636
|
+
exports.encapsulateKyber = encapsulateKyber;
|
|
2637
|
+
exports.encryptAndStoreEmail = encryptAndStoreEmail;
|
|
2638
|
+
exports.encryptAndStoreManyEmail = encryptAndStoreManyEmail;
|
|
2639
|
+
exports.encryptEmailAndSubjectHybrid = encryptEmailAndSubjectHybrid;
|
|
2640
|
+
exports.encryptEmailAndSubjectHybridForMultipleRecipients = encryptEmailAndSubjectHybridForMultipleRecipients;
|
|
2641
|
+
exports.encryptEmailHybrid = encryptEmailHybrid;
|
|
2642
|
+
exports.encryptEmailHybridForMultipleRecipients = encryptEmailHybridForMultipleRecipients;
|
|
2643
|
+
exports.encryptSymmetrically = encryptSymmetrically;
|
|
2644
|
+
exports.encryptedKeystoreToBase64 = encryptedKeystoreToBase64;
|
|
2645
|
+
exports.encryptionKeysToBase64 = encryptionKeysToBase64;
|
|
2646
|
+
exports.enforceMaxEmailNumber = enforceMaxEmailNumber;
|
|
2647
|
+
exports.exportPrivateKey = exportPrivateKey;
|
|
2648
|
+
exports.exportPublicKey = exportPublicKey;
|
|
2649
|
+
exports.exportSymmetricCryptoKey = exportSymmetricCryptoKey;
|
|
2650
|
+
exports.genMnemonic = genMnemonic;
|
|
2651
|
+
exports.genSymmetricCryptoKey = genSymmetricCryptoKey;
|
|
2652
|
+
exports.genSymmetricKey = genSymmetricKey;
|
|
2653
|
+
exports.generateEccKeys = generateEccKeys;
|
|
2654
|
+
exports.generateEmailID = generateEmailID;
|
|
2655
|
+
exports.generateEncryptionKeys = generateEncryptionKeys;
|
|
2656
|
+
exports.generateIdentityKeys = generateIdentityKeys;
|
|
2657
|
+
exports.generateKyberKeys = generateKyberKeys;
|
|
2658
|
+
exports.generateRecoveryCodes = generateRecoveryCodes;
|
|
2659
|
+
exports.getAllEmailsSortedNewestFirst = getAllEmailsSortedNewestFirst;
|
|
2660
|
+
exports.getAllEmailsSortedOldestFirst = getAllEmailsSortedOldestFirst;
|
|
2661
|
+
exports.getAndDecryptAllEmails = getAndDecryptAllEmails;
|
|
2662
|
+
exports.getAndDecryptEmail = getAndDecryptEmail;
|
|
2663
|
+
exports.getAux = getAux;
|
|
2664
|
+
exports.getAuxWithoutSubject = getAuxWithoutSubject;
|
|
2665
|
+
exports.getBytesFromData = getBytesFromData;
|
|
2666
|
+
exports.getBytesFromDataHex = getBytesFromDataHex;
|
|
2667
|
+
exports.getBytesFromString = getBytesFromString;
|
|
2668
|
+
exports.getEmailBatch = getEmailBatch;
|
|
2669
|
+
exports.getEmailCount = getEmailCount;
|
|
2670
|
+
exports.getEmailFromCache = getEmailFromCache;
|
|
2671
|
+
exports.getEmailServiceAPI = getEmailServiceAPI;
|
|
2672
|
+
exports.getKeyFromPassword = getKeyFromPassword;
|
|
2673
|
+
exports.getKeyFromPasswordAndSalt = getKeyFromPasswordAndSalt;
|
|
2674
|
+
exports.getKeyFromPasswordAndSaltHex = getKeyFromPasswordAndSaltHex;
|
|
2675
|
+
exports.getKeyFromPasswordHex = getKeyFromPasswordHex;
|
|
2676
|
+
exports.getKeyServiceAPI = getKeyServiceAPI;
|
|
2677
|
+
exports.hashData = hashData;
|
|
2678
|
+
exports.hexToUint8Array = hexToUint8Array;
|
|
2679
|
+
exports.identityKeysToBase64 = identityKeysToBase64;
|
|
2680
|
+
exports.importPrivateKey = importPrivateKey;
|
|
2681
|
+
exports.importPublicKey = importPublicKey;
|
|
2682
|
+
exports.importSymmetricCryptoKey = importSymmetricCryptoKey;
|
|
2683
|
+
exports.mediaKeysToBase64 = mediaKeysToBase64;
|
|
2684
|
+
exports.openDatabase = openDatabase;
|
|
2685
|
+
exports.openEncryptionKeystore = openEncryptionKeystore;
|
|
2686
|
+
exports.openIdentityKeystore = openIdentityKeystore;
|
|
2687
|
+
exports.openRecoveryKeystore = openRecoveryKeystore;
|
|
2688
|
+
exports.publicKeyToBase64 = publicKeyToBase64;
|
|
2689
|
+
exports.removeEmailFromSearchIndex = removeEmailFromSearchIndex;
|
|
2690
|
+
exports.searchEmails = searchEmails;
|
|
2691
|
+
exports.uint8ArrayToBase64 = uint8ArrayToBase64;
|
|
2692
|
+
exports.uint8ArrayToHex = uint8ArrayToHex;
|
|
2693
|
+
exports.uint8ToUTF8 = uint8ToUTF8;
|
|
2694
|
+
exports.unwrapKey = unwrapKey;
|
|
2695
|
+
exports.verifyKeyFromPasswordHex = verifyKeyFromPasswordHex;
|
|
2696
|
+
exports.wrapKey = wrapKey;
|
|
2055
2697
|
//# sourceMappingURL=index.js.map
|
|
2698
|
+
//# sourceMappingURL=index.js.map
|