internxt-crypto 0.0.9-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/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 +2073 -8247
- 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 Me=require("hash-wasm"),qt=require("buffer"),Li=require("uuid");var xr=typeof document<"u"?document.currentScript:null;const ze="AES-GCM",G=256,Ks=128,_s=16,Wt="AES-KW",Ye="raw",Os="CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets",ft="X25519",Rs="CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore",Cs="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",Is="CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices",js="CRYPTO library 2025-08-27 17:08:00 derive one key from two keys",Pr="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",Bs=3,Ns=4,Ls=65536,Ms=16,Us=32,Qr="Identity keystore",en="Encryption keystore",tn="Key recovery keystroe",Di="Current encrypted indices",Hi=800,$i=1632,zi=1184,Yi=2400,Vi=1568,Ji=3168,Gi=64,dt=256,Ds=6e8,Ir=100,ee="email",Hs=1;async function rn(e,t){try{const r=await crypto.subtle.deriveBits({name:ft,public:e},t,G);return new Uint8Array(r)}catch(r){throw new Error("Failed to derive elliptic curve secret key",{cause:r})}}async function Zt(){try{return await crypto.subtle.generateKey({name:ft},!0,["deriveBits"])}catch(e){throw new Error("Failed to generate elliptic curve key pair",{cause:e})}}async function Qt(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 er(e){try{return await crypto.subtle.importKey("spki",e,{name:ft},!0,[])}catch(t){throw new Error("Failed to import public key",{cause:t})}}async function nn(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 sn(e){try{return await crypto.subtle.importKey("pkcs8",e,{name:ft},!0,["deriveBits"])}catch(t){throw new Error("Failed to import private key",{cause:t})}}const Xi=Object.freeze(Object.defineProperty({__proto__:null,deriveSecretKey:rn,exportPrivateKey:nn,exportPublicKey:Qt,generateEccKeys:Zt,importPrivateKey:sn,importPublicKey:er},Symbol.toStringTag,{value:"Module"}));function nt(e){return qt.Buffer.from(e).toString("hex")}function tr(e){return new TextEncoder().encode(e)}function on(e){return new TextDecoder().decode(e)}function Bt(e){return new Uint8Array(qt.Buffer.from(e,"hex"))}function H(e){return qt.Buffer.from(e).toString("base64")}function D(e){return new Uint8Array(qt.Buffer.from(e,"base64"))}function Ce(e){try{const t=H(e.iv),r=H(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 rr(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 Qt(e.userPublicKey),r=await nn(e.userPrivateKey),n=JSON.stringify({userPublicKey:H(t),userPrivateKey:H(r)});return btoa(n)}catch(t){throw new Error("Failed to convert identity keys to base64",{cause:t})}}async function zs(e){try{const t=await Qt(e.userPublicKey),r=await nn(e.userPrivateKey),n=JSON.stringify({userPublicKey:H(t),userPrivateKey:H(r),userPublicKyberKey:H(e.userPublicKyberKey),userPrivateKyberKey:H(e.userPrivateKyberKey)});return btoa(n)}catch(t){throw new Error("Failed to convert identity keys to base64",{cause:t})}}function Ys(e){try{const t=Ce(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 Vs(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.userPublicKey),s=D(r.userPrivateKey),o=await er(n),i=await sn(s);return{userPublicKey:o,userPrivateKey:i}}catch(t){throw new Error("Failed convert base64 to idenity key",{cause:t})}}async function cn(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.userPublicKey),s=D(r.userPrivateKey),o=await er(n),i=await sn(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 Js(e){try{const t=atob(e),r=JSON.parse(t),n=rr(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 Gs(e){try{const t=JSON.stringify({olmKey:H(e.olmKey),pqKey:H(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 qi(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})}}async function Xs(e){try{const t=atob(e),r=JSON.parse(t),n=D(r.eccPublicKey),s=await er(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 Wi(e){try{const t=await Qt(e.eccPublicKey),r=JSON.stringify({eccPublicKey:H(t),kyberPublicKey:H(e.kyberPublicKey)});return btoa(r)}catch(t){throw new Error("Failed to convert key of the type PublicKeys to base64",{cause:t})}}const je=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 jr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function _e(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 Nt(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){_e(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 st(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ce(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 Un=Qi?e=>e:tc,rc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ue={_0:48,_9:57,A:65,F:70,a:97,f:102};function Dn(e){if(e>=ue._0&&e<=ue._9)return e-ue._0;if(e>=ue.A&&e<=ue.F)return e-(ue.A-10);if(e>=ue.a&&e<=ue.f)return e-(ue.a-10)}function Z(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=Dn(e.charCodeAt(o)),c=Dn(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 nr(e){return typeof e=="string"&&(e=nc(e)),_e(e),e}class Zs{}function Qs(e){const t=n=>e().update(nr(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(nr(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}function eo(e=32){if(je&&typeof je.getRandomValues=="function")return je.getRandomValues(new Uint8Array(e));if(je&&typeof je.randomBytes=="function")return Uint8Array.from(je.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=kr(this.buffer)}update(t){Nt(this),t=nr(t),_e(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=kr(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){Nt(this),qs(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:s,isLE:o}=this;let{pos:i}=this;r[i++]=128,st(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=kr(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 ye=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Et=BigInt(2**32-1),Hn=BigInt(32);function lc(e,t=!1){return t?{h:Number(e&Et),l:Number(e>>Hn&Et)}:{h:Number(e>>Hn&Et)|0,l:Number(e&Et)|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]),me=new Uint32Array(64);class mc extends ac{constructor(t=32){super(64,t,8,!1),this.A=ye[0]|0,this.B=ye[1]|0,this.C=ye[2]|0,this.D=ye[3]|0,this.E=ye[4]|0,this.F=ye[5]|0,this.G=ye[6]|0,this.H=ye[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)me[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){const m=me[h-15],y=me[h-2],p=ce(m,7)^ce(m,18)^m>>>3,f=ce(y,17)^ce(y,19)^y>>>10;me[h]=f+me[h-7]+p+me[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=ce(c,6)^ce(c,11)^ce(c,25),y=u+m+ic(c,a,l)+yc[h]+me[h]|0,f=(ce(n,2)^ce(n,13)^ce(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(){st(me)}destroy(){this.set(0,0,0,0,0,0,0,0),st(this.buffer)}}const gc=Qs(()=>new mc);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Lt(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 Mt(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Ve(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Ut(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=>(Ut(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=>(Ut(s),s.map(o=>{Mt("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 Mt("join",e),{encode:t=>(Dt("join.decode",t),t.join(e)),decode:t=>(Mt("join.decode",t),t.split(e))}}function kc(e,t="="){return Ve(e),Mt("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 Fr(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(Ut(e),!e.length)return[];let n=0;const s=[],o=Array.from(e,c=>{if(Ve(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),Ht=(e,t)=>e+(t-no(e,t)),vr=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Br(e,t,r,n){if(Ut(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(Ht(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${Ht(t,r)}`);let s=0,o=0;const i=vr[t],c=vr[r]-1,a=[];for(const l of e){if(Ve(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=vr[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){Ve(e);const t=2**8;return{encode:r=>{if(!Lt(r))throw new Error("radix.encode input should be Uint8Array");return Fr(Array.from(r),t,e)},decode:r=>(ro("radix.decode",r),Uint8Array.from(Fr(r,e,t)))}}function Sc(e,t=!1){if(Ve(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Ht(8,e)>32||Ht(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Lt(r))throw new Error("radix2.encode input should be Uint8Array");return Br(Array.from(r),8,e,!t)},decode:r=>(ro("radix2.decode",r),Uint8Array.from(Br(r,e,8,t)))}}function Tc(e,t){return Ve(e),wc(t),{encode(r){if(!Lt(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(!Lt(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 xt={alphabet:Ec,chain:bc,checksum:Tc,convertRadix:Fr,convertRadix2:Br,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 Kc(e){_e(e,16,20,24,28,32)}function _c(e,t=128){if(jr(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)}),xt.chain(xt.checksum(1,Oc),xt.radix2(11,!0),xt.alphabet(e))}function Cc(e,t){return Kc(e),Rc(t).encode(e).join(Ac(t)?" ":" ")}const Pc=`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 _c(Pc,e)}const Ic=Object.freeze(Object.defineProperty({__proto__:null,UTF8ToUint8:tr,base64ToCiphertext:rr,base64ToEncryptedKeystore:Js,base64ToEncryptionKeys:cn,base64ToIdentityKeys:Vs,base64ToMediaKeys:qi,base64ToPublicKey:Xs,base64ToUint8Array:D,ciphertextToBase64:Ce,encryptedKeystoreToBase64:Ys,encryptionKeysToBase64:zs,genMnemonic:so,hexToUint8Array:Bt,identityKeysToBase64:$s,mediaKeysToBase64:Gs,publicKeyToBase64:Wi,uint8ArrayToBase64:H,uint8ArrayToHex:nt,uint8ToUTF8:on},Symbol.toStringTag,{value:"Module"}));async function an(e,t){try{const r=await Me.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 Me.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 Fc(e){try{return(await an(dt,e)).digest()}catch(t){throw new Error("Failed to compute hash",{cause:t})}}async function oo(e,t){try{return(await an(e,t)).digest("binary")}catch(r){throw new Error("Failed to get bits from data",{cause:r})}}async function Je(e,t){try{return(await an(e,[t])).digest("binary")}catch(r){throw new Error("Failed to get bits from string",{cause:r})}}async function Bc(e){try{const t=Gs(e),r=await oo(dt,[Fs,t]);return nt(r)}catch(t){throw new Error("Failed to compute commitment to media keys",{cause:t})}}async function Nc(e,t){try{const r=await Je(G,e);return(await jc(dt,r,t)).digest()}catch(r){throw new Error("Failed to compute mac",{cause:r})}}const Lc=Object.freeze(Object.defineProperty({__proto__:null,comitToMediaKey:Bc,computeMac:Nc,getBitsFromData:oo,getBitsFromString:Je,hashData:Fc},Symbol.toStringTag,{value:"Module"}));async function sr(e){return crypto.subtle.importKey(Ye,new Uint8Array(e),{name:ze,length:G},!0,["encrypt","decrypt"])}async function Mc(e){try{const t=await crypto.subtle.exportKey(Ye,e);return new Uint8Array(t)}catch(t){throw new Error("Failed to export symmetric CryptoKey",{cause:t})}}async function ln(){return crypto.subtle.generateKey({name:ze,length:G},!0,["encrypt","decrypt"])}function Uc(){try{const e=new Uint8Array(G/8);return crypto.getRandomValues(e),e}catch(e){throw new Error("Failed to generate symmetric key",{cause:e})}}async function Dc(e){try{const t=await Je(G,e);return sr(t)}catch(t){throw new Error("Failed to derive CryptoKey from the given key material",{cause:t})}}const Hc=BigInt(0),Ze=BigInt(1),$c=BigInt(2),zc=BigInt(7),Yc=BigInt(256),Vc=BigInt(113),io=[],co=[],ao=[];for(let e=0,t=Ze,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<<Ze^(t>>zc)*Vc)%Yc,t&$c&&(s^=Ze<<(Ze<<BigInt(o))-Ze);ao.push(s)}const lo=uc(ao,!0),Jc=lo[0],Gc=lo[1],$n=(e,t,r)=>r>32?dc(e,t,r):hc(e,t,r),zn=(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=$n(l,u,1)^r[c],m=zn(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=$n(s,o,c),l=zn(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]}st(r)}class or 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,jr(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(){Un(this.state32),Xc(this.state32,this.rounds),Un(this.state32),this.posOut=0,this.pos=0}update(t){Nt(this),t=nr(t),_e(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){Nt(this,!1),_e(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 jr(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,st(this.state)}_cloneInto(t){const{blockLen:r,suffix:n,outputLen:s,rounds:o,enableXOF:i}=this;return t||(t=new or(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 or(t,e,r)),qc=uo(6,136,256/8),Wc=uo(6,72,512/8),ho=(e,t,r)=>sc((n={})=>new or(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 fe=_e,$t=eo;function Yn(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 _t(...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]);fe(l,a),s.set(l,i),typeof c!="number"&&l.fill(0),i+=a}return s},decode:n=>{fe(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 Sr(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=>{fe(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 Te(...e){for(const t of e)if(Array.isArray(t))for(const r of t)r.fill(0);else t.fill(0)}function Vn(e){return(1<<e)-1}Z("0609608648016503040201"),Z("0609608648016503040202"),Z("0609608648016503040203"),Z("0609608648016503040204"),Z("0609608648016503040205"),Z("0609608648016503040206"),Z("0609608648016503040207"),Z("0609608648016503040208"),Z("0609608648016503040209"),Z("060960864801650304020A"),Z("060960864801650304020B"),Z("060960864801650304020C");async function Qc(e){try{if(!e)return $t(_s);const t=new Uint8Array(16),r=$t(12);t.set(r,0);const n=await Je(32,e);return t.set(n,12),t}catch(t){throw new Error("Failed to create IV",{cause:t})}}async function po(e){return Je(Ks,e)}async function ea(e,t,r,n){try{const s=await crypto.subtle.encrypt({name:ze,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:ze,iv:t,additionalData:n},r,e);return new Uint8Array(s)}catch(s){throw new Error("Failed to decrypt symmetrically",{cause:s})}}async function ir(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 ot(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:ot,deriveSymmetricCryptoKey:Dc,encryptSymmetrically:ir,exportSymmetricCryptoKey:Mc,genSymmetricCryptoKey:ln,genSymmetricKey:Uc,importSymmetricCryptoKey:sr},Symbol.toStringTag,{value:"Module"}));async function it(e,t){try{const r=await Me.blake3(e),n=Bt(r),s=await Me.blake3(t,G,n);return Bt(s)}catch(r){throw new Error("Failed to derive key from base key and context",{cause:r})}}async function pt(e,t){try{if(t.length!=G/8)throw new Error(`Base key length must be exactly ${G/8} bytes`);if(!e)throw new Error("Context is empry");const r=await it(e,t);return await sr(r)}catch(r){throw new Error("Failed to derive CryptoKey from base key and context",{cause:r})}}async function yo(e,t,r=Bs,n=Ns,s=Ls,o=Us){return Me.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!=G/8||e.length!=G/8)throw new Error(`Input key length must be exactly ${G/8} bytes`);const n=await Me.blake3(e,dt,t);return await it(r,n)}catch(n){throw new Error("Failed to derive symmetric key from two keys",{cause:n})}}async function un(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 hn(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 un(e);return{keyHex:nt(t),saltHex:nt(r)}}catch(t){throw new Error("Failed to derive key from password",{cause:t})}}async function go(e,t){try{const r=Bt(t),n=await hn(e,r);return nt(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,js)}async function ia(e,t){try{const r=await wo(e,t);return await sr(r)}catch(r){throw new Error("Failed to derive symmetric CryptoKey from two keys",{cause:r})}}async function ca(e){try{const t=await it(Pr,e.olmKey),r=await it(Pr,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:pt,deriveSymmetricCryptoKeyFromTwoKeys:ia,deriveSymmetricKeyFromContext:it,deriveSymmetricKeyFromTwoKeys:wo,getKeyFromPassword:un,getKeyFromPasswordAndSalt:hn,getKeyFromPasswordAndSaltHex:go,getKeyFromPasswordHex:sa,ratchetMediaKey:ca,verifyKeyFromPasswordHex:oa},Symbol.toStringTag,{value:"Module"}));function Ot(e){try{const t=JSON.stringify(e);return btoa(t)}catch(t){throw new Error("Failed to convert User to base64",{cause:t})}}function Rt(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 tr(t)}catch(t){throw new Error("Failed to convert EmailBody to Uint8Array",{cause:t})}}function fn(e){try{const t=on(e);return JSON.parse(t)}catch(t){throw new Error("Failed to convert Uint8Array to EmailBody",{cause:t})}}function Eo(e){try{const t=JSON.stringify({kyberCiphertext:H(e.kyberCiphertext),encryptedKey:H(e.encryptedKey)});return btoa(t)}catch(t){throw new Error("Failed to convert hybrid key to base64",{cause:t})}}function la(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 xo(e){try{const t=JSON.stringify({encryptedKey:H(e.encryptedKey),salt:H(e.salt)});return btoa(t)}catch(t){throw new Error("Failed to convert password-protected key to base64",{cause:t})}}function ua(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 ha(e){try{const t=JSON.stringify({...e,sender:Ot(e.sender),recipient:Ot(e.recipient),recipients:e.recipients?.map(Ot)});return btoa(t)}catch(t){throw new Error("Failed to convert email public parameters to base64",{cause:t})}}function fa(e){try{const t=atob(e),r=JSON.parse(t);return{...r,sender:Rt(r.sender),recipient:Rt(r.recipient),recipients:r.recipients?.map(Rt)}}catch(t){throw new Error("Failed to convert base64 to email params",{cause:t})}}function ko(e){try{const t=JSON.stringify({encryptedKey:Eo(e.encryptedKey),enc:Ce(e.enc),recipientEmail:e.recipientEmail});return btoa(t)}catch(t){throw new Error("Failed to convert hybrid email to base64",{cause:t})}}function vo(e){try{const t=JSON.stringify({encryptedKey:xo(e.encryptedKey),enc:Ce(e.enc)});return btoa(t)}catch(t){throw new Error("Failed to convert pwd protected email to base64",{cause:t})}}function So(e){try{const t=JSON.stringify(e);return tr(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 da(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 pa=e=>{const{newPoly:t,N:r,Q:n,F:s,ROOT_OF_UNITY:o,brvBits:i}=e,c=(f,d=n)=>{const w=f%d|0;return(w>=0?w|0:d+w|0)|0},a=(f,d=n)=>{const w=c(f,d)|0;return(w>d>>1?w-d|0:w)|0};function l(){const f=t(r);for(let d=0;d<r;d++){const w=da(d,i),b=BigInt(o)**BigInt(w)%BigInt(n);f[d]=Number(b)|0}return f}const u=l(),h=128,m=1;return{mod:c,smod:a,nttZetas:u,NTT:{encode:f=>{for(let d=1,w=128;w>m;w>>=1)for(let b=0;b<r;b+=2*w){const E=u[d++];for(let x=b;x<b+w;x++){const k=c(E*f[x+w]);f[x+w]=c(f[x]-k)|0,f[x]=c(f[x]+k)|0}}return f},decode:f=>{for(let d=h-1,w=1+m;w<h+m;w<<=1)for(let b=0;b<r;b+=2*w){const E=u[d--];for(let x=b;x<b+w;x++){const k=f[x];f[x]=c(k+f[x+w]),f[x+w]=c(E*(f[x+w]-k))}}for(let d=0;d<f.length;d++)f[d]=c(s*f[d]);return f}},bitsCoder:(f,d)=>{const w=Vn(f),b=f*(r/8);return{bytesLen:b,encode:E=>{const x=new Uint8Array(b);for(let k=0,S=0,v=0,T=0;k<E.length;k++)for(S|=(d.encode(E[k])&w)<<v,v+=f;v>=8;v-=8,S>>=8)x[T++]=S&Vn(v);return x},decode:E=>{const x=t(r);for(let k=0,S=0,v=0,T=0;k<E.length;k++)for(S|=E[k]<<v,v+=8;v>=f;v-=f,S>>=f)x[T++]=d.decode(S&w);return x}}}}},ya=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)}}},ma=ya(Zc);/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */const J=256,de=3329,ga=3303,wa=17,{mod:ct,nttZetas:ba,NTT:ke,bitsCoder:Ea}=pa({N:J,Q:de,F:ga,ROOT_OF_UNITY:wa,newPoly:e=>new Uint16Array(e),brvBits:7}),dn={512:{N:J,Q:de,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128},768:{N:J,Q:de,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192},1024:{N:J,Q:de,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256}},xa=e=>{if(e>=12)return{encode:r=>r,decode:r=>r};const t=2**(e-1);return{encode:r=>((r<<e)+de/2)/de,decode:r=>r*de+t>>>e}},Qe=e=>Ea(e,xa(e));function ve(e,t){for(let r=0;r<J;r++)e[r]=ct(e[r]+t[r])}function ka(e,t){for(let r=0;r<J;r++)e[r]=ct(e[r]-t[r])}function va(e,t,r,n,s){const o=ct(t*n*s+e*r),i=ct(e*n+t*r);return{c0:o,c1:i}}function kt(e,t){for(let r=0;r<J/2;r++){let n=ba[64+(r>>1)];r&1&&(n=-n);const{c0:s,c1:o}=va(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 Jn(e){const t=new Uint16Array(J);for(let r=0;r<J;){const n=e();if(n.length%3)throw new Error("SampleNTT: unaligned block");for(let s=0;r<J&&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<de&&(t[r++]=o),r<J&&i<de&&(t[r++]=i)}}return t}function et(e,t,r,n){const s=e(n*J/4,t,r),o=new Uint16Array(J),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++]=ct(h-u),u=0,c=0)}if(c)throw new Error(`sampleCBD: leftover bits: ${c}`);return o}const Sa=e=>{const{K:t,PRF:r,XOF:n,HASH512:s,ETA1:o,ETA2:i,du:c,dv:a}=e,l=Qe(1),u=Qe(a),h=Qe(c),m=_t(Sr(Qe(12),t),32),y=Sr(Qe(12),t),p=_t(Sr(h,t),u),f=_t(32,32);return{secretCoder:y,secretKeyLen:y.bytesLen,publicKeyLen:m.bytesLen,cipherTextLen:p.bytesLen,keygen:d=>{fe(d,32);const w=new Uint8Array(33);w.set(d),w[32]=t;const b=s(w),[E,x]=f.decode(b),k=[],S=[];for(let K=0;K<t;K++)k.push(ke.encode(et(r,x,K,o)));const v=n(E);for(let K=0;K<t;K++){const C=ke.encode(et(r,x,t+K,o));for(let O=0;O<t;O++){const P=Jn(v.get(O,K));ve(C,kt(P,k[O]))}S.push(C)}v.clean();const T={publicKey:m.encode([S,E]),secretKey:y.encode(k)};return Te(E,x,k,S,w,b),T},encrypt:(d,w,b)=>{const[E,x]=m.decode(d),k=[];for(let O=0;O<t;O++)k.push(ke.encode(et(r,b,O,o)));const S=n(x),v=new Uint16Array(J),T=[];for(let O=0;O<t;O++){const P=et(r,b,t+O,i),F=new Uint16Array(J);for(let I=0;I<t;I++){const B=Jn(S.get(O,I));ve(F,kt(B,k[I]))}ve(P,ke.decode(F)),T.push(P),ve(v,kt(E[O],k[O])),F.fill(0)}S.clean();const K=et(r,b,2*t,i);ve(K,ke.decode(v));const C=l.decode(w);return ve(C,K),Te(E,k,v,K),p.encode([T,C])},decrypt:(d,w)=>{const[b,E]=p.decode(d),x=y.decode(w),k=new Uint16Array(J);for(let S=0;S<t;S++)ve(k,kt(x[S],ke.encode(b[S])));return ka(E,ke.decode(k)),Te(k,x,b),l.encode(E)}}};function pn(e){const t=Sa(e),{HASH256:r,HASH512:n,KDF:s}=e,{secretCoder:o,cipherTextLen:i}=t,c=t.publicKeyLen,a=_t(t.secretKeyLen,t.publicKeyLen,32,32),l=a.bytesLen,u=32;return{publicKeyLen:c,msgLen:u,keygen:(h=$t(64))=>{fe(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 Te(y,p),{publicKey:m,secretKey:f}},encapsulate:(h,m=$t(32))=>{fe(h,c),fe(m,u);const y=h.subarray(0,384*e.K),p=o.encode(o.decode(y.slice()));if(!Yn(p,y))throw Te(p),new Error("ML-KEM.encapsulate: wrong publicKey modulus");Te(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)=>{fe(m,l),fe(h,i);const[y,p,f,d]=a.decode(m),w=t.decrypt(h,y),b=n.create().update(w).update(f).digest(),E=b.subarray(0,32),x=t.encrypt(p,w,b.subarray(32,64)),k=Yn(h,x),S=s.create({dkLen:32}).update(d).update(h).digest();return Te(w,x,k?S:E),k?E:S}}}function Ta(e,t,r){return fo.create({dkLen:e}).update(t).update(new Uint8Array([r])).digest()}const yn={HASH256:qc,HASH512:Wc,KDF:fo,XOF:ma,PRF:Ta},mn=pn({...yn,...dn[512]}),gn=pn({...yn,...dn[768]}),wn=pn({...yn,...dn[1024]});function bn(e){try{return gn.keygen(e)}catch(t){throw new Error("Failed to generate Kyber keys",{cause:t})}}function To(e){try{return gn.encapsulate(e)}catch(t){throw new Error("Failed to encapsulate",{cause:t})}}function Ao(e,t){try{return gn.decapsulate(e,t)}catch(r){throw new Error("Failed to decapsulate",{cause:r})}}function Aa(e){try{return mn.keygen(e)}catch(t){throw new Error("Failed to generate Kyber keys",{cause:t})}}function Ka(e){try{return mn.encapsulate(e)}catch(t){throw new Error("Failed to encapsulate",{cause:t})}}function _a(e,t){try{return mn.decapsulate(e,t)}catch(r){throw new Error("Failed to decapsulate",{cause:r})}}const Oa=Object.freeze(Object.defineProperty({__proto__:null,decapsulateKyber:_a,encapsulateKyber:Ka,generateKyberKeys:Aa},Symbol.toStringTag,{value:"Module"}));function Ra(e){try{return wn.keygen(e)}catch(t){throw new Error("Failed to generate Kyber keys",{cause:t})}}function Ca(e){try{return wn.encapsulate(e)}catch(t){throw new Error("Failed to encapsulate",{cause:t})}}function Pa(e,t){try{return wn.decapsulate(e,t)}catch(r){throw new Error("Failed to decapsulate",{cause:r})}}const Ia=Object.freeze(Object.defineProperty({__proto__:null,decapsulateKyber:Pa,encapsulateKyber:Ca,generateKyberKeys:Ra},Symbol.toStringTag,{value:"Module"})),ja=Object.freeze(Object.defineProperty({__proto__:null,decapsulateKyber:Ao,encapsulateKyber:To,generateKyberKeys:bn,kyber1024:Ia,kyber512:Oa},Symbol.toStringTag,{value:"Module"}));async function cr(e){try{return await crypto.subtle.importKey(Ye,e,Wt,!1,["wrapKey","unwrapKey"])}catch(t){throw new Error("Failed to import wrapping key",{cause:t})}}async function En(e,t){try{if(e.length!==t.length)throw new Error("secrets must have equal length");const r=await mo(e,t,Os);return await cr(r)}catch(r){throw new Error("Failed to derive wrapping key",{cause:r})}}async function xn(e,t){try{return await crypto.subtle.unwrapKey(Ye,e,t,Wt,ze,!1,["encrypt","decrypt"])}catch(r){throw new Error("Failed to unwrap key",{cause:r})}}async function kn(e,t){try{const r=await crypto.subtle.wrapKey(Ye,e,t,Wt);return new Uint8Array(r)}catch(r){throw new Error("Failed to wrap key",{cause:r})}}const Fa=Object.freeze(Object.defineProperty({__proto__:null,deriveWrappingKey:En,importWrappingKey:cr,unwrapKey:xn,wrapKey:kn},Symbol.toStringTag,{value:"Module"}));async function vn(e,t,r){try{const n=await ln();return{enc:await ar(e,n,t,r),encryptionKey:n}}catch(n){throw new Error("Failed to symmetrically encrypt email",{cause:n})}}async function Sn(e,t,r,n){try{const s=await ln(),o=await ar(e,s,r,n),i=tr(t),c=await ir(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 ot(r,e,n),o=await ot(r,t,n);return{body:fn(s),subject:on(o)}}catch(s){throw new Error("Failed to symmetrically decrypt email and subject",{cause:s})}}async function ar(e,t,r,n){try{const s=bo(e);return await ir(t,s,r,n)}catch(s){throw new Error("Failed to symmetrically encrypt email with the given key",{cause:s})}}async function lr(e,t,r){try{const n=await ot(t,e,r);return fn(n)}catch(n){throw new Error("Failed to symmetrically decrypt email",{cause:n})}}async function ur(e,t,r){try{const n=await rn(t.eccPublicKey,r.eccPrivateKey),{cipherText:s,sharedSecret:o}=To(t.kyberPublicKey),i=await En(n,o);return{encryptedKey:await kn(e,i),kyberCiphertext:s}}catch(n){throw new Error("Failed to encrypt email key using hybrid encryption",{cause:n})}}async function _o(e,t,r){try{const n=await rn(t.eccPublicKey,r.eccPrivateKey),s=Ao(e.kyberCiphertext,r.kyberPrivateKey),o=await En(n,s);return await xn(e.encryptedKey,o)}catch(n){throw new Error("Failed to decrypt email key encrypted via hybrid encryption",{cause:n})}}async function Oo(e,t){try{const{key:r,salt:n}=await un(t),s=await cr(r);return{encryptedKey:await kn(e,s),salt:n}}catch(r){throw new Error("Failed to password-protect email key",{cause:r})}}async function Ro(e,t){try{const r=await hn(t,e.salt),n=await cr(r);return await xn(e.encryptedKey,n)}catch(r){throw new Error("Failed to remove password-protection from email key",{cause:r})}}function le(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 Ge(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 Ba(){return Li.v4()}async function Na(e,t,r){try{const n=le(e.params),{enc:s,encryptionKey:o}=await vn(e.body,n,e.id),i=await ur(o,t.publicKeys,r);return{enc:s,encryptedKey:i,recipientEmail:t.email,params:e.params,id:e.id}}catch(n){throw new Error("Failed to encrypt email with hybrid encryption",{cause:n})}}async function La(e,t,r){try{const n=le(e.params),{enc:s,encryptionKey:o}=await vn(e.body,n,e.id),i=[];for(const c of t){const a=await ur(o,c.publicKeys,r);i.push({enc:s,encryptedKey:a,recipientEmail:c.email,params:e.params,id:e.id})}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=le(e.params),s=await _o(e.encryptedKey,t,r);return{body:await lr(e.enc,s,n),params:e.params,id:e.id}}catch(n){throw new Error("Failed to decrypt email with hybrid encryption",{cause:n})}}async function Ua(e,t,r){try{const n=Ge(e.params),{enc:s,encryptionKey:o,subjectEnc:i}=await Sn(e.body,e.params.subject,n,e.id),c=Ce(i),a=await ur(o,t.publicKeys,r),l={...e.params,subject:c};return{enc:s,encryptedKey:a,recipientEmail:t.email,params:l,id:e.id}}catch(n){throw new Error("Failed to encrypt the email and its subject with hybrid encryption",{cause:n})}}async function Da(e,t,r){try{const n=Ge(e.params),{enc:s,encryptionKey:o,subjectEnc:i}=await Sn(e.body,e.params.subject,n,e.id),c=Ce(i),a=[];for(const l of t){const u=await ur(o,l.publicKeys,r),h={...e.params,subject:c};a.push({enc:s,encryptedKey:u,recipientEmail:l.email,params:h,id:e.id})}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 Ha(e,t,r){try{const n=Ge(e.params),s=await _o(e.encryptedKey,t,r),o=rr(e.params.subject),{body:i,subject:c}=await Ko(e.enc,o,s,n),a={...e.params,subject:c};return{body:i,params:a,id:e.id}}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=le(e.params),{enc:n,encryptionKey:s}=await vn(e.body,r,e.id),o=await Oo(s,t);return{enc:n,encryptedKey:o,params:e.params,id:e.id}}catch(r){throw new Error("Failed to password-protect email",{cause:r})}}async function za(e,t){try{const r=le(e.params),n=await Ro(e.encryptedKey,t);return{body:await lr(e.enc,n,r),params:e.params,id:e.id}}catch(r){throw new Error("Failed to decrypt password-protect email",{cause:r})}}async function Ya(e,t){try{if(!e?.body||!e.params)throw new Error("Failed to password-protect email and subject: Invalid email structure");const r=Ge(e.params),{enc:n,encryptionKey:s,subjectEnc:o}=await Sn(e.body,e.params.subject,r,e.id),i=await Oo(s,t),c=Ce(o),a={...e.params,subject:c};return{enc:n,encryptedKey:i,params:a,id:e.id}}catch(r){throw new Error("Failed to password-protect email and subject",{cause:r})}}async function Va(e,t){try{const r=Ge(e.params),n=await Ro(e.encryptedKey,t),s=rr(e.params.subject),{body:o,subject:i}=await Ko(e.enc,s,n,r),c={...e.params,subject:i};return{body:o,params:c,id:e.id}}catch(r){throw new Error("Failed to decrypt password-protect email",{cause:r})}}async function Ja(){try{const e=bn(),t=await Zt(),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 Ga=Object.freeze(Object.defineProperty({__proto__:null,base64ToEncHybridKey:la,base64ToParams:fa,base64ToPwdProtectedKey:ua,base64ToUser:Rt,binaryToEmailBody:fn,createPwdProtectedEmail:$a,createPwdProtectedEmailAndSubject:Ya,decryptEmailAndSubjectHybrid:Ha,decryptEmailHybrid:Ma,decryptPwdProtectedEmail:za,decryptPwdProtectedEmailAndSubject:Va,emailBodyToBinary:bo,emailToBinary:So,encHybridKeyToBase64:Eo,encryptEmailAndSubjectHybrid:Ua,encryptEmailAndSubjectHybridForMultipleRecipients:Da,encryptEmailHybrid:Na,encryptEmailHybridForMultipleRecipients:La,generateEmailID:Ba,generateEmailKeys:Ja,getAux:le,getAuxWithoutSubject:Ge,hybridEncyptedEmailToBase64:ko,paramsToBase64:ha,pwdProtectedEmailToBase64:vo,pwdProtectedKeyToBase64:xo,userToBase64:Ot},Symbol.toStringTag,{value:"Module"})),Nr=(e,t)=>t.some(r=>e instanceof r);let Gn,Xn;function Xa(){return Gn||(Gn=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function qa(){return Xn||(Xn=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Lr=new WeakMap,Tr=new WeakMap,hr=new WeakMap;function Wa(e){const t=new Promise((r,n)=>{const s=()=>{e.removeEventListener("success",o),e.removeEventListener("error",i)},o=()=>{r(we(e.result)),s()},i=()=>{n(e.error),s()};e.addEventListener("success",o),e.addEventListener("error",i)});return hr.set(t,e),t}function Za(e){if(Lr.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)});Lr.set(e,t)}let Mr={get(e,t,r){if(e instanceof IDBTransaction){if(t==="done")return Lr.get(e);if(t==="store")return r.objectStoreNames[1]?void 0:r.objectStore(r.objectStoreNames[0])}return we(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 Co(e){Mr=e(Mr)}function Qa(e){return qa().includes(e)?function(...t){return e.apply(Ur(this),t),we(this.request)}:function(...t){return we(e.apply(Ur(this),t))}}function el(e){return typeof e=="function"?Qa(e):(e instanceof IDBTransaction&&Za(e),Nr(e,Xa())?new Proxy(e,Mr):e)}function we(e){if(e instanceof IDBRequest)return Wa(e);if(Tr.has(e))return Tr.get(e);const t=el(e);return t!==e&&(Tr.set(e,t),hr.set(t,e)),t}const Ur=e=>hr.get(e);function tl(e,t,{blocked:r,upgrade:n,blocking:s,terminated:o}={}){const i=indexedDB.open(e,t),c=we(i);return n&&i.addEventListener("upgradeneeded",a=>{n(we(i.result),a.oldVersion,a.newVersion,we(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 rl(e,{blocked:t}={}){const r=indexedDB.deleteDatabase(e);return t&&r.addEventListener("blocked",n=>t(n.oldVersion,n)),we(r).then(()=>{})}const nl=["get","getKey","getAll","getAllKeys","count"],sl=["put","add","delete","clear"],Ar=new Map;function qn(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(Ar.get(t))return Ar.get(t);const r=t.replace(/FromIndex$/,""),n=t!==r,s=sl.includes(r);if(!(r in(n?IDBIndex:IDBObjectStore).prototype)||!(s||nl.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 Ar.set(t,o),o}Co(e=>({...e,get:(t,r,n)=>qn(t,r)||e.get(t,r,n),has:(t,r)=>!!qn(t,r)||e.has(t,r)}));const ol=["continue","continuePrimaryKey","advance"],Wn={},Dr=new WeakMap,Po=new WeakMap,il={get(e,t){if(!ol.includes(t))return e[t];let r=Wn[t];return r||(r=Wn[t]=function(...n){Dr.set(this,Po.get(this)[t](...n))}),r}};async function*cl(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;t=t;const r=new Proxy(t,il);for(Po.set(r,t),hr.set(r,Ur(t));t;)yield r,t=await(Dr.get(r)||t.continue()),Dr.delete(r)}function Zn(e,t){return t===Symbol.asyncIterator&&Nr(e,[IDBIndex,IDBObjectStore,IDBCursor])||t==="iterate"&&Nr(e,[IDBIndex,IDBObjectStore])}Co(e=>({...e,get(t,r,n){return Zn(t,r)?cl:e.get(t,r,n)},has(t,r){return Zn(t,r)||e.has(t,r)}}));const Io=e=>`ES:${e}:DB`,al=async e=>{try{const t=Io(e);return tl(t,Hs,{upgrade(r){r.objectStoreNames.contains(ee)||r.createObjectStore(ee,{keyPath:"id"}).createIndex("byTime","params.createdAt")}})}catch(t){throw new Error(`Cannot open a database for the user ${e}`,{cause:t})}},ll=e=>e.close(),ul=async e=>{const t=Io(e);return rl(t)},hl=async e=>pt(Is,e),fl=async(e,t,r)=>{try{const n=le(e.params),o={content:await ar(e.body,t,n,e.id),params:e.params,id:e.id};await r.put(ee,o)}catch(n){throw new Error("Cannot encrypt and add the given email to the database",{cause:n})}},dl=async(e,t,r)=>{try{const n=await Promise.all(e.map(async o=>{const i=le(o.params);return{content:await ar(o.body,t,i,o.id),params:o.params,id:o.id}})),s=r.transaction(ee,"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})}},Tn=async(e,t)=>{try{const r=le(t.params);return{body:await lr(t.content,e,r),params:t.params,id:t.id}}catch(r){throw new Error("Cannot decrypt the given email",{cause:r})}},pl=async(e,t,r)=>{try{const n=await r.get(ee,e);if(!n)throw new Error(`DB cannot find email with id ${e}`);return Tn(t,n)}catch(n){throw new Error(`Cannot fetch the email ${e} from the database`,{cause:n})}},yl=async(e,t)=>{try{const r=await t.getAll(ee);return(await Promise.all(r.map(async s=>{const o=le(s.params);return{body:await lr(s.content,e,o),params:s.params,id:s.id}}))).filter(s=>s!==null)}catch(r){throw new Error("Cannot fetch and decrypt all emails from the database",{cause:r})}},ml=async(e,t)=>{await t.delete(ee,e)},An=async e=>await e.count(ee),jo=async(e,t)=>{try{const r=t.transaction(ee,"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})}},gl=async(e,t)=>{try{const r=await An(e);if(r<=t)return;await jo(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(ee,"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=>Tn(t,a)))}catch(n){throw new Error("Cannot fetch emails from database",{cause:n})}},Bo=async(e,t)=>Fo(e,t,"prev"),wl=async(e,t)=>Fo(e,t,"next"),No=async(e,t,r,n)=>{try{const o=e.transaction(ee,"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=>Tn(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 Lo(e){return So(e).byteLength}function bl(){return{esCache:new Map,cacheSize:0,isCacheLimited:!1,isCacheReady:!0}}const El=async(e,t)=>{const r=bl();r.isCacheReady=!1;try{const n=await An(t);if(!n)return r.isCacheReady=!0,r;if(n<=Ir){const s=await Bo(t,e);Hr(s,r)}else{let s,o=!1;for(;!o;){const{emails:i,nextCursor:c}=await No(t,e,Ir,s);if(!c||!i.length)break;s=c,Hr(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},xl=async(e,t)=>{try{const r=await Mo(e,t),n=Lo(r);t.esCache.delete(e)&&(t.cacheSize-=n)}catch(r){throw new Error(`Failed to delete email with ID ${e}`,{cause:r})}};function Hr(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.id))return{success:!1,reason:"email already exists in cache"};const r=Lo(e);return t.cacheSize+r>Ds?(t.isCacheLimited=!0,{success:!1,reason:"hit cache limit"}):(t.esCache.set(e.id,e),t.cacheSize+=r,{success:!0})}catch(r){throw new Error("Failed to add email to the cache",{cause:r})}};var A;function $(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 Fe(e,t){return typeof e>"u"?t:e}function U(){return Object.create(null)}function re(e){return typeof e=="string"}function at(e){return typeof e=="object"}function lt(e,t){if(re(t))e=e[t];else for(let r=0;e&&r<t.length;r++)e=e[t[r]];return e}const kl=/[^\p{L}\p{N}]+/u,vl=/(\d{3})/g,Sl=/(\D)(\d{3})/g,Tl=/(\d{3})(\D)/g,Qn=/[\u0300-\u036f]/g;function ut(e={}){if(!this||this.constructor!==ut)return new ut(...arguments);if(arguments.length)for(e=0;e<arguments.length;e++)this.assign(arguments[e]);else this.assign(e)}A=ut.prototype;A.assign=function(e){this.normalize=$(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=$(e.numeric,n)}else{try{this.split=$(this.split,kl)}catch{this.split=/\s+/}this.numeric=$(e.numeric,$(this.numeric,!0))}if(this.prepare=$(e.prepare,null,this.prepare),this.finalize=$(e.finalize,null,this.finalize),r=e.filter,this.filter=typeof r=="function"?r:$(r&&new Set(r),null,this.filter),this.dedupe=$(e.dedupe,!0,this.dedupe),this.matcher=$((r=e.matcher)&&new Map(r),null,this.matcher),this.mapper=$((r=e.mapper)&&new Map(r),null,this.mapper),this.stemmer=$((r=e.stemmer)&&new Map(r),null,this.stemmer),this.replacer=$(e.replacer,null,this.replacer),this.minlength=$(e.minlength,1,this.minlength),this.maxlength=$(e.maxlength,1024,this.maxlength),this.rtl=$(e.rtl,!1,this.rtl),(this.cache=r=$(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&&Oe(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&&Oe(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&&Oe(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&&Oe(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&&Oe(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(Oe,50,this);this.normalize&&(typeof this.normalize=="function"?e=this.normalize(e):e=Qn?e.normalize("NFKD").replace(Qn,"").toLowerCase():e.toLowerCase()),this.prepare&&(e=this.prepare(e)),this.numeric&&e.length>3&&(e=e.replace(Sl,"$1 $2").replace(Tl,"$1 $2").replace(vl,"$1 "));const r=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let n=[],s=U(),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(Oe,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 Oe(e){e.F=null,e.B.clear(),e.D.clear()}function Kn(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 Pe);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 Pe(e){this.limit=e&&e!==!0?e:1e3,this.cache=new Map,this.h=""}Pe.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)};Pe.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};Pe.prototype.remove=function(e){for(const t of this.cache){const r=t[0];t[1].includes(e)&&this.cache.delete(r)}};Pe.prototype.clear=function(){this.cache.clear(),this.h=""};const es={normalize:!1,numeric:!1,dedupe:!1},vt={},Kr=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"]]),ts=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),rs=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"],ns={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 Do={Exact:es,Default:vt,Normalize:vt,LatinBalance:{mapper:Kr},LatinAdvanced:{mapper:Kr,matcher:ts,replacer:rs},LatinExtra:{mapper:Kr,replacer:rs.concat([/(?!^)[aeo]/g,""]),matcher:ts},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=ns[n];for(let o=1,i;o<t.length&&(i=t.charAt(o),i==="h"||i==="w"||!(i=ns[i])||i===s||(n+=i,s=i,n.length!==4));o++);e[r]=n}}},CJK:{split:""},LatinExact:es,LatinDefault:vt,LatinSimple:vt};function ss(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 Ue(e){if(!this||this.constructor!==Ue)return new Ue(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 ss(t,s||0,o||t.length,!1)};if(n==="splice")return function(s,o){return ss(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}})}Ue.prototype.clear=function(){this.index.length=0};Ue.prototype.push=function(){};function ne(e=8){if(!this||this.constructor!==ne)return new ne(e);this.index=U(),this.h=[],this.size=0,e>32?(this.B=$o,this.A=BigInt(e)):(this.B=Ho,this.A=e)}ne.prototype.get=function(e){const t=this.index[this.B(e)];return t&&t.get(e)};ne.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 se(e=8){if(!this||this.constructor!==se)return new se(e);this.index=U(),this.h=[],this.size=0,e>32?(this.B=$o,this.A=BigInt(e)):(this.B=Ho,this.A=e)}se.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=ne.prototype;A.has=se.prototype.has=function(e){const t=this.index[this.B(e)];return t&&t.has(e)};A.delete=se.prototype.delete=function(e){const t=this.index[this.B(e)];t&&t.delete(e)&&this.size--};A.clear=se.prototype.clear=function(){this.index=U(),this.h=[],this.size=0};A.values=se.prototype.values=function*(){for(let e=0;e<this.h.length;e++)for(let t of this.h[e].values())yield t};A.keys=se.prototype.keys=function*(){for(let e=0;e<this.h.length;e++)for(let t of this.h[e].keys())yield t};A.entries=se.prototype.entries=function*(){for(let e=0;e<this.h.length;e++)for(let t of this.h[e].entries())yield t};function Ho(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 Be,tt;async function Al(e){e=e.data;var t=e.task;const r=e.id;let n=e.args;switch(t){case"init":tt=e.options||{},(t=e.factory)?(Function("return "+t)()(self),Be=new self.FlexSearch.Index(tt),delete self.FlexSearch):Be=new oe(tt),postMessage({id:r});break;default:let s;t==="export"&&(n[1]?(n[0]=tt.export,n[2]=0,n[3]=1):n=null),t==="import"?n[0]&&(e=await tt.import.call(Be,n[0]),Be.import(n[0],e)):((s=n&&Be[t].apply(Be,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 _n(e){Ne.call(e,"add"),Ne.call(e,"append"),Ne.call(e,"search"),Ne.call(e,"update"),Ne.call(e,"remove"),Ne.call(e,"searchCache")}let $r,os,Ct;function Kl(){$r=Ct=0}function Ne(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]),$r?Ct||(Ct=Date.now()-os>=this.priority*this.priority*3):($r=setTimeout(Kl,0),os=Date.now()),Ct){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 ge=0;function De(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=U(),this.worker)return s?this.worker.on("message",a):this.worker.onmessage=a,e.config?new Promise(function(l){ge>1e9&&(ge=0),o.h[++ge]=function(){l(o)},o.worker.postMessage({id:ge,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!==De)return new De(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=_l(n,s,e.worker);return i.then?i.then(function(c){return r.call(o,c)}):r.call(this,i)}be("add");be("append");be("search");be("update");be("remove");be("clear");be("export");be("import");De.prototype.searchCache=Kn;_n(De.prototype);function be(e){De.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),ge>1e9&&(ge=0),t.h[++ge]=o,t.worker.postMessage({task:e,id:ge,args:r})}),s?(n.then(s),this):n}}function _l(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="+Al.toString()],{type:"text/javascript"}))):new window.Worker(typeof r=="string"?r:(typeof document>"u"?require("url").pathToFileURL(__filename).href:xr&&xr.tagName.toUpperCase()==="SCRIPT"&&xr.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"})}He.prototype.add=function(e,t,r){if(at(e)&&(t=e,e=lt(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]:re(a)&&(a=[a]),Yr(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=U();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=lt(t,o)}if(s&&o){re(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 Ue(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=U();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(re(l)||l.constructor===String){c[l]=t[l];continue}zr(t,c,l,0,l[0],u)}}this.store.set(e,c||t)}this.worker&&(this.fastupdate||this.reg.add(e))}return this};function zr(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++)zr(e,t,r,n,s);else t=t[s]||(t[s]=U()),s=r[++n],zr(e,t,r,n,s)}function Yr(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++)Yr(e,t,r,n,s,o,i,c);else i=t[++n],Yr(e,t,r,n,s,o,i,c)}function On(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?Le.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?Le.call(this,i):i;if(s.push(i),t-=c,!t)break}return s=s.length>1?[].concat.apply([],s):s[0],n?Le.call(this,s):s}function fr(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===N)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 w=s.field||s.pluck;if(w&&(!d||e.query&&!h||(e.query=d,e.field=w,e.highlight=h),f=f.index.get(w)),y&&(m||e.await)){m=1;let b;const E=e.C.length,x=new Promise(function(k){b=k});(function(k,S){x.h=function(){S.index=null,S.resolve=!1;let v=p?k.searchAsync(S):k.search(S);return v.then?v.then(function(T){return e.C[E]=T=T.result||T,b(T),T}):(v=v.result||v,b(v),v)}})(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=St(s,"and",f);else if(s.or)y=St(s,"or",f);else if(s.not)y=St(s,"not",f);else if(s.xor)y=St(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}Rn(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 St(e,t,r){e=e[t];const n=e[0]||e;return n.index||(n.index=r),r=new N(n),e.length>1&&(r=r[t].apply(r,e.slice(1))),r}N.prototype.or=function(){return fr(this,"or",Ol,arguments)};function Ol(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=zo(e,t,r,!1,this.h),r=0)),s&&(this.await=null),s?this.resolve(t,r,n,i):this}N.prototype.and=function(){return fr(this,"and",Rl,arguments)};function Rl(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=zt(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}N.prototype.xor=function(){return fr(this,"xor",Cl,arguments)};function Cl(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=U();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,w;d<m.length;d++)if(w=m[d],l[w]===1)if(o)o--;else if(s){if(a.push(w),a.length===t){e=a;break e}}else{const b=h+(p?c:0);if(a[b]||(a[b]=[]),a[b].push(w),++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}N.prototype.not=function(){return fr(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 Pt(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 Ie=0,Y,We,xe;Ie<t.length;Ie++){let X;if(n)X=t,xe=n;else{var f=t[Ie];if(xe=f.field,!xe)continue;X=f.result}We=r.get(xe),Y=We.encoder,f=h.get(Y),typeof f!="string"&&(f=Y.encode(e),h.set(Y,f));for(let te=0;te<X.length;te++){var d=X[te].doc;if(!d||(d=lt(d,xe),!d))continue;var w=d.trim().split(/\s+/);if(!w.length)continue;d="";var b=[];let pe=[];for(var E=-1,x=-1,k=0,S=0;S<w.length;S++){var v=w[S],T=Y.encode(v);T=T.length>1?T.join(" "):T[0];let _;if(T&&v){for(var K=v.length,C=(Y.split?v.replace(Y.split,""):v).length-T.length,O="",P=0,F=0;F<f.length;F++){var I=f[F];if(I){var B=I.length;B+=C<0?0:C,P&&B<=P||(I=T.indexOf(I),I>-1&&(O=(I?v.substring(0,I):"")+i+v.substring(I,I+B)+c+(I+B<K?v.substring(I+B):""),P=B,_=!0))}}O&&(a&&(E<0&&(E=d.length+(d?1:0)),x=d.length+(d?1:0)+O.length,k+=K,pe.push(b.length),b.push({match:O})),d+=(d?" ":"")+O)}if(!_)v=w[S],d+=(d?" ":"")+v,a&&b.push({text:v});else if(a&&k>=a)break}if(k=pe.length*(o.length-2),y||p||a&&d.length-k>a)if(k=a+k-m*2,S=x-E,y>0&&(S+=y),p>0&&(S+=p),S<=k)w=y?E-(y>0?y:0):E-((k-S)/2|0),b=p?x+(p>0?p:0):w+k,l||(w>0&&d.charAt(w)!==" "&&d.charAt(w-1)!==" "&&(w=d.indexOf(" ",w),w<0&&(w=0)),b<d.length&&d.charAt(b-1)!==" "&&d.charAt(b)!==" "&&(b=d.lastIndexOf(" ",b),b<x?b=x:++b)),d=(w?s:"")+d.substring(w,b)+(b<d.length?s:"");else{for(x=[],E={},k={},S={},v={},T={},O=C=K=0,F=P=1;;){var M=void 0;for(let _=0,L;_<pe.length;_++){if(L=pe[_],O)if(C!==O){if(S[_+1])continue;if(L+=O,E[L]){K-=m,k[_+1]=1,S[_+1]=1;continue}if(L>=b.length-1){if(L>=b.length){S[_+1]=1,L>=w.length&&(k[_+1]=1);continue}K-=m}if(d=b[L].text,B=p&&T[_])if(B>0){if(d.length>B)if(S[_+1]=1,l)d=d.substring(0,B);else continue;(B-=d.length)||(B=-1),T[_]=B}else{S[_+1]=1;continue}if(K+d.length+1<=a)d=" "+d,x[_]+=d;else if(l)M=a-K-1,M>0&&(d=" "+d.substring(0,M),x[_]+=d),S[_+1]=1;else{S[_+1]=1;continue}}else{if(S[_])continue;if(L-=C,E[L]){K-=m,S[_]=1,k[_]=1;continue}if(L<=0){if(L<0){S[_]=1,k[_]=1;continue}K-=m}if(d=b[L].text,B=y&&v[_])if(B>0){if(d.length>B)if(S[_]=1,l)d=d.substring(d.length-B);else continue;(B-=d.length)||(B=-1),v[_]=B}else{S[_]=1;continue}if(K+d.length+1<=a)d+=" ",x[_]=d+x[_];else if(l)M=d.length+1-(a-K),M>=0&&M<d.length&&(d=d.substring(M)+" ",x[_]=d+x[_]),S[_]=1;else{S[_]=1;continue}}else{d=b[L].match,y&&(v[_]=y),p&&(T[_]=p),_&&K++;let Er;if(L?!_&&m&&(K+=m):(k[_]=1,S[_]=1),L>=w.length-1||L<b.length-1&&b[L+1].match?Er=1:m&&(K+=m),K-=o.length-2,!_||K+d.length<=a)x[_]=d;else{M=P=F=k[_]=0;break}Er&&(k[_+1]=1,S[_+1]=1)}K+=d.length,M=E[L]=1}if(M)C===O?O++:C++;else{if(C===O?P=0:F=0,!P&&!F)break;P?(C++,O=C):O++}}d="";for(let _=0,L;_<x.length;_++)L=(k[_]?_?" ":"":(_&&!s?" ":"")+s)+x[_],d+=L;s&&!k[x.length]&&(d+=s)}u&&(d=d.replace(u," ")),X[te].highlight=d}if(n)break}return t}function N(e,t){if(!this||this.constructor!==N)return new N(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,Rn(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=N.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 Rn(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?Rn(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?Le.call(this.index,o):o:On.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=Pt(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 zt(e,t,r,n,s,o,i){const c=e.length;let a=[],l,u;l=U();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 w=0;w<m.length;w++){if(y=m[w],(u=l[y])?l[y]++:(u=0,l[y]=1),f=a[u]||(a[u]=[]),!i){let b=h+(d||!s?0:o||0);f=f[b]||(f[b]=[])}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?zo(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 zo(e,t,r,n,s){const o=[],i=U();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 Il(e,t,r,n,s){const o=U(),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}He.prototype.search=function(e,t,r,n){r||(!t&&at(e)?(r=e,e=""):at(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 w=r.offset||0;if(t||(t=y?100:0),f&&(!this.db||!n)){f.constructor!==Array&&(f=[f]);var b=[];for(let v=0,T;v<f.length;v++)if(T=f[v],T.field&&T.tag){var E=T.tag;if(E.constructor===Array)for(var x=0;x<E.length;x++)b.push(T.field,E[x]);else b.push(T.field,E)}else{E=Object.keys(T);for(let K=0,C,O;K<E.length;K++)if(C=E[K],O=T[C],O.constructor===Array)for(x=0;x<O.length;x++)b.push(C,O[x]);else b.push(C,O)}if(f=b,!e){if(o=[],b.length)for(f=0;f<b.length;f+=2){if(this.db){if(n=this.index.get(b[f]),!n)continue;o.push(n=n.db.tag(b[f+1],t,w,d))}else n=jl.call(this,b[f],b[f+1],t,w,d);s.push(y?{field:b[f],tag:b[f+1],result:n}:[n])}if(o.length){const v=this;return Promise.all(o).then(function(T){for(let K=0;K<T.length;K++)y?s[K].result=T[K]:s[K]=T[K];return y?s:new N(s.length>1?zt(s,1,0,0,a,l):s[0],v)})}return y?s:new N(s.length>1?zt(s,1,0,0,a,l):s[0],this)}}y||i||!(h=h||this.field)||(re(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;b=(this.worker||this.db)&&!n&&[];for(let v=0,T,K,C;v<h.length;v++){if(K=h[v],this.db&&this.tag&&!this.B[v])continue;let O;if(re(K)||(O=K,K=O.field,e=O.query||e,t=Fe(O.limit,t),w=Fe(O.offset,w),a=Fe(O.suggest,a),p=y&&this.store&&Fe(O.highlight,p),d=!!p||y&&this.store&&Fe(O.enrich,d),u=Fe(O.cache,u)),n)T=n[v];else{E=O||r||{},x=E.enrich;var S=this.index.get(K);if(f&&(this.db&&(E.tag=f,E.field=h,k=S.db.support_tag_search),!k&&x&&(E.enrich=!1),k||(E.limit=0,E.offset=0)),T=u?S.searchCache(e,f&&!k?0:t,E):S.search(e,f&&!k?0:t,E),f&&!k&&(E.limit=t,E.offset=w),x&&(E.enrich=x),b){b[v]=T;continue}}if(C=(T=T.result||T)&&T.length,f&&C){if(E=[],x=0,this.db&&n){if(!k)for(S=h.length;S<n.length;S++){let P=n[S];if(P&&P.length)x++,E.push(P);else if(!a)return y?s:new N(s,this)}}else for(let P=0,F,I;P<f.length;P+=2){if(F=this.tag.get(f[P]),!F){if(a)continue;return y?s:new N(s,this)}if(I=(F=F&&F.get(f[P+1]))&&F.length)x++,E.push(F);else if(!a)return y?s:new N(s,this)}if(x){if(T=Il(T,E,t,w,y),C=T.length,!C&&!a)return y?T:new N(T,this);x--}}if(C)o[m]=K,s.push(T),m++;else if(h.length===1)return y?s:new N(s,this)}if(b){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 N(s,this)}b.push(o.db.tag(f[d+1],t,w,!1))}const v=this;return Promise.all(b).then(function(T){return r&&(r.resolve=y),T.length&&(T=v.search(e,t,r,T)),T})}if(!m)return y?s:new N(s,this);if(i&&(!d||!this.store))return s=s[0],y?s:new N(s,this);for(b=[],w=0;w<o.length;w++){if(f=s[w],d&&f.length&&typeof f[0].doc>"u"&&(this.db?b.push(f=this.index.get(this.field[0]).db.enrich(f)):f=Le.call(this,f)),i)return y?p?Pt(e,f,this.index,i,p):f:new N(f,this);s[w]={field:o[w],result:f}}if(d&&this.db&&b.length){const v=this;return Promise.all(b).then(function(T){for(let K=0;K<T.length;K++)s[K].result=T[K];return p&&(s=Pt(e,s,v.index,i,p)),c?is(s):s})}return p&&(s=Pt(e,s,this.index,i,p)),c?is(s):s};function is(e){const t=[],r=U(),n=U();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 jl(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=Le.call(this,e))),e):[]):[]}function Le(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 He(e){if(!this||this.constructor!==He)return new He(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)&&Yt(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 se(n):new Set:n?new ne(n):new Map,this.h=(r=t.store||null)&&r&&r!==!0&&[],this.store=r?n?new ne(n):new Map:null,this.cache=(r=e.cache||null)&&new Pe(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]=Yt(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=He.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 oe({},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;re(n)&&(n=[n]);for(let o=0,i,c;o<n.length;o++){if(i=n[o],re(i)||(c=i,i=i.field),c=at(c)?Object.assign({},e,c):e,this.worker){var s=void 0;s=(s=c.encoder)&&s.encode?s:new ut(typeof s=="string"?Do[s]:s||{}),s=new De(c,s),r.set(i,s)}this.worker||r.set(i,new oe(c,this.reg)),c.custom?this.B[o]=c.custom:(this.B[o]=Yt(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,re(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]=Yt(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 Yt(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){at(e)&&(e=lt(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=lt(t,this.key)),this.store.set(e,t),this};A.searchCache=Kn;A.export=Bl;A.import=Nl;_n(He.prototype);function Cn(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 Pn(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 Yo(e,t=0){let r=[],n=[];t&&(t=25e4/t*1e3|0);for(const s of e.entries())n.push([s[0],Cn(s[1])[0]||[]]),n.length===t&&(r.push(n),n=[]);return n.length&&r.push(n),r}function Vo(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],Pn(n[1],s));return t}function Jo(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 Go(e,t){t||(t=new Set);for(let r=0;r<e.length;r++)t.add(e[r]);return t}function Vt(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 Vt.call(l,e,t,r,c?n:null,s,o,i+1)})}return Vt.call(this,e,t,r,c?n:null,s,o,i+1)}function Bl(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=Jo(this.reg),t=null;break;case 1:s="tag",o=this.tag&&Yo(this.tag,this.reg.size),t=null;break;case 2:s="doc",o=this.store&&Cn(this.store),t=null;break;default:return}return Vt.call(this,e,t,s,o||null,r,n)}function Nl(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=Go(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=Vo(t,this.tag);break;case"doc":this.store=Pn(t,this.store)}}}function cs(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}oe.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 ht(this.map,e),this.depth&&ht(this.ctx,e);t||this.reg.delete(e)}return this.db&&(this.commit_task.push({del:e}),this.M&&Xo(this)),this.cache&&this.cache.remove(e),this};function ht(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],ht(s[1],t)?r++:e.delete(n);return r}const Ll={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};oe.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=U(),h=U(),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):Tt(m,l,y),i="";switch(this.tokenize){case"tolerant":if(he(this,h,p,o,e,r),s>2){for(let f=1,d,w,b,E;f<s-1;f++)d=p.charAt(f),w=p.charAt(f+1),b=p.substring(0,f)+w,E=p.substring(f+2),i=b+d+E,he(this,h,i,o,e,r),i=b+E,he(this,h,i,o,e,r);he(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):Tt(m,l,y,s,d);he(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):Tt(m,l,y,s,c);he(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],he(this,h,i,o,e,r);break}default:if(he(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):Tt(s+(l/2>s?0:1),l,y,o-1,c-1);he(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&&Xo(this)),this};function he(e,t,r,n,s,o,i){let c,a;if(!(c=t[r])||i&&!c[i]){if(i?(t=c||(t[r]=U()),t[i]=1,a=e.ctx,(c=a.get(i))?a=c:a.set(i,a=e.keystore?new ne(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 Ue(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 Tt(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}oe.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 ls.call(this,y[0],"",t,c,a,m,l);if(s===2&&o&&!i)return ls.call(this,y[1],y[0],t,c,a,m,l);let p=U(),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 w=this;return(async function(){for(let b,E;f<s;f++){if((E=y[f])&&!p[E]){if(p[E]=1,b=await Vr(w,E,d,0,0,!1,!1),b=us(b,n,i,h)){n=b;break}d&&(i&&b&&n.length||(d=E))}i&&d&&f===s-1&&!n.length&&(h=w.resolution,d="",f=-1,p=U())}return as(n,h,t,c,i,u,a)})()}for(let w,b;f<s;f++){if((b=y[f])&&!p[b]){if(p[b]=1,w=Vr(this,b,d,0,0,!1,!1),w=us(w,n,i,h)){n=w;break}d&&(i&&w&&n.length||(d=b))}i&&d&&f===s-1&&!n.length&&(h=this.resolution,d="",f=-1,p=U())}return as(n,h,t,c,i,u,a)};function as(e,t,r,n,s,o,i){let c=e.length,a=e;if(c>1)a=zt(e,t,r,n,s,o,i);else if(c===1)return i?On.call(null,e[0],r,n):new N(e[0],this);return i?a:new N(a,this)}function ls(e,t,r,n,s,o,i){return e=Vr(this,e,t,r,n,s,o,i),this.db?e.then(function(c){return s?c||[]:new N(c,this)}):e&&e.length?s?On.call(this,e,r,n):new N(e,this):s?[]:new N([],this)}function us(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 Vr(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 oe(e,t){if(!this||this.constructor!==oe)return new oe(e);if(e){var r=re(e)?e:e.preset;r&&(e=Object.assign({},Ll[r],e))}else e={};r=e.context;const n=r===!0?{depth:1}:r||{},s=re(e.encoder)?Do[e.encoder]:e.encode||e.encoder||{};this.encoder=s.encode?s:typeof s=="object"?new ut(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 ne(r):new Map,this.ctx=r?new ne(r):new Map,this.reg=t||(this.fastupdate?r?new ne(r):new Map:r?new se(r):new Set),this.N=n.resolution||3,this.rtl=s.rtl||e.rtl||!1,this.cache=(r=e.cache||null)&&new Pe(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=oe.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 Xo(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?(ht(this.map),this.depth&&ht(this.ctx),this):this};A.searchCache=Kn;A.export=function(e,t,r=0,n=0){let s,o;switch(n){case 0:s="reg",o=Jo(this.reg);break;case 1:s="cfg",o=null;break;case 2:s="map",o=Cn(this.map,this.reg.size);break;case 3:s="ctx",o=Yo(this.ctx,this.reg.size);break;default:return}return Vt.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=Go(t,this.reg);break;case"map":this.map=Pn(t,this.map);break;case"ctx":this.ctx=Vo(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=cs(this.map,o),r="index.map=new Map(["+r+"]);";for(const i of this.ctx.entries()){s=i[0];let c=cs(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};_n(oe.prototype);const qo=typeof window<"u"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Jt=["map","ctx","tag","reg","cfg"],Se=U();function Jr(e,t={}){if(!this||this.constructor!==Jr)return new Jr(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=Jr.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(),Se[e.id]||(Se[e.id]=[]),Se[e.id].push(e.field);const t=qo.open(e.id,1);return t.onupgradeneeded=function(){const r=e.db=this.result;for(let n=0,s;n<Jt.length;n++){s=Jt[n];for(let o=0,i;o<Se[e.id].length;o++)i=Se[e.id][o],r.objectStoreNames.contains(s+(s!=="reg"&&i?":"+i:""))||r.createObjectStore(s+(s!=="reg"&&i?":"+i:""))}},e.db=Ee(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=qo.deleteDatabase(this.id);return Ee(e)};A.clear=function(){const e=[];for(let r=0,n;r<Jt.length;r++){n=Jt[r];for(let s=0,o;s<Se[this.id].length;s++)o=Se[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 Ee(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 Ee(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 Ee(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]=Ee(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),Ee(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,Ee(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 _r(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&&_r(r,e)}}),this.transaction("ctx","readwrite",function(t){t.openCursor().onsuccess=function(){const r=this.result;r&&_r(r,e)}}),this.transaction("tag","readwrite",function(t){t.openCursor().onsuccess=function(){const r=this.result;r&&_r(r,e,!0)}}),this.transaction("reg","readwrite",function(t){for(let r=0;r<e.length;r++)t.delete(e[r])})])};function Ee(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 At=oe,dr={preset:"match",tokenize:"forward",resolution:9,minlength:2,optimize:!0,fastupdate:!0,cache:!0},Ml={...dr,minlength:3,resolution:6},Ul={...dr,tokenize:"strict",minlength:1},Dl={...dr,tokenize:"strict",minlength:1},Hl=()=>({subjectIndex:new At(dr),bodyIndex:new At(Ml),fromIndex:new At(Ul),toIndex:new At(Dl),isReady:!1}),Wo=(e,t)=>{try{const r=e.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})}},zl=async e=>{try{const t=Hl();t.isReady=!1;for(const r of e.esCache.values())Wo(r,t);return t.isReady=!0,t}catch(t){throw new Error("Failed build an email search index from the cache",{cause:t})}},Yl=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})}},Vl=Object.freeze(Object.defineProperty({__proto__:null,addEmailToCache:Uo,addEmailToSearchIndex:Wo,addEmailsToCache:Hr,buildSearchIndexFromCache:zl,closeDatabase:ll,createCacheFromDB:El,deleteDatabase:ul,deleteEmail:ml,deleteEmailFromCache:xl,deleteOldestEmails:jo,deriveIndexKey:hl,encryptAndStoreEmail:fl,encryptAndStoreManyEmail:dl,enforceMaxEmailNumber:gl,getAllEmailsSortedNewestFirst:Bo,getAllEmailsSortedOldestFirst:wl,getAndDecryptAllEmails:yl,getAndDecryptEmail:pl,getEmailBatch:No,getEmailCount:An,getEmailFromCache:Mo,openDatabase:al,removeEmailFromSearchIndex:$l,searchEmails:Yl},Symbol.toStringTag,{value:"Module"}));class yt{constructor(t=0,r="Network Error"){this.status=t,this.text=r}}const Jl=()=>{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:Jl()},In=e=>e?typeof e=="string"?{publicKey:e}:e.toString()==="[object Object]"?e:{}:{},Gl=(e,t="https://api.emailjs.com")=>{if(!e)return;const r=In(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},Zo=async(e,t,r={})=>{const n=await fetch(z.origin+e,{method:"POST",headers:r,body:t}),s=await n.text(),o=new yt(n.status,s);if(n.ok)return o;throw o},Qo=(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"},Xl=e=>{if(e&&e.toString()!=="[object Object]")throw"The template params have to be the object. Visit https://www.emailjs.com/docs/sdk/send/"},ei=e=>e.webdriver||!e.languages||e.languages.length===0,ti=()=>new yt(451,"Unavailable For Headless Browser"),ql=(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"},Wl=e=>!e.list?.length||!e.watchVariable,Zl=(e,t)=>e instanceof FormData?e.get(t):e[t],ri=(e,t)=>{if(Wl(e))return!1;ql(e.list,e.watchVariable);const r=Zl(t,e.watchVariable);return typeof r!="string"?!1:e.list.includes(r)},ni=()=>new yt(403,"Forbidden"),Ql=(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"},eu=async(e,t,r)=>{const n=Number(await r.get(e)||0);return t-Date.now()+n},si=async(e,t,r)=>{if(!t.throttle||!r)return!1;Ql(t.throttle,t.id);const n=t.id||e;return await eu(n,t.throttle,r)>0?!0:(await r.set(n,Date.now().toString()),!1)},oi=()=>new yt(429,"Too Many Requests"),tu=async(e,t,r,n)=>{const s=In(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&&ei(navigator)?Promise.reject(ti()):(Qo(o,e,t),Xl(r),r&&ri(a,r)?Promise.reject(ni()):await si(location.pathname,l,c)?Promise.reject(oi()):Zo("/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"}))},ru=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"},nu=e=>typeof e=="string"?document.querySelector(e):e,su=async(e,t,r,n)=>{const s=In(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&&ei(navigator))return Promise.reject(ti());const u=nu(r);Qo(o,e,t),ru(u);const h=new FormData(u);return ri(a,h)?Promise.reject(ni()):await si(location.pathname,l,c)?Promise.reject(oi()):(h.append("lib_version","4.4.1"),h.append("service_id",e),h.append("template_id",t),h.append("user_id",o),Zo("/api/v1.0/email/send-form",h))},ou={init:Gl,send:tu,sendForm:su,EmailJSResponseStatus:yt};class ii{constructor(t,r,n){this.serviceId=t,this.templateId=r,this.publicKey=n}async sendEmail(t,r){try{const n={from_email:r.sender.email,from_name:r.sender.name,to_email:r.recipient.email,to_name:r.recipient.name,email_subject:r.subject,email_body:t,timestamp:new Date().toISOString()};await ou.send(this.serviceId,this.templateId,n,this.publicKey)}catch(n){throw new Error(`Failed to send an email ${n.message}`,{cause:n})}}async sendHybridEmail(t){try{if(t.recipientEmail!==t.params.recipient.email)throw new Error("Email is encrypted for another recipient");const r=ko(t);await this.sendEmail(r,t.params)}catch(r){throw new Error(`Failed to email to the recipient: ${r.message}`,{cause:r})}}async sendPwdProtectedEmail(t){try{const r=vo(t);await this.sendEmail(r,t.params)}catch(r){throw new Error(`Failed to email to the recipient ${r.message}`,{cause:r})}}}function iu(e,t,r){return new ii(e,t,r)}const cu=Object.freeze(Object.defineProperty({__proto__:null,EmailServiceAPI:ii,getEmailServiceAPI:iu},Symbol.toStringTag,{value:"Module"}));var Q=(e=>(e.IDENTITY="identity",e.ENCRYPTION="encryption",e.RECOVERY="recovery",e.INDEX="index",e))(Q||{});function au(e){return sessionStorage.getItem(e)}function lu(e,t){return sessionStorage.setItem(e,t)}function uu(e){sessionStorage.removeItem(e)}function hu(e){return!!sessionStorage.getItem(e)}function fu(){sessionStorage.clear()}const jn={set:lu,get:au,removeItem:uu,exists:hu,clear:fu},du=Object.freeze(Object.defineProperty({__proto__:null,default:jn},Symbol.toStringTag,{value:"Module"}));async function Gr(e,t,r,n){try{const s=r+n,o=D(t);return await ir(e,o,s)}catch(s){throw new Error("Failed to encrypt keystore content",{cause:s})}}async function Fn(e,t,r,n){try{const s=r+n,o=await ot(e,t,s);return H(o)}catch(s){throw new Error("Failed to decrypt keystore content",{cause:s})}}function Gt(){try{const e=jn.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 pr(){try{const e=jn.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 ci(e){return pt(Rs,e)}async function ai(e){const t=await Je(G,e);return pt(Ps,t)}async function li(e){return pt(Cs,e)}function ui(){return so(G)}async function hi(){try{const e=await Zt(),t=bn();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 pu(){try{const e=Gt(),t=pr(),r=await hi(),n=await zs(r),s=await li(t),o=await Gr(s,n,e,en),i={userID:e,type:Q.ENCRYPTION,encryptedKeys:o},c=ui(),a=await ai(c),l=await Gr(a,n,e,tn),u={userID:e,type:Q.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 yu(e){try{if(e.type!=Q.ENCRYPTION)throw new Error("Input is invalid");const t=pr(),r=await li(t),n=await Fn(r,e.encryptedKeys,e.userID,en);return await cn(n)}catch(t){throw new Error("Failed to open encryption keystore",{cause:t})}}async function mu(e,t){try{if(t.type!=Q.RECOVERY)throw new Error("Input is invalid");const r=await ai(e),n=await Fn(r,t.encryptedKeys,t.userID,tn);return await cn(n)}catch(r){throw new Error("Failed to open recovery keystore",{cause:r})}}async function fi(){try{const e=await Zt();return{userPrivateKey:e.privateKey,userPublicKey:e.publicKey}}catch(e){throw new Error("Failed to generate idenity keys",{cause:e})}}async function gu(){try{const e=Q.IDENTITY,t=Gt(),r=pr(),n=await fi(),s=await $s(n),o=await ci(r),i=await Gr(o,s,t,Qr);return{userID:t,type:e,encryptedKeys:i}}catch(e){throw new Error("Failed to create identity keystore",{cause:e})}}async function wu(e){try{if(e.type!=Q.IDENTITY)throw new Error("Input is invalid");const t=pr(),r=await ci(t),n=await Fn(r,e.encryptedKeys,e.userID,Qr);return await Vs(n)}catch(t){throw new Error("Failed to open identity keystore",{cause:t})}}const bu=Object.freeze(Object.defineProperty({__proto__:null,createEncryptionAndRecoveryKeystores:pu,createIdentityKeystore:gu,generateEncryptionKeys:hi,generateIdentityKeys:fi,generateRecoveryCodes:ui,openEncryptionKeystore:yu,openIdentityKeystore:wu,openRecoveryKeystore:mu},Symbol.toStringTag,{value:"Module"}));function di(e,t){return function(){return e.apply(t,arguments)}}const{toString:Eu}=Object.prototype,{getPrototypeOf:Bn}=Object,{iterator:yr,toStringTag:pi}=Symbol,mr=(e=>t=>{const r=Eu.call(t);return e[r]||(e[r]=r.slice(8,-1).toLowerCase())})(Object.create(null)),ie=e=>(e=e.toLowerCase(),t=>mr(t)===e),gr=e=>t=>typeof t===e,{isArray:Xe}=Array,$e=gr("undefined");function mt(e){return e!==null&&!$e(e)&&e.constructor!==null&&!$e(e.constructor)&&q(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const yi=ie("ArrayBuffer");function xu(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&yi(e.buffer),t}const ku=gr("string"),q=gr("function"),mi=gr("number"),gt=e=>e!==null&&typeof e=="object",vu=e=>e===!0||e===!1,It=e=>{if(mr(e)!=="object")return!1;const t=Bn(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(pi in e)&&!(yr in e)},Su=e=>{if(!gt(e)||mt(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Tu=ie("Date"),Au=ie("File"),Ku=ie("Blob"),_u=ie("FileList"),Ou=e=>gt(e)&&q(e.pipe),Ru=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||q(e.append)&&((t=mr(e))==="formdata"||t==="object"&&q(e.toString)&&e.toString()==="[object FormData]"))},Cu=ie("URLSearchParams"),[Pu,Iu,ju,Fu]=["ReadableStream","Request","Response","Headers"].map(ie),Bu=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function wt(e,t,{allOwnKeys:r=!1}={}){if(e===null||typeof e>"u")return;let n,s;if(typeof e!="object"&&(e=[e]),Xe(e))for(n=0,s=e.length;n<s;n++)t.call(null,e[n],n,e);else{if(mt(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 gi(e,t){if(mt(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 Ae=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:globalThis,wi=e=>!$e(e)&&e!==Ae;function Xr(){const{caseless:e,skipUndefined:t}=wi(this)&&this||{},r={},n=(s,o)=>{const i=e&&gi(r,o)||o;It(r[i])&&It(s)?r[i]=Xr(r[i],s):It(s)?r[i]=Xr({},s):Xe(s)?r[i]=s.slice():(!t||!$e(s))&&(r[i]=s)};for(let s=0,o=arguments.length;s<o;s++)arguments[s]&&wt(arguments[s],n);return r}const Nu=(e,t,r,{allOwnKeys:n}={})=>(wt(t,(s,o)=>{r&&q(s)?e[o]=di(s,r):e[o]=s},{allOwnKeys:n}),e),Lu=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Mu=(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)},Uu=(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&&Bn(e)}while(e&&(!r||r(e,t))&&e!==Object.prototype);return t},Du=(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},Hu=e=>{if(!e)return null;if(Xe(e))return e;let t=e.length;if(!mi(t))return null;const r=new Array(t);for(;t-- >0;)r[t]=e[t];return r},$u=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Bn(Uint8Array)),zu=(e,t)=>{const n=(e&&e[yr]).call(e);let s;for(;(s=n.next())&&!s.done;){const o=s.value;t.call(e,o[0],o[1])}},Yu=(e,t)=>{let r;const n=[];for(;(r=e.exec(t))!==null;)n.push(r);return n},Vu=ie("HTMLFormElement"),Ju=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(r,n,s){return n.toUpperCase()+s}),hs=(({hasOwnProperty:e})=>(t,r)=>e.call(t,r))(Object.prototype),Gu=ie("RegExp"),bi=(e,t)=>{const r=Object.getOwnPropertyDescriptors(e),n={};wt(r,(s,o)=>{let i;(i=t(s,o,e))!==!1&&(n[o]=i||s)}),Object.defineProperties(e,n)},Xu=e=>{bi(e,(t,r)=>{if(q(e)&&["arguments","caller","callee"].indexOf(r)!==-1)return!1;const n=e[r];if(q(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+"'")})}})},qu=(e,t)=>{const r={},n=s=>{s.forEach(o=>{r[o]=!0})};return Xe(e)?n(e):n(String(e).split(t)),r},Wu=()=>{},Zu=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Qu(e){return!!(e&&q(e.append)&&e[pi]==="FormData"&&e[yr])}const eh=e=>{const t=new Array(10),r=(n,s)=>{if(gt(n)){if(t.indexOf(n)>=0)return;if(mt(n))return n;if(!("toJSON"in n)){t[s]=n;const o=Xe(n)?[]:{};return wt(n,(i,c)=>{const a=r(i,s+1);!$e(a)&&(o[c]=a)}),t[s]=void 0,o}}return n};return r(e,0)},th=ie("AsyncFunction"),rh=e=>e&&(gt(e)||q(e))&&q(e.then)&&q(e.catch),Ei=((e,t)=>e?setImmediate:t?((r,n)=>(Ae.addEventListener("message",({source:s,data:o})=>{s===Ae&&o===r&&n.length&&n.shift()()},!1),s=>{n.push(s),Ae.postMessage(r,"*")}))(`axios@${Math.random()}`,[]):r=>setTimeout(r))(typeof setImmediate=="function",q(Ae.postMessage)),nh=typeof queueMicrotask<"u"?queueMicrotask.bind(Ae):typeof process<"u"&&process.nextTick||Ei,sh=e=>e!=null&&q(e[yr]),g={isArray:Xe,isArrayBuffer:yi,isBuffer:mt,isFormData:Ru,isArrayBufferView:xu,isString:ku,isNumber:mi,isBoolean:vu,isObject:gt,isPlainObject:It,isEmptyObject:Su,isReadableStream:Pu,isRequest:Iu,isResponse:ju,isHeaders:Fu,isUndefined:$e,isDate:Tu,isFile:Au,isBlob:Ku,isRegExp:Gu,isFunction:q,isStream:Ou,isURLSearchParams:Cu,isTypedArray:$u,isFileList:_u,forEach:wt,merge:Xr,extend:Nu,trim:Bu,stripBOM:Lu,inherits:Mu,toFlatObject:Uu,kindOf:mr,kindOfTest:ie,endsWith:Du,toArray:Hu,forEachEntry:zu,matchAll:Yu,isHTMLForm:Vu,hasOwnProperty:hs,hasOwnProp:hs,reduceDescriptors:bi,freezeMethods:Xu,toObjectSet:qu,toCamelCase:Ju,noop:Wu,toFiniteNumber:Zu,findKey:gi,global:Ae,isContextDefined:wi,isSpecCompliantForm:Qu,toJSONObject:eh,isAsyncFn:th,isThenable:rh,setImmediate:Ei,asap:nh,isIterable:sh};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 xi=R.prototype,ki={};["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=>{ki[e]={value:e}});Object.defineProperties(R,ki);Object.defineProperty(xi,"isAxiosError",{value:!0});R.from=(e,t,r,n,s,o)=>{const i=Object.create(xi);g.toFlatObject(e,i,function(u){return u!==Error.prototype},l=>l!=="isAxiosError");const c=e&&e.message?e.message:"Error",a=t==null&&e?e.code:t;return R.call(i,c,a,r,n,s),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",o&&Object.assign(i,o),i};const oh=null;function qr(e){return g.isPlainObject(e)||g.isArray(e)}function vi(e){return g.endsWith(e,"[]")?e.slice(0,-2):e}function fs(e,t,r){return e?e.concat(t).map(function(s,o){return s=vi(s),!r&&o?"["+s+"]":s}).join(r?".":""):t}function ih(e){return g.isArray(e)&&!e.some(qr)}const ch=g.toFlatObject(g,{},null,function(t){return/^is[A-Z]/.test(t)});function wr(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 w=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)&&ih(p)||(g.isFileList(p)||g.endsWith(f,"[]"))&&(w=g.toArray(p)))return f=vi(f),w.forEach(function(E,x){!(g.isUndefined(E)||E===null)&&t.append(i===!0?fs([f],x,o):i===null?f:f+"[]",l(E))}),!1}return qr(p)?!0:(t.append(fs(d,f,o),l(p)),!1)}const h=[],m=Object.assign(ch,{defaultVisitor:u,convertValue:l,isVisitable:qr});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(w,b){(!(g.isUndefined(w)||w===null)&&s.call(t,w,g.isString(b)?b.trim():b,f,m))===!0&&y(w,f?f.concat(b):[b])}),h.pop()}}if(!g.isObject(e))throw new TypeError("data must be an object");return y(e),t}function ds(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(n){return t[n]})}function Nn(e,t){this._pairs=[],e&&wr(e,this,t)}const Si=Nn.prototype;Si.append=function(t,r){this._pairs.push([t,r])};Si.toString=function(t){const r=t?function(n){return t.call(this,n,ds)}:ds;return this._pairs.map(function(s){return r(s[0])+"="+r(s[1])},"").join("&")};function ah(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Ti(e,t,r){if(!t)return e;const n=r&&r.encode||ah;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 Nn(t,r).toString(n),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class ps{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 Ai={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},lh=typeof URLSearchParams<"u"?URLSearchParams:Nn,uh=typeof FormData<"u"?FormData:null,hh=typeof Blob<"u"?Blob:null,fh={isBrowser:!0,classes:{URLSearchParams:lh,FormData:uh,Blob:hh},protocols:["http","https","file","blob","url","data"]},Ln=typeof window<"u"&&typeof document<"u",Wr=typeof navigator=="object"&&navigator||void 0,dh=Ln&&(!Wr||["ReactNative","NativeScript","NS"].indexOf(Wr.product)<0),ph=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",yh=Ln&&window.location.href||"http://localhost",mh=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Ln,hasStandardBrowserEnv:dh,hasStandardBrowserWebWorkerEnv:ph,navigator:Wr,origin:yh},Symbol.toStringTag,{value:"Module"})),V={...mh,...fh};function gh(e,t){return wr(e,new V.classes.URLSearchParams,{visitor:function(r,n,s,o){return V.isNode&&g.isBuffer(r)?(this.append(n,r.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)},...t})}function wh(e){return g.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function bh(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 Ki(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]=bh(s[i])),!c)}if(g.isFormData(e)&&g.isFunction(e.entries)){const r={};return g.forEachEntry(e,(n,s)=>{t(wh(n),s,r,0)}),r}return null}function Eh(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 bt={transitional:Ai,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(Ki(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 gh(t,this.formSerializer).toString();if((c=g.isFileList(t))||n.indexOf("multipart/form-data")>-1){const a=this.env&&this.env.FormData;return wr(c?{"files[]":t}:t,a&&new a,this.formSerializer)}}return o||s?(r.setContentType("application/json",!1),Eh(t)):t}],transformResponse:[function(t){const r=this.transitional||bt.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,this.parseReviver)}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:V.classes.FormData,Blob:V.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=>{bt.headers[e]={}});const xh=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"]),kh=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[ys]=this[ys]={accessors:{}}).accessors,s=this.prototype;function o(i){const c=rt(i);n[c]||(Ah(s,i),n[c]=!0)}return g.isArray(t)?t.forEach(o):o(t),this}};W.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);g.reduceDescriptors(W.prototype,({value:e},t)=>{let r=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(n){this[r]=n}}});g.freezeMethods(W);function Rr(e,t){const r=this||bt,n=t||r,s=W.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 _i(e){return!!(e&&e.__CANCEL__)}function qe(e,t,r){R.call(this,e??"canceled",R.ERR_CANCELED,t,r),this.name="CanceledError"}g.inherits(qe,R,{__CANCEL__:!0});function Oi(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 Kh(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function _h(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 Oh(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 Xt=(e,t,r=3)=>{let n=0;const s=_h(50,250);return Oh(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)},ms=(e,t)=>{const r=e!=null;return[n=>t[0]({lengthComputable:r,total:e,loaded:n}),t[1]]},gs=e=>(...t)=>g.asap(()=>e(...t)),Rh=V.hasStandardBrowserEnv?((e,t)=>r=>(r=new URL(r,V.origin),e.protocol===r.protocol&&e.host===r.host&&(t||e.port===r.port)))(new URL(V.origin),V.navigator&&/(msie|trident)/i.test(V.navigator.userAgent)):()=>!0,Ch=V.hasStandardBrowserEnv?{write(e,t,r,n,s,o,i){if(typeof document>"u")return;const c=[`${e}=${encodeURIComponent(t)}`];g.isNumber(r)&&c.push(`expires=${new Date(r).toUTCString()}`),g.isString(n)&&c.push(`path=${n}`),g.isString(s)&&c.push(`domain=${s}`),o===!0&&c.push("secure"),g.isString(i)&&c.push(`SameSite=${i}`),document.cookie=c.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function Ph(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Ih(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Ri(e,t,r){let n=!Ph(t);return e&&(n||r==!1)?Ih(e,t):t}const ws=e=>e instanceof W?{...e}:e;function Re(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(ws(l),ws(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 Ci=e=>{const t=Re({},e);let{data:r,withXSRFToken:n,xsrfHeaderName:s,xsrfCookieName:o,headers:i,auth:c}=t;if(t.headers=i=W.from(i),t.url=Ti(Ri(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&i.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),g.isFormData(r)){if(V.hasStandardBrowserEnv||V.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(g.isFunction(r.getHeaders)){const a=r.getHeaders(),l=["content-type","content-length"];Object.entries(a).forEach(([u,h])=>{l.includes(u.toLowerCase())&&i.set(u,h)})}}if(V.hasStandardBrowserEnv&&(n&&g.isFunction(n)&&(n=n(t)),n||n!==!1&&Rh(t.url))){const a=s&&o&&Ch.read(o);a&&i.set(s,a)}return t},jh=typeof XMLHttpRequest<"u",Fh=jh&&function(e){return new Promise(function(r,n){const s=Ci(e);let o=s.data;const i=W.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 w(){if(!d)return;const E=W.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};Oi(function(v){r(v),f()},function(v){n(v),f()},k),d=null}"onloadend"in d?d.onloadend=w:d.onreadystatechange=function(){!d||d.readyState!==4||d.status===0&&!(d.responseURL&&d.responseURL.indexOf("file:")===0)||setTimeout(w)},d.onabort=function(){d&&(n(new R("Request aborted",R.ECONNABORTED,e,d)),d=null)},d.onerror=function(x){const k=x&&x.message?x.message:"Network Error",S=new R(k,R.ERR_NETWORK,e,d);S.event=x||null,n(S),d=null},d.ontimeout=function(){let x=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const k=s.transitional||Ai;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]=Xt(l,!0),d.addEventListener("progress",m)),a&&d.upload&&([h,y]=Xt(a),d.upload.addEventListener("progress",h),d.upload.addEventListener("loadend",y)),(s.cancelToken||s.signal)&&(u=E=>{d&&(n(!E||E.type?new qe(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 b=Kh(s.url);if(b&&V.protocols.indexOf(b)===-1){n(new R("Unsupported protocol "+b+":",R.ERR_BAD_REQUEST,e));return}d.send(o||null)})},Bh=(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 qe(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}},Nh=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},Lh=async function*(e,t){for await(const r of Mh(e))yield*Nh(r,t)},Mh=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()}},bs=(e,t,r,n)=>{const s=Lh(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})},Es=64*1024,{isFunction:Kt}=g,Uh=(({Request:e,Response:t})=>({Request:e,Response:t}))(g.global),{ReadableStream:xs,TextEncoder:ks}=g.global,vs=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Dh=e=>{e=g.merge.call({skipUndefined:!0},Uh,e);const{fetch:t,Request:r,Response:n}=e,s=t?Kt(t):typeof fetch=="function",o=Kt(r),i=Kt(n);if(!s)return!1;const c=s&&Kt(xs),a=s&&(typeof ks=="function"?(p=>f=>p.encode(f))(new ks):async p=>new Uint8Array(await new r(p).arrayBuffer())),l=o&&c&&vs(()=>{let p=!1;const f=new r(V.origin,{body:new xs,method:"POST",get duplex(){return p=!0,"half"}}).headers.has("Content-Type");return p&&!f}),u=i&&c&&vs(()=>g.isReadableStream(new n("").body)),h={stream:u&&(p=>p.body)};s&&["text","arrayBuffer","blob","formData","stream"].forEach(p=>{!h[p]&&(h[p]=(f,d)=>{let w=f&&f[p];if(w)return w.call(f);throw new R(`Response type '${p}' is not supported`,R.ERR_NOT_SUPPORT,d)})});const m=async p=>{if(p==null)return 0;if(g.isBlob(p))return p.size;if(g.isSpecCompliantForm(p))return(await new r(V.origin,{method:"POST",body:p}).arrayBuffer()).byteLength;if(g.isArrayBufferView(p)||g.isArrayBuffer(p))return p.byteLength;if(g.isURLSearchParams(p)&&(p=p+""),g.isString(p))return(await a(p)).byteLength},y=async(p,f)=>{const d=g.toFiniteNumber(p.getContentLength());return d??m(f)};return async p=>{let{url:f,method:d,data:w,signal:b,cancelToken:E,timeout:x,onDownloadProgress:k,onUploadProgress:S,responseType:v,headers:T,withCredentials:K="same-origin",fetchOptions:C}=Ci(p),O=t||fetch;v=v?(v+"").toLowerCase():"text";let P=Bh([b,E&&E.toAbortSignal()],x),F=null;const I=P&&P.unsubscribe&&(()=>{P.unsubscribe()});let B;try{if(S&&l&&d!=="get"&&d!=="head"&&(B=await y(T,w))!==0){let X=new r(f,{method:"POST",body:w,duplex:"half"}),te;if(g.isFormData(w)&&(te=X.headers.get("content-type"))&&T.setContentType(te),X.body){const[pe,_]=ms(B,Xt(gs(S)));w=bs(X.body,Es,pe,_)}}g.isString(K)||(K=K?"include":"omit");const M=o&&"credentials"in r.prototype,Ie={...C,signal:P,method:d.toUpperCase(),headers:T.normalize().toJSON(),body:w,duplex:"half",credentials:M?K:void 0};F=o&&new r(f,Ie);let Y=await(o?O(F,C):O(f,Ie));const We=u&&(v==="stream"||v==="response");if(u&&(k||We&&I)){const X={};["status","statusText","headers"].forEach(L=>{X[L]=Y[L]});const te=g.toFiniteNumber(Y.headers.get("content-length")),[pe,_]=k&&ms(te,Xt(gs(k),!0))||[];Y=new n(bs(Y.body,Es,pe,()=>{_&&_(),I&&I()}),X)}v=v||"text";let xe=await h[g.findKey(h,v)||"text"](Y,p);return!We&&I&&I(),await new Promise((X,te)=>{Oi(X,te,{data:xe,headers:W.from(Y.headers),status:Y.status,statusText:Y.statusText,config:p,request:F})})}catch(M){throw I&&I(),M&&M.name==="TypeError"&&/Load failed|fetch/i.test(M.message)?Object.assign(new R("Network Error",R.ERR_NETWORK,p,F),{cause:M.cause||M}):R.from(M,M&&M.code,p,F)}}},Hh=new Map,Pi=e=>{let t=e&&e.env||{};const{fetch:r,Request:n,Response:s}=t,o=[n,s,r];let i=o.length,c=i,a,l,u=Hh;for(;c--;)a=o[c],l=u.get(a),l===void 0&&u.set(a,l=c?new Map:Dh(t)),u=l;return l};Pi();const Mn={http:oh,xhr:Fh,fetch:{get:Pi}};g.forEach(Mn,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ss=e=>`- ${e}`,$h=e=>g.isFunction(e)||e===null||e===!1;function zh(e,t){e=g.isArray(e)?e:[e];const{length:r}=e;let n,s;const o={};for(let i=0;i<r;i++){n=e[i];let c;if(s=n,!$h(n)&&(s=Mn[(c=String(n)).toLowerCase()],s===void 0))throw new R(`Unknown adapter '${c}'`);if(s&&(g.isFunction(s)||(s=s.get(t))))break;o[c||"#"+i]=s}if(!s){const i=Object.entries(o).map(([a,l])=>`adapter ${a} `+(l===!1?"is not supported by the environment":"is not available in the build"));let c=r?i.length>1?`since :
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
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+AhBACACKQNwIAEpA3CFNwOACUEAIAIpA3ggASkDeIU3A4gJQQAgAikDgAEgASkDgAGFNwOQCUEAIAIpA4gBIAEpA4gBhTcDmAlBACACKQOQASABKQOQAYU3A6AJQQAgAikDmAEgASkDmAGFNwOoCUEAIAIpA6ABIAEpA6ABhTcDsAlBACACKQOoASABKQOoAYU3A7gJQQAgAikDsAEgASkDsAGFNwPACUEAIAIpA7gBIAEpA7gBhTcDyAlBACACKQPAASABKQPAAYU3A9AJQQAgAikDyAEgASkD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";
|
|
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
|