dns-worker 1.1.7 → 1.1.8

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.
Files changed (28) hide show
  1. package/dist/serverfull.mjs +166 -166
  2. package/dist/serverfull.mjs.map +3 -3
  3. package/package.json +3 -3
  4. package/static/assets/{AccountView-Yowwz2Gg.js → AccountView-DE0I53v4.js} +3 -3
  5. package/static/assets/AnalyticsView-2koXmar8.js +2 -0
  6. package/static/assets/{DestinationMap-DoNQwdnV.js → DestinationMap-DvmffkR6.js} +1 -1
  7. package/static/assets/{FilteringView-DVmIVx_P.js → FilteringView-C3e7d__9.js} +1 -1
  8. package/static/assets/{LogsView-D1dRHMqS.js → LogsView-jNLLQ8le.js} +3 -3
  9. package/static/assets/{RulesView-DnQoSZ4S.js → RulesView-CnmSPz0p.js} +1 -1
  10. package/static/assets/{SettingsView-Ci0mrIcm.js → SettingsView-BKvenuLL.js} +1 -1
  11. package/static/assets/{SetupView-CfkQXcdY.js → SetupView-3fqqCCHL.js} +1 -1
  12. package/static/assets/{SwipeableDrawer-DW0I7SLC.js → SwipeableDrawer-B1CCYC-Y.js} +1 -1
  13. package/static/assets/{TrendChart-B8jOSMgO.js → TrendChart-bmtDyrNL.js} +1 -1
  14. package/static/assets/browser-DGSv7yOq.js +1 -0
  15. package/static/assets/date-DqJrNNA3.js +1 -0
  16. package/static/assets/{index-BDIG7T8u.js → index-D0aw4Fjy.js} +6 -6
  17. package/static/assets/{services-CcZhHzmI.js → services-DYNQDGKX.js} +1 -1
  18. package/static/assets/{useLogsE2ee-DR83v9Pr.js → useLogsE2ee-Ceq0lZyV.js} +1 -1
  19. package/static/assets/vendor-i18next-BC3ewzY3.js +1 -0
  20. package/static/assets/{vendor-react-BOaLEa_F.js → vendor-react-BtC4HVVO.js} +2 -2
  21. package/static/assets/{vendor-ui-core-C8brnfYc.js → vendor-ui-core-DUyKOLA8.js} +1 -1
  22. package/static/assets/{vendor-utils-DkfyN6f3.js → vendor-utils-xrsi4rSa.js} +1 -1
  23. package/static/index.html +5 -5
  24. package/static/sw.js +1 -1
  25. package/static/assets/AnalyticsView-C9e4mI_K.js +0 -2
  26. package/static/assets/browser-BRLLTlVv.js +0 -1
  27. package/static/assets/date-Cw6CNU-1.js +0 -1
  28. package/static/assets/vendor-i18next-BlwxMUL4.js +0 -1
@@ -1,4 +1,4 @@
1
- import{i as e,t}from"./rolldown-runtime-C4Xdq4VV.js";import{a as n,c as r,h as i,l as a,o,s,tn as c}from"./vendor-react-BOaLEa_F.js";import{S as l}from"./vendor-icons-other-BTYC6Wvz.js";function u(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}var d=e=>e?`"${e}" `:``;function f(e,t=``){if(typeof e!=`number`)throw TypeError(d(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(d(t)+`expected integer >= 0, got `+e);return e}function p(e,t=``){if(typeof e!=`boolean`)throw TypeError(d(t)+`expected boolean, got type=`+typeof e);return e}function m(e,t,n=``){if(u(e)&&(t===void 0||e.length===t))return e;t!==void 0&&f(t,`length`);let r=u(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=d(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}function h(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`expected hash wrapped by utils.createHasher`);if(f(e.outputLen),f(e.blockLen),e.outputLen<1||e.blockLen<1)throw Error(`hash blockLen / outputLen must be >= 1`)}var g=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)},_=(e,t)=>{g(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,`__proto__`))throw TypeError(`"${t}.__proto__" is not allowed`)};function v(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function y(e,t){m(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function b(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function x(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function S(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function C(e,t){return e<<32-t|e>>>t}const w=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function T(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function E(e){for(let t=0;t<e.length;t++)e[t]=T(e[t]);return e}const D=w?e=>e:E;var O=(()=>typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`)(),k=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function A(e){if(m(e),O)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=k[e[n]];return t}function j(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function M(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(O)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=j(e.charCodeAt(i)),a=j(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function N(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];m(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function ee(e,t,n=`opts`){return _(e,`defaults`),t!==void 0&&_(t,n),Object.assign(Object.create(null),e,t)}function te(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=ee({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function ne(e=32){f(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}const re=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ie(e,t,n=()=>{}){if(!Array.isArray(e))throw TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}const P=(e,t,n)=>m(e,t,n),ae=f;function oe(e,t=``){if(typeof e!=`string`){let n=t&&`"${t}" `;throw TypeError(n+`expected string, got type=`+typeof e)}return e}function se(e,t=`object`){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`);return e}function ce(e,t){if(typeof e!=`function`)throw TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}const le=A,ue=(...e)=>N(...e),de=e=>M(e),fe=u,pe=e=>ne(e);var me=BigInt(0),he=BigInt(1),ge=e=>e?`"${e}" `:``;function _e(e,t=``){if(typeof e!=`boolean`)throw TypeError(ge(t)+`expected boolean, got type=`+typeof e);return e}function ve(e){if(typeof e==`bigint`){if(!Oe(e))throw RangeError(`positive bigint expected, got `+e)}else ae(e);return e}function ye(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function be(e){let t=ve(e).toString(16);return t.length&1?`0`+t:t}function xe(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?me:BigInt(`0x`+e)}function Se(e){return xe(A(e))}function Ce(e){return xe(A(Ee(m(e)).reverse()))}function we(e,t){if(f(t),t===0)throw Error(`zero output length is invalid`);e=ve(e);let n=t*2,r=e.toString(16);if(r.length>n)throw RangeError(`number is too large`);return M(r.padStart(n,`0`))}function Te(e,t){return we(e,t).reverse()}function Ee(e){return Uint8Array.from(P(e))}function De(e){if(typeof e!=`string`)throw TypeError(`ascii string expected, got `+typeof e);return Uint8Array.from(e,(t,n)=>{let r=t.charCodeAt(0);if(t.length!==1||r>127)throw RangeError(`string contains non-ASCII character "${e[n]}" with code ${r} at position ${n}`);return r})}function Oe(e){return typeof e==`bigint`&&me<=e}function ke(e,t,n){return Oe(e)&&Oe(t)&&Oe(n)&&t<=e&&e<n}function Ae(e,t,n,r){if(!ke(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function je(e){if(e<me)throw Error(`expected non-negative bigint, got `+e);return e===me?0:e.toString(2).length}const Me=e=>(ye(e,`n`),(he<<BigInt(e))-he);function Ne(e,t,n){if(f(e,`hashLen`),f(t,`qByteLen`),typeof n!=`function`)throw TypeError(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=Uint8Array.of(),a=Uint8Array.of(0),o=Uint8Array.of(1),s=r(e),c=r(e),l=0,u=()=>{s.fill(1),c.fill(0),l=0},d=(...e)=>n(c,ue(s,...e)),p=(e=i)=>{c=d(a,e),s=d(),e.length!==0&&(c=d(o,e),s=d())},m=()=>{if(l++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){s=d();let t=s.slice();n.push(t),e+=s.length}return ue(...n)};return(e,t)=>{u(),p(e);let n;for(;(n=t(m()))===void 0;)p();return u(),n}}function Pe(e,t={},n={},r=`object`){se(e,r),se(t,`fields`),se(n,`optFields`);function i(t,n,i){let a=r===`object`?`param "${String(t)}"`:`"${r}.${String(t)}"`,o=e[t];if(!Object.hasOwn(e,t)&&(i?o!==void 0:n!==`function`))throw TypeError(`${a} is invalid: expected own property`);if(i&&o===void 0)return;let s=typeof o;if(s!==n||o===null)throw TypeError(`${a} is invalid: expected ${n}, got ${s}`)}let a=(e,t)=>Object.entries(e).forEach(([e,n])=>i(e,n,t));a(t,!1),a(n,!0)}var F=BigInt(0),I=BigInt(1),Fe=BigInt(2),Ie=BigInt(3),Le=BigInt(4),Re=BigInt(5),ze=BigInt(7),Be=BigInt(8),Ve=BigInt(9),He=BigInt(15),Ue=BigInt(16),We=BigInt(`0x10000000000000000`);function L(e,t){if(t<=F)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=F?n:t+n}function Ge(e,t,n){if(n<=I)throw Error(`pow: expected modulus > 1, got `+n);if(typeof t!=`bigint`)throw TypeError(`invalid exponent: expected bigint, got `+typeof t);if(t<F)throw Error(`invalid exponent, negatives unsupported`);if(t===F)return I;if(t===I)return e;let r=e%n;if(r<F&&(r+=n),t<We){let e=I;for(;t>F;)t&I&&(e=e*r%n),r=r*r%n,t>>=I;return e}let i=[];for(;t>F;)i.push(Number(t&He)),t>>=Le;let a=Array(16);a[0]=I,a[1]=r;for(let e=2;e<16;e++)a[e]=a[e-1]*r%n;let o=a[i[i.length-1]];for(let e=i.length-2;e>=0;e--){o=o*o%n,o=o*o%n,o=o*o%n,o=o*o%n;let t=i[e];t!==0&&(o=o*a[t]%n)}return o}function Ke(e,t){if(e===F)throw Error(`invert: expected non-zero number`);if(t<=I)throw Error(`invert: expected modulus > 1, got `+t);let n=L(e,t),r=t,i=F,a=I;for(;n!==F;){let e=r/n,t=r-n*e,o=i-a*e;r=n,n=t,i=a,a=o}if(r!==I)throw Error(`invert: does not exist`);return L(i,t)}function qe(e,t){if(t<=I)throw Error(`invertCt: expected prime modulus > 1, got `+t);let n=L(e,t);if(n===F)throw Error(`invertCt: expected non-zero number`);let r=Ge(n,t-Fe,t);if(L(n*r,t)!==I)throw Error(`invertCt: does not exist`);return r}function Je(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function Ye(e,t){if((e&I)===F)throw Error(t+`: expected odd modulus, got `+e)}function Xe(e,t){let n=e,r=(n.ORDER+I)/Le,i=n.pow(t,r);return Je(n,i,t),i}function Ze(e,t){let n=e,r=(n.ORDER-Re)/Be,i=n.mul(t,Fe),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,Fe),a),c=n.mul(o,n.sub(s,n.ONE));return Je(n,c,t),c}function Qe(e){let t=ct(e),n=$e(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+ze)/Ue;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return Je(n,m,t),m})}function $e(e){if(e<Ie)throw Error(`sqrt is not defined for small field`);Ye(e,`tonelliShanks`);let t=e-I,n=0;for(;t%Fe===F;)t/=Fe,n++;let r=Fe,i=ct(e);for(;it(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return Xe;let a=i.pow(r,t),o=(t+I)/Fe;return function(e,r){let i=e;if(i.is0(r))return r;if(it(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))throw Error(`Cannot find square root: probably non-prime P`);let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=I<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function et(e){return Ye(e,`Fp.sqrt`),e%Le===Ie?Xe:e%Be===Re?Ze:e%Ue===Ve?Qe(e):$e(e)}var tt=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function nt(e){if(se(e,`field`),typeof e.ORDER!=`bigint`)throw TypeError(`param "ORDER" is invalid: expected bigint, got `+typeof e.ORDER);ye(e.BYTES,`BYTES`),ye(e.BITS,`BITS`);for(let t of tt)ce(e[t],`field.`+t);if(e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=I)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function rt(e,t,n=!1){nt(e),ie(t,`nums`),_e(n,`passZero`);let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function it(e,t){nt(e);let n=e;Ye(n.ORDER,`FpLegendre`);let r=(n.ORDER-I)/Fe,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function at(e,t){if(t!==void 0&&ae(t),e<=F)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=je(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${n})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}var ot=new WeakMap,st=class{ORDER;BITS;BYTES;isLE;ZERO=F;ONE=I;_lengths;_mod;constructor(e,t={}){if(e<=I)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,`sqrt`,{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=at(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return L(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return F<=e&&e<this.ORDER}is0(e){return e===F}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&I)===I}neg(e){return L(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return L(e*e,this.ORDER)}add(e,t){return L(e+t,this.ORDER)}sub(e,t){return L(e-t,this.ORDER)}mul(e,t){return L(e*t,this.ORDER)}pow(e,t){return Ge(e,t,this.ORDER)}div(e,t){return L(e*Ke(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Ke(e,this.ORDER)}sqrt(e){let t=ot.get(this);return t||ot.set(this,t=et(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Te(e,this.BYTES):we(e,this.BYTES)}fromBytes(e,t=!1){P(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?Ce(e):Se(e);if(o&&(s=L(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return rt(this,e,!0)}cmov(e,t,n){return _e(n,`condition`),n?t:e}};function ct(e,t={}){return Object.freeze(st.prototype),new st(e,t)}function lt(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=I)throw Error(`field order must be greater than 1`);let t=je(e-I);return Math.ceil(t/8)}function ut(e){let t=lt(e);return t+Math.ceil(t/2)}function dt(e,t,n=!1){P(e);let r=e.length,i=lt(t),a=Math.max(ut(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=L(n?Ce(e):Se(e),t-I)+I;return n?Te(o,i):we(o,i)}var ft=BigInt(0),pt=BigInt(1),mt=BigInt(4),ht=16,gt=128,_t=5,vt=(()=>2**31)();function yt(e){let t=e;if(typeof t!=`function`)throw TypeError(`"Point" expected constructor, got type=`+typeof e);ce(t.fromAffine,`Point.fromAffine`),ce(t.fromBytes,`Point.fromBytes`),ce(t.fromHex,`Point.fromHex`),se(t.BASE,`Point.BASE`),se(t.ZERO,`Point.ZERO`),nt(t.Fp),nt(t.Fn)}function bt(e,t){yt(e),wt(t,e);let n=rt(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function xt(e,t,n=1){if(!Number.isSafeInteger(e)||e<n||e>t)throw Error(`invalid window size, expected [`+n+`..`+t+`], got W=`+e)}function St(e,t){let n=e*(4*t+128);if(n>vt)throw Error(`invalid window size: table would need ~`+Math.ceil(n/2**20)+` MiB, max `+vt/2**20+` MiB`)}function Ct(e,t){if(e!==void 0){ce(e,`randomBytes`);try{let n=e(t);if(!fe(n)||n.length!==t)return}catch{return}return e}}function wt(e,t){ie(e,`points`),e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function Tt(e,t,n){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,r)=>{if(!(n===void 0?t.isValid(e):Oe(e)&&e<n))throw Error(`invalid scalar at index `+r)})}var Et=new WeakMap;function Dt(e){return Et.get(e)||1}function Ot(e,t){let n=e.double(),r=[e];for(let e=1;e<t;e++)r.push(r[e-1].add(n));return r}function kt(e,t){let n=2**t,r=n/2,i=BigInt(n-1),a=[];for(;e>ft;){let t=0;e&pt&&(t=Number(e&i),t>=r&&(t-=n),e-=BigInt(t)),a.push(t),e>>=pt}return a}function At(e,t,n){let r=2**t,i=r/2,a=BigInt(r-1),o=BigInt(t),s=[];for(let t=0;t<n;t++){let t=Number(e&a);e>>=o,t>i&&(t-=r,e+=pt),s.push(t)}if(e!==ft)throw Error(`invalid wnaf`);return s}function jt(e,t,n){let r=0;for(let e of n)r=Math.max(r,e.length);let i=e;for(let e=r-1;e>=0;e--){e!==r-1&&(i=i.double());for(let r=0;r<n.length;r++){let a=n[r][e];if(a){let e=t[r][Math.abs(a)-1>>1];i=i.add(a<0?e.negate():e)}}}return i}var Mt=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,t){yt(e),this.randomBytes=Ct(t,ht),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,t,n){let r=Math.ceil(n/t)+1,i=2**(t-1),a=[],o=e;for(let e=0;e<r;e++){let e=o;for(let t=0;t<i;t++)a.push(e),e=e.add(o);o=a[a.length-1].double()}return{W:t,bits:n,windows:r,comp:a}}wnafCachedCT(e,t){let{W:n,windows:r,comp:i}=e,a=2**(n-1),o=At(t,n,r),s=this.ZERO,c=this.BASE;for(let e=0;e<r;e++){let t=o[e],n=e*a,r=Math.abs(t)-1,l=i[n];for(let e=1;e<a;e++)l=e===r?i[n+e]:l;let u=l.negate();t===0?c=c.add(i[n]):s=s.add(t<0?u:l)}return{p:s,f:c}}getWnafPrecomputes(e,t,n,r){let i=this.wnafPrecomputes.get(t),a=i?.find(t=>t.W===e&&t.bits===n);return a||(a=this.buildWnafTable(t,e,n),typeof r==`function`&&(a={...a,comp:r(a.comp)}),i||(i=[],this.wnafPrecomputes.set(t,i)),i.push(a)),a}assertPoint(e){if(!(e instanceof this.Point))throw TypeError(`"point" expected Point instance, got type=`+typeof e)}validateMulInput(e,t){if(this.assertPoint(e),!ke(t,pt,this.Point.Fn.ORDER))throw Error(`invalid scalar`)}runCT(e,t,n,r){let i=Dt(e);return i===1?this.fixedWindowCT(e,t,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,r),t)}mulCT(e,t,n){return this.validateMulInput(e,t),this.runCT(e,t,this.bits,n)}mulCTBlinded(e,t,n){if(this.validateMulInput(e,t),this.randomBytes===void 0)throw Error(`randomBytes is required for scalar blinding`);let r=this.Point.Fn.BITS+gt,i=this.randomBytes(ht);if(!fe(i)||i.length!==ht)throw Error(`randomBytes returned invalid byte array`);i[0]=i[0]&63|128;let a=t+Se(i)*this.Point.Fn.ORDER;return this.runCT(e,a,r,n)}fixedWindowCT(e,t,n){let r=_t,i=1<<r,a=Me(r),o=Array(i);o[0]=this.ZERO;for(let t=1;t<i;t++)o[t]=o[t-1].add(e);let s=Math.ceil(n/r),c=this.ZERO;for(let e=s-1;e>=0;e--){if(e!==s-1)for(let e=0;e<r;e++)c=c.double();let n=Number(t>>BigInt(e*r)&a),l=o[0];for(let e=1;e<i;e++)l=e===n?o[e]:l;c=c.add(l)}return{p:c,f:c}}shouldBlind(e,t){return this.randomBytes===void 0?!1:t===pt?!0:e===this.BASE?(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded):!1}mulSecret(e,t,n,r){return this.shouldBlind(e,n)?this.mulCTBlinded(e,t,r):this.mulCT(e,t,r)}mulUnsafe(e,t,n){if(this.assertPoint(e),!Oe(t))throw Error(`invalid scalar`);let r=Dt(e);if(r===1||t>=this.Point.Fn.ORDER)return Nt(this.Point,[e],[t],!0);let i=this.getWnafPrecomputes(r,e,this.bits,n);return this.wnafCachedCT(i,t).p}setWindowSize(e,t){this.assertPoint(e),xt(t,this.bits),St((Math.ceil((this.bits+gt)/t)+1)*2**(t-1),this.Point.Fp.BYTES),Et.set(e,t),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Dt(e)!==1}};function Nt(e,t,n,r=!1){if(yt(e),wt(t,e),_e(r,`allowOversized`),Tt(n,e.Fn,r?e.Fn.ORDER**mt:void 0),t.length!==n.length)throw Error(`arrays of points and scalars must have equal length`);let i=t.map(e=>Ot(e,4)),a=n.map(e=>kt(e,4));return jt(e.ZERO,i,a)}function Pt(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return nt(t),t}else return ct(e,{isLE:n})}function Ft(e,t,n={},r){if(e!==`weierstrass`&&e!==`edwards`)throw Error(`expected curve type "weierstrass" or "edwards"`);if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);Pe(n);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(Oe(n)&&n!==ft))throw Error(`CURVE.${e} must be positive bigint`)}let i=Pt(t.p,n.Fp,r),a=Pt(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function It(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var Lt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(h(e),m(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`expected Hash instance`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),x(r)}update(e){return v(this),this.iHash.update(e),this}digestInto(e){v(this),y(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const Rt=(()=>{let e=((e,t,n)=>new Lt(e,t).update(n).digest());return e.create=(e,t)=>new Lt(e,t),e})();var zt=BigInt(0),Bt={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Bt;if(ye(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(oe(t,`data`),t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=be(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?be(i.length/2|128):``;return be(e)+a+i+t},decode(e,t){let{Err:n}=Bt;t=P(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.decode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Bt;if(ve(e),e<zt)throw new t(`integer: negative integers are not allowed`);let n=be(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Bt;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return Se(e)}},toSig(e,t){let{Err:n,_int:r,_tlv:i}=Bt;if(t!==void 0&&(ye(t,`maxScalarBytes`),t<1))throw new n(`invalid signature: maxScalarBytes must be positive`);let a=P(e,void 0,`signature`),{v:o,l:s}=i.decode(48,a);if(s.length)throw new n(`invalid signature: left bytes after parsing`);let{v:c,l}=i.decode(2,o),{v:u,l:d}=i.decode(2,l);if(d.length)throw new n(`invalid signature: left bytes after parsing`);if(t!==void 0&&(c.length>t||u.length>t))throw new n(`invalid signature: integer too large`);return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:n}=Bt;Pe(e,{r:`bigint`,s:`bigint`},{},`sig`);let r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};const Vt=(()=>(Object.freeze(Bt._tlv),Object.freeze(Bt._int),Object.freeze(Bt)))();var Ht=(e,t)=>(e+(e>=0?t:-t)/Jt)/t;function Ut(e,t,n){Ae(`scalar`,e,Kt,n);let[[r,i],[a,o]]=t,s=Ht(o*e,n),c=Ht(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<Kt,f=u<Kt;d&&(l=-l),f&&(u=-u);let p=Me(Math.ceil(je(n)/2))+qt;if(l<Kt||l>=p||u<Kt||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Wt(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function Gt(e,t){Pe(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return _e(n.lowS,`lowS`),_e(n.prehash,`prehash`),n.format!==void 0&&Wt(n.format),n}var Kt=BigInt(0),qt=BigInt(1),Jt=BigInt(2),Yt=BigInt(3),Xt=BigInt(4);function Zt(e,t={}){let n=Ft(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;Pe(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,randomBytes:`function`});let{endo:c,allowInfinityPoint:l,clearCofactor:u,isTorsionFree:d,fromBytes:f,toBytes:p}=t,m=t.randomBytes===void 0?pe:t.randomBytes;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let h=c?{beta:c.beta,basises:c.basises.map(e=>[...e])}:void 0,g=$t(r,i);function _(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function v(e,t,n){if(t.is0()){if(!l)throw Error(`bad point: ZERO`);return Uint8Array.of(0)}let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return _e(n,`isCompressed`),n?(_(),ue(Qt(!r.isOdd(a)),o)):ue(Uint8Array.of(4),o,r.toBytes(a))}function y(e){P(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=g,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=w(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}_();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!T(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let b=p===void 0?v:p,x=f===void 0?y:f,S=r.mul(a.b,Yt),C=r.is0(a.a)?e=>r.ZERO:e=>r.mul(a.a,e);function w(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function T(e,t){let n=r.sqr(t),i=w(e);return r.eql(n,i)}if(!T(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let E=r.mul(r.pow(a.a,Yt),Xt),D=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(E,D)))throw Error(`bad curve params: a or b`);function O(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return typeof t==`object`&&t?r.create(t):t}function k(e){if(!(e instanceof N))throw Error(`Weierstrass Point expected`)}function A(e){if(!h||!h.basises)throw Error(`no endo`);return Ut(e,h.basises,i.ORDER)}function j(e,t,n,a){if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(h){let{k1neg:i,k1:o,k2neg:s,k2:c}=A(a),l=new N(r.mul(n.X,h.beta),n.Y,n.Z);e.push(i?n.negate():n,s?l.negate():l),t.push(o,c)}else e.push(n),t.push(a)}let M=new WeakSet;class N{static BASE=new N(a.Gx,a.Gy,r.ONE);static ZERO=new N(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=O(`x`,e),this.Y=O(`y`,t,!0),this.Z=O(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof N)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?N.ZERO:new N(t,n,r.ONE)}static fromBytes(e){let t=N.fromAffine(x(P(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return N.fromBytes(de(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=6,t=!0){return te.setWindowSize(this,e),t||this.multiply(Yt),this}assertValidity(){let e=this;if(e.is0()){if(l&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}if(M.has(e))return;let{x:t,y:n}=e.toAffine();if(!r.isValid(t)||!r.isValid(n))throw Error(`bad point: x or y not field elements`);if(!T(t,n))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);M.add(e)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){k(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new N(this.X,r.neg(this.Y),this.Z)}double(){let{X:e,Y:t,Z:n}=this,i=r.ZERO,a=r.ZERO,o=r.ZERO,s=r.mul(e,e),c=r.mul(t,t),l=r.mul(n,n),u=r.mul(e,t);return u=r.add(u,u),o=r.mul(e,n),o=r.add(o,o),i=C(o),a=r.mul(S,l),a=r.add(i,a),i=r.sub(c,a),a=r.add(c,a),a=r.mul(i,a),i=r.mul(u,i),o=r.mul(S,o),l=C(l),u=r.sub(s,l),u=C(u),u=r.add(u,o),o=r.add(s,s),s=r.add(o,s),s=r.add(s,l),s=r.mul(s,u),a=r.add(a,s),l=r.mul(t,n),l=r.add(l,l),s=r.mul(l,u),i=r.sub(i,s),o=r.mul(l,c),o=r.add(o,o),o=r.add(o,o),new N(i,a,o)}add(e){k(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(t,a),f=r.mul(n,o),p=r.mul(i,s),m=r.add(t,n),h=r.add(a,o);m=r.mul(m,h),h=r.add(d,f),m=r.sub(m,h),h=r.add(t,i);let g=r.add(a,s);return h=r.mul(h,g),g=r.add(d,p),h=r.sub(h,g),g=r.add(n,i),c=r.add(o,s),g=r.mul(g,c),c=r.add(f,p),g=r.sub(g,c),u=C(h),c=r.mul(S,p),u=r.add(c,u),c=r.sub(f,u),u=r.add(f,u),l=r.mul(c,u),f=r.add(d,d),f=r.add(f,d),p=C(p),h=r.mul(S,h),f=r.add(f,p),p=r.sub(d,p),p=C(p),h=r.add(h,p),d=r.mul(f,h),l=r.add(l,d),d=r.mul(g,h),c=r.mul(m,c),c=r.sub(c,d),d=r.mul(m,f),u=r.mul(g,u),u=r.add(u,d),new N(c,l,u)}subtract(e){return k(e),this.add(e.negate())}is0(){return this.equals(N.ZERO)}multiply(e){if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let{p:t,f:n}=te.mulSecret(this,e,o,ee);return ee([t,n])[0]}multiplyUnsafe(e){let t=this,n=e;if(!i.isValid(n))throw RangeError(`invalid scalar: out of range`);if(n===Kt||t.is0())return N.ZERO;if(n===qt)return t;if(te.hasWindowSize(this))return te.mulUnsafe(t,n,ee);let r=[],a=[];return j(r,a,t,n),Nt(N,r,a)}mulAddUnsafe(e,t,n){k(t);let r=[],i=[];return j(r,i,this,e),j(r,i,t,n),Nt(N,r,i)}toAffine(e){let t=this,n=e;if(n!=null&&!r.isValid(n))throw RangeError(`"invertedZ" expected valid field element`);let{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){return o===qt?!0:d?d(N,this):te.mulUnsafe(this,s).is0()}clearCofactor(){return o===qt?this:u?u(N,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===qt?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return _e(e,`isCompressed`),this.assertValidity(),b(N,this,e)}toHex(e=!0){return le(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let ee=e=>bt(N,e),te=new Mt(N,m);return te.bits>=6&&N.BASE.precompute(6),Object.freeze(N.prototype),Object.freeze(N),N}function Qt(e){return Uint8Array.of(e?2:3)}function $t(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function en(e,t={}){yt(e);let{Fn:n}=e,r=t.randomBytes===void 0?pe:t.randomBytes,i=Object.assign($t(e.Fp,n),{seed:Math.max(ut(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!e.fromBytes(t).is0()}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,dt(P(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!fe(e))return;let s=P(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t),o=e.fromBytes(r);if(o.is0())throw Error(`invalid public key: point at infinity`);return o.multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=It(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function tn(e,t,n={}){yt(e);let r=t;h(r),Pe(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let i=Object.assign({},n),a=i.randomBytes===void 0?pe:i.randomBytes,o=i.hmac===void 0?(e,t)=>Rt(r,e,t):i.hmac,{Fp:s,Fn:c}=e,{ORDER:l,BITS:u}=c,d=ut(l),f=Ct(a,d),{keygen:p,getPublicKey:m,getSharedSecret:g,utils:_,lengths:v}=en(e,i),y={prehash:!0,lowS:typeof i.lowS==`boolean`?i.lowS:!0,format:`compact`,extraEntropy:!1},b=l*Jt+qt<s.ORDER;function x(e){return e>l>>qt}function S(e,t){if(!c.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function C(){if(!s.isOdd)throw Error(`Field doesn't support isOdd`)}function w(e,t,n){return C(),(e===n?0:2)|Number(s.isOdd(t))}function T(){if(b)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function E(e,t){Wt(t);let n=v.signature;return P(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class D{r;s;recovery;constructor(e,t,n){if(this.r=S(`r`,e),this.s=S(`s`,t),n!=null){if(T(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=y.format){E(e,t);let n;if(t===`der`){if(e.length>2*c.BYTES+16)throw new Vt.Err(`invalid signature: DER signature too long`);let{r:t,s:n}=Vt.toSig(P(e),c.BYTES+1);return new D(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=v.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new D(c.fromBytes(i),c.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(de(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new D(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+l:n;if(!s.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let o=s.toBytes(a),u=e.fromBytes(ue(Qt((i&1)==0),o)),d=c.inv(a),f=k(P(t,void 0,`msgHash`)),p=c.create(-f*d),m=c.create(r*d),h=e.BASE.mulAddUnsafe(p,u,m);if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return x(this.s)}toBytes(e=y.format){if(Wt(e),e===`der`)return de(Vt.hexFromSig(this));let{r:t,s:n}=this,r=c.toBytes(t),i=c.toBytes(n);return e===`recovered`?(T(),ue(Uint8Array.of(this.assertRecovery()),r,i)):ue(r,i)}toHex(e){return le(this.toBytes(e))}}Object.freeze(D.prototype),Object.freeze(D);let O=i.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=Se(e),n=e.length*8-u;return n>0?t>>BigInt(n):t}:i.bits2int,k=i.bits2int_modN===void 0?function(e){return c.create(O(e))}:i.bits2int_modN,A=Me(u);function j(e){return Ae(`num < 2^`+u,e,Kt,A),c.toBytes(e)}function M(e,t){return P(e,void 0,`message`),t?P(r(e),void 0,`prehashed message`):e}function N(t,n,r){let{lowS:i,prehash:o,extraEntropy:s}=Gt(r,y);t=M(t,o);let u=k(t),p=c.fromBytes(n);if(!c.isValidNot0(p))throw Error(`invalid private key`);let m=[j(p),j(u)];if(s!=null&&s!==!1){let e=s===!0?a(v.secretKey):s;m.push(P(e,void 0,`extraEntropy`))}let h=ue(...m),g=u;function _(t){let n=O(t);if(!c.isValidNot0(n))return;let r=e.BASE.multiply(n).toAffine(),a=c.create(r.x);if(a===Kt)return;let o;if(f!==void 0){let e=Se(dt(f(d),l)),t=c.inv(c.mul(e,n)),r=c.mul(e,g),i=c.mul(e,p);o=c.create(t*c.create(r+i*a))}else{let e=qe(n,l);o=c.create(e*c.create(g+a*p))}if(o===Kt)return;let s=w(r.x,r.y,a),u=o;return i&&x(o)&&(u=c.neg(o),s^=1),new D(a,u,b?void 0:s)}return{seed:h,k2sig:_}}function ee(e,t,n={}){let{seed:i,k2sig:a}=N(e,t,n);return Ne(r.outputLen,c.BYTES,o)(i,a).toBytes(n.format)}function te(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=Gt(i,y);if(r=P(r,void 0,`publicKey`),n=M(n,o),!fe(t)){let e=t instanceof D?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}E(t,s);try{let i=D.fromBytes(t,s),o=e.fromBytes(r);if(o.is0()||a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=k(n),f=c.inv(u),p=c.create(d*f),m=c.create(l*f),h=e.BASE.mulAddUnsafe(p,o,m);if(h.is0())return!1;let g=h.toAffine();return!(c.create(g.x)!==l||s===`recovered`&&i.recovery!==w(g.x,g.y,l))}catch{return!1}}function ne(e,t,n={}){let{prehash:r}=Gt(n,y);return t=M(t,r),D.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:p,getPublicKey:m,getSharedSecret:g,utils:_,lengths:v,Point:e,sign:ee,verify:te,recoverPublicKey:ne,Signature:D,hash:r})}var nn=(()=>BigInt(2**32-1))(),rn=BigInt(32);function an(e,t=!1){return t?{h:Number(e&nn),l:Number(e>>rn&nn)}:{h:Number(e>>rn&nn)|0,l:Number(e&nn)|0}}function on(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=an(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}var sn=e=>e/2**32|0,cn=e=>e>>>0;function ln(e,t,n,r){let i=sn(n),a=cn(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}function un(e,t,n){return e&t^~e&n}function dn(e,t,n){return e&t^e&n^t&n}var fn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=S(this.buffer)}update(e){v(this),m(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=S(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){v(this),y(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),ln(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:S(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};const pn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mn=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]),hn=new Uint32Array(64),gn=class extends fn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)hn[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=hn[e-15],n=hn[e-2],r=C(t,7)^C(t,18)^t>>>3;hn[e]=(C(n,17)^C(n,19)^n>>>10)+hn[e-7]+r+hn[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=C(o,6)^C(o,11)^C(o,25),u=l+t+un(o,s,c)+mn[e]+hn[e]|0,d=(C(n,2)^C(n,13)^C(n,22))+dn(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){x(hn)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),x(this.buffer)}},_n=class extends gn{constructor(){super(32,pn)}};const vn=te(()=>new _n,re(1));function yn(e,t=`n`){if(typeof e!=`number`)throw TypeError(`wrong u32 integer "${t}": expected number, got type=${typeof e}`);if(!Number.isSafeInteger(e)||e<0||e>4294967295)throw RangeError(`wrong u32 integer "${t}": expected 0..4294967295, got ${e}`);return e}function bn(e){return yn(e,`x`),(e&e-1)==0&&e!==0}function xn(e,t){if(yn(e),typeof t!=`number`)throw TypeError(`"bits" expected number, got type=`+typeof t);if(!Number.isSafeInteger(t)||t<0||t>32)throw Error(`expected integer 0 <= bits <= 32, got ${t}`);let n=0;for(let r=0;r<t;r++,e>>>=1)n=n<<1|e&1;return n>>>0}function Sn(e){return yn(e),31-Math.clz32(e)}function Cn(e){if(!e||typeof e!=`object`||typeof e.length!=`number`)throw TypeError(`"values" expected array-like, got type=`+typeof e);let t=e.length;if(!bn(t))throw Error(`expected positive power-of-two length, got `+t);let n=Sn(t);for(let r=0;r<t;r++){let t=xn(r,n);if(r<t){let n=e[r];e[r]=e[t],e[t]=n}}return e}const wn=(e,t)=>{Pe(t,{N:`number`,roots:`object`,dit:`boolean`},{invertButterflies:`boolean`,skipStages:`number`,brp:`boolean`},`coreOpts`);let{N:n,roots:r,dit:i,invertButterflies:a=!1,skipStages:o=0,brp:s=!0}=t;yn(n,`coreOpts.N`);let c=Sn(n);if(!bn(n))throw Error(`FFT: Polynomial size should be power of two`);yn(o,`coreOpts.skipStages`);let l=c===0?0:c-1;if(o>l)throw Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${l}`);if(r.length!==n)throw Error(`FFT: wrong roots length: expected ${n}, got ${r.length}`);let u=i!==a;return t=>{if(t.length!==n)throw Error(`FFT: wrong Polynomial length`);i&&s&&Cn(t);for(let s=0,l=1;s<c-o;s++){let d=i?s+1+o:c-s,f=1<<d,p=f>>1,m=n>>d;for(let o=0;o<n;o+=f)for(let s=0,c=l++;s<p;s++){let l=a?i?n-c:c:s*m,d=o+s,f=o+s+p,h=r[l],g=t[f],_=t[d];if(u){let n=e.mul(g,h);t[d]=e.add(_,n),t[f]=e.sub(_,n)}else a?(t[d]=e.add(g,_),t[f]=e.mul(e.sub(g,_),h)):(t[d]=e.add(_,g),t[f]=e.mul(e.sub(_,g),h))}}return!i&&s&&Cn(t),t}},Tn=tn(Zt((()=>({p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)}))()),vn);var En=BigInt(0),Dn=BigInt(1),On=BigInt(2),kn=BigInt(7),An=BigInt(256),jn=BigInt(113),Mn=[],Nn=[],Pn=[];for(let e=0,t=Dn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Mn.push(2*(5*r+n)),Nn.push((e+1)*(e+2)/2%64);let i=En;for(let e=0;e<7;e++)t=(t<<Dn^(t>>kn)*jn)%An,t&On&&(i^=Dn<<(Dn<<BigInt(e))-Dn);Pn.push(i)}var Fn=on(Pn,!0),In=Fn[0],Ln=Fn[1],Rn=(e,t,n)=>e<<n|t>>>32-n,zn=(e,t,n)=>t<<n|e>>>32-n,Bn=(e,t,n)=>t<<n-32|e>>>64-n,Vn=(e,t,n)=>e<<n-32|t>>>64-n,Hn=(e,t,n)=>n>32?Bn(e,t,n):Rn(e,t,n),Un=(e,t,n)=>n>32?Vn(e,t,n):zn(e,t,n),Wn=new Uint32Array(10);function Gn(e,t=24){if(!(e instanceof Uint32Array))throw TypeError(`"s" expected Uint32Array(50), got type=`+typeof e);if(e.length!==50)throw RangeError(`"s" expected Uint32Array(50), got length=`+e.length);if(f(t,`rounds`),t<1||t>24)throw Error(`"rounds" expected integer 1..24`);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)Wn[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let n=(t+8)%10,r=(t+2)%10,i=Wn[r],a=Wn[r+1],o=Hn(i,a,1)^Wn[n],s=Un(i,a,1)^Wn[n+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=s}let t=e[2],r=e[3];for(let n=0;n<24;n++){let i=Nn[n],a=Hn(t,r,i),o=Un(t,r,i),s=Mn[n];t=e[s],r=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];e[t]^=~e[t+2]&e[t+4],e[t+1]^=~e[t+3]&e[t+5],e[t+2]^=~e[t+4]&e[t+6],e[t+3]^=~e[t+5]&e[t+7],e[t+4]^=~e[t+6]&e[t+8],e[t+5]^=~e[t+7]&e[t+9],e[t+6]^=~e[t+8]&n,e[t+7]^=~e[t+9]&r,e[t+8]^=~n&i,e[t+9]^=~r&a}e[0]^=In[n],e[1]^=Ln[n]}x(Wn)}var Kn=class e{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;enableXOF=!1;rounds;constructor(e,t,n,r=!1,i=24){if(f(e,`blockLen`),f(t,`suffix`),f(i,`rounds`),p(r,`enableXOF`),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.canXOF=r,this.rounds=i,f(n,`outputLen`),!(0<e&&e<200))throw Error(`"blockLen" must be 1..199`);this.state=new Uint8Array(200),this.state32=b(this.state)}clone(){return this._cloneInto()}keccak(){D(this.state32),Gn(this.state32,this.rounds),D(this.state32),this.posOut=0,this.pos=0}update(e){v(this),m(e);let{blockLen:t,state:n,state32:r}=this,i=e.length,a=t%4==0&&e.byteOffset%4==0,o=t/4,s=a&&i>=t?b(e):void 0;for(let a=0;a<i;){if(s!==void 0&&this.pos===0&&a%4==0&&i-a>=t){for(let e=0,t=a/4;e<o;e++)r[e]^=s[t+e];a+=t,this.pos=t,this.keccak();continue}let c=Math.min(t-this.pos,i-a);for(let t=0;t<c;t++)n[this.pos++]^=e[a++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){v(this,!1),m(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not enabled`);return this.writeInto(e)}xof(e){return f(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(y(e,this),this.finished)throw Error(`digest() was already called`);this.writeInto(e.length===this.outputLen?e:e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,x(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||=new e(n,r,i,o,a),t.blockLen=n,t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}},qn=(e,t,n,r={})=>te(()=>new Kn(t,e,n),r);const Jn=qn(6,136,32,re(8)),Yn=qn(6,72,64,re(10));var Xn=(e,t,n,r={})=>te((r={})=>(r=ee({},r),new Kn(t,e,r.dkLen===void 0?n:r.dkLen,!0)),r);const Zn=Xn(31,168,16,re(11)),Qn=Xn(31,136,32,re(12));var $n=m;const er=ne;function tr(e,t,n=()=>{}){if(!Array.isArray(e))throw TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}function nr(e,t=`object`){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`);return e}function rr(e,t){if(e=m(e),t=m(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function ir(e){return new Uint8Array(m(e))}function ar(e,...t){let n=e=>typeof e==`number`?e:e.bytesLen,r=t.reduce((e,t)=>e+n(t),0);return{bytesLen:r,encode:i=>{let a=new Uint8Array(r);for(let r=0,o=0;r<t.length;r++){let s=t[r],c=n(s),l=typeof s==`number`?i[r]:s.encode(i[r]);m(l,c,e),a.set(l,o),typeof s!=`number`&&l.fill(0),o+=c}return a},decode:i=>{m(i,r,e);let a=[];for(let e of t){let t=n(e),r=i.subarray(0,t);a.push(typeof e==`number`?r:e.decode(r)),i=i.subarray(t)}return a}}}function or(e,t){let n=e,r=t*n.bytesLen;return{bytesLen:r,encode:e=>{let i=tr(e,`u`);if(i.length!==t)throw RangeError(`vecCoder.encode: wrong length=${i.length}. Expected: ${t}`);let a=new Uint8Array(r);for(let e=0,t=0;e<i.length;e++){let r=n.encode(i[e]);a.set(r,t),r.fill(0),t+=r.length}return a},decode:e=>{m(e,r);let t=[];for(let r=0;r<e.length;r+=n.bytesLen)t.push(n.decode(e.subarray(r,r+n.bytesLen)));return t}}}function R(...e){for(let t of e)if(Array.isArray(t))for(let e of t)e.fill(0);else t.fill(0)}function sr(e){if(f(e,`bits`),e>32)throw RangeError(`"bits" expected <= 32, got `+e);return e===32?4294967295:~(-1<<e)>>>0}const cr=e=>{let{newPoly:t,N:n,Q:r,F:i,ROOT_OF_UNITY:a,brvBits:o,isKyber:s}=e,c=(e,t=r)=>{let n=e%t|0;return(n>=0?n|0:t+n|0)|0},l=(e,t=r)=>{let n=c(e,t)|0;return(n>t>>1?n-t|0:n)|0};function u(){let e=t(n);for(let t=0;t<n;t++){let n=xn(t,o),i=BigInt(a)**BigInt(n)%BigInt(r);e[t]=Number(i)|0}return e}let d=u(),f=e=>{throw Error(`not implemented`)},p=s?{add:(e,t)=>{let n=e+t|0;return n>=r?n-r|0:n},sub:(e,t)=>{let n=e-t|0;return n<0?n+r|0:n},mul:(e,t)=>c((e|0)*(t|0))|0,inv:f}:{add:(e,t)=>c((e|0)+(t|0))|0,sub:(e,t)=>c((e|0)-(t|0))|0,mul:(e,t)=>c((e|0)*(t|0))|0,inv:f},m={N:n,roots:d,invertButterflies:!0,skipStages:s?1:0,brp:!1},h=wn(p,{dit:!1,...m}),g=wn(p,{dit:!0,...m}),_={encode:e=>h(e),decode:e=>{g(e);for(let t=0;t<e.length;t++)e[t]=c(i*e[t]);return e}};return{mod:c,smod:l,nttZetas:d,NTT:{encode:e=>_.encode(e),decode:e=>_.decode(e)},bitsCoder:(e,r)=>{for(let t=0,r=0;t<n;t++)r+=e,r>32&&sr(r),r%=8;let i=sr(e),a=n/8*e;return{bytesLen:a,encode:t=>{let n=t,o=new Uint8Array(a);for(let t=0,a=0,s=0,c=0;t<n.length;t++)for(a|=(r.encode(n[t])&i)<<s,s+=e;s>=8;s-=8,a>>=8)o[c++]=a&255;return o},decode:a=>{let o=t(n);for(let t=0,n=0,s=0,c=0;t<a.length;t++)for(n|=a[t]<<s,s+=8;s>=e;s-=e,n>>=e)o[c++]=r.decode(n&i);return o}}}}},lr=(e=>(t,n)=>{n||=e.blockLen;let r=new Uint8Array(t.length+2);r.set(t);let i=t.length,a=new Uint8Array(n),o=e.create({}),s=0,c=0;return{stats:()=>({calls:s,xofs:c}),get:(t,n)=>(r[i+0]=t,r[i+1]=n,o.destroy(),o=e.create({}).update(r),s++,()=>(c++,o.xofInto(a))),clean:()=>{o.destroy(),R(a,r)}}})(Zn);var z=256,B=3329,V=cr({N:z,Q:B,F:3303,ROOT_OF_UNITY:17,newPoly:e=>new Uint16Array(e),brvBits:7,isKyber:!0});const ur=(()=>Object.freeze({512:Object.freeze({N:z,Q:B,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128}),768:Object.freeze({N:z,Q:B,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192}),1024:Object.freeze({N:z,Q:B,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256})}))();var dr=e=>{if(e>=12)return{encode:e=>e,decode:e=>e>=B?e-B:e};let t=2**(e-1);return{encode:t=>((t<<e)+B/2)/B,decode:n=>n*B+t>>>e}},fr=e=>V.bitsCoder(e,e===12?{encode:e=>e,decode:e=>e>=B?e-B:e}:{encode:e=>e,decode:e=>e}),pr=e=>e===12?fr(12):V.bitsCoder(e,dr(e));function mr(e,t){let n=e,r=t;for(let e=0;e<z;e++){let t=n[e]+r[e];n[e]=t>=B?t-B:t}}function hr(e,t){let n=e,r=t;for(let e=0;e<z;e++){let t=n[e]-r[e];n[e]=t<0?t+B:t}}function gr(e,t,n,r,i){return{c0:V.mod(V.mod(t*r)*i+e*n),c1:V.mod(e*r+t*n)}}function _r(e,t){let n=e,r=t;for(let e=0;e<z/2;e++){let t=V.nttZetas[64+(e>>1)];e&1&&(t=-t);let{c0:i,c1:a}=gr(n[2*e+0],n[2*e+1],r[2*e+0],r[2*e+1],t);n[2*e+0]=i,n[2*e+1]=a}return n}function vr(e){let t=e,n=new Uint16Array(z);for(let e=0;e<z;){let r=t();if(r.length%3)throw Error(`SampleNTT: unaligned block`);for(let t=0;e<z&&t+3<=r.length;t+=3){let i=(r[t+0]>>0|r[t+1]<<8)&4095,a=(r[t+1]>>4|r[t+2]<<4)&4095;i<B&&(n[e++]=i),e<z&&a<B&&(n[e++]=a)}}return n}var yr=(e,t)=>{let n=new Uint16Array(z),r=b(e);D(r);let i=0;for(let e=0,a=0,o=0,s=0;e<r.length;e++){let c=r[e];for(let e=0;e<32;e++)o+=c&1,c>>=1,i+=1,i===t?(s=o,o=0):i===2*t&&(n[a++]=V.mod(s-o),o=0,i=0)}if(D(r),i)throw Error(`sampleCBD: leftover bits: ${i}`);return n};function br(e,t,n,r){return yr(e(r*z/4,t,n),r)}var xr=e=>{let{K:t,PRF:n,XOF:r,HASH512:i,ETA1:a,ETA2:o,du:s,dv:c}=e,l=pr(1),u=pr(c),d=pr(s),f=ar(`publicKey`,or(pr(12),t),32),p=or(pr(12),t),m=ar(`ciphertext`,or(d,t),u),h=ar(`seed`,32,32),g=(e,r,i,s)=>{let c=[];for(let e=0;e<t;e++)c.push(V.NTT.encode(br(n,s,e,a)));let u=new Uint16Array(z),d=[];for(let i=0;i<t;i++){let a=br(n,s,t+i,o),l=new Uint16Array(z);for(let e=0;e<t;e++)mr(l,_r(r(i,e),c[e]));mr(a,V.NTT.decode(l)),d.push(a),mr(u,_r(e[i],c[i])),R(l)}let f=br(n,s,2*t,o);mr(f,V.NTT.decode(u));let p=l.decode(i);return mr(p,f),R(e,c,u,f),m.encode([d,p])};return{secretCoder:p,lengths:{secretKey:p.bytesLen,publicKey:f.bytesLen,cipherText:m.bytesLen},keygen:e=>{$n(e,32,`seed`);let o=new Uint8Array(33);o.set(e),o[32]=t;let s=i(o),[c,l]=h.decode(s),u=[],d=[];for(let e=0;e<t;e++)u.push(V.NTT.encode(br(n,l,e,a)));let m=r(c);for(let e=0;e<t;e++){let r=V.NTT.encode(br(n,l,t+e,a));for(let n=0;n<t;n++)mr(r,_r(vr(m.get(n,e)),u[n]));d.push(r)}m.clean();let g={publicKey:f.encode([d,c]),secretKey:p.encode(u)};return R(c,l,u,d,o,s),g},encrypt:(e,t,n)=>{let[i,a]=f.decode(e),o=r(a),s=g(i,(e,t)=>vr(o.get(e,t)),t,n);return o.clean(),s},prepare:e=>{let[n,i]=f.decode(e),a=r(i),o=[];for(let e=0;e<t;e++)for(let n=0;n<t;n++)o.push(vr(a.get(e,n)));return a.clean(),{encrypt:(e,r)=>g(n.map(e=>e.slice()),(e,n)=>o[e*t+n].slice(),e,r),clean:()=>R(n,o)}},decrypt:(e,n)=>{let[r,i]=m.decode(e),a=p.decode(n),o=new Uint16Array(z);for(let e=0;e<t;e++)mr(o,_r(a[e],V.NTT.encode(r[e])));hr(i,V.NTT.decode(o));let s=l.encode(i);return R(o,a,r,i),s}}};function Sr(e){let t=e,n=xr(t),{HASH256:r,HASH512:i,KDF:a}=t,{secretCoder:o,lengths:s}=n,c=ar(`secretKey`,s.secretKey,s.publicKey,32,32),l=(e,n)=>{let r=e.subarray(0,384*t.K),i=o.encode(o.decode(ir(r))),a=rr(i,r);if(R(i),!a)throw Error(`ML-KEM.${n}: wrong publicKey modulus`)},u=Object.freeze({...s,seed:64,msg:32,msgRand:32,secretKey:c.bytesLen});return Object.freeze({info:Object.freeze({type:`ml-kem`}),lengths:u,keygen:e=>{let t=e===void 0,i=t?er(64):e,a,o;try{$n(i,64,`seed`);let e=n.keygen(i.subarray(0,32)),t=e.publicKey;return a=e.secretKey,o=r(t),{publicKey:t,secretKey:c.encode([a,t,o,i.subarray(32)])}}finally{a!==void 0&&R(a),o!==void 0&&R(o),t&&R(i)}},getPublicKey:e=>{let[t,n,r,i]=c.decode(e);return Uint8Array.from(n)},encapsulate:(e,t)=>{let a=t===void 0,o=a?er(32):t,c;try{return $n(e,s.publicKey,`publicKey`),$n(o,32,`message`),l(e,`encapsulate`),c=i.create().update(o).update(r(e)).digest(),{cipherText:n.encrypt(e,o,c.subarray(32,64)),sharedSecret:c.subarray(0,32)}}finally{c!==void 0&&R(c.subarray(32)),a&&R(o)}},decapsulate:(e,t)=>{$n(t,c.bytesLen,`secretKey`),$n(e,s.cipherText,`cipherText`);let o=c.bytesLen-96,l=o+32;if(!rr(r(t.subarray(o/2,l)),t.subarray(l,l+32)))throw Error(`invalid secretKey: hash check failed`);let[u,d,f,p]=c.decode(t),m=n.decrypt(e,u),h=i.create().update(m).update(f).digest(),g=h.subarray(0,32),_=n.encrypt(d,m,h.subarray(32,64)),v=rr(e,_),y=a.create({dkLen:32}).update(p).update(e).digest();return R(m,_,h.subarray(32),v?y:g),v?g:y},prepare:e=>{$n(e,s.publicKey,`publicKey`),l(e,`prepare`);let t=ir(e),o=r(t),u=n.prepare(t);return Object.freeze({publicKey:t,encapsulate:e=>{let t=e===void 0,n=t?er(32):e,r;try{return $n(n,32,`message`),r=i.create().update(n).update(o).digest(),{cipherText:u.encrypt(n,r.subarray(32,64)),sharedSecret:r.subarray(0,32)}}finally{r!==void 0&&R(r.subarray(32)),t&&R(n)}},decapsulate:(e,r)=>{$n(r,c.bytesLen,`secretKey`),$n(e,s.cipherText,`cipherText`);let[l,d,f,p]=c.decode(r);if(!rr(d,t)||!rr(f,o))throw Error(`ML-KEM.decapsulate: secretKey does not match prepared publicKey`);let m=n.decrypt(e,l),h=i.create().update(m).update(o).digest(),g=h.subarray(0,32),_=u.encrypt(m,h.subarray(32,64)),v=rr(e,_),y=a.create({dkLen:32}).update(p).update(e).digest();return R(m,_,h.subarray(32),v?y:g),v?g:y},clean:u.clean})}})}function Cr(e,t,n){return Qn.create({dkLen:e}).update(t).update(new Uint8Array([n])).digest()}var wr=(()=>({HASH256:Jn,HASH512:Yn,KDF:Qn,XOF:lr,PRF:Cr}))(),Tr=e=>Sr({...wr,...e});const Er=(()=>Tr(ur[768]))();var Dr=(e,t)=>{let n=nr(e,t);return nr(n.lengths,`${t}.lengths`),ce(n.keygen,`${t}.keygen`),ce(n.getPublicKey,`${t}.getPublicKey`),ce(n.encapsulate,`${t}.encapsulate`),ce(n.decapsulate,`${t}.decapsulate`),n};function Or(e,t){let n=f(e,t);if(n===0)throw RangeError(`"${t}" expected integer greater than 0, got 0`);return n}function kr(e,t){let n=ar(t,...e.map(e=>{if(typeof e.lengths[t]!=`number`)throw Error(`wrong length: `+t);return Or(e.lengths[t],t)}));return Or(n.bytesLen,t),n}function Ar(e,t,...n){let r=t,i=n,a=kr(i,`seed`),o=kr(i,`publicKey`),s=Or(e===void 0?a.bytesLen:e,`realSeedLen`);function c(e){m(e,s);let t=r(e,a.bytesLen),n=t.buffer===e.buffer?ir(t):t,o=[],c=[],l=[],u=[],d=!1;try{for(let e of a.decode(n))o.push(ir(e));for(let e=0;e<i.length;e++){let t=i[e].keygen(o[e]);c.push(t.secretKey),l.push(ir(t.secretKey)),u.push(t.publicKey)}return d=!0,{secretKey:l,publicKey:u}}finally{R(n,o,c),d||R(l)}}let l=e=>{let t=e===void 0?er(s):ir(e),n;try{let{publicKey:e,secretKey:r}=c(t);try{n={secretKey:t,publicKey:o.encode(e)}}finally{R(e,r)}return n}finally{n||R(t)}};return{info:{lengths:{seed:s,publicKey:o.bytesLen,secretKey:s}},getPublicKey:e=>{let t=l(e);return R(t.secretKey),t.publicKey},keygen:l,expandDecapsulationKey:c,realSeedLen:s}}function jr(e,t,n,r,...i){if(e!==void 0&&Or(e,`realSeedLen`),t!==void 0&&Or(t,`realMsgLen`),typeof n!=`function`)throw TypeError(`"expandSeed" expected function, got type=`+typeof n);if(typeof r!=`function`)throw TypeError(`"combiner" expected function, got type=`+typeof r);let a=r,o=i;if(o.length===0)throw RangeError(`combineKEMS requires at least one KEM`);for(let e=0;e<o.length;e++)Dr(o[e],`kems[${e}]`);let s=Ar(e,n,...o),c=kr(o,`cipherText`),l=kr(o,`publicKey`),d=kr(o,`msg`),f=Or(t===void 0?d.bytesLen:t,`realMsgLen`),p=Object.freeze({...s.info.lengths,msg:f,msgRand:d.bytesLen,cipherText:c.bytesLen}),h=(e,t,n)=>{let r=a(e,t,n);try{return ir(m(r,f,`sharedSecret`))}catch(n){if(u(r)){let n=e=>r.buffer===e.buffer&&r.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<r.byteOffset+r.byteLength;e.some(n)||t.some(n)||R(r)}throw n}};return Object.freeze({lengths:p,getPublicKey:s.getPublicKey,keygen:s.keygen,encapsulate(e,t=er(d.bytesLen)){let n=l.decode(e),r=d.decode(t),i=[],a=[];try{for(let e=0;e<o.length;e++){let t=o[e].encapsulate(n[e],r[e]);i.push(t.sharedSecret),a.push(t.cipherText)}let e=c.encode(a);return{sharedSecret:h(n,a,i),cipherText:e}}finally{R(i,a)}},decapsulate(e,t){let n=c.decode(e),{publicKey:r,secretKey:i}=s.expandDecapsulationKey(t),a=[];try{for(let e=0;e<o.length;e++)a.push(o[e].decapsulate(n[e],i[e]));return h(r,n,a)}finally{R(i,a)}}})}function Mr(e,t,n,r){let i=e.Point.Fn;if(!i)throw Error(`no Point.Fn`);function a(n){let r;for(let e=0,a=t;;e=a,a+=t){if(a>n.length)throw Error(`rejection sampling failed`);if(r=i.fromBytes(n.subarray(e,a),!0),i.isValidNot0(r))break}let a=i.toBytes(i.create(r));return{secretKey:a,publicKey:e.getPublicKey(a,!1)}}let o=(t,n)=>e.getSharedSecret(n,t).subarray(1);return{lengths:{secretKey:t,publicKey:n,seed:r,msg:r,cipherText:n},keygen(e=er(r)){return m(e,r,`seed`),a(e)},getPublicKey(t){return e.getPublicKey(t,!1)},encapsulate(t,n=er(r)){m(n,r,`rand`);let i;try{return i=a(n).secretKey,{sharedSecret:o(t,i),cipherText:e.getPublicKey(i,!1)}}finally{i&&R(i)}},decapsulate:o}}function Nr(e,t,n,r){let{secretKey:i,publicKeyUncompressed:a}=n.lengths;if(!i||!a)throw Error(`wrong curve`);let o=Mr(n,i,a,r),s=64+r;return jr(32,32,e=>(m(e,32),Qn(e,{dkLen:s})),(t,n,r)=>Jn(ue(r[0],r[1],n[1],t[1],De(e))),t,o)}const Pr=(()=>Nr(`MLKEM768-P256`,Er,Tn,128))();function Fr(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Fr(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Ir(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Fr(e))&&(r&&(r+=` `),r+=t);return r}var Lr=Ir,Rr=t(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),zr=t((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),Br=t((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),Vr=t(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),Hr=t(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),Ur=t((e=>{var t=zr().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),Wr=t((e=>{var t=zr().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Gr=t((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),Kr=t((e=>{var t=Br(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),qr=t((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),Jr=t((e=>{var t=qr();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),Yr=t(((e,t)=>{var n=Jr();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),Xr=t((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Zr=t((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
1
+ import{i as e,t}from"./rolldown-runtime-C4Xdq4VV.js";import{a as n,c as r,h as i,l as a,o,s,tn as c}from"./vendor-react-BtC4HVVO.js";import{S as l}from"./vendor-icons-other-BTYC6Wvz.js";function u(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}var d=e=>e?`"${e}" `:``;function f(e,t=``){if(typeof e!=`number`)throw TypeError(d(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(d(t)+`expected integer >= 0, got `+e);return e}function p(e,t=``){if(typeof e!=`boolean`)throw TypeError(d(t)+`expected boolean, got type=`+typeof e);return e}function m(e,t,n=``){if(u(e)&&(t===void 0||e.length===t))return e;t!==void 0&&f(t,`length`);let r=u(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=d(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}function h(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`expected hash wrapped by utils.createHasher`);if(f(e.outputLen),f(e.blockLen),e.outputLen<1||e.blockLen<1)throw Error(`hash blockLen / outputLen must be >= 1`)}var g=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)},_=(e,t)=>{g(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,`__proto__`))throw TypeError(`"${t}.__proto__" is not allowed`)};function v(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function y(e,t){m(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function b(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function x(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function S(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function C(e,t){return e<<32-t|e>>>t}const w=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function T(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function E(e){for(let t=0;t<e.length;t++)e[t]=T(e[t]);return e}const D=w?e=>e:E;var O=(()=>typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`)(),k=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function A(e){if(m(e),O)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=k[e[n]];return t}function j(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function M(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(O)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=j(e.charCodeAt(i)),a=j(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function N(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];m(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function ee(e,t,n=`opts`){return _(e,`defaults`),t!==void 0&&_(t,n),Object.assign(Object.create(null),e,t)}function te(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=ee({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function ne(e=32){f(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}const re=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ie(e,t,n=()=>{}){if(!Array.isArray(e))throw TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}const P=(e,t,n)=>m(e,t,n),ae=f;function oe(e,t=``){if(typeof e!=`string`){let n=t&&`"${t}" `;throw TypeError(n+`expected string, got type=`+typeof e)}return e}function se(e,t=`object`){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`);return e}function ce(e,t){if(typeof e!=`function`)throw TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}const le=A,ue=(...e)=>N(...e),de=e=>M(e),fe=u,pe=e=>ne(e);var me=BigInt(0),he=BigInt(1),ge=e=>e?`"${e}" `:``;function _e(e,t=``){if(typeof e!=`boolean`)throw TypeError(ge(t)+`expected boolean, got type=`+typeof e);return e}function ve(e){if(typeof e==`bigint`){if(!Oe(e))throw RangeError(`positive bigint expected, got `+e)}else ae(e);return e}function ye(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function be(e){let t=ve(e).toString(16);return t.length&1?`0`+t:t}function xe(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?me:BigInt(`0x`+e)}function Se(e){return xe(A(e))}function Ce(e){return xe(A(Ee(m(e)).reverse()))}function we(e,t){if(f(t),t===0)throw Error(`zero output length is invalid`);e=ve(e);let n=t*2,r=e.toString(16);if(r.length>n)throw RangeError(`number is too large`);return M(r.padStart(n,`0`))}function Te(e,t){return we(e,t).reverse()}function Ee(e){return Uint8Array.from(P(e))}function De(e){if(typeof e!=`string`)throw TypeError(`ascii string expected, got `+typeof e);return Uint8Array.from(e,(t,n)=>{let r=t.charCodeAt(0);if(t.length!==1||r>127)throw RangeError(`string contains non-ASCII character "${e[n]}" with code ${r} at position ${n}`);return r})}function Oe(e){return typeof e==`bigint`&&me<=e}function ke(e,t,n){return Oe(e)&&Oe(t)&&Oe(n)&&t<=e&&e<n}function Ae(e,t,n,r){if(!ke(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function je(e){if(e<me)throw Error(`expected non-negative bigint, got `+e);return e===me?0:e.toString(2).length}const Me=e=>(ye(e,`n`),(he<<BigInt(e))-he);function Ne(e,t,n){if(f(e,`hashLen`),f(t,`qByteLen`),typeof n!=`function`)throw TypeError(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=Uint8Array.of(),a=Uint8Array.of(0),o=Uint8Array.of(1),s=r(e),c=r(e),l=0,u=()=>{s.fill(1),c.fill(0),l=0},d=(...e)=>n(c,ue(s,...e)),p=(e=i)=>{c=d(a,e),s=d(),e.length!==0&&(c=d(o,e),s=d())},m=()=>{if(l++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){s=d();let t=s.slice();n.push(t),e+=s.length}return ue(...n)};return(e,t)=>{u(),p(e);let n;for(;(n=t(m()))===void 0;)p();return u(),n}}function Pe(e,t={},n={},r=`object`){se(e,r),se(t,`fields`),se(n,`optFields`);function i(t,n,i){let a=r===`object`?`param "${String(t)}"`:`"${r}.${String(t)}"`,o=e[t];if(!Object.hasOwn(e,t)&&(i?o!==void 0:n!==`function`))throw TypeError(`${a} is invalid: expected own property`);if(i&&o===void 0)return;let s=typeof o;if(s!==n||o===null)throw TypeError(`${a} is invalid: expected ${n}, got ${s}`)}let a=(e,t)=>Object.entries(e).forEach(([e,n])=>i(e,n,t));a(t,!1),a(n,!0)}var F=BigInt(0),I=BigInt(1),Fe=BigInt(2),Ie=BigInt(3),Le=BigInt(4),Re=BigInt(5),ze=BigInt(7),Be=BigInt(8),Ve=BigInt(9),He=BigInt(15),Ue=BigInt(16),We=BigInt(`0x10000000000000000`);function L(e,t){if(t<=F)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=F?n:t+n}function Ge(e,t,n){if(n<=I)throw Error(`pow: expected modulus > 1, got `+n);if(typeof t!=`bigint`)throw TypeError(`invalid exponent: expected bigint, got `+typeof t);if(t<F)throw Error(`invalid exponent, negatives unsupported`);if(t===F)return I;if(t===I)return e;let r=e%n;if(r<F&&(r+=n),t<We){let e=I;for(;t>F;)t&I&&(e=e*r%n),r=r*r%n,t>>=I;return e}let i=[];for(;t>F;)i.push(Number(t&He)),t>>=Le;let a=Array(16);a[0]=I,a[1]=r;for(let e=2;e<16;e++)a[e]=a[e-1]*r%n;let o=a[i[i.length-1]];for(let e=i.length-2;e>=0;e--){o=o*o%n,o=o*o%n,o=o*o%n,o=o*o%n;let t=i[e];t!==0&&(o=o*a[t]%n)}return o}function Ke(e,t){if(e===F)throw Error(`invert: expected non-zero number`);if(t<=I)throw Error(`invert: expected modulus > 1, got `+t);let n=L(e,t),r=t,i=F,a=I;for(;n!==F;){let e=r/n,t=r-n*e,o=i-a*e;r=n,n=t,i=a,a=o}if(r!==I)throw Error(`invert: does not exist`);return L(i,t)}function qe(e,t){if(t<=I)throw Error(`invertCt: expected prime modulus > 1, got `+t);let n=L(e,t);if(n===F)throw Error(`invertCt: expected non-zero number`);let r=Ge(n,t-Fe,t);if(L(n*r,t)!==I)throw Error(`invertCt: does not exist`);return r}function Je(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function Ye(e,t){if((e&I)===F)throw Error(t+`: expected odd modulus, got `+e)}function Xe(e,t){let n=e,r=(n.ORDER+I)/Le,i=n.pow(t,r);return Je(n,i,t),i}function Ze(e,t){let n=e,r=(n.ORDER-Re)/Be,i=n.mul(t,Fe),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,Fe),a),c=n.mul(o,n.sub(s,n.ONE));return Je(n,c,t),c}function Qe(e){let t=ct(e),n=$e(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+ze)/Ue;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return Je(n,m,t),m})}function $e(e){if(e<Ie)throw Error(`sqrt is not defined for small field`);Ye(e,`tonelliShanks`);let t=e-I,n=0;for(;t%Fe===F;)t/=Fe,n++;let r=Fe,i=ct(e);for(;it(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return Xe;let a=i.pow(r,t),o=(t+I)/Fe;return function(e,r){let i=e;if(i.is0(r))return r;if(it(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))throw Error(`Cannot find square root: probably non-prime P`);let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=I<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function et(e){return Ye(e,`Fp.sqrt`),e%Le===Ie?Xe:e%Be===Re?Ze:e%Ue===Ve?Qe(e):$e(e)}var tt=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function nt(e){if(se(e,`field`),typeof e.ORDER!=`bigint`)throw TypeError(`param "ORDER" is invalid: expected bigint, got `+typeof e.ORDER);ye(e.BYTES,`BYTES`),ye(e.BITS,`BITS`);for(let t of tt)ce(e[t],`field.`+t);if(e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=I)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function rt(e,t,n=!1){nt(e),ie(t,`nums`),_e(n,`passZero`);let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function it(e,t){nt(e);let n=e;Ye(n.ORDER,`FpLegendre`);let r=(n.ORDER-I)/Fe,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function at(e,t){if(t!==void 0&&ae(t),e<=F)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=je(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${n})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}var ot=new WeakMap,st=class{ORDER;BITS;BYTES;isLE;ZERO=F;ONE=I;_lengths;_mod;constructor(e,t={}){if(e<=I)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,`sqrt`,{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=at(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return L(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return F<=e&&e<this.ORDER}is0(e){return e===F}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&I)===I}neg(e){return L(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return L(e*e,this.ORDER)}add(e,t){return L(e+t,this.ORDER)}sub(e,t){return L(e-t,this.ORDER)}mul(e,t){return L(e*t,this.ORDER)}pow(e,t){return Ge(e,t,this.ORDER)}div(e,t){return L(e*Ke(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Ke(e,this.ORDER)}sqrt(e){let t=ot.get(this);return t||ot.set(this,t=et(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Te(e,this.BYTES):we(e,this.BYTES)}fromBytes(e,t=!1){P(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?Ce(e):Se(e);if(o&&(s=L(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return rt(this,e,!0)}cmov(e,t,n){return _e(n,`condition`),n?t:e}};function ct(e,t={}){return Object.freeze(st.prototype),new st(e,t)}function lt(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=I)throw Error(`field order must be greater than 1`);let t=je(e-I);return Math.ceil(t/8)}function ut(e){let t=lt(e);return t+Math.ceil(t/2)}function dt(e,t,n=!1){P(e);let r=e.length,i=lt(t),a=Math.max(ut(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=L(n?Ce(e):Se(e),t-I)+I;return n?Te(o,i):we(o,i)}var ft=BigInt(0),pt=BigInt(1),mt=BigInt(4),ht=16,gt=128,_t=5,vt=(()=>2**31)();function yt(e){let t=e;if(typeof t!=`function`)throw TypeError(`"Point" expected constructor, got type=`+typeof e);ce(t.fromAffine,`Point.fromAffine`),ce(t.fromBytes,`Point.fromBytes`),ce(t.fromHex,`Point.fromHex`),se(t.BASE,`Point.BASE`),se(t.ZERO,`Point.ZERO`),nt(t.Fp),nt(t.Fn)}function bt(e,t){yt(e),wt(t,e);let n=rt(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function xt(e,t,n=1){if(!Number.isSafeInteger(e)||e<n||e>t)throw Error(`invalid window size, expected [`+n+`..`+t+`], got W=`+e)}function St(e,t){let n=e*(4*t+128);if(n>vt)throw Error(`invalid window size: table would need ~`+Math.ceil(n/2**20)+` MiB, max `+vt/2**20+` MiB`)}function Ct(e,t){if(e!==void 0){ce(e,`randomBytes`);try{let n=e(t);if(!fe(n)||n.length!==t)return}catch{return}return e}}function wt(e,t){ie(e,`points`),e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function Tt(e,t,n){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,r)=>{if(!(n===void 0?t.isValid(e):Oe(e)&&e<n))throw Error(`invalid scalar at index `+r)})}var Et=new WeakMap;function Dt(e){return Et.get(e)||1}function Ot(e,t){let n=e.double(),r=[e];for(let e=1;e<t;e++)r.push(r[e-1].add(n));return r}function kt(e,t){let n=2**t,r=n/2,i=BigInt(n-1),a=[];for(;e>ft;){let t=0;e&pt&&(t=Number(e&i),t>=r&&(t-=n),e-=BigInt(t)),a.push(t),e>>=pt}return a}function At(e,t,n){let r=2**t,i=r/2,a=BigInt(r-1),o=BigInt(t),s=[];for(let t=0;t<n;t++){let t=Number(e&a);e>>=o,t>i&&(t-=r,e+=pt),s.push(t)}if(e!==ft)throw Error(`invalid wnaf`);return s}function jt(e,t,n){let r=0;for(let e of n)r=Math.max(r,e.length);let i=e;for(let e=r-1;e>=0;e--){e!==r-1&&(i=i.double());for(let r=0;r<n.length;r++){let a=n[r][e];if(a){let e=t[r][Math.abs(a)-1>>1];i=i.add(a<0?e.negate():e)}}}return i}var Mt=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,t){yt(e),this.randomBytes=Ct(t,ht),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,t,n){let r=Math.ceil(n/t)+1,i=2**(t-1),a=[],o=e;for(let e=0;e<r;e++){let e=o;for(let t=0;t<i;t++)a.push(e),e=e.add(o);o=a[a.length-1].double()}return{W:t,bits:n,windows:r,comp:a}}wnafCachedCT(e,t){let{W:n,windows:r,comp:i}=e,a=2**(n-1),o=At(t,n,r),s=this.ZERO,c=this.BASE;for(let e=0;e<r;e++){let t=o[e],n=e*a,r=Math.abs(t)-1,l=i[n];for(let e=1;e<a;e++)l=e===r?i[n+e]:l;let u=l.negate();t===0?c=c.add(i[n]):s=s.add(t<0?u:l)}return{p:s,f:c}}getWnafPrecomputes(e,t,n,r){let i=this.wnafPrecomputes.get(t),a=i?.find(t=>t.W===e&&t.bits===n);return a||(a=this.buildWnafTable(t,e,n),typeof r==`function`&&(a={...a,comp:r(a.comp)}),i||(i=[],this.wnafPrecomputes.set(t,i)),i.push(a)),a}assertPoint(e){if(!(e instanceof this.Point))throw TypeError(`"point" expected Point instance, got type=`+typeof e)}validateMulInput(e,t){if(this.assertPoint(e),!ke(t,pt,this.Point.Fn.ORDER))throw Error(`invalid scalar`)}runCT(e,t,n,r){let i=Dt(e);return i===1?this.fixedWindowCT(e,t,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,r),t)}mulCT(e,t,n){return this.validateMulInput(e,t),this.runCT(e,t,this.bits,n)}mulCTBlinded(e,t,n){if(this.validateMulInput(e,t),this.randomBytes===void 0)throw Error(`randomBytes is required for scalar blinding`);let r=this.Point.Fn.BITS+gt,i=this.randomBytes(ht);if(!fe(i)||i.length!==ht)throw Error(`randomBytes returned invalid byte array`);i[0]=i[0]&63|128;let a=t+Se(i)*this.Point.Fn.ORDER;return this.runCT(e,a,r,n)}fixedWindowCT(e,t,n){let r=_t,i=1<<r,a=Me(r),o=Array(i);o[0]=this.ZERO;for(let t=1;t<i;t++)o[t]=o[t-1].add(e);let s=Math.ceil(n/r),c=this.ZERO;for(let e=s-1;e>=0;e--){if(e!==s-1)for(let e=0;e<r;e++)c=c.double();let n=Number(t>>BigInt(e*r)&a),l=o[0];for(let e=1;e<i;e++)l=e===n?o[e]:l;c=c.add(l)}return{p:c,f:c}}shouldBlind(e,t){return this.randomBytes===void 0?!1:t===pt?!0:e===this.BASE?(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded):!1}mulSecret(e,t,n,r){return this.shouldBlind(e,n)?this.mulCTBlinded(e,t,r):this.mulCT(e,t,r)}mulUnsafe(e,t,n){if(this.assertPoint(e),!Oe(t))throw Error(`invalid scalar`);let r=Dt(e);if(r===1||t>=this.Point.Fn.ORDER)return Nt(this.Point,[e],[t],!0);let i=this.getWnafPrecomputes(r,e,this.bits,n);return this.wnafCachedCT(i,t).p}setWindowSize(e,t){this.assertPoint(e),xt(t,this.bits),St((Math.ceil((this.bits+gt)/t)+1)*2**(t-1),this.Point.Fp.BYTES),Et.set(e,t),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Dt(e)!==1}};function Nt(e,t,n,r=!1){if(yt(e),wt(t,e),_e(r,`allowOversized`),Tt(n,e.Fn,r?e.Fn.ORDER**mt:void 0),t.length!==n.length)throw Error(`arrays of points and scalars must have equal length`);let i=t.map(e=>Ot(e,4)),a=n.map(e=>kt(e,4));return jt(e.ZERO,i,a)}function Pt(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return nt(t),t}else return ct(e,{isLE:n})}function Ft(e,t,n={},r){if(e!==`weierstrass`&&e!==`edwards`)throw Error(`expected curve type "weierstrass" or "edwards"`);if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);Pe(n);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(Oe(n)&&n!==ft))throw Error(`CURVE.${e} must be positive bigint`)}let i=Pt(t.p,n.Fp,r),a=Pt(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function It(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var Lt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(h(e),m(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`expected Hash instance`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),x(r)}update(e){return v(this),this.iHash.update(e),this}digestInto(e){v(this),y(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const Rt=(()=>{let e=((e,t,n)=>new Lt(e,t).update(n).digest());return e.create=(e,t)=>new Lt(e,t),e})();var zt=BigInt(0),Bt={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Bt;if(ye(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(oe(t,`data`),t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=be(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?be(i.length/2|128):``;return be(e)+a+i+t},decode(e,t){let{Err:n}=Bt;t=P(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.decode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Bt;if(ve(e),e<zt)throw new t(`integer: negative integers are not allowed`);let n=be(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Bt;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return Se(e)}},toSig(e,t){let{Err:n,_int:r,_tlv:i}=Bt;if(t!==void 0&&(ye(t,`maxScalarBytes`),t<1))throw new n(`invalid signature: maxScalarBytes must be positive`);let a=P(e,void 0,`signature`),{v:o,l:s}=i.decode(48,a);if(s.length)throw new n(`invalid signature: left bytes after parsing`);let{v:c,l}=i.decode(2,o),{v:u,l:d}=i.decode(2,l);if(d.length)throw new n(`invalid signature: left bytes after parsing`);if(t!==void 0&&(c.length>t||u.length>t))throw new n(`invalid signature: integer too large`);return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:n}=Bt;Pe(e,{r:`bigint`,s:`bigint`},{},`sig`);let r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};const Vt=(()=>(Object.freeze(Bt._tlv),Object.freeze(Bt._int),Object.freeze(Bt)))();var Ht=(e,t)=>(e+(e>=0?t:-t)/Jt)/t;function Ut(e,t,n){Ae(`scalar`,e,Kt,n);let[[r,i],[a,o]]=t,s=Ht(o*e,n),c=Ht(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<Kt,f=u<Kt;d&&(l=-l),f&&(u=-u);let p=Me(Math.ceil(je(n)/2))+qt;if(l<Kt||l>=p||u<Kt||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Wt(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function Gt(e,t){Pe(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return _e(n.lowS,`lowS`),_e(n.prehash,`prehash`),n.format!==void 0&&Wt(n.format),n}var Kt=BigInt(0),qt=BigInt(1),Jt=BigInt(2),Yt=BigInt(3),Xt=BigInt(4);function Zt(e,t={}){let n=Ft(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;Pe(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,randomBytes:`function`});let{endo:c,allowInfinityPoint:l,clearCofactor:u,isTorsionFree:d,fromBytes:f,toBytes:p}=t,m=t.randomBytes===void 0?pe:t.randomBytes;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let h=c?{beta:c.beta,basises:c.basises.map(e=>[...e])}:void 0,g=$t(r,i);function _(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function v(e,t,n){if(t.is0()){if(!l)throw Error(`bad point: ZERO`);return Uint8Array.of(0)}let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return _e(n,`isCompressed`),n?(_(),ue(Qt(!r.isOdd(a)),o)):ue(Uint8Array.of(4),o,r.toBytes(a))}function y(e){P(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=g,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=w(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}_();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!T(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let b=p===void 0?v:p,x=f===void 0?y:f,S=r.mul(a.b,Yt),C=r.is0(a.a)?e=>r.ZERO:e=>r.mul(a.a,e);function w(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function T(e,t){let n=r.sqr(t),i=w(e);return r.eql(n,i)}if(!T(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let E=r.mul(r.pow(a.a,Yt),Xt),D=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(E,D)))throw Error(`bad curve params: a or b`);function O(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return typeof t==`object`&&t?r.create(t):t}function k(e){if(!(e instanceof N))throw Error(`Weierstrass Point expected`)}function A(e){if(!h||!h.basises)throw Error(`no endo`);return Ut(e,h.basises,i.ORDER)}function j(e,t,n,a){if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(h){let{k1neg:i,k1:o,k2neg:s,k2:c}=A(a),l=new N(r.mul(n.X,h.beta),n.Y,n.Z);e.push(i?n.negate():n,s?l.negate():l),t.push(o,c)}else e.push(n),t.push(a)}let M=new WeakSet;class N{static BASE=new N(a.Gx,a.Gy,r.ONE);static ZERO=new N(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=O(`x`,e),this.Y=O(`y`,t,!0),this.Z=O(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof N)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?N.ZERO:new N(t,n,r.ONE)}static fromBytes(e){let t=N.fromAffine(x(P(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return N.fromBytes(de(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=6,t=!0){return te.setWindowSize(this,e),t||this.multiply(Yt),this}assertValidity(){let e=this;if(e.is0()){if(l&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}if(M.has(e))return;let{x:t,y:n}=e.toAffine();if(!r.isValid(t)||!r.isValid(n))throw Error(`bad point: x or y not field elements`);if(!T(t,n))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);M.add(e)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){k(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new N(this.X,r.neg(this.Y),this.Z)}double(){let{X:e,Y:t,Z:n}=this,i=r.ZERO,a=r.ZERO,o=r.ZERO,s=r.mul(e,e),c=r.mul(t,t),l=r.mul(n,n),u=r.mul(e,t);return u=r.add(u,u),o=r.mul(e,n),o=r.add(o,o),i=C(o),a=r.mul(S,l),a=r.add(i,a),i=r.sub(c,a),a=r.add(c,a),a=r.mul(i,a),i=r.mul(u,i),o=r.mul(S,o),l=C(l),u=r.sub(s,l),u=C(u),u=r.add(u,o),o=r.add(s,s),s=r.add(o,s),s=r.add(s,l),s=r.mul(s,u),a=r.add(a,s),l=r.mul(t,n),l=r.add(l,l),s=r.mul(l,u),i=r.sub(i,s),o=r.mul(l,c),o=r.add(o,o),o=r.add(o,o),new N(i,a,o)}add(e){k(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(t,a),f=r.mul(n,o),p=r.mul(i,s),m=r.add(t,n),h=r.add(a,o);m=r.mul(m,h),h=r.add(d,f),m=r.sub(m,h),h=r.add(t,i);let g=r.add(a,s);return h=r.mul(h,g),g=r.add(d,p),h=r.sub(h,g),g=r.add(n,i),c=r.add(o,s),g=r.mul(g,c),c=r.add(f,p),g=r.sub(g,c),u=C(h),c=r.mul(S,p),u=r.add(c,u),c=r.sub(f,u),u=r.add(f,u),l=r.mul(c,u),f=r.add(d,d),f=r.add(f,d),p=C(p),h=r.mul(S,h),f=r.add(f,p),p=r.sub(d,p),p=C(p),h=r.add(h,p),d=r.mul(f,h),l=r.add(l,d),d=r.mul(g,h),c=r.mul(m,c),c=r.sub(c,d),d=r.mul(m,f),u=r.mul(g,u),u=r.add(u,d),new N(c,l,u)}subtract(e){return k(e),this.add(e.negate())}is0(){return this.equals(N.ZERO)}multiply(e){if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let{p:t,f:n}=te.mulSecret(this,e,o,ee);return ee([t,n])[0]}multiplyUnsafe(e){let t=this,n=e;if(!i.isValid(n))throw RangeError(`invalid scalar: out of range`);if(n===Kt||t.is0())return N.ZERO;if(n===qt)return t;if(te.hasWindowSize(this))return te.mulUnsafe(t,n,ee);let r=[],a=[];return j(r,a,t,n),Nt(N,r,a)}mulAddUnsafe(e,t,n){k(t);let r=[],i=[];return j(r,i,this,e),j(r,i,t,n),Nt(N,r,i)}toAffine(e){let t=this,n=e;if(n!=null&&!r.isValid(n))throw RangeError(`"invertedZ" expected valid field element`);let{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){return o===qt?!0:d?d(N,this):te.mulUnsafe(this,s).is0()}clearCofactor(){return o===qt?this:u?u(N,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===qt?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return _e(e,`isCompressed`),this.assertValidity(),b(N,this,e)}toHex(e=!0){return le(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let ee=e=>bt(N,e),te=new Mt(N,m);return te.bits>=6&&N.BASE.precompute(6),Object.freeze(N.prototype),Object.freeze(N),N}function Qt(e){return Uint8Array.of(e?2:3)}function $t(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function en(e,t={}){yt(e);let{Fn:n}=e,r=t.randomBytes===void 0?pe:t.randomBytes,i=Object.assign($t(e.Fp,n),{seed:Math.max(ut(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!e.fromBytes(t).is0()}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,dt(P(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!fe(e))return;let s=P(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t),o=e.fromBytes(r);if(o.is0())throw Error(`invalid public key: point at infinity`);return o.multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=It(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function tn(e,t,n={}){yt(e);let r=t;h(r),Pe(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let i=Object.assign({},n),a=i.randomBytes===void 0?pe:i.randomBytes,o=i.hmac===void 0?(e,t)=>Rt(r,e,t):i.hmac,{Fp:s,Fn:c}=e,{ORDER:l,BITS:u}=c,d=ut(l),f=Ct(a,d),{keygen:p,getPublicKey:m,getSharedSecret:g,utils:_,lengths:v}=en(e,i),y={prehash:!0,lowS:typeof i.lowS==`boolean`?i.lowS:!0,format:`compact`,extraEntropy:!1},b=l*Jt+qt<s.ORDER;function x(e){return e>l>>qt}function S(e,t){if(!c.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function C(){if(!s.isOdd)throw Error(`Field doesn't support isOdd`)}function w(e,t,n){return C(),(e===n?0:2)|Number(s.isOdd(t))}function T(){if(b)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function E(e,t){Wt(t);let n=v.signature;return P(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class D{r;s;recovery;constructor(e,t,n){if(this.r=S(`r`,e),this.s=S(`s`,t),n!=null){if(T(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=y.format){E(e,t);let n;if(t===`der`){if(e.length>2*c.BYTES+16)throw new Vt.Err(`invalid signature: DER signature too long`);let{r:t,s:n}=Vt.toSig(P(e),c.BYTES+1);return new D(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=v.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new D(c.fromBytes(i),c.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(de(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new D(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+l:n;if(!s.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let o=s.toBytes(a),u=e.fromBytes(ue(Qt((i&1)==0),o)),d=c.inv(a),f=k(P(t,void 0,`msgHash`)),p=c.create(-f*d),m=c.create(r*d),h=e.BASE.mulAddUnsafe(p,u,m);if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return x(this.s)}toBytes(e=y.format){if(Wt(e),e===`der`)return de(Vt.hexFromSig(this));let{r:t,s:n}=this,r=c.toBytes(t),i=c.toBytes(n);return e===`recovered`?(T(),ue(Uint8Array.of(this.assertRecovery()),r,i)):ue(r,i)}toHex(e){return le(this.toBytes(e))}}Object.freeze(D.prototype),Object.freeze(D);let O=i.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=Se(e),n=e.length*8-u;return n>0?t>>BigInt(n):t}:i.bits2int,k=i.bits2int_modN===void 0?function(e){return c.create(O(e))}:i.bits2int_modN,A=Me(u);function j(e){return Ae(`num < 2^`+u,e,Kt,A),c.toBytes(e)}function M(e,t){return P(e,void 0,`message`),t?P(r(e),void 0,`prehashed message`):e}function N(t,n,r){let{lowS:i,prehash:o,extraEntropy:s}=Gt(r,y);t=M(t,o);let u=k(t),p=c.fromBytes(n);if(!c.isValidNot0(p))throw Error(`invalid private key`);let m=[j(p),j(u)];if(s!=null&&s!==!1){let e=s===!0?a(v.secretKey):s;m.push(P(e,void 0,`extraEntropy`))}let h=ue(...m),g=u;function _(t){let n=O(t);if(!c.isValidNot0(n))return;let r=e.BASE.multiply(n).toAffine(),a=c.create(r.x);if(a===Kt)return;let o;if(f!==void 0){let e=Se(dt(f(d),l)),t=c.inv(c.mul(e,n)),r=c.mul(e,g),i=c.mul(e,p);o=c.create(t*c.create(r+i*a))}else{let e=qe(n,l);o=c.create(e*c.create(g+a*p))}if(o===Kt)return;let s=w(r.x,r.y,a),u=o;return i&&x(o)&&(u=c.neg(o),s^=1),new D(a,u,b?void 0:s)}return{seed:h,k2sig:_}}function ee(e,t,n={}){let{seed:i,k2sig:a}=N(e,t,n);return Ne(r.outputLen,c.BYTES,o)(i,a).toBytes(n.format)}function te(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=Gt(i,y);if(r=P(r,void 0,`publicKey`),n=M(n,o),!fe(t)){let e=t instanceof D?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}E(t,s);try{let i=D.fromBytes(t,s),o=e.fromBytes(r);if(o.is0()||a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=k(n),f=c.inv(u),p=c.create(d*f),m=c.create(l*f),h=e.BASE.mulAddUnsafe(p,o,m);if(h.is0())return!1;let g=h.toAffine();return!(c.create(g.x)!==l||s===`recovered`&&i.recovery!==w(g.x,g.y,l))}catch{return!1}}function ne(e,t,n={}){let{prehash:r}=Gt(n,y);return t=M(t,r),D.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:p,getPublicKey:m,getSharedSecret:g,utils:_,lengths:v,Point:e,sign:ee,verify:te,recoverPublicKey:ne,Signature:D,hash:r})}var nn=(()=>BigInt(2**32-1))(),rn=BigInt(32);function an(e,t=!1){return t?{h:Number(e&nn),l:Number(e>>rn&nn)}:{h:Number(e>>rn&nn)|0,l:Number(e&nn)|0}}function on(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=an(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}var sn=e=>e/2**32|0,cn=e=>e>>>0;function ln(e,t,n,r){let i=sn(n),a=cn(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}function un(e,t,n){return e&t^~e&n}function dn(e,t,n){return e&t^e&n^t&n}var fn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=S(this.buffer)}update(e){v(this),m(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=S(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){v(this),y(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),ln(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:S(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};const pn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mn=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]),hn=new Uint32Array(64),gn=class extends fn{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)hn[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=hn[e-15],n=hn[e-2],r=C(t,7)^C(t,18)^t>>>3;hn[e]=(C(n,17)^C(n,19)^n>>>10)+hn[e-7]+r+hn[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=C(o,6)^C(o,11)^C(o,25),u=l+t+un(o,s,c)+mn[e]+hn[e]|0,d=(C(n,2)^C(n,13)^C(n,22))+dn(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){x(hn)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),x(this.buffer)}},_n=class extends gn{constructor(){super(32,pn)}};const vn=te(()=>new _n,re(1));function yn(e,t=`n`){if(typeof e!=`number`)throw TypeError(`wrong u32 integer "${t}": expected number, got type=${typeof e}`);if(!Number.isSafeInteger(e)||e<0||e>4294967295)throw RangeError(`wrong u32 integer "${t}": expected 0..4294967295, got ${e}`);return e}function bn(e){return yn(e,`x`),(e&e-1)==0&&e!==0}function xn(e,t){if(yn(e),typeof t!=`number`)throw TypeError(`"bits" expected number, got type=`+typeof t);if(!Number.isSafeInteger(t)||t<0||t>32)throw Error(`expected integer 0 <= bits <= 32, got ${t}`);let n=0;for(let r=0;r<t;r++,e>>>=1)n=n<<1|e&1;return n>>>0}function Sn(e){return yn(e),31-Math.clz32(e)}function Cn(e){if(!e||typeof e!=`object`||typeof e.length!=`number`)throw TypeError(`"values" expected array-like, got type=`+typeof e);let t=e.length;if(!bn(t))throw Error(`expected positive power-of-two length, got `+t);let n=Sn(t);for(let r=0;r<t;r++){let t=xn(r,n);if(r<t){let n=e[r];e[r]=e[t],e[t]=n}}return e}const wn=(e,t)=>{Pe(t,{N:`number`,roots:`object`,dit:`boolean`},{invertButterflies:`boolean`,skipStages:`number`,brp:`boolean`},`coreOpts`);let{N:n,roots:r,dit:i,invertButterflies:a=!1,skipStages:o=0,brp:s=!0}=t;yn(n,`coreOpts.N`);let c=Sn(n);if(!bn(n))throw Error(`FFT: Polynomial size should be power of two`);yn(o,`coreOpts.skipStages`);let l=c===0?0:c-1;if(o>l)throw Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${l}`);if(r.length!==n)throw Error(`FFT: wrong roots length: expected ${n}, got ${r.length}`);let u=i!==a;return t=>{if(t.length!==n)throw Error(`FFT: wrong Polynomial length`);i&&s&&Cn(t);for(let s=0,l=1;s<c-o;s++){let d=i?s+1+o:c-s,f=1<<d,p=f>>1,m=n>>d;for(let o=0;o<n;o+=f)for(let s=0,c=l++;s<p;s++){let l=a?i?n-c:c:s*m,d=o+s,f=o+s+p,h=r[l],g=t[f],_=t[d];if(u){let n=e.mul(g,h);t[d]=e.add(_,n),t[f]=e.sub(_,n)}else a?(t[d]=e.add(g,_),t[f]=e.mul(e.sub(g,_),h)):(t[d]=e.add(_,g),t[f]=e.mul(e.sub(_,g),h))}}return!i&&s&&Cn(t),t}},Tn=tn(Zt((()=>({p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)}))()),vn);var En=BigInt(0),Dn=BigInt(1),On=BigInt(2),kn=BigInt(7),An=BigInt(256),jn=BigInt(113),Mn=[],Nn=[],Pn=[];for(let e=0,t=Dn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Mn.push(2*(5*r+n)),Nn.push((e+1)*(e+2)/2%64);let i=En;for(let e=0;e<7;e++)t=(t<<Dn^(t>>kn)*jn)%An,t&On&&(i^=Dn<<(Dn<<BigInt(e))-Dn);Pn.push(i)}var Fn=on(Pn,!0),In=Fn[0],Ln=Fn[1],Rn=(e,t,n)=>e<<n|t>>>32-n,zn=(e,t,n)=>t<<n|e>>>32-n,Bn=(e,t,n)=>t<<n-32|e>>>64-n,Vn=(e,t,n)=>e<<n-32|t>>>64-n,Hn=(e,t,n)=>n>32?Bn(e,t,n):Rn(e,t,n),Un=(e,t,n)=>n>32?Vn(e,t,n):zn(e,t,n),Wn=new Uint32Array(10);function Gn(e,t=24){if(!(e instanceof Uint32Array))throw TypeError(`"s" expected Uint32Array(50), got type=`+typeof e);if(e.length!==50)throw RangeError(`"s" expected Uint32Array(50), got length=`+e.length);if(f(t,`rounds`),t<1||t>24)throw Error(`"rounds" expected integer 1..24`);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)Wn[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let n=(t+8)%10,r=(t+2)%10,i=Wn[r],a=Wn[r+1],o=Hn(i,a,1)^Wn[n],s=Un(i,a,1)^Wn[n+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=s}let t=e[2],r=e[3];for(let n=0;n<24;n++){let i=Nn[n],a=Hn(t,r,i),o=Un(t,r,i),s=Mn[n];t=e[s],r=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];e[t]^=~e[t+2]&e[t+4],e[t+1]^=~e[t+3]&e[t+5],e[t+2]^=~e[t+4]&e[t+6],e[t+3]^=~e[t+5]&e[t+7],e[t+4]^=~e[t+6]&e[t+8],e[t+5]^=~e[t+7]&e[t+9],e[t+6]^=~e[t+8]&n,e[t+7]^=~e[t+9]&r,e[t+8]^=~n&i,e[t+9]^=~r&a}e[0]^=In[n],e[1]^=Ln[n]}x(Wn)}var Kn=class e{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;enableXOF=!1;rounds;constructor(e,t,n,r=!1,i=24){if(f(e,`blockLen`),f(t,`suffix`),f(i,`rounds`),p(r,`enableXOF`),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.canXOF=r,this.rounds=i,f(n,`outputLen`),!(0<e&&e<200))throw Error(`"blockLen" must be 1..199`);this.state=new Uint8Array(200),this.state32=b(this.state)}clone(){return this._cloneInto()}keccak(){D(this.state32),Gn(this.state32,this.rounds),D(this.state32),this.posOut=0,this.pos=0}update(e){v(this),m(e);let{blockLen:t,state:n,state32:r}=this,i=e.length,a=t%4==0&&e.byteOffset%4==0,o=t/4,s=a&&i>=t?b(e):void 0;for(let a=0;a<i;){if(s!==void 0&&this.pos===0&&a%4==0&&i-a>=t){for(let e=0,t=a/4;e<o;e++)r[e]^=s[t+e];a+=t,this.pos=t,this.keccak();continue}let c=Math.min(t-this.pos,i-a);for(let t=0;t<c;t++)n[this.pos++]^=e[a++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){v(this,!1),m(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not enabled`);return this.writeInto(e)}xof(e){return f(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(y(e,this),this.finished)throw Error(`digest() was already called`);this.writeInto(e.length===this.outputLen?e:e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,x(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||=new e(n,r,i,o,a),t.blockLen=n,t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}},qn=(e,t,n,r={})=>te(()=>new Kn(t,e,n),r);const Jn=qn(6,136,32,re(8)),Yn=qn(6,72,64,re(10));var Xn=(e,t,n,r={})=>te((r={})=>(r=ee({},r),new Kn(t,e,r.dkLen===void 0?n:r.dkLen,!0)),r);const Zn=Xn(31,168,16,re(11)),Qn=Xn(31,136,32,re(12));var $n=m;const er=ne;function tr(e,t,n=()=>{}){if(!Array.isArray(e))throw TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}function nr(e,t=`object`){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`);return e}function rr(e,t){if(e=m(e),t=m(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function ir(e){return new Uint8Array(m(e))}function ar(e,...t){let n=e=>typeof e==`number`?e:e.bytesLen,r=t.reduce((e,t)=>e+n(t),0);return{bytesLen:r,encode:i=>{let a=new Uint8Array(r);for(let r=0,o=0;r<t.length;r++){let s=t[r],c=n(s),l=typeof s==`number`?i[r]:s.encode(i[r]);m(l,c,e),a.set(l,o),typeof s!=`number`&&l.fill(0),o+=c}return a},decode:i=>{m(i,r,e);let a=[];for(let e of t){let t=n(e),r=i.subarray(0,t);a.push(typeof e==`number`?r:e.decode(r)),i=i.subarray(t)}return a}}}function or(e,t){let n=e,r=t*n.bytesLen;return{bytesLen:r,encode:e=>{let i=tr(e,`u`);if(i.length!==t)throw RangeError(`vecCoder.encode: wrong length=${i.length}. Expected: ${t}`);let a=new Uint8Array(r);for(let e=0,t=0;e<i.length;e++){let r=n.encode(i[e]);a.set(r,t),r.fill(0),t+=r.length}return a},decode:e=>{m(e,r);let t=[];for(let r=0;r<e.length;r+=n.bytesLen)t.push(n.decode(e.subarray(r,r+n.bytesLen)));return t}}}function R(...e){for(let t of e)if(Array.isArray(t))for(let e of t)e.fill(0);else t.fill(0)}function sr(e){if(f(e,`bits`),e>32)throw RangeError(`"bits" expected <= 32, got `+e);return e===32?4294967295:~(-1<<e)>>>0}const cr=e=>{let{newPoly:t,N:n,Q:r,F:i,ROOT_OF_UNITY:a,brvBits:o,isKyber:s}=e,c=(e,t=r)=>{let n=e%t|0;return(n>=0?n|0:t+n|0)|0},l=(e,t=r)=>{let n=c(e,t)|0;return(n>t>>1?n-t|0:n)|0};function u(){let e=t(n);for(let t=0;t<n;t++){let n=xn(t,o),i=BigInt(a)**BigInt(n)%BigInt(r);e[t]=Number(i)|0}return e}let d=u(),f=e=>{throw Error(`not implemented`)},p=s?{add:(e,t)=>{let n=e+t|0;return n>=r?n-r|0:n},sub:(e,t)=>{let n=e-t|0;return n<0?n+r|0:n},mul:(e,t)=>c((e|0)*(t|0))|0,inv:f}:{add:(e,t)=>c((e|0)+(t|0))|0,sub:(e,t)=>c((e|0)-(t|0))|0,mul:(e,t)=>c((e|0)*(t|0))|0,inv:f},m={N:n,roots:d,invertButterflies:!0,skipStages:s?1:0,brp:!1},h=wn(p,{dit:!1,...m}),g=wn(p,{dit:!0,...m}),_={encode:e=>h(e),decode:e=>{g(e);for(let t=0;t<e.length;t++)e[t]=c(i*e[t]);return e}};return{mod:c,smod:l,nttZetas:d,NTT:{encode:e=>_.encode(e),decode:e=>_.decode(e)},bitsCoder:(e,r)=>{for(let t=0,r=0;t<n;t++)r+=e,r>32&&sr(r),r%=8;let i=sr(e),a=n/8*e;return{bytesLen:a,encode:t=>{let n=t,o=new Uint8Array(a);for(let t=0,a=0,s=0,c=0;t<n.length;t++)for(a|=(r.encode(n[t])&i)<<s,s+=e;s>=8;s-=8,a>>=8)o[c++]=a&255;return o},decode:a=>{let o=t(n);for(let t=0,n=0,s=0,c=0;t<a.length;t++)for(n|=a[t]<<s,s+=8;s>=e;s-=e,n>>=e)o[c++]=r.decode(n&i);return o}}}}},lr=(e=>(t,n)=>{n||=e.blockLen;let r=new Uint8Array(t.length+2);r.set(t);let i=t.length,a=new Uint8Array(n),o=e.create({}),s=0,c=0;return{stats:()=>({calls:s,xofs:c}),get:(t,n)=>(r[i+0]=t,r[i+1]=n,o.destroy(),o=e.create({}).update(r),s++,()=>(c++,o.xofInto(a))),clean:()=>{o.destroy(),R(a,r)}}})(Zn);var z=256,B=3329,V=cr({N:z,Q:B,F:3303,ROOT_OF_UNITY:17,newPoly:e=>new Uint16Array(e),brvBits:7,isKyber:!0});const ur=(()=>Object.freeze({512:Object.freeze({N:z,Q:B,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128}),768:Object.freeze({N:z,Q:B,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192}),1024:Object.freeze({N:z,Q:B,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256})}))();var dr=e=>{if(e>=12)return{encode:e=>e,decode:e=>e>=B?e-B:e};let t=2**(e-1);return{encode:t=>((t<<e)+B/2)/B,decode:n=>n*B+t>>>e}},fr=e=>V.bitsCoder(e,e===12?{encode:e=>e,decode:e=>e>=B?e-B:e}:{encode:e=>e,decode:e=>e}),pr=e=>e===12?fr(12):V.bitsCoder(e,dr(e));function mr(e,t){let n=e,r=t;for(let e=0;e<z;e++){let t=n[e]+r[e];n[e]=t>=B?t-B:t}}function hr(e,t){let n=e,r=t;for(let e=0;e<z;e++){let t=n[e]-r[e];n[e]=t<0?t+B:t}}function gr(e,t,n,r,i){return{c0:V.mod(V.mod(t*r)*i+e*n),c1:V.mod(e*r+t*n)}}function _r(e,t){let n=e,r=t;for(let e=0;e<z/2;e++){let t=V.nttZetas[64+(e>>1)];e&1&&(t=-t);let{c0:i,c1:a}=gr(n[2*e+0],n[2*e+1],r[2*e+0],r[2*e+1],t);n[2*e+0]=i,n[2*e+1]=a}return n}function vr(e){let t=e,n=new Uint16Array(z);for(let e=0;e<z;){let r=t();if(r.length%3)throw Error(`SampleNTT: unaligned block`);for(let t=0;e<z&&t+3<=r.length;t+=3){let i=(r[t+0]>>0|r[t+1]<<8)&4095,a=(r[t+1]>>4|r[t+2]<<4)&4095;i<B&&(n[e++]=i),e<z&&a<B&&(n[e++]=a)}}return n}var yr=(e,t)=>{let n=new Uint16Array(z),r=b(e);D(r);let i=0;for(let e=0,a=0,o=0,s=0;e<r.length;e++){let c=r[e];for(let e=0;e<32;e++)o+=c&1,c>>=1,i+=1,i===t?(s=o,o=0):i===2*t&&(n[a++]=V.mod(s-o),o=0,i=0)}if(D(r),i)throw Error(`sampleCBD: leftover bits: ${i}`);return n};function br(e,t,n,r){return yr(e(r*z/4,t,n),r)}var xr=e=>{let{K:t,PRF:n,XOF:r,HASH512:i,ETA1:a,ETA2:o,du:s,dv:c}=e,l=pr(1),u=pr(c),d=pr(s),f=ar(`publicKey`,or(pr(12),t),32),p=or(pr(12),t),m=ar(`ciphertext`,or(d,t),u),h=ar(`seed`,32,32),g=(e,r,i,s)=>{let c=[];for(let e=0;e<t;e++)c.push(V.NTT.encode(br(n,s,e,a)));let u=new Uint16Array(z),d=[];for(let i=0;i<t;i++){let a=br(n,s,t+i,o),l=new Uint16Array(z);for(let e=0;e<t;e++)mr(l,_r(r(i,e),c[e]));mr(a,V.NTT.decode(l)),d.push(a),mr(u,_r(e[i],c[i])),R(l)}let f=br(n,s,2*t,o);mr(f,V.NTT.decode(u));let p=l.decode(i);return mr(p,f),R(e,c,u,f),m.encode([d,p])};return{secretCoder:p,lengths:{secretKey:p.bytesLen,publicKey:f.bytesLen,cipherText:m.bytesLen},keygen:e=>{$n(e,32,`seed`);let o=new Uint8Array(33);o.set(e),o[32]=t;let s=i(o),[c,l]=h.decode(s),u=[],d=[];for(let e=0;e<t;e++)u.push(V.NTT.encode(br(n,l,e,a)));let m=r(c);for(let e=0;e<t;e++){let r=V.NTT.encode(br(n,l,t+e,a));for(let n=0;n<t;n++)mr(r,_r(vr(m.get(n,e)),u[n]));d.push(r)}m.clean();let g={publicKey:f.encode([d,c]),secretKey:p.encode(u)};return R(c,l,u,d,o,s),g},encrypt:(e,t,n)=>{let[i,a]=f.decode(e),o=r(a),s=g(i,(e,t)=>vr(o.get(e,t)),t,n);return o.clean(),s},prepare:e=>{let[n,i]=f.decode(e),a=r(i),o=[];for(let e=0;e<t;e++)for(let n=0;n<t;n++)o.push(vr(a.get(e,n)));return a.clean(),{encrypt:(e,r)=>g(n.map(e=>e.slice()),(e,n)=>o[e*t+n].slice(),e,r),clean:()=>R(n,o)}},decrypt:(e,n)=>{let[r,i]=m.decode(e),a=p.decode(n),o=new Uint16Array(z);for(let e=0;e<t;e++)mr(o,_r(a[e],V.NTT.encode(r[e])));hr(i,V.NTT.decode(o));let s=l.encode(i);return R(o,a,r,i),s}}};function Sr(e){let t=e,n=xr(t),{HASH256:r,HASH512:i,KDF:a}=t,{secretCoder:o,lengths:s}=n,c=ar(`secretKey`,s.secretKey,s.publicKey,32,32),l=(e,n)=>{let r=e.subarray(0,384*t.K),i=o.encode(o.decode(ir(r))),a=rr(i,r);if(R(i),!a)throw Error(`ML-KEM.${n}: wrong publicKey modulus`)},u=Object.freeze({...s,seed:64,msg:32,msgRand:32,secretKey:c.bytesLen});return Object.freeze({info:Object.freeze({type:`ml-kem`}),lengths:u,keygen:e=>{let t=e===void 0,i=t?er(64):e,a,o;try{$n(i,64,`seed`);let e=n.keygen(i.subarray(0,32)),t=e.publicKey;return a=e.secretKey,o=r(t),{publicKey:t,secretKey:c.encode([a,t,o,i.subarray(32)])}}finally{a!==void 0&&R(a),o!==void 0&&R(o),t&&R(i)}},getPublicKey:e=>{let[t,n,r,i]=c.decode(e);return Uint8Array.from(n)},encapsulate:(e,t)=>{let a=t===void 0,o=a?er(32):t,c;try{return $n(e,s.publicKey,`publicKey`),$n(o,32,`message`),l(e,`encapsulate`),c=i.create().update(o).update(r(e)).digest(),{cipherText:n.encrypt(e,o,c.subarray(32,64)),sharedSecret:c.subarray(0,32)}}finally{c!==void 0&&R(c.subarray(32)),a&&R(o)}},decapsulate:(e,t)=>{$n(t,c.bytesLen,`secretKey`),$n(e,s.cipherText,`cipherText`);let o=c.bytesLen-96,l=o+32;if(!rr(r(t.subarray(o/2,l)),t.subarray(l,l+32)))throw Error(`invalid secretKey: hash check failed`);let[u,d,f,p]=c.decode(t),m=n.decrypt(e,u),h=i.create().update(m).update(f).digest(),g=h.subarray(0,32),_=n.encrypt(d,m,h.subarray(32,64)),v=rr(e,_),y=a.create({dkLen:32}).update(p).update(e).digest();return R(m,_,h.subarray(32),v?y:g),v?g:y},prepare:e=>{$n(e,s.publicKey,`publicKey`),l(e,`prepare`);let t=ir(e),o=r(t),u=n.prepare(t);return Object.freeze({publicKey:t,encapsulate:e=>{let t=e===void 0,n=t?er(32):e,r;try{return $n(n,32,`message`),r=i.create().update(n).update(o).digest(),{cipherText:u.encrypt(n,r.subarray(32,64)),sharedSecret:r.subarray(0,32)}}finally{r!==void 0&&R(r.subarray(32)),t&&R(n)}},decapsulate:(e,r)=>{$n(r,c.bytesLen,`secretKey`),$n(e,s.cipherText,`cipherText`);let[l,d,f,p]=c.decode(r);if(!rr(d,t)||!rr(f,o))throw Error(`ML-KEM.decapsulate: secretKey does not match prepared publicKey`);let m=n.decrypt(e,l),h=i.create().update(m).update(o).digest(),g=h.subarray(0,32),_=u.encrypt(m,h.subarray(32,64)),v=rr(e,_),y=a.create({dkLen:32}).update(p).update(e).digest();return R(m,_,h.subarray(32),v?y:g),v?g:y},clean:u.clean})}})}function Cr(e,t,n){return Qn.create({dkLen:e}).update(t).update(new Uint8Array([n])).digest()}var wr=(()=>({HASH256:Jn,HASH512:Yn,KDF:Qn,XOF:lr,PRF:Cr}))(),Tr=e=>Sr({...wr,...e});const Er=(()=>Tr(ur[768]))();var Dr=(e,t)=>{let n=nr(e,t);return nr(n.lengths,`${t}.lengths`),ce(n.keygen,`${t}.keygen`),ce(n.getPublicKey,`${t}.getPublicKey`),ce(n.encapsulate,`${t}.encapsulate`),ce(n.decapsulate,`${t}.decapsulate`),n};function Or(e,t){let n=f(e,t);if(n===0)throw RangeError(`"${t}" expected integer greater than 0, got 0`);return n}function kr(e,t){let n=ar(t,...e.map(e=>{if(typeof e.lengths[t]!=`number`)throw Error(`wrong length: `+t);return Or(e.lengths[t],t)}));return Or(n.bytesLen,t),n}function Ar(e,t,...n){let r=t,i=n,a=kr(i,`seed`),o=kr(i,`publicKey`),s=Or(e===void 0?a.bytesLen:e,`realSeedLen`);function c(e){m(e,s);let t=r(e,a.bytesLen),n=t.buffer===e.buffer?ir(t):t,o=[],c=[],l=[],u=[],d=!1;try{for(let e of a.decode(n))o.push(ir(e));for(let e=0;e<i.length;e++){let t=i[e].keygen(o[e]);c.push(t.secretKey),l.push(ir(t.secretKey)),u.push(t.publicKey)}return d=!0,{secretKey:l,publicKey:u}}finally{R(n,o,c),d||R(l)}}let l=e=>{let t=e===void 0?er(s):ir(e),n;try{let{publicKey:e,secretKey:r}=c(t);try{n={secretKey:t,publicKey:o.encode(e)}}finally{R(e,r)}return n}finally{n||R(t)}};return{info:{lengths:{seed:s,publicKey:o.bytesLen,secretKey:s}},getPublicKey:e=>{let t=l(e);return R(t.secretKey),t.publicKey},keygen:l,expandDecapsulationKey:c,realSeedLen:s}}function jr(e,t,n,r,...i){if(e!==void 0&&Or(e,`realSeedLen`),t!==void 0&&Or(t,`realMsgLen`),typeof n!=`function`)throw TypeError(`"expandSeed" expected function, got type=`+typeof n);if(typeof r!=`function`)throw TypeError(`"combiner" expected function, got type=`+typeof r);let a=r,o=i;if(o.length===0)throw RangeError(`combineKEMS requires at least one KEM`);for(let e=0;e<o.length;e++)Dr(o[e],`kems[${e}]`);let s=Ar(e,n,...o),c=kr(o,`cipherText`),l=kr(o,`publicKey`),d=kr(o,`msg`),f=Or(t===void 0?d.bytesLen:t,`realMsgLen`),p=Object.freeze({...s.info.lengths,msg:f,msgRand:d.bytesLen,cipherText:c.bytesLen}),h=(e,t,n)=>{let r=a(e,t,n);try{return ir(m(r,f,`sharedSecret`))}catch(n){if(u(r)){let n=e=>r.buffer===e.buffer&&r.byteOffset<e.byteOffset+e.byteLength&&e.byteOffset<r.byteOffset+r.byteLength;e.some(n)||t.some(n)||R(r)}throw n}};return Object.freeze({lengths:p,getPublicKey:s.getPublicKey,keygen:s.keygen,encapsulate(e,t=er(d.bytesLen)){let n=l.decode(e),r=d.decode(t),i=[],a=[];try{for(let e=0;e<o.length;e++){let t=o[e].encapsulate(n[e],r[e]);i.push(t.sharedSecret),a.push(t.cipherText)}let e=c.encode(a);return{sharedSecret:h(n,a,i),cipherText:e}}finally{R(i,a)}},decapsulate(e,t){let n=c.decode(e),{publicKey:r,secretKey:i}=s.expandDecapsulationKey(t),a=[];try{for(let e=0;e<o.length;e++)a.push(o[e].decapsulate(n[e],i[e]));return h(r,n,a)}finally{R(i,a)}}})}function Mr(e,t,n,r){let i=e.Point.Fn;if(!i)throw Error(`no Point.Fn`);function a(n){let r;for(let e=0,a=t;;e=a,a+=t){if(a>n.length)throw Error(`rejection sampling failed`);if(r=i.fromBytes(n.subarray(e,a),!0),i.isValidNot0(r))break}let a=i.toBytes(i.create(r));return{secretKey:a,publicKey:e.getPublicKey(a,!1)}}let o=(t,n)=>e.getSharedSecret(n,t).subarray(1);return{lengths:{secretKey:t,publicKey:n,seed:r,msg:r,cipherText:n},keygen(e=er(r)){return m(e,r,`seed`),a(e)},getPublicKey(t){return e.getPublicKey(t,!1)},encapsulate(t,n=er(r)){m(n,r,`rand`);let i;try{return i=a(n).secretKey,{sharedSecret:o(t,i),cipherText:e.getPublicKey(i,!1)}}finally{i&&R(i)}},decapsulate:o}}function Nr(e,t,n,r){let{secretKey:i,publicKeyUncompressed:a}=n.lengths;if(!i||!a)throw Error(`wrong curve`);let o=Mr(n,i,a,r),s=64+r;return jr(32,32,e=>(m(e,32),Qn(e,{dkLen:s})),(t,n,r)=>Jn(ue(r[0],r[1],n[1],t[1],De(e))),t,o)}const Pr=(()=>Nr(`MLKEM768-P256`,Er,Tn,128))();function Fr(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Fr(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Ir(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Fr(e))&&(r&&(r+=` `),r+=t);return r}var Lr=Ir,Rr=t(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),zr=t((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),Br=t((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),Vr=t(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),Hr=t(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),Ur=t((e=>{var t=zr().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),Wr=t((e=>{var t=zr().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),Gr=t((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),Kr=t((e=>{var t=Br(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),qr=t((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),Jr=t((e=>{var t=qr();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),Yr=t(((e,t)=>{var n=Jr();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),Xr=t((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Zr=t((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
2
2
  ]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^`+t+`$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),Qr=t((e=>{var t=Xr(),n=Zr();e.NUMERIC={id:`Numeric`,bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:`Alphanumeric`,bit:2,ccBits:[9,11,13]},e.BYTE={id:`Byte`,bit:4,ccBits:[8,16,16]},e.KANJI={id:`Kanji`,bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw Error(`Invalid mode: `+e);if(!t.isValid(n))throw Error(`Invalid version: `+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw Error(`Invalid mode`)},e.isValid=function(e){return e&&e.bit&&e.ccBits};function r(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`numeric`:return e.NUMERIC;case`alphanumeric`:return e.ALPHANUMERIC;case`kanji`:return e.KANJI;case`byte`:return e.BYTE;default:throw Error(`Unknown mode: `+t)}}e.from=function(t,n){if(e.isValid(t))return t;try{return r(t)}catch{return n}}})),$r=t((e=>{var t=zr(),n=Kr(),r=Br(),i=Qr(),a=Xr(),o=7973,s=t.getBCHDigit(o);function c(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}function l(e,t){return i.getCharCountIndicator(e,t)+4}function u(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}function d(t,n){for(let r=1;r<=40;r++)if(u(t,r)<=e.getCapacity(r,n,i.MIXED))return r}e.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,o){if(!a.isValid(e))throw Error(`Invalid QR Code version`);o===void 0&&(o=i.BYTE);let s=(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r))*8;if(o===i.MIXED)return s;let c=s-l(o,e);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(e,t){let n,i=r.from(t,r.M);if(Array.isArray(e)){if(e.length>1)return d(e,i);if(e.length===0)return 1;n=e[0]}else n=e;return c(n.mode,n.getLength(),i)},e.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error(`Invalid QR Code version`);let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=o<<t.getBCHDigit(n)-s;return e<<12|n}})),ei=t((e=>{var t=zr(),n=1335,r=21522,i=t.getBCHDigit(n);e.getEncodedBits=function(e,a){let o=e.bit<<3|a,s=o<<10;for(;t.getBCHDigit(s)-i>=0;)s^=n<<t.getBCHDigit(s)-i;return(o<<10|s)^r}})),ti=t(((e,t)=>{var n=Qr();function r(e){this.mode=n.NUMERIC,this.data=e.toString()}r.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);let i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,i*3+1))},t.exports=r})),ni=t(((e,t)=>{var n=Qr(),r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function i(e){this.mode=n.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=r.indexOf(this.data[t])*45;n+=r.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(r.indexOf(this.data[t]),6)},t.exports=i})),ri=t(((e,t)=>{var n=Qr();function r(e){this.mode=n.BYTE,typeof e==`string`?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}r.getBitsLength=function(e){return e*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},t.exports=r})),ii=t(((e,t)=>{var n=Qr(),r=zr();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
3
3
  Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),ai=t(((e,t)=>{var n={single_source_shortest_paths:function(e,t,r){var i={},a={};a[t]=0;var o=n.PriorityQueue.make();o.push(t,0);for(var s,c,l,u,d,f,p,m,h;!o.empty();)for(l in s=o.pop(),c=s.value,u=s.cost,d=e[c]||{},d)d.hasOwnProperty(l)&&(f=d[l],p=u+f,m=a[l],h=a[l]===void 0,(h||m>p)&&(a[l]=p,o.push(l,p),i[l]=c));if(r!==void 0&&a[r]===void 0){var g=[`Could not find a path from `,t,` to `,r,`.`].join(``);throw Error(g)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,r){var i=n.single_source_shortest_paths(e,t,r);return n.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var t=n.PriorityQueue,r={},i;for(i in e||={},t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r.queue=[],r.sorter=e.sorter||t.default_sorter,r},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t!==void 0&&(t.exports=n)})),oi=t((e=>{var t=Qr(),n=ti(),r=ni(),i=ri(),a=ii(),o=Zr(),s=zr(),c=ai();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
4
4
  Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),si=t((e=>{var t=zr(),n=Br(),r=Vr(),i=Hr(),a=Ur(),o=Wr(),s=Gr(),c=Kr(),l=Yr(),u=$r(),d=ei(),f=Qr(),p=oi();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function _(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function v(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function y(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function b(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return x(a,e,n)}function x(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function S(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
package/static/index.html CHANGED
@@ -8,15 +8,15 @@
8
8
  <link rel="shortcut icon" href="/favicon.ico">
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
10
  <title>DNS Worker</title>
11
- <script type="module" crossorigin src="/assets/index-BDIG7T8u.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-D0aw4Fjy.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C4Xdq4VV.js">
13
13
  <link rel="modulepreload" crossorigin href="/assets/vendor-icons-16-BgwRBCeU.js">
14
14
  <link rel="modulepreload" crossorigin href="/assets/vendor-icons-20-X5NPN60g.js">
15
15
  <link rel="modulepreload" crossorigin href="/assets/vendor-icons-other-BTYC6Wvz.js">
16
- <link rel="modulepreload" crossorigin href="/assets/vendor-i18next-BlwxMUL4.js">
17
- <link rel="modulepreload" crossorigin href="/assets/vendor-react-BOaLEa_F.js">
18
- <link rel="modulepreload" crossorigin href="/assets/vendor-ui-core-C8brnfYc.js">
19
- <link rel="modulepreload" crossorigin href="/assets/vendor-utils-DkfyN6f3.js">
16
+ <link rel="modulepreload" crossorigin href="/assets/vendor-i18next-BC3ewzY3.js">
17
+ <link rel="modulepreload" crossorigin href="/assets/vendor-react-BtC4HVVO.js">
18
+ <link rel="modulepreload" crossorigin href="/assets/vendor-ui-core-DUyKOLA8.js">
19
+ <link rel="modulepreload" crossorigin href="/assets/vendor-utils-xrsi4rSa.js">
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-Ps0MlBLt.css">
21
21
  <link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
22
22
 
package/static/sw.js CHANGED
@@ -1 +1 @@
1
- const e=`dns-worker-icons-v2`,t=`/api/icon/`,n=1440*60*1e3;15*n,30*n;function r(){return new Response(`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#9ca3af" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>`,{headers:{"Content-Type":`image/svg+xml`,"Cache-Control":`public, max-age=86400`}})}async function i(e){try{return await fetch(e,{mode:`cors`})}catch{return fetch(e,{mode:`no-cors`})}}function a(e){return e.startsWith(t)}async function o(e,t,n){let r=typeof t==`string`?t:t.url,i=new Request(r+`?sw-cached-at`),a=new Response(Date.now().toString());await e.put(t,n),await e.put(i,a)}async function s(e,t){try{let n=new Request(t.url+`?sw-cached-at`),r=await e.match(n);if(!r)return 1/0;let i=await r.text(),a=parseInt(i,10);return isNaN(a)?1/0:Date.now()-a}catch{return 1/0}}async function c(t){let n=await caches.open(e),a=await n.match(t.request);if(a){let e=await s(n,t.request);if(e<1296e6)return a;if(e<2592e6)return i(t.request.url).then(e=>{e&&(e.ok||e.status===0)&&o(n,t.request,e)}).catch(()=>{}),a}try{let e=await i(t.request.url);return e&&(e.ok||e.status===0)?(await o(n,t.request,e.clone()),e):a??r()}catch{return a??r()}}function l(n=[]){caches.open(e).then(e=>{n.forEach(n=>{let r=`${t}${n.replace(/^\*\./,``)}.ico`,a=new Request(r);e.match(a).then(t=>{t||i(r).then(t=>{t&&(t.ok||t.status===0)&&o(e,a,t)}).catch(()=>{})})})})}async function u(){try{let t=await caches.open(e),n=await t.keys(),r=Date.now(),i=n.filter(e=>e.url.includes(`?sw-cached-at`));for(let e of i){let n=await t.match(e);if(n){let i=await n.text(),a=parseInt(i,10);if(!isNaN(a)&&r-a>2592e6){let n=e.url.split(`?`)[0];await t.delete(new Request(n)),await t.delete(e)}}}}catch(e){console.error(`Failed to execute service worker cache cleanup:`,e)}}async function d(){try{let e=await caches.keys();for(let t of e)t.startsWith(`dns-worker-icons-`)&&t!==`dns-worker-icons-v2`&&await caches.delete(t)}catch(e){console.error(`Failed to clean up old caches:`,e)}}const f=`dns-worker-logs-v1`;function p(e){try{let t=new URL(e);return/^\/api\/profiles\/[^/]+\/logs\/\d+$/.test(t.pathname)}catch{return!1}}async function m(e){let t=await caches.open(f),n=await t.match(e.request);if(n)return n;try{let n=await fetch(e.request);return n.ok&&await o(t,e.request,n.clone()),n}catch{return new Response(JSON.stringify({error:`Network error fetching log details`}),{status:503,headers:{"Content-Type":`application/json`}})}}async function h(){try{let e=await caches.open(f),t=await e.keys(),n=Date.now(),r=t.filter(e=>e.url.includes(`?sw-cached-at`));for(let t of r){let r=await e.match(t);if(r){let i=await r.text(),a=parseInt(i,10);if(!isNaN(a)&&n-a>864e5){let n=t.url.split(`?`)[0];await e.delete(new Request(n)),await e.delete(t)}}}}catch(e){console.error(`Failed to execute service worker log cache cleanup:`,e)}}[{"revision":"c3f8f1bb273e4c3ad61c528eee12ea8d","url":"sqlite3-opfs-async-proxy.js"},{"revision":"1872c500de691dce40960bb85481de07","url":"registerSW.js"},{"revision":"71c30ca03f46d36dd2c46ee0aeb21d33","url":"index.html"},{"revision":null,"url":"assets/zh-TW-BuAII2MX.js"},{"revision":null,"url":"assets/zh-CN-Da_oIx9u.js"},{"revision":null,"url":"assets/vi-VN-BOpyUW1f.js"},{"revision":null,"url":"assets/vendor-utils-DkfyN6f3.js"},{"revision":null,"url":"assets/vendor-ui-core-C8brnfYc.js"},{"revision":null,"url":"assets/vendor-react-BOaLEa_F.js"},{"revision":null,"url":"assets/vendor-icons-other-BTYC6Wvz.js"},{"revision":null,"url":"assets/vendor-icons-20-X5NPN60g.js"},{"revision":null,"url":"assets/vendor-icons-16-BgwRBCeU.js"},{"revision":null,"url":"assets/vendor-i18next-BlwxMUL4.js"},{"revision":null,"url":"assets/useLogsE2ee-DR83v9Pr.js"},{"revision":null,"url":"assets/sqlite3-worker1-Cx6t16S_.js"},{"revision":null,"url":"assets/sqlite3-opfs-async-proxy.js"},{"revision":null,"url":"assets/sqlite3-opfs-async-proxy-DeAec6oc.js"},{"revision":null,"url":"assets/sqlite3-k2cTanUO.wasm"},{"revision":null,"url":"assets/sqlite.worker-DfuIqYyd.js"},{"revision":null,"url":"assets/splitPathsBySizeLoader-htHoS0DT.js"},{"revision":null,"url":"assets/services-CcZhHzmI.js"},{"revision":null,"url":"assets/ru-RU-D39eC2of.js"},{"revision":null,"url":"assets/rolldown-runtime-C4Xdq4VV.js"},{"revision":null,"url":"assets/paths-cc-gUzxh.js"},{"revision":null,"url":"assets/paths-CfqdBnl8.js"},{"revision":null,"url":"assets/ko-KR-BLWDY5Fe.js"},{"revision":null,"url":"assets/ja-JP-DMwARVKx.js"},{"revision":null,"url":"assets/index-Ps0MlBLt.css"},{"revision":null,"url":"assets/index-BDIG7T8u.js"},{"revision":null,"url":"assets/getFlagEmoji-Cd2A891A.js"},{"revision":null,"url":"assets/fr-FR-CFQh-3E3.js"},{"revision":null,"url":"assets/formatCountryName-C6cFVUu2.js"},{"revision":null,"url":"assets/es-ES-BURmloF3.js"},{"revision":null,"url":"assets/de-DE-DbbT5Cxx.js"},{"revision":null,"url":"assets/date-Cw6CNU-1.js"},{"revision":null,"url":"assets/browser-BRLLTlVv.js"},{"revision":null,"url":"assets/async-R_IFRE5c.js"},{"revision":null,"url":"assets/allPathsLoader-CvGx1ejI.js"},{"revision":null,"url":"assets/allPaths-ZKIw3HqD.js"},{"revision":null,"url":"assets/TrendChart-B8jOSMgO.js"},{"revision":null,"url":"assets/SwipeableDrawer-DW0I7SLC.js"},{"revision":null,"url":"assets/SetupView-CfkQXcdY.js"},{"revision":null,"url":"assets/SettingsView-Ci0mrIcm.js"},{"revision":null,"url":"assets/RulesView-DnQoSZ4S.js"},{"revision":null,"url":"assets/LogsView-D1dRHMqS.js"},{"revision":null,"url":"assets/FilteringView-DVmIVx_P.js"},{"revision":null,"url":"assets/DestinationMap-DoNQwdnV.js"},{"revision":null,"url":"assets/AnalyticsView-C9e4mI_K.js"},{"revision":null,"url":"assets/AccountView-Yowwz2Gg.js"},{"revision":"edbf27fdbbc78a5a7269553eed5447b1","url":"manifest.webmanifest"}],self.addEventListener(`install`,()=>{self.skipWaiting()}),self.addEventListener(`activate`,e=>{e.waitUntil(Promise.all([self.clients.claim(),u(),d(),h()]))}),self.addEventListener(`fetch`,e=>{let t=e.request.url;a(t)&&e.respondWith(c(e)),p(t)&&e.respondWith(m(e))}),self.addEventListener(`message`,e=>{e.data&&e.data.type===`PREFETCH_ICONS`&&l(e.data.domains)});
1
+ const e=`dns-worker-icons-v2`,t=`/api/icon/`,n=1440*60*1e3;15*n,30*n;function r(){return new Response(`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#9ca3af" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>`,{headers:{"Content-Type":`image/svg+xml`,"Cache-Control":`public, max-age=86400`}})}async function i(e){try{return await fetch(e,{mode:`cors`})}catch{return fetch(e,{mode:`no-cors`})}}function a(e){return e.startsWith(t)}async function o(e,t,n){let r=typeof t==`string`?t:t.url,i=new Request(r+`?sw-cached-at`),a=new Response(Date.now().toString());await e.put(t,n),await e.put(i,a)}async function s(e,t){try{let n=new Request(t.url+`?sw-cached-at`),r=await e.match(n);if(!r)return 1/0;let i=await r.text(),a=parseInt(i,10);return isNaN(a)?1/0:Date.now()-a}catch{return 1/0}}async function c(t){let n=await caches.open(e),a=await n.match(t.request);if(a){let e=await s(n,t.request);if(e<1296e6)return a;if(e<2592e6)return i(t.request.url).then(e=>{e&&(e.ok||e.status===0)&&o(n,t.request,e)}).catch(()=>{}),a}try{let e=await i(t.request.url);return e&&(e.ok||e.status===0)?(await o(n,t.request,e.clone()),e):a??r()}catch{return a??r()}}function l(n=[]){caches.open(e).then(e=>{n.forEach(n=>{let r=`${t}${n.replace(/^\*\./,``)}.ico`,a=new Request(r);e.match(a).then(t=>{t||i(r).then(t=>{t&&(t.ok||t.status===0)&&o(e,a,t)}).catch(()=>{})})})})}async function u(){try{let t=await caches.open(e),n=await t.keys(),r=Date.now(),i=n.filter(e=>e.url.includes(`?sw-cached-at`));for(let e of i){let n=await t.match(e);if(n){let i=await n.text(),a=parseInt(i,10);if(!isNaN(a)&&r-a>2592e6){let n=e.url.split(`?`)[0];await t.delete(new Request(n)),await t.delete(e)}}}}catch(e){console.error(`Failed to execute service worker cache cleanup:`,e)}}async function d(){try{let e=await caches.keys();for(let t of e)t.startsWith(`dns-worker-icons-`)&&t!==`dns-worker-icons-v2`&&await caches.delete(t)}catch(e){console.error(`Failed to clean up old caches:`,e)}}const f=`dns-worker-logs-v1`;function p(e){try{let t=new URL(e);return/^\/api\/profiles\/[^/]+\/logs\/\d+$/.test(t.pathname)}catch{return!1}}async function m(e){let t=await caches.open(f),n=await t.match(e.request);if(n)return n;try{let n=await fetch(e.request);return n.ok&&await o(t,e.request,n.clone()),n}catch{return new Response(JSON.stringify({error:`Network error fetching log details`}),{status:503,headers:{"Content-Type":`application/json`}})}}async function h(){try{let e=await caches.open(f),t=await e.keys(),n=Date.now(),r=t.filter(e=>e.url.includes(`?sw-cached-at`));for(let t of r){let r=await e.match(t);if(r){let i=await r.text(),a=parseInt(i,10);if(!isNaN(a)&&n-a>864e5){let n=t.url.split(`?`)[0];await e.delete(new Request(n)),await e.delete(t)}}}}catch(e){console.error(`Failed to execute service worker log cache cleanup:`,e)}}[{"revision":"edbf27fdbbc78a5a7269553eed5447b1","url":"manifest.webmanifest"}],self.addEventListener(`install`,()=>{self.skipWaiting()}),self.addEventListener(`activate`,e=>{e.waitUntil(Promise.all([self.clients.claim(),u(),d(),h()]))}),self.addEventListener(`fetch`,e=>{let t=e.request.url;a(t)&&e.respondWith(c(e)),p(t)&&e.respondWith(m(e))}),self.addEventListener(`message`,e=>{e.data&&e.data.type===`PREFETCH_ICONS`&&l(e.data.domains)});
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrendChart-B8jOSMgO.js","assets/index-BDIG7T8u.js","assets/vendor-icons-other-BTYC6Wvz.js","assets/vendor-icons-16-BgwRBCeU.js","assets/rolldown-runtime-C4Xdq4VV.js","assets/vendor-icons-20-X5NPN60g.js","assets/vendor-react-BOaLEa_F.js","assets/vendor-i18next-BlwxMUL4.js","assets/vendor-ui-core-C8brnfYc.js","assets/vendor-utils-DkfyN6f3.js","assets/index-Ps0MlBLt.css","assets/DestinationMap-DoNQwdnV.js","assets/formatCountryName-C6cFVUu2.js","assets/getFlagEmoji-Cd2A891A.js"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-C4Xdq4VV.js";import{D as t,J as n,L as r,Z as i,bt as a,en as o,j as s,nt as c,v as l}from"./vendor-react-BOaLEa_F.js";import{S as u,b as d,x as f}from"./vendor-icons-other-BTYC6Wvz.js";import"./vendor-i18next-BlwxMUL4.js";import{C as p,H as m,M as h,N as g,P as _,T as v,V as y,d as b,f as x,o as S,p as C,r as w,u as T,x as E}from"./vendor-ui-core-C8brnfYc.js";import{_t as D}from"./vendor-utils-DkfyN6f3.js";import{E as O,at as k,b as A,it as j,ot as M,sn as N}from"./index-BDIG7T8u.js";import{t as P}from"./getFlagEmoji-Cd2A891A.js";import{i as F,n as I,r as L,t as R}from"./useLogsE2ee-DR83v9Pr.js";var z=e(u(),1);function B(e,t,n){if(!e)return[];let r={},i=Math.floor(Date.now()/1e3),a,o;switch(t){case`10m`:o=60,a=i-600;break;case`1h`:o=60,a=i-3600;break;case`24h`:o=3600,a=i-24*3600;break;case`7d`:o=86400,a=i-7*86400;break;case`30d`:o=86400,a=i-30*86400;break;case`custom`:if(o=3600,n.start&&n.end)a=Math.floor(new Date(n.start).getTime()/1e3),i=Math.floor(new Date(n.end).getTime()/1e3);else{let t=e.trend.map(e=>e.timestamp);a=t.length?Math.min(...t):i-86400,i=t.length?Math.max(...t):i}break;default:o=60,a=i-3600}a=Math.floor(a/o)*o,i=Math.floor(i/o)*o;for(let e=a;e<=i;e+=o)r[e]={timestamp:e,allowed:0,blocked:0,redirected:0};return e.trend.forEach(e=>{let t=Math.floor(e.timestamp/o)*o;r[t]||(r[t]={timestamp:t,allowed:0,blocked:0,redirected:0}),e.action===`PASS`?r[t].allowed+=e.count:e.action===`BLOCK`?r[t].blocked+=e.count:e.action===`REDIRECT`&&(r[t].redirected+=e.count)}),Object.keys(r).sort((e,t)=>Number(e)-Number(t)).map(e=>r[Number(e)])}var V=e(d(),1);const H=({title:e,data:t,intent:n})=>{let{t:r}=o(),a=[{key:`rank`,cellClassName:`w-8 opacity-30 font-mono text-xs`,render:(e,t)=>t+1},{key:`domain`,cellClassName:`font-medium text-sm truncate max-w-50`,render:e=>e.domain===`[Encrypted]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-gray-400 dark:text-gray-500 italic font-normal`,children:[(0,V.jsx)(i,{size:14,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:r(`logs.encryptedRecord`,`[加密记录]`)})]}):e.domain===`[Decryption Failed]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-red-400 dark:text-red-500 italic font-normal`,children:[(0,V.jsx)(i,{size:14,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:r(`logs.decryptionFailed`,`[解密失败]`)})]}):e.domain},{key:`count`,cellClassName:`text-right`,render:e=>(0,V.jsx)(w,{minimal:!0,intent:n,className:`font-bold`,children:e.count})}];return(0,V.jsxs)(E,{elevation:m.ZERO,className:`dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,V.jsx)(h,{className:`mb-4 font-bold`,children:e}),(0,V.jsx)(T,{striped:!0,className:`w-full`,children:(0,V.jsxs)(`tbody`,{children:[t.map((e,t)=>(0,V.jsx)(`tr`,{children:a.map(n=>(0,V.jsx)(`td`,{className:n.cellClassName,children:n.render(e,t)},n.key))},t)),t.length===0&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:a.length,className:`text-center py-8 opacity-50`,children:r(`analytics.noData`)})})]})})]})},U=new class{cache=new Map;MAX_ENTRIES=50;buildKey(e,t,n,r,i){return`${e}|${t}|${n||``}|${r||``}|${i||`all`}`}getTtlConfig(e,t){if(e===`custom`&&t&&Date.now()-new Date(t).getTime()>2*3600*1e3)return{staleAfterMs:1800*1e3,ttlMs:3600*1e3};switch(e){case`10m`:case`1h`:return{staleAfterMs:30*1e3,ttlMs:60*1e3};case`24h`:return{staleAfterMs:120*1e3,ttlMs:300*1e3};case`7d`:case`30d`:return{staleAfterMs:300*1e3,ttlMs:900*1e3};default:return{staleAfterMs:60*1e3,ttlMs:120*1e3}}}get(e){let t=this.cache.get(e);if(!t)return null;let n=Date.now()-t.timestamp;return n>t.ttlMs?(this.cache.delete(e),null):{data:t.data,isStale:n>t.staleAfterMs}}set(e,t,n,r){if(this.cache.size>=this.MAX_ENTRIES){let e=this.cache.keys().next().value;e&&this.cache.delete(e)}let{ttlMs:i,staleAfterMs:a}=this.getTtlConfig(n,r);this.cache.set(e,{data:t,timestamp:Date.now(),ttlMs:i,staleAfterMs:a})}invalidateProfile(e){for(let t of Array.from(this.cache.keys()))t.startsWith(`${e}|`)&&this.cache.delete(t)}clear(){this.cache.clear()}};function W(e,t){let{t:n}=o(),[r,i]=(0,z.useState)(null),[a,s]=(0,z.useState)(!0),[c,l]=(0,z.useState)(!1),[u,d]=(0,z.useState)(0),[f,p]=(0,z.useState)(`1h`),[m,h]=(0,z.useState)({start:``,end:``}),[g,_]=(0,z.useState)(null),[v,b]=(0,z.useState)([]),[x,S]=(0,z.useState)(30),C=(0,z.useRef)(null),w=(0,z.useRef)(null),T=(0,z.useRef)(null);(0,z.useEffect)(()=>()=>{C.current?.abort(),w.current?.abort()},[]),(0,z.useEffect)(()=>{j(e).then(e=>b(e)).catch(e=>console.error(`[useAnalyticsData] Failed to load access points:`,e))},[e]),(0,z.useEffect)(()=>{M(e).then(e=>{try{let t=JSON.parse(e.settings||`{}`);S(t.log_retention_days===void 0?30:Number(t.log_retention_days))}catch(e){console.error(`[useAnalyticsData] Failed to parse settings:`,e)}}).catch(e=>console.error(`[useAnalyticsData] Failed to fetch profile settings:`,e))},[e]);let E=(0,z.useCallback)(async(t,n,r,a,o=!1)=>{C.current?.abort();let c=new AbortController;C.current=c;let l=c.signal,u=U.buildKey(e,t,n,r,a);if(o)U.invalidateProfile(e);else{let e=U.get(u);if(e&&!l.aborted&&(i(e.data),s(!1),!e.isStale))return}s(!0);let d=Math.floor(Date.now()/1e3),f,p=d,m;if(t===`custom`&&n&&r){f=Math.floor(new Date(n).getTime()/1e3),p=Math.floor(new Date(r).getTime()/1e3);let e=p-f;m=e<=7200?60:e<=172800?3600:86400}else switch(t){case`10m`:f=d-600,m=60;break;case`1h`:f=d-3600,m=60;break;case`24h`:f=d-86400,m=3600;break;case`7d`:f=d-604800,m=86400;break;case`30d`:f=d-2592e3,m=86400;break;default:f=d-3600,m=60;break}try{(O.isProfileUnlocked(e)||O.isUnlocked())&&await A.reDecryptLocalLogs(e)}catch{}try{if(await A.init()&&!l.aborted){let t=await A.queryAnalytics({profileId:e,since:f,until:p,bucketSec:m,accessPointId:a||void 0});t.summary.some(e=>e.count>0)&&!l.aborted&&(i(t),s(!1))}}catch(e){console.warn(`[useAnalyticsData] Local SQLite preview failed:`,e)}let h=!1,g=!1,_=!1,v=!1;try{let o=`?range=${t}`;t===`custom`&&n&&r&&(o+=`&start=${f}&end=${p}`),a&&(o+=`&access_point_id=${a}`);let s=null;try{s=await k(e,``,o)}catch{if(l.aborted)return;let[t,n,r,i,a,c]=await Promise.all([k(e,`summary`,o),k(e,`trend`,o),k(e,`top_allowed`,o),k(e,`top_blocked`,o),k(e,`clients`,o),k(e,`destinations`,o)]);s={summary:t,trend:n,top_allowed:r,top_blocked:i,clients:a,destinations:c}}s&&!l.aborted&&(h=(s.clients||[]).length>0&&s.clients.some(e=>e.client_ip&&e.client_ip!==`[Encrypted]`&&e.client_ip!==`[Decryption Failed]`),_=(s.top_allowed||[]).length>0&&s.top_allowed.some(e=>e.domain&&e.domain!==`[Encrypted]`&&e.domain!==`[Decryption Failed]`),v=(s.top_blocked||[]).length>0&&s.top_blocked.some(e=>e.domain&&e.domain!==`[Encrypted]`&&e.domain!==`[Decryption Failed]`),g=(s.destinations||[]).length>0,i(e=>{let n={...s,trend:s.trend||[],summary:s.summary||[],top_allowed:_?s.top_allowed:e?.top_allowed?.length?e.top_allowed:s.top_allowed||[],top_blocked:v?s.top_blocked:e?.top_blocked?.length?e.top_blocked:s.top_blocked||[],clients:h?s.clients:e?.clients?.length?e.clients:s.clients||[],destinations:g?s.destinations:e?.destinations&&e.destinations.length>0?e.destinations:[]};return U.set(u,n,t,r),n}))}catch(e){l.aborted||console.error(`[useAnalyticsData] Failed to fetch server analytics:`,e)}finally{l.aborted||s(!1)}try{let n=O.isProfileUnlocked(e)||O.isUnlocked(),o=async()=>{if(!l.aborted)try{let n=await A.queryAnalytics({profileId:e,since:f,until:p,bucketSec:m,accessPointId:a||void 0});l.aborted||i(e=>{if(!e)return U.set(u,n,t,r),n;let i={...e,destinations:g?e.destinations:n.destinations.length>0?n.destinations:e.destinations,top_allowed:_?e.top_allowed:n.top_allowed.length>0?n.top_allowed:e.top_allowed,top_blocked:v?e.top_blocked:n.top_blocked.length>0?n.top_blocked:e.top_blocked,clients:h?e.clients:n.clients.length>0?n.clients:e.clients};return U.set(u,i,t,r),i})}catch{}},s=await A.syncMissingIntervals(e,f,p,l,()=>{o()});!l.aborted&&(s>0||n)&&await o()}catch(e){e?.name!==`AbortError`&&console.warn(`[useAnalyticsData] Missing intervals sync error:`,e)}},[e]),D=(0,z.useCallback)(async()=>{if(c)return;let r=Math.floor(Date.now()/1e3),a=T.current;if(a!==null&&a.range===f&&a.accessPointId===g&&(f!==`custom`||a.customStart===m.start&&a.customEnd===m.end)&&r-a.completedAt<30){t?.current?.show({message:n(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:y.PRIMARY,icon:`tick`});return}l(!0),d(.05),w.current?.abort();let o=new AbortController;w.current=o;let s=o.signal,u,p=r,h;if(f===`custom`&&m.start&&m.end){u=Math.floor(new Date(m.start).getTime()/1e3),p=Math.floor(new Date(m.end).getTime()/1e3);let e=p-u;h=e<=7200?60:e<=172800?3600:86400}else switch(f){case`10m`:u=r-600,h=60;break;case`1h`:u=r-3600,h=60;break;case`24h`:u=r-86400,h=3600;break;case`7d`:u=r-604800,h=86400;break;case`30d`:u=r-2592e3,h=86400;break;default:u=r-3600,h=60;break}try{let r=async()=>{if(!s.aborted)try{let t=await A.queryAnalytics({profileId:e,since:u,until:p,bucketSec:h,accessPointId:g||void 0});s.aborted||i(e=>e?{...e,destinations:t.destinations.length>0?t.destinations:e.destinations,top_allowed:t.top_allowed.length>0?t.top_allowed:e.top_allowed,top_blocked:t.top_blocked.length>0?t.top_blocked:e.top_blocked,clients:t.clients.length>0?t.clients:e.clients}:t)}catch{}},a=await A.syncTargetInterval(e,u,p,s,e=>{s.aborted||(d(e),r())});s.aborted||(T.current={range:f,customStart:m.start,customEnd:m.end,accessPointId:g,completedAt:Math.floor(Date.now()/1e3)},U.invalidateProfile(e),a===0?t?.current?.show({message:n(`analytics.syncAlreadyUpToDate`,`本地记录已是最新`),intent:y.PRIMARY,icon:`tick`}):(d(1),await r(),t?.current?.show({message:n(`analytics.syncSuccess`,`本地记录同步完成`),intent:y.SUCCESS,icon:`tick`}),await new Promise(e=>setTimeout(e,600))))}catch(e){e?.name!==`AbortError`&&!s.aborted&&(console.error(`[useAnalyticsData] Manual sync error:`,e),t?.current?.show({message:n(`analytics.syncFailed`,`本地记录同步失败`),intent:y.DANGER,icon:`error`}))}finally{l(!1),d(0)}},[e,f,m,g,c,t,n]),N=(0,z.useCallback)(()=>{w.current&&=(w.current.abort(),null),l(!1),d(0),t?.current?.show({message:n(`analytics.syncStopped`,`同步已停止`),intent:y.WARNING,icon:`stop`})},[t,n]);return(0,z.useEffect)(()=>{f!==`custom`&&E(f,void 0,void 0,g)},[f,g,E]),{data:r,loading:a,syncing:c,syncProgress:u,range:f,setRange:p,customRange:m,setCustomRange:h,accessPointIdFilter:g,setAccessPointIdFilter:_,accessPoints:v,logRetentionDays:x,fetchData:E,syncTargetRange:D,stopSync:N}}var G=[{key:`10m`,days:.007},{key:`1h`,days:.0416},{key:`24h`,days:1},{key:`7d`,days:7},{key:`30d`,days:30}];const K=({range:e,setRange:t,customRange:n,setCustomRange:r,logRetentionDays:i,accessPoints:s,accessPointIdFilter:c,setAccessPointIdFilter:l,loading:u,onApplyCustom:d})=>{let{t:f}=o(),m=new Date().toLocaleString(`sv-SE`).replace(` `,`T`).slice(0,16);return(0,V.jsxs)(`div`,{className:`flex justify-between items-center bg-white dark:bg-gray-900 p-2 rounded-lg shadow-sm border border-gray-100 dark:border-gray-800`,children:[(0,V.jsxs)(p,{variant:`minimal`,children:[G.filter(e=>e.days<=i).map(e=>e.key).map(n=>(0,V.jsx)(g,{active:e===n,onClick:()=>t(n),text:n.toUpperCase()},n)),(0,V.jsx)(v,{content:(0,V.jsxs)(`div`,{className:`p-4 space-y-4 w-64`,children:[(0,V.jsx)(h,{children:f(`analytics.customRange`)}),(0,V.jsx)(C,{label:f(`analytics.startTime`),children:(0,V.jsx)(x,{type:`datetime-local`,max:n.end||m,value:n.start,onChange:e=>r({...n,start:e.target.value})})}),(0,V.jsx)(C,{label:f(`analytics.endTime`),children:(0,V.jsx)(x,{type:`datetime-local`,min:n.start,max:m,value:n.end,onChange:e=>r({...n,end:e.target.value})})}),(0,V.jsx)(g,{fill:!0,intent:y.PRIMARY,text:f(`analytics.apply`),onClick:d})]}),children:(0,V.jsx)(g,{active:e===`custom`,icon:(0,V.jsx)(a,{size:14,className:`mr-1`}),text:f(`analytics.custom`)})})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.length>0&&(0,V.jsx)(b,{value:c||``,onChange:e=>l(e.target.value||null),options:[{label:`${f(`logs.allAccessPoint`)}`,value:``},...s.map(e=>({label:e.name,value:e.id}))],minimal:!0}),u&&(0,V.jsx)(_,{size:16})]})]})},q=({title:e,value:t,icon:n})=>(0,V.jsxs)(E,{elevation:m.ZERO,className:`flex items-center gap-4 p-4 dark:bg-gray-900 dark:border-gray-800 border border-gray-100 shadow-sm`,children:[(0,V.jsx)(`div`,{className:`p-3 bg-gray-50 dark:bg-gray-800 rounded-lg`,children:n}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-xs text-gray-500 font-medium uppercase tracking-wider`,children:e}),(0,V.jsx)(`div`,{className:`text-xl font-bold dark:text-white`,children:t})]})]}),J=({data:e})=>{let{t:n}=o(),i=e?.summary.reduce((e,t)=>e+t.count,0)||0,a=e?.summary.find(e=>e.action===`BLOCK`)?.count||0,u=e?.summary.find(e=>e.action===`REDIRECT`)?.count||0,d=i>0?(a/i*100).toFixed(1):`0.0`;return(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-2 lg:gap-4`,children:[{title:n(`analytics.totalQueries`),value:i.toLocaleString(),icon:(0,V.jsx)(l,{className:`text-blue-500`,size:20})},{title:n(`analytics.blocked`),value:a.toLocaleString(),icon:(0,V.jsx)(s,{className:`text-red-500`,size:20})},{title:n(`analytics.redirected`),value:u.toLocaleString(),icon:(0,V.jsx)(r,{className:`text-amber-500`,size:20})},{title:n(`analytics.blockRate`),value:`${d}%`,icon:(0,V.jsx)(t,{className:`text-green-500`,size:20})},{title:n(`analytics.activeIPs`),value:e?.clients.length.toString()||`0`,icon:(0,V.jsx)(c,{className:`text-purple-500`,size:20})}].map((e,t)=>(0,V.jsx)(q,{title:e.title,value:e.value,icon:e.icon},t))})},Y=({clients:e})=>{let{t}=o();return(0,V.jsx)(S,{title:t(`analytics.clientActivity`),icon:(0,V.jsx)(c,{size:16}),children:(0,V.jsxs)(T,{striped:!0,className:`w-full mt-2`,children:[(0,V.jsx)(`thead`,{children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:t(`analytics.ipAddress`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60`,children:t(`analytics.location`)}),(0,V.jsx)(`th`,{className:`text-xs uppercase opacity-60 text-right`,children:t(`analytics.queries`)})]})}),(0,V.jsxs)(`tbody`,{children:[e?.map((e,n)=>(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`td`,{className:`font-mono text-xs`,children:e.client_ip===`[Encrypted]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-gray-400 dark:text-gray-500 italic`,children:[(0,V.jsx)(i,{size:12,className:`text-amber-500 shrink-0`}),(0,V.jsx)(`span`,{children:t(`logs.encryptedRecord`,`[加密记录]`)})]}):e.client_ip===`[Decryption Failed]`?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-red-400 dark:text-red-500 italic`,children:[(0,V.jsx)(i,{size:12,className:`text-red-500 shrink-0`}),(0,V.jsx)(`span`,{children:t(`logs.decryptionFailed`,`[解密失败]`)})]}):e.client_ip||`-`}),(0,V.jsx)(`td`,{children:(0,V.jsx)(w,{minimal:!0,children:P(e.geo_country)})}),(0,V.jsx)(`td`,{className:`text-right font-bold`,children:e.count})]},n)),(!e||e.length===0)&&(0,V.jsx)(`tr`,{children:(0,V.jsx)(`td`,{colSpan:3,className:`text-center py-8 opacity-50`,children:t(`analytics.noData`)})})]})]})})};var X=(0,z.lazy)(()=>f(()=>import(`./TrendChart-B8jOSMgO.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(e=>({default:e.TrendChart}))),Z=(0,z.lazy)(()=>f(()=>import(`./DestinationMap-DoNQwdnV.js`),__vite__mapDeps([11,1,2,3,4,5,6,7,8,9,10,12,13])).then(e=>({default:e.DestinationMap}))),Q=()=>(0,V.jsx)(`div`,{className:`h-64 flex items-center justify-center`,children:(0,V.jsx)(_,{size:30})});const $=({profileId:e,toasterRef:t})=>{let{t:r}=o(),i=N(),{data:a,loading:s,range:c,setRange:l,customRange:u,setCustomRange:d,accessPointIdFilter:f,setAccessPointIdFilter:p,accessPoints:g,logRetentionDays:v,fetchData:b}=W(e,t),{isE2eeEnabled:x,isE2eeUnlocked:C,unlocking:T,recoveryDialogOpen:O,setRecoveryDialogOpen:k,recoveryKeyInput:A,setRecoveryKeyInput:j,recoveryError:M,setRecoveryError:P,rotatedKey:U,setRotatedKey:G,copiedKey:q,handleCopyRotatedKey:$,handleUnlockPasskey:ee,handleUnlockRecoveryKey:te}=R({profileId:e,range:c,onUnlocked:()=>{b(c,u.start,u.end,f)},toasterRef:t}),ne=!!(a&&(a.top_allowed?.some(e=>e.domain===`[Encrypted]`)||a.top_blocked?.some(e=>e.domain===`[Encrypted]`)||a.clients?.some(e=>e.client_ip===`[Encrypted]`)));if(s&&!a)return(0,V.jsx)(`div`,{className:`p-20 flex justify-center`,children:(0,V.jsx)(_,{size:50})});let re=B(a,c,u);return(0,V.jsxs)(`div`,{className:D(`max-w-7xl mx-auto space-y-6`,i?`p-0`:`p-6`),children:[(0,V.jsx)(K,{range:c,setRange:l,customRange:u,setCustomRange:d,logRetentionDays:v,accessPoints:g,accessPointIdFilter:f,setAccessPointIdFilter:p,loading:s,onApplyCustom:()=>{l(`custom`),b(`custom`,u.start,u.end,f)}}),(x||ne)&&!C&&(0,V.jsx)(F,{isMobile:i,unlocking:T,onUnlockPasskey:ee,onOpenRecoveryDialog:()=>{P(``),j(``),k(!0)}}),(0,V.jsx)(J,{data:a}),(0,V.jsxs)(E,{elevation:m.ONE,className:`dark:bg-gray-900 dark:border-gray-800 relative`,children:[(0,V.jsxs)(h,{className:`mb-4 font-bold flex items-center gap-2`,children:[r(`analytics.queryTrend`),(0,V.jsx)(w,{minimal:!0,round:!0,children:c===`custom`?r(`analytics.custom`):c.toUpperCase()})]}),(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)(Q,{}),children:(0,V.jsx)(X,{chartData:re,range:c})})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,V.jsx)(H,{title:r(`analytics.topAllowed`),data:a?.top_allowed||[],intent:y.SUCCESS}),(0,V.jsx)(H,{title:r(`analytics.topBlocked`),data:a?.top_blocked||[],intent:y.DANGER})]}),(0,V.jsxs)(`div`,{className:`grid gap-6 grid-cols-1`,children:[(0,V.jsx)(S,{title:r(`analytics.destinationDistribution`),icon:(0,V.jsx)(n,{size:16}),children:(0,V.jsx)(z.Suspense,{fallback:(0,V.jsx)(Q,{}),children:(0,V.jsx)(Z,{destinations:a?.destinations||[],profileId:e||``,range:c,customRange:u,accessPointId:f||void 0})})}),(0,V.jsx)(Y,{clients:a?.clients})]}),(0,V.jsx)(L,{isOpen:O,onClose:()=>k(!1),recoveryKeyInput:A,setRecoveryKeyInput:j,recoveryError:M,unlocking:T,onSubmit:te}),(0,V.jsx)(I,{rotatedKey:U,onClose:()=>G(null),copiedKey:q,onCopyKey:$})]})};export{$ as AnalyticsView};
@@ -1 +0,0 @@
1
- import{gt as e}from"./vendor-utils-DkfyN6f3.js";export default e();
@@ -1 +0,0 @@
1
- import{_ as e,g as t,h as n}from"./index-BDIG7T8u.js";export{t as setSystemLocale,e as setSystemTimeZone};