"use strict";(()=>{var $s=Object.create;var uo=Object.defineProperty;var qs=Object.getOwnPropertyDescriptor;var Gs=Object.getOwnPropertyNames;var Xs=Object.getPrototypeOf,Zs=Object.prototype.hasOwnProperty;var Ws=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var Gr=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Ys=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Gs(e))!Zs.call(r,i)&&i!==t&&uo(r,i,{get:()=>e[i],enumerable:!(n=qs(e,i))||n.enumerable});return r};var Ue=(r,e,t)=>(t=r!=null?$s(Xs(r)):{},Ys(e||!r||!r.__esModule?uo(t,"default",{value:r,enumerable:!0}):t,r));var ho=Gr(Xr=>{"use strict";Xr.byteLength=Qs;Xr.toByteArray=ta;Xr.fromByteArray=ia;var $e=[],Ce=[],Js=typeof Uint8Array<"u"?Uint8Array:Array,ni="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Pt=0,lo=ni.length;Pt<lo;++Pt)$e[Pt]=ni[Pt],Ce[ni.charCodeAt(Pt)]=Pt;var Pt,lo;Ce[45]=62;Ce[95]=63;function fo(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function Qs(r){var e=fo(r),t=e[0],n=e[1];return(t+n)*3/4-n}function ea(r,e,t){return(e+t)*3/4-t}function ta(r){var e,t=fo(r),n=t[0],i=t[1],o=new Js(ea(r,n,i)),s=0,a=i>0?n-4:n,u;for(u=0;u<a;u+=4)e=Ce[r.charCodeAt(u)]<<18|Ce[r.charCodeAt(u+1)]<<12|Ce[r.charCodeAt(u+2)]<<6|Ce[r.charCodeAt(u+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=Ce[r.charCodeAt(u)]<<2|Ce[r.charCodeAt(u+1)]>>4,o[s++]=e&255),i===1&&(e=Ce[r.charCodeAt(u)]<<10|Ce[r.charCodeAt(u+1)]<<4|Ce[r.charCodeAt(u+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function ra(r){return $e[r>>18&63]+$e[r>>12&63]+$e[r>>6&63]+$e[r&63]}function na(r,e,t){for(var n,i=[],o=e;o<t;o+=3)n=(r[o]<<16&16711680)+(r[o+1]<<8&65280)+(r[o+2]&255),i.push(ra(n));return i.join("")}function ia(r){for(var e,t=r.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(na(r,s,s+o>a?a:s+o));return n===1?(e=r[t-1],i.push($e[e>>2]+$e[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push($e[e>>10]+$e[e>>4&63]+$e[e<<2&63]+"=")),i.join("")}});var po=Gr(ii=>{ii.read=function(r,e,t,n,i){var o,s,a=i*8-n-1,u=(1<<a)-1,d=u>>1,c=-7,l=t?i-1:0,f=t?-1:1,h=r[e+l];for(l+=f,o=h&(1<<-c)-1,h>>=-c,c+=a;c>0;o=o*256+r[e+l],l+=f,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=s*256+r[e+l],l+=f,c-=8);if(o===0)o=1-d;else{if(o===u)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),o=o-d}return(h?-1:1)*s*Math.pow(2,o-n)};ii.write=function(r,e,t,n,i,o){var s,a,u,d=o*8-i-1,c=(1<<d)-1,l=c>>1,f=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:o-1,p=n?1:-1,y=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),s+l>=1?e+=f/u:e+=f*Math.pow(2,1-l),e*u>=2&&(s++,u/=2),s+l>=c?(a=0,s=c):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s=s+l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;r[t+h]=a&255,h+=p,a/=256,i-=8);for(s=s<<i|a,d+=i;d>0;r[t+h]=s&255,h+=p,s/=256,d-=8);r[t+h-p]|=y*128}});var ze=Gr(Xt=>{"use strict";var oi=ho(),qt=po(),wo=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Xt.Buffer=w;Xt.SlowBuffer=la;Xt.INSPECT_MAX_BYTES=50;var Zr=2147483647;Xt.kMaxLength=Zr;w.TYPED_ARRAY_SUPPORT=oa();!w.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function oa(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(w.prototype,"parent",{enumerable:!0,get:function(){if(w.isBuffer(this))return this.buffer}});Object.defineProperty(w.prototype,"offset",{enumerable:!0,get:function(){if(w.isBuffer(this))return this.byteOffset}});function Qe(r){if(r>Zr)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,w.prototype),e}function w(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ui(r)}return bo(r,e,t)}w.poolSize=8192;function bo(r,e,t){if(typeof r=="string")return aa(r,e);if(ArrayBuffer.isView(r))return ca(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(qe(r,ArrayBuffer)||r&&qe(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qe(r,SharedArrayBuffer)||r&&qe(r.buffer,SharedArrayBuffer)))return ai(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return w.from(n,e,t);let i=ua(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return w.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}w.from=function(r,e,t){return bo(r,e,t)};Object.setPrototypeOf(w.prototype,Uint8Array.prototype);Object.setPrototypeOf(w,Uint8Array);function xo(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function sa(r,e,t){return xo(r),r<=0?Qe(r):e!==void 0?typeof t=="string"?Qe(r).fill(e,t):Qe(r).fill(e):Qe(r)}w.alloc=function(r,e,t){return sa(r,e,t)};function ui(r){return xo(r),Qe(r<0?0:li(r)|0)}w.allocUnsafe=function(r){return ui(r)};w.allocUnsafeSlow=function(r){return ui(r)};function aa(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!w.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=Eo(r,e)|0,n=Qe(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function si(r){let e=r.length<0?0:li(r.length)|0,t=Qe(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function ca(r){if(qe(r,Uint8Array)){let e=new Uint8Array(r);return ai(e.buffer,e.byteOffset,e.byteLength)}return si(r)}function ai(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,w.prototype),n}function ua(r){if(w.isBuffer(r)){let e=li(r.length)|0,t=Qe(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||hi(r.length)?Qe(0):si(r);if(r.type==="Buffer"&&Array.isArray(r.data))return si(r.data)}function li(r){if(r>=Zr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Zr.toString(16)+" bytes");return r|0}function la(r){return+r!=r&&(r=0),w.alloc(+r)}w.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==w.prototype};w.compare=function(e,t){if(qe(e,Uint8Array)&&(e=w.from(e,e.offset,e.byteLength)),qe(t,Uint8Array)&&(t=w.from(t,t.offset,t.byteLength)),!w.isBuffer(e)||!w.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let o=0,s=Math.min(n,i);o<s;++o)if(e[o]!==t[o]){n=e[o],i=t[o];break}return n<i?-1:i<n?1:0};w.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};w.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return w.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let i=w.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){let s=e[n];if(qe(s,Uint8Array))o+s.length>i.length?(w.isBuffer(s)||(s=w.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(w.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Eo(r,e){if(w.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||qe(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return ci(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Lo(r).length;default:if(i)return n?-1:ci(r).length;e=(""+e).toLowerCase(),i=!0}}w.byteLength=Eo;function fa(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return Ea(this,e,t);case"utf8":case"utf-8":return vo(this,e,t);case"ascii":return ba(this,e,t);case"latin1":case"binary":return xa(this,e,t);case"base64":return ga(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _a(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}w.prototype._isBuffer=!0;function Lt(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}w.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)Lt(this,t,t+1);return this};w.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)Lt(this,t,t+3),Lt(this,t+1,t+2);return this};w.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)Lt(this,t,t+7),Lt(this,t+1,t+6),Lt(this,t+2,t+5),Lt(this,t+3,t+4);return this};w.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?vo(this,0,e):fa.apply(this,arguments)};w.prototype.toLocaleString=w.prototype.toString;w.prototype.equals=function(e){if(!w.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:w.compare(this,e)===0};w.prototype.inspect=function(){let e="",t=Xt.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};wo&&(w.prototype[wo]=w.prototype.inspect);w.prototype.compare=function(e,t,n,i,o){if(qe(e,Uint8Array)&&(e=w.from(e,e.offset,e.byteLength)),!w.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,a=n-t,u=Math.min(s,a),d=this.slice(i,o),c=e.slice(t,n);for(let l=0;l<u;++l)if(d[l]!==c[l]){s=d[l],a=c[l];break}return s<a?-1:a<s?1:0};function _o(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,hi(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=w.from(e,n)),w.isBuffer(e))return e.length===0?-1:mo(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):mo(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function mo(r,e,t,n,i){let o=1,s=r.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;o=2,s/=2,a/=2,t/=2}function u(c,l){return o===1?c[l]:c.readUInt16BE(l*o)}let d;if(i){let c=-1;for(d=t;d<s;d++)if(u(r,d)===u(e,c===-1?0:d-c)){if(c===-1&&(c=d),d-c+1===a)return c*o}else c!==-1&&(d-=d-c),c=-1}else for(t+a>s&&(t=s-a),d=t;d>=0;d--){let c=!0;for(let l=0;l<a;l++)if(u(r,d+l)!==u(e,l)){c=!1;break}if(c)return d}return-1}w.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};w.prototype.indexOf=function(e,t,n){return _o(this,e,t,n,!0)};w.prototype.lastIndexOf=function(e,t,n){return _o(this,e,t,n,!1)};function ha(r,e,t,n){t=Number(t)||0;let i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let o=e.length;n>o/2&&(n=o/2);let s;for(s=0;s<n;++s){let a=parseInt(e.substr(s*2,2),16);if(hi(a))return s;r[t+s]=a}return s}function da(r,e,t,n){return Wr(ci(e,r.length-t),r,t,n)}function pa(r,e,t,n){return Wr(Ba(e),r,t,n)}function wa(r,e,t,n){return Wr(Lo(e),r,t,n)}function ma(r,e,t,n){return Wr(Ia(e,r.length-t),r,t,n)}w.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return ha(this,e,t,n);case"utf8":case"utf-8":return da(this,e,t,n);case"ascii":case"latin1":case"binary":return pa(this,e,t,n);case"base64":return wa(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ma(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ga(r,e,t){return e===0&&t===r.length?oi.fromByteArray(r):oi.fromByteArray(r.slice(e,t))}function vo(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i<t;){let o=r[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(i+a<=t){let u,d,c,l;switch(a){case 1:o<128&&(s=o);break;case 2:u=r[i+1],(u&192)===128&&(l=(o&31)<<6|u&63,l>127&&(s=l));break;case 3:u=r[i+1],d=r[i+2],(u&192)===128&&(d&192)===128&&(l=(o&15)<<12|(u&63)<<6|d&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:u=r[i+1],d=r[i+2],c=r[i+3],(u&192)===128&&(d&192)===128&&(c&192)===128&&(l=(o&15)<<18|(u&63)<<12|(d&63)<<6|c&63,l>65535&&l<1114112&&(s=l))}}s===null?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=a}return ya(n)}var go=4096;function ya(r){let e=r.length;if(e<=go)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=go));return t}function ba(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function xa(r,e,t){let n="";t=Math.min(r.length,t);for(let i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function Ea(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let i="";for(let o=e;o<t;++o)i+=Aa[r[o]];return i}function _a(r,e,t){let n=r.slice(e,t),i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}w.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let i=this.subarray(e,t);return Object.setPrototypeOf(i,w.prototype),i};function he(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}w.prototype.readUintLE=w.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||he(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return i};w.prototype.readUintBE=w.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||he(e,t,this.length);let i=this[e+--t],o=1;for(;t>0&&(o*=256);)i+=this[e+--t]*o;return i};w.prototype.readUint8=w.prototype.readUInt8=function(e,t){return e=e>>>0,t||he(e,1,this.length),this[e]};w.prototype.readUint16LE=w.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||he(e,2,this.length),this[e]|this[e+1]<<8};w.prototype.readUint16BE=w.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||he(e,2,this.length),this[e]<<8|this[e+1]};w.prototype.readUint32LE=w.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||he(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};w.prototype.readUint32BE=w.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||he(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};w.prototype.readBigUInt64LE=lt(function(e){e=e>>>0,Gt(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mr(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});w.prototype.readBigUInt64BE=lt(function(e){e=e>>>0,Gt(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mr(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<<BigInt(32))+BigInt(o)});w.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||he(e,t,this.length);let i=this[e],o=1,s=0;for(;++s<t&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i};w.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||he(e,t,this.length);let i=t,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*t)),s};w.prototype.readInt8=function(e,t){return e=e>>>0,t||he(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};w.prototype.readInt16LE=function(e,t){e=e>>>0,t||he(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};w.prototype.readInt16BE=function(e,t){e=e>>>0,t||he(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};w.prototype.readInt32LE=function(e,t){return e=e>>>0,t||he(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};w.prototype.readInt32BE=function(e,t){return e=e>>>0,t||he(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};w.prototype.readBigInt64LE=lt(function(e){e=e>>>0,Gt(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mr(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});w.prototype.readBigInt64BE=lt(function(e){e=e>>>0,Gt(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&mr(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)});w.prototype.readFloatLE=function(e,t){return e=e>>>0,t||he(e,4,this.length),qt.read(this,e,!0,23,4)};w.prototype.readFloatBE=function(e,t){return e=e>>>0,t||he(e,4,this.length),qt.read(this,e,!1,23,4)};w.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||he(e,8,this.length),qt.read(this,e,!0,52,8)};w.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||he(e,8,this.length),qt.read(this,e,!1,52,8)};function _e(r,e,t,n,i,o){if(!w.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}w.prototype.writeUintLE=w.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;_e(this,e,t,n,a,0)}let o=1,s=0;for(this[t]=e&255;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n};w.prototype.writeUintBE=w.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;_e(this,e,t,n,a,0)}let o=n-1,s=1;for(this[t+o]=e&255;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n};w.prototype.writeUint8=w.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,1,255,0),this[t]=e&255,t+1};w.prototype.writeUint16LE=w.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};w.prototype.writeUint16BE=w.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};w.prototype.writeUint32LE=w.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};w.prototype.writeUint32BE=w.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function So(r,e,t,n,i){Po(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,t}function ko(r,e,t,n,i){Po(e,n,i,r,t,7);let o=Number(e&BigInt(4294967295));r[t+7]=o,o=o>>8,r[t+6]=o,o=o>>8,r[t+5]=o,o=o>>8,r[t+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=s,s=s>>8,r[t+2]=s,s=s>>8,r[t+1]=s,s=s>>8,r[t]=s,t+8}w.prototype.writeBigUInt64LE=lt(function(e,t=0){return So(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});w.prototype.writeBigUInt64BE=lt(function(e,t=0){return ko(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});w.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);_e(this,e,t,n,u-1,-u)}let o=0,s=1,a=0;for(this[t]=e&255;++o<n&&(s*=256);)e<0&&a===0&&this[t+o-1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};w.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let u=Math.pow(2,8*n-1);_e(this,e,t,n,u-1,-u)}let o=n-1,s=1,a=0;for(this[t+o]=e&255;--o>=0&&(s*=256);)e<0&&a===0&&this[t+o+1]!==0&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n};w.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};w.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};w.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};w.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};w.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||_e(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};w.prototype.writeBigInt64LE=lt(function(e,t=0){return So(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});w.prototype.writeBigInt64BE=lt(function(e,t=0){return ko(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Bo(r,e,t,n,i,o){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Io(r,e,t,n,i){return e=+e,t=t>>>0,i||Bo(r,e,t,4,34028234663852886e22,-34028234663852886e22),qt.write(r,e,t,n,23,4),t+4}w.prototype.writeFloatLE=function(e,t,n){return Io(this,e,t,!0,n)};w.prototype.writeFloatBE=function(e,t,n){return Io(this,e,t,!1,n)};function Ao(r,e,t,n,i){return e=+e,t=t>>>0,i||Bo(r,e,t,8,17976931348623157e292,-17976931348623157e292),qt.write(r,e,t,n,52,8),t+8}w.prototype.writeDoubleLE=function(e,t,n){return Ao(this,e,t,!0,n)};w.prototype.writeDoubleBE=function(e,t,n){return Ao(this,e,t,!1,n)};w.prototype.copy=function(e,t,n,i){if(!w.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);let o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),o};w.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!w.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let o;if(typeof e=="number")for(o=t;o<n;++o)this[o]=e;else{let s=w.isBuffer(e)?e:w.from(e,i),a=s.length;if(a===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<n-t;++o)this[o+t]=s[o%a]}return this};var $t={};function fi(r,e,t){$t[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}fi("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);fi("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError);fi("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=yo(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=yo(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function yo(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function va(r,e,t){Gt(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&mr(e,r.length-(t+1))}function Po(r,e,t,n,i,o){if(r>t||r<e){let s=typeof e=="bigint"?"n":"",a;throw o>3?e===0||e===BigInt(0)?a=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:a=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:a=`>= ${e}${s} and <= ${t}${s}`,new $t.ERR_OUT_OF_RANGE("value",a,r)}va(n,i,o)}function Gt(r,e){if(typeof r!="number")throw new $t.ERR_INVALID_ARG_TYPE(e,"number",r)}function mr(r,e,t){throw Math.floor(r)!==r?(Gt(r,t),new $t.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new $t.ERR_BUFFER_OUT_OF_BOUNDS:new $t.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var Sa=/[^+/0-9A-Za-z-_]/g;function ka(r){if(r=r.split("=")[0],r=r.trim().replace(Sa,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function ci(r,e){e=e||1/0;let t,n=r.length,i=null,o=[];for(let s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&o.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;o.push(t)}else if(t<2048){if((e-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function Ba(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function Ia(r,e){let t,n,i,o=[];for(let s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,o.push(i),o.push(n);return o}function Lo(r){return oi.toByteArray(ka(r))}function Wr(r,e,t,n){let i;for(i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function qe(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function hi(r){return r!==r}var Aa=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function lt(r){return typeof BigInt>"u"?Pa:r}function Pa(){throw new Error("BigInt not supported")}});var js=Gr((Vr,Qn)=>{(function(r,e){"use strict";var t="1.0.39",n="",i="?",o="function",s="undefined",a="object",u="string",d="major",c="model",l="name",f="type",h="vendor",p="version",y="architecture",_="console",x="mobile",m="tablet",g="smarttv",k="wearable",C="embedded",R=500,z="Amazon",A="Apple",L="ASUS",O="BlackBerry",U="Browser",M="Chrome",$="Edge",q="Firefox",V="Google",S="Huawei",b="LG",v="Microsoft",E="Motorola",I="Opera",P="Samsung",T="Sharp",D="Sony",F="Xiaomi",G="Zebra",te="Facebook",ie="Chromium OS",ae="Mac OS",ce=" Browser",Ee=function(j,W){var H={};for(var Q in j)W[Q]&&W[Q].length%2===0?H[Q]=W[Q].concat(j[Q]):H[Q]=j[Q];return H},Ae=function(j){for(var W={},H=0;H<j.length;H++)W[j[H].toUpperCase()]=j[H];return W},Me=function(j,W){return typeof j===u?Re(W).indexOf(Re(j))!==-1:!1},Re=function(j){return j.toLowerCase()},$r=function(j){return typeof j===u?j.replace(/[^\d\.]/g,n).split(".")[0]:e},jt=function(j,W){if(typeof j===u)return j=j.replace(/^\s\s*/,n),typeof W===s?j:j.substring(0,R)},It=function(j,W){for(var H=0,Q,He,Te,J,K,Ve;H<W.length&&!K;){var ri=W[H],co=W[H+1];for(Q=He=0;Q<ri.length&&!K&&ri[Q];)if(K=ri[Q++].exec(j),K)for(Te=0;Te<co.length;Te++)Ve=K[++He],J=co[Te],typeof J===a&&J.length>0?J.length===2?typeof J[1]==o?this[J[0]]=J[1].call(this,Ve):this[J[0]]=J[1]:J.length===3?typeof J[1]===o&&!(J[1].exec&&J[1].test)?this[J[0]]=Ve?J[1].call(this,Ve,J[2]):e:this[J[0]]=Ve?Ve.replace(J[1],J[2]):e:J.length===4&&(this[J[0]]=Ve?J[3].call(this,Ve.replace(J[1],J[2])):e):this[J]=Ve||e;H+=2}},Vt=function(j,W){for(var H in W)if(typeof W[H]===a&&W[H].length>0){for(var Q=0;Q<W[H].length;Q++)if(Me(W[H][Q],j))return H===i?e:H}else if(Me(W[H],j))return H===i?e:H;return W.hasOwnProperty("*")?W["*"]:j},ti={"1.0":"/8","1.2":"/1","1.3":"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"},qr={ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2","8.1":"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"},wr={browser:[[/\b(?:crmo|crios)\/([\w\.]+)/i],[p,[l,"Chrome"]],[/edg(?:e|ios|a)?\/([\w\.]+)/i],[p,[l,"Edge"]],[/(opera mini)\/([-\w\.]+)/i,/(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,/(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i],[l,p],[/opios[\/ ]+([\w\.]+)/i],[p,[l,I+" Mini"]],[/\bop(?:rg)?x\/([\w\.]+)/i],[p,[l,I+" GX"]],[/\bopr\/([\w\.]+)/i],[p,[l,I]],[/\bb[ai]*d(?:uhd|[ub]*[aekoprswx]{5,6})[\/ ]?([\w\.]+)/i],[p,[l,"Baidu"]],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer|sleipnir)[\/ ]?([\w\.]*)/i,/(avant|iemobile|slim)\s?(?:browser)?[\/ ]?([\w\.]*)/i,/(?:ms|\()(ie) ([\w\.]+)/i,/(flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|qupzilla|falkon|rekonq|puffin|brave|whale(?!.+naver)|qqbrowserlite|duckduckgo|klar|helio)\/([-\w\.]+)/i,/(heytap|ovi)browser\/([\d\.]+)/i,/(weibo)__([\d\.]+)/i],[l,p],[/quark(?:pc)?\/([-\w\.]+)/i],[p,[l,"Quark"]],[/\bddg\/([\w\.]+)/i],[p,[l,"DuckDuckGo"]],[/(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i],[p,[l,"UC"+U]],[/microm.+\bqbcore\/([\w\.]+)/i,/\bqbcore\/([\w\.]+).+microm/i,/micromessenger\/([\w\.]+)/i],[p,[l,"WeChat"]],[/konqueror\/([\w\.]+)/i],[p,[l,"Konqueror"]],[/trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i],[p,[l,"IE"]],[/ya(?:search)?browser\/([\w\.]+)/i],[p,[l,"Yandex"]],[/slbrowser\/([\w\.]+)/i],[p,[l,"Smart Lenovo "+U]],[/(avast|avg)\/([\w\.]+)/i],[[l,/(.+)/,"$1 Secure "+U],p],[/\bfocus\/([\w\.]+)/i],[p,[l,q+" Focus"]],[/\bopt\/([\w\.]+)/i],[p,[l,I+" Touch"]],[/coc_coc\w+\/([\w\.]+)/i],[p,[l,"Coc Coc"]],[/dolfin\/([\w\.]+)/i],[p,[l,"Dolphin"]],[/coast\/([\w\.]+)/i],[p,[l,I+" Coast"]],[/miuibrowser\/([\w\.]+)/i],[p,[l,"MIUI "+U]],[/fxios\/([-\w\.]+)/i],[p,[l,q]],[/\bqihu|(qi?ho?o?|360)browser/i],[[l,"360"+ce]],[/\b(qq)\/([\w\.]+)/i],[[l,/(.+)/,"$1Browser"],p],[/(oculus|sailfish|huawei|vivo|pico)browser\/([\w\.]+)/i],[[l,/(.+)/,"$1"+ce],p],[/samsungbrowser\/([\w\.]+)/i],[p,[l,P+" Internet"]],[/(comodo_dragon)\/([\w\.]+)/i],[[l,/_/g," "],p],[/metasr[\/ ]?([\d\.]+)/i],[p,[l,"Sogou Explorer"]],[/(sogou)mo\w+\/([\d\.]+)/i],[[l,"Sogou Mobile"],p],[/(electron)\/([\w\.]+) safari/i,/(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,/m?(qqbrowser|2345Explorer)[\/ ]?([\w\.]+)/i],[l,p],[/(lbbrowser|rekonq)/i,/\[(linkedin)app\]/i],[l],[/((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i],[[l,te],p],[/(Klarna)\/([\w\.]+)/i,/(kakao(?:talk|story))[\/ ]([\w\.]+)/i,/(naver)\(.*?(\d+\.[\w\.]+).*\)/i,/safari (line)\/([\w\.]+)/i,/\b(line)\/([\w\.]+)\/iab/i,/(alipay)client\/([\w\.]+)/i,/(twitter)(?:and| f.+e\/([\w\.]+))/i,/(chromium|instagram|snapchat)[\/ ]([-\w\.]+)/i],[l,p],[/\bgsa\/([\w\.]+) .*safari\//i],[p,[l,"GSA"]],[/musical_ly(?:.+app_?version\/|_)([\w\.]+)/i],[p,[l,"TikTok"]],[/headlesschrome(?:\/([\w\.]+)| )/i],[p,[l,M+" Headless"]],[/ wv\).+(chrome)\/([\w\.]+)/i],[[l,M+" WebView"],p],[/droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i],[p,[l,"Android "+U]],[/(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i],[l,p],[/version\/([\w\.\,]+) .*mobile\/\w+ (safari)/i],[p,[l,"Mobile Safari"]],[/version\/([\w(\.|\,)]+) .*(mobile ?safari|safari)/i],[p,l],[/webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i],[l,[p,Vt,ti]],[/(webkit|khtml)\/([\w\.]+)/i],[l,p],[/(navigator|netscape\d?)\/([-\w\.]+)/i],[[l,"Netscape"],p],[/(wolvic)\/([\w\.]+)/i],[l,p],[/mobile vr; rv:([\w\.]+)\).+firefox/i],[p,[l,q+" Reality"]],[/ekiohf.+(flow)\/([\w\.]+)/i,/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror)[\/ ]?([\w\.\+]+)/i,/(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([-\w\.]+)$/i,/(firefox)\/([\w\.]+)/i,/(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,/(links) \(([\w\.]+)/i],[l,[p,/_/g,"."]],[/(cobalt)\/([\w\.]+)/i],[l,[p,/master.|lts./,""]]],cpu:[[/(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i],[[y,"amd64"]],[/(ia32(?=;))/i],[[y,Re]],[/((?:i[346]|x)86)[;\)]/i],[[y,"ia32"]],[/\b(aarch64|arm(v?8e?l?|_?64))\b/i],[[y,"arm64"]],[/\b(arm(?:v[67])?ht?n?[fl]p?)\b/i],[[y,"armhf"]],[/windows (ce|mobile); ppc;/i],[[y,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i],[[y,/ower/,n,Re]],[/(sun4\w)[;\)]/i],[[y,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i],[[y,Re]]],device:[[/\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i],[c,[h,P],[f,m]],[/\b((?:s[cgp]h|gt|sm)-(?![lr])\w+|sc[g-]?[\d]+a?|galaxy nexus)/i,/samsung[- ]((?!sm-[lr])[-\w]+)/i,/sec-(sgh\w+)/i],[c,[h,P],[f,x]],[/(?:\/|\()(ip(?:hone|od)[\w, ]*)(?:\/|;)/i],[c,[h,A],[f,x]],[/\((ipad);[-\w\),; ]+apple/i,/applecoremedia\/[\w\.]+ \((ipad)/i,/\b(ipad)\d\d?,\d\d?[;\]].+ios/i],[c,[h,A],[f,m]],[/(macintosh);/i],[c,[h,A]],[/\b(sh-?[altvz]?\d\d[a-ekm]?)/i],[c,[h,T],[f,x]],[/\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i],[c,[h,S],[f,m]],[/(?:huawei|honor)([-\w ]+)[;\)]/i,/\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i],[c,[h,S],[f,x]],[/\b(poco[\w ]+|m2\d{3}j\d\d[a-z]{2})(?: bui|\))/i,/\b; (\w+) build\/hm\1/i,/\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i,/\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i,/oid[^\)]+; (m?[12][0-389][01]\w{3,6}[c-y])( bui|; wv|\))/i,/\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note lte|max|cc)?[_ ]?(?:\d?\w?)[_ ]?(?:plus|se|lite|pro)?)(?: bui|\))/i],[[c,/_/g," "],[h,F],[f,x]],[/oid[^\)]+; (2\d{4}(283|rpbf)[cgl])( bui|\))/i,/\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i],[[c,/_/g," "],[h,F],[f,m]],[/; (\w+) bui.+ oppo/i,/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i],[c,[h,"OPPO"],[f,x]],[/\b(opd2\d{3}a?) bui/i],[c,[h,"OPPO"],[f,m]],[/vivo (\w+)(?: bui|\))/i,/\b(v[12]\d{3}\w?[at])(?: bui|;)/i],[c,[h,"Vivo"],[f,x]],[/\b(rmx[1-3]\d{3})(?: bui|;|\))/i],[c,[h,"Realme"],[f,x]],[/\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,/\bmot(?:orola)?[- ](\w*)/i,/((?:moto[\w\(\) ]+|xt\d{3,4}|nexus 6)(?= bui|\)))/i],[c,[h,E],[f,x]],[/\b(mz60\d|xoom[2 ]{0,2}) build\//i],[c,[h,E],[f,m]],[/((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i],[c,[h,b],[f,m]],[/(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,/\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,/\blg-?([\d\w]+) bui/i],[c,[h,b],[f,x]],[/(ideatab[-\w ]+)/i,/lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i],[c,[h,"Lenovo"],[f,m]],[/(?:maemo|nokia).*(n900|lumia \d+)/i,/nokia[-_ ]?([-\w\.]*)/i],[[c,/_/g," "],[h,"Nokia"],[f,x]],[/(pixel c)\b/i],[c,[h,V],[f,m]],[/droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i],[c,[h,V],[f,x]],[/droid.+ (a?\d[0-2]{2}so|[c-g]\d{4}|so[-gl]\w+|xq-a\w[4-7][12])(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i],[c,[h,D],[f,x]],[/sony tablet [ps]/i,/\b(?:sony)?sgp\w+(?: bui|\))/i],[[c,"Xperia Tablet"],[h,D],[f,m]],[/ (kb2005|in20[12]5|be20[12][59])\b/i,/(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i],[c,[h,"OnePlus"],[f,x]],[/(alexa)webm/i,/(kf[a-z]{2}wi|aeo(?!bc)\w\w)( bui|\))/i,/(kf[a-z]+)( bui|\)).+silk\//i],[c,[h,z],[f,m]],[/((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i],[[c,/(.+)/g,"Fire Phone $1"],[h,z],[f,x]],[/(playbook);[-\w\),; ]+(rim)/i],[c,h,[f,m]],[/\b((?:bb[a-f]|st[hv])100-\d)/i,/\(bb10; (\w+)/i],[c,[h,O],[f,x]],[/(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i],[c,[h,L],[f,m]],[/ (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i],[c,[h,L],[f,x]],[/(nexus 9)/i],[c,[h,"HTC"],[f,m]],[/(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,/(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,/(alcatel|geeksphone|nexian|panasonic(?!(?:;|\.))|sony(?!-bra))[-_ ]?([-\w]*)/i],[h,[c,/_/g," "],[f,x]],[/droid [\w\.]+; ((?:8[14]9[16]|9(?:0(?:48|60|8[01])|1(?:3[27]|66)|2(?:6[69]|9[56])|466))[gqswx])\w*(\)| bui)/i],[c,[h,"TCL"],[f,m]],[/(itel) ((\w+))/i],[[h,Re],c,[f,Vt,{tablet:["p10001l","w7001"],"*":"mobile"}]],[/droid.+; ([ab][1-7]-?[0178a]\d\d?)/i],[c,[h,"Acer"],[f,m]],[/droid.+; (m[1-5] note) bui/i,/\bmz-([-\w]{2,})/i],[c,[h,"Meizu"],[f,x]],[/; ((?:power )?armor(?:[\w ]{0,8}))(?: bui|\))/i],[c,[h,"Ulefone"],[f,x]],[/droid.+; (a(?:015|06[35]|142p?))/i],[c,[h,"Nothing"],[f,x]],[/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron|infinix|tecno)[-_ ]?([-\w]*)/i,/(hp) ([\w ]+\w)/i,/(asus)-?(\w+)/i,/(microsoft); (lumia[\w ]+)/i,/(lenovo)[-_ ]?([-\w]+)/i,/(jolla)/i,/(oppo) ?([\w ]+) bui/i],[h,c,[f,x]],[/(kobo)\s(ereader|touch)/i,/(archos) (gamepad2?)/i,/(hp).+(touchpad(?!.+tablet)|tablet)/i,/(kindle)\/([\w\.]+)/i,/(nook)[\w ]+build\/(\w+)/i,/(dell) (strea[kpr\d ]*[\dko])/i,/(le[- ]+pan)[- ]+(\w{1,9}) bui/i,/(trinity)[- ]*(t\d{3}) bui/i,/(gigaset)[- ]+(q\w{1,9}) bui/i,/(vodafone) ([\w ]+)(?:\)| bui)/i],[h,c,[f,m]],[/(surface duo)/i],[c,[h,v],[f,m]],[/droid [\d\.]+; (fp\du?)(?: b|\))/i],[c,[h,"Fairphone"],[f,x]],[/(u304aa)/i],[c,[h,"AT&T"],[f,x]],[/\bsie-(\w*)/i],[c,[h,"Siemens"],[f,x]],[/\b(rct\w+) b/i],[c,[h,"RCA"],[f,m]],[/\b(venue[\d ]{2,7}) b/i],[c,[h,"Dell"],[f,m]],[/\b(q(?:mv|ta)\w+) b/i],[c,[h,"Verizon"],[f,m]],[/\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i],[c,[h,"Barnes & Noble"],[f,m]],[/\b(tm\d{3}\w+) b/i],[c,[h,"NuVision"],[f,m]],[/\b(k88) b/i],[c,[h,"ZTE"],[f,m]],[/\b(nx\d{3}j) b/i],[c,[h,"ZTE"],[f,x]],[/\b(gen\d{3}) b.+49h/i],[c,[h,"Swiss"],[f,x]],[/\b(zur\d{3}) b/i],[c,[h,"Swiss"],[f,m]],[/\b((zeki)?tb.*\b) b/i],[c,[h,"Zeki"],[f,m]],[/\b([yr]\d{2}) b/i,/\b(dragon[- ]+touch |dt)(\w{5}) b/i],[[h,"Dragon Touch"],c,[f,m]],[/\b(ns-?\w{0,9}) b/i],[c,[h,"Insignia"],[f,m]],[/\b((nxa|next)-?\w{0,9}) b/i],[c,[h,"NextBook"],[f,m]],[/\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i],[[h,"Voice"],c,[f,x]],[/\b(lvtel\-)?(v1[12]) b/i],[[h,"LvTel"],c,[f,x]],[/\b(ph-1) /i],[c,[h,"Essential"],[f,x]],[/\b(v(100md|700na|7011|917g).*\b) b/i],[c,[h,"Envizen"],[f,m]],[/\b(trio[-\w\. ]+) b/i],[c,[h,"MachSpeed"],[f,m]],[/\btu_(1491) b/i],[c,[h,"Rotor"],[f,m]],[/(shield[\w ]+) b/i],[c,[h,"Nvidia"],[f,m]],[/(sprint) (\w+)/i],[h,c,[f,x]],[/(kin\.[onetw]{3})/i],[[c,/\./g," "],[h,v],[f,x]],[/droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i],[c,[h,G],[f,m]],[/droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i],[c,[h,G],[f,x]],[/smart-tv.+(samsung)/i],[h,[f,g]],[/hbbtv.+maple;(\d+)/i],[[c,/^/,"SmartTV"],[h,P],[f,g]],[/(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i],[[h,b],[f,g]],[/(apple) ?tv/i],[h,[c,A+" TV"],[f,g]],[/crkey/i],[[c,M+"cast"],[h,V],[f,g]],[/droid.+aft(\w+)( bui|\))/i],[c,[h,z],[f,g]],[/\(dtv[\);].+(aquos)/i,/(aquos-tv[\w ]+)\)/i],[c,[h,T],[f,g]],[/(bravia[\w ]+)( bui|\))/i],[c,[h,D],[f,g]],[/(mitv-\w{5}) bui/i],[c,[h,F],[f,g]],[/Hbbtv.*(technisat) (.*);/i],[h,c,[f,g]],[/\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,/hbbtv\/\d+\.\d+\.\d+ +\([\w\+ ]*; *([\w\d][^;]*);([^;]*)/i],[[h,jt],[c,jt],[f,g]],[/\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i],[[f,g]],[/(ouya)/i,/(nintendo) ([wids3utch]+)/i],[h,c,[f,_]],[/droid.+; (shield) bui/i],[c,[h,"Nvidia"],[f,_]],[/(playstation [345portablevi]+)/i],[c,[h,D],[f,_]],[/\b(xbox(?: one)?(?!; xbox))[\); ]/i],[c,[h,v],[f,_]],[/\b(sm-[lr]\d\d[05][fnuw]?s?)\b/i],[c,[h,P],[f,k]],[/((pebble))app/i],[h,c,[f,k]],[/(watch)(?: ?os[,\/]|\d,\d\/)[\d\.]+/i],[c,[h,A],[f,k]],[/droid.+; (glass) \d/i],[c,[h,V],[f,k]],[/droid.+; (wt63?0{2,3})\)/i],[c,[h,G],[f,k]],[/(quest( \d| pro)?)/i],[c,[h,te],[f,k]],[/(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i],[h,[f,C]],[/(aeobc)\b/i],[c,[h,z],[f,C]],[/droid .+?; ([^;]+?)(?: bui|; wv\)|\) applew).+? mobile safari/i],[c,[f,x]],[/droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i],[c,[f,m]],[/\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i],[[f,m]],[/(phone|mobile(?:[;\/]| [ \w\/\.]*safari)|pda(?=.+windows ce))/i],[[f,x]],[/(android[-\w\. ]{0,9});.+buil/i],[c,[h,"Generic"]]],engine:[[/windows.+ edge\/([\w\.]+)/i],[p,[l,$+"HTML"]],[/webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i],[p,[l,"Blink"]],[/(presto)\/([\w\.]+)/i,/(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,/ekioh(flow)\/([\w\.]+)/i,/(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i,/(icab)[\/ ]([23]\.[\d\.]+)/i,/\b(libweb)/i],[l,p],[/rv\:([\w\.]{1,9})\b.+(gecko)/i],[p,l]],os:[[/microsoft (windows) (vista|xp)/i],[l,p],[/(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i],[l,[p,Vt,qr]],[/windows nt 6\.2; (arm)/i,/windows[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i,/(?:win(?=3|9|n)|win 9x )([nt\d\.]+)/i],[[p,Vt,qr],[l,"Windows"]],[/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,/(?:ios;fbsv\/|iphone.+ios[\/ ])([\d\.]+)/i,/cfnetwork\/.+darwin/i],[[p,/_/g,"."],[l,"iOS"]],[/(mac os x) ?([\w\. ]*)/i,/(macintosh|mac_powerpc\b)(?!.+haiku)/i],[[l,ae],[p,/_/g,"."]],[/droid ([\w\.]+)\b.+(android[- ]x86|harmonyos)/i],[p,l],[/(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,/(blackberry)\w*\/([\w\.]*)/i,/(tizen|kaios)[\/ ]([\w\.]+)/i,/\((series40);/i],[l,p],[/\(bb(10);/i],[p,[l,O]],[/(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i],[p,[l,"Symbian"]],[/mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i],[p,[l,q+" OS"]],[/web0s;.+rt(tv)/i,/\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i],[p,[l,"webOS"]],[/watch(?: ?os[,\/]|\d,\d\/)([\d\.]+)/i],[p,[l,"watchOS"]],[/crkey\/([\d\.]+)/i],[p,[l,M+"cast"]],[/(cros) [\w]+(?:\)| ([\w\.]+)\b)/i],[[l,ie],p],[/panasonic;(viera)/i,/(netrange)mmh/i,/(nettv)\/(\d+\.[\w\.]+)/i,/(nintendo|playstation) ([wids345portablevuch]+)/i,/(xbox); +xbox ([^\);]+)/i,/\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i,/(mint)[\/\(\) ]?(\w*)/i,/(mageia|vectorlinux)[; ]/i,/([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,/(hurd|linux) ?([\w\.]*)/i,/(gnu) ?([\w\.]*)/i,/\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i,/(haiku) (\w+)/i],[l,p],[/(sunos) ?([\w\.\d]*)/i],[[l,"Solaris"],p],[/((?:open)?solaris)[-\/ ]?([\w\.]*)/i,/(aix) ((\d)(?=\.|\)| )[\w\.])*/i,/\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux|serenityos)/i,/(unix) ?([\w\.]*)/i],[l,p]]},ye=function(j,W){if(typeof j===a&&(W=j,j=e),!(this instanceof ye))return new ye(j,W).getResult();var H=typeof r!==s&&r.navigator?r.navigator:e,Q=j||(H&&H.userAgent?H.userAgent:n),He=H&&H.userAgentData?H.userAgentData:e,Te=W?Ee(wr,W):wr,J=H&&H.userAgent==Q;return this.getBrowser=function(){var K={};return K[l]=e,K[p]=e,It.call(K,Q,Te.browser),K[d]=$r(K[p]),J&&H&&H.brave&&typeof H.brave.isBrave==o&&(K[l]="Brave"),K},this.getCPU=function(){var K={};return K[y]=e,It.call(K,Q,Te.cpu),K},this.getDevice=function(){var K={};return K[h]=e,K[c]=e,K[f]=e,It.call(K,Q,Te.device),J&&!K[f]&&He&&He.mobile&&(K[f]=x),J&&K[c]=="Macintosh"&&H&&typeof H.standalone!==s&&H.maxTouchPoints&&H.maxTouchPoints>2&&(K[c]="iPad",K[f]=m),K},this.getEngine=function(){var K={};return K[l]=e,K[p]=e,It.call(K,Q,Te.engine),K},this.getOS=function(){var K={};return K[l]=e,K[p]=e,It.call(K,Q,Te.os),J&&!K[l]&&He&&He.platform&&He.platform!="Unknown"&&(K[l]=He.platform.replace(/chrome os/i,ie).replace(/macos/i,ae)),K},this.getResult=function(){return{ua:this.getUA(),browser:this.getBrowser(),engine:this.getEngine(),os:this.getOS(),device:this.getDevice(),cpu:this.getCPU()}},this.getUA=function(){return Q},this.setUA=function(K){return Q=typeof K===u&&K.length>R?jt(K,R):K,this},this.setUA(Q),this};ye.VERSION=t,ye.BROWSER=Ae([l,p,d]),ye.CPU=Ae([y]),ye.DEVICE=Ae([c,h,f,_,x,g,m,k,C]),ye.ENGINE=ye.OS=Ae([l,p]),typeof Vr!==s?(typeof Qn!==s&&Qn.exports&&(Vr=Qn.exports=ye),Vr.UAParser=ye):typeof define===o&&define.amd?define(function(){return ye}):typeof r!==s&&(r.UAParser=ye);var je=typeof r!==s&&(r.jQuery||r.Zepto);if(je&&!je.ua){var At=new ye;je.ua=At.getResult(),je.ua.get=function(){return At.getUA()},je.ua.set=function(j){At.setUA(j);var W=At.getResult();for(var H in W)je.ua[H]=W[H]}}})(typeof window=="object"?window:Vr)});var Fs=Ue(ze(),1);var di=Ue(ze(),1);var La=globalThis||window||self,Yr=La.crypto;function Jr(r,e){let t=256n**BigInt(e);if(r>=t)throw new Error(`Integer ${r} too large for ${e} byte array (max ${t}).`);let n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=Number(r%256n),r/=256n;return n}function To(r){return r.reduceRight((e,t,n)=>e+256n**BigInt(r.length-n-1)*BigInt(t),0n)}function Qr(r){return r.reduce((e,t,n)=>e+256n**BigInt(n)*BigInt(t),0n)}function Y(r,e){let t=new Array(r);for(let n=0;n<r;n++)t[n]=e(n);return t}function Tt(r,e,t){return t.slice(e*r,(e+1)*r)}function Ge(r,e){return new Array(r).fill(e)}function ft(r){if(r>0)return 2**Math.ceil(Math.log2(r));throw new Error("log of negative number")}function Uo(r){if(r===1n)return 1n;if(r>0n)return 2n**BigInt((r-1n).toString(2).length);throw new Error("log of negative number")}function Xe(r){let e=new Uint8Array(r);return Yr.getRandomValues(e),e}function en(r){let e=r.reduce((i,o)=>i+o.byteLength,0),t=new Uint8Array(e),n=0;for(let i of r)t.set(i,n),n+=i.byteLength;return t}var et=class r{buffer;constructor(e){if(typeof e=="string"?this.buffer=di.Buffer.from(e.replace(/-/g,"+").replace(/_/g,"/"),"base64"):this.buffer=e,this.buffer.length!==32)throw new Error(`expected TaskId to be 32 bytes long (${this.toString()})`)}static random(){return new r(di.Buffer.from(Xe(32)))}toString(){return this.buffer.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}encode(){return this.buffer}};var Co=Ue(ze(),1),tn=class r{bytes;constructor(e){if(this.bytes=e,this.bytes.length!==16)throw new Error("expected ReportId to be 16 bytes")}static random(){return new r(Co.Buffer.from(Xe(16)))}encode(){return this.bytes}};var ht=Ue(ze(),1);var tt=Ue(ze(),1);function rn(r){let e=tt.Buffer.concat([tt.Buffer.alloc(2),...r.map(t=>t.encode())]);return e.writeUInt16BE(e.length-2,0),e}function Oo(r){let e=tt.Buffer.concat([tt.Buffer.alloc(2),r]);return e.writeUInt16BE(r.length,0),e}function Zt(r){let e=tt.Buffer.concat([tt.Buffer.alloc(4),r]);return e.writeUInt32BE(r.length,0),e}var gr=class r{index=0;buffer;static from(e){return e instanceof r?e:new r(e)}constructor(e){this.buffer=tt.Buffer.from(e)}increment(e,t){if(this.index+e>this.buffer.length)throw new Error("attempted to read off end of buffer");let n=t.call(this);return this.index+=e,n}array16(e){let t=this.uint16(),n=this.index+t,i=[];for(;this.index<n;)i.push(e.parse(this));if(this.index!==n)throw new Error(`expected to read exactly ${t} but read ${this.index-n} over`);return i}slice(e){return this.increment(e,()=>tt.Buffer.from(this.buffer.subarray(this.index,this.index+e)))}uint16(){return this.increment(2,()=>this.buffer.readUInt16BE(this.index))}uint8(){return this.increment(1,()=>this.buffer[this.index])}opaque16(){return this.slice(this.uint16())}};var pi=Ue(ze(),1);var nn=class{configId;encapsulatedContext;payload;constructor(e,t,n){if(this.configId=e,this.encapsulatedContext=t,this.payload=n,e!==Math.floor(e)||e<0||e>255)throw new Error("configId must be a uint8 (< 256)")}encode(){return pi.Buffer.concat([pi.Buffer.from([this.configId]),Oo(this.encapsulatedContext),Zt(this.payload)])}};var on=Object.freeze("dap-09"),br=Object.freeze({REPORT:"application/dap-report",HPKE_CONFIG_LIST:"application/dap-hpke-config-list"}),yr;(function(r){r[r.Collector=0]="Collector",r[r.Client=1]="Client",r[r.Leader=2]="Leader",r[r.Helper=3]="Helper"})(yr||(yr={}));var Qu=Ue(ze(),1),Ko;(function(r){r[r.TBD=0]="TBD"})(Ko||(Ko={}));var sn=class{reportId;time;constructor(e,t){this.reportId=e,this.time=t}encode(){let e=ht.Buffer.alloc(24);return this.reportId.encode().copy(e,0),e.writeUInt32BE(this.time,20),e}},an=class{metadata;publicShare;leaderCiphertext;helperCiphertext;constructor(e,t,n,i){this.metadata=e,this.publicShare=t,this.leaderCiphertext=n,this.helperCiphertext=i}encode(){return ht.Buffer.concat([this.metadata.encode(),Zt(this.publicShare),this.leaderCiphertext.encode(),this.helperCiphertext.encode()])}},xr=class{extensions;payload;constructor(e,t){this.extensions=e,this.payload=t}encode(){return ht.Buffer.concat([rn(this.extensions),Zt(this.payload)])}},cn=class{taskId;metadata;publicShare;constructor(e,t,n){this.taskId=e,this.metadata=t,this.publicShare=n}encode(){return ht.Buffer.concat([this.taskId.encode(),this.metadata.encode(),Zt(this.publicShare)])}},Ta=ht.Buffer.from(`${on} input share`,"ascii"),un=class{serverRole;constructor(e){this.serverRole=e}encode(){return ht.Buffer.concat([Ta,ht.Buffer.from([1,this.serverRole])])}};var Rn=Ue(ze(),1);var Er=class extends Error{constructor(e){let t;e instanceof Error?t=e.message:typeof e=="string"?t=e:t="",super(t),this.name=this.constructor.name}},be=class extends Er{},se=class extends be{};var we=class extends be{},ue=class extends be{},Wt=class extends be{},Yt=class extends be{},Jt=class extends be{},Qt=class extends be{},er=class extends be{},tr=class extends be{},Ze=class extends be{},me=class extends be{};var Ua={},wi=Ca(globalThis,Ua);function Ca(r,e){return new Proxy(r,{get(t,n,i){return n in e?e[n]:r[n]},set(t,n,i){return n in e&&delete e[n],r[n]=i,!0},deleteProperty(t,n){let i=!1;return n in e&&(delete e[n],i=!0),n in r&&(delete r[n],i=!0),i},ownKeys(t){let n=Reflect.ownKeys(r),i=Reflect.ownKeys(e),o=new Set(i);return[...n.filter(s=>!o.has(s)),...i]},defineProperty(t,n,i){return n in e&&delete e[n],Reflect.defineProperty(r,n,i),!0},getOwnPropertyDescriptor(t,n){return n in e?Reflect.getOwnPropertyDescriptor(e,n):Reflect.getOwnPropertyDescriptor(r,n)},has(t,n){return n in e||n in r}})}async function Oa(){if(wi!==void 0&&globalThis.crypto!==void 0)return globalThis.crypto.subtle;try{let{webcrypto:r}=await import("crypto");return r.subtle}catch(r){throw new me(r)}}var Ne=class{constructor(){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}async _setup(){this._api===void 0&&(this._api=await Oa())}};var We={Base:0,Psk:1,Auth:2,AuthPsk:3},X={NotAssigned:0,DhkemP256HkdfSha256:16,DhkemP384HkdfSha384:17,DhkemP521HkdfSha512:18,DhkemSecp256k1HkdfSha256:19,DhkemX25519HkdfSha256:32,DhkemX448HkdfSha512:33,HybridkemX25519Kyber768:48},Pe={HkdfSha256:1,HkdfSha384:2,HkdfSha512:3},de={Aes128Gcm:1,Aes256Gcm:2,Chacha20Poly1305:3,ExportOnly:65535};var ee=new Uint8Array(0);var ln=new Uint8Array([75,69,77,0,0]);var dt=r=>typeof r=="object"&&r!==null&&typeof r.privateKey=="object"&&typeof r.publicKey=="object";function Oe(r,e){if(e<=0)throw new Error("i2Osp: too small size");if(r>=256**e)throw new Error("i2Osp: too large integer");let t=new Uint8Array(e);for(let n=0;n<e&&r;n++)t[e-(n+1)]=r%256,r=r>>8;return t}function Ut(r,e){let t=new Uint8Array(r.length+e.length);return t.set(r,0),t.set(e,r.length),t}function Ho(r){let e=r.replace(/-/g,"+").replace(/_/g,"/"),t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n}function mi(r,e){if(r.byteLength!==e.byteLength)throw new Error("xor: different length inputs");let t=new Uint8Array(r.byteLength);for(let n=0;n<r.byteLength;n++)t[n]=r[n]^e[n];return t}var Ka=new Uint8Array([101,97,101,95,112,114,107]),Ra=new Uint8Array([115,104,97,114,101,100,95,115,101,99,114,101,116]);function Ha(r,e,t){let n=new Uint8Array(r.length+e.length+t.length);return n.set(r,0),n.set(e,r.length),n.set(t,r.length+e.length),n}var ve=class{constructor(e,t,n){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_prim",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.id=e,this._prim=t,this._kdf=n;let i=new Uint8Array(ln);i.set(Oe(this.id,2),3),this._kdf.init(i)}async serializePublicKey(e){return await this._prim.serializePublicKey(e)}async deserializePublicKey(e){return await this._prim.deserializePublicKey(e)}async serializePrivateKey(e){return await this._prim.serializePrivateKey(e)}async deserializePrivateKey(e){return await this._prim.deserializePrivateKey(e)}async importKey(e,t,n=!0){return await this._prim.importKey(e,t,n)}async generateKeyPair(){return await this._prim.generateKeyPair()}async deriveKeyPair(e){if(e.byteLength>8192)throw new se("Too long ikm");return await this._prim.deriveKeyPair(e)}async encap(e){let t;e.ekm===void 0?t=await this.generateKeyPair():dt(e.ekm)?t=e.ekm:t=await this.deriveKeyPair(e.ekm);let n=await this._prim.serializePublicKey(t.publicKey),i=await this._prim.serializePublicKey(e.recipientPublicKey);try{let o;if(e.senderKey===void 0)o=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey));else{let u=dt(e.senderKey)?e.senderKey.privateKey:e.senderKey,d=new Uint8Array(await this._prim.dh(t.privateKey,e.recipientPublicKey)),c=new Uint8Array(await this._prim.dh(u,e.recipientPublicKey));o=Ut(d,c)}let s;if(e.senderKey===void 0)s=Ut(new Uint8Array(n),new Uint8Array(i));else{let u=dt(e.senderKey)?e.senderKey.publicKey:await this._prim.derivePublicKey(e.senderKey),d=await this._prim.serializePublicKey(u);s=Ha(new Uint8Array(n),new Uint8Array(i),new Uint8Array(d))}let a=await this._generateSharedSecret(o,s);return{enc:n,sharedSecret:a}}catch(o){throw new Wt(o)}}async decap(e){let t=await this._prim.deserializePublicKey(e.enc),n=dt(e.recipientKey)?e.recipientKey.privateKey:e.recipientKey,i=dt(e.recipientKey)?e.recipientKey.publicKey:await this._prim.derivePublicKey(e.recipientKey),o=await this._prim.serializePublicKey(i);try{let s;if(e.senderPublicKey===void 0)s=new Uint8Array(await this._prim.dh(n,t));else{let u=new Uint8Array(await this._prim.dh(n,t)),d=new Uint8Array(await this._prim.dh(n,e.senderPublicKey));s=Ut(u,d)}let a;if(e.senderPublicKey===void 0)a=Ut(new Uint8Array(e.enc),new Uint8Array(o));else{let u=await this._prim.serializePublicKey(e.senderPublicKey);a=new Uint8Array(e.enc.byteLength+o.byteLength+u.byteLength),a.set(new Uint8Array(e.enc),0),a.set(new Uint8Array(o),e.enc.byteLength),a.set(new Uint8Array(u),e.enc.byteLength+o.byteLength)}return await this._generateSharedSecret(s,a)}catch(s){throw new Yt(s)}}async _generateSharedSecret(e,t){let n=this._kdf.buildLabeledIkm(Ka,e),i=this._kdf.buildLabeledInfo(Ra,t,this.secretSize);return await this._kdf.extractAndExpand(ee,n,i,this.secretSize)}};var xe=["deriveBits"],wt=new Uint8Array([100,107,112,95,112,114,107]),rr=new Uint8Array([115,107]);var fn=class{constructor(e){Object.defineProperty(this,"_num",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._num=new Uint8Array(e)}val(){return this._num}reset(){this._num.fill(0)}set(e){if(e.length!==this._num.length)throw new Error("Bignum.set: invalid argument");this._num.set(e)}isZero(){for(let e=0;e<this._num.length;e++)if(this._num[e]!==0)return!1;return!0}lessThan(e){if(e.length!==this._num.length)throw new Error("Bignum.lessThan: invalid argument");for(let t=0;t<this._num.length;t++){if(this._num[t]<e[t])return!0;if(this._num[t]>e[t])return!1}return!1}};var za=new Uint8Array([99,97,110,100,105,100,97,116,101]),Na=new Uint8Array([255,255,255,255,0,0,0,0,255,255,255,255,255,255,255,255,188,230,250,173,167,23,158,132,243,185,202,194,252,99,37,81]),Da=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,199,99,77,129,244,55,45,223,88,26,13,178,72,176,167,122,236,236,25,106,204,197,41,115]),Fa=new Uint8Array([1,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,81,134,135,131,191,47,150,107,127,204,1,72,247,9,165,208,59,181,201,184,137,156,71,174,187,111,183,30,145,56,100,9]),Ma=new Uint8Array([48,65,2,1,0,48,19,6,7,42,134,72,206,61,2,1,6,8,42,134,72,206,61,3,1,7,4,39,48,37,2,1,1,4,32]),ja=new Uint8Array([48,78,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,34,4,55,48,53,2,1,1,4,48]),Va=new Uint8Array([48,96,2,1,0,48,16,6,7,42,134,72,206,61,2,1,6,5,43,129,4,0,35,4,73,48,71,2,1,1,4,66]),Ye=class extends Ne{constructor(e,t){switch(super(),Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_alg",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nDh",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_order",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bitmask",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pkcs8AlgId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=t,e){case X.DhkemP256HkdfSha256:this._alg={name:"ECDH",namedCurve:"P-256"},this._nPk=65,this._nSk=32,this._nDh=32,this._order=Na,this._bitmask=255,this._pkcs8AlgId=Ma;break;case X.DhkemP384HkdfSha384:this._alg={name:"ECDH",namedCurve:"P-384"},this._nPk=97,this._nSk=48,this._nDh=48,this._order=Da,this._bitmask=255,this._pkcs8AlgId=ja;break;default:this._alg={name:"ECDH",namedCurve:"P-521"},this._nPk=133,this._nSk=66,this._nDh=66,this._order=Fa,this._bitmask=1,this._pkcs8AlgId=Va;break}}async serializePublicKey(e){await this._setup();try{return await this._api.exportKey("raw",e)}catch(t){throw new we(t)}}async deserializePublicKey(e){await this._setup();try{return await this._importRawKey(e,!0)}catch(t){throw new ue(t)}}async serializePrivateKey(e){await this._setup();try{let t=await this._api.exportKey("jwk",e);if(!("d"in t))throw new Error("Not private key");return Ho(t.d)}catch(t){throw new we(t)}}async deserializePrivateKey(e){await this._setup();try{return await this._importRawKey(e,!1)}catch(t){throw new ue(t)}}async importKey(e,t,n){await this._setup();try{if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}catch(i){throw new ue(i)}}async generateKeyPair(){await this._setup();try{return await this._api.generateKey(this._alg,!0,xe)}catch(e){throw new me(e)}}async deriveKeyPair(e){await this._setup();try{let t=await this._hkdf.labeledExtract(ee,wt,new Uint8Array(e)),n=new fn(this._nSk);for(let o=0;n.isZero()||!n.lessThan(this._order);o++){if(o>255)throw new Error("Faild to derive a key pair");let s=new Uint8Array(await this._hkdf.labeledExpand(t,za,Oe(o,1),this._nSk));s[0]=s[0]&this._bitmask,n.set(s)}let i=await this._deserializePkcs8Key(n.val());return n.reset(),{privateKey:i,publicKey:await this.derivePublicKey(i)}}catch(t){throw new Ze(t)}}async derivePublicKey(e){await this._setup();try{let t=await this._api.exportKey("jwk",e);return delete t.d,delete t.key_ops,await this._api.importKey("jwk",t,this._alg,!0,[])}catch(t){throw new ue(t)}}async dh(e,t){try{return await this._setup(),await this._api.deriveBits({name:"ECDH",public:t},e,this._nDh*8)}catch(n){throw new we(n)}}async _importRawKey(e,t){if(t&&e.byteLength!==this._nPk)throw new Error("Invalid public key for the ciphersuite");if(!t&&e.byteLength!==this._nSk)throw new Error("Invalid private key for the ciphersuite");return t?await this._api.importKey("raw",e,this._alg,!0,[]):await this._deserializePkcs8Key(new Uint8Array(e))}async _importJWK(e,t){if(typeof e.crv>"u"||e.crv!==this._alg.namedCurve)throw new Error(`Invalid crv: ${e.crv}`);if(t){if(typeof e.d<"u")throw new Error("Invalid key: `d` should not be set");return await this._api.importKey("jwk",e,this._alg,!0,[])}if(typeof e.d>"u")throw new Error("Invalid key: `d` not found");return await this._api.importKey("jwk",e,this._alg,!0,xe)}async _deserializePkcs8Key(e){let t=new Uint8Array(this._pkcs8AlgId.length+e.length);return t.set(this._pkcs8AlgId,0),t.set(e,this._pkcs8AlgId.length),await this._api.importKey("pkcs8",t,this._alg,!0,xe)}};var pe=class{constructor(e,t,n,i=[]){Object.defineProperty(this,"key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extractable",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"algorithm",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"usages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.key=t,this.type=n,this.algorithm={name:e},this.usages=i,n==="public"&&(this.usages=[])}};var zo=new Uint8Array([72,80,75,69,45,118,49]),_r=class extends Ne{constructor(){super(),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Pe.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:ee}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}init(e){this._suiteId=e}buildLabeledIkm(e,t){this._checkInit();let n=new Uint8Array(7+this._suiteId.byteLength+e.byteLength+t.byteLength);return n.set(zo,0),n.set(this._suiteId,7),n.set(e,7+this._suiteId.byteLength),n.set(t,7+this._suiteId.byteLength+e.byteLength),n}buildLabeledInfo(e,t,n){this._checkInit();let i=new Uint8Array(9+this._suiteId.byteLength+e.byteLength+t.byteLength);return i.set(new Uint8Array([0,n]),0),i.set(zo,2),i.set(this._suiteId,9),i.set(e,9+this._suiteId.byteLength),i.set(t,9+this._suiteId.byteLength+e.byteLength),i}async extract(e,t){if(await this._setup(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)throw new se("The salt length must be the same as the hashSize");let n=await this._api.importKey("raw",e,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,t)}async expand(e,t,n){await this._setup();let i=await this._api.importKey("raw",e,this.algHash,!1,["sign"]),o=new ArrayBuffer(n),s=new Uint8Array(o),a=ee,u=new Uint8Array(t),d=new Uint8Array(1);if(n>255*this.hashSize)throw new Error("Entropy limit reached");let c=new Uint8Array(this.hashSize+u.length+1);for(let l=1,f=0;f<s.length;l++)d[0]=l,c.set(a,0),c.set(u,a.length),c.set(d,a.length+u.length),a=new Uint8Array(await this._api.sign("HMAC",i,c.slice(0,a.length+u.length+1))),s.length-f>=a.length?(s.set(a,f),f+=a.length):(s.set(a.slice(0,s.length-f),f),f+=s.length-f);return o}async extractAndExpand(e,t,n,i){await this._setup();let o=await this._api.importKey("raw",t,"HKDF",!1,["deriveBits"]);return await this._api.deriveBits({name:"HKDF",hash:this.algHash.hash,salt:e,info:n},o,i*8)}async labeledExtract(e,t,n){return await this.extract(e,this.buildLabeledIkm(t,n))}async labeledExpand(e,t,n,i){return await this.expand(e,this.buildLabeledInfo(t,n,i),i)}_checkInit(){if(this._suiteId===ee)throw new Error("Not initialized. Call init()")}},Ct=class extends _r{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Pe.HkdfSha256}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-256",length:256}})}},Ot=class extends _r{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Pe.HkdfSha384}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:48}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-384",length:384}})}},Kt=class extends _r{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:Pe.HkdfSha512}),Object.defineProperty(this,"hashSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"algHash",{enumerable:!0,configurable:!0,writable:!0,value:{name:"HMAC",hash:"SHA-512",length:512}})}};var gi=["encrypt","decrypt"];var bi=class extends Ne{constructor(e){super(),Object.defineProperty(this,"_rawKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._rawKey=e}async seal(e,t,n){await this._setupKey();let i={name:"AES-GCM",iv:e,additionalData:n};return await this._api.encrypt(i,this._key,t)}async open(e,t,n){await this._setupKey();let i={name:"AES-GCM",iv:e,additionalData:n};return await this._api.decrypt(i,this._key,t)}async _setupKey(){if(this._key!==void 0)return;await this._setup();let e=await this._importKey(this._rawKey);new Uint8Array(this._rawKey).fill(0),this._key=e}async _importKey(e){return await this._api.importKey("raw",e,{name:"AES-GCM"},!0,gi)}},nr=class{constructor(){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:de.Aes128Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:16}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createEncryptionContext(e){return new bi(e)}},vr=class extends nr{constructor(){super(...arguments),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:de.Aes256Gcm}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}};var Sr=class{constructor(){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:de.ExportOnly}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:0})}createEncryptionContext(e){throw new me("Export only")}};function xi(){return new Promise((r,e)=>{e(new me("Not supported"))})}var $a=new Uint8Array([115,101,99]),ir=class{constructor(e,t,n){Object.defineProperty(this,"_api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exporterSecret",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._api=e,this._kdf=t,this.exporterSecret=n}async seal(e,t){return await xi()}async open(e,t){return await xi()}async export(e,t){if(e.byteLength>8192)throw new se("Too long exporter context");try{return await this._kdf.labeledExpand(this.exporterSecret,$a,new Uint8Array(e),t)}catch(n){throw new Jt(n)}}},hn=class extends ir{},dn=class extends ir{constructor(e,t,n,i){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=i}};var or=class extends ir{constructor(e,t,n){if(super(e,t,n.exporterSecret),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nK",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nN",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nT",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ctx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.key===void 0||n.baseNonce===void 0||n.seq===void 0)throw new Error("Required parameters are missing");this._aead=n.aead,this._nK=this._aead.keySize,this._nN=this._aead.nonceSize,this._nT=this._aead.tagSize;let i=this._aead.createEncryptionContext(n.key);this._ctx={key:i,baseNonce:n.baseNonce,seq:n.seq}}computeNonce(e){let t=Oe(e.seq,e.baseNonce.byteLength);return mi(e.baseNonce,t)}incrementSeq(e){if(e.seq>Number.MAX_SAFE_INTEGER)throw new tr("Message limit reached");e.seq+=1}};var pn=class extends or{async open(e,t=ee){let n;try{n=await this._ctx.key.open(this.computeNonce(this._ctx),e,t)}catch(i){throw new er(i)}return this.incrementSeq(this._ctx),n}};var wn=class extends or{constructor(e,t,n,i){super(e,t,n),Object.defineProperty(this,"enc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.enc=i}async seal(e,t=ee){let n;try{n=await this._ctx.key.seal(this.computeNonce(this._ctx),e,t)}catch(i){throw new Qt(i)}return this.incrementSeq(this._ctx),n}};var qa=new Uint8Array([98,97,115,101,95,110,111,110,99,101]),Ga=new Uint8Array([101,120,112]),Xa=new Uint8Array([105,110,102,111,95,104,97,115,104]),Za=new Uint8Array([107,101,121]),Wa=new Uint8Array([112,115,107,95,105,100,95,104,97,115,104]),Ya=new Uint8Array([115,101,99,114,101,116]),Ja=new Uint8Array([72,80,75,69,0,0,0,0,0,0]),mn=class extends Ne{constructor(e){if(super(),Object.defineProperty(this,"_kem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_kdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_aead",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_suiteId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),typeof e.kem=="number")throw new se("KemId cannot be used");if(this._kem=e.kem,typeof e.kdf=="number")throw new se("KdfId cannot be used");if(this._kdf=e.kdf,typeof e.aead=="number")throw new se("AeadId cannot be used");this._aead=e.aead,this._suiteId=new Uint8Array(Ja),this._suiteId.set(Oe(this._kem.id,2),4),this._suiteId.set(Oe(this._kdf.id,2),6),this._suiteId.set(Oe(this._aead.id,2),8),this._kdf.init(this._suiteId)}get kem(){return this._kem}get kdf(){return this._kdf}get aead(){return this._aead}async createSenderContext(e){this._validateInputLength(e),await this._setup();let t=await this._kem.encap(e),n;return e.psk!==void 0?n=e.senderKey!==void 0?We.AuthPsk:We.Psk:n=e.senderKey!==void 0?We.Auth:We.Base,await this._keyScheduleS(n,t.sharedSecret,t.enc,e)}async createRecipientContext(e){this._validateInputLength(e),await this._setup();let t=await this._kem.decap(e),n;return e.psk!==void 0?n=e.senderPublicKey!==void 0?We.AuthPsk:We.Psk:n=e.senderPublicKey!==void 0?We.Auth:We.Base,await this._keyScheduleR(n,t,e)}async seal(e,t,n=ee){let i=await this.createSenderContext(e);return{ct:await i.seal(t,n),enc:i.enc}}async open(e,t,n=ee){return await(await this.createRecipientContext(e)).open(t,n)}async _keySchedule(e,t,n){let i=n.psk===void 0?ee:new Uint8Array(n.psk.id),o=await this._kdf.labeledExtract(ee,Wa,i),s=n.info===void 0?ee:new Uint8Array(n.info),a=await this._kdf.labeledExtract(ee,Xa,s),u=new Uint8Array(1+o.byteLength+a.byteLength);u.set(new Uint8Array([e]),0),u.set(new Uint8Array(o),1),u.set(new Uint8Array(a),1+o.byteLength);let d=n.psk===void 0?ee:new Uint8Array(n.psk.key),c=this._kdf.buildLabeledIkm(Ya,d),l=this._kdf.buildLabeledInfo(Ga,u,this._kdf.hashSize),f=await this._kdf.extractAndExpand(t,c,l,this._kdf.hashSize);if(this._aead.id===de.ExportOnly)return{aead:this._aead,exporterSecret:f};let h=this._kdf.buildLabeledInfo(Za,u,this._aead.keySize),p=await this._kdf.extractAndExpand(t,c,h,this._aead.keySize),y=this._kdf.buildLabeledInfo(qa,u,this._aead.nonceSize),_=await this._kdf.extractAndExpand(t,c,y,this._aead.nonceSize);return{aead:this._aead,exporterSecret:f,key:p,baseNonce:new Uint8Array(_),seq:0}}async _keyScheduleS(e,t,n,i){let o=await this._keySchedule(e,t,i);return o.key===void 0?new dn(this._api,this._kdf,o.exporterSecret,n):new wn(this._api,this._kdf,o,n)}async _keyScheduleR(e,t,n){let i=await this._keySchedule(e,t,n);return i.key===void 0?new hn(this._api,this._kdf,i.exporterSecret):new pn(this._api,this._kdf,i)}_validateInputLength(e){if(e.info!==void 0&&e.info.byteLength>8192)throw new se("Too long info");if(e.psk!==void 0){if(e.psk.key.byteLength<32)throw new se(`PSK must have at least ${32} bytes`);if(e.psk.key.byteLength>8192)throw new se("Too long psk.key");if(e.psk.id.byteLength>8192)throw new se("Too long psk.id")}}};var kr=class extends mn{};function gn(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function Ei(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function _i(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Se(r,...e){if(!_i(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function vi(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function No(r,e){Se(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var rt=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),Do=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),ec=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!ec)throw new Error("Non little-endian hardware is not supported");function tc(r){if(typeof r!="string")throw new Error(`string expected, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function yn(r){if(typeof r=="string")r=tc(r);else if(_i(r))r=r.slice();else throw new Error(`Uint8Array expected, got ${typeof r}`);return r}function Fo(r,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(r,e)}function Mo(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}var Si=(r,e)=>(Object.assign(e,r),e);function ki(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),u=n?4:0,d=n?0:4;r.setUint32(e+u,s,n),r.setUint32(e+d,a,n)}var ge=(r,e)=>r[e++]&255|(r[e++]&255)<<8,Bi=class{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=yn(e),Se(e,32);let t=ge(e,0),n=ge(e,2),i=ge(e,4),o=ge(e,6),s=ge(e,8),a=ge(e,10),u=ge(e,12),d=ge(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|o<<9)&8191,this.r[4]=(o>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|a<<2)&8191,this.r[7]=(a>>>11|u<<5)&8065,this.r[8]=(u>>>8|d<<8)&8191,this.r[9]=d>>>5&127;for(let c=0;c<8;c++)this.pad[c]=ge(e,16+2*c)}process(e,t,n=!1){let i=n?0:2048,{h:o,r:s}=this,a=s[0],u=s[1],d=s[2],c=s[3],l=s[4],f=s[5],h=s[6],p=s[7],y=s[8],_=s[9],x=ge(e,t+0),m=ge(e,t+2),g=ge(e,t+4),k=ge(e,t+6),C=ge(e,t+8),R=ge(e,t+10),z=ge(e,t+12),A=ge(e,t+14),L=o[0]+(x&8191),O=o[1]+((x>>>13|m<<3)&8191),U=o[2]+((m>>>10|g<<6)&8191),M=o[3]+((g>>>7|k<<9)&8191),$=o[4]+((k>>>4|C<<12)&8191),q=o[5]+(C>>>1&8191),V=o[6]+((C>>>14|R<<2)&8191),S=o[7]+((R>>>11|z<<5)&8191),b=o[8]+((z>>>8|A<<8)&8191),v=o[9]+(A>>>5|i),E=0,I=E+L*a+O*(5*_)+U*(5*y)+M*(5*p)+$*(5*h);E=I>>>13,I&=8191,I+=q*(5*f)+V*(5*l)+S*(5*c)+b*(5*d)+v*(5*u),E+=I>>>13,I&=8191;let P=E+L*u+O*a+U*(5*_)+M*(5*y)+$*(5*p);E=P>>>13,P&=8191,P+=q*(5*h)+V*(5*f)+S*(5*l)+b*(5*c)+v*(5*d),E+=P>>>13,P&=8191;let T=E+L*d+O*u+U*a+M*(5*_)+$*(5*y);E=T>>>13,T&=8191,T+=q*(5*p)+V*(5*h)+S*(5*f)+b*(5*l)+v*(5*c),E+=T>>>13,T&=8191;let D=E+L*c+O*d+U*u+M*a+$*(5*_);E=D>>>13,D&=8191,D+=q*(5*y)+V*(5*p)+S*(5*h)+b*(5*f)+v*(5*l),E+=D>>>13,D&=8191;let F=E+L*l+O*c+U*d+M*u+$*a;E=F>>>13,F&=8191,F+=q*(5*_)+V*(5*y)+S*(5*p)+b*(5*h)+v*(5*f),E+=F>>>13,F&=8191;let G=E+L*f+O*l+U*c+M*d+$*u;E=G>>>13,G&=8191,G+=q*a+V*(5*_)+S*(5*y)+b*(5*p)+v*(5*h),E+=G>>>13,G&=8191;let te=E+L*h+O*f+U*l+M*c+$*d;E=te>>>13,te&=8191,te+=q*u+V*a+S*(5*_)+b*(5*y)+v*(5*p),E+=te>>>13,te&=8191;let ie=E+L*p+O*h+U*f+M*l+$*c;E=ie>>>13,ie&=8191,ie+=q*d+V*u+S*a+b*(5*_)+v*(5*y),E+=ie>>>13,ie&=8191;let ae=E+L*y+O*p+U*h+M*f+$*l;E=ae>>>13,ae&=8191,ae+=q*c+V*d+S*u+b*a+v*(5*_),E+=ae>>>13,ae&=8191;let ce=E+L*_+O*y+U*p+M*h+$*f;E=ce>>>13,ce&=8191,ce+=q*l+V*c+S*d+b*u+v*a,E+=ce>>>13,ce&=8191,E=(E<<2)+E|0,E=E+I|0,I=E&8191,E=E>>>13,P+=E,o[0]=I,o[1]=P,o[2]=T,o[3]=D,o[4]=F,o[5]=G,o[6]=te,o[7]=ie,o[8]=ae,o[9]=ce}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),i=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=i,i=e[a]>>>13,e[a]&=8191;e[0]+=i*5,i=e[0]>>>13,e[0]&=8191,e[1]+=i,i=e[1]>>>13,e[1]&=8191,e[2]+=i,n[0]=e[0]+5,i=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+i,i=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(i^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)e[a]=e[a]&o|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let s=e[0]+t[0];e[0]=s&65535;for(let a=1;a<8;a++)s=(e[a]+t[a]|0)+(s>>>16)|0,e[a]=s&65535}update(e){vi(this);let{buffer:t,blockLen:n}=this;e=yn(e);let i=e.length;for(let o=0;o<i;){let s=Math.min(n-this.pos,i-o);if(s===n){for(;n<=i-o;o+=n)this.process(e,o);continue}t.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(e){vi(this),No(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:i}=this;if(i){for(t[i++]=1;i<16;i++)t[i]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let s=0;s<8;s++)e[o++]=n[s]>>>0,e[o++]=n[s]>>>8;return e}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}};function rc(r){let e=(n,i)=>r(i).update(yn(n)).digest(),t=r(new Uint8Array(32));return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}var jo=rc(r=>new Bi(r));var $o=r=>Uint8Array.from(r.split("").map(e=>e.charCodeAt(0))),nc=$o("expand 16-byte k"),ic=$o("expand 32-byte k"),oc=rt(nc),qo=rt(ic),bh=qo.slice();function B(r,e){return r<<e|r>>>32-e}function Ii(r){return r.byteOffset%4===0}var bn=64,sc=16,Go=2**32-1,Vo=new Uint32Array;function ac(r,e,t,n,i,o,s,a){let u=i.length,d=new Uint8Array(bn),c=rt(d),l=Ii(i)&&Ii(o),f=l?rt(i):Vo,h=l?rt(o):Vo;for(let p=0;p<u;s++){if(r(e,t,n,c,s,a),s>=Go)throw new Error("arx: counter overflow");let y=Math.min(bn,u-p);if(l&&y===bn){let _=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let x=0,m;x<sc;x++)m=_+x,h[m]=f[m]^c[x];p+=bn;continue}for(let _=0,x;_<y;_++)x=p+_,o[x]=i[x]^d[_];p+=y}}function Ai(r,e){let{allowShortKeys:t,extendNonceFn:n,counterLength:i,counterRight:o,rounds:s}=Fo({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof r!="function")throw new Error("core must be a function");return gn(i),gn(s),Ei(o),Ei(t),(a,u,d,c,l=0)=>{Se(a),Se(u),Se(d);let f=d.length;if(c||(c=new Uint8Array(f)),Se(c),gn(l),l<0||l>=Go)throw new Error("arx: counter overflow");if(c.length<f)throw new Error(`arx: output (${c.length}) is shorter than data (${f})`);let h=[],p=a.length,y,_;if(p===32)y=a.slice(),h.push(y),_=qo;else if(p===16&&t)y=new Uint8Array(32),y.set(a),y.set(a,16),_=oc,h.push(y);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Ii(u)||(u=u.slice(),h.push(u));let x=rt(y);if(n){if(u.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(_,x,rt(u.subarray(0,16)),x),u=u.subarray(16)}let m=16-i;if(m!==u.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(m!==12){let k=new Uint8Array(12);k.set(u,o?0:12-u.length),u=k,h.push(u)}let g=rt(u);for(ac(r,_,x,g,d,c,l,s);h.length>0;)h.pop().fill(0);return c}}function Wo(r,e,t,n,i,o=20){let s=r[0],a=r[1],u=r[2],d=r[3],c=e[0],l=e[1],f=e[2],h=e[3],p=e[4],y=e[5],_=e[6],x=e[7],m=i,g=t[0],k=t[1],C=t[2],R=s,z=a,A=u,L=d,O=c,U=l,M=f,$=h,q=p,V=y,S=_,b=x,v=m,E=g,I=k,P=C;for(let D=0;D<o;D+=2)R=R+O|0,v=B(v^R,16),q=q+v|0,O=B(O^q,12),R=R+O|0,v=B(v^R,8),q=q+v|0,O=B(O^q,7),z=z+U|0,E=B(E^z,16),V=V+E|0,U=B(U^V,12),z=z+U|0,E=B(E^z,8),V=V+E|0,U=B(U^V,7),A=A+M|0,I=B(I^A,16),S=S+I|0,M=B(M^S,12),A=A+M|0,I=B(I^A,8),S=S+I|0,M=B(M^S,7),L=L+$|0,P=B(P^L,16),b=b+P|0,$=B($^b,12),L=L+$|0,P=B(P^L,8),b=b+P|0,$=B($^b,7),R=R+U|0,P=B(P^R,16),S=S+P|0,U=B(U^S,12),R=R+U|0,P=B(P^R,8),S=S+P|0,U=B(U^S,7),z=z+M|0,v=B(v^z,16),b=b+v|0,M=B(M^b,12),z=z+M|0,v=B(v^z,8),b=b+v|0,M=B(M^b,7),A=A+$|0,E=B(E^A,16),q=q+E|0,$=B($^q,12),A=A+$|0,E=B(E^A,8),q=q+E|0,$=B($^q,7),L=L+O|0,I=B(I^L,16),V=V+I|0,O=B(O^V,12),L=L+O|0,I=B(I^L,8),V=V+I|0,O=B(O^V,7);let T=0;n[T++]=s+R|0,n[T++]=a+z|0,n[T++]=u+A|0,n[T++]=d+L|0,n[T++]=c+O|0,n[T++]=l+U|0,n[T++]=f+M|0,n[T++]=h+$|0,n[T++]=p+q|0,n[T++]=y+V|0,n[T++]=_+S|0,n[T++]=x+b|0,n[T++]=m+v|0,n[T++]=g+E|0,n[T++]=k+I|0,n[T++]=C+P|0}function cc(r,e,t,n){let i=r[0],o=r[1],s=r[2],a=r[3],u=e[0],d=e[1],c=e[2],l=e[3],f=e[4],h=e[5],p=e[6],y=e[7],_=t[0],x=t[1],m=t[2],g=t[3];for(let C=0;C<20;C+=2)i=i+u|0,_=B(_^i,16),f=f+_|0,u=B(u^f,12),i=i+u|0,_=B(_^i,8),f=f+_|0,u=B(u^f,7),o=o+d|0,x=B(x^o,16),h=h+x|0,d=B(d^h,12),o=o+d|0,x=B(x^o,8),h=h+x|0,d=B(d^h,7),s=s+c|0,m=B(m^s,16),p=p+m|0,c=B(c^p,12),s=s+c|0,m=B(m^s,8),p=p+m|0,c=B(c^p,7),a=a+l|0,g=B(g^a,16),y=y+g|0,l=B(l^y,12),a=a+l|0,g=B(g^a,8),y=y+g|0,l=B(l^y,7),i=i+d|0,g=B(g^i,16),p=p+g|0,d=B(d^p,12),i=i+d|0,g=B(g^i,8),p=p+g|0,d=B(d^p,7),o=o+c|0,_=B(_^o,16),y=y+_|0,c=B(c^y,12),o=o+c|0,_=B(_^o,8),y=y+_|0,c=B(c^y,7),s=s+l|0,x=B(x^s,16),f=f+x|0,l=B(l^f,12),s=s+l|0,x=B(x^s,8),f=f+x|0,l=B(l^f,7),a=a+u|0,m=B(m^a,16),h=h+m|0,u=B(u^h,12),a=a+u|0,m=B(m^a,8),h=h+m|0,u=B(u^h,7);let k=0;n[k++]=i,n[k++]=o,n[k++]=s,n[k++]=a,n[k++]=_,n[k++]=x,n[k++]=m,n[k++]=g}var uc=Ai(Wo,{counterRight:!1,counterLength:4,allowShortKeys:!1}),lc=Ai(Wo,{counterRight:!1,counterLength:8,extendNonceFn:cc,allowShortKeys:!1});var fc=new Uint8Array(16),Xo=(r,e)=>{r.update(e);let t=e.length%16;t&&r.update(fc.subarray(t))},hc=new Uint8Array(32);function Zo(r,e,t,n,i){let o=r(e,t,hc),s=jo.create(o);i&&Xo(s,i),Xo(s,n);let a=new Uint8Array(16),u=Do(a);ki(u,0,BigInt(i?i.length:0),!0),ki(u,8,BigInt(n.length),!0),s.update(a);let d=s.digest();return o.fill(0),d}var Yo=r=>(e,t,n)=>(Se(e,32),Se(t),{encrypt:(o,s)=>{let a=o.length,u=a+16;s?Se(s,u):s=new Uint8Array(u),r(e,t,o,s,1);let d=Zo(r,e,t,s.subarray(0,-16),n);return s.set(d,a),s},decrypt:(o,s)=>{let a=o.length,u=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");s?Se(s,u):s=new Uint8Array(u);let d=o.subarray(0,-16),c=o.subarray(-16),l=Zo(r,e,t,d,n);if(!Mo(c,l))throw new Error("invalid tag");return r(e,t,d,s,1),s}}),Pi=Si({blockSize:64,nonceLength:12,tagLength:16},Yo(uc)),kh=Si({blockSize:64,nonceLength:24,tagLength:16},Yo(lc));var Li=class{constructor(e){Object.defineProperty(this,"_key",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._key=new Uint8Array(e)}async seal(e,t,n){return await this._seal(e,t,n)}async open(e,t,n){return await this._open(e,t,n)}_seal(e,t,n){return new Promise(i=>{let o=Pi(this._key,new Uint8Array(e),new Uint8Array(n)).encrypt(new Uint8Array(t));i(o.buffer)})}_open(e,t,n){return new Promise(i=>{let o=Pi(this._key,new Uint8Array(e),new Uint8Array(n)).decrypt(new Uint8Array(t));i(o.buffer)})}},Br=class{constructor(){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:de.Chacha20Poly1305}),Object.defineProperty(this,"keySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"nonceSize",{enumerable:!0,configurable:!0,writable:!0,value:12}),Object.defineProperty(this,"tagSize",{enumerable:!0,configurable:!0,writable:!0,value:16})}createEncryptionContext(e){return new Li(e)}};function Ir(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function dc(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function mt(r,...e){if(!dc(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function Jo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ir(r.outputLen),Ir(r.blockLen)}function nt(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function xn(r,e){mt(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var Rt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Ti=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)),En=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),De=(r,e)=>r<<32-e|r>>>e;var Ui=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,pc=r=>r<<24&4278190080|r<<8&16711680|r>>>8&65280|r>>>24&255;function Ci(r){for(let e=0;e<r.length;e++)r[e]=pc(r[e])}function _n(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function it(r){return typeof r=="string"&&(r=_n(r)),mt(r),r}function Oi(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];mt(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var gt=class{clone(){return this._cloneInto()}},Rh={}.toString;function Je(r){let e=n=>r().update(it(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function vn(r){let e=(n,i)=>r(i).update(it(n)).digest(),t=r({});return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=n=>r(n),e}function Ar(r=32){if(Rt&&typeof Rt.getRandomValues=="function")return Rt.getRandomValues(new Uint8Array(r));if(Rt&&typeof Rt.randomBytes=="function")return Rt.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}var Sn=class extends gt{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Jo(e);let n=it(t);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return nt(this),this.iHash.update(e),this}digestInto(e){nt(this),mt(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:t,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ht=(r,e,t)=>new Sn(r,e).update(t).digest();Ht.create=(r,e)=>new Sn(r,e);function wc(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(t>>i&o),a=Number(t&o),u=n?4:0,d=n?0:4;r.setUint32(e+u,s,n),r.setUint32(e+d,a,n)}var Qo=(r,e,t)=>r&e^~r&t,es=(r,e,t)=>r&e^r&t^e&t,sr=class extends gt{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=En(this.buffer)}update(e){nt(this);let{view:t,buffer:n,blockLen:i}=this;e=it(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let u=En(e);for(;i<=o-s;s+=i)this.process(u,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){nt(this),xn(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let l=s;l<i;l++)t[l]=0;wc(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=En(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=u/4,c=this.get();if(d>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,c[l],o)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%t&&e.buffer.set(n),e}};var mc=new Uint32Array([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]),yt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),bt=new Uint32Array(64),Ki=class extends sr{constructor(){super(64,32,8,!1),this.A=yt[0]|0,this.B=yt[1]|0,this.C=yt[2]|0,this.D=yt[3]|0,this.E=yt[4]|0,this.F=yt[5]|0,this.G=yt[6]|0,this.H=yt[7]|0}get(){let{A:e,B:t,C:n,D:i,E:o,F:s,G:a,H:u}=this;return[e,t,n,i,o,s,a,u]}set(e,t,n,i,o,s,a,u){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=u|0}process(e,t){for(let l=0;l<16;l++,t+=4)bt[l]=e.getUint32(t,!1);for(let l=16;l<64;l++){let f=bt[l-15],h=bt[l-2],p=De(f,7)^De(f,18)^f>>>3,y=De(h,17)^De(h,19)^h>>>10;bt[l]=y+bt[l-7]+p+bt[l-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:u,G:d,H:c}=this;for(let l=0;l<64;l++){let f=De(a,6)^De(a,11)^De(a,25),h=c+f+Qo(a,u,d)+mc[l]+bt[l]|0,y=(De(n,2)^De(n,13)^De(n,22))+es(n,i,o)|0;c=d,d=u,u=a,a=s+h|0,s=o,o=i,i=n,n=h+y|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,d=d+this.G|0,c=c+this.H|0,this.set(n,i,o,s,a,u,d,c)}roundClean(){bt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ts=Je(()=>new Ki);var ot=class extends Ct{async extract(e,t){if(await this._setup(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)return Ht(ts,new Uint8Array(e),new Uint8Array(t));let n=await this._api.importKey("raw",e,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,t)}};var kn=BigInt(4294967295),Ri=BigInt(32);function rs(r,e=!1){return e?{h:Number(r&kn),l:Number(r>>Ri&kn)}:{h:Number(r>>Ri&kn)|0,l:Number(r&kn)|0}}function Hi(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:o,l:s}=rs(r[i],e);[t[i],n[i]]=[o,s]}return[t,n]}var gc=(r,e)=>BigInt(r>>>0)<<Ri|BigInt(e>>>0),yc=(r,e,t)=>r>>>t,bc=(r,e,t)=>r<<32-t|e>>>t,xc=(r,e,t)=>r>>>t|e<<32-t,Ec=(r,e,t)=>r<<32-t|e>>>t,_c=(r,e,t)=>r<<64-t|e>>>t-32,vc=(r,e,t)=>r>>>t-32|e<<64-t,Sc=(r,e)=>e,kc=(r,e)=>r,zi=(r,e,t)=>r<<t|e>>>32-t,Ni=(r,e,t)=>e<<t|r>>>32-t,Di=(r,e,t)=>e<<t-32|r>>>64-t,Fi=(r,e,t)=>r<<t-32|e>>>64-t;function Bc(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var Ic=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Ac=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Pc=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Lc=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,Tc=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),Uc=(r,e,t,n,i,o)=>e+t+n+i+o+(r/2**32|0)|0;var Cc={fromBig:rs,split:Hi,toBig:gc,shrSH:yc,shrSL:bc,rotrSH:xc,rotrSL:Ec,rotrBH:_c,rotrBL:vc,rotr32H:Sc,rotr32L:kc,rotlSH:zi,rotlSL:Ni,rotlBH:Di,rotlBL:Fi,add:Bc,add3L:Ic,add3H:Ac,add4L:Pc,add4H:Lc,add5H:Uc,add5L:Tc},N=Cc;var[Oc,Kc]=N.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),xt=new Uint32Array(80),Et=new Uint32Array(80),Bn=class extends sr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:u,Eh:d,El:c,Fh:l,Fl:f,Gh:h,Gl:p,Hh:y,Hl:_}=this;return[e,t,n,i,o,s,a,u,d,c,l,f,h,p,y,_]}set(e,t,n,i,o,s,a,u,d,c,l,f,h,p,y,_){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=u|0,this.Eh=d|0,this.El=c|0,this.Fh=l|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=y|0,this.Hl=_|0}process(e,t){for(let g=0;g<16;g++,t+=4)xt[g]=e.getUint32(t),Et[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let k=xt[g-15]|0,C=Et[g-15]|0,R=N.rotrSH(k,C,1)^N.rotrSH(k,C,8)^N.shrSH(k,C,7),z=N.rotrSL(k,C,1)^N.rotrSL(k,C,8)^N.shrSL(k,C,7),A=xt[g-2]|0,L=Et[g-2]|0,O=N.rotrSH(A,L,19)^N.rotrBH(A,L,61)^N.shrSH(A,L,6),U=N.rotrSL(A,L,19)^N.rotrBL(A,L,61)^N.shrSL(A,L,6),M=N.add4L(z,U,Et[g-7],Et[g-16]),$=N.add4H(M,R,O,xt[g-7],xt[g-16]);xt[g]=$|0,Et[g]=M|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:u,Dh:d,Dl:c,Eh:l,El:f,Fh:h,Fl:p,Gh:y,Gl:_,Hh:x,Hl:m}=this;for(let g=0;g<80;g++){let k=N.rotrSH(l,f,14)^N.rotrSH(l,f,18)^N.rotrBH(l,f,41),C=N.rotrSL(l,f,14)^N.rotrSL(l,f,18)^N.rotrBL(l,f,41),R=l&h^~l&y,z=f&p^~f&_,A=N.add5L(m,C,z,Kc[g],Et[g]),L=N.add5H(A,x,k,R,Oc[g],xt[g]),O=A|0,U=N.rotrSH(n,i,28)^N.rotrBH(n,i,34)^N.rotrBH(n,i,39),M=N.rotrSL(n,i,28)^N.rotrBL(n,i,34)^N.rotrBL(n,i,39),$=n&o^n&a^o&a,q=i&s^i&u^s&u;x=y|0,m=_|0,y=h|0,_=p|0,h=l|0,p=f|0,{h:l,l:f}=N.add(d|0,c|0,L|0,O|0),d=a|0,c=u|0,a=o|0,u=s|0,o=n|0,s=i|0;let V=N.add3L(O,M,q);n=N.add3H(V,L,U,$),i=V|0}({h:n,l:i}=N.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=N.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:u}=N.add(this.Ch|0,this.Cl|0,a|0,u|0),{h:d,l:c}=N.add(this.Dh|0,this.Dl|0,d|0,c|0),{h:l,l:f}=N.add(this.Eh|0,this.El|0,l|0,f|0),{h,l:p}=N.add(this.Fh|0,this.Fl|0,h|0,p|0),{h:y,l:_}=N.add(this.Gh|0,this.Gl|0,y|0,_|0),{h:x,l:m}=N.add(this.Hh|0,this.Hl|0,x|0,m|0),this.set(n,i,o,s,a,u,d,c,l,f,h,p,y,_,x,m)}roundClean(){xt.fill(0),Et.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Mi=class extends Bn{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}},ns=Je(()=>new Bn);var is=Je(()=>new Mi);var ss=BigInt(0),as=BigInt(1),Rc=BigInt(2);function Vi(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function $i(r){if(!Vi(r))throw new Error("Uint8Array expected")}function In(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var Hc=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function An(r){$i(r);let e="";for(let t=0;t<r.length;t++)e+=Hc[r[t]];return e}function cs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var st={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function os(r){if(r>=st._0&&r<=st._9)return r-st._0;if(r>=st._A&&r<=st._F)return r-(st._A-10);if(r>=st._a&&r<=st._f)return r-(st._a-10)}function us(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,o=0;i<t;i++,o+=2){let s=os(r.charCodeAt(o)),a=os(r.charCodeAt(o+1));if(s===void 0||a===void 0){let u=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+o)}n[i]=s*16+a}return n}function ls(r){return cs(An(r))}function at(r){return $i(r),cs(An(Uint8Array.from(r).reverse()))}function qi(r,e){return us(r.toString(16).padStart(e*2,"0"))}function zt(r,e){return qi(r,e).reverse()}function Le(r,e,t){let n;if(typeof e=="string")try{n=us(e)}catch(o){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Vi(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function Gi(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];$i(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let o=r[n];t.set(o,i),i+=o.length}return t}var ji=r=>typeof r=="bigint"&&ss<=r;function zc(r,e,t){return ji(r)&&ji(e)&&ji(t)&&e<=r&&r<t}function ct(r,e,t,n){if(!zc(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function fs(r){let e;for(e=0;r>ss;r>>=as,e+=1);return e}var hs=r=>(Rc<<BigInt(r-1))-as;var Nc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Vi(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function _t(r,e,t={}){let n=(i,o,s)=>{let a=Nc[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let u=r[i];if(!(s&&u===void 0)&&!a(u,r))throw new Error(`Invalid param ${String(i)}=${u} (${typeof u}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(t))n(i,o,!0);return r}function Xi(r){let e=new WeakMap;return(t,...n)=>{let i=e.get(t);if(i!==void 0)return i;let o=r(t,...n);return e.set(t,o),o}}var fe=BigInt(0),le=BigInt(1),Nt=BigInt(2),Fc=BigInt(3),Zi=BigInt(4),ds=BigInt(5),ps=BigInt(8),Mc=BigInt(9),jc=BigInt(16);function oe(r,e){let t=r%e;return t>=fe?t:e+t}function Wi(r,e,t){if(t<=fe||e<fe)throw new Error("Expected power/modulo > 0");if(t===le)return fe;let n=le;for(;e>fe;)e&le&&(n=n*r%t),r=r*r%t,e>>=le;return n}function ne(r,e,t){let n=r;for(;e-- >fe;)n*=n,n%=t;return n}function ws(r,e){if(r===fe||e<=fe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=oe(r,e),n=e,i=fe,o=le,s=le,a=fe;for(;t!==fe;){let d=n/t,c=n%t,l=i-s*d,f=o-a*d;n=t,t=c,i=s,o=a,s=l,a=f}if(n!==le)throw new Error("invert: does not exist");return oe(i,e)}function Vc(r){let e=(r-le)/Nt,t,n,i;for(t=r-le,n=0;t%Nt===fe;t/=Nt,n++);for(i=Nt;i<r&&Wi(i,e,r)!==r-le;i++);if(n===1){let s=(r+le)/Zi;return function(u,d){let c=u.pow(d,s);if(!u.eql(u.sqr(c),d))throw new Error("Cannot find square root");return c}}let o=(t+le)/Nt;return function(a,u){if(a.pow(u,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let d=n,c=a.pow(a.mul(a.ONE,i),t),l=a.pow(u,o),f=a.pow(u,t);for(;!a.eql(f,a.ONE);){if(a.eql(f,a.ZERO))return a.ZERO;let h=1;for(let y=a.sqr(f);h<d&&!a.eql(y,a.ONE);h++)y=a.sqr(y);let p=a.pow(c,le<<BigInt(d-h-1));c=a.sqr(p),l=a.mul(l,p),f=a.mul(f,c),d=h}return l}}function $c(r){if(r%Zi===Fc){let e=(r+le)/Zi;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(r%ps===ds){let e=(r-ds)/ps;return function(n,i){let o=n.mul(i,Nt),s=n.pow(o,e),a=n.mul(i,s),u=n.mul(n.mul(a,Nt),s),d=n.mul(a,n.sub(u,n.ONE));if(!n.eql(n.sqr(d),i))throw new Error("Cannot find square root");return d}}return r%jc,Vc(r)}var qc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ms(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=qc.reduce((n,i)=>(n[i]="function",n),e);return _t(r,t)}function Gc(r,e,t){if(t<fe)throw new Error("Expected power > 0");if(t===fe)return r.ONE;if(t===le)return e;let n=r.ONE,i=e;for(;t>fe;)t&le&&(n=r.mul(n,i)),i=r.sqr(i),t>>=le;return n}function Xc(r,e){let t=new Array(e.length),n=e.reduce((o,s,a)=>r.is0(s)?o:(t[a]=o,r.mul(o,s)),r.ONE),i=r.inv(n);return e.reduceRight((o,s,a)=>r.is0(s)?o:(t[a]=r.mul(o,t[a]),r.mul(o,s)),i),t}function Yi(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Pr(r,e,t=!1,n={}){if(r<=fe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:o}=Yi(r,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=$c(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:o,MASK:hs(i),ZERO:fe,ONE:le,create:u=>oe(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof u}`);return fe<=u&&u<r},is0:u=>u===fe,isOdd:u=>(u&le)===le,neg:u=>oe(-u,r),eql:(u,d)=>u===d,sqr:u=>oe(u*u,r),add:(u,d)=>oe(u+d,r),sub:(u,d)=>oe(u-d,r),mul:(u,d)=>oe(u*d,r),pow:(u,d)=>Gc(a,u,d),div:(u,d)=>oe(u*ws(d,r),r),sqrN:u=>u*u,addN:(u,d)=>u+d,subN:(u,d)=>u-d,mulN:(u,d)=>u*d,inv:u=>ws(u,r),sqrt:n.sqrt||(u=>s(a,u)),invertBatch:u=>Xc(a,u),cmov:(u,d,c)=>c?d:u,toBytes:u=>t?zt(u,o):qi(u,o),fromBytes:u=>{if(u.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${u.length}`);return t?at(u):ls(u)}});return Object.freeze(a)}var Zc=BigInt(0),Ji=BigInt(1),Qi=new WeakMap,gs=new WeakMap;function ys(r,e){let t=(o,s)=>{let a=s.negate();return o?a:s},n=o=>{if(!Number.isSafeInteger(o)||o<=0||o>e)throw new Error(`Wrong window size=${o}, should be [1..${e}]`)},i=o=>{n(o);let s=Math.ceil(e/o)+1,a=2**(o-1);return{windows:s,windowSize:a}};return{constTimeNegate:t,unsafeLadder(o,s){let a=r.ZERO,u=o;for(;s>Zc;)s&Ji&&(a=a.add(u)),u=u.double(),s>>=Ji;return a},precomputeWindow(o,s){let{windows:a,windowSize:u}=i(s),d=[],c=o,l=c;for(let f=0;f<a;f++){l=c,d.push(l);for(let h=1;h<u;h++)l=l.add(c),d.push(l);c=l.double()}return d},wNAF(o,s,a){let{windows:u,windowSize:d}=i(o),c=r.ZERO,l=r.BASE,f=BigInt(2**o-1),h=2**o,p=BigInt(o);for(let y=0;y<u;y++){let _=y*d,x=Number(a&f);a>>=p,x>d&&(x-=h,a+=Ji);let m=_,g=_+Math.abs(x)-1,k=y%2!==0,C=x<0;x===0?l=l.add(t(k,s[m])):c=c.add(t(C,s[g]))}return{p:c,f:l}},wNAFCached(o,s,a){let u=gs.get(o)||1,d=Qi.get(o);return d||(d=this.precomputeWindow(o,u),u!==1&&Qi.set(o,a(d))),this.wNAF(u,d,s)},setWindowSize(o,s){n(s),gs.set(o,s),Qi.delete(o)}}}function bs(r,e,t,n){if(!Array.isArray(t)||!Array.isArray(n)||n.length!==t.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((c,l)=>{if(!e.isValid(c))throw new Error(`wrong scalar at index ${l}`)}),t.forEach((c,l)=>{if(!(c instanceof r))throw new Error(`wrong point at index ${l}`)});let i=fs(BigInt(t.length)),o=i>12?i-3:i>4?i-2:i?2:1,s=(1<<o)-1,a=new Array(s+1).fill(r.ZERO),u=Math.floor((e.BITS-1)/o)*o,d=r.ZERO;for(let c=u;c>=0;c-=o){a.fill(r.ZERO);for(let f=0;f<n.length;f++){let h=n[f],p=Number(h>>BigInt(c)&BigInt(s));a[p]=a[p].add(t[f])}let l=r.ZERO;for(let f=a.length-1,h=r.ZERO;f>0;f--)h=h.add(a[f]),l=l.add(h);if(d=d.add(l),c!==0)for(let f=0;f<o;f++)d=d.double()}return d}function xs(r){return ms(r.Fp),_t(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Yi(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Fe=BigInt(0),ke=BigInt(1),Pn=BigInt(2),Wc=BigInt(8),Yc={zip215:!0};function Jc(r){let e=xs(r);return _t(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Es(r){let e=Jc(r),{Fp:t,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:u}=e,d=Pn<<BigInt(a*8)-ke,c=t.create,l=Pr(e.n,e.nBitLength),f=e.uvRatio||((S,b)=>{try{return{isValid:!0,value:t.sqrt(S*t.inv(b))}}catch{return{isValid:!1,value:Fe}}}),h=e.adjustScalarBytes||(S=>S),p=e.domain||((S,b,v)=>{if(In("phflag",v),b.length||v)throw new Error("Contexts/pre-hash are not supported");return S});function y(S,b){ct("coordinate "+S,b,Fe,d)}function _(S){if(!(S instanceof g))throw new Error("ExtendedPoint expected")}let x=Xi((S,b)=>{let{ex:v,ey:E,ez:I}=S,P=S.is0();b==null&&(b=P?Wc:t.inv(I));let T=c(v*b),D=c(E*b),F=c(I*b);if(P)return{x:Fe,y:ke};if(F!==ke)throw new Error("invZ was invalid");return{x:T,y:D}}),m=Xi(S=>{let{a:b,d:v}=e;if(S.is0())throw new Error("bad point: ZERO");let{ex:E,ey:I,ez:P,et:T}=S,D=c(E*E),F=c(I*I),G=c(P*P),te=c(G*G),ie=c(D*b),ae=c(G*c(ie+F)),ce=c(te+c(v*c(D*F)));if(ae!==ce)throw new Error("bad point: equation left != right (1)");let Ee=c(E*I),Ae=c(P*T);if(Ee!==Ae)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(b,v,E,I){this.ex=b,this.ey=v,this.ez=E,this.et=I,y("x",b),y("y",v),y("z",E),y("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(b){if(b instanceof g)throw new Error("extended point not allowed");let{x:v,y:E}=b||{};return y("x",v),y("y",E),new g(v,E,ke,c(v*E))}static normalizeZ(b){let v=t.invertBatch(b.map(E=>E.ez));return b.map((E,I)=>E.toAffine(v[I])).map(g.fromAffine)}static msm(b,v){return bs(g,l,b,v)}_setWindowSize(b){R.setWindowSize(this,b)}assertValidity(){m(this)}equals(b){_(b);let{ex:v,ey:E,ez:I}=this,{ex:P,ey:T,ez:D}=b,F=c(v*D),G=c(P*I),te=c(E*D),ie=c(T*I);return F===G&&te===ie}is0(){return this.equals(g.ZERO)}negate(){return new g(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:b}=e,{ex:v,ey:E,ez:I}=this,P=c(v*v),T=c(E*E),D=c(Pn*c(I*I)),F=c(b*P),G=v+E,te=c(c(G*G)-P-T),ie=F+T,ae=ie-D,ce=F-T,Ee=c(te*ae),Ae=c(ie*ce),Me=c(te*ce),Re=c(ae*ie);return new g(Ee,Ae,Re,Me)}add(b){_(b);let{a:v,d:E}=e,{ex:I,ey:P,ez:T,et:D}=this,{ex:F,ey:G,ez:te,et:ie}=b;if(v===BigInt(-1)){let wr=c((P-I)*(G+F)),ye=c((P+I)*(G-F)),je=c(ye-wr);if(je===Fe)return this.double();let At=c(T*Pn*ie),j=c(D*Pn*te),W=j+At,H=ye+wr,Q=j-At,He=c(W*je),Te=c(H*Q),J=c(W*Q),K=c(je*H);return new g(He,Te,K,J)}let ae=c(I*F),ce=c(P*G),Ee=c(D*E*ie),Ae=c(T*te),Me=c((I+P)*(F+G)-ae-ce),Re=Ae-Ee,$r=Ae+Ee,jt=c(ce-v*ae),It=c(Me*Re),Vt=c($r*jt),ti=c(Me*jt),qr=c(Re*$r);return new g(It,Vt,qr,ti)}subtract(b){return this.add(b.negate())}wNAF(b){return R.wNAFCached(this,b,g.normalizeZ)}multiply(b){let v=b;ct("scalar",v,ke,n);let{p:E,f:I}=this.wNAF(v);return g.normalizeZ([E,I])[0]}multiplyUnsafe(b){let v=b;return ct("scalar",v,Fe,n),v===Fe?C:this.equals(C)||v===ke?this:this.equals(k)?this.wNAF(v).p:R.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return R.unsafeLadder(this,n).is0()}toAffine(b){return x(this,b)}clearCofactor(){let{h:b}=e;return b===ke?this:this.multiplyUnsafe(b)}static fromHex(b,v=!1){let{d:E,a:I}=e,P=t.BYTES;b=Le("pointHex",b,P),In("zip215",v);let T=b.slice(),D=b[P-1];T[P-1]=D&-129;let F=at(T),G=v?d:t.ORDER;ct("pointHex.y",F,Fe,G);let te=c(F*F),ie=c(te-ke),ae=c(E*te-I),{isValid:ce,value:Ee}=f(ie,ae);if(!ce)throw new Error("Point.fromHex: invalid y coordinate");let Ae=(Ee&ke)===ke,Me=(D&128)!==0;if(!v&&Ee===Fe&&Me)throw new Error("Point.fromHex: x=0 and x_0=1");return Me!==Ae&&(Ee=c(-Ee)),g.fromAffine({x:Ee,y:F})}static fromPrivateKey(b){return L(b).point}toRawBytes(){let{x:b,y:v}=this.toAffine(),E=zt(v,t.BYTES);return E[E.length-1]|=b&ke?128:0,E}toHex(){return An(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,ke,c(e.Gx*e.Gy)),g.ZERO=new g(Fe,ke,ke,Fe);let{BASE:k,ZERO:C}=g,R=ys(g,a*8);function z(S){return oe(S,n)}function A(S){return z(at(S))}function L(S){let b=a;S=Le("private key",S,b);let v=Le("hashed private key",o(S),2*b),E=h(v.slice(0,b)),I=v.slice(b,2*b),P=A(E),T=k.multiply(P),D=T.toRawBytes();return{head:E,prefix:I,scalar:P,point:T,pointBytes:D}}function O(S){return L(S).pointBytes}function U(S=new Uint8Array,...b){let v=Gi(...b);return A(o(p(v,Le("context",S),!!i)))}function M(S,b,v={}){S=Le("message",S),i&&(S=i(S));let{prefix:E,scalar:I,pointBytes:P}=L(b),T=U(v.context,E,S),D=k.multiply(T).toRawBytes(),F=U(v.context,D,P,S),G=z(T+F*I);ct("signature.s",G,Fe,n);let te=Gi(D,zt(G,t.BYTES));return Le("result",te,a*2)}let $=Yc;function q(S,b,v,E=$){let{context:I,zip215:P}=E,T=t.BYTES;S=Le("signature",S,2*T),b=Le("message",b),P!==void 0&&In("zip215",P),i&&(b=i(b));let D=at(S.slice(T,2*T)),F,G,te;try{F=g.fromHex(v,P),G=g.fromHex(S.slice(0,T),P),te=k.multiplyUnsafe(D)}catch{return!1}if(!P&&F.isSmallOrder())return!1;let ie=U(I,G.toRawBytes(),F.toRawBytes(),b);return G.add(F.multiplyUnsafe(ie)).subtract(te).clearCofactor().equals(g.ZERO)}return k._setWindowSize(8),{CURVE:e,getPublicKey:O,sign:M,verify:q,ExtendedPoint:g,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>s(t.BYTES),precompute(S=8,b=g.BASE){return b._setWindowSize(S),b.multiply(BigInt(3)),b}}}}var ar=BigInt(0),eo=BigInt(1);function Qc(r){return _t(r,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r})}function Ln(r){let e=Qc(r),{P:t}=e,n=m=>oe(m,t),i=e.montgomeryBits,o=Math.ceil(i/8),s=e.nByteLength,a=e.adjustScalarBytes||(m=>m),u=e.powPminus2||(m=>Wi(m,t-BigInt(2),t));function d(m,g,k){let C=n(m*(g-k));return g=n(g-C),k=n(k+C),[g,k]}let c=(e.a-BigInt(2))/BigInt(4);function l(m,g){ct("u",m,ar,t),ct("scalar",g,ar,t);let k=g,C=m,R=eo,z=ar,A=m,L=eo,O=ar,U;for(let $=BigInt(i-1);$>=ar;$--){let q=k>>$&eo;O^=q,U=d(O,R,A),R=U[0],A=U[1],U=d(O,z,L),z=U[0],L=U[1],O=q;let V=R+z,S=n(V*V),b=R-z,v=n(b*b),E=S-v,I=A+L,P=A-L,T=n(P*V),D=n(I*b),F=T+D,G=T-D;A=n(F*F),L=n(C*n(G*G)),R=n(S*v),z=n(E*(S+n(c*E)))}U=d(O,R,A),R=U[0],A=U[1],U=d(O,z,L),z=U[0],L=U[1];let M=u(z);return n(R*M)}function f(m){return zt(n(m),o)}function h(m){let g=Le("u coordinate",m,o);return s===32&&(g[31]&=127),at(g)}function p(m){let g=Le("scalar",m),k=g.length;if(k!==o&&k!==s)throw new Error(`Expected ${o} or ${s} bytes, got ${k}`);return at(a(g))}function y(m,g){let k=h(g),C=p(m),R=l(k,C);if(R===ar)throw new Error("Invalid private or public key received");return f(R)}let _=f(e.Gu);function x(m){return y(m,_)}return{scalarMult:y,scalarMultBase:x,getSharedSecret:(m,g)=>y(m,g),getPublicKey:m=>x(m),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:_}}var to=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");var yd=BigInt(0),tu=BigInt(1),_s=BigInt(2),ru=BigInt(3),nu=BigInt(5),bd=BigInt(8);function iu(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),i=BigInt(80),o=to,a=r*r%o*r%o,u=ne(a,_s,o)*a%o,d=ne(u,tu,o)*r%o,c=ne(d,nu,o)*d%o,l=ne(c,e,o)*c%o,f=ne(l,t,o)*l%o,h=ne(f,n,o)*f%o,p=ne(h,i,o)*h%o,y=ne(p,i,o)*h%o,_=ne(y,e,o)*c%o;return{pow_p_5_8:ne(_,_s,o)*r%o,b2:a}}function ou(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Tn=Ln({P:to,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:r=>{let e=to,{pow_p_5_8:t,b2:n}=iu(r);return oe(ne(t,ru,e)*n,e)},adjustScalarBytes:ou,randomBytes:Ar});var cr="X25519";function vs(r){let e=r.replace(/-/g,"+").replace(/_/g,"/"),t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n}var Lr=class{constructor(e){Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=e,this._nPk=32,this._nSk=32}async serializePublicKey(e){try{return await this._serializePublicKey(e)}catch(t){throw new we(t)}}async deserializePublicKey(e){try{return await this._importRawKey(e,!0)}catch(t){throw new ue(t)}}async serializePrivateKey(e){try{return await this._serializePrivateKey(e)}catch(t){throw new we(t)}}async deserializePrivateKey(e){try{return await this._importRawKey(e,!1)}catch(t){throw new ue(t)}}async importKey(e,t,n){try{if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}catch(i){throw new ue(i)}}async generateKeyPair(){try{let e=Tn.utils.randomPrivateKey(),t=new pe(cr,e,"private",xe);return{publicKey:await this.derivePublicKey(t),privateKey:t}}catch(e){throw new me(e)}}async deriveKeyPair(e){try{let t=await this._hkdf.labeledExtract(ee,wt,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,rr,ee,this._nSk),i=new pe(cr,new Uint8Array(n),"private",xe);return{privateKey:i,publicKey:await this.derivePublicKey(i)}}catch(t){throw new Ze(t)}}async derivePublicKey(e){try{return await this._derivePublicKey(e)}catch(t){throw new ue(t)}}async dh(e,t){try{return await this._dh(e,t)}catch(n){throw new we(n)}}_serializePublicKey(e){return new Promise(t=>{t(e.key.buffer)})}_serializePrivateKey(e){return new Promise(t=>{t(e.key.buffer)})}_importRawKey(e,t){return new Promise((n,i)=>{t&&e.byteLength!==this._nPk&&i(new Error("Invalid length of the key")),!t&&e.byteLength!==this._nSk&&i(new Error("Invalid length of the key")),n(new pe(cr,new Uint8Array(e),t?"public":"private",t?[]:xe))})}_importJWK(e,t){return new Promise((n,i)=>{(typeof e.kty>"u"||e.kty!=="OKP")&&i(new Error(`Invalid kty: ${e.kty}`)),(typeof e.crv>"u"||e.crv!=="X25519")&&i(new Error(`Invalid crv: ${e.crv}`)),t?(typeof e.d<"u"&&i(new Error("Invalid key: `d` should not be set")),typeof e.x>"u"&&i(new Error("Invalid key: `x` not found")),n(new pe(cr,vs(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new pe(cr,vs(e.d),"private",xe)))})}_derivePublicKey(e){return new Promise((t,n)=>{try{let i=Tn.getPublicKey(e.key);t(new pe(cr,i,"public"))}catch(i){n(i)}})}_dh(e,t){return new Promise((n,i)=>{try{n(Tn.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var Tr=class extends ve{constructor(){let e=new ot;super(X.DhkemX25519HkdfSha256,new Lr(e),e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:X.DhkemX25519HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}};var ut=class extends Kt{async extract(e,t){if(await this._setup(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)return Ht(ns,new Uint8Array(e),new Uint8Array(t));let n=await this._api.importKey("raw",e,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,t)}};var Bs=[],Is=[],As=[],su=BigInt(0),Ur=BigInt(1),au=BigInt(2),cu=BigInt(7),uu=BigInt(256),lu=BigInt(113);for(let r=0,e=Ur,t=1,n=0;r<24;r++){[t,n]=[n,(2*t+3*n)%5],Bs.push(2*(5*n+t)),Is.push((r+1)*(r+2)/2%64);let i=su;for(let o=0;o<7;o++)e=(e<<Ur^(e>>cu)*lu)%uu,e&au&&(i^=Ur<<(Ur<<BigInt(o))-Ur);As.push(i)}var[fu,hu]=Hi(As,!0),Ss=(r,e,t)=>t>32?Di(r,e,t):zi(r,e,t),ks=(r,e,t)=>t>32?Fi(r,e,t):Ni(r,e,t);function du(r,e=24){let t=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let s=0;s<10;s++)t[s]=r[s]^r[s+10]^r[s+20]^r[s+30]^r[s+40];for(let s=0;s<10;s+=2){let a=(s+8)%10,u=(s+2)%10,d=t[u],c=t[u+1],l=Ss(d,c,1)^t[a],f=ks(d,c,1)^t[a+1];for(let h=0;h<50;h+=10)r[s+h]^=l,r[s+h+1]^=f}let i=r[2],o=r[3];for(let s=0;s<24;s++){let a=Is[s],u=Ss(i,o,a),d=ks(i,o,a),c=Bs[s];i=r[c],o=r[c+1],r[c]=u,r[c+1]=d}for(let s=0;s<50;s+=10){for(let a=0;a<10;a++)t[a]=r[s+a];for(let a=0;a<10;a++)r[s+a]^=~t[(a+2)%10]&t[(a+4)%10]}r[0]^=fu[n],r[1]^=hu[n]}t.fill(0)}var ur=class r extends gt{constructor(e,t,n,i=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=i,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Ir(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Ti(this.state)}keccak(){Ui||Ci(this.state32),du(this.state32,this.rounds),Ui||Ci(this.state32),this.posOut=0,this.pos=0}update(e){nt(this);let{blockLen:t,state:n}=this;e=it(e);let i=e.length;for(let o=0;o<i;){let s=Math.min(t-this.pos,i-o);for(let a=0;a<s;a++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:i}=this;e[n]^=t,t&128&&n===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){nt(this,!1),mt(e),this.finish();let t=this.state,{blockLen:n}=this;for(let i=0,o=e.length;i<o;){this.posOut>=n&&this.keccak();let s=Math.min(n-this.posOut,o-i);e.set(t.subarray(this.posOut,this.posOut+s),i),this.posOut+=s,i+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Ir(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(xn(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:i,rounds:o,enableXOF:s}=this;return e||(e=new r(t,n,i,s,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=i,e.enableXOF=s,e.destroyed=this.destroyed,e}},vt=(r,e,t)=>Je(()=>new ur(e,r,t)),Nd=vt(6,144,224/8),Dd=vt(6,136,256/8),Fd=vt(6,104,384/8),Md=vt(6,72,512/8),jd=vt(1,144,224/8),Vd=vt(1,136,256/8),$d=vt(1,104,384/8),qd=vt(1,72,512/8),Ps=(r,e,t)=>vn((n={})=>new ur(e,r,n.dkLen===void 0?t:n.dkLen,!0)),Gd=Ps(31,168,128/8),ro=Ps(31,136,256/8);var pu=Je(()=>ro.create({dkLen:114})),wu=Je(()=>ro.create({dkLen:64})),Cr=BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439"),mu=BigInt(1),Ls=BigInt(2),Ts=BigInt(3),e0=BigInt(4),gu=BigInt(11),yu=BigInt(22),Us=BigInt(44),bu=BigInt(88),xu=BigInt(223);function Cs(r){let e=Cr,t=r*r*r%e,n=t*t*r%e,i=ne(n,Ts,e)*n%e,o=ne(i,Ts,e)*n%e,s=ne(o,Ls,e)*t%e,a=ne(s,gu,e)*s%e,u=ne(a,yu,e)*a%e,d=ne(u,Us,e)*u%e,c=ne(d,bu,e)*d%e,l=ne(c,Us,e)*u%e,f=ne(l,Ls,e)*t%e,h=ne(f,mu,e)*r%e;return ne(h,xu,e)*f%e}function Os(r){return r[0]&=252,r[55]|=128,r[56]=0,r}function Eu(r,e){let t=Cr,n=oe(r*r*e,t),i=oe(n*r,t),o=oe(i*n*e,t),s=Cs(o),a=oe(i*s,t),u=oe(a*a,t);return{isValid:oe(u*e,t)===r,value:a}}var Ks=Pr(Cr,456,!0),_u={a:BigInt(1),d:BigInt("726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358"),Fp:Ks,n:BigInt("181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779"),nBitLength:456,h:BigInt(4),Gx:BigInt("224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710"),Gy:BigInt("298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660"),hash:pu,randomBytes:Ar,adjustScalarBytes:Os,domain:(r,e,t)=>{if(e.length>255)throw new Error(`Context is too big: ${e.length}`);return Oi(_n("SigEd448"),new Uint8Array([t?1:0,e.length]),e,r)},uvRatio:Eu};var t0=Es({..._u,prehash:wu}),Un=Ln({a:BigInt(156326),montgomeryBits:448,nByteLength:56,P:Cr,Gu:BigInt(5),powPminus2:r=>{let e=Cr,t=Cs(r),n=ne(t,BigInt(2),e);return oe(n*r,e)},adjustScalarBytes:Os,randomBytes:Ar});var r0=(Ks.ORDER-BigInt(3))/BigInt(4),n0=BigInt(156326);var i0=BigInt("39082"),o0=BigInt("78163"),s0=BigInt("98944233647732219769177004876929019128417576295529901074099889598043702116001257856802131563896515373927712232092845883226922417596214"),a0=BigInt("315019913931389607337177038330951043522456072897266928557328499619017160722351061360252776265186336876723201881398623946864393857820716");var c0=BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var lr="X448";function Rs(r){let e=r.replace(/-/g,"+").replace(/_/g,"/"),t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n}var Or=class{constructor(e){Object.defineProperty(this,"_hkdf",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nPk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nSk",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._hkdf=e,this._nPk=56,this._nSk=56}async serializePublicKey(e){try{return await this._serializePublicKey(e)}catch(t){throw new we(t)}}async deserializePublicKey(e){try{return await this._importRawKey(e,!0)}catch(t){throw new ue(t)}}async serializePrivateKey(e){try{return await this._serializePrivateKey(e)}catch(t){throw new we(t)}}async deserializePrivateKey(e){try{return await this._importRawKey(e,!1)}catch(t){throw new ue(t)}}async importKey(e,t,n){try{if(e==="raw")return await this._importRawKey(t,n);if(t instanceof ArrayBuffer)throw new Error("Invalid jwk key format");return await this._importJWK(t,n)}catch(i){throw new ue(i)}}async generateKeyPair(){try{let e=Un.utils.randomPrivateKey(),t=new pe(lr,e,"private",xe);return{publicKey:await this.derivePublicKey(t),privateKey:t}}catch(e){throw new me(e)}}async deriveKeyPair(e){try{let t=await this._hkdf.labeledExtract(ee,wt,new Uint8Array(e)),n=await this._hkdf.labeledExpand(t,rr,ee,this._nSk),i=new pe(lr,new Uint8Array(n),"private",xe);return{privateKey:i,publicKey:await this.derivePublicKey(i)}}catch(t){throw new Ze(t)}}async derivePublicKey(e){try{return await this._derivePublicKey(e)}catch(t){throw new ue(t)}}async dh(e,t){try{return await this._dh(e,t)}catch(n){throw new we(n)}}_serializePublicKey(e){return new Promise(t=>{t(e.key.buffer)})}_serializePrivateKey(e){return new Promise(t=>{t(e.key.buffer)})}_importRawKey(e,t){return new Promise((n,i)=>{t&&e.byteLength!==this._nPk&&i(new Error("Invalid length of the key")),!t&&e.byteLength!==this._nSk&&i(new Error("Invalid length of the key")),n(new pe(lr,new Uint8Array(e),t?"public":"private",t?[]:xe))})}_importJWK(e,t){return new Promise((n,i)=>{e.kty!=="OKP"&&i(new Error(`Invalid kty: ${e.kty}`)),e.crv!=="X448"&&i(new Error(`Invalid crv: ${e.crv}`)),t?(typeof e.d<"u"&&i(new Error("Invalid key: `d` should not be set")),typeof e.x!="string"&&i(new Error("Invalid key: `x` not found")),n(new pe(lr,Rs(e.x),"public"))):(typeof e.d!="string"&&i(new Error("Invalid key: `d` not found")),n(new pe(lr,Rs(e.d),"private",xe)))})}_derivePublicKey(e){return new Promise((t,n)=>{try{let i=Un.getPublicKey(e.key);t(new pe(lr,i,"public"))}catch(i){n(i)}})}_dh(e,t){return new Promise((n,i)=>{try{n(Un.getSharedSecret(e.key,t.key).buffer)}catch(o){i(o)}})}};var Kr=class extends ve{constructor(){let e=new ut;super(X.DhkemX448HkdfSha512,new Or(e),e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:X.DhkemX448HkdfSha512}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:56}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:56}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:56})}};var fr=class extends Ot{async extract(e,t){if(await this._setup(),e.byteLength===0&&(e=new ArrayBuffer(this.hashSize)),e.byteLength!==this.hashSize)return Ht(is,new Uint8Array(e),new Uint8Array(t));let n=await this._api.importKey("raw",e,this.algHash,!1,["sign"]);return await this._api.sign("HMAC",n,t)}};var Cn=class extends ve{constructor(){let e=new ot,t=new Ye(X.DhkemP256HkdfSha256,e);super(X.DhkemP256HkdfSha256,t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:X.DhkemP256HkdfSha256}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:32}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:65}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:32})}};var On=class extends ve{constructor(){let e=new fr,t=new Ye(X.DhkemP384HkdfSha384,e);super(X.DhkemP384HkdfSha384,t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:X.DhkemP384HkdfSha384}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:48}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:97}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:97}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:48})}};var Kn=class extends ve{constructor(){let e=new ut,t=new Ye(X.DhkemP521HkdfSha512,e);super(X.DhkemP521HkdfSha512,t,e),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:X.DhkemP521HkdfSha512}),Object.defineProperty(this,"secretSize",{enumerable:!0,configurable:!0,writable:!0,value:64}),Object.defineProperty(this,"encSize",{enumerable:!0,configurable:!0,writable:!0,value:133}),Object.defineProperty(this,"publicKeySize",{enumerable:!0,configurable:!0,writable:!0,value:133}),Object.defineProperty(this,"privateKeySize",{enumerable:!0,configurable:!0,writable:!0,value:64})}};var Rr=class extends kr{constructor(e){if(typeof e.kem=="number")switch(e.kem){case X.DhkemP256HkdfSha256:e.kem=new Cn;break;case X.DhkemP384HkdfSha384:e.kem=new On;break;case X.DhkemP521HkdfSha512:e.kem=new Kn;break;case X.DhkemX25519HkdfSha256:e.kem=new Tr;break;case X.DhkemX448HkdfSha512:e.kem=new Kr;break;default:throw new se(`The KEM (${e.kem}) cannot be specified by KemId. Use submodule for the KEM`)}if(typeof e.kdf=="number")switch(e.kdf){case Pe.HkdfSha256:e.kdf=new ot;break;case Pe.HkdfSha384:e.kdf=new fr;break;default:e.kdf=new ut;break}if(typeof e.aead=="number")switch(e.aead){case de.Aes128Gcm:e.aead=new nr;break;case de.Aes256Gcm:e.aead=new vr;break;case de.Chacha20Poly1305:e.aead=new Br;break;default:e.aead=new Sr;break}super(e)}async generateKeyPair(){return await this._setup(),await this._kem.generateKeyPair()}async deriveKeyPair(e){return await this._setup(),await this._kem.deriveKeyPair(e)}async importKey(e,t,n=!0){return await this._setup(),await this._kem.importKey(e,t,n)}};var Hn=class r{configs;#e;constructor(e){this.configs=e}static parse(e){return new r(gr.from(e).array16(zn))}encode(){return rn(this.configs)}selectConfig(){if(this.#e)return this.#e;for(let e of this.configs)try{return e.cipherSuite(),this.#e=e,e}catch{}throw new Error("no hpke configurations were recognized")}},zn=class r{id;kemId;kdfId;aeadId;publicKey;constructor(e,t,n,i,o){if(this.id=e,this.kemId=t,this.kdfId=n,this.aeadId=i,this.publicKey=o,e!==Math.floor(e)||e<0||e>255)throw new Error("id must be an integer in [0, 255]");if(t!==Math.floor(t)||t<0||t>65535)throw new Error("kemId must be an integer in [0, 65535]");if(n!==Math.floor(n)||n<0||n>65535)throw new Error("kdfId must be an integer in [0, 65535]");if(i!==Math.floor(i)||i<0||i>65535)throw new Error("aeadId must be an integer in [0, 65535]");if(o.length>65535)throw new Error("publicKey must not be longer than 65535 bytes")}validate(e,t){let n=this[t];if(!Object.values(e).includes(n)){let i=Object.entries(e).map(([o,s])=>`    ${s}: ${o}`).join(`
`);throw new Error(`${t} was ${n} but must be one of the following:
${i}`)}}static parse(e){let t=gr.from(e);return new r(t.uint8(),t.uint16(),t.uint16(),t.uint16(),t.opaque16())}encode(){let e=this.publicKey.length,t=Rn.Buffer.alloc(e+9),n=0;return t.writeUInt8(this.id,n),t.writeUInt16BE(this.kemId,n+=1),t.writeUInt16BE(this.kdfId,n+=2),t.writeUInt16BE(this.aeadId,n+=2),t.writeUInt16BE(e,n+=2),this.publicKey.copy(t,n+2),t}cipherSuite(){this.validate(X,"kemId"),this.validate(Pe,"kdfId"),this.validate(de,"aeadId");let e=this.aeadId,t=this.kdfId,n=this.kemId;return new Rr({aead:e,kdf:t,kem:n})}async seal(e,t,n){let o=await this.cipherSuite().kem.importKey("raw",this.publicKey),{ct:s,enc:a}=await this.cipherSuite().seal({recipientPublicKey:o,info:e},t,n);return new nn(this.id,Rn.Buffer.from(a),Rn.Buffer.from(s))}};var Dt=class r extends Error{type;title;status;detail;instance;clientContext;taskId;shortType;constructor(e,t){let n=e.type.split(":").slice(-1)[0];super(`${n}: ${e.title}`),this.shortType=n,this.type=e.type,this.title=e.title,this.status=e.status,this.detail=e.detail,this.instance=e.instance,this.clientContext=t,this.taskId=new et(e.taskid)}static async fromResponse(e,t){let n=e.headers.get("Content-Type");if(n&&n.match(/^application\/problem\+json/)){let i=await e.json();return new r(i,t)}return new Error(t)}};var Hr=class r{role;hpkeConfigList;url;constructor(e,t,n){this.role=t,this.hpkeConfigList=n,this.url=new URL(e),this.url.pathname.endsWith("/")||(this.url.pathname+="/")}static helper(e){return new r(e,yr.Helper)}static leader(e){return new r(e,yr.Leader)}async seal(e,t){if(!this.hpkeConfigList)throw new Error("Attempted to call Aggregator#seal before fetching a hpkeConfigList.");return await this.hpkeConfigList.selectConfig().seal(new un(this.role).encode(),e.encode(),t.encode())}};var zr=Ue(ze(),1),vu=8;var Nn=class{async shardEncoded(e,t,n){let{inputShares:i,publicShare:o}=await this.shard(e,t,n);return{publicShare:this.encodePublicShare(o),inputShares:i.map(s=>this.encodeInputShare(s))}}domainSeparationTag(e){return ku(0,this.id,e)}run({aggregationParameter:e,verifyKey:t,nonces:n,measurements:i,rands:o}){return Su({vdaf:this,verifyKey:t,aggregationParameter:e,nonces:n,measurements:i,rands:o})}async test(e,t){return(await this.run({aggregationParameter:e,measurements:t})).agg_result}encodeTestVectorInputShare(e){return this.encodeInputShare(e).toString("hex")}encodeTestVectorPublicShare(e){return this.encodePublicShare(e).toString("hex")}encodeTestVectorAggregatorShare(e){return this.encodeAggregatorShare(e).toString("hex")}encodeTestVectorPreparationShare(e){return this.encodePreparationShare(e).toString("hex")}encodeTestVectorPreparationMessage(e){return this.encodePreparationMessage(e).toString("hex")}encodeTestVectorOutputShare(e){return[]}};async function Su(r){let{vdaf:e,aggregationParameter:t,measurements:n}=r,{verifyKeySize:i,randSize:o,nonceSize:s,rounds:a,shares:u}=e,d=r.verifyKey??zr.Buffer.from(Xe(i)),c={agg_param:t,agg_shares:[],prep:[],verify_key:d.toString("hex"),shares:u},l=await Promise.all(n.map(async(p,y)=>{let _=r.nonces?.[y]??zr.Buffer.from(Xe(s)),x=r.rands?.[y]??zr.Buffer.from(Xe(o)),{publicShare:m,inputShares:g}=await e.shard(p,_,x),k={input_shares:g.map(A=>e.encodeTestVectorInputShare(A)),measurement:p,nonce:_.toString("hex"),out_shares:[],prep_messages:[],prep_shares:Y(a,()=>[]),public_share:e.encodeTestVectorPublicShare(m),rand:x.toString("hex")},C=await Promise.all(g.map((A,L)=>e.prepareInit(d,L,t,_,m,A)));k.prep_shares[0]=C.map(({preparationShare:A})=>e.encodeTestVectorPreparationShare(A));for(let A=0;A<a-1;A++){let L=await e.unshardPreparationShares(t,C.map(({preparationShare:O})=>O));k.prep_messages.push(e.encodeTestVectorPreparationMessage(L)),C=C.map(({preparationState:O})=>{let U=e.prepareNext(O,L);if("outputShare"in U)throw new Error("expected preparationState and preparationShare");return U}),k.prep_shares[A]=C.map(({preparationShare:O})=>e.encodeTestVectorPreparationShare(O))}let R=await e.unshardPreparationShares(t,C.map(({preparationShare:A})=>A));k.prep_messages.push(e.encodeTestVectorPreparationMessage(R));let z=C.map(({preparationState:A})=>{let L=e.prepareNext(A,R);if("preparationState"in L)throw new Error("expected outputShare for the last share");return L.outputShare});return k.out_shares=z.map(A=>e.encodeTestVectorOutputShare(A)),c.prep.push(k),z})),f=Y(u,p=>{let y=l.reduce((x,m)=>[...x,m[p]],[]),_=e.aggregate(t,y);return c.agg_shares.push(e.encodeTestVectorAggregatorShare(_)),_}),h=e.unshard(t,f,n.length);return{...c,agg_result:h}}function ku(r,e,t){let n=zr.Buffer.alloc(8);return n.writeUInt8(vu,0),n.writeUInt8(r,1),n.writeUInt32BE(e,2),n.writeUInt16BE(t,6),n}var St=class{values;elementSize;constructor(e,t){this.values=e,this.elementSize=t}get length(){return this.values.length}toValues(){return this.values}};var Bu=8,Dn=class{modulus;elementSize;constructor(e){this.modulus=e;let t=1;for(;e!=1n;)e=e>>1n,t++;this.elementSize=Math.max(Math.ceil(t/8),Bu)}mod(e){return e>=0n?e%this.modulus:(e%this.modulus+this.modulus)%this.modulus}add(e,t){return this.mod(e+t)}sub(e,t){return this.mod(e-t)}mul(e,t){return this.mod(e*t)}div(e,t){return this.mul(e,this.inv(t))}exp(e,t){if(e=this.mod(e),e===0n){if(t===0n)throw new TypeError("Base and exponent cannot be both 0");return 0n}t<0n&&(e=this.inv(e),t=-t);let n=1n;for(;t>0n;)t%2n&&(n=this.mul(n,e)),t=t/2n,e=this.mul(e,e);return n}inv(e){let t=this.mod(e);if(t===0n)return 0n;let n=1n,i=0n,o=this.modulus;for(;t>1n;){let s=o/t,a=i-n*s,u=o-t*s;o=t,i=n,n=a,t=u}return this.mod(n)}rand(){let e=this.modulus,t=new Uint8Array(this.elementSize);for(;e>=this.modulus;)Yr.getRandomValues(t),e=To(t);return e}newVectorFrom(e){return new St(e,this.elementSize)}addVectorElements(e,t){return typeof t=="bigint"?this.vectorScalarOp(this.add.bind(this),e,t):this.vectorElementsOp(this.add.bind(this),e,t)}subVectorElements(e,t){return typeof t=="bigint"?this.vectorScalarOp(this.sub.bind(this),e,t):this.vectorElementsOp(this.sub.bind(this),e,t)}mulVectorElements(e,t){return typeof t=="bigint"?this.vectorScalarOp(this.mul.bind(this),e,t):this.vectorElementsOp(this.mul.bind(this),e,t)}divVectorElements(e,t){return typeof t=="bigint"?this.vectorScalarOp(this.mul.bind(this),e,this.inv(t)):this.vectorElementsOp(this.mul.bind(this),e,this.invVectorElements(t))}expVectorElements(e,t){return typeof t=="bigint"?this.vectorScalarOp(this.exp.bind(this),e,t):this.vectorElementsOp(this.exp.bind(this),e,t)}invVectorElements(e){let t=new Array(e.length),n=e.toValues(),i=1n;for(let s=0;s<e.length;s++)t[s]=i,i=this.mod(i*(n[s]||1n));let o=this.inv(i);for(let s=e.length-1;s>=0;s--)t[s]=this.mod(n[s]?t[s]*o:0n),o=this.mul(o,n[s]||1n);return this.newVectorFrom(t)}combineVectors(e,t){let n=e.toValues(),i=t.toValues(),o=0n;for(let s=0;s<e.length;s++)o=this.mod(o+n[s]*i[s]);return o}vectorElementsOp(e,t,n){let i=t.toValues(),o=n.toValues(),s=new Array(t.length);for(let a=0;a<s.length;a++)s[a]=e.call(this,i[a],o[a]);return new St(s,this.elementSize)}vectorScalarOp(e,t,n){let i=t.toValues(),o=new Array(t.length);for(let s=0;s<o.length;s++)o[s]=e.call(this,i[s],n);return new St(o,this.elementSize)}getRootOfUnity(e){if(!no(e))throw new Error("Order of unity must be 2^n");let t=BigInt(e);for(let n=2n;n<this.modulus;n++){let i=this.exp(n,(this.modulus-1n)/t);if(this.exp(i,t)===1n&&this.exp(i,t/2n)!==1n)return i}throw new Error(`Root of Unity for order ${e} was not found`)}getPowerSeries(e,t){let n=new Array(t);n[0]=1n;for(let i=1;i<t;i++)n[i]=this.mul(n[i-1],e);return this.newVectorFrom(n)}addPolys(e,t){let n=e.toValues(),i=t.toValues(),o=new Array(Math.max(e.length,t.length));for(let s=0;s<o.length;s++){let a=s<e.length?n[s]:0n,u=s<t.length?i[s]:0n;o[s]=this.mod(a+u)}return this.newVectorFrom(o)}subPolys(e,t){let n=e.toValues(),i=t.toValues(),o=new Array(Math.max(e.length,t.length));for(let s=0;s<o.length;s++){let a=s<e.length?n[s]:0n,u=s<t.length?i[s]:0n;o[s]=this.mod(a-u)}return this.newVectorFrom(o)}mulPolys(e,t){let n=e.toValues(),i=t.toValues(),o=new Array(e.length+t.length-1);for(let s=0;s<e.length;s++)for(let a=0;a<t.length;a++){let u=s+a;o[u]=this.mod((o[u]||0n)+n[s]*i[a])}return this.newVectorFrom(o)}divPolys(e,t){let n=e.toValues().slice(),i=t.toValues(),o=Hs(n),s=Hs(i);if(o<s)throw new Error("Cannot divide by polynomial of higher order");let a=o-s,u=new Array(a+1);for(let d=u.length-1;a>=0;a--,o--,d--){let c=this.div(n[o],i[s]);u[d]=c;for(let l=s;l>=0;l--)n[a+l]=this.mod(n[a+l]-i[l]*c)}return this.newVectorFrom(u)}evalPolyAt(e,t){let n=e.toValues();switch(e.length){case 0:return 0n;case 1:return n[0];case 2:return this.mod(n[0]+n[1]*t);case 3:return this.mod(n[0]+n[1]*t+n[2]*t*t);case 4:{let i=t*t,o=i*t;return this.mod(n[0]+n[1]*t+n[2]*i+n[3]*o)}case 5:{let i=t*t,o=i*t;return this.mod(n[0]+n[1]*t+n[2]*i+n[3]*o+n[4]*o*t)}default:{let i=0n,o=1n;for(let s=0;s<e.length;s++)i=this.mod(i+n[s]*o),o=this.mul(o,t);return i}}}evalPolyAtRoots(e,t){if(!no(t.length))throw new Error("Number of roots of unity must be a power of 2");if(e.length>t.length)throw new Error("Vectorial degree must be smaller than or equal to the number of roots of unity");let n=e.toValues();if(t.length>e.length){let o=new Array(t.length);for(let s=0;s<e.length;s++)o[s]=n[s];o.fill(0n,e.length),n=o}let i=Fn(n,t.toValues(),0,0,this);return this.newVectorFrom(i)}interpolate(e,t){if(e.length!==t.length)throw new Error("Number of x coordinates must be the same as number of y coordinates");let n=e.toValues(),i=this.newVectorFrom(Iu(n,this)),o=this.newVectorFrom([0n,1n]),s=new Array(e.length);for(let l=0;l<e.length;l++)o.values[0]=-n[l],s[l]=this.divPolys(i,o);let a=new Array(e.length);for(let l=0;l<e.length;l++)a[l]=this.evalPolyAt(s[l],n[l]);let u=this.invVectorElements(this.newVectorFrom(a)).values,d=t.toValues(),c=new Array(e.length).fill(0n);for(let l=0;l<e.length;l++){let f=this.mod(d[l]*u[l]);for(let h=0;h<e.length;h++)s[l].values[h]&&d[l]&&(c[h]=this.mod(c[h]+s[l].values[h]*f))}return this.newVectorFrom(c)}interpolateRoots(e,t){if(!no(e.length))throw new Error("Number of roots of unity must be 2^n");let n=e.toValues(),i=this.exp(BigInt(e.length),this.modulus-2n),o=new Array(e.length);o[0]=1n;for(let s=e.length-1,a=1;s>0;s--,a++)o[a]=n[s];if(t instanceof St){if(e.length!==t.length)throw new Error("Number of roots of unity must be the same as number of y coordinates");let s=t.toValues(),a=Fn(s,o,0,0,this);for(let u=0;u<a.length;u++)a[u]=this.mod(a[u]*i);return this.newVectorFrom(a)}else throw new Error("y-coordinates object is invalid")}};function Fn(r,e,t,n,i){let o=1<<t,s=e.length/o;if(s==2){let l=new Array(2);for(let f=0;f<2;f++){let h=r[n]*e[0];h+=r[n+o]*e[f*o],l[f]=i.mod(h)}return l}if(s==4){let l=new Array(4);for(let f=0;f<4;f++){let h=r[n]*e[0];h+=r[n+o]*e[f*o],h+=r[n+2*o]*e[f*2%4*o],h+=r[n+3*o]*e[f*3%4*o],l[f]=i.mod(h)}return l}let a=Fn(r,e,t+1,n,i),u=Fn(r,e,t+1,n+o,i),d=s/2,c=new Array(s);for(let l=0;l<d;l++){let f=a[l],p=u[l]*e[l*o];c[l]=i.add(f,p),c[l+d]=i.sub(f,p)}return c}function Iu(r,e){let t=new Array(r.length+1);t[t.length-1]=1n;let n=t.length-2;for(let i=0;i<r.length;i++,n--){t[n]=0n;for(let o=n;o<t.length-1;o++)t[o]=e.mod(t[o]-t[o+1]*r[i])}return t}function Hs(r){for(let e=r.length-1;e>=0;e--)if(r[e]!==0n)return e}function no(r){return r!==0&&(r&r-1)===0}var Mn=class{#e;modulus;genOrder;encodedSize;generator;constructor({modulus:e,genOrder:t,encodedSize:n,generator:i}){this.#e=new Dn(e),this.modulus=e,this.genOrder=t,this.encodedSize=n,this.generator=this.#e.exp(i.base,i.exponent)}sub(e,t){return this.#e.sub(e,t)}exp(e,t){return this.#e.exp(e,t)}evalPoly(e,t){let n=this.#e.newVectorFrom(e);return this.#e.evalPolyAt(n,t)}interpolate(e,t){let n=this.#e.newVectorFrom(e),i=this.#e.newVectorFrom(t);return this.#e.interpolateRoots(n,i).toValues()}add(e,t){return this.#e.add(e,t)}mul(e,t){return this.#e.mul(e,t)}mulPolys(e,t){let n=this.#e.newVectorFrom(e),i=this.#e.newVectorFrom(t);return this.#e.mulPolys(n,i).toValues()}randomElement(){return this.#e.rand()}encode(e){return en(e.map(t=>Jr(t,this.encodedSize)))}vecSub(e,t){let n=this.#e.newVectorFrom(e),i=this.#e.newVectorFrom(t);return this.#e.subVectorElements(n,i).toValues()}vecAdd(e,t){let n=this.#e.newVectorFrom(e),i=this.#e.newVectorFrom(t);return this.#e.addVectorElements(n,i).toValues()}decode(e){let t=this.encodedSize;if(e.length%t!==0)throw new Error(`could not decode, expected ${e.length} to be a multiple of ${t}`);return Y(e.length/t,n=>{let i=Qr(e.slice(n*t,(n+1)*t));if(i>=this.modulus)throw new Error("decoded an element that is not in the field");return i})}fillRandom(e){return Y(e,()=>this.#e.rand())}sum(e,t){return e.reduce((n,i,o)=>this.add(n,t(i,o)),0n)}additiveSecretShare(e,t){let n=Y(t-1,()=>this.fillRandom(e.length));return[...n,n.reduce((i,o)=>this.vecSub(i,o),e)]}},jn=class extends Mn{constructor(){super({modulus:2n**32n*4294967295n+1n,genOrder:2n**32n,encodedSize:8,generator:{base:7n,exponent:4294967295n}})}};var hr=class extends Mn{constructor(){super({modulus:2n**66n*4611686018427387897n+1n,genOrder:2n**66n,encodedSize:16,generator:{base:7n,exponent:4611686018427387897n}})}};var re=Ue(ze(),1),Be;(function(r){r[r.MeasurementShare=1]="MeasurementShare",r[r.ProofShare=2]="ProofShare",r[r.JointRandomness=3]="JointRandomness",r[r.ProveRandomness=4]="ProveRandomness",r[r.QueryRandomness=5]="QueryRandomness",r[r.JointRandSeed=6]="JointRandSeed",r[r.JointRandPart=7]="JointRandPart"})(Be||(Be={}));var kt=class extends Nn{xof;flp;shares;proofs;id;rounds=1;verifyKeySize;nonceSize=16;randSize;constructor(e,t,n,i,o){if(super(),this.xof=e,this.flp=t,this.shares=n,this.proofs=i,this.id=o,n<2||Math.trunc(n)!==n||n>255)throw new Error("shares must be an integer in [2, 256)");if(i<1||Math.trunc(i)!==i||i>255)throw new Error("proofs must be an integer in [1, 256)");this.verifyKeySize=e.seedSize,this.randSize=e.seedSize*(1+2*(n-1)+(t.jointRandLen===0?0:n))}isValid(e,t){return t.length===0}async shard(e,t,n){let{flp:i,proofs:o}=this;if(n.length!==this.randSize)throw new Error(`rand length was ${n.length} but must be ${this.randSize}`);let s=await this.buildHelperShares(t,n),a=i.encode(e),u=await this.buildLeaderShare(a,s,t,n),{publicShare:d,jointRands:c}=await this.jointRands([u,...s]),l=await this.proveRands(n),f=[];for(let p=0;p<o;p++){let y=Tt(i.jointRandLen,p,c),_=Tt(i.proveRandLen,p,l);f.push(...i.prove(a,_,y))}return{inputShares:this.addProof(f,u,s).map(({jointRandPart:p,...y})=>y),publicShare:d}}async prepareInit(e,t,n,i,{jointRandParts:o},{blind:s,measurementShare:a,proofsShare:u}){let{xof:d,flp:c,field:l,shares:f,proofs:h}=this,{jointRandLen:p}=c,y=c.truncate(a),_=await this.pseudorandom(c.queryRandLen*h,Be.QueryRandomness,e,re.Buffer.concat([re.Buffer.of(h),i])),x,m,g;if(this.useJointRand()){let C=l.encode(a);g=await this.deriveSeed(s,Be.JointRandPart,[Uint8Array.of(t),i,C]),o[t]=g,m=await this.deriveSeed(re.Buffer.alloc(d.seedSize),Be.JointRandSeed,o),x=await this.pseudorandom(p*h,Be.JointRandomness,m,h)}else x=[],g=re.Buffer.alloc(0),m=re.Buffer.alloc(0);let k=[];for(let C=0;C<h;C++){let R=Tt(c.jointRandLen,C,x),z=Tt(c.queryRandLen,C,_),A=Tt(c.proofLen,C,u);k.push(...c.query(a,A,z,R,f))}return{preparationShare:{verifiersShare:k,jointRandomnessPart:g},preparationState:{correctedJointRandSeed:m,outputShare:y}}}prepareNext(e,t){let{jointRand:n}=t,{outputShare:i,correctedJointRandSeed:o}=e;if(!n.equals(o))throw new Error("Verify error");return{outputShare:i}}async unshardPreparationShares(e,t){let{flp:n,field:i,xof:o,proofs:s}=this,{verifiers:a,jointRandParts:u}=t.reduce(({verifiers:d,jointRandParts:c},l)=>{let{jointRandomnessPart:f,verifiersShare:h}=l;return{verifiers:i.vecAdd(d,h),jointRandParts:[...c,f]}},{verifiers:Ge(n.verifierLen*s,0n),jointRandParts:[]});for(let d=0;d<s;d++){let c=Tt(n.verifierLen,d,a);if(!n.decide(c))throw new Error("Verify error")}return this.useJointRand()?{jointRand:await this.deriveSeed(re.Buffer.alloc(o.seedSize),Be.JointRandSeed,u)}:{jointRand:re.Buffer.alloc(0)}}aggregate(e,t){let{field:n,flp:i}=this;return t.reduce((o,s)=>n.vecAdd(o,s),Ge(i.outputLen,0n))}unshard(e,t,n){let{field:i,flp:o}=this;return o.decode(t.reduce((s,a)=>i.vecAdd(s,a),Ge(o.outputLen,0n)),n)}encodeInputShare({wireMeasurementShare:e,wireProofShare:t,blind:n}){return re.Buffer.concat([e,t,n])}encodePublicShare({jointRandParts:e}){return re.Buffer.concat(e)}encodeAggregatorShare(e){return re.Buffer.from(this.field.encode(e))}encodePreparationShare({jointRandomnessPart:e,verifiersShare:t}){return re.Buffer.concat([this.field.encode(t),e])}encodePreparationMessage({jointRand:e}){return e}encodeAggregationParameter(e){return re.Buffer.alloc(0)}encodeTestVectorOutputShare(e){return e.map(t=>re.Buffer.from(Jr(t,this.field.encodedSize)).toString("hex"))}async deriveSeed(e,t,n){return re.Buffer.from(await this.xof.deriveSeed(e,this.domainSeparationTag(t),en(n)))}async buildLeaderShare(e,t,n,i){let{xof:o,field:s}=this,a=t.reduce((d,c)=>s.vecSub(d,c.measurementShare),e),u=re.Buffer.from(this.field.encode(a));if(this.useJointRand()){let d=i.subarray(t.length*3*o.seedSize,(t.length*3+1)*o.seedSize),c=await this.deriveSeed(d,Be.JointRandPart,[Uint8Array.of(0),n,s.encode(a)]);return{blind:d,measurementShare:a,wireMeasurementShare:u,jointRandPart:c}}else return{blind:re.Buffer.alloc(0),measurementShare:a,wireMeasurementShare:u,jointRandPart:re.Buffer.alloc(0)}}addProof(e,t,n){let{field:i}=this,o=n.reduce((a,u)=>i.vecSub(a,u.proofsShare),e),s=re.Buffer.from(i.encode(o));return[{...t,wireProofShare:s,proofsShare:o},...n]}useJointRand(){return this.flp.jointRandLen!==0}buildHelperShares(e,t){let{flp:n,xof:i,field:o,proofs:s}=this,{proofLen:a,measurementLen:u}=n;return Promise.all(Y(this.shares-1,async d=>{let c,l,f,{seedSize:h}=i;this.useJointRand()?[c,l,f]=Y(3,m=>t.subarray(h*(d*3+m),h*(d*3+m+1))):([c,l]=Y(2,m=>t.subarray(h*(d*2+m),h*(d*2+m+1))),f=re.Buffer.alloc(0));let p=re.Buffer.of(d+1),y=await this.pseudorandom(u,Be.MeasurementShare,c,p),_=await this.pseudorandom(a*s,Be.ProofShare,l,re.Buffer.from([s,d+1])),x=this.useJointRand()?await this.deriveSeed(f,Be.JointRandPart,[p,e,o.encode(y)]):re.Buffer.alloc(0);return{measurementShare:y,blind:f,wireMeasurementShare:c,wireProofShare:l,proofsShare:_,jointRandPart:x}}))}pseudorandom(e,t,n,i){let{xof:o,field:s}=this;return o.expandIntoVec(s,n,this.domainSeparationTag(t),typeof i=="number"?re.Buffer.of(i):i||re.Buffer.alloc(0),e)}get field(){return this.flp.field}proveRands(e){let{shares:t,flp:n,xof:i,proofs:o}=this,{seedSize:s}=i,a=this.useJointRand()?(t-1)*3+1:(t-1)*2;return this.pseudorandom(n.proveRandLen*o,Be.ProveRandomness,e.subarray(a*s,(a+1)*s),o)}async jointRands(e){if(!this.useJointRand())return{jointRands:[],publicShare:{jointRandParts:[]}};let{flp:t,xof:n,proofs:i}=this,o=e.map(({jointRandPart:u})=>u),s=await this.deriveSeed(re.Buffer.alloc(n.seedSize),Be.JointRandSeed,o);return{jointRands:await this.pseudorandom(t.jointRandLen*i,Be.JointRandomness,s,i),publicShare:{jointRandParts:o}}}};var Nr=class{static deriveSeed(e,t,n){return new this(e,t,n).next(this.seedSize)}async nextVec(e,t){let n=Uo(e.modulus)-1n,i=new Array(t);for(let o=0;o<t;o++)do i[o]=Qr(await this.next(e.encodedSize))&n;while(i[o]>=e.modulus);return i}static async expandIntoVec(e,t,n,i,o){return new this(t,n,i).nextVec(e,o)}};var zs=(r,e)=>vn((t={})=>{let n=t.D===void 0?31:t.D;if(!Number.isSafeInteger(n)||n<1||n>127)throw new Error(`turboshake: wrong domain separation byte: ${n}, should be 0x01..0x7f`);return new ur(r,n,t.dkLen===void 0?e:t.dkLen,!0,12)}),Ns=zs(168,256/8),Op=zs(136,512/8);var Kp=new Uint8Array([]);var dr=class io extends Nr{static seedSize=16;#e;constructor(e,t,n){if(super(),e.length!==io.seedSize)throw new Error(`XofTurboShake128 seed length must be exactly ${io.seedSize}`);if(t.length>255)throw new Error("dst length must be one byte");this.#e=Ns.create({D:1}).update(Uint8Array.of(t.length)).update(t).update(e).update(n)}next(e){return Promise.resolve(this.#e.xof(e))}};var Ke=class{ensureArity(e){if(e.length!==this.arity)throw new Error(`expected gadget input length (${e.length}) to equal arity (${this.arity}), but it did not`)}ensurePolyArity(e){if(e.length!==this.arity||e.find(t=>t.length!==e[0].length))throw new Error("expected gadget input to equal arity, but it did not")}};var Ie=class{get proveRandLen(){return this.gadgets.reduce((e,t)=>e+t.arity,0)}get queryRandLen(){return this.gadgets.length}get proofLen(){return this.gadgets.reduce((e,t,n)=>{let i=this.gadgetCalls[n],o=ft(i+1);return e+t.arity+t.degree*(o-1)+1},0)}get verifierLen(){return this.gadgets.reduce((e,t)=>e+t.arity+1,1)}ensureValidEval(e,t){if(e.length!=this.measurementLen)throw new Error(`expected measurement length to be ${this.measurementLen} but it was ${e.length}`);if(t.length!=this.jointRandLen)throw new Error(`expected joint rand length to be ${this.jointRandLen} but it was ${t.length}`)}};var Vn=class extends Ke{wire;gadget;gadgetPoly;alpha;callCount=0;constructor(e,t,n,i,o){super(),this.gadget=i,this.gadgetPoly=n;let s=ft(o+1);this.wire=Y(this.arity,a=>[t[a],...Ge(s-1,0n)]),this.alpha=e.exp(e.generator,e.genOrder/BigInt(s))}eval(e,t){return this.callCount+=1,this.wire.forEach((n,i)=>{n[this.callCount]=t[i]}),e.evalPoly(this.gadgetPoly,e.exp(this.alpha,BigInt(this.callCount)))}evalPoly(e,t){throw new Error("evalPoly is not implemented for QueryGadget")}get arity(){return this.gadget.arity}get degree(){return this.gadget.degree}};var $n=class extends Ie{gadgets;circuit;get gadgetCalls(){return this.circuit.gadgetCalls}get measurementLen(){return this.circuit.measurementLen}get outputLen(){return this.circuit.outputLen}get field(){return this.circuit.field}get jointRandLen(){return this.circuit.jointRandLen}eval(e,t,n){return this.circuit.eval.call(this,e,t,n)}encode(e){return this.circuit.encode.call(this,e)}truncate(e){return this.circuit.truncate.call(this,e)}decode(e,t){return this.circuit.decode(e,t)}constructor(e,t){super();for(let i in e)i in this||(this[i]=e[i]);this.circuit=e;let n=0;if(this.gadgets=e.gadgets.map((i,o)=>{let s=e.gadgetCalls[o],a=ft(s+1),u=i.degree*(a-1)+1,d=t.slice(n,n+=i.arity),c=t.slice(n,n+=u);return new Vn(e.field,d,c,i,s)}),t.length!==this.proofLen)throw new Error(`expected proof length to be ${this.proofLen} but it was ${t.length}`);if(n!==t.length)throw new Error(`did not use all of proof (used ${n}/${t.length})`)}};var qn=class extends Ke{gadget;wire;callCount=0;constructor(e,t,n){super(),this.gadget=t;let i=ft(1+n);this.wire=Y(this.arity,o=>[e[o],...Ge(i-1,0n)])}eval(e,t){return this.callCount+=1,this.wire.forEach((n,i)=>{n[this.callCount]=t[i]}),this.gadget.eval(e,t)}evalPoly(e,t){return this.gadget.evalPoly(e,t)}get arity(){return this.gadget.arity}get degree(){return this.gadget.degree}};var Gn=class extends Ie{gadgets;circuit;get gadgetCalls(){return this.circuit.gadgetCalls}get measurementLen(){return this.circuit.measurementLen}get outputLen(){return this.circuit.outputLen}get field(){return this.circuit.field}get jointRandLen(){return this.circuit.jointRandLen}eval(e,t,n){return this.circuit.eval.call(this,e,t,n)}encode(e){return this.circuit.encode.call(this,e)}truncate(e){return this.circuit.truncate.call(this,e)}decode(e,t){return this.circuit.decode(e,t)}constructor(e,t){super();for(let i in e)i in this||(this[i]=e[i]);if(this.circuit=e,t.length!=e.proveRandLen)throw new Error("prove rand was not the correct length");let n=0;if(this.gadgets=e.gadgets.map((i,o)=>new qn(t.slice(n,n+=i.arity),i,this.gadgetCalls[o])),t.length!==n)throw new Error("did not use all of the proof randomness")}};var Ft=class{circuit;constructor(e){this.circuit=e}get jointRandLen(){return this.circuit.jointRandLen}get proveRandLen(){return this.circuit.proveRandLen}get queryRandLen(){return this.circuit.queryRandLen}get measurementLen(){return this.circuit.measurementLen}get outputLen(){return this.circuit.outputLen}get proofLen(){return this.circuit.proofLen}get verifierLen(){return this.circuit.verifierLen}get field(){return this.circuit.field}prove(e,t,n){let i=new Gn(this.circuit,t),{field:o}=this;return i.eval(e,n,1),i.gadgets.flatMap(s=>{let a=s.wire[0].length,u=o.exp(this.field.generator,this.field.genOrder/BigInt(a)),d=Y(a,f=>o.exp(u,BigInt(f))),c=Y(s.arity,f=>this.field.interpolate(d,s.wire[f])),l=s.evalPoly(o,c);return s.wire.map(f=>f[0]).concat(l)})}encode(e){return this.circuit.encode(e)}truncate(e){return this.circuit.truncate(e)}query(e,t,n,i,o){let s=new $n(this.circuit,t),a=s.eval(e,i,o),{field:u}=this;if(n.length!==this.circuit.queryRandLen)throw new Error(`mismatched query rand length. expected ${this.circuit.queryRandLen} but got ${n.length}`);return s.gadgets.reduce((d,c,l)=>{let f=n[l],h=c.wire[0].length;if(u.exp(f,BigInt(h))==1n)throw new Error("Degenerate point would leak gadget output to the verifier");let p=Y(h,y=>u.exp(c.alpha,BigInt(y)));return[...d,...c.wire.map(y=>u.evalPoly(u.interpolate(p,y),f)),u.evalPoly(c.gadgetPoly,f)]},[a])}decide(e){if(e.length!==this.circuit.verifierLen)throw new Error(`expected verifier of length ${this.circuit.verifierLen} but got ${e.length}`);if(e[0]!==0n)return!1;let t=1;for(let n of this.circuit.gadgets){let i=e.slice(t,t+=n.arity),o=e[t];if(n.eval(this.field,i)!=o)return!1;t+=1}if(t!=this.circuit.verifierLen)throw new Error(`unused verifier (${t} / ${this.circuit.verifierLen})`);return!0}decode(e,t){return this.circuit.decode(e,t)}};var Bt=class extends Ke{arity=2;degree=2;eval(e,t){return this.ensureArity(t),e.mul(t[0],t[1])}evalPoly(e,t){return this.ensurePolyArity(t),e.mulPolys(t[0],t[1])}};var Xn=class extends Ie{field;gadgets=[new Bt];gadgetCalls=[1];measurementLen=1;jointRandLen=0;outputLen=1;constructor(e){super(),this.field=e}eval(e,t,n){this.ensureValidEval(e,t);let{field:i}=this,[o]=e,[s]=this.gadgets;return i.sub(s.eval(i,[o,o]),o)}encode(e){if(typeof e!="boolean")throw new Error("expected count measurement to be a boolean");return[e?1n:0n]}truncate(e){if(e.length!==1)throw new Error("expected Count input to be exactly one boolean");return e}decode(e,t){return Number(e[0])}};var pr=class extends Ke{subcircuit;count;arity;degree;constructor(e,t){super(),this.subcircuit=e,this.count=t,this.arity=e.arity*t,this.degree=e.degree}eval(e,t){this.ensureArity(t);let{arity:n}=this.subcircuit;return Y(this.count,i=>this.subcircuit.eval(e,t.slice(i*n,(i+1)*n))).reduce((i,o)=>e.add(i,o))}evalPoly(e,t){this.ensurePolyArity(t);let{arity:n}=this.subcircuit;return Au(Y(this.count,i=>this.subcircuit.evalPoly(e,t.slice(i*n,(i+1)*n))).reduce((i,o)=>e.vecAdd(i,o)))}};function Au(r){let e=r.length-1;for(;e>=0&&r[e]==0n;)e--;return r.slice(0,e+1)}var Zn=class extends Ie{field;gadgets;jointRandLen=2;gadgetCalls;measurementLen;outputLen;length;chunkLength;constructor(e,t,n){if(super(),this.field=e,typeof t!="number"||Math.trunc(t)!==t||t<=0)throw new Error("invalid histogram length");if(typeof n!="number"||Math.trunc(n)!==n||n<=0)throw new Error("invalid histogram chunk length");this.gadgets=[new pr(new Bt,n)],this.length=t,this.chunkLength=n,this.gadgetCalls=[Math.floor((t+n-1)/n)],this.measurementLen=t,this.outputLen=t}eval(e,t,n){this.ensureValidEval(e,t);let[i,o]=t,[s]=this.gadgets,[a]=this.gadgetCalls,{field:u}=this,{chunkLength:d}=this,c=u.exp(BigInt(n),-1n),l=Y(a,h=>Y(d,p=>{let y=h*d+p,_=e[y]||0n;return[u.mul(u.exp(i,BigInt(y+1)),_),u.sub(_,c)]}).flat()).reduce((h,p)=>u.add(h,s.eval(u,p)),0n),f=e.reduce((h,p)=>u.add(h,p),u.mul(c,-1n));return u.add(u.mul(o,l),u.mul(u.exp(o,2n),f))}encode(e){if(typeof e=="number"&&e===Math.trunc(e)&&e>=0&&e<this.length)return Y(this.length,t=>t===e?1n:0n);throw new Error(`Measurement ${e} must an integer in [0, ${this.length}).

Note: As of VDAF-07, Histogram now takes the bucket *index*, not the raw value.
`)}truncate(e){return e}decode(e,t){return e.map(Number)}};function Ds(r){let e=r.length-1;for(;e>=0&&r[e]==0n;)e--;return r.slice(0,e+1)}var Wn=class extends Ke{arity=1;polynomial;degree;constructor(e){if(super(),e=Ds(e),e.length===0)throw new Error("invalid polynomial: zero length");this.polynomial=e.map(BigInt),this.degree=e.length-1}eval(e,t){return this.ensureArity(t),e.evalPoly(this.polynomial,t[0])}evalPoly(e,t){this.ensurePolyArity(t);let n=Ge(this.degree*(t[0].length-1)+1,0n);n[0]=this.polynomial[0];let i=t[0];for(let o=1;o<this.polynomial.length;o++){for(let s=0;s<i.length;s++)n[s]=e.add(n[s],e.mul(this.polynomial[o],i[s]));i=e.mulPolys(i,t[0])}return Ds(n)}};var Yn=class extends Ie{field;gadgets=[new Wn([0n,-1n,1n])];gadgetCalls;measurementLen;jointRandLen=1;outputLen=1;constructor(e,t){if(super(),this.field=e,2n**BigInt(t)>=this.field.modulus)throw new Error("bit size exceeds field modulus");this.gadgetCalls=[t],this.measurementLen=t}eval(e,t,n){this.ensureValidEval(e,t);let[i]=this.gadgets,o=this.field,s=t[0];return o.sum(e,(a,u)=>o.mul(o.exp(s,BigInt(u+1)),i.eval(o,[a])))}encode(e){if(typeof e=="number"&&e!==Math.trunc(e))throw new Error(`measurement ${e} was not an integer in [0, ${2**this.measurementLen})`);let t=BigInt(e);if(t<0n||t>=BigInt(2**this.measurementLen))throw new Error(`measurement ${t} was not an integer in [0, ${2**this.measurementLen})`);return Y(this.measurementLen,n=>t>>BigInt(n)&1n)}truncate(e){let t=this.field;return[t.sum(e,(n,i)=>t.mul(t.exp(2n,BigInt(i)),n))]}decode(e,t){return e[0]}};var Jn=class extends Ie{field;gadgets;jointRandLen=1;gadgetCalls;measurementLen;outputLen;max;bits;length;chunkLength;constructor(e,t,n,i){if(super(),this.field=e,typeof n!="number"||Math.trunc(n)!==n||n<=0)throw new Error("invalid bits");let o=Math.pow(2,n);if(o>=this.field.modulus)throw new Error("bit size exceeds field modulus");if(typeof t!="number"||Math.trunc(t)!==t||t<=0)throw new Error("invalid length");if(typeof i!="number"||Math.trunc(i)!==i||i<=0)throw new Error("invalid chunk length");this.gadgets=[new pr(new Bt,i)],this.length=t,this.chunkLength=i,this.gadgetCalls=[Math.floor((t*n+i-1)/i)],this.measurementLen=t*n,this.outputLen=t,this.max=o,this.bits=n}eval(e,t,n){this.ensureValidEval(e,t);let[i]=t,[o]=this.gadgets,[s]=this.gadgetCalls,{field:a}=this,{chunkLength:u}=this,d=a.exp(BigInt(n),-1n);return Y(s,c=>Y(u,l=>{let f=c*u+l,h=e[f]||0n;return[a.mul(a.exp(i,BigInt(f+1)),h),a.sub(h,d)]}).flat()).reduce((c,l)=>a.add(c,o.eval(a,l)),0n)}encode(e){let{bits:t,max:n,length:i}=this;if(e.length!==i)throw new Error(`length must be ${i} but was ${e.length}`);return e.flatMap(o=>{if(typeof o!="number"||o!==Math.trunc(o)||o<0||o>=this.max)throw new Error(`Measurement ${o} must a number in [0, ${n})`);return Y(t,s=>BigInt(o>>s&1))})}truncate(e){let{field:t,length:n,bits:i}=this;return Y(n,o=>Y(i,s=>this.field.mul(BigInt(1<<s),e[o*i+s])).reduce((s,a)=>t.add(s,a)))}decode(e,t){return e.map(Number)}};var Dr=class extends kt{constructor({shares:e}){super(dr,new Ft(new Xn(new jn)),e,1,0)}},Fr=class extends kt{bits;constructor({shares:e,bits:t}){super(dr,new Ft(new Yn(new hr,t)),e,1,1),this.bits=t}},Mr=class extends kt{chunkLength;length;constructor({shares:e,length:t,chunkLength:n}){super(dr,new Ft(new Zn(new hr,t,n)),e,1,3),this.chunkLength=n,this.length=t}},jr=class extends kt{chunkLength;length;bits;constructor({shares:e,length:t,chunkLength:n,bits:i}){super(dr,new Ft(new Jn(new hr,t,i,n)),e,1,2),this.chunkLength=n,this.length=t,this.bits=i}};function Pu(r,e=2){switch(r.type){case"count":return new Dr({...r,shares:e});case"histogram":return new Mr({...r,shares:e});case"sum":return new Fr({...r,shares:e});case"sumVec":return new jr({...r,shares:e})}}var Mt=class{#e;#n;#t;#r;#s;#a=[];#i=globalThis.fetch.bind(globalThis);#o=!1;static protocolVersion=on;constructor(e){if(this.#e=Pu(e),this.#n=Lu(e.id),this.#t=Hr.leader(e.leader),this.#r=Hr.helper(e.helper),typeof e.timePrecisionSeconds!="number")throw new Error("timePrecisionSeconds must be a number");this.#s=e.timePrecisionSeconds}get aggregators(){return[this.#t,this.#r]}get vdaf(){return this.#e}set fetch(e){this.#i=e}get id(){return this.#n}async generateReport(e,t){await this.fetchKeyConfiguration();let n=tn.random(),i=Fs.Buffer.from(Xe(this.#e.randSize)),{publicShare:o,inputShares:[s,a]}=await this.#e.shardEncoded(e,n.encode(),i),u=Tu(this.#s,t?.timestamp),d=new sn(n,u),c=new cn(this.id,d,o),l=await this.#t.seal(new xr(this.#a,s),c),f=await this.#r.seal(new xr(this.#a,a),c);return new an(d,o,l,f)}async sendReport(e){let t=e.encode(),n=this.#t,i=this.#n.toString(),o=await this.#i(new URL(`tasks/${i}/reports`,n.url).toString(),{method:"PUT",headers:{"Content-Type":br.REPORT},body:t});if(!o.ok)throw await Dt.fromResponse(o,"report upload failed")}hasKeyConfiguration(){return!!this.#t.hpkeConfigList&&!!this.#r.hpkeConfigList}async sendMeasurement(e,t){let n=await this.generateReport(e,t);try{await this.sendReport(n),this.#o=!1}catch(i){if(i instanceof Dt&&i.shortType==="outdatedConfig"&&!this.#o)this.invalidateHpkeConfig(),await this.sendMeasurement(e);else throw i}}invalidateHpkeConfig(){this.#o=!0,delete this.#t.hpkeConfigList,delete this.#r.hpkeConfigList}async fetchKeyConfiguration(){this.hasKeyConfiguration()||await Promise.all(this.aggregators.map(async e=>{let t=new URL("hpke_config",e.url);t.searchParams.append("task_id",this.#n.toString());let n=await this.#i(t.toString(),{headers:{Accept:br.HPKE_CONFIG_LIST}});if(!n.ok)throw await Dt.fromResponse(n,`fetchKeyConfiguration received a ${n.status} response, aborting`);let i=await n.blob();if(i.type!==br.HPKE_CONFIG_LIST)throw new Error(`expected ${br.HPKE_CONFIG_LIST} content-type header, aborting`);e.hpkeConfigList=Hn.parse(await i.arrayBuffer()),e.hpkeConfigList.selectConfig()}))}};function Lu(r){return r instanceof et?r:new et(r)}function Tu(r,e){let t=(e?e.getTime():Date.now())/1e3;return Math.floor(t/r)*r}var oo=class{DEBUG;constructor(){this.DEBUG=!this.isProduction()}isProduction(){return typeof window>"u"||window.location.protocol==="file:"?!1:window.location.hostname!=="localhost"&&window.location.hostname!=="127.0.0.1"&&!window.location.hostname.startsWith("192.168.")&&!window.location.hostname.includes("dev")&&!window.location.hostname.includes("staging")}logWithLevel(e,...t){this.DEBUG&&console[e](...t)}log(...e){this.logWithLevel("log",...e)}warn(...e){this.logWithLevel("warn",...e)}error(...e){this.logWithLevel("error",...e)}},Z=new oo;var ao="https://api.tinfoil.sh";function so(r){return typeof r=="object"&&r!==null&&typeof r.taskId=="string"&&typeof r.type=="string"&&typeof r.timePrecision=="number"&&typeof r.vdafConfig=="object"&&r.vdafConfig!==null&&(r.vdafConfig.sumBitLength==null||typeof r.vdafConfig.sumBitLength=="number")&&(r.vdafConfig.numBuckets==null||typeof r.vdafConfig.numBuckets=="number")&&(r.vdafConfig.proofChunkSize==null||typeof r.vdafConfig.proofChunkSize=="number")}function Uu(r,e){switch(e){case"os":case"browser":case"device":return typeof r=="object"&&Array.isArray(r.labels);case"session":return typeof r=="object"&&typeof r.sessionInterval=="number";case"country":return typeof r=="object"&&typeof r.countryIndex=="number";case"visit":return!0;case"engaged":return!0;default:return!1}}function Cu(r,e){return typeof r!="object"||r===null?!1:["os","browser","device","session","visit","country","engaged"].includes(e)?Uu(r.metricsInfo,e)&&so(r.aggregationConfig):so(r.aggregationConfig)}function Ou(r){return typeof r=="object"&&r!==null&&so(r.aggregationConfig)}function Ku(r){if(typeof r!="object"||r===null||!r.leaderUrl||!r.helperUrl||typeof r.metrics!="object"||r.metrics===null)throw new Error("Invalid configuration format");let e={os:null,browser:null,device:null,session:null,visit:null,country:null};for(let[t,n]of Object.entries(r.metrics)){if(n===null){e[t]=null;continue}Cu(n,t)||Ou(n)?e[t]=n:Z.warn(`Invalid metric configuration for ${t}`)}return{leaderUrl:r.leaderUrl,helperUrl:r.helperUrl,metrics:e}}async function Ms(r,e=ao){try{let t=new URL(`domains/${r}/config`,e);Z.log(`Fetching global config from URL: ${t}`);let n=await fetch(t.toString());if(!n.ok)return Z.error(`HTTP error! status: ${n.status}`),null;let i=await n.json();return Ku(i)}catch(t){return Z.error("Error fetching config:",t),null}}var Vs=Ue(js(),1),ei=class{config;globalConfig=null;tasks=new Map;constructor(e){this.config={configEndpoint:ao,debug:!1,...e}}async init(){await this.initTracking()}async initTracking(){if(!await this.refreshConfig()){Z.error("Tinfoil: Failed to refresh config");return}this.startSessionTracking(),this.setupCustomEventTracking(),this.setupBounceTracking(),(await Promise.allSettled([this.trackPageVisit(),this.trackCountry(),this.trackTelemetry()])).forEach((n,i)=>{if(n.status==="rejected"){let o=["trackPageVisit","trackCountry","trackTelemetry"][i];Z.error(`Tinfoil: ${o} failed:`,n.reason)}})}async refreshConfig(){if(this.globalConfig!==null)return!0;try{let e=await Ms(this.config.domain,this.config.configEndpoint);return e?(this.globalConfig=e,Z.log("Tinfoil: Global config fetched successfully:",e),!0):(Z.error("Failed to fetch global config"),!1)}catch(e){return Z.error("Error fetching global config:",e),!1}}async getTask(e){let t=this.tasks.get(e);if(t)return t;if(!this.globalConfig&&!await this.refreshConfig())return null;let n=this.globalConfig?.metrics[e];if(!n)return Z.error(`Tinfoil: No configuration found for event: ${e}`),null;let i=await this.createTask(n);return i&&this.tasks.set(e,i),i}async createTask(e){let{taskId:t,timePrecision:n,type:i,vdafConfig:o}=e.aggregationConfig,{leaderUrl:s,helperUrl:a}=this.globalConfig;if(i==="count")return new Mt({type:"count",id:t,leader:s,helper:a,timePrecisionSeconds:n});if(i==="histogram"){if(!o)throw new Error("Invalid histogram configuration: vdafConfig is undefined");let{numBuckets:u,proofChunkSize:d}=o;if(u==null||d==null)throw new Error("Invalid histogram configuration: numBuckets or proofChunkSize is null or undefined");return new Mt({type:"histogram",id:t,leader:s,helper:a,timePrecisionSeconds:n,length:u,chunkLength:d})}return Z.error(`Unsupported event type: ${i}`),null}async trackEvent(e,t){let n=await this.getTask(e);if(!n){Z.error(`Tinfoil: No configuration found for event: ${e}`);return}Z.log(`Tinfoil: Tracking event: ${e} with value: ${t}`);try{await n.sendMeasurement(t!==void 0?t:!0),Z.log(`Tinfoil: Event '${e}' tracked successfully`)}catch(i){Z.error(`Tinfoil: Error tracking event '${e}':`,i)}}async trackPageVisit(){if(typeof window>"u"||!window.sessionStorage||sessionStorage.getItem("tinfoil-page-visit")||!await this.refreshConfig()||!this.globalConfig?.metrics.visit)return;sessionStorage.setItem("tinfoil-page-visit","true"),Z.log("Tinfoil: Tracking page visit");let t=!localStorage.getItem("tinfoil-unique-visit");t?(localStorage.setItem("tinfoil-unique-visit","true"),Z.log("Tinfoil: New unique visitor")):Z.log("Tinfoil: Returning visitor"),await this.trackEvent("visit",t)}async trackCountry(){if(typeof window>"u"||!window.sessionStorage||sessionStorage.getItem("did-submit-country")||!await this.refreshConfig())return;let t=this.globalConfig?.metrics.country;if(!t||!t.metricsInfo)return;sessionStorage.setItem("did-submit-country","true"),Z.log("Tinfoil: Tracking country");let n=t.metricsInfo.countryIndex;await this.trackEvent("country",n)}async trackTelemetry(){if(typeof window>"u"||!await this.refreshConfig())return;let t=window.navigator.userAgent,n=new Vs.UAParser(t),i=n.getBrowser().name,o=n.getOS().name,s=n.getDevice().type||"Desktop";await Promise.allSettled([this.sendBrowserType(i),this.sendOSType(o),this.sendDeviceType(s)])}async sendOSType(e){try{if(!this.globalConfig?.metrics.os||sessionStorage.getItem("did-submit-os-type"))return;if(!e){Z.log("Tinfoil: OS type is undefined");return}sessionStorage.setItem("did-submit-os-type","true"),Z.log("Tinfoil: Tracking OS type");let n=this.globalConfig.metrics.os.metricsInfo?.labels;if(!n)return;let i=n.findIndex(o=>e.toLowerCase().includes(o.toLowerCase()));i===-1&&(i=n.length-1),Z.log("Tinfoil: OS type is",n[i]),await this.trackEvent("os",i)}catch(t){Z.error("Error in sendOSType:",t)}}async sendBrowserType(e){try{if(!this.globalConfig?.metrics.browser||sessionStorage.getItem("did-submit-browser-type"))return;if(!e){Z.log("Tinfoil: Browser type is undefined");return}sessionStorage.setItem("did-submit-browser-type","true"),Z.log("Tinfoil: Tracking browser type");let n=this.globalConfig.metrics.browser.metricsInfo?.labels;if(!n)return;let i=n.findIndex(o=>e.toLowerCase().includes(o.toLowerCase()));i===-1&&(i=n.length-1),Z.log("Tinfoil: Browser type is",n[i]),await this.trackEvent("browser",i)}catch(t){Z.error("Error in sendBrowserType:",t)}}async sendDeviceType(e){try{if(!this.globalConfig?.metrics.device||sessionStorage.getItem("did-submit-device-type"))return;if(!e){Z.log("Tinfoil: Device type is undefined");return}sessionStorage.setItem("did-submit-device-type","true"),Z.log("Tinfoil: Tracking device type");let n=this.globalConfig.metrics.device.metricsInfo?.labels;if(!n)return;let i=n.findIndex(o=>e.toLowerCase().includes(o.toLowerCase()));i===-1&&(i=n.length-1),Z.log("Tinfoil: Device type is",n[i]),await this.trackEvent("device",i)}catch(t){Z.error("Error in sendDeviceType:",t)}}startSessionTracking(){if(typeof window>"u")return;let e=Date.now(),t=async()=>{let n=Date.now()-e;if(this.globalConfig?.metrics.session){let i=this.globalConfig.metrics.session;if(!i.metricsInfo)return;let{sessionInterval:o}=i.metricsInfo,s=i.aggregationConfig.vdafConfig;if(!s)return;let a=s.numBuckets;if(!a)return;let u=this.bucketTime(n,o,a);Z.log(`Tinfoil: Session duration bucketed as ${u}`),await this.trackEvent("session",u)}};document.addEventListener("visibilitychange",async()=>{document.visibilityState==="hidden"?await t():e=Date.now()}),window.addEventListener("beforeunload",()=>{t().catch(console.error)})}bucketTime(e,t,n){let i=t*1e3;return e>n*i?n-1:Math.floor(e/i)}setupCustomEventTracking(){typeof document>"u"||(document.addEventListener("click",e=>{let t=e.target;for(;t&&t!==document.body;){let n=Array.from(t.classList).find(i=>i.startsWith("tinfoil-event-name="));if(n){let i=n.split("=");if(i.length>1){let o=i[1].replace(/\+/g," ");this.trackEvent(o)}break}t=t.parentElement}}),document.addEventListener("submit",e=>{let t=e.target,n=Array.from(t.classList).find(i=>i.startsWith("tinfoil-event-name="));if(n){let i=n.split("=");if(i.length>1){let o=i[1].replace(/\+/g," ");this.trackEvent(o)}}}))}setupBounceTracking(){if(typeof document>"u")return;let e=["click","keypress"],t=()=>{e.forEach(n=>{document.removeEventListener(n,t)}),Z.log("Tinfoil: User interaction detected"),sessionStorage.getItem("tinfoil-engaged")||(sessionStorage.setItem("tinfoil-engaged","true"),this.trackEvent("engaged"))};e.forEach(n=>{document.addEventListener(n,t)})}};async function Ru(){let e=document.currentScript?.dataset.param;if(!e){console.error("Tinfoil: No domain provided");return}let t=new ei({domain:e});try{await t.init(),window.TinfoilAnalytics=t}catch(n){console.error("Tinfoil: Failed to initialize",n)}}Ru().catch(console.error);})();
/*! Bundled license information:

ieee754/index.js:
  (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)

buffer/index.js:
  (*!
   * The buffer module from node.js, for the browser.
   *
   * @author   Feross Aboukhadijeh <https://feross.org>
   * @license  MIT
   *)

@noble/ciphers/esm/utils.js:
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)

@noble/hashes/esm/utils.js:
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/abstract/utils.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/abstract/modular.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/abstract/curve.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/abstract/edwards.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/abstract/montgomery.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/ed25519.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)

@noble/curves/esm/ed448.js:
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/
//# sourceMappingURL=browser.js.map
