@solarpunkltd/swarm-chat-js 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- (function(ce,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("@ethersphere/bee-js")):typeof define=="function"&&define.amd?define(["exports","@ethersphere/bee-js"],S):(ce=typeof globalThis<"u"?globalThis:ce||self,S(ce.SwarmChatJs={},ce.BeeJs))})(this,function(ce,S){"use strict";const P=[];for(let a=0;a<256;++a)P.push((a+256).toString(16).slice(1));function pi(a,n=0){return(P[a[n+0]]+P[a[n+1]]+P[a[n+2]]+P[a[n+3]]+"-"+P[a[n+4]]+P[a[n+5]]+"-"+P[a[n+6]]+P[a[n+7]]+"-"+P[a[n+8]]+P[a[n+9]]+"-"+P[a[n+10]]+P[a[n+11]]+P[a[n+12]]+P[a[n+13]]+P[a[n+14]]+P[a[n+15]]).toLowerCase()}let Vt;const gi=new Uint8Array(16);function yi(){if(!Vt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Vt=crypto.getRandomValues.bind(crypto)}return Vt(gi)}const Sn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function vi(a,n,i){if(Sn.randomUUID&&!n&&!a)return Sn.randomUUID();a=a||{};const c=a.random||(a.rng||yi)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,pi(c)}function wi(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var On={};(function(a){var n;Object.defineProperty(a,"__esModule",{value:!0}),a.Vector=a.Cache=a.Assertions=a.Strings=a.Types=a.Objects=a.Dates=a.Promises=a.Numbers=a.System=a.Arrays=a.Random=a.Elliptic=a.Binary=a.AsyncQueue=a.PubSubChannel=a.FixedPointNumber=a.MerkleTree=a.Chunk=a.Uint8ArrayWriter=a.Uint8ArrayReader=a.AsyncLazy=a.Lazy=a.Optional=void 0;async function i(e){return new Promise((t,r)=>e.then(r,t))}async function c(e){return i(Promise.all(e.map(i)))}async function u(e,t=1){const r=Bs(e,t),s=[],o=r.map(async d=>{for(const f of d)s.push(await f())});return await Promise.all(o),s}async function l(e){return new Promise(t=>setTimeout(()=>{t(!0)},e))}function h(e,t=Math.random){for(let r=e.length-1;r>0;r--){const s=Math.floor(t()*(r+1)),o=e[r];e[r]=e[s],e[s]=o}return e}function m(e){if(e.length===1)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)}function w(e){return e.length===1?e[0]:null}function v(e){return e.length>0?e[0]:null}function E(e){if(!e.length)throw Error("Received empty array");return e[0]}function D(e,t){const r=[];for(let s=0;s<e;s++)r.push(t(s));return r}function ie(e){const t=[];for(let r=0;r<e[0].length;r++){t.push([]);for(let s=0;s<e.length;s++)t[r].push(e[s][r])}return t}function ae(e,t,r){const s=[];for(let o=0;o<e;o++){s.push([]);for(let d=0;d<t;d++)s[o].push(r)}return s}function nt(e,t,r,s){if(r<0||s<0||s+t[0].length>e[0].length||r+t.length>e.length)return!1;for(let o=0;o<t.length;o++)for(let d=0;d<t[o].length;d++)if(t[o][d]!==void 0&&e[r+o][s+d]!==t[o][d])return!1;return!0}function Ne(e,t,r=Math.random){return h(cs(0,e.length-1),r).slice(0,t)}function er(e,t){return e.map(r=>r[t])}function tr(e){let t=e,r=3405648695,s=3735928559;return function(){return t+=r,r^=t<<7,t*=s,s^=t<<13,t^=r^s,(t>>>0)/4294967296}}function st(e,t,r=Math.random){return Math.floor(r()*(t-e+1))+e}function qn(e,t,r=Math.random){return r()*(t-e)+e}function ja(){return Math.random()*2-1}function Ua(e,t,r){return t>=e.x&&t<e.x+e.width&&r>=e.y&&r<e.y+e.height}function Pa(e,t,r,s=Math.random){let o,d;do o=st(0,e-1,s),d=st(0,t-1,s);while(r&&Ua(r,o,d));return[o,d]}function Za(e,t=Math.random){const r=Math.floor(e),s=e-r;return Gn(s,t)?r+1:r}function Gn(e,t=Math.random){return t()<e}function rr(e,t=Math.random){return e[Math.floor(e.length*t())]}function Ba(e,t,r=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return Ne(e,t,r).map(s=>e[s])}function La(e,t,r,s=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);const o=[];for(;o.length<t;){const d=rr(e,s);o.some(f=>r(f,d))||o.push(d)}return o}function za(e,t,r,s,o,d=Math.random){const f=e.filter(p=>p!==t&&p!==r),g=[];for(t!==null&&g.push(t);f.length&&g.length<s;){const p=a.Random.intBetween(0,f.length-1,d);o(f[p],g)&&g.push(f[p]),f.splice(p,1)}return h(g,d),{values:g,indexOfGuaranteed:t!==null?g.indexOf(t):-1}}function it(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function Kn(e,t,r){return r(t.reduce((s,o)=>o(s),e))}function Fa(e,t){return r=>Kn(r,e,t)}function Va(e,t,r){if(r===void 0&&(r=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let s=t.reduce((d,f)=>d+f,0);const o=r*s;for(let d=0;d<e.length-1;d++)if(s-=t[d],o>=s)return e[d];return it(e)}function Wa(e,t,r=Math.random){const s=t.map(d=>r()*d),o=[];for(let d=0;d<e.length;d++)o.push([e[d],s[d]]);return o.sort((d,f)=>f[1]-d[1]).map(d=>d[0])}function be(e,t){if(e==null)return null;const r=t.split(".");let s=e;for(const o of r){if(s[o]===null||s[o]===void 0)return null;s=s[o]}return s}function xe(e,t,r){const s=t.split(/\.|\[/);let o=e;for(let d=0;d<s.length;d++){const f=s[d],g=d<s.length-1&&s[d+1].includes("]"),p=f.includes("]")?f.replace(/\[|\]/g,""):f;if(d===s.length-1)return o[p]=r,r;he(o[p])||(g?o[p]=[]:o[p]={}),o=o[p]}return r}function Ha(e,t,r=1){const s=be(e,t)||0;return xe(e,t,s+r),s}function qa(e,t,r){return be(e,t)||xe(e,t,r)}function Ga(e,t){const r=dr(t,"."),s=ls(t,".");if(!r||!s)return;const o=be(e,r);delete o[s]}function Ka(e,t,r){const s=be(e,t);if(!s)throw new Error("Key '"+t+"' does not exist.");return xe(e,t,r),s}function Ya(e,t,r){for(const s of t){const o=be(e,s);if(o)return o}if(r){const s=Object.values(e);if(s.length)return s[0]}return null}async function Qa(e,t,r){for(;;){try{await e()}catch(s){r&&r("Error in forever",s)}await l(t)}}function Xa(e,t){e();const r=setInterval(()=>{e()},t);return()=>clearInterval(r)}function Ja(e){return e/1024/1024}function eo(e){return e>=1024*1024*1024*1024?(e/1024/1024/1024/1024).toFixed(3)+" TB":e>=1024*1024*1024?(e/1024/1024/1024).toFixed(3)+" GB":e>=1024*1024?(e/1024/1024).toFixed(3)+" MB":e>=1024?(e/1024).toFixed(3)+" KB":e+" B"}function to(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e.toLowerCase());if(!t)throw new Error("Invalid hex color: "+e);return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]}function ro(e){return"#"+e.map(t=>t.toString(16).padStart(2,"0")).join("")}function no(e,t,r,s){const o=e*Math.PI/180,d=r*Math.PI/180,f=(r-e)*Math.PI/180,g=(s-t)*Math.PI/180,p=Math.sin(f/2)*Math.sin(f/2)+Math.cos(o)*Math.cos(d)*Math.sin(g/2)*Math.sin(g/2);return 6371e3*(2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p)))}function It(e,t){return Math.round(e/t)*t}function so(e){return e>1e3?(e/1e3).toFixed(0)+" km":e>=500?It(e,100)+" m":e>=100?It(e,50)+" m":It(e,10)+" m"}function io(e){return e*(e+1)/2}function ao(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])}function he(e,t=!0){return!e||t&&!nr(e._readableState)||t&&e.constructor&&(e.constructor.isBuffer||e.constructor.name=="Uint8Array"||e.constructor.name==="ArrayBuffer"||e.constructor.name==="ReadableStream")?!1:typeof e=="object"}function Re(e){return he(e)&&!Array.isArray(e)}function Yn(e){return Array.isArray(e)&&e.length===0}function oo(e){return Re(e)&&Object.keys(e).length===0}function nr(e){return e===void 0}function sr(e){return Object.prototype.toString.call(e)==="[object Function]"||Object.prototype.toString.call(e)==="[object AsyncFunction]"}function V(e){return Object.prototype.toString.call(e)==="[object String]"}function me(e){return typeof e=="number"&&isFinite(e)}function Qn(e){return e===!0||e===!1}function De(e){return Object.prototype.toString.call(e)==="[object Date]"}function Mt(e){return!V(e)||e.trim().length===0}function ir(e){return me(e)&&Number.isInteger(e)&&e>=1}function Xn(e){return V(e)&&e.match(/^-?\d+$/)!==null}function Jn(e){return V(e)&&e.match(/^(0x)?[0-9a-f]+$/i)!==null}const co="!@#$%^&*()_+-=[]{}|;:<>?,./",uo="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),ar="abcdefghijklmnopqrstuvwxyz",lo="ABCDEFGHIJKLMNOPQRSTUVWXYZ",fo="1234567890",or=ar+lo+fo,es=or+co,ts=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],rs="0123456789abcdef";function ho(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=ar[Math.floor(t()*ar.length)];return r}function mo(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=or[Math.floor(t()*or.length)];return r}function po(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=es[Math.floor(t()*es.length)];return r}function go(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=ts[Math.floor(t()*ts.length)];return r}function yo(e,t){const r=new RegExp(`[0-9a-f]{${t}}`,"i"),s=e.match(r);return s?s[0]:null}function vo(e,t,r=uo){const s=ds(e,r);for(const o of s)if(t(o))return o;return null}function wo(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=rs[Math.floor(t()*rs.length)];return r}function _o(e,t){if(!Xn(e))throw new TypeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=BigInt(e);if(t&&(t.min&&r<t.min||t.max&&r>t.max))throw RangeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+r);return e}function ns(e,t){if(Mt(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);if(t&&(t.min!==void 0&&e.length<t.min||t.max!==void 0&&e.length>t.max))throw RangeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""} length in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e.length}`);return e}function bo(e,t){if(!Jn(e))throw new TypeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.replace(/^0x/,"");if(t&&t.byteLength&&r.length!==t.byteLength*2)throw RangeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+r);return r}function xo(e,t){if(!ns(e,t).split("").every(r=>r==="_"||ct(r)))throw new TypeError(`Expected safe string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ss(e,t){if(t.min!==void 0&&e<t.min||t.max!==void 0&&e>t.max)throw RangeError(`Expected value${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e}`)}function ko(e,t){if(!sr(e))throw new TypeError(`Expected function${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function $t(e,t){if(me(e))return t&&ss(e,t),e;if(!V(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=parseFloat(e);return t&&ss(r,t),r}function cr(e,t){return $t(e,t)|0}function Eo(e,t){if(e==="true")return!0;if(e==="false")return!1;if(!Qn(e))throw new TypeError(`Expected boolean${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function To(e,t){if(!De(e))throw new TypeError(`Expected date${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Ao(e){return Mt(e)?null:e}function So(e,t){if(!V(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Oo(e,t){if(ir(e))return e;const r=parseInt(e,10);if(!ir(r))throw new TypeError(`Expected id${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function Io(e,t){if(!V(e))throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.split(":");if(r.length!==2)throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const s=parseInt(r[0],10),o=parseInt(r[1],10);if(!me(s)||!me(o)||s<0||s>23||o<0||o>59)throw new TypeError(`Expected time, got${t!=null&&t.name?` for ${t.name}`:""}: `+e);return`${String(s).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function Mo(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Ct(e,t){if(!Re(e))throw new TypeError(`Expected object${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function $o(e,t){return e===null?null:Ct(e,t)}function Co(e,t){const r=Ct(e,t);for(const s of Object.keys(r))if(!V(r[s]))throw new TypeError(`Expected string map${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function No(e,t){const r=Ct(e),s=Object.keys(r),o=Object.values(r);if(!s.every(V)||!o.every(me))throw new TypeError(`Expected numeric dictionary${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function is(e){return V(e)&&e.match(/^https?:\/\/.+/)!==null}function Ro(e,t){if(!is(e))throw new TypeError(`Expected url${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Do(e,t){return t==null?!0:e(t)}function jo(e,t){return t==null?null:e(t)}function Uo(e,t){return t==null?void 0:e(t)}function as(e,t){for(const[r,s]of Object.entries(t))if(!s(e[r]))throw TypeError(`${r} in value does not exist or match shape`);for(const r of Object.keys(e))if(!t[r])throw TypeError(`${r} exists in value but not in shape`);return!0}function Po(e,t){return e.every(r=>as(r,t))}function at(e,t="json",r=0){if(he(e,!1)){if(r>1)return"[object Object]";if(t==="json"){if(Array.isArray(e)){const o=e.map(d=>at(d,"json",r+1));return r===0?JSON.stringify(o):o}const s={};e.message&&(s.message=at(e.message,"json",r+1));for(const[o,d]of Object.entries(e))s[o]=at(d,"json",r+1);return r===0?JSON.stringify(s):s}else if(t==="key-value"){const s=Object.keys(e);return e.message&&!s.includes("message")&&s.unshift("message"),s.map(o=>`${o}=${JSON.stringify(at(e[o],"json",r+1))}`).join(" ")}}return nr(e)&&(e="undefined"),r===0?JSON.stringify(e):e}function Zo(e,t){if(V(e))return e;const r=Object.keys(e);e.message&&!r.includes("message")&&r.push("message");const s=r.map(o=>`${o}: ${e[o]}`).join("; ");return t&&e.stack?s+`
2
- `+e.stack:s}function ke(e,t){if(Re(e)&&Re(t))for(const r in t)Re(t[r])?(e[r]||(e[r]={}),ke(e[r],t[r])):Array.isArray(t[r])?e[r]=[...t[r]]:(t[r]!==null&&t[r]!==void 0||e[r]===null||e[r]===void 0)&&(e[r]=t[r]);return e}function Bo(e,t){const r={};return ke(r,e),ke(r,t),r}function Lo(e,t,r){const s={};return ke(s,e),ke(s,t),ke(s,r),s}function os(e,t){const r={};for(const s of e)for(const o of Object.keys(s))r[o]?r[o]=t(r[o],s[o]):r[o]=s[o];return r}function zo(e){return os(e,(t,r)=>t+r)}function Fo(e,t,r){e[t]||(e[t]=[]),e[t].push(r)}function Vo(e,t,r){for(e.unshift(t);e.length>r;)e.pop()}function Wo(e,t){let r=t%e.length;return r<0&&(r+=e.length),e[r]}function Nt(e,t){Array.prototype.push.apply(e,t)}function Ho(e,t){Array.prototype.unshift.apply(e,t)}async function qo(e,t){const r=[];for(const s of e)r.push(await t(s));return r}function Go(e,t){const r=[];for(let s=0;s<e.length;s++)r.push(e[s]),s<e.length-1&&(sr(t)?r.push(t()):r.push(t));return r}function Ko(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]}function Yo(e){if(e!==!0)throw Error(`Expected [true], got: [${e}]`);return e}function Qo(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e}function Xo(e){if(e!==!1)throw Error(`Expected [false], got: [${e}]`);return e}function Jo(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e}function ec(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}function tc(e,t){for(let r=0;r<e.length;r++){const s=e[r],o=t[r],d=Math.max(0,o.getTime()-Date.now());setTimeout(s,d)}}function rc(e,t,r){return e+(t-e)*r}function nc(e){return e.reduce((t,r)=>t+r,0)}function sc(e){return e.reduce((t,r)=>t+r,0)/e.length}function ic(e){const t=[...e].sort((s,o)=>s-o),r=Math.floor(t.length/2);return t.length%2===0?(t[r]+t[r-1])/2:t[r]}function ac(e,t){return e-(t-1)/2}function cs(e,t){const r=[];for(let s=e;s<=t;s++)r.push(s);return r}function oc(e,t){return t.some(r=>e.includes(r))}function cc(e){return/^[\u4E00-\u9FA5]+$/.test(e)}function ur(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(r=>/[a-z0-9]/.test(r)||t(r)?r:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function uc(e){return ur(e).replaceAll("-","")}function lc(e){return Dt(e.replace(/([A-Z])/g," $1"))}function dc(e){return e.split("-").map(Dt).join(" ")}function fc(e){return hs(e.split("-").map(Dt).join(""))}function hc(e,t=", ",r=" and "){return!e||!e.length?"":e.length===1?e[0]:e.length===2?`${e[0]}${r}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${r}${e[e.length-1]}`}function mc(e,t){return t+e.split("").join(t)+t}function pc(e){return ur(e).replace(/-/g,"_").toUpperCase()}function Rt(e,t){if(t.length===0)return 0;const r=e.toLowerCase(),s=t.toLowerCase();return e===t?1e4:r.startsWith(s)?1e4-e.length:r.includes(s)?5e3-e.length:new RegExp(".*"+s.split("").join(".*")+".*").test(r)?1e3-e.length:0}function gc(e,t){return e.filter(r=>Rt(r,t)).sort((r,s)=>Rt(s,t)-Rt(r,t))}function yc(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const vc={"&amp;":"&","&quot;":'"',"&apos;":"'","&gt;":">","&lt;":"<"};function wc(e){let t=e.replace(/&#(\d+);/g,(r,s)=>String.fromCharCode(s)).replace(/&#x(\d+);/g,(r,s)=>String.fromCharCode(parseInt(s,16)));for(const[r,s]of Object.entries(vc))t=t.replaceAll(r,s);return t}function us(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(0,r)}function lr(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(r+t.length)}function dr(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(0,r)}function ls(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(r+t.length)}function _c(e,t,r){const s=dr(e,r);return s?lr(s,t):null}function bc(e,t,r){const s=lr(e,t);return s?us(s,r):null}function fr(e,t,r=!1){const s=r?e.lastIndexOf(t):e.indexOf(t);return s===-1?r?[null,e]:[e,null]:[e.slice(0,s),e.slice(s+t.length)]}function ds(e,t){let r=[e];for(const s of t)r=r.flatMap(o=>o.split(s));return r.filter(s=>s)}function hr(e){const t=it(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?"":t.slice(r+1)}function mr(e){const t=it(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?t:t.slice(0,r)}function xc(e){let[t,r]=e.split("@");t=ot(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[s]=t.split("+");if(!s||!r||r.indexOf(".")===-1||r.indexOf(".")===r.length-1)throw new Error("Invalid email");return r=ot(r.toLowerCase()).replaceAll(" ",""),`${s}@${r}`}function kc(e){const t=mr(e),r=hr(e);return r?`${t}.${r}`:t}function Ec(e){const t=mr(e),r=hr(e);return{basename:t,extension:r,filename:r?`${t}.${r}`:t}}function Tc(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(r,s)=>rr(s.split("|"),t))}function fs(e){const t=/\{(.+?)\}/,r=e.match(t);if(!r||!r.index)return[e];const s=r[1].split(","),o=e.slice(0,r.index),d=e.slice(r.index+r[0].length);let f=[];for(const g of s){const p=fs(o+g+d);f=f.concat(p)}return f}function ot(e){return e.split(`
1
+ (function(ce,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("@ethersphere/bee-js")):typeof define=="function"&&define.amd?define(["exports","@ethersphere/bee-js"],T):(ce=typeof globalThis<"u"?globalThis:ce||self,T(ce.SwarmChatJs={},ce.BeeJs))})(this,function(ce,T){"use strict";const P=[];for(let a=0;a<256;++a)P.push((a+256).toString(16).slice(1));function mi(a,n=0){return(P[a[n+0]]+P[a[n+1]]+P[a[n+2]]+P[a[n+3]]+"-"+P[a[n+4]]+P[a[n+5]]+"-"+P[a[n+6]]+P[a[n+7]]+"-"+P[a[n+8]]+P[a[n+9]]+"-"+P[a[n+10]]+P[a[n+11]]+P[a[n+12]]+P[a[n+13]]+P[a[n+14]]+P[a[n+15]]).toLowerCase()}let Vt;const gi=new Uint8Array(16);function yi(){if(!Vt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Vt=crypto.getRandomValues.bind(crypto)}return Vt(gi)}const Tn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function vi(a,n,i){if(Tn.randomUUID&&!n&&!a)return Tn.randomUUID();a=a||{};const c=a.random||(a.rng||yi)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,mi(c)}function wi(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var On={};(function(a){var n;Object.defineProperty(a,"__esModule",{value:!0}),a.Vector=a.Cache=a.Assertions=a.Strings=a.Types=a.Objects=a.Dates=a.Promises=a.Numbers=a.System=a.Arrays=a.Random=a.Elliptic=a.Binary=a.AsyncQueue=a.PubSubChannel=a.FixedPointNumber=a.MerkleTree=a.Chunk=a.Uint8ArrayWriter=a.Uint8ArrayReader=a.AsyncLazy=a.Lazy=a.Optional=void 0;async function i(e){return new Promise((t,r)=>e.then(r,t))}async function c(e){return i(Promise.all(e.map(i)))}async function u(e,t=1){const r=Bs(e,t),s=[],o=r.map(async l=>{for(const f of l)s.push(await f())});return await Promise.all(o),s}async function d(e){return new Promise(t=>setTimeout(()=>{t(!0)},e))}function h(e,t=Math.random){for(let r=e.length-1;r>0;r--){const s=Math.floor(t()*(r+1)),o=e[r];e[r]=e[s],e[s]=o}return e}function p(e){if(e.length===1)return e[0];throw Error(`Expected exactly one element, actual: ${e.length}`)}function w(e){return e.length===1?e[0]:null}function v(e){return e.length>0?e[0]:null}function E(e){if(!e.length)throw Error("Received empty array");return e[0]}function D(e,t){const r=[];for(let s=0;s<e;s++)r.push(t(s));return r}function ie(e){const t=[];for(let r=0;r<e[0].length;r++){t.push([]);for(let s=0;s<e.length;s++)t[r].push(e[s][r])}return t}function ae(e,t,r){const s=[];for(let o=0;o<e;o++){s.push([]);for(let l=0;l<t;l++)s[o].push(r)}return s}function nt(e,t,r,s){if(r<0||s<0||s+t[0].length>e[0].length||r+t.length>e.length)return!1;for(let o=0;o<t.length;o++)for(let l=0;l<t[o].length;l++)if(t[o][l]!==void 0&&e[r+o][s+l]!==t[o][l])return!1;return!0}function Ne(e,t,r=Math.random){return h(cs(0,e.length-1),r).slice(0,t)}function er(e,t){return e.map(r=>r[t])}function tr(e){let t=e,r=3405648695,s=3735928559;return function(){return t+=r,r^=t<<7,t*=s,s^=t<<13,t^=r^s,(t>>>0)/4294967296}}function st(e,t,r=Math.random){return Math.floor(r()*(t-e+1))+e}function qn(e,t,r=Math.random){return r()*(t-e)+e}function ja(){return Math.random()*2-1}function Ua(e,t,r){return t>=e.x&&t<e.x+e.width&&r>=e.y&&r<e.y+e.height}function Pa(e,t,r,s=Math.random){let o,l;do o=st(0,e-1,s),l=st(0,t-1,s);while(r&&Ua(r,o,l));return[o,l]}function Za(e,t=Math.random){const r=Math.floor(e),s=e-r;return Gn(s,t)?r+1:r}function Gn(e,t=Math.random){return t()<e}function rr(e,t=Math.random){return e[Math.floor(e.length*t())]}function Ba(e,t,r=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);return Ne(e,t,r).map(s=>e[s])}function La(e,t,r,s=Math.random){if(t>e.length)throw new Error(`Count (${t}) is greater than array length (${e.length})`);const o=[];for(;o.length<t;){const l=rr(e,s);o.some(f=>r(f,l))||o.push(l)}return o}function Fa(e,t,r,s,o,l=Math.random){const f=e.filter(m=>m!==t&&m!==r),g=[];for(t!==null&&g.push(t);f.length&&g.length<s;){const m=a.Random.intBetween(0,f.length-1,l);o(f[m],g)&&g.push(f[m]),f.splice(m,1)}return h(g,l),{values:g,indexOfGuaranteed:t!==null?g.indexOf(t):-1}}function it(e){if(!e.length)throw Error("Received empty array");return e[e.length-1]}function Kn(e,t,r){return r(t.reduce((s,o)=>o(s),e))}function za(e,t){return r=>Kn(r,e,t)}function Va(e,t,r){if(r===void 0&&(r=Math.random()),e.length!==t.length)throw new Error("Array length mismatch");let s=t.reduce((l,f)=>l+f,0);const o=r*s;for(let l=0;l<e.length-1;l++)if(s-=t[l],o>=s)return e[l];return it(e)}function Wa(e,t,r=Math.random){const s=t.map(l=>r()*l),o=[];for(let l=0;l<e.length;l++)o.push([e[l],s[l]]);return o.sort((l,f)=>f[1]-l[1]).map(l=>l[0])}function be(e,t){if(e==null)return null;const r=t.split(".");let s=e;for(const o of r){if(s[o]===null||s[o]===void 0)return null;s=s[o]}return s}function xe(e,t,r){const s=t.split(/\.|\[/);let o=e;for(let l=0;l<s.length;l++){const f=s[l],g=l<s.length-1&&s[l+1].includes("]"),m=f.includes("]")?f.replace(/\[|\]/g,""):f;if(l===s.length-1)return o[m]=r,r;he(o[m])||(g?o[m]=[]:o[m]={}),o=o[m]}return r}function Ha(e,t,r=1){const s=be(e,t)||0;return xe(e,t,s+r),s}function qa(e,t,r){return be(e,t)||xe(e,t,r)}function Ga(e,t){const r=dr(t,"."),s=ls(t,".");if(!r||!s)return;const o=be(e,r);delete o[s]}function Ka(e,t,r){const s=be(e,t);if(!s)throw new Error("Key '"+t+"' does not exist.");return xe(e,t,r),s}function Ya(e,t,r){for(const s of t){const o=be(e,s);if(o)return o}if(r){const s=Object.values(e);if(s.length)return s[0]}return null}async function Qa(e,t,r){for(;;){try{await e()}catch(s){r&&r("Error in forever",s)}await d(t)}}function Xa(e,t){e();const r=setInterval(()=>{e()},t);return()=>clearInterval(r)}function Ja(e){return e/1024/1024}function eo(e){return e>=1024*1024*1024*1024?(e/1024/1024/1024/1024).toFixed(3)+" TB":e>=1024*1024*1024?(e/1024/1024/1024).toFixed(3)+" GB":e>=1024*1024?(e/1024/1024).toFixed(3)+" MB":e>=1024?(e/1024).toFixed(3)+" KB":e+" B"}function to(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e.toLowerCase());if(!t)throw new Error("Invalid hex color: "+e);return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]}function ro(e){return"#"+e.map(t=>t.toString(16).padStart(2,"0")).join("")}function no(e,t,r,s){const o=e*Math.PI/180,l=r*Math.PI/180,f=(r-e)*Math.PI/180,g=(s-t)*Math.PI/180,m=Math.sin(f/2)*Math.sin(f/2)+Math.cos(o)*Math.cos(l)*Math.sin(g/2)*Math.sin(g/2);return 6371e3*(2*Math.atan2(Math.sqrt(m),Math.sqrt(1-m)))}function It(e,t){return Math.round(e/t)*t}function so(e){return e>1e3?(e/1e3).toFixed(0)+" km":e>=500?It(e,100)+" m":e>=100?It(e,50)+" m":It(e,10)+" m"}function io(e){return e*(e+1)/2}function ao(e){const t=e.match(/-?\d+(\.\d+)?/);if(!t)throw Error("No float found in "+e);return parseFloat(t[0])}function he(e,t=!0){return!e||t&&!nr(e._readableState)||t&&e.constructor&&(e.constructor.isBuffer||e.constructor.name=="Uint8Array"||e.constructor.name==="ArrayBuffer"||e.constructor.name==="ReadableStream")?!1:typeof e=="object"}function Re(e){return he(e)&&!Array.isArray(e)}function Yn(e){return Array.isArray(e)&&e.length===0}function oo(e){return Re(e)&&Object.keys(e).length===0}function nr(e){return e===void 0}function sr(e){return Object.prototype.toString.call(e)==="[object Function]"||Object.prototype.toString.call(e)==="[object AsyncFunction]"}function V(e){return Object.prototype.toString.call(e)==="[object String]"}function pe(e){return typeof e=="number"&&isFinite(e)}function Qn(e){return e===!0||e===!1}function De(e){return Object.prototype.toString.call(e)==="[object Date]"}function Mt(e){return!V(e)||e.trim().length===0}function ir(e){return pe(e)&&Number.isInteger(e)&&e>=1}function Xn(e){return V(e)&&e.match(/^-?\d+$/)!==null}function Jn(e){return V(e)&&e.match(/^(0x)?[0-9a-f]+$/i)!==null}const co="!@#$%^&*()_+-=[]{}|;:<>?,./",uo="!@#$%^&*()_+-=[]{}|;:<>?,./".split(""),ar="abcdefghijklmnopqrstuvwxyz",lo="ABCDEFGHIJKLMNOPQRSTUVWXYZ",fo="1234567890",or=ar+lo+fo,es=or+co,ts=["—","\\","東","京","都","𝖆","𝖇","𝖈","👾","🙇","💁","🙅","ᚠ","ᛇ","ᚻ","ᛦ"],rs="0123456789abcdef";function ho(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=ar[Math.floor(t()*ar.length)];return r}function po(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=or[Math.floor(t()*or.length)];return r}function mo(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=es[Math.floor(t()*es.length)];return r}function go(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=ts[Math.floor(t()*ts.length)];return r}function yo(e,t){const r=new RegExp(`[0-9a-f]{${t}}`,"i"),s=e.match(r);return s?s[0]:null}function vo(e,t,r=uo){const s=ds(e,r);for(const o of s)if(t(o))return o;return null}function wo(e,t=Math.random){let r="";for(let s=0;s<e;s++)r+=rs[Math.floor(t()*rs.length)];return r}function _o(e,t){if(!Xn(e))throw new TypeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=BigInt(e);if(t&&(t.min&&r<t.min||t.max&&r>t.max))throw RangeError(`Expected integer string${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: `+r);return e}function ns(e,t){if(Mt(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);if(t&&(t.min!==void 0&&e.length<t.min||t.max!==void 0&&e.length>t.max))throw RangeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""} length in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e.length}`);return e}function bo(e,t){if(!Jn(e))throw new TypeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.replace(/^0x/,"");if(t&&t.byteLength&&r.length!==t.byteLength*2)throw RangeError(`Expected hex string${t!=null&&t.name?` for ${t.name}`:""} of byte length ${t.byteLength}; got: `+r);return r}function xo(e,t){if(!ns(e,t).split("").every(r=>r==="_"||ct(r)))throw new TypeError(`Expected safe string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function ss(e,t){if(t.min!==void 0&&e<t.min||t.max!==void 0&&e>t.max)throw RangeError(`Expected value${t!=null&&t.name?` for ${t.name}`:""} in range: ${t.min??"-inf"}..${t.max??"inf"}; got: ${e}`)}function ko(e,t){if(!sr(e))throw new TypeError(`Expected function${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function $t(e,t){if(pe(e))return t&&ss(e,t),e;if(!V(e)||!e.match(/^-?\d+(\.\d+)?$/))throw new TypeError(`Expected number${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=parseFloat(e);return t&&ss(r,t),r}function cr(e,t){return $t(e,t)|0}function Eo(e,t){if(e==="true")return!0;if(e==="false")return!1;if(!Qn(e))throw new TypeError(`Expected boolean${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Ao(e,t){if(!De(e))throw new TypeError(`Expected date${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function So(e){return Mt(e)?null:e}function To(e,t){if(!V(e))throw new TypeError(`Expected string${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Oo(e,t){if(ir(e))return e;const r=parseInt(e,10);if(!ir(r))throw new TypeError(`Expected id${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function Io(e,t){if(!V(e))throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const r=e.split(":");if(r.length!==2)throw new TypeError(`Expected time${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);const s=parseInt(r[0],10),o=parseInt(r[1],10);if(!pe(s)||!pe(o)||s<0||s>23||o<0||o>59)throw new TypeError(`Expected time, got${t!=null&&t.name?` for ${t.name}`:""}: `+e);return`${String(s).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function Mo(e,t){if(!Array.isArray(e))throw new TypeError(`Expected array${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Ct(e,t){if(!Re(e))throw new TypeError(`Expected object${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function $o(e,t){return e===null?null:Ct(e,t)}function Co(e,t){const r=Ct(e,t);for(const s of Object.keys(r))if(!V(r[s]))throw new TypeError(`Expected string map${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function No(e,t){const r=Ct(e),s=Object.keys(r),o=Object.values(r);if(!s.every(V)||!o.every(pe))throw new TypeError(`Expected numeric dictionary${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return r}function is(e){return V(e)&&e.match(/^https?:\/\/.+/)!==null}function Ro(e,t){if(!is(e))throw new TypeError(`Expected url${t!=null&&t.name?` for ${t.name}`:""}, got: `+e);return e}function Do(e,t){return t==null?!0:e(t)}function jo(e,t){return t==null?null:e(t)}function Uo(e,t){return t==null?void 0:e(t)}function as(e,t){for(const[r,s]of Object.entries(t))if(!s(e[r]))throw TypeError(`${r} in value does not exist or match shape`);for(const r of Object.keys(e))if(!t[r])throw TypeError(`${r} exists in value but not in shape`);return!0}function Po(e,t){return e.every(r=>as(r,t))}function at(e,t="json",r=0){if(he(e,!1)){if(r>1)return"[object Object]";if(t==="json"){if(Array.isArray(e)){const o=e.map(l=>at(l,"json",r+1));return r===0?JSON.stringify(o):o}const s={};e.message&&(s.message=at(e.message,"json",r+1));for(const[o,l]of Object.entries(e))s[o]=at(l,"json",r+1);return r===0?JSON.stringify(s):s}else if(t==="key-value"){const s=Object.keys(e);return e.message&&!s.includes("message")&&s.unshift("message"),s.map(o=>`${o}=${JSON.stringify(at(e[o],"json",r+1))}`).join(" ")}}return nr(e)&&(e="undefined"),r===0?JSON.stringify(e):e}function Zo(e,t){if(V(e))return e;const r=Object.keys(e);e.message&&!r.includes("message")&&r.push("message");const s=r.map(o=>`${o}: ${e[o]}`).join("; ");return t&&e.stack?s+`
2
+ `+e.stack:s}function ke(e,t){if(Re(e)&&Re(t))for(const r in t)Re(t[r])?(e[r]||(e[r]={}),ke(e[r],t[r])):Array.isArray(t[r])?e[r]=[...t[r]]:(t[r]!==null&&t[r]!==void 0||e[r]===null||e[r]===void 0)&&(e[r]=t[r]);return e}function Bo(e,t){const r={};return ke(r,e),ke(r,t),r}function Lo(e,t,r){const s={};return ke(s,e),ke(s,t),ke(s,r),s}function os(e,t){const r={};for(const s of e)for(const o of Object.keys(s))r[o]?r[o]=t(r[o],s[o]):r[o]=s[o];return r}function Fo(e){return os(e,(t,r)=>t+r)}function zo(e,t,r){e[t]||(e[t]=[]),e[t].push(r)}function Vo(e,t,r){for(e.unshift(t);e.length>r;)e.pop()}function Wo(e,t){let r=t%e.length;return r<0&&(r+=e.length),e[r]}function Nt(e,t){Array.prototype.push.apply(e,t)}function Ho(e,t){Array.prototype.unshift.apply(e,t)}async function qo(e,t){const r=[];for(const s of e)r.push(await t(s));return r}function Go(e,t){const r=[];for(let s=0;s<e.length;s++)r.push(e[s]),s<e.length-1&&(sr(t)?r.push(t()):r.push(t));return r}function Ko(e,t){if(e!==t)throw Error(`Expected [${e}] to equal [${t}]`);return[e,t]}function Yo(e){if(e!==!0)throw Error(`Expected [true], got: [${e}]`);return e}function Qo(e){if(!e)throw Error(`Expected truthy value, got: [${e}]`);return e}function Xo(e){if(e!==!1)throw Error(`Expected [false], got: [${e}]`);return e}function Jo(e){if(e)throw Error(`Expected falsy value, got: [${e}]`);return e}function ec(e,t){if(!t.includes(e))throw Error(`Expected any of [${t.join(", ")}], got: [${e}]`);return e}function tc(e,t){for(let r=0;r<e.length;r++){const s=e[r],o=t[r],l=Math.max(0,o.getTime()-Date.now());setTimeout(s,l)}}function rc(e,t,r){return e+(t-e)*r}function nc(e){return e.reduce((t,r)=>t+r,0)}function sc(e){return e.reduce((t,r)=>t+r,0)/e.length}function ic(e){const t=[...e].sort((s,o)=>s-o),r=Math.floor(t.length/2);return t.length%2===0?(t[r]+t[r-1])/2:t[r]}function ac(e,t){return e-(t-1)/2}function cs(e,t){const r=[];for(let s=e;s<=t;s++)r.push(s);return r}function oc(e,t){return t.some(r=>e.includes(r))}function cc(e){return/^[\u4E00-\u9FA5]+$/.test(e)}function ur(e,t=()=>!1){return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").split("").map(r=>/[a-z0-9]/.test(r)||t(r)?r:"-").join("").replace(/-+/g,"-").replace(/^-|-$/g,"")}function uc(e){return ur(e).replaceAll("-","")}function lc(e){return Dt(e.replace(/([A-Z])/g," $1"))}function dc(e){return e.split("-").map(Dt).join(" ")}function fc(e){return hs(e.split("-").map(Dt).join(""))}function hc(e,t=", ",r=" and "){return!e||!e.length?"":e.length===1?e[0]:e.length===2?`${e[0]}${r}${e[1]}`:`${e.slice(0,e.length-1).join(t)}${r}${e[e.length-1]}`}function pc(e,t){return t+e.split("").join(t)+t}function mc(e){return ur(e).replace(/-/g,"_").toUpperCase()}function Rt(e,t){if(t.length===0)return 0;const r=e.toLowerCase(),s=t.toLowerCase();return e===t?1e4:r.startsWith(s)?1e4-e.length:r.includes(s)?5e3-e.length:new RegExp(".*"+s.split("").join(".*")+".*").test(r)?1e3-e.length:0}function gc(e,t){return e.filter(r=>Rt(r,t)).sort((r,s)=>Rt(s,t)-Rt(r,t))}function yc(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const vc={"&amp;":"&","&quot;":'"',"&apos;":"'","&gt;":">","&lt;":"<"};function wc(e){let t=e.replace(/&#(\d+);/g,(r,s)=>String.fromCharCode(s)).replace(/&#x(\d+);/g,(r,s)=>String.fromCharCode(parseInt(s,16)));for(const[r,s]of Object.entries(vc))t=t.replaceAll(r,s);return t}function us(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(0,r)}function lr(e,t){const r=e.indexOf(t);return r===-1?null:e.slice(r+t.length)}function dr(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(0,r)}function ls(e,t){const r=e.lastIndexOf(t);return r===-1?null:e.slice(r+t.length)}function _c(e,t,r){const s=dr(e,r);return s?lr(s,t):null}function bc(e,t,r){const s=lr(e,t);return s?us(s,r):null}function fr(e,t,r=!1){const s=r?e.lastIndexOf(t):e.indexOf(t);return s===-1?r?[null,e]:[e,null]:[e.slice(0,s),e.slice(s+t.length)]}function ds(e,t){let r=[e];for(const s of t)r=r.flatMap(o=>o.split(s));return r.filter(s=>s)}function hr(e){const t=it(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?"":t.slice(r+1)}function pr(e){const t=it(e.split(/\\|\//g)),r=t.lastIndexOf(".",t.length-1);return r<=0?t:t.slice(0,r)}function xc(e){let[t,r]=e.split("@");t=ot(t.replaceAll(".","").toLowerCase()).replaceAll(" ","");const[s]=t.split("+");if(!s||!r||r.indexOf(".")===-1||r.indexOf(".")===r.length-1)throw new Error("Invalid email");return r=ot(r.toLowerCase()).replaceAll(" ",""),`${s}@${r}`}function kc(e){const t=pr(e),r=hr(e);return r?`${t}.${r}`:t}function Ec(e){const t=pr(e),r=hr(e);return{basename:t,extension:r,filename:r?`${t}.${r}`:t}}function Ac(e,t=Math.random){return e.replace(/\{(.+?)\}/g,(r,s)=>rr(s.split("|"),t))}function fs(e){const t=/\{(.+?)\}/,r=e.match(t);if(!r||!r.index)return[e];const s=r[1].split(","),o=e.slice(0,r.index),l=e.slice(r.index+r[0].length);let f=[];for(const g of s){const m=fs(o+g+l);f=f.concat(m)}return f}function ot(e){return e.split(`
3
3
  `).map(t=>t.trim().replace(/\s+/g," ")).filter(t=>t.length>0).join(`
4
- `)}function Dt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function hs(e){return e.charAt(0).toLowerCase()+e.slice(1)}function ms(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function ps(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function ct(e){return ms(e)||ps(e)}const Ac=`
5
- \r.,?!:;"'\`(){}[]~@#$%^&*-+=|<>/\\`.split("");function Sc(e){return Ac.includes(e)}function Oc(e){return ct(e)||e==="."||e==="["||e==="]"||e==="_"}function Ic(e,t,r,s,o){return e.slice(0,t)+s+e.slice(t,t+r)+o+e.slice(t+r)}function gs(e,t,r=0){const s=t.exec(e.slice(r));return s?{index:s.index,match:s[0]}:null}function ys(e,t,r=!0){if(!r)return t.every(o=>o instanceof RegExp?o.test(e):e.indexOf(o,0)!==-1);let s=0;for(const o of t)if(o instanceof RegExp){const d=gs(e,o,s);if(!d)return!1;s=d.index+d.match.length}else{const d=e.indexOf(o,s);if(d===-1)return!1;s=d+o.length}return!0}function Mc(e,t,r=!0){let s=0;for(const o of t){let d=!1;for(;!d&&s<e.length;)ys(e[s],o,r)&&(d=!0),s++;if(!d)return!1}return!0}function $c(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e}function je(e,t,r=0){let s=-1;for(const o of t){const d=e.indexOf(o,r);d!==-1&&(s===-1||d<s)&&(s=d)}return s}function Cc(e,t=0){for(let r=t;r<e.length;r++)if(Sc(e[r]))return r;return-1}function Nc(e,t=0){for(let r=t;r<e.length;r++)if(e[r]==="#"&&ct(e[r+1]))return r;return-1}function vs(e,t,r=0){return e.slice(0,r).lastIndexOf(t)}function ws(e,t=0,r="{",s="}"){let o=1;for(let d=t;d<e.length;d++)if(e.slice(d,d+s.length)===s){if(--o===0)return d}else e.slice(d,d+r.length)===r&&o++;return-1}function _s(e,t){const r=t.wordBoundary?je(e,[`${t.opening} `,`${t.opening}
4
+ `)}function Dt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function hs(e){return e.charAt(0).toLowerCase()+e.slice(1)}function ps(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function ms(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function ct(e){return ps(e)||ms(e)}const Sc=`
5
+ \r.,?!:;"'\`(){}[]~@#$%^&*-+=|<>/\\`.split("");function Tc(e){return Sc.includes(e)}function Oc(e){return ct(e)||e==="."||e==="["||e==="]"||e==="_"}function Ic(e,t,r,s,o){return e.slice(0,t)+s+e.slice(t,t+r)+o+e.slice(t+r)}function gs(e,t,r=0){const s=t.exec(e.slice(r));return s?{index:s.index,match:s[0]}:null}function ys(e,t,r=!0){if(!r)return t.every(o=>o instanceof RegExp?o.test(e):e.indexOf(o,0)!==-1);let s=0;for(const o of t)if(o instanceof RegExp){const l=gs(e,o,s);if(!l)return!1;s=l.index+l.match.length}else{const l=e.indexOf(o,s);if(l===-1)return!1;s=l+o.length}return!0}function Mc(e,t,r=!0){let s=0;for(const o of t){let l=!1;for(;!l&&s<e.length;)ys(e[s],o,r)&&(l=!0),s++;if(!l)return!1}return!0}function $c(e){return e.match(/"|,/)?`"${e.replace(/"/g,'""')}"`:e}function je(e,t,r=0){let s=-1;for(const o of t){const l=e.indexOf(o,r);l!==-1&&(s===-1||l<s)&&(s=l)}return s}function Cc(e,t=0){for(let r=t;r<e.length;r++)if(Tc(e[r]))return r;return-1}function Nc(e,t=0){for(let r=t;r<e.length;r++)if(e[r]==="#"&&ct(e[r+1]))return r;return-1}function vs(e,t,r=0){return e.slice(0,r).lastIndexOf(t)}function ws(e,t=0,r="{",s="}"){let o=1;for(let l=t;l<e.length;l++)if(e.slice(l,l+s.length)===s){if(--o===0)return l}else e.slice(l,l+r.length)===r&&o++;return-1}function _s(e,t){const r=t.wordBoundary?je(e,[`${t.opening} `,`${t.opening}
6
6
  `],t.start||0):e.indexOf(t.opening,t.start||0);if(r===-1)return null;const s=ws(e,r+t.opening.length,t.opening,t.closing);return s===-1?null:t.exclusive?e.slice(r+t.opening.length,s):e.slice(r,s+t.closing.length)}function Rc(e,t){const r=[];let s=t.wordBoundary?je(e,[`${t.opening} `,`${t.opening}
7
7
  `],t.start||0):e.indexOf(t.opening,t.start||0);for(;;){if(s===-1)return r;const o=_s(e,{...t,start:s});if(!o)return r;r.push(o),s=t.wordBoundary?je(e,[`${t.opening} `,`${t.opening}
8
- `],s+o.length):e.indexOf(t.opening,s+o.length)}}function Dc(e,t,r){let s=0;for(;;){const o=a.Strings.extractBlock(e,{...r,start:s});if(!o)return e;const d=t(o);s=e.indexOf(o,s)+d.length,e=e.replace(o,d)}}function jc(e,t){const r=[];let s=0;for(;s<e.length;){const o=e.indexOf(t,s);if(o===-1){r.push({string:e.slice(s),symbol:null});break}const d=e.indexOf(t,o+t.length);if(o>s&&d!==-1&&r.push({string:e.slice(s,o),symbol:null}),d===-1){r.push({string:e.slice(s),symbol:null});break}r.push({string:e.slice(o+t.length,d),symbol:t}),s=d+t.length}return r}function Uc(e){const t=[];let r=0;for(;r<e.length;){const s=Nc(e,r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=Cc(e,s+1);if(o===-1){t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1),symbol:"#"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1,o),symbol:"#"}),r=o}return t}function Pc(e){const t=[];let r=0;for(;r<e.length;){const s=je(e,["http://","https://"],r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=je(e,[" ",`
9
- `],s);if(o===-1){s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s),symbol:"http"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s,o),symbol:"http"}),r=o}return t}const bs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xs="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Zc(e){return ks(e,bs)}function Bc(e){return Es(e,bs)}function Lc(e){return ks(e,xs)}function zc(e){return Es(e,xs)}function ks(e,t){const r="=",s=t.length;let o=0,d=0;const f=[];for(let g=0;g<e.length;g++){const p=e[g];if(p===r)break;const k=t.indexOf(p);if(k===-1)throw new Error(`Invalid character: ${p}`);d=d<<Math.log2(s)|k,o+=Math.log2(s),o>=8&&(o-=8,f.push(d>>o&255))}return new Uint8Array(f)}function Es(e,t){const r=t.length;let s=0,o=0,d="";for(let f=0;f<e.length;f++)for(o=o<<8|e[f],s+=8;s>=Math.log2(r);)s-=Math.log2(r),d+=t[o>>s&r-1];return s>0&&(d+=t[o<<Math.log2(r)-s&r-1]),d.length%4!==0&&(d+="=".repeat(4-d.length%4)),d}function Fc(e){e.startsWith("0x")&&(e=e.slice(2));const t=e.length/2,r=new Uint8Array(t);for(let s=0;s<t;s++){const o=parseInt(e.slice(s*2,s*2+2),16);r[s]=o}return r}function Vc(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Wc(e,t){const r=e.split("/").filter(d=>d),s=t.split("/").filter(d=>d);if(r.length!==s.length)return null;const o={};for(let d=0;d<r.length;d++){const f=r[d];if(f.startsWith(":"))o[f.slice(1)]=s[d];else if(f!==s[d])return null}return o}function pr(e,t,r){const s=[];for(const o of r)o!==t&&s.push(e.replace(t,o));return s}function Hc(e,t,r,s=Math.random){const o=a.Arrays.shuffle(t.map(f=>({variants:a.Arrays.shuffle(f.variants.map(g=>g),s),avoid:f.avoid})),s),d=[];for(const f of o){const g=f.variants.filter(k=>k!==f.avoid),p=g.find(k=>e.includes(k));if(p&&(Nt(d,pr(e,p,g)),d.length>=r))break}if(d.length<r)for(const f of o){const g=f.variants.find(p=>e.includes(p));if(g&&(Nt(d,pr(e,g,f.variants)),d.length>=r))break}return d.slice(0,r)}function qc(e,t,r,s=!1){const o=new RegExp(s?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(o,r)}function Gc(e,t){const r=/\b[A-Z][a-zA-Z0-9]*\b/g;return e.replace(r,s=>s.toUpperCase()===s?s:t(s))}function Kc(e){return e.replace(/<[^>]*>/g,"")}function Ts(e){const t=e.lastIndexOf(" ");if(t===-1)return{line:e,rest:""};const r=e.slice(0,t),s=e.slice(t+1);return{line:r,rest:s}}function Yc(e,t={}){return[...e].reduce((r,s)=>r+(t[s]||1),0)}function Qc(e,t,r={}){const s=[];let o="",d=0;for(let f=0;f<e.length;f++){const g=e[f],p=r[g]||1;if(o+=g,d+=p,d>t){const{line:k,rest:$}=Ts(o);s.push(k),o=$,d=$.split("").map(U=>r[U]||1).reduce((U,Be)=>U+Be,0)}}return o&&s.push(o),s}function Xc(e,t){const r=[];for(let s=0;s<=e.length;s++)r[s]=[s];for(let s=0;s<=t.length;s++)r[0][s]=s;for(let s=1;s<=e.length;s++)for(let o=1;o<=t.length;o++){const d=e[s-1]===t[o-1]?0:1;r[s][o]=Math.min(r[s-1][o]+1,r[s][o-1]+1,r[s-1][o-1]+d)}return r[e.length][t.length]}function gr(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function Jc(e,t,r){return r==="any"?t.some(s=>gr(e,s)):t.every(s=>gr(e,s))}function eu(e){const t={},r=e.match(/([a-z\-]+)="([^"]+)"/g);if(r)for(const s of r){const[o,d]=fr(s,"=");t[o]=d.slice(1,d.length-1)}return t}function jt(e,t,r=[]){let s="";for(;t<e.length&&(ct(e[t])||r.includes(e[t]));)s+=e[t++];return s}function tu(e,t,r="$",s=":"){for(const o in t)e=As(e,o,t[o],r,s);return e=Ss(e),e}function As(e,t,r,s="$",o=":"){if(r==="")return e;let d=e.indexOf(`${s}${t}`);for(;d!==-1;){if(e[d+t.length+1]===o)if(e[d+t.length+2]===o)e=e.replace(`${s}${t}${o}${o}`,r);else{const f=jt(e,d+t.length+2,["_"]);e=e.replace(`${s}${t}${o}${f}`,r)}else e=e.replace(`${s}${t}`,r);d=e.indexOf(`${s}${t}`,d+r.length)}return e}function Ss(e,t="$",r=":"){let s=e.indexOf(t);for(;s!==-1;){const o=jt(e,s+1);if(e[s+o.length+1]===r)if(e[s+o.length+2]===r)e=e.replace(`${t}${o}${r}${r}`,"");else{const d=jt(e,s+o.length+2);e=e.replace(`${t}${o}${r}${d}`,d)}s=e.indexOf(t,s+1)}return e}function ru(e,t){let r=e.indexOf("](");for(;r!==-1;){const s=vs(e,"[",r),o=e.indexOf(")",r);if(s!==-1&&o!==-1){const[d,f]=e.slice(s+1,o).split("]("),g=t(d,f);e=e.slice(0,s)+g+e.slice(o+1)}r=e.indexOf("](",r+1)}return e}function Os(e,t=!0){const r=Object.entries(e).filter(([s,o])=>o!=null).map(([s,o])=>`${s}=${encodeURIComponent(o)}`).join("&");return r?(t?"?":"")+r:""}function nu(e){const t={},r=e.split("&");for(const s of r){const[o,d]=s.split("=");o&&d&&(t[o]=decodeURIComponent(d))}return t}function su(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function iu(e,t){let r=null,s=-1/0;for(const[o,d]of Object.entries(e)){const f=t(d);f>s&&(s=f,r=o)}return r?[r,e[r]]:null}function au(e,t,r,s){const o=e.find(f=>f[t]===r),d=e.find(f=>f[t]===r+s);o&&d?(o[t]=r+s,d[t]=r):o&&(o[t]=r+s),e.sort((f,g)=>$t(f[t])-$t(g[t])),e.forEach((f,g)=>f[t]=g+1)}function ou(e){const t=Object.keys(e);if(t.length===1)return e[t[0]];throw new Error("Expected object to have a single key")}function cu(e,t=":"){return Object.fromEntries(e.map(r=>fr(r,t)).map(r=>r[0]&&r[1]?[ot(r[0]),ot(r[1])]:null).filter(r=>r))}function uu(e,t,r){return Cs(e,t)+Os(r||{})}function lu(e,t=",",r='"'){const s=[];let o="",d=!1;const f=e.split("");for(const g of f)g===t&&!d?(s.push(o),o=""):g===r&&(!o&&!d||d)?d=!d:o+=g;return s.push(o),s}function du(e){return`[${Math.floor(e.progress*100)}%] ${Ut(e.deltaMs)} out of ${Ut(e.totalTimeMs)} (${Ut(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`}async function fu(e,t,r){for(let s=0;s<r;s++){try{if(await e())return!0}catch{}s<r-1&&await l(t)}return!1}function hu(e,t){const r=[];for(let s=e.length-1;s>=0;s--)t(e[s])&&r.push(e.splice(s,1)[0]);return r}function mu(e){return JSON.parse(JSON.stringify(e))}function pu(e){return Math.ceil((e||Date.now())/1e3)}function gu(e){return(e||new Date).toISOString().slice(0,10)}function yu(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")}function vu(e){const t=new Date(e);return new Date(t.getTime()-t.getTimezoneOffset()*6e4)}function wu(e){return new Date(e)}function ee(e){return String(Math.floor(e)).padStart(2,"0")}function _u(e){let[t,r]=e.split(":");me(parseInt(t,10))||(t="0"),me(parseInt(r,10))||(r="0");let s=br(cr(t),0,23),o=br(cr(r),0,59);return`${ee(s)}:${ee(o)}`}function Ut(e){const t=Math.floor(e/36e5);e=e%36e5;const r=Math.floor(e/6e4);e=e%6e4;const s=Math.floor(e/1e3);return t?`${ee(t)}:${ee(r)}:${ee(s)}`:`${ee(r)}:${ee(s)}`}function Ee(e){return Math.floor((De(e)?e.getTime():e)/864e5)}const bu={today:(e,t)=>ee(e)+":"+ee(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`};function xu(e,t){const r=new Date((t==null?void 0:t.now)||Date.now()),s=(t==null?void 0:t.labels)||bu,o=De(e)?e:new Date(e);if(Ee(r)===Ee(o))return s.today(o.getUTCHours(),o.getUTCMinutes(),o.getUTCHours()>12);if(Ee(r)-Ee(o)===1)return s.yesterday();const d=vr(o);return Ee(r)-Ee(o)<7?s[d.day]():s.weeks(Math.round((r.getTime()-o.getTime())/6048e5))}const Is={now:()=>"A few seconds",seconds:e=>`${e} seconds`,minutes:e=>`${e} minutes`,hours:e=>`${e} hours`,days:e=>`${e} days`,weeks:e=>`${e} weeks`};function Ms(e,t){const r=(t==null?void 0:t.now)??Date.now(),s=(t==null?void 0:t.labels)||Is,o=a.Types.isDate(e)?e.getTime():e;let d=(r-o)/1e3;return d<10?s.now():d<120?s.seconds(Math.floor(d)):(d/=60,d<120?s.minutes(Math.floor(d)):(d/=60,d<48?s.hours(Math.floor(d)):(d/=24,d<14?s.days(Math.floor(d)):(d/=7,s.weeks(Math.floor(d))))))}function ku(e,t=Is){return Ms(0,{now:e*1e3,labels:t})}function Eu(e,t,r){const s=((r==null?void 0:r.now)??Date.now())-e,o=Math.floor(s/t),d=t/((r==null?void 0:r.precision)??1)-Math.ceil(s%t/((r==null?void 0:r.precision)??1));return{cycles:o,remaining:d}}const yr={};function Tu(e,t){return!yr[e]||Date.now()>yr[e]?(yr[e]=Date.now()+t,!0):!1}const Au={s:1e3,m:6e4,h:36e5,d:864e5};function Su(e,t,r){return t=De(t)?t.getTime():t,r=r?De(r)?r.getTime():r:Date.now(),(r-t)/Au[e]}function Ou(e,t,r,s){s||(s=Date.now());const o=t/r,d=s-e,f=d/t,g=f*r,p=g-d;return{deltaMs:d,progress:o,baseTimeMs:f,totalTimeMs:g,remainingTimeMs:p}}const Iu={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function $s(e){return{zeroBasedIndex:e,day:Iu[e]}}function vr(e){return $s(e.getDay())}function Mu(e){return vr(new Date(e))}function $u(e){return e*1e3}function Cu(e){return e*6e4}function Nu(e){return e*36e5}function Ru(e){return e*864e5}const Du={ms:1,milli:1,millis:1,millisecond:1,milliseconds:1,s:1e3,sec:1e3,second:1e3,seconds:1e3,m:6e4,min:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,month:2592e6,months:2592e6,y:31536e6,year:31536e6,years:31536e6};function ju(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Du[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}const Uu={b:1,byte:1,bytes:1,kb:1024,kilobyte:1024,kilobytes:1024,mb:1024**2,megabyte:1024**2,megabytes:1024**2,gb:1024**3,gigabyte:1024**3,gigabytes:1024**3,tb:1024**4,terabyte:1024**4,terabytes:1024**4};function Pu(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Uu[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}function Zu(e){return e.replace(/ +/g," ").replace(/^ /gm,"")}const wr={};async function Bu(e,t,r){const s=Date.now(),o=wr[e];if(o&&o.validUntil>s)return o.value;const d=await r(),f=s+t;return wr[e]={value:d,validUntil:f},d}function Lu(e){delete wr[e]}function Cs(...e){return e.filter(t=>t).join("/").replace(new RegExp("(?<!:)\\/+","g"),"/")}function zu(e,t,r,s,o=!0){const d=e.indexOf(t),f=e.indexOf(r,d+t.length);if(d===-1||f===-1)throw Error("Start or end not found");return o?e.substring(0,d+t.length)+s+e.substring(f):e.substring(0,d)+s+e.substring(f+r.length)}function Fu(e){let t="p";e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim());const r=e[0]===e[0].toUpperCase(),s=/[.?!]$/.test(e),o=/:$/.test(e);return{type:t,isCapitalized:r,hasPunctuation:s,endsWithColon:o}}function Vu(e,t="(",r=")"){let s=0,o=0;for(;o<e.length;)if(e.startsWith(t,o)?(s++,o+=t.length):e.startsWith(r,o)?(s--,o+=r.length):o++,s<0)return!1;return t===r?s%2===0:s===0}function Wu(e){e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"");let t=e.length;for(;e=e.replace(/(\w+)[\s,']+\w+/g,"$1"),e.length!==t;)t=e.length;return e=e.replaceAll(/[A-Z][a-zA-Z0-9]*/g,"A"),e=e.replaceAll(/[a-z][a-zA-Z0-9]*/g,"a"),e=e.replaceAll(/[\u4E00-\u9FA5]+/g,"Z"),e}function Ns(e){const t=Object.keys(e).sort((s,o)=>s.localeCompare(o)),r={};for(const s of t)r[s]=Te(e[s]);return r}function Rs(e){const t=[];return e.sort((r,s)=>JSON.stringify(Te(r)).localeCompare(JSON.stringify(Te(s)))).forEach(r=>t.push(Te(r))),t}function Te(e){return Array.isArray(e)?Rs(e):he(e)?Ns(e):e}function Ds(e,t){return JSON.stringify(Te(e))===JSON.stringify(Te(t))}function Hu(...e){for(let t=1;t<e.length;t++)if(!Ds(e[t-1],e[t]))return!1;return!0}function qu(e){try{return JSON.parse(e)}catch{return null}}function Gu(){let e=0;return{next:()=>e++}}function Ku(e){let t=0;return{next:()=>e[t++%e.length]}}function Yu(e){let t;return r=>{const s=r===e&&t!==e;return t=r,s}}function Qu(e,t,r,s,o){const d={};for(const f of Object.keys(t))d[f]=[];d[s]=[],o&&(e=e.sort(o));for(const f of e){const g=f[r],p=t[g]?g:s;d[p].length>=t[p]?d[s].push(f):d[p].push(f)}return d}function Xu(e,t){const r=Object.keys(e),s=Object.keys(t);return{uniqueToA:r.filter(o=>!s.includes(o)),uniqueToB:s.filter(o=>!r.includes(o))}}function js(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}function Ju(e,t){const r=js(e);return e[r]=t(e[r]),r}function el(e){return e=e.replace(/\r\n/g,`
10
- `),e=e.replace(/(\w+)\((.+)\)/g,(t,r,s)=>`${r}(${s.replaceAll(",","&comma;")})`),e=e.replace(/(,)(\s+})/g,"$2"),e=e.replace(/\.\.\..+?,/g,""),e=e.replace(/({\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/(,\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/:(.+)\?(.+):/g,(t,r,s)=>`: (${r.trim()} && ${s.trim()}) ||`),e=e.replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2'),e=e.replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,r,s,o)=>`"${r}":"${s.trim()}"${o}`),e=e.replace(/("'|'")/g,'"'),e=e.replaceAll("&comma;",","),JSON.parse(e)}const pe=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],tl=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],Us=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function rl(e,t,r){let s=e.length-t;if(s<=0)return"0."+"0".repeat(-s)+e+(r?" "+r:"");let o=e.substring(0,s),d=e.substring(s);return o===""&&(o="0"),o+"."+d+(r?" "+r:"")}function nl(e,t){const r=(t==null?void 0:t.longForm)??!1,s=t!=null&&t.unit?` ${t.unit}`:"",o=r?tl:Us,d=(t==null?void 0:t.precision)??1;if(e<pe[0])return`${e}${s}`;for(let f=0;f<pe.length-1;f++)if(e<pe[f+1])return`${(e/pe[f]).toFixed(d)}${r?" ":""}${o[f]}${s}`;return`${(e/pe[pe.length-1]).toFixed(d)}${r?" ":""}${o[pe.length-1]}${s}`}function _r(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim(),s=Us.findIndex(o=>o.toLowerCase()===r.toLowerCase());return s===-1?t:t*pe[s]}function br(e,t,r){return e<t?t:e>r?r:e}function sl(e,t,r){const s=e+t;return s>r?r:s}function il(e,t,r){const s=e-t;return s<r?r:s}function al(e,t){return t(e),e}function ol(e,t){e&&t(e)}function cl(e,t){const r=Object.keys(t);for(const s of r)Array.isArray(t[s])&&Array.isArray(e[s])&&Nt(e[s],t[s])}function ul(e){return e.splice(0,e.length),e}function ll(e){for(const t of Object.keys(e))(Yn(e[t])||Array.isArray(e[t])&&e[t].every(r=>r==null))&&delete e[t];return e}function dl(e){for(const t of Object.entries(e))(t[1]===null||t[1]===void 0||V(t[1])&&Mt(t[1]))&&delete e[t[0]];return e}function fl(e,t){const r={};for(const[s,o]of Object.entries(e))t(s)&&(r[s]=o);return r}function hl(e,t){const r={};for(const[s,o]of Object.entries(e))t(o)&&(r[s]=o);return r}function ml(e,t){const r={};for(const s of Object.entries(e))r[s[0]]=t(s[1]);return r}function pl(e,t){const r=[];let s=0;for(const o of e)r.push(t(o,s++));return r}async function gl(e,t){try{return await e()}catch{throw t}}function yl(e,t,r){r!=null&&(e[t]=r)}function vl(e,t,r,s){const o=be(r,s);o!=null&&xe(e,t,o)}function wl(e){const t={};for(const[r,s]of Object.entries(e))t[s]=r;return t}function _l(e){const t=Object.keys(e),r=t.map(g=>e[g].length),s=r.reduce((g,p)=>g*=p);let o=1;const d=[1];for(let g=0;g<r.length-1;g++)o*=r[g],d.push(o);const f=[];for(let g=0;g<s;g++){const p={};for(let k=0;k<t.length;k++){const $=e[t[k]],U=Math.floor(g/d[k])%$.length;p[t[k]]=$[U]}f.push(p)}return f}function bl(e){return Object.values(e).filter(t=>t).length}function xl(e,t,r){return e+(r?"["+t+"]":(e.length?".":"")+t)}function Pt(e,t,r,s,o){if(!he(t))return t;for(const[d,f]of Object.entries(t)){const g=xl(r,d,s);Array.isArray(f)?o?Pt(e,f,g,!0,o):e[g]=f.map(p=>Pt(Array.isArray(p)?[]:{},p,"",!1,o)):he(f)?Pt(e,f,g,!1,o):e[g]=f}return e}function kl(e,t=!1,r){return Pt({},e,r||"",!1,t)}function Ps(e){if(!he(e))return e;const t=Array.isArray(e)?[]:{};for(const[r,s]of Object.entries(e))Array.isArray(s)?xe(t,r,s.map(o=>Ps(o))):xe(t,r,s);return t}function El(e,t,r){return t[e]?t[e]:r}function Zs(e,t){const r={};for(const s of e){const o=t(s);r[o]=s}return r}function Tl(e,t){const r={};for(const s of e){const o=t(s);r[o]||(r[o]=[]),r[o].push(s)}return r}function Al(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r}function Bs(e,t){const r=Math.ceil(e.length/t),s=[];for(let o=0;o<e.length;o+=r)s.push(e.slice(o,o+r));return s}function Ls(e,t){const r=[],s=Math.ceil(e.length/t);for(let o=0;o<s;o++)r.push(e.slice(o*t,o*t+t));return r}function Sl(e,t){const r=Math.ceil(e.length/t);return Ls(e,r)}function Ol(e,t){return Object.values(Zs(e,t))}function Il(e,t,r,s,o){const d=t?e.map(t):e,f={};for(const p of d)f[p]=(f[p]||0)+1;const g=s?zs(f,o?(p,k)=>p[1]-k[1]:(p,k)=>k[1]-p[1]):f;return r?Object.keys(g):g}function zs(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function Ml(e){const t=[],r=Object.keys(e),s=e[r[0]].length;for(let o=0;o<s;o++){const d={};for(const f of r)d[f]=e[f][o];t.push(d)}return t}function $l(e,t,r=1){for(const s of e)s[t]+=r}function Cl(e,t,r){for(const s of e)s[t]=r}function xr(e,t){const r=[];let s=[];return e.forEach((o,d)=>{(d===0||!t(o,e[d-1]))&&(s=[],r.push(s)),s.push(o)}),r}function Nl(){return{map:new Map,keys:[]}}function Rl(){return{map:new Map,keys:[]}}function Fs(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.push(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function Dl(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.unshift(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function jl(e,t,r,s,o=100){Fs(e,t,{validUntil:Date.now()+s,data:r},o)}function Ul(e,t){const r=e.map.get(t);return r&&r.validUntil>Date.now()?r.data:null}class ge{constructor(t){this.value=t}static of(t){return new ge(t)}static empty(){return new ge(null)}map(t){return new ge(this.value!==null&&this.value!==void 0?t(this.value):null)}mapAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(r=>ge.of(r)):Promise.resolve(ge.empty())}ifPresent(t){return this.value!==null&&this.value!==void 0&&t(this.value),this}ifPresentAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(t){return(this.value===null||this.value===void 0)&&t(),this}ifAbsentAsync(t){return this.value===null||this.value===void 0?t().then(()=>this):Promise.resolve(this)}getOrFallback(t){return this.value??t()}getOrFallbackAsync(t){return this.value!==null&&this.value!==void 0?Promise.resolve(this.value):t()}getOrThrow(){if(this.value===null||this.value===void 0)throw Error("Optional.value is empty");return this.value}}a.Optional=ge;class Pl{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}}a.Lazy=Pl;class Zl{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}}a.AsyncLazy=Zl;function Bl(e){return()=>e.forEach(t=>t())}function Ll(e,t){return e.reduce((r,s)=>t(r)>t(s)?r:s)}function zl(e,t){const r=e.find(s=>s instanceof t);return ge.of(r)}function Fl(e,t){return e.filter(r=>r instanceof t)}function Vl(e,t){const r=[],s=Math.max(e.length,t.length);for(let o=0;o<s;o++)e[o]&&r.push(e[o]),t[o]&&r.push(t[o]);return r}function Wl(e,t){return e.includes(t)?e.filter(r=>r!==t):[...e,t]}class Hl{constructor(t){this.value=t,this.children=[]}}function ql(e,t,r,s,o=!1){const d=new Map,f=[];e.forEach(p=>{const k=new Hl(p);d.set(p[t],k)}),e.forEach(p=>{const k=d.get(p[t]);if(!k)return;const $=p[r];if($){const U=d.get($);U&&U.children.push(k)}else f.push(k)});const g=p=>{p.children.sort((k,$)=>{const U=k.value[s],Be=$.value[s];return o?Be-U:U-Be}),p.children.forEach(g)};return f.forEach(g),f}function Vs(e,t){if(Math.log2(e.length)%1!==0)throw new Error("Array length must be a power of 2");let r=[...e];for(;r.length>1;){const s=[];for(let o=0;o<r.length;o+=2){const d=r[o+1];s.push(t(r[o],d))}r=s}return r[0]}function Ue(...e){const t=e.reduce((o,d)=>o+d.length,0),r=new Uint8Array(t);let s=0;return e.forEach(o=>{r.set(o,s),s+=o.length}),r}function Ws(e){return e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function Hs(e){return e[0]===255&&e[1]===216}function qs(e){return e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function Gl(e){return Ws(e)||Hs(e)||qs(e)}function Kl(e){return new Uint8Array([e])}function Yl(e){return e[0]}function Ql(e,t){const r=new ArrayBuffer(2);return new DataView(r).setUint16(0,e,t==="LE"),new Uint8Array(r)}function Xl(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,t==="LE")}function Jl(e,t){const r=new ArrayBuffer(4);return new DataView(r).setUint32(0,e,t==="LE"),new Uint8Array(r)}function ed(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,t==="LE")}function kr(e,t){const r=new ArrayBuffer(8);return new DataView(r).setBigUint64(0,BigInt(e),t==="LE"),new Uint8Array(r)}function td(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,t==="LE")}function Pe(e,t){const r=new Uint8Array(32);let s=e;if(t==="LE"){for(let o=0;o<32;o++)r[o]=Number(s&0xffn),s>>=8n;return r}for(let o=31;o>=0;o--)r[o]=Number(s&0xffn),s>>=8n;return r}function Ze(e,t){let r=0n;if(t==="LE"){for(let s=31;s>=0;s--)r=r<<8n|BigInt(e[s]);return r}for(let s=0;s<32;s++)r=r<<8n|BigInt(e[s]);return r}function rd(e,t){const r=[];let s=0;for(const o of t)r.push(e.subarray(s,s+o)),s+=o;return r}function Er(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.subarray(s,s+t));return r}const Gs=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function nd(e){for(let t=0;t<24;t++){const r=e[0]^e[10]^e[20]^e[30]^e[40],s=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],d=e[3]^e[13]^e[23]^e[33]^e[43],f=e[4]^e[14]^e[24]^e[34]^e[44],g=e[5]^e[15]^e[25]^e[35]^e[45],p=e[6]^e[16]^e[26]^e[36]^e[46],k=e[7]^e[17]^e[27]^e[37]^e[47],$=e[8]^e[18]^e[28]^e[38]^e[48],U=e[9]^e[19]^e[29]^e[39]^e[49],Be=o<<1|d>>>31,Zd=d<<1|o>>>31,dt=$^Be,ft=U^Zd,Bd=f<<1|g>>>31,Ld=g<<1|f>>>31,ht=r^Bd,mt=s^Ld,zd=p<<1|k>>>31,Fd=k<<1|p>>>31,pt=o^zd,gt=d^Fd,Vd=$<<1|U>>>31,Wd=U<<1|$>>>31,yt=f^Vd,vt=g^Wd,Hd=r<<1|s>>>31,qd=s<<1|r>>>31,wt=p^Hd,_t=k^qd;e[0]^=dt,e[1]^=ft,e[2]^=ht,e[3]^=mt,e[4]^=pt,e[5]^=gt,e[6]^=yt,e[7]^=vt,e[8]^=wt,e[9]^=_t,e[10]^=dt,e[11]^=ft,e[12]^=ht,e[13]^=mt,e[14]^=pt,e[15]^=gt,e[16]^=yt,e[17]^=vt,e[18]^=wt,e[19]^=_t,e[20]^=dt,e[21]^=ft,e[22]^=ht,e[23]^=mt,e[24]^=pt,e[25]^=gt,e[26]^=yt,e[27]^=vt,e[28]^=wt,e[29]^=_t,e[30]^=dt,e[31]^=ft,e[32]^=ht,e[33]^=mt,e[34]^=pt,e[35]^=gt,e[36]^=yt,e[37]^=vt,e[38]^=wt,e[39]^=_t,e[40]^=dt,e[41]^=ft,e[42]^=ht,e[43]^=mt,e[44]^=pt,e[45]^=gt,e[46]^=yt,e[47]^=vt,e[48]^=wt,e[49]^=_t;const Mr=e[0],$r=e[1],Cr=e[2]<<1|e[3]>>>31,Nr=e[3]<<1|e[2]>>>31,Rr=e[5]<<30|e[4]>>>2,Dr=e[4]<<30|e[5]>>>2,jr=e[6]<<28|e[7]>>>4,Ur=e[7]<<28|e[6]>>>4,Pr=e[8]<<27|e[9]>>>5,Zr=e[9]<<27|e[8]>>>5,Br=e[11]<<4|e[10]>>>28,Lr=e[10]<<4|e[11]>>>28,zr=e[13]<<12|e[12]>>>20,Fr=e[12]<<12|e[13]>>>20,Vr=e[14]<<6|e[15]>>>26,Wr=e[15]<<6|e[14]>>>26,Hr=e[17]<<23|e[16]>>>9,qr=e[16]<<23|e[17]>>>9,Gr=e[18]<<20|e[19]>>>12,Kr=e[19]<<20|e[18]>>>12,Yr=e[20]<<3|e[21]>>>29,Qr=e[21]<<3|e[20]>>>29,Xr=e[22]<<10|e[23]>>>22,Jr=e[23]<<10|e[22]>>>22,en=e[25]<<11|e[24]>>>21,tn=e[24]<<11|e[25]>>>21,rn=e[26]<<25|e[27]>>>7,nn=e[27]<<25|e[26]>>>7,sn=e[29]<<7|e[28]>>>25,an=e[28]<<7|e[29]>>>25,on=e[31]<<9|e[30]>>>23,cn=e[30]<<9|e[31]>>>23,un=e[33]<<13|e[32]>>>19,ln=e[32]<<13|e[33]>>>19,dn=e[34]<<15|e[35]>>>17,fn=e[35]<<15|e[34]>>>17,hn=e[36]<<21|e[37]>>>11,mn=e[37]<<21|e[36]>>>11,pn=e[38]<<8|e[39]>>>24,gn=e[39]<<8|e[38]>>>24,yn=e[40]<<18|e[41]>>>14,vn=e[41]<<18|e[40]>>>14,wn=e[42]<<2|e[43]>>>30,_n=e[43]<<2|e[42]>>>30,bn=e[45]<<29|e[44]>>>3,xn=e[44]<<29|e[45]>>>3,kn=e[47]<<24|e[46]>>>8,En=e[46]<<24|e[47]>>>8,Tn=e[48]<<14|e[49]>>>18,An=e[49]<<14|e[48]>>>18;e[0]=Mr^~zr&en,e[1]=$r^~Fr&tn,e[2]=zr^~en&hn,e[3]=Fr^~tn&mn,e[4]=en^~hn&Tn,e[5]=tn^~mn&An,e[6]=hn^~Tn&Mr,e[7]=mn^~An&$r,e[8]=Tn^~Mr&zr,e[9]=An^~$r&Fr,e[10]=jr^~Gr&Yr,e[11]=Ur^~Kr&Qr,e[12]=Gr^~Yr&un,e[13]=Kr^~Qr&ln,e[14]=Yr^~un&bn,e[15]=Qr^~ln&xn,e[16]=un^~bn&jr,e[17]=ln^~xn&Ur,e[18]=bn^~jr&Gr,e[19]=xn^~Ur&Kr,e[20]=Cr^~Vr&rn,e[21]=Nr^~Wr&nn,e[22]=Vr^~rn&pn,e[23]=Wr^~nn&gn,e[24]=rn^~pn&yn,e[25]=nn^~gn&vn,e[26]=pn^~yn&Cr,e[27]=gn^~vn&Nr,e[28]=yn^~Cr&Vr,e[29]=vn^~Nr&Wr,e[30]=Pr^~Br&Xr,e[31]=Zr^~Lr&Jr,e[32]=Br^~Xr&dn,e[33]=Lr^~Jr&fn,e[34]=Xr^~dn&kn,e[35]=Jr^~fn&En,e[36]=dn^~kn&Pr,e[37]=fn^~En&Zr,e[38]=kn^~Pr&Br,e[39]=En^~Zr&Lr,e[40]=Rr^~Hr&sn,e[41]=Dr^~qr&an,e[42]=Hr^~sn&on,e[43]=qr^~an&cn,e[44]=sn^~on&wn,e[45]=an^~cn&_n,e[46]=on^~wn&Rr,e[47]=cn^~_n&Dr,e[48]=wn^~Rr&Hr,e[49]=_n^~Dr&qr,e[0]^=Gs[t*2],e[1]^=Gs[t*2+1]}}function Ks(e){const t=[];for(let r=0;r<e.length;r+=4)t.push(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24);return t}function Ys(e,t){if(!e.length){const o=new Uint8Array(136);return o[0]=t,o[135]=128,[Ks(o)]}const r=Er(e,136),s=r[r.length-1];if(s.length<136){const o=new Uint8Array(136);o.set(s),o[s.length]=t,o[135]|=128,r[r.length-1]=o}if(s.length===136){const o=new Uint8Array(136);o[0]=t,o[135]=128,r.push(o)}return r.map(Ks)}function Qs(e,t){for(const r of t){for(let s=0;s<34;s+=2)e[s]^=r[s+1],e[s+1]^=r[s];nd(e)}return e}function Xs(e){return new Uint8Array([e[1],e[1]>>-24,e[1]>>-16,e[1]>>-8,e[0],e[0]>>8,e[0]>>16,e[0]>>24,e[3],e[3]>>-24,e[3]>>-16,e[3]>>-8,e[2],e[2]>>8,e[2]>>16,e[2]>>24,e[5],e[5]>>-24,e[5]>>-16,e[5]>>-8,e[4],e[4]>>8,e[4]>>16,e[4]>>24,e[7],e[7]>>-24,e[7]>>-16,e[7]>>-8,e[6],e[6]>>8,e[6]>>16,e[6]>>24])}function oe(e){return Xs(Qs(new Array(50).fill(0),Ys(e,1)))}function sd(e){return Xs(Qs(new Array(50).fill(0),Ys(e,6)))}function id(e,t,r){const s=Math.min(e.length,t.length,r/8+1);for(let o=0;o<s;o++){const d=e[o]^t[o];for(let f=0;f<8;f++)if(d>>7-f&1)return o*8+f}return r}function ad(e,t){const r=Math.min(e.length,t.length);for(let s=0;s<r;s++)if(e[s]!==t[s])return e.subarray(0,s);return e.subarray(0,r)}function od(e,t,r,s){const o=Math.floor(t/8),d=t%8;r===1?e[o]|=1<<(s==="BE"?7-d:d):e[o]&=~(1<<(s==="BE"?7-d:d))}function cd(e,t,r){const s=Math.floor(t/8),o=t%8;return e[s]>>(r==="BE"?7-o:o)&1}function ud(e,t,r=0){for(let s=r;s<e.length;s++)for(let o=0;o<t.length&&e[s+o]===t[o];o++)if(o===t.length-1)return s;return-1}function Js(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,t-e.length),s}function ld(e,t,r=0){const s=e.length%t;return s===0?e:Js(e,e.length+t-s,r)}function ei(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,0),s}function dd(e,t,r=0){const s=e.length%t;return s===0?e:ei(e,e.length+t-s,r)}function fd(e,t){const r=new Uint8Array(e.length);for(let s=0;s<e.length;s++)r[s]=e[s]^t[s%t.length];return r}function hd(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function C(e,t){return(e%t+t)%t}function ut(e,t){e=C(e,t);let[r,s]=[0n,1n],[o,d]=[t,e];for(;d!==0n;){const f=o/d;[r,s]=[s,r-f*s],[o,d]=[d,o-f*d]}if(o>1n)throw new Error("a is not invertible");return r<0n&&(r+=t),r}function md(e,t,r){let s=1n;for(e=C(e,r);t>0;)t%2n===1n&&(s=C(s*e,r)),e=C(e*e,r),t=t/2n;return s}function ti(e,t){return C(e,t)===0n?0n:t%4n===3n?md(e,(t+1n)/4n,t):null}const L=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,j=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Zt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Bt=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Tr(e,t,r){if(t===0n)return[0n,0n];const s=C(3n*e*e*ut(2n*t,r),r),o=C(s*s-2n*e,r),d=C(s*(e-o)-t,r);return[o,d]}function Lt(e,t,r,s,o){if(e===0n&&t===0n)return[r,s];if(r===0n&&s===0n)return[e,t];if(e===r&&t===C(-s,o))return[0n,0n];if(e===r&&t===s)return Tr(e,t,o);const d=C((s-t)*ut(r-e,o),o),f=C(d*d-e-r,o),g=C(d*(e-f)-t,o);return[f,g]}function pd(e){if(e<=0n||e>=j)throw new Error("Invalid private key");return Ae(Zt,Bt,e,L)}function gd(e){const t=e[1]%2n===0n?2:3;return new Uint8Array([t,...Pe(e[0],"BE")])}function yd(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Invalid compressed public key");const t=Ze(e.slice(1),"BE"),r=ti(C(t**3n+7n,L),L);if(!r)throw Error("Invalid x: does not correspond to a valid curve point");const s=C(-r,L),o=r%2n===0n;return[t,e[0]===2?o?r:s:o?s:r]}function vd(e){const t=new Uint8Array(20),r=oe(Ue(Pe(e[0],"BE"),Pe(e[1],"BE")));return t.set(r.subarray(12)),t}function wd(e){const t=a.Binary.uint8ArrayToHex(e),r=a.Binary.uint8ArrayToHex(a.Binary.keccak256(new Uint8Array([...t].map(o=>o.charCodeAt(0)))));let s="0x";for(let o=0;o<t.length;o++)parseInt(r[o],16)>7?s+=t[o].toUpperCase():s+=t[o];return s}function Ae(e,t,r,s){let o=[0n,0n],d=[e,t];const f=r.toString(2);for(const g of f)g==="0"?(d=Lt(o[0],o[1],d[0],d[1],s),o=Tr(o[0],o[1],s)):(o=Lt(o[0],o[1],d[0],d[1],s),d=Tr(d[0],d[1],s));return o}function _d(e,t,r){return ri(Ze(oe(e),"BE"),t,r)}function ri(e,t,r){if(t<=0n||t>=j)throw new Error("Invalid private key");if(r||(r=C(Ze(oe(Ue(oe(Pe(t,"BE")),Pe(e,"BE"))),"BE"),j)),r<=0n||r>=j)throw new Error("Invalid nonce");const s=C(e,j),o=Ae(Zt,Bt,r,L),d=C(o[0],j);let f=C((s+C(d,j)*t)*ut(r,j),j);if(d===0n||f===0n)throw new Error("Invalid r or s value");let g=o[1]%2n===0n?27n:28n;return f>j/2n&&(f=j-f,g=g===27n?28n:27n),[d,f,g]}function bd(e,t,r,s){const o=ti(C(t**3n+7n,L),L);if(!o)throw new Error("Invalid r: does not correspond to a valid curve point");const d=s===27n?0n:1n,f=o%2n===d?o:L-o,g=C(Ze(oe(e),"BE"),j),p=Ae(t,f,r,L),k=Ae(Zt,Bt,g,L),$=Lt(p[0],p[1],k[0],C(-k[1],L),L);return Ae($[0],$[1],ut(t,j),L)}function xd(e,t,r,s){const o=C(Ze(oe(e),"BE"),j),d=ut(s,j),f=C(o*d,j),g=C(r*d,j),p=Ae(Zt,Bt,f,L),k=Ae(t[0],t[1],g,L),$=Lt(p[0],p[1],k[0],k[1],L);return r===C($[0],j)}class ni{constructor(t){this.cursor=0,this.buffer=t}read(t){const r=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayReader=ni;class si{constructor(t){this.buffer=t,this.cursor=0}write(t){const r=Math.min(this.max(),t.max());return this.buffer.set(t.read(r),this.cursor),this.cursor+=r,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayWriter=si;class zt{constructor(t,r=0n){this.span=r,this.writer=new si(new Uint8Array(t))}build(){return Ue(kr(this.span,"LE"),this.writer.buffer)}hash(){const t=Vs(Er(this.writer.buffer,32),(r,s)=>oe(Ue(r,s)));return oe(Ue(kr(this.span,"LE"),t))}}a.Chunk=zt;class Ar{constructor(t,r=4096){this.counters=[1],this.capacity=r,this.chunks=[new zt(r)],this.onChunk=t}static async root(t,r=4096){const s=new n(n.NOOP,r);return await s.append(t),s.finalize()}async append(t,r=0,s=0n){const o=new ni(t);for(;o.max()>0;){this.chunks[r].writer.max()===0&&await this.elevate(r);const d=this.chunks[r].writer.write(o);s?this.chunks[r].span+=s:this.chunks[0].span+=BigInt(d)}}async elevate(t){this.counters[t]=++this.counters[t]%(this.capacity/32),this.chunks[t+1]||(this.chunks.push(new zt(this.capacity)),this.counters.push(1)),await this.append(this.chunks[t].hash(),t+1,this.chunks[t].span),await this.onChunk(this.chunks[t]),this.chunks[t]=new zt(this.capacity)}async finalize(t=0){return this.chunks[t+1]?this.counters[t]===1?(await this.elevate(t+1),this.chunks[t+1]=this.chunks[t],this.finalize(t+1)):(await this.elevate(t),this.finalize(t+1)):(await this.onChunk(this.chunks[t]),this.chunks[t])}}a.MerkleTree=Ar,n=Ar,Ar.NOOP=async e=>{};class te{constructor(t,r){if(r<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=r}static fromDecimalString(t,r){let[s,o]=t.split(".");return o=(o||"").padEnd(r,"0").slice(0,r),new te(BigInt(s+o),r)}add(t){return this.assertSameScale(t),new te(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new te(this.value-t.value,this.scale)}multiply(t){return new te(this.value*t,this.scale)}divmod(t){if(t===0n)throw new Error("Division by zero is not allowed");const r=this.value/t,s=this.value%t;return[new te(r,this.scale),new te(s,this.scale)]}exchange(t,r,s){if(t==="*"){const d=this.value*r.value/10n**BigInt(this.scale);return new te(d,s)}this.assertSameScale(r);const o=this.value*10n**BigInt(s)/r.value;return new te(o,s)}compare(t){return this.assertSameScale(t),this.value>t.value?1:this.value<t.value?-1:0}toDecimalString(){if(this.scale===0)return this.value.toString();const t=this.value.toString(),r=t.slice(0,-this.scale)||"0",s=t.slice(-this.scale).padStart(this.scale,"0");return`${r}.${s}`}toString(){return this.value.toString()}toJSON(){return this.toString()}assertSameScale(t){if(this.scale!==t.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${t.scale}`)}}a.FixedPointNumber=te;function kd(e){if(e.length===0)return null;const t=e[0];return t.ttlMax?--t.ttl<=0&&e.shift():t.ttlMax=t.ttl,{progress:(t.ttlMax-t.ttl)/t.ttlMax,data:t.data}}function Ft(e,t,r,s){const o=e.findIndex(g=>g===`--${t}`||g.startsWith(`--${t}=`)),d=e[o];if(!d)return(r||{})[s||t||""]||null;if(d.includes("="))return d.split("=")[1];const f=e[o+1];return f&&!f.startsWith("-")?f:(r||{})[s||t||""]||null}function Ed(e,t,r,s){const o=Ft(e,t,r,s);if(!o)return null;try{return _r(o)}catch{throw new Error(`Invalid number argument ${t}: ${o}`)}}function Td(e,t,r,s){const o=e.some(p=>p.endsWith("-"+t)),d=Ft(e,t,r,s);if(!d&&o)return!0;if(!d&&!o)return null;const f=["true","1","yes","y","on"],g=["false","0","no","n","off"];if(f.includes(d.toLowerCase()))return!0;if(g.includes(d.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${t}: ${d}`)}function ii(e,t,r,s){const o=Ft(e,t,r,s);if(!o)throw new Error(`Missing argument ${t}`);return o}function Ad(e,t,r,s){const o=ii(e,t,r,s);try{return _r(o)}catch{throw new Error(`Invalid argument ${t}: ${o}`)}}function ai(e,t){const r=e[t];e.splice(t,1),e.unshift(r)}function Sd(e,t){const r=[...e];return ai(r,t),r}function oi(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Od(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Sr(e,t){return{x:e.x*t,y:e.y*t}}function Id(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}}function ci(e,t,r){return{x:e.x+Math.cos(t)*r,y:e.y+Math.sin(t)*r}}function ui(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function lt(e,t,r="row-first"){const s=[];if(r==="column-first")for(let o=0;o<e.length;o++)for(let d=0;d<e[0].length;d++)t(o,d)&&s.push({x:o,y:d});else for(let o=0;o<e[0].length;o++)for(let d=0;d<e.length;d++)t(d,o)&&s.push({x:d,y:o});return s}function Md(e,t,r){var s,o;return((s=e[t+1])==null?void 0:s[r])&&((o=e[t-1])==null?void 0:o[r])&&!e[t][r-1]&&!e[t][r+1]}function $d(e,t,r){var s,o;return e[t][r+1]&&e[t][r-1]&&!((s=e[t-1])!=null&&s[r])&&!((o=e[t+1])!=null&&o[r])}function li(e,t,r){var s;return!((s=e[t-1])!=null&&s[r])}function di(e,t,r){var s;return!((s=e[t+1])!=null&&s[r])}function fi(e,t,r){return!e[t][r-1]}function hi(e,t,r){return!e[t][r+1]}function Cd(e,t,r){var o,d,f,g,p,k,$,U;const s=[];return e[t][r]?Md(e,t,r)||$d(e,t,r)?[]:(!((o=e[t-1])!=null&&o[r-1])&&li(e,t,r)&&fi(e,t,r)&&s.push({x:t,y:r}),!((d=e[t+1])!=null&&d[r-1])&&di(e,t,r)&&fi(e,t,r)&&s.push({x:t+1,y:r}),!((f=e[t-1])!=null&&f[r+1])&&li(e,t,r)&&hi(e,t,r)&&s.push({x:t,y:r+1}),!((g=e[t+1])!=null&&g[r+1])&&di(e,t,r)&&hi(e,t,r)&&s.push({x:t+1,y:r+1}),s):((p=e[t-1])!=null&&p[r]&&e[t][r-1]&&s.push({x:t,y:r}),(k=e[t+1])!=null&&k[r]&&e[t][r-1]&&s.push({x:t+1,y:r}),($=e[t-1])!=null&&$[r]&&e[t][r+1]&&s.push({x:t,y:r+1}),(U=e[t+1])!=null&&U[r]&&e[t][r+1]&&s.push({x:t+1,y:r+1}),s)}function Nd(e,t,r,s){const o=[{x:0,y:0},{x:r,y:0},{x:0,y:s},{x:r,y:s}];for(let d=0;d<e.length;d++)for(let f=0;f<e[0].length;f++){const g=Cd(e,d,f);for(const p of g)o.some(k=>k.x===p.x&&k.y===p.y)||o.push(p)}return o.map(d=>({x:d.x*t,y:d.y*t}))}function Rd(e,t){const r=lt(e,(p,k)=>e[p][k]===0&&e[p][k+1]!==0,"row-first").map(p=>({...p,dx:1,dy:0})),s=lt(e,(p,k)=>e[p][k]===0&&e[p][k-1]!==0,"row-first").map(p=>({...p,dx:1,dy:0})),o=lt(e,(p,k)=>{var $;return e[p][k]===0&&(($=e[p-1])==null?void 0:$[k])!==0},"column-first").map(p=>({...p,dx:0,dy:1})),d=lt(e,(p,k)=>{var $;return e[p][k]===0&&(($=e[p+1])==null?void 0:$[k])!==0},"column-first").map(p=>({...p,dx:0,dy:1}));r.forEach(p=>p.y++),d.forEach(p=>p.x++);const f=xr([...o,...d],(p,k)=>p.x===k.x&&p.y-1===k.y),g=xr([...s,...r],(p,k)=>p.y===k.y&&p.x-1===k.x);return[...f,...g].map(p=>({start:p[0],end:it(p)})).map(p=>({start:Sr(p.start,t),end:Sr(oi(p.end,{x:p.start.dx,y:p.start.dy}),t)}))}function Dd(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}function jd(e,t){return t.map(r=>Dd(e,r)).sort((r,s)=>r-s)}function mi(e,t,r,s){const o=(s.y-r.y)*(t.x-e.x)-(s.x-r.x)*(t.y-e.y);if(o===0)return null;let d=e.y-r.y,f=e.x-r.x;const g=(s.x-r.x)*d-(s.y-r.y)*f,p=(t.x-e.x)*d-(t.y-e.y)*f;return d=g/o,f=p/o,d>0&&d<1&&f>0&&f<1?{x:e.x+d*(t.x-e.x),y:e.y+d*(t.y-e.y)}:null}function Or(e,t,r){const s=[],o=ci(e,r,1e4);for(const d of t){const f=mi(e,o,d.start,d.end);f&&s.push(f)}return s.length?s.reduce((d,f)=>{const g=ui(e,f),p=ui(e,d);return g<p?f:d}):null}function Ud(e,t,r){const s=jd(e,r),o=[];for(const d of s){const f=Or(e,t,d-.001),g=Or(e,t,d+.001);f&&o.push(f),g&&o.push(g)}return o}class Ir{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(r=>r!==t)}}publish(t){this.subscribers.forEach(r=>r(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}a.PubSubChannel=Ir;class Pd{constructor(t,r){this.queue=[],this.running=0,this.onProcessed=new Ir,this.onDrained=new Ir,this.concurrency=t,this.capacity=r}process(){if(this.running>=this.concurrency)return;const t=this.queue.shift();t&&(this.running++,t().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),this.running===0&&this.onDrained.publish()}))}enqueue(t){if(this.queue.length<this.capacity)return this.queue.push(t),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(r=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),r())})})}drain(){if(this.running===0)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(t=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),t()})})}}a.AsyncQueue=Pd,a.Binary={hexToUint8Array:Fc,uint8ArrayToHex:Vc,base64ToUint8Array:Zc,uint8ArrayToBase64:Bc,base32ToUint8Array:Lc,uint8ArrayToBase32:zc,log2Reduce:Vs,partition:Er,concatBytes:Ue,numberToUint8:Kl,uint8ToNumber:Yl,numberToUint16:Ql,uint16ToNumber:Xl,numberToUint32:Jl,uint32ToNumber:ed,numberToUint64:kr,uint64ToNumber:td,numberToUint256:Pe,uint256ToNumber:Ze,sliceBytes:rd,keccak256:oe,sha3_256:sd,proximity:id,commonPrefix:ad,setBit:od,getBit:cd,indexOf:ud,equals:hd,padStart:Js,padStartToMultiple:ld,padEnd:ei,padEndToMultiple:dd,xorCypher:fd},a.Elliptic={privateKeyToPublicKey:pd,compressPublicKey:gd,publicKeyFromCompressed:yd,publicKeyToAddress:vd,signMessage:_d,signHash:ri,verifySignature:xd,recoverPublicKey:bd,checksumEncode:wd},a.Random={intBetween:st,floatBetween:qn,chance:Gn,signed:ja,makeSeededRng:tr,point:Pa,procs:Za},a.Arrays={countUnique:Il,makeUnique:Ol,splitBySize:Al,splitByCount:Bs,index:Zs,indexCollection:Tl,onlyOrThrow:m,onlyOrNull:w,firstOrThrow:E,firstOrNull:v,shuffle:h,initialize:D,initialize2D:ae,rotate2D:ie,containsShape:nt,glue:Go,pluck:er,pick:rr,pickMany:Ba,pickManyUnique:La,pickWeighted:Va,pickRandomIndices:Ne,pickGuaranteed:za,last:it,pipe:Kn,makePipe:Fa,sortWeighted:Wa,pushAll:Nt,unshiftAll:Ho,filterAndRemove:hu,merge:cl,empty:ul,pushToBucket:Fo,unshiftAndLimit:Vo,atRolling:Wo,group:xr,createOscillator:Ku,organiseWithLimits:Qu,tickPlaybook:kd,getArgument:Ft,getBooleanArgument:Td,getNumberArgument:Ed,requireStringArgument:ii,requireNumberArgument:Ad,bringToFront:Sd,bringToFrontInPlace:ai,findInstance:zl,filterInstances:Fl,interleave:Vl,toggle:Wl,createHierarchy:ql,multicall:Bl,maxBy:Ll},a.System={sleepMillis:l,forever:Qa,scheduleMany:tc,waitFor:fu,expandError:Zo,runAndSetInterval:Xa},a.Numbers={make:_r,sum:nc,average:sc,median:ic,getDistanceFromMidpoint:ac,clamp:br,range:cs,interpolate:rc,createSequence:Gu,increment:sl,decrement:il,format:nl,fromDecimals:rl,makeStorage:Pu,asMegabytes:Ja,convertBytes:eo,hexToRgb:to,rgbToHex:ro,haversineDistanceToMeters:no,roundToNearest:It,formatDistance:so,triangularNumber:io,searchFloat:ao},a.Promises={raceFulfilled:c,invert:i,runInParallelBatches:u},a.Dates={getTimestamp:xu,getTimeDelta:Ms,secondsToHumanTime:ku,countCycles:Eu,isoDate:gu,throttle:Tu,timeSince:Su,dateTimeSlug:yu,unixTimestamp:pu,fromUtcString:vu,fromMillis:wu,getProgress:Ou,humanizeTime:Ut,humanizeProgress:du,createTimeDigits:ee,mapDayNumber:$s,getDayInfoFromDate:vr,getDayInfoFromDateTimeString:Mu,seconds:$u,minutes:Cu,hours:Nu,days:Ru,make:ju,normalizeTime:_u,absoluteDays:Ee},a.Objects={safeParse:qu,deleteDeep:Ga,getDeep:be,setDeep:xe,incrementDeep:Ha,ensureDeep:qa,replaceDeep:Ka,getFirstDeep:Ya,deepMergeInPlace:ke,deepMerge2:Bo,deepMerge3:Lo,mapAllAsync:qo,cloneWithJson:mu,sortObject:Ns,sortArray:Rs,sortAny:Te,deepEquals:Ds,deepEqualsEvery:Hu,runOn:al,ifPresent:ol,zip:os,zipSum:zo,removeEmptyArrays:ll,removeEmptyValues:dl,flatten:kl,unflatten:Ps,match:El,sort:zs,map:ml,mapIterable:pl,filterKeys:fl,filterValues:hl,rethrow:gl,setSomeOnObject:yl,setSomeDeep:vl,flip:wl,getAllPermutations:_l,countTruthyValues:bl,transformToArray:Ml,setMulti:Cl,incrementMulti:$l,createBidirectionalMap:Nl,createTemporalBidirectionalMap:Rl,pushToBidirectionalMap:Fs,unshiftToBidirectionalMap:Dl,addToTemporalBidirectionalMap:jl,getFromTemporalBidirectionalMap:Ul,createStatefulToggle:Yu,diffKeys:Xu,pickRandomKey:js,mapRandomKey:Ju,fromObjectString:el,toQueryString:Os,parseQueryString:nu,hasKey:su,selectMax:iu,reposition:au,unwrapSingleKey:ou,parseKeyValues:cu},a.Types={isFunction:sr,isObject:he,isStrictlyObject:Re,isEmptyArray:Yn,isEmptyObject:oo,isUndefined:nr,isString:V,isNumber:me,isBoolean:Qn,isDate:De,isBlank:Mt,isId:ir,isIntegerString:Xn,isHexString:Jn,isUrl:is,isNullable:Do,asString:ns,asHexString:bo,asSafeString:xo,asIntegerString:_o,asNumber:$t,asFunction:ko,asInteger:cr,asBoolean:Eo,asDate:To,asNullableString:Ao,asEmptiableString:So,asId:Oo,asTime:Io,asArray:Mo,asObject:Ct,asNullableObject:$o,asStringMap:Co,asNumericDictionary:No,asUrl:Ro,asNullable:jo,asOptional:Uo,enforceObjectShape:as,enforceArrayShape:Po,isPng:Ws,isJpg:Hs,isWebp:qs,isImage:Gl},a.Strings={tokenizeByCount:Sl,tokenizeByLength:Ls,searchHex:yo,searchSubstring:vo,randomHex:wo,randomLetter:ho,randomAlphanumeric:mo,randomRichAscii:po,randomUnicode:go,includesAny:oc,slugify:ur,normalForm:uc,enumify:pc,escapeHtml:yc,decodeHtmlEntities:wc,after:lr,afterLast:ls,before:us,beforeLast:dr,betweenWide:_c,betweenNarrow:bc,getPreLine:Zu,containsWord:gr,containsWords:Jc,joinUrl:Cs,getFuzzyMatchScore:Rt,sortByFuzzyScore:gc,splitOnce:fr,splitAll:ds,randomize:Tc,expand:fs,shrinkTrim:ot,capitalize:Dt,decapitalize:hs,csvEscape:$c,parseCsv:lu,surroundInOut:mc,getExtension:hr,getBasename:mr,normalizeEmail:xc,normalizeFilename:kc,parseFilename:Ec,camelToTitle:lc,slugToTitle:dc,slugToCamel:fc,joinHumanly:hc,findWeightedPair:ws,extractBlock:_s,extractAllBlocks:Rc,replaceBlocks:Dc,indexOfEarliest:je,lastIndexOfBefore:vs,parseHtmlAttributes:eu,readNextWord:jt,resolveVariables:tu,resolveVariableWithDefaultSyntax:As,resolveRemainingVariablesWithDefaults:Ss,isLetter:ms,isDigit:ps,isLetterOrDigit:ct,isValidObjectPathCharacter:Oc,insert:Ic,indexOfRegex:gs,lineMatches:ys,linesMatchInOrder:Mc,represent:at,resolveMarkdownLinks:ru,buildUrl:uu,isChinese:cc,replaceBetweenStrings:zu,describeMarkdown:Fu,isBalanced:Vu,textToFormat:Wu,splitFormatting:jc,splitHashtags:Uc,splitUrls:Pc,route:Wc,explodeReplace:pr,generateVariants:Hc,replaceWord:qc,replacePascalCaseWords:Gc,stripHtml:Kc,breakLine:Ts,measureTextWidth:Yc,toLines:Qc,levenshteinDistance:Xc},a.Assertions={asEqual:Ko,asTrue:Yo,asTruthy:Qo,asFalse:Xo,asFalsy:Jo,asEither:ec},a.Cache={get:Bu,invalidate:Lu},a.Vector={addPoint:oi,subtractPoint:Od,multiplyPoint:Sr,normalizePoint:Id,pushPoint:ci,filterCoordinates:lt,findCorners:Nd,findLines:Rd,raycast:Or,raycastCircle:Ud,getLineIntersectionPoint:mi}})(On);const N=wi(On);N.Arrays,N.Assertions;const Z=N.Binary;N.Cache,N.Dates,N.Elliptic,N.Numbers,N.Objects,N.Pagination,N.Promises,N.Random,N.Strings,N.System,N.Types,N.Optional,N.Vector,N.PubSubChannel,N.Chunk;const _i=N.MerkleTree;N.FixedPointNumber,N.Lazy,N.AsyncLazy,N.AsyncQueue,N.Uint8ArrayReader,N.Uint8ArrayWriter;const bi=new TextEncoder,In=1,Mn=4096,Wt=4096,xi=32;function $n(a,n){return n=typeof n=="number"?S.FeedIndex.fromBigInt(BigInt(n)):n,new S.Identifier(Z.keccak256(Z.concatBytes(a.toUint8Array(),n.toUint8Array())))}function ki(a){const n=a.slice(0,S.Span.LENGTH),i=a.slice(S.Span.LENGTH),c=Ei(i),u=Z.keccak256(Z.concatBytes(n,c));return new S.Reference(u)}function Ei(a){if(a.length>Wt)throw new S.BeeArgumentError(`payload size ${a.length} exceeds maximum chunk payload size ${Wt}`,a);const n=new Uint8Array(Wt);return n.set(a),Z.log2Reduce(Z.partition(n,xi),(i,c)=>Z.keccak256(Z.concatBytes(i,c)))}function Cn(a){if(a instanceof Uint8Array||(a=bi.encode(a)),a.length<In||a.length>Mn)throw new RangeError(`payload size ${a.length} exceeds limits [${In}, ${Mn}]`);const n=S.Span.fromBigInt(BigInt(a.length)),i=Z.concatBytes(n.toUint8Array(),a);return{data:i,span:n,payload:S.Bytes.fromSlice(i,S.Span.LENGTH),address:ki(i)}}function Ti(a,n){return new S.Reference(Z.keccak256(Z.concatBytes(a.toUint8Array(),n.toUint8Array())))}function Nn(a,n,i){n=new S.Identifier(n),i=new S.PrivateKey(i);const c=Ti(n,i.publicKey().address()),u=i.sign(Z.concatBytes(n.toUint8Array(),a.address.toUint8Array())),l=Z.concatBytes(n.toUint8Array(),u.toUint8Array(),a.data),h=S.Span.fromSlice(a.data,0),m=S.Bytes.fromSlice(a.data,S.Span.LENGTH);return{data:l,identifier:n,signature:u,span:h,payload:m,address:c,owner:i.publicKey().address()}}function Ht(a){return(a.startsWith("0x")?a.slice(2):a).toLowerCase()}class K{constructor(){}static getInstance(){return K.instance||(K.instance=new K),K.instance}formatMessage(n,...i){return`[${new Date().toISOString()}] [${n.toUpperCase()}] - ${i.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ")}`}log(...n){console.log(this.formatMessage("log",...n))}info(...n){console.info(this.formatMessage("info",...n))}warn(...n){console.warn(this.formatMessage("warn",...n))}error(...n){console.error(this.formatMessage("error",...n))}debug(...n){console.debug(this.formatMessage("debug",...n))}}class qt{constructor(){this.logger=K.getInstance()}handleError(n,i){const c=n instanceof Error?n.message:"Unknown error occurred",u=n instanceof Error?n.stack:null;this.logger.error(`Error in ${i||"unknown context"}: ${c}`,{stack:u})}}class Ai{constructor(){this.events={},this.on=this.on.bind(this),this.off=this.off.bind(this),this.cleanAll=this.cleanAll.bind(this),this.emit=this.emit.bind(this)}on(n,i){this.events[n]||(this.events[n]=[]),this.events[n].push(i)}off(n,i){if(!this.events[n])return;const c=this.events[n].indexOf(i);c>-1&&this.events[n].splice(c,1)}cleanAll(){this.events={}}emit(n,i){this.events[n]&&this.events[n].forEach(c=>c(i))}}var M;(function(a){a.assertEqual=u=>u;function n(u){}a.assertIs=n;function i(u){throw new Error}a.assertNever=i,a.arrayToEnum=u=>{const l={};for(const h of u)l[h]=h;return l},a.getValidEnumValues=u=>{const l=a.objectKeys(u).filter(m=>typeof u[u[m]]!="number"),h={};for(const m of l)h[m]=u[m];return a.objectValues(h)},a.objectValues=u=>a.objectKeys(u).map(function(l){return u[l]}),a.objectKeys=typeof Object.keys=="function"?u=>Object.keys(u):u=>{const l=[];for(const h in u)Object.prototype.hasOwnProperty.call(u,h)&&l.push(h);return l},a.find=(u,l)=>{for(const h of u)if(l(h))return h},a.isInteger=typeof Number.isInteger=="function"?u=>Number.isInteger(u):u=>typeof u=="number"&&isFinite(u)&&Math.floor(u)===u;function c(u,l=" | "){return u.map(h=>typeof h=="string"?`'${h}'`:h).join(l)}a.joinValues=c,a.jsonStringifyReplacer=(u,l)=>typeof l=="bigint"?l.toString():l})(M||(M={}));var Gt;(function(a){a.mergeShapes=(n,i)=>({...n,...i})})(Gt||(Gt={}));const b=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),re=a=>{switch(typeof a){case"undefined":return b.undefined;case"string":return b.string;case"number":return isNaN(a)?b.nan:b.number;case"boolean":return b.boolean;case"function":return b.function;case"bigint":return b.bigint;case"symbol":return b.symbol;case"object":return Array.isArray(a)?b.array:a===null?b.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?b.promise:typeof Map<"u"&&a instanceof Map?b.map:typeof Set<"u"&&a instanceof Set?b.set:typeof Date<"u"&&a instanceof Date?b.date:b.object;default:return b.unknown}},y=M.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Si=a=>JSON.stringify(a,null,2).replace(/"([^"]+)":/g,"$1:");class F extends Error{get errors(){return this.issues}constructor(n){super(),this.issues=[],this.addIssue=c=>{this.issues=[...this.issues,c]},this.addIssues=(c=[])=>{this.issues=[...this.issues,...c]};const i=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,i):this.__proto__=i,this.name="ZodError",this.issues=n}format(n){const i=n||function(l){return l.message},c={_errors:[]},u=l=>{for(const h of l.issues)if(h.code==="invalid_union")h.unionErrors.map(u);else if(h.code==="invalid_return_type")u(h.returnTypeError);else if(h.code==="invalid_arguments")u(h.argumentsError);else if(h.path.length===0)c._errors.push(i(h));else{let m=c,w=0;for(;w<h.path.length;){const v=h.path[w];w===h.path.length-1?(m[v]=m[v]||{_errors:[]},m[v]._errors.push(i(h))):m[v]=m[v]||{_errors:[]},m=m[v],w++}}};return u(this),c}static assert(n){if(!(n instanceof F))throw new Error(`Not a ZodError: ${n}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(n=i=>i.message){const i={},c=[];for(const u of this.issues)u.path.length>0?(i[u.path[0]]=i[u.path[0]]||[],i[u.path[0]].push(n(u))):c.push(n(u));return{formErrors:c,fieldErrors:i}}get formErrors(){return this.flatten()}}F.create=a=>new F(a);const Se=(a,n)=>{let i;switch(a.code){case y.invalid_type:a.received===b.undefined?i="Required":i=`Expected ${a.expected}, received ${a.received}`;break;case y.invalid_literal:i=`Invalid literal value, expected ${JSON.stringify(a.expected,M.jsonStringifyReplacer)}`;break;case y.unrecognized_keys:i=`Unrecognized key(s) in object: ${M.joinValues(a.keys,", ")}`;break;case y.invalid_union:i="Invalid input";break;case y.invalid_union_discriminator:i=`Invalid discriminator value. Expected ${M.joinValues(a.options)}`;break;case y.invalid_enum_value:i=`Invalid enum value. Expected ${M.joinValues(a.options)}, received '${a.received}'`;break;case y.invalid_arguments:i="Invalid function arguments";break;case y.invalid_return_type:i="Invalid function return type";break;case y.invalid_date:i="Invalid date";break;case y.invalid_string:typeof a.validation=="object"?"includes"in a.validation?(i=`Invalid input: must include "${a.validation.includes}"`,typeof a.validation.position=="number"&&(i=`${i} at one or more positions greater than or equal to ${a.validation.position}`)):"startsWith"in a.validation?i=`Invalid input: must start with "${a.validation.startsWith}"`:"endsWith"in a.validation?i=`Invalid input: must end with "${a.validation.endsWith}"`:M.assertNever(a.validation):a.validation!=="regex"?i=`Invalid ${a.validation}`:i="Invalid";break;case y.too_small:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at least":"more than"} ${a.minimum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at least":"over"} ${a.minimum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${a.minimum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(a.minimum))}`:i="Invalid input";break;case y.too_big:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at most":"less than"} ${a.maximum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at most":"under"} ${a.maximum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="bigint"?i=`BigInt must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly":a.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(a.maximum))}`:i="Invalid input";break;case y.custom:i="Invalid input";break;case y.invalid_intersection_types:i="Intersection results could not be merged";break;case y.not_multiple_of:i=`Number must be a multiple of ${a.multipleOf}`;break;case y.not_finite:i="Number must be finite";break;default:i=n.defaultError,M.assertNever(a)}return{message:i}};let Rn=Se;function Oi(a){Rn=a}function bt(){return Rn}const xt=a=>{const{data:n,path:i,errorMaps:c,issueData:u}=a,l=[...i,...u.path||[]],h={...u,path:l};if(u.message!==void 0)return{...u,path:l,message:u.message};let m="";const w=c.filter(v=>!!v).slice().reverse();for(const v of w)m=v(h,{data:n,defaultError:m}).message;return{...u,path:l,message:m}},Ii=[];function _(a,n){const i=bt(),c=xt({issueData:n,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,i,i===Se?void 0:Se].filter(u=>!!u)});a.common.issues.push(c)}class B{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(n,i){const c=[];for(const u of i){if(u.status==="aborted")return A;u.status==="dirty"&&n.dirty(),c.push(u.value)}return{status:n.value,value:c}}static async mergeObjectAsync(n,i){const c=[];for(const u of i){const l=await u.key,h=await u.value;c.push({key:l,value:h})}return B.mergeObjectSync(n,c)}static mergeObjectSync(n,i){const c={};for(const u of i){const{key:l,value:h}=u;if(l.status==="aborted"||h.status==="aborted")return A;l.status==="dirty"&&n.dirty(),h.status==="dirty"&&n.dirty(),l.value!=="__proto__"&&(typeof h.value<"u"||u.alwaysSet)&&(c[l.value]=h.value)}return{status:n.value,value:c}}}const A=Object.freeze({status:"aborted"}),Oe=a=>({status:"dirty",value:a}),z=a=>({status:"valid",value:a}),Kt=a=>a.status==="aborted",Yt=a=>a.status==="dirty",ye=a=>a.status==="valid",Le=a=>typeof Promise<"u"&&a instanceof Promise;function kt(a,n,i,c){if(typeof n=="function"?a!==n||!c:!n.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n.get(a)}function Dn(a,n,i,c,u){if(typeof n=="function"?a!==n||!u:!n.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n.set(a,i),i}typeof SuppressedError=="function"&&SuppressedError;var x;(function(a){a.errToObj=n=>typeof n=="string"?{message:n}:n||{},a.toString=n=>typeof n=="string"?n:n==null?void 0:n.message})(x||(x={}));var ze,Fe;class Y{constructor(n,i,c,u){this._cachedPath=[],this.parent=n,this.data=i,this._path=c,this._key=u}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const jn=(a,n)=>{if(ye(n))return{success:!0,data:n.value};if(!a.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const i=new F(a.common.issues);return this._error=i,this._error}}};function O(a){if(!a)return{};const{errorMap:n,invalid_type_error:i,required_error:c,description:u}=a;if(n&&(i||c))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return n?{errorMap:n,description:u}:{errorMap:(h,m)=>{var w,v;const{message:E}=a;return h.code==="invalid_enum_value"?{message:E??m.defaultError}:typeof m.data>"u"?{message:(w=E??c)!==null&&w!==void 0?w:m.defaultError}:h.code!=="invalid_type"?{message:m.defaultError}:{message:(v=E??i)!==null&&v!==void 0?v:m.defaultError}},description:u}}class I{get description(){return this._def.description}_getType(n){return re(n.data)}_getOrReturnCtx(n,i){return i||{common:n.parent.common,data:n.data,parsedType:re(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}_processInputParams(n){return{status:new B,ctx:{common:n.parent.common,data:n.data,parsedType:re(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}}_parseSync(n){const i=this._parse(n);if(Le(i))throw new Error("Synchronous parse encountered promise.");return i}_parseAsync(n){const i=this._parse(n);return Promise.resolve(i)}parse(n,i){const c=this.safeParse(n,i);if(c.success)return c.data;throw c.error}safeParse(n,i){var c;const u={common:{issues:[],async:(c=i==null?void 0:i.async)!==null&&c!==void 0?c:!1,contextualErrorMap:i==null?void 0:i.errorMap},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:re(n)},l=this._parseSync({data:n,path:u.path,parent:u});return jn(u,l)}"~validate"(n){var i,c;const u={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:re(n)};if(!this["~standard"].async)try{const l=this._parseSync({data:n,path:[],parent:u});return ye(l)?{value:l.value}:{issues:u.common.issues}}catch(l){!((c=(i=l==null?void 0:l.message)===null||i===void 0?void 0:i.toLowerCase())===null||c===void 0)&&c.includes("encountered")&&(this["~standard"].async=!0),u.common={issues:[],async:!0}}return this._parseAsync({data:n,path:[],parent:u}).then(l=>ye(l)?{value:l.value}:{issues:u.common.issues})}async parseAsync(n,i){const c=await this.safeParseAsync(n,i);if(c.success)return c.data;throw c.error}async safeParseAsync(n,i){const c={common:{issues:[],contextualErrorMap:i==null?void 0:i.errorMap,async:!0},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:re(n)},u=this._parse({data:n,path:c.path,parent:c}),l=await(Le(u)?u:Promise.resolve(u));return jn(c,l)}refine(n,i){const c=u=>typeof i=="string"||typeof i>"u"?{message:i}:typeof i=="function"?i(u):i;return this._refinement((u,l)=>{const h=n(u),m=()=>l.addIssue({code:y.custom,...c(u)});return typeof Promise<"u"&&h instanceof Promise?h.then(w=>w?!0:(m(),!1)):h?!0:(m(),!1)})}refinement(n,i){return this._refinement((c,u)=>n(c)?!0:(u.addIssue(typeof i=="function"?i(c,u):i),!1))}_refinement(n){return new q({schema:this,typeName:T.ZodEffects,effect:{type:"refinement",refinement:n}})}superRefine(n){return this._refinement(n)}constructor(n){this.spa=this.safeParseAsync,this._def=n,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:i=>this["~validate"](i)}}optional(){return X.create(this,this._def)}nullable(){return fe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return H.create(this)}promise(){return Ce.create(this,this._def)}or(n){return qe.create([this,n],this._def)}and(n){return Ge.create(this,n,this._def)}transform(n){return new q({...O(this._def),schema:this,typeName:T.ZodEffects,effect:{type:"transform",transform:n}})}default(n){const i=typeof n=="function"?n:()=>n;return new Je({...O(this._def),innerType:this,defaultValue:i,typeName:T.ZodDefault})}brand(){return new Jt({typeName:T.ZodBranded,type:this,...O(this._def)})}catch(n){const i=typeof n=="function"?n:()=>n;return new et({...O(this._def),innerType:this,catchValue:i,typeName:T.ZodCatch})}describe(n){const i=this.constructor;return new i({...this._def,description:n})}pipe(n){return tt.create(this,n)}readonly(){return rt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Mi=/^c[^\s-]{8,}$/i,$i=/^[0-9a-z]+$/,Ci=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ni=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Ri=/^[a-z0-9_-]{21}$/i,Di=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ji=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Ui=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Pi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Qt;const Zi=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Bi=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Li=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,zi=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Fi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Vi=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Un="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Wi=new RegExp(`^${Un}$`);function Pn(a){let n="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?n=`${n}\\.\\d{${a.precision}}`:a.precision==null&&(n=`${n}(\\.\\d+)?`),n}function Hi(a){return new RegExp(`^${Pn(a)}$`)}function Zn(a){let n=`${Un}T${Pn(a)}`;const i=[];return i.push(a.local?"Z?":"Z"),a.offset&&i.push("([+-]\\d{2}:?\\d{2})"),n=`${n}(${i.join("|")})`,new RegExp(`^${n}$`)}function qi(a,n){return!!((n==="v4"||!n)&&Zi.test(a)||(n==="v6"||!n)&&Li.test(a))}function Gi(a,n){if(!Di.test(a))return!1;try{const[i]=a.split("."),c=i.replace(/-/g,"+").replace(/_/g,"/").padEnd(i.length+(4-i.length%4)%4,"="),u=JSON.parse(atob(c));return!(typeof u!="object"||u===null||!u.typ||!u.alg||n&&u.alg!==n)}catch{return!1}}function Ki(a,n){return!!((n==="v4"||!n)&&Bi.test(a)||(n==="v6"||!n)&&zi.test(a))}class W extends I{_parse(n){if(this._def.coerce&&(n.data=String(n.data)),this._getType(n)!==b.string){const l=this._getOrReturnCtx(n);return _(l,{code:y.invalid_type,expected:b.string,received:l.parsedType}),A}const c=new B;let u;for(const l of this._def.checks)if(l.kind==="min")n.data.length<l.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="max")n.data.length>l.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!1,message:l.message}),c.dirty());else if(l.kind==="length"){const h=n.data.length>l.value,m=n.data.length<l.value;(h||m)&&(u=this._getOrReturnCtx(n,u),h?_(u,{code:y.too_big,maximum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}):m&&_(u,{code:y.too_small,minimum:l.value,type:"string",inclusive:!0,exact:!0,message:l.message}),c.dirty())}else if(l.kind==="email")Ui.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"email",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="emoji")Qt||(Qt=new RegExp(Pi,"u")),Qt.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"emoji",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="uuid")Ni.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"uuid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="nanoid")Ri.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"nanoid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid")Mi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"cuid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="cuid2")$i.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"cuid2",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="ulid")Ci.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"ulid",code:y.invalid_string,message:l.message}),c.dirty());else if(l.kind==="url")try{new URL(n.data)}catch{u=this._getOrReturnCtx(n,u),_(u,{validation:"url",code:y.invalid_string,message:l.message}),c.dirty()}else l.kind==="regex"?(l.regex.lastIndex=0,l.regex.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"regex",code:y.invalid_string,message:l.message}),c.dirty())):l.kind==="trim"?n.data=n.data.trim():l.kind==="includes"?n.data.includes(l.value,l.position)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:{includes:l.value,position:l.position},message:l.message}),c.dirty()):l.kind==="toLowerCase"?n.data=n.data.toLowerCase():l.kind==="toUpperCase"?n.data=n.data.toUpperCase():l.kind==="startsWith"?n.data.startsWith(l.value)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:{startsWith:l.value},message:l.message}),c.dirty()):l.kind==="endsWith"?n.data.endsWith(l.value)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:{endsWith:l.value},message:l.message}),c.dirty()):l.kind==="datetime"?Zn(l).test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:"datetime",message:l.message}),c.dirty()):l.kind==="date"?Wi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:"date",message:l.message}),c.dirty()):l.kind==="time"?Hi(l).test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:"time",message:l.message}),c.dirty()):l.kind==="duration"?ji.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"duration",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="ip"?qi(n.data,l.version)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"ip",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="jwt"?Gi(n.data,l.alg)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"jwt",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="cidr"?Ki(n.data,l.version)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"cidr",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="base64"?Fi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"base64",code:y.invalid_string,message:l.message}),c.dirty()):l.kind==="base64url"?Vi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"base64url",code:y.invalid_string,message:l.message}),c.dirty()):M.assertNever(l);return{status:c.value,value:n.data}}_regex(n,i,c){return this.refinement(u=>n.test(u),{validation:i,code:y.invalid_string,...x.errToObj(c)})}_addCheck(n){return new W({...this._def,checks:[...this._def.checks,n]})}email(n){return this._addCheck({kind:"email",...x.errToObj(n)})}url(n){return this._addCheck({kind:"url",...x.errToObj(n)})}emoji(n){return this._addCheck({kind:"emoji",...x.errToObj(n)})}uuid(n){return this._addCheck({kind:"uuid",...x.errToObj(n)})}nanoid(n){return this._addCheck({kind:"nanoid",...x.errToObj(n)})}cuid(n){return this._addCheck({kind:"cuid",...x.errToObj(n)})}cuid2(n){return this._addCheck({kind:"cuid2",...x.errToObj(n)})}ulid(n){return this._addCheck({kind:"ulid",...x.errToObj(n)})}base64(n){return this._addCheck({kind:"base64",...x.errToObj(n)})}base64url(n){return this._addCheck({kind:"base64url",...x.errToObj(n)})}jwt(n){return this._addCheck({kind:"jwt",...x.errToObj(n)})}ip(n){return this._addCheck({kind:"ip",...x.errToObj(n)})}cidr(n){return this._addCheck({kind:"cidr",...x.errToObj(n)})}datetime(n){var i,c;return typeof n=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:n}):this._addCheck({kind:"datetime",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,offset:(i=n==null?void 0:n.offset)!==null&&i!==void 0?i:!1,local:(c=n==null?void 0:n.local)!==null&&c!==void 0?c:!1,...x.errToObj(n==null?void 0:n.message)})}date(n){return this._addCheck({kind:"date",message:n})}time(n){return typeof n=="string"?this._addCheck({kind:"time",precision:null,message:n}):this._addCheck({kind:"time",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,...x.errToObj(n==null?void 0:n.message)})}duration(n){return this._addCheck({kind:"duration",...x.errToObj(n)})}regex(n,i){return this._addCheck({kind:"regex",regex:n,...x.errToObj(i)})}includes(n,i){return this._addCheck({kind:"includes",value:n,position:i==null?void 0:i.position,...x.errToObj(i==null?void 0:i.message)})}startsWith(n,i){return this._addCheck({kind:"startsWith",value:n,...x.errToObj(i)})}endsWith(n,i){return this._addCheck({kind:"endsWith",value:n,...x.errToObj(i)})}min(n,i){return this._addCheck({kind:"min",value:n,...x.errToObj(i)})}max(n,i){return this._addCheck({kind:"max",value:n,...x.errToObj(i)})}length(n,i){return this._addCheck({kind:"length",value:n,...x.errToObj(i)})}nonempty(n){return this.min(1,x.errToObj(n))}trim(){return new W({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new W({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new W({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(n=>n.kind==="datetime")}get isDate(){return!!this._def.checks.find(n=>n.kind==="date")}get isTime(){return!!this._def.checks.find(n=>n.kind==="time")}get isDuration(){return!!this._def.checks.find(n=>n.kind==="duration")}get isEmail(){return!!this._def.checks.find(n=>n.kind==="email")}get isURL(){return!!this._def.checks.find(n=>n.kind==="url")}get isEmoji(){return!!this._def.checks.find(n=>n.kind==="emoji")}get isUUID(){return!!this._def.checks.find(n=>n.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(n=>n.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(n=>n.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(n=>n.kind==="cuid2")}get isULID(){return!!this._def.checks.find(n=>n.kind==="ulid")}get isIP(){return!!this._def.checks.find(n=>n.kind==="ip")}get isCIDR(){return!!this._def.checks.find(n=>n.kind==="cidr")}get isBase64(){return!!this._def.checks.find(n=>n.kind==="base64")}get isBase64url(){return!!this._def.checks.find(n=>n.kind==="base64url")}get minLength(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxLength(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}W.create=a=>{var n;return new W({checks:[],typeName:T.ZodString,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};function Yi(a,n){const i=(a.toString().split(".")[1]||"").length,c=(n.toString().split(".")[1]||"").length,u=i>c?i:c,l=parseInt(a.toFixed(u).replace(".","")),h=parseInt(n.toFixed(u).replace(".",""));return l%h/Math.pow(10,u)}class ue extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(n){if(this._def.coerce&&(n.data=Number(n.data)),this._getType(n)!==b.number){const l=this._getOrReturnCtx(n);return _(l,{code:y.invalid_type,expected:b.number,received:l.parsedType}),A}let c;const u=new B;for(const l of this._def.checks)l.kind==="int"?M.isInteger(n.data)||(c=this._getOrReturnCtx(n,c),_(c,{code:y.invalid_type,expected:"integer",received:"float",message:l.message}),u.dirty()):l.kind==="min"?(l.inclusive?n.data<l.value:n.data<=l.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_small,minimum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?n.data>l.value:n.data>=l.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_big,maximum:l.value,type:"number",inclusive:l.inclusive,exact:!1,message:l.message}),u.dirty()):l.kind==="multipleOf"?Yi(n.data,l.value)!==0&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):l.kind==="finite"?Number.isFinite(n.data)||(c=this._getOrReturnCtx(n,c),_(c,{code:y.not_finite,message:l.message}),u.dirty()):M.assertNever(l);return{status:u.value,value:n.data}}gte(n,i){return this.setLimit("min",n,!0,x.toString(i))}gt(n,i){return this.setLimit("min",n,!1,x.toString(i))}lte(n,i){return this.setLimit("max",n,!0,x.toString(i))}lt(n,i){return this.setLimit("max",n,!1,x.toString(i))}setLimit(n,i,c,u){return new ue({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(n){return new ue({...this._def,checks:[...this._def.checks,n]})}int(n){return this._addCheck({kind:"int",message:x.toString(n)})}positive(n){return this._addCheck({kind:"min",value:0,inclusive:!1,message:x.toString(n)})}negative(n){return this._addCheck({kind:"max",value:0,inclusive:!1,message:x.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:0,inclusive:!0,message:x.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:0,inclusive:!0,message:x.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:x.toString(i)})}finite(n){return this._addCheck({kind:"finite",message:x.toString(n)})}safe(n){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:x.toString(n)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:x.toString(n)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}get isInt(){return!!this._def.checks.find(n=>n.kind==="int"||n.kind==="multipleOf"&&M.isInteger(n.value))}get isFinite(){let n=null,i=null;for(const c of this._def.checks){if(c.kind==="finite"||c.kind==="int"||c.kind==="multipleOf")return!0;c.kind==="min"?(i===null||c.value>i)&&(i=c.value):c.kind==="max"&&(n===null||c.value<n)&&(n=c.value)}return Number.isFinite(i)&&Number.isFinite(n)}}ue.create=a=>new ue({checks:[],typeName:T.ZodNumber,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class le extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(n){if(this._def.coerce)try{n.data=BigInt(n.data)}catch{return this._getInvalidInput(n)}if(this._getType(n)!==b.bigint)return this._getInvalidInput(n);let c;const u=new B;for(const l of this._def.checks)l.kind==="min"?(l.inclusive?n.data<l.value:n.data<=l.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_small,type:"bigint",minimum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="max"?(l.inclusive?n.data>l.value:n.data>=l.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_big,type:"bigint",maximum:l.value,inclusive:l.inclusive,message:l.message}),u.dirty()):l.kind==="multipleOf"?n.data%l.value!==BigInt(0)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.not_multiple_of,multipleOf:l.value,message:l.message}),u.dirty()):M.assertNever(l);return{status:u.value,value:n.data}}_getInvalidInput(n){const i=this._getOrReturnCtx(n);return _(i,{code:y.invalid_type,expected:b.bigint,received:i.parsedType}),A}gte(n,i){return this.setLimit("min",n,!0,x.toString(i))}gt(n,i){return this.setLimit("min",n,!1,x.toString(i))}lte(n,i){return this.setLimit("max",n,!0,x.toString(i))}lt(n,i){return this.setLimit("max",n,!1,x.toString(i))}setLimit(n,i,c,u){return new le({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(n){return new le({...this._def,checks:[...this._def.checks,n]})}positive(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:x.toString(n)})}negative(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:x.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:x.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:x.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:x.toString(i)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}le.create=a=>{var n;return new le({checks:[],typeName:T.ZodBigInt,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};class Ve extends I{_parse(n){if(this._def.coerce&&(n.data=!!n.data),this._getType(n)!==b.boolean){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.boolean,received:c.parsedType}),A}return z(n.data)}}Ve.create=a=>new Ve({typeName:T.ZodBoolean,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class ve extends I{_parse(n){if(this._def.coerce&&(n.data=new Date(n.data)),this._getType(n)!==b.date){const l=this._getOrReturnCtx(n);return _(l,{code:y.invalid_type,expected:b.date,received:l.parsedType}),A}if(isNaN(n.data.getTime())){const l=this._getOrReturnCtx(n);return _(l,{code:y.invalid_date}),A}const c=new B;let u;for(const l of this._def.checks)l.kind==="min"?n.data.getTime()<l.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_small,message:l.message,inclusive:!0,exact:!1,minimum:l.value,type:"date"}),c.dirty()):l.kind==="max"?n.data.getTime()>l.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_big,message:l.message,inclusive:!0,exact:!1,maximum:l.value,type:"date"}),c.dirty()):M.assertNever(l);return{status:c.value,value:new Date(n.data.getTime())}}_addCheck(n){return new ve({...this._def,checks:[...this._def.checks,n]})}min(n,i){return this._addCheck({kind:"min",value:n.getTime(),message:x.toString(i)})}max(n,i){return this._addCheck({kind:"max",value:n.getTime(),message:x.toString(i)})}get minDate(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n!=null?new Date(n):null}get maxDate(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n!=null?new Date(n):null}}ve.create=a=>new ve({checks:[],coerce:(a==null?void 0:a.coerce)||!1,typeName:T.ZodDate,...O(a)});class Et extends I{_parse(n){if(this._getType(n)!==b.symbol){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.symbol,received:c.parsedType}),A}return z(n.data)}}Et.create=a=>new Et({typeName:T.ZodSymbol,...O(a)});class We extends I{_parse(n){if(this._getType(n)!==b.undefined){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.undefined,received:c.parsedType}),A}return z(n.data)}}We.create=a=>new We({typeName:T.ZodUndefined,...O(a)});class He extends I{_parse(n){if(this._getType(n)!==b.null){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.null,received:c.parsedType}),A}return z(n.data)}}He.create=a=>new He({typeName:T.ZodNull,...O(a)});class Ie extends I{constructor(){super(...arguments),this._any=!0}_parse(n){return z(n.data)}}Ie.create=a=>new Ie({typeName:T.ZodAny,...O(a)});class we extends I{constructor(){super(...arguments),this._unknown=!0}_parse(n){return z(n.data)}}we.create=a=>new we({typeName:T.ZodUnknown,...O(a)});class ne extends I{_parse(n){const i=this._getOrReturnCtx(n);return _(i,{code:y.invalid_type,expected:b.never,received:i.parsedType}),A}}ne.create=a=>new ne({typeName:T.ZodNever,...O(a)});class Tt extends I{_parse(n){if(this._getType(n)!==b.undefined){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.void,received:c.parsedType}),A}return z(n.data)}}Tt.create=a=>new Tt({typeName:T.ZodVoid,...O(a)});class H extends I{_parse(n){const{ctx:i,status:c}=this._processInputParams(n),u=this._def;if(i.parsedType!==b.array)return _(i,{code:y.invalid_type,expected:b.array,received:i.parsedType}),A;if(u.exactLength!==null){const h=i.data.length>u.exactLength.value,m=i.data.length<u.exactLength.value;(h||m)&&(_(i,{code:h?y.too_big:y.too_small,minimum:m?u.exactLength.value:void 0,maximum:h?u.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:u.exactLength.message}),c.dirty())}if(u.minLength!==null&&i.data.length<u.minLength.value&&(_(i,{code:y.too_small,minimum:u.minLength.value,type:"array",inclusive:!0,exact:!1,message:u.minLength.message}),c.dirty()),u.maxLength!==null&&i.data.length>u.maxLength.value&&(_(i,{code:y.too_big,maximum:u.maxLength.value,type:"array",inclusive:!0,exact:!1,message:u.maxLength.message}),c.dirty()),i.common.async)return Promise.all([...i.data].map((h,m)=>u.type._parseAsync(new Y(i,h,i.path,m)))).then(h=>B.mergeArray(c,h));const l=[...i.data].map((h,m)=>u.type._parseSync(new Y(i,h,i.path,m)));return B.mergeArray(c,l)}get element(){return this._def.type}min(n,i){return new H({...this._def,minLength:{value:n,message:x.toString(i)}})}max(n,i){return new H({...this._def,maxLength:{value:n,message:x.toString(i)}})}length(n,i){return new H({...this._def,exactLength:{value:n,message:x.toString(i)}})}nonempty(n){return this.min(1,n)}}H.create=(a,n)=>new H({type:a,minLength:null,maxLength:null,exactLength:null,typeName:T.ZodArray,...O(n)});function Me(a){if(a instanceof R){const n={};for(const i in a.shape){const c=a.shape[i];n[i]=X.create(Me(c))}return new R({...a._def,shape:()=>n})}else return a instanceof H?new H({...a._def,type:Me(a.element)}):a instanceof X?X.create(Me(a.unwrap())):a instanceof fe?fe.create(Me(a.unwrap())):a instanceof Q?Q.create(a.items.map(n=>Me(n))):a}class R extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const n=this._def.shape(),i=M.objectKeys(n);return this._cached={shape:n,keys:i}}_parse(n){if(this._getType(n)!==b.object){const v=this._getOrReturnCtx(n);return _(v,{code:y.invalid_type,expected:b.object,received:v.parsedType}),A}const{status:c,ctx:u}=this._processInputParams(n),{shape:l,keys:h}=this._getCached(),m=[];if(!(this._def.catchall instanceof ne&&this._def.unknownKeys==="strip"))for(const v in u.data)h.includes(v)||m.push(v);const w=[];for(const v of h){const E=l[v],D=u.data[v];w.push({key:{status:"valid",value:v},value:E._parse(new Y(u,D,u.path,v)),alwaysSet:v in u.data})}if(this._def.catchall instanceof ne){const v=this._def.unknownKeys;if(v==="passthrough")for(const E of m)w.push({key:{status:"valid",value:E},value:{status:"valid",value:u.data[E]}});else if(v==="strict")m.length>0&&(_(u,{code:y.unrecognized_keys,keys:m}),c.dirty());else if(v!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const v=this._def.catchall;for(const E of m){const D=u.data[E];w.push({key:{status:"valid",value:E},value:v._parse(new Y(u,D,u.path,E)),alwaysSet:E in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const v=[];for(const E of w){const D=await E.key,ie=await E.value;v.push({key:D,value:ie,alwaysSet:E.alwaysSet})}return v}).then(v=>B.mergeObjectSync(c,v)):B.mergeObjectSync(c,w)}get shape(){return this._def.shape()}strict(n){return x.errToObj,new R({...this._def,unknownKeys:"strict",...n!==void 0?{errorMap:(i,c)=>{var u,l,h,m;const w=(h=(l=(u=this._def).errorMap)===null||l===void 0?void 0:l.call(u,i,c).message)!==null&&h!==void 0?h:c.defaultError;return i.code==="unrecognized_keys"?{message:(m=x.errToObj(n).message)!==null&&m!==void 0?m:w}:{message:w}}}:{}})}strip(){return new R({...this._def,unknownKeys:"strip"})}passthrough(){return new R({...this._def,unknownKeys:"passthrough"})}extend(n){return new R({...this._def,shape:()=>({...this._def.shape(),...n})})}merge(n){return new R({unknownKeys:n._def.unknownKeys,catchall:n._def.catchall,shape:()=>({...this._def.shape(),...n._def.shape()}),typeName:T.ZodObject})}setKey(n,i){return this.augment({[n]:i})}catchall(n){return new R({...this._def,catchall:n})}pick(n){const i={};return M.objectKeys(n).forEach(c=>{n[c]&&this.shape[c]&&(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}omit(n){const i={};return M.objectKeys(this.shape).forEach(c=>{n[c]||(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}deepPartial(){return Me(this)}partial(n){const i={};return M.objectKeys(this.shape).forEach(c=>{const u=this.shape[c];n&&!n[c]?i[c]=u:i[c]=u.optional()}),new R({...this._def,shape:()=>i})}required(n){const i={};return M.objectKeys(this.shape).forEach(c=>{if(n&&!n[c])i[c]=this.shape[c];else{let l=this.shape[c];for(;l instanceof X;)l=l._def.innerType;i[c]=l}}),new R({...this._def,shape:()=>i})}keyof(){return Bn(M.objectKeys(this.shape))}}R.create=(a,n)=>new R({shape:()=>a,unknownKeys:"strip",catchall:ne.create(),typeName:T.ZodObject,...O(n)}),R.strictCreate=(a,n)=>new R({shape:()=>a,unknownKeys:"strict",catchall:ne.create(),typeName:T.ZodObject,...O(n)}),R.lazycreate=(a,n)=>new R({shape:a,unknownKeys:"strip",catchall:ne.create(),typeName:T.ZodObject,...O(n)});class qe extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=this._def.options;function u(l){for(const m of l)if(m.result.status==="valid")return m.result;for(const m of l)if(m.result.status==="dirty")return i.common.issues.push(...m.ctx.common.issues),m.result;const h=l.map(m=>new F(m.ctx.common.issues));return _(i,{code:y.invalid_union,unionErrors:h}),A}if(i.common.async)return Promise.all(c.map(async l=>{const h={...i,common:{...i.common,issues:[]},parent:null};return{result:await l._parseAsync({data:i.data,path:i.path,parent:h}),ctx:h}})).then(u);{let l;const h=[];for(const w of c){const v={...i,common:{...i.common,issues:[]},parent:null},E=w._parseSync({data:i.data,path:i.path,parent:v});if(E.status==="valid")return E;E.status==="dirty"&&!l&&(l={result:E,ctx:v}),v.common.issues.length&&h.push(v.common.issues)}if(l)return i.common.issues.push(...l.ctx.common.issues),l.result;const m=h.map(w=>new F(w));return _(i,{code:y.invalid_union,unionErrors:m}),A}}get options(){return this._def.options}}qe.create=(a,n)=>new qe({options:a,typeName:T.ZodUnion,...O(n)});const se=a=>a instanceof Ye?se(a.schema):a instanceof q?se(a.innerType()):a instanceof Qe?[a.value]:a instanceof de?a.options:a instanceof Xe?M.objectValues(a.enum):a instanceof Je?se(a._def.innerType):a instanceof We?[void 0]:a instanceof He?[null]:a instanceof X?[void 0,...se(a.unwrap())]:a instanceof fe?[null,...se(a.unwrap())]:a instanceof Jt||a instanceof rt?se(a.unwrap()):a instanceof et?se(a._def.innerType):[];class At extends I{_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==b.object)return _(i,{code:y.invalid_type,expected:b.object,received:i.parsedType}),A;const c=this.discriminator,u=i.data[c],l=this.optionsMap.get(u);return l?i.common.async?l._parseAsync({data:i.data,path:i.path,parent:i}):l._parseSync({data:i.data,path:i.path,parent:i}):(_(i,{code:y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[c]}),A)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(n,i,c){const u=new Map;for(const l of i){const h=se(l.shape[n]);if(!h.length)throw new Error(`A discriminator value for key \`${n}\` could not be extracted from all schema options`);for(const m of h){if(u.has(m))throw new Error(`Discriminator property ${String(n)} has duplicate value ${String(m)}`);u.set(m,l)}}return new At({typeName:T.ZodDiscriminatedUnion,discriminator:n,options:i,optionsMap:u,...O(c)})}}function Xt(a,n){const i=re(a),c=re(n);if(a===n)return{valid:!0,data:a};if(i===b.object&&c===b.object){const u=M.objectKeys(n),l=M.objectKeys(a).filter(m=>u.indexOf(m)!==-1),h={...a,...n};for(const m of l){const w=Xt(a[m],n[m]);if(!w.valid)return{valid:!1};h[m]=w.data}return{valid:!0,data:h}}else if(i===b.array&&c===b.array){if(a.length!==n.length)return{valid:!1};const u=[];for(let l=0;l<a.length;l++){const h=a[l],m=n[l],w=Xt(h,m);if(!w.valid)return{valid:!1};u.push(w.data)}return{valid:!0,data:u}}else return i===b.date&&c===b.date&&+a==+n?{valid:!0,data:a}:{valid:!1}}class Ge extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=(l,h)=>{if(Kt(l)||Kt(h))return A;const m=Xt(l.value,h.value);return m.valid?((Yt(l)||Yt(h))&&i.dirty(),{status:i.value,value:m.data}):(_(c,{code:y.invalid_intersection_types}),A)};return c.common.async?Promise.all([this._def.left._parseAsync({data:c.data,path:c.path,parent:c}),this._def.right._parseAsync({data:c.data,path:c.path,parent:c})]).then(([l,h])=>u(l,h)):u(this._def.left._parseSync({data:c.data,path:c.path,parent:c}),this._def.right._parseSync({data:c.data,path:c.path,parent:c}))}}Ge.create=(a,n,i)=>new Ge({left:a,right:n,typeName:T.ZodIntersection,...O(i)});class Q extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.array)return _(c,{code:y.invalid_type,expected:b.array,received:c.parsedType}),A;if(c.data.length<this._def.items.length)return _(c,{code:y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),A;!this._def.rest&&c.data.length>this._def.items.length&&(_(c,{code:y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),i.dirty());const l=[...c.data].map((h,m)=>{const w=this._def.items[m]||this._def.rest;return w?w._parse(new Y(c,h,c.path,m)):null}).filter(h=>!!h);return c.common.async?Promise.all(l).then(h=>B.mergeArray(i,h)):B.mergeArray(i,l)}get items(){return this._def.items}rest(n){return new Q({...this._def,rest:n})}}Q.create=(a,n)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Q({items:a,typeName:T.ZodTuple,rest:null,...O(n)})};class Ke extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.object)return _(c,{code:y.invalid_type,expected:b.object,received:c.parsedType}),A;const u=[],l=this._def.keyType,h=this._def.valueType;for(const m in c.data)u.push({key:l._parse(new Y(c,m,c.path,m)),value:h._parse(new Y(c,c.data[m],c.path,m)),alwaysSet:m in c.data});return c.common.async?B.mergeObjectAsync(i,u):B.mergeObjectSync(i,u)}get element(){return this._def.valueType}static create(n,i,c){return i instanceof I?new Ke({keyType:n,valueType:i,typeName:T.ZodRecord,...O(c)}):new Ke({keyType:W.create(),valueType:n,typeName:T.ZodRecord,...O(i)})}}class St extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.map)return _(c,{code:y.invalid_type,expected:b.map,received:c.parsedType}),A;const u=this._def.keyType,l=this._def.valueType,h=[...c.data.entries()].map(([m,w],v)=>({key:u._parse(new Y(c,m,c.path,[v,"key"])),value:l._parse(new Y(c,w,c.path,[v,"value"]))}));if(c.common.async){const m=new Map;return Promise.resolve().then(async()=>{for(const w of h){const v=await w.key,E=await w.value;if(v.status==="aborted"||E.status==="aborted")return A;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),m.set(v.value,E.value)}return{status:i.value,value:m}})}else{const m=new Map;for(const w of h){const v=w.key,E=w.value;if(v.status==="aborted"||E.status==="aborted")return A;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),m.set(v.value,E.value)}return{status:i.value,value:m}}}}St.create=(a,n,i)=>new St({valueType:n,keyType:a,typeName:T.ZodMap,...O(i)});class _e extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.set)return _(c,{code:y.invalid_type,expected:b.set,received:c.parsedType}),A;const u=this._def;u.minSize!==null&&c.data.size<u.minSize.value&&(_(c,{code:y.too_small,minimum:u.minSize.value,type:"set",inclusive:!0,exact:!1,message:u.minSize.message}),i.dirty()),u.maxSize!==null&&c.data.size>u.maxSize.value&&(_(c,{code:y.too_big,maximum:u.maxSize.value,type:"set",inclusive:!0,exact:!1,message:u.maxSize.message}),i.dirty());const l=this._def.valueType;function h(w){const v=new Set;for(const E of w){if(E.status==="aborted")return A;E.status==="dirty"&&i.dirty(),v.add(E.value)}return{status:i.value,value:v}}const m=[...c.data.values()].map((w,v)=>l._parse(new Y(c,w,c.path,v)));return c.common.async?Promise.all(m).then(w=>h(w)):h(m)}min(n,i){return new _e({...this._def,minSize:{value:n,message:x.toString(i)}})}max(n,i){return new _e({...this._def,maxSize:{value:n,message:x.toString(i)}})}size(n,i){return this.min(n,i).max(n,i)}nonempty(n){return this.min(1,n)}}_e.create=(a,n)=>new _e({valueType:a,minSize:null,maxSize:null,typeName:T.ZodSet,...O(n)});class $e extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==b.function)return _(i,{code:y.invalid_type,expected:b.function,received:i.parsedType}),A;function c(m,w){return xt({data:m,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,bt(),Se].filter(v=>!!v),issueData:{code:y.invalid_arguments,argumentsError:w}})}function u(m,w){return xt({data:m,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,bt(),Se].filter(v=>!!v),issueData:{code:y.invalid_return_type,returnTypeError:w}})}const l={errorMap:i.common.contextualErrorMap},h=i.data;if(this._def.returns instanceof Ce){const m=this;return z(async function(...w){const v=new F([]),E=await m._def.args.parseAsync(w,l).catch(ae=>{throw v.addIssue(c(w,ae)),v}),D=await Reflect.apply(h,this,E);return await m._def.returns._def.type.parseAsync(D,l).catch(ae=>{throw v.addIssue(u(D,ae)),v})})}else{const m=this;return z(function(...w){const v=m._def.args.safeParse(w,l);if(!v.success)throw new F([c(w,v.error)]);const E=Reflect.apply(h,this,v.data),D=m._def.returns.safeParse(E,l);if(!D.success)throw new F([u(E,D.error)]);return D.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...n){return new $e({...this._def,args:Q.create(n).rest(we.create())})}returns(n){return new $e({...this._def,returns:n})}implement(n){return this.parse(n)}strictImplement(n){return this.parse(n)}static create(n,i,c){return new $e({args:n||Q.create([]).rest(we.create()),returns:i||we.create(),typeName:T.ZodFunction,...O(c)})}}class Ye extends I{get schema(){return this._def.getter()}_parse(n){const{ctx:i}=this._processInputParams(n);return this._def.getter()._parse({data:i.data,path:i.path,parent:i})}}Ye.create=(a,n)=>new Ye({getter:a,typeName:T.ZodLazy,...O(n)});class Qe extends I{_parse(n){if(n.data!==this._def.value){const i=this._getOrReturnCtx(n);return _(i,{received:i.data,code:y.invalid_literal,expected:this._def.value}),A}return{status:"valid",value:n.data}}get value(){return this._def.value}}Qe.create=(a,n)=>new Qe({value:a,typeName:T.ZodLiteral,...O(n)});function Bn(a,n){return new de({values:a,typeName:T.ZodEnum,...O(n)})}class de extends I{constructor(){super(...arguments),ze.set(this,void 0)}_parse(n){if(typeof n.data!="string"){const i=this._getOrReturnCtx(n),c=this._def.values;return _(i,{expected:M.joinValues(c),received:i.parsedType,code:y.invalid_type}),A}if(kt(this,ze)||Dn(this,ze,new Set(this._def.values)),!kt(this,ze).has(n.data)){const i=this._getOrReturnCtx(n),c=this._def.values;return _(i,{received:i.data,code:y.invalid_enum_value,options:c}),A}return z(n.data)}get options(){return this._def.values}get enum(){const n={};for(const i of this._def.values)n[i]=i;return n}get Values(){const n={};for(const i of this._def.values)n[i]=i;return n}get Enum(){const n={};for(const i of this._def.values)n[i]=i;return n}extract(n,i=this._def){return de.create(n,{...this._def,...i})}exclude(n,i=this._def){return de.create(this.options.filter(c=>!n.includes(c)),{...this._def,...i})}}ze=new WeakMap,de.create=Bn;class Xe extends I{constructor(){super(...arguments),Fe.set(this,void 0)}_parse(n){const i=M.getValidEnumValues(this._def.values),c=this._getOrReturnCtx(n);if(c.parsedType!==b.string&&c.parsedType!==b.number){const u=M.objectValues(i);return _(c,{expected:M.joinValues(u),received:c.parsedType,code:y.invalid_type}),A}if(kt(this,Fe)||Dn(this,Fe,new Set(M.getValidEnumValues(this._def.values))),!kt(this,Fe).has(n.data)){const u=M.objectValues(i);return _(c,{received:c.data,code:y.invalid_enum_value,options:u}),A}return z(n.data)}get enum(){return this._def.values}}Fe=new WeakMap,Xe.create=(a,n)=>new Xe({values:a,typeName:T.ZodNativeEnum,...O(n)});class Ce extends I{unwrap(){return this._def.type}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==b.promise&&i.common.async===!1)return _(i,{code:y.invalid_type,expected:b.promise,received:i.parsedType}),A;const c=i.parsedType===b.promise?i.data:Promise.resolve(i.data);return z(c.then(u=>this._def.type.parseAsync(u,{path:i.path,errorMap:i.common.contextualErrorMap})))}}Ce.create=(a,n)=>new Ce({type:a,typeName:T.ZodPromise,...O(n)});class q extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===T.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=this._def.effect||null,l={addIssue:h=>{_(c,h),h.fatal?i.abort():i.dirty()},get path(){return c.path}};if(l.addIssue=l.addIssue.bind(l),u.type==="preprocess"){const h=u.transform(c.data,l);if(c.common.async)return Promise.resolve(h).then(async m=>{if(i.value==="aborted")return A;const w=await this._def.schema._parseAsync({data:m,path:c.path,parent:c});return w.status==="aborted"?A:w.status==="dirty"||i.value==="dirty"?Oe(w.value):w});{if(i.value==="aborted")return A;const m=this._def.schema._parseSync({data:h,path:c.path,parent:c});return m.status==="aborted"?A:m.status==="dirty"||i.value==="dirty"?Oe(m.value):m}}if(u.type==="refinement"){const h=m=>{const w=u.refinement(m,l);if(c.common.async)return Promise.resolve(w);if(w instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return m};if(c.common.async===!1){const m=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});return m.status==="aborted"?A:(m.status==="dirty"&&i.dirty(),h(m.value),{status:i.value,value:m.value})}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(m=>m.status==="aborted"?A:(m.status==="dirty"&&i.dirty(),h(m.value).then(()=>({status:i.value,value:m.value}))))}if(u.type==="transform")if(c.common.async===!1){const h=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});if(!ye(h))return h;const m=u.transform(h.value,l);if(m instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:i.value,value:m}}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(h=>ye(h)?Promise.resolve(u.transform(h.value,l)).then(m=>({status:i.value,value:m})):h);M.assertNever(u)}}q.create=(a,n,i)=>new q({schema:a,typeName:T.ZodEffects,effect:n,...O(i)}),q.createWithPreprocess=(a,n,i)=>new q({schema:n,effect:{type:"preprocess",transform:a},typeName:T.ZodEffects,...O(i)});class X extends I{_parse(n){return this._getType(n)===b.undefined?z(void 0):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}X.create=(a,n)=>new X({innerType:a,typeName:T.ZodOptional,...O(n)});class fe extends I{_parse(n){return this._getType(n)===b.null?z(null):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}fe.create=(a,n)=>new fe({innerType:a,typeName:T.ZodNullable,...O(n)});class Je extends I{_parse(n){const{ctx:i}=this._processInputParams(n);let c=i.data;return i.parsedType===b.undefined&&(c=this._def.defaultValue()),this._def.innerType._parse({data:c,path:i.path,parent:i})}removeDefault(){return this._def.innerType}}Je.create=(a,n)=>new Je({innerType:a,typeName:T.ZodDefault,defaultValue:typeof n.default=="function"?n.default:()=>n.default,...O(n)});class et extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c={...i,common:{...i.common,issues:[]}},u=this._def.innerType._parse({data:c.data,path:c.path,parent:{...c}});return Le(u)?u.then(l=>({status:"valid",value:l.status==="valid"?l.value:this._def.catchValue({get error(){return new F(c.common.issues)},input:c.data})})):{status:"valid",value:u.status==="valid"?u.value:this._def.catchValue({get error(){return new F(c.common.issues)},input:c.data})}}removeCatch(){return this._def.innerType}}et.create=(a,n)=>new et({innerType:a,typeName:T.ZodCatch,catchValue:typeof n.catch=="function"?n.catch:()=>n.catch,...O(n)});class Ot extends I{_parse(n){if(this._getType(n)!==b.nan){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.nan,received:c.parsedType}),A}return{status:"valid",value:n.data}}}Ot.create=a=>new Ot({typeName:T.ZodNaN,...O(a)});const Qi=Symbol("zod_brand");class Jt extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=i.data;return this._def.type._parse({data:c,path:i.path,parent:i})}unwrap(){return this._def.type}}class tt extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.common.async)return(async()=>{const l=await this._def.in._parseAsync({data:c.data,path:c.path,parent:c});return l.status==="aborted"?A:l.status==="dirty"?(i.dirty(),Oe(l.value)):this._def.out._parseAsync({data:l.value,path:c.path,parent:c})})();{const u=this._def.in._parseSync({data:c.data,path:c.path,parent:c});return u.status==="aborted"?A:u.status==="dirty"?(i.dirty(),{status:"dirty",value:u.value}):this._def.out._parseSync({data:u.value,path:c.path,parent:c})}}static create(n,i){return new tt({in:n,out:i,typeName:T.ZodPipeline})}}class rt extends I{_parse(n){const i=this._def.innerType._parse(n),c=u=>(ye(u)&&(u.value=Object.freeze(u.value)),u);return Le(i)?i.then(u=>c(u)):c(i)}unwrap(){return this._def.innerType}}rt.create=(a,n)=>new rt({innerType:a,typeName:T.ZodReadonly,...O(n)});function Ln(a,n={},i){return a?Ie.create().superRefine((c,u)=>{var l,h;if(!a(c)){const m=typeof n=="function"?n(c):typeof n=="string"?{message:n}:n,w=(h=(l=m.fatal)!==null&&l!==void 0?l:i)!==null&&h!==void 0?h:!0,v=typeof m=="string"?{message:m}:m;u.addIssue({code:"custom",...v,fatal:w})}}):Ie.create()}const Xi={object:R.lazycreate};var T;(function(a){a.ZodString="ZodString",a.ZodNumber="ZodNumber",a.ZodNaN="ZodNaN",a.ZodBigInt="ZodBigInt",a.ZodBoolean="ZodBoolean",a.ZodDate="ZodDate",a.ZodSymbol="ZodSymbol",a.ZodUndefined="ZodUndefined",a.ZodNull="ZodNull",a.ZodAny="ZodAny",a.ZodUnknown="ZodUnknown",a.ZodNever="ZodNever",a.ZodVoid="ZodVoid",a.ZodArray="ZodArray",a.ZodObject="ZodObject",a.ZodUnion="ZodUnion",a.ZodDiscriminatedUnion="ZodDiscriminatedUnion",a.ZodIntersection="ZodIntersection",a.ZodTuple="ZodTuple",a.ZodRecord="ZodRecord",a.ZodMap="ZodMap",a.ZodSet="ZodSet",a.ZodFunction="ZodFunction",a.ZodLazy="ZodLazy",a.ZodLiteral="ZodLiteral",a.ZodEnum="ZodEnum",a.ZodEffects="ZodEffects",a.ZodNativeEnum="ZodNativeEnum",a.ZodOptional="ZodOptional",a.ZodNullable="ZodNullable",a.ZodDefault="ZodDefault",a.ZodCatch="ZodCatch",a.ZodPromise="ZodPromise",a.ZodBranded="ZodBranded",a.ZodPipeline="ZodPipeline",a.ZodReadonly="ZodReadonly"})(T||(T={}));const Ji=(a,n={message:`Input not instance of ${a.name}`})=>Ln(i=>i instanceof a,n),zn=W.create,Fn=ue.create,ea=Ot.create,ta=le.create,Vn=Ve.create,ra=ve.create,na=Et.create,sa=We.create,ia=He.create,aa=Ie.create,oa=we.create,ca=ne.create,ua=Tt.create,la=H.create,da=R.create,fa=R.strictCreate,ha=qe.create,ma=At.create,pa=Ge.create,ga=Q.create,ya=Ke.create,va=St.create,wa=_e.create,_a=$e.create,ba=Ye.create,xa=Qe.create,ka=de.create,Ea=Xe.create,Ta=Ce.create,Wn=q.create,Aa=X.create,Sa=fe.create,Oa=q.createWithPreprocess,Ia=tt.create;var J=Object.freeze({__proto__:null,defaultErrorMap:Se,setErrorMap:Oi,getErrorMap:bt,makeIssue:xt,EMPTY_PATH:Ii,addIssueToContext:_,ParseStatus:B,INVALID:A,DIRTY:Oe,OK:z,isAborted:Kt,isDirty:Yt,isValid:ye,isAsync:Le,get util(){return M},get objectUtil(){return Gt},ZodParsedType:b,getParsedType:re,ZodType:I,datetimeRegex:Zn,ZodString:W,ZodNumber:ue,ZodBigInt:le,ZodBoolean:Ve,ZodDate:ve,ZodSymbol:Et,ZodUndefined:We,ZodNull:He,ZodAny:Ie,ZodUnknown:we,ZodNever:ne,ZodVoid:Tt,ZodArray:H,ZodObject:R,ZodUnion:qe,ZodDiscriminatedUnion:At,ZodIntersection:Ge,ZodTuple:Q,ZodRecord:Ke,ZodMap:St,ZodSet:_e,ZodFunction:$e,ZodLazy:Ye,ZodLiteral:Qe,ZodEnum:de,ZodNativeEnum:Xe,ZodPromise:Ce,ZodEffects:q,ZodTransformer:q,ZodOptional:X,ZodNullable:fe,ZodDefault:Je,ZodCatch:et,ZodNaN:Ot,BRAND:Qi,ZodBranded:Jt,ZodPipeline:tt,ZodReadonly:rt,custom:Ln,Schema:I,ZodSchema:I,late:Xi,get ZodFirstPartyTypeKind(){return T},coerce:{string:a=>W.create({...a,coerce:!0}),number:a=>ue.create({...a,coerce:!0}),boolean:a=>Ve.create({...a,coerce:!0}),bigint:a=>le.create({...a,coerce:!0}),date:a=>ve.create({...a,coerce:!0})},any:aa,array:la,bigint:ta,boolean:Vn,date:ra,discriminatedUnion:ma,effect:Wn,enum:ka,function:_a,instanceof:Ji,intersection:pa,lazy:ba,literal:xa,map:va,nan:ea,nativeEnum:Ea,never:ca,null:ia,nullable:Sa,number:Fn,object:da,oboolean:()=>Vn().optional(),onumber:()=>Fn().optional(),optional:Aa,ostring:()=>zn().optional(),pipeline:Ia,preprocess:Oa,promise:Ta,record:ya,set:wa,strictObject:fa,string:zn,symbol:na,transformer:Wn,tuple:ga,undefined:sa,union:ha,unknown:oa,void:ua,NEVER:A,ZodIssueCode:y,quotelessJson:Si,ZodError:F});const Hn=K.getInstance(),Ma=J.object({id:J.string(),message:J.string(),username:J.string(),address:J.string(),timestamp:J.number(),signature:J.string(),index:J.number(),chatTopic:J.string(),userTopic:J.string()});function $a(a){const n=Ma.safeParse(a);return n.success?Ca({usnermame:a.username,address:a.address,timestamp:a.timestamp})?!0:(console.warn("Invalid messageSender"),!1):(Hn.warn(n.error.format()),!1)}function Ca(a){try{const n={username:a.username,address:a.address,timestamp:a.timestamp},i=new TextEncoder,c=Z.concatBytes(i.encode(`Ethereum Signed Message:
11
- 32`),Z.keccak256(i.encode(JSON.stringify(n))));if(new S.Signature(a.signature).isValid(c,a.address))throw new Error("Signature verification failed!");return!0}catch(n){return Hn.warn("Error in validateUserSignature",n),!1}}const G={LOADING_INIT:"loadingInit",LOADING_PREVIOUS_MESSAGES:"loadingPreviousMessages",MESSAGE_RECEIVED:"messageReceived",MESSAGE_REQUEST_INITIATED:"messageRequestInitiated",MESSAGE_REQUEST_UPLOADED:"messageRequestUploaded",MESSAGE_REQUEST_ERROR:"messageRequestError",CRITICAL_ERROR:"criticalError"};class Na{constructor(n,i){this.utils=n,this.emitter=i,this.logger=K.getInstance(),this.errorHandler=new qt,this.historyIndex=null}async init(){try{const n=await this.utils.fetchLatestChatMessage();return this.historyIndex=n.index,await this.fetchPreviousMessages(),this.historyIndex}catch(n){return this.errorHandler.handleError(n,"SwarmHistory.init"),S.FeedIndex.fromBigInt(0n)}}async fetchPreviousMessages(n=10){try{if(!this.historyIndex){this.logger.warn("History index is not set. Cannot fetch previous messages.");return}if(this.historyIndex.toBigInt()===0n){this.logger.warn("No previous messages to fetch.");return}const i=this.historyIndex.toBigInt(),c=i>BigInt(n)?i-BigInt(n):0n;for(let u=i-1n;u>=c;u--){const l=await this.utils.fetchChatMessage(S.FeedIndex.fromBigInt(u));if(this.emitter.emit(G.MESSAGE_RECEIVED,l),this.historyIndex=S.FeedIndex.fromBigInt(u),u===0n)break}}catch(i){this.errorHandler.handleError(i,"SwarmHistory.fetchPreviousMessages")}}}class Ra{constructor(n,i){this.userDetails=n,this.swarmSettings=i,this.depth=24,this.logger=K.getInstance(),this.errorHandler=new qt,this.UPLOAD_GSOC_TIMEOUT=2e3}async writeOwnFeedDataByIndex(n,i){const{enveloped:c,stamp:u}=this.swarmSettings;if(!c)await this.writeOwnFeedDataByIndexOwned(n,i);else if(u)await this.writeOwnFeedDataByIndexEnvelope(n,i);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async writeOwnFeedDataByIndexOwned(n,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:m}=this.userDetails,w=this.generateUserOwnedFeedId(l,m),v=S.Topic.fromString(w);console.log("DEBUG: feedID write",v.toString(),m,n,w),await c.makeFeedWriter(v,new S.PrivateKey(h)).uploadPayload(u,JSON.stringify(i),{index:n})}async writeOwnFeedDataByIndexEnvelope(n,i){const{bee:c,stamp:u,chatTopic:l}=this.swarmSettings,{privateKey:h,ownAddress:m}=this.userDetails,w=new S.PrivateKey(h),v=S.Stamper.fromBlank(h,u,this.depth),E=this.generateUserOwnedFeedId(l,m),D=S.Topic.fromString(E),ie=$n(D,n),ae=Cn(i),nt=Nn(ae,ie,w),Ne={hash:()=>nt.address.toUint8Array()},er=v.stamp(Ne),{upload:tr}=c.makeSOCWriter(w),st=S.Bytes.fromUtf8(i);return(await tr(er,ie,st.toUint8Array())).reference.toHex()}orderMessages(n){return n.sort((i,c)=>i.timestamp-c.timestamp)}async retryAwaitableAsync(n,i=3,c=250){return new Promise((u,l)=>{n().then(u).catch(h=>{i>0?(this.logger.info(`Retrying... Attempts left: ${i}. Error: ${h.message}`),setTimeout(()=>{this.retryAwaitableAsync(n,i-1,c).then(u).catch(l)},c)):(this.errorHandler.handleError(h,"Utils.retryAwaitableAsync"),l(h))})})}async uploadObjectToBee(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(i){if(c)return this.uploadObjectToBeeEnvelope(n);throw new Error("Enveloped mode is enabled, but stamp is not provided")}else return this.uploadObjectToBeeOwn(n)}async uploadObjectToBeeOwn(n){try{const{bee:i,stamp:c}=this.swarmSettings,u=await i.uploadData(c,JSON.stringify(n),{redundancyLevel:4});return console.log("DEBUG: result",u.reference.toString()),u.reference.toString()}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async uploadObjectToBeeEnvelope(n){try{const{bee:i,stamp:c}=this.swarmSettings,{privateKey:u}=this.userDetails,l=S.Stamper.fromBlank(u,c,this.depth),h=S.Bytes.fromUtf8(JSON.stringify(n)),m=new _i(async v=>{await i.uploadChunk(l.stamp(v),v.build())});await m.append(h.toUint8Array());const w=await m.finalize();return Z.uint8ArrayToHex(w.hash())}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async getOwnLatestFeedIndex(){try{const{bee:n,chatTopic:i}=this.swarmSettings,{ownAddress:c}=this.userDetails,u=this.generateUserOwnedFeedId(i,c),l=S.Topic.fromString(u),m=await n.makeFeedReader(l,c).downloadPayload(),w=Number(m.feedIndex.toBigInt()),v=w+1;return console.log("DEBUG: getLatestFeedIndex",w,v),{latestIndex:w,nextIndex:v}}catch(n){if(this.isNotFoundError(n))return{latestIndex:-1,nextIndex:0};throw n}}async fetchLatestChatMessage(){const{bee:n,chatTopic:i,chatAddress:c}=this.swarmSettings,l=await n.makeFeedReader(S.Topic.fromString(i),Ht(c)).downloadPayload();return{message:l.payload.toJSON(),index:l.feedIndex}}async fetchChatMessage(n){const{bee:i,chatTopic:c,chatAddress:u}=this.swarmSettings;return(await i.makeFeedReader(S.Topic.fromString(c),Ht(u)).downloadPayload({index:n})).payload.toJSON()}async sendMessageToGsoc(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(!i)await this.sendMessageToGsocOwn(n);else if(c)await this.sendMessageToGsocEnvelope(n);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async rawSocDownload(n,i){const{beeUrl:c}=this.swarmSettings,u=await fetch(`${c}/soc/${n}/${i}`,{headers:{"swarm-chunk-retrieval-timeout":"2000ms"}});if(!u.ok)throw new Error(`Failed to fetch: ${n}/${i}`);return u}async sendMessageToGsocOwn(n){this.logger.debug("sendMessageToGsoc entry CALLED");const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,h=new S.PrivateKey(l),m=S.Identifier.fromString(u),w=S.Bytes.fromUtf8(n),{upload:v}=i.makeSOCWriter(h,{timeout:this.UPLOAD_GSOC_TIMEOUT});await v(c,m,w.toUint8Array()),this.logger.debug("sendMessageToGsoc end CALLED")}async sendMessageToGsocEnvelope(n){this.logger.debug("sendMessageToGsoc entry CALLED");const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:l}=this.swarmSettings,{privateKey:h}=this.userDetails,m=S.Stamper.fromBlank(h,c,this.depth),w=new S.PrivateKey(l),v=S.Identifier.fromString(u),E=S.Bytes.fromUtf8(n),D=Cn(E.toUint8Array()),ie=Nn(D,v,w),ae={hash:()=>ie.address.toUint8Array()},nt=m.stamp(ae),{upload:Ne}=i.makeSOCWriter(w,{timeout:this.UPLOAD_GSOC_TIMEOUT});await Ne(nt,v,E.toUint8Array()),this.logger.debug("sendMessageToGsoc end CALLED")}generateUserOwnedFeedId(n,i){return`${n}_EthercastChat_${i}`}isNotFoundError(n){return n.stack.includes("404")||n.message.includes("Not Found")||n.message.includes("404")}}class Da{constructor(n){this.logger=K.getInstance(),this.errorHandler=new qt,this.gsocIndex=null,this.fetchMessageTimer=null;const i=new S.PrivateKey(Ht(n.user.privateKey));this.userDetails={privateKey:n.user.privateKey,ownAddress:i.publicKey().address().toString(),nickname:n.user.nickname,ownIndex:-1},this.swarmSettings={bee:new S.Bee(n.infra.beeUrl),beeUrl:n.infra.beeUrl,stamp:n.infra.stamp||"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",enveloped:n.infra.enveloped,gsocTopic:n.infra.gsocTopic,gsocResourceId:n.infra.gsocResourceId,chatTopic:n.infra.chatTopic,chatAddress:n.infra.chatAddress,messageFetchInterval:n.infra.messageFetchInterval||1500},this.emitter=new Ai,this.utils=new Ra(this.userDetails,this.swarmSettings),this.history=new Na(this.utils,this.emitter)}start(){this.init(),this.startMessagesFetchProcess()}stop(){this.emitter.cleanAll(),this.stopMessagesFetchProcess()}getEmitter(){return this.emitter}orderMessages(n){return this.utils.orderMessages(n)}async sendMessage(n,i){const c=this.userDetails.ownIndex===-1?0:this.userDetails.ownIndex+1,u={id:i||vi(),username:this.userDetails.nickname,address:this.userDetails.ownAddress,chatTopic:this.swarmSettings.chatTopic,userTopic:this.utils.generateUserOwnedFeedId(this.swarmSettings.chatTopic,this.userDetails.ownAddress),signature:this.getSignature(),timestamp:Date.now(),index:c,message:n};try{this.emitter.emit(G.MESSAGE_REQUEST_INITIATED,u),await this.utils.writeOwnFeedDataByIndex(c,JSON.stringify(u)),this.userDetails.ownIndex=c,this.emitter.emit(G.MESSAGE_REQUEST_UPLOADED,u),await this.broadcastUserMessage(u)}catch(l){this.emitter.emit(G.MESSAGE_REQUEST_ERROR,u),this.errorHandler.handleError(l,"Chat.sendMessage")}}async fetchPreviousMessages(){try{return this.emitter.emit(G.LOADING_PREVIOUS_MESSAGES,!0),await this.history.fetchPreviousMessages()}finally{this.emitter.emit(G.LOADING_PREVIOUS_MESSAGES,!1)}}async retrySendMessage(n){this.sendMessage(n.message,n.id)}async retryBroadcastUserMessage(n){this.broadcastUserMessage(n)}async init(){try{this.emitter.emit(G.LOADING_INIT,!0);const[n,i]=await Promise.allSettled([this.initOwnIndex(),this.history.init()]);if(n.status==="rejected")throw n.reason;i.status==="fulfilled"&&(this.gsocIndex=i.value),this.emitter.emit(G.LOADING_INIT,!1)}catch(n){this.errorHandler.handleError(n,"Chat.initSelfState"),this.emitter.emit(G.CRITICAL_ERROR,n)}}async initOwnIndex(){const{latestIndex:c}=await this.utils.retryAwaitableAsync(()=>this.utils.getOwnLatestFeedIndex(),10,1e3);this.userDetails.ownIndex=c}async fetchLatestMessage(){var n;try{const i=(n=this.gsocIndex)==null?void 0:n.next();if(!i){this.logger.error("No next index available for fetching the latest message.");return}const c=S.Topic.fromString(this.swarmSettings.chatTopic),u=$n(c,i),l=await this.utils.rawSocDownload(this.swarmSettings.chatAddress,u.toString());if(this.logger.debug("fetchLatestMessage entry CALLED",l),!$a(l)){this.logger.warn("Invalid GSOC message during fetching");return}this.emitter.emit(G.MESSAGE_RECEIVED,JSON.parse(l)),this.gsocIndex=i}catch(i){this.errorHandler.handleError(i,"Chat.fetchLatestMessage")}}async broadcastUserMessage(n){try{return this.logger.debug("broadcastUserMessage entry CALLED"),console.log("DEBUG broadcastUserMessage",n),this.utils.retryAwaitableAsync(()=>this.utils.sendMessageToGsoc(JSON.stringify(n)))}catch(i){this.errorHandler.handleError(i,"Chat.broadcastUserMessage")}}getSignature(){const{ownAddress:n,privateKey:i,nickname:c}=this.userDetails,u=new S.EthAddress(n).toString(),l=new S.PrivateKey(i);if(l.publicKey().address().toString()!==u)throw new Error("The provided address does not match the address derived from the private key");const m=Date.now();return l.sign(JSON.stringify({username:c,address:u,timestamp:m})).toHex()}startMessagesFetchProcess(){const{messageFetchInterval:n}=this.swarmSettings;if(this.fetchMessageTimer){this.logger.warn("Messages fetch process is already running.");return}this.fetchMessageTimer=setInterval(this.fetchLatestMessage.bind(this),n)}stopMessagesFetchProcess(){this.fetchMessageTimer&&(clearInterval(this.fetchMessageTimer),this.fetchMessageTimer=null)}}ce.EVENTS=G,ce.SwarmChat=Da,Object.defineProperty(ce,Symbol.toStringTag,{value:"Module"})});
8
+ `],s+o.length):e.indexOf(t.opening,s+o.length)}}function Dc(e,t,r){let s=0;for(;;){const o=a.Strings.extractBlock(e,{...r,start:s});if(!o)return e;const l=t(o);s=e.indexOf(o,s)+l.length,e=e.replace(o,l)}}function jc(e,t){const r=[];let s=0;for(;s<e.length;){const o=e.indexOf(t,s);if(o===-1){r.push({string:e.slice(s),symbol:null});break}const l=e.indexOf(t,o+t.length);if(o>s&&l!==-1&&r.push({string:e.slice(s,o),symbol:null}),l===-1){r.push({string:e.slice(s),symbol:null});break}r.push({string:e.slice(o+t.length,l),symbol:t}),s=l+t.length}return r}function Uc(e){const t=[];let r=0;for(;r<e.length;){const s=Nc(e,r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=Cc(e,s+1);if(o===-1){t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1),symbol:"#"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s+1,o),symbol:"#"}),r=o}return t}function Pc(e){const t=[];let r=0;for(;r<e.length;){const s=je(e,["http://","https://"],r);if(s===-1){t.push({string:e.slice(r),symbol:null});break}const o=je(e,[" ",`
9
+ `],s);if(o===-1){s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s),symbol:"http"});break}s>r&&t.push({string:e.slice(r,s),symbol:null}),t.push({string:e.slice(s,o),symbol:"http"}),r=o}return t}const bs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",xs="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function Zc(e){return ks(e,bs)}function Bc(e){return Es(e,bs)}function Lc(e){return ks(e,xs)}function Fc(e){return Es(e,xs)}function ks(e,t){const r="=",s=t.length;let o=0,l=0;const f=[];for(let g=0;g<e.length;g++){const m=e[g];if(m===r)break;const k=t.indexOf(m);if(k===-1)throw new Error(`Invalid character: ${m}`);l=l<<Math.log2(s)|k,o+=Math.log2(s),o>=8&&(o-=8,f.push(l>>o&255))}return new Uint8Array(f)}function Es(e,t){const r=t.length;let s=0,o=0,l="";for(let f=0;f<e.length;f++)for(o=o<<8|e[f],s+=8;s>=Math.log2(r);)s-=Math.log2(r),l+=t[o>>s&r-1];return s>0&&(l+=t[o<<Math.log2(r)-s&r-1]),l.length%4!==0&&(l+="=".repeat(4-l.length%4)),l}function zc(e){e.startsWith("0x")&&(e=e.slice(2));const t=e.length/2,r=new Uint8Array(t);for(let s=0;s<t;s++){const o=parseInt(e.slice(s*2,s*2+2),16);r[s]=o}return r}function Vc(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function Wc(e,t){const r=e.split("/").filter(l=>l),s=t.split("/").filter(l=>l);if(r.length!==s.length)return null;const o={};for(let l=0;l<r.length;l++){const f=r[l];if(f.startsWith(":"))o[f.slice(1)]=s[l];else if(f!==s[l])return null}return o}function mr(e,t,r){const s=[];for(const o of r)o!==t&&s.push(e.replace(t,o));return s}function Hc(e,t,r,s=Math.random){const o=a.Arrays.shuffle(t.map(f=>({variants:a.Arrays.shuffle(f.variants.map(g=>g),s),avoid:f.avoid})),s),l=[];for(const f of o){const g=f.variants.filter(k=>k!==f.avoid),m=g.find(k=>e.includes(k));if(m&&(Nt(l,mr(e,m,g)),l.length>=r))break}if(l.length<r)for(const f of o){const g=f.variants.find(m=>e.includes(m));if(g&&(Nt(l,mr(e,g,f.variants)),l.length>=r))break}return l.slice(0,r)}function qc(e,t,r,s=!1){const o=new RegExp(s?`(?<=\\s|^)${t}(?=\\s|$)`:`\\b${t}\\b`,"g");return e.replace(o,r)}function Gc(e,t){const r=/\b[A-Z][a-zA-Z0-9]*\b/g;return e.replace(r,s=>s.toUpperCase()===s?s:t(s))}function Kc(e){return e.replace(/<[^>]*>/g,"")}function As(e){const t=e.lastIndexOf(" ");if(t===-1)return{line:e,rest:""};const r=e.slice(0,t),s=e.slice(t+1);return{line:r,rest:s}}function Yc(e,t={}){return[...e].reduce((r,s)=>r+(t[s]||1),0)}function Qc(e,t,r={}){const s=[];let o="",l=0;for(let f=0;f<e.length;f++){const g=e[f],m=r[g]||1;if(o+=g,l+=m,l>t){const{line:k,rest:$}=As(o);s.push(k),o=$,l=$.split("").map(U=>r[U]||1).reduce((U,Be)=>U+Be,0)}}return o&&s.push(o),s}function Xc(e,t){const r=[];for(let s=0;s<=e.length;s++)r[s]=[s];for(let s=0;s<=t.length;s++)r[0][s]=s;for(let s=1;s<=e.length;s++)for(let o=1;o<=t.length;o++){const l=e[s-1]===t[o-1]?0:1;r[s][o]=Math.min(r[s-1][o]+1,r[s][o-1]+1,r[s-1][o-1]+l)}return r[e.length][t.length]}function gr(e,t){return new RegExp(`\\b${t}\\b`).test(e)}function Jc(e,t,r){return r==="any"?t.some(s=>gr(e,s)):t.every(s=>gr(e,s))}function eu(e){const t={},r=e.match(/([a-z\-]+)="([^"]+)"/g);if(r)for(const s of r){const[o,l]=fr(s,"=");t[o]=l.slice(1,l.length-1)}return t}function jt(e,t,r=[]){let s="";for(;t<e.length&&(ct(e[t])||r.includes(e[t]));)s+=e[t++];return s}function tu(e,t,r="$",s=":"){for(const o in t)e=Ss(e,o,t[o],r,s);return e=Ts(e),e}function Ss(e,t,r,s="$",o=":"){if(r==="")return e;let l=e.indexOf(`${s}${t}`);for(;l!==-1;){if(e[l+t.length+1]===o)if(e[l+t.length+2]===o)e=e.replace(`${s}${t}${o}${o}`,r);else{const f=jt(e,l+t.length+2,["_"]);e=e.replace(`${s}${t}${o}${f}`,r)}else e=e.replace(`${s}${t}`,r);l=e.indexOf(`${s}${t}`,l+r.length)}return e}function Ts(e,t="$",r=":"){let s=e.indexOf(t);for(;s!==-1;){const o=jt(e,s+1);if(e[s+o.length+1]===r)if(e[s+o.length+2]===r)e=e.replace(`${t}${o}${r}${r}`,"");else{const l=jt(e,s+o.length+2);e=e.replace(`${t}${o}${r}${l}`,l)}s=e.indexOf(t,s+1)}return e}function ru(e,t){let r=e.indexOf("](");for(;r!==-1;){const s=vs(e,"[",r),o=e.indexOf(")",r);if(s!==-1&&o!==-1){const[l,f]=e.slice(s+1,o).split("]("),g=t(l,f);e=e.slice(0,s)+g+e.slice(o+1)}r=e.indexOf("](",r+1)}return e}function Os(e,t=!0){const r=Object.entries(e).filter(([s,o])=>o!=null).map(([s,o])=>`${s}=${encodeURIComponent(o)}`).join("&");return r?(t?"?":"")+r:""}function nu(e){const t={},r=e.split("&");for(const s of r){const[o,l]=s.split("=");o&&l&&(t[o]=decodeURIComponent(l))}return t}function su(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function iu(e,t){let r=null,s=-1/0;for(const[o,l]of Object.entries(e)){const f=t(l);f>s&&(s=f,r=o)}return r?[r,e[r]]:null}function au(e,t,r,s){const o=e.find(f=>f[t]===r),l=e.find(f=>f[t]===r+s);o&&l?(o[t]=r+s,l[t]=r):o&&(o[t]=r+s),e.sort((f,g)=>$t(f[t])-$t(g[t])),e.forEach((f,g)=>f[t]=g+1)}function ou(e){const t=Object.keys(e);if(t.length===1)return e[t[0]];throw new Error("Expected object to have a single key")}function cu(e,t=":"){return Object.fromEntries(e.map(r=>fr(r,t)).map(r=>r[0]&&r[1]?[ot(r[0]),ot(r[1])]:null).filter(r=>r))}function uu(e,t,r){return Cs(e,t)+Os(r||{})}function lu(e,t=",",r='"'){const s=[];let o="",l=!1;const f=e.split("");for(const g of f)g===t&&!l?(s.push(o),o=""):g===r&&(!o&&!l||l)?l=!l:o+=g;return s.push(o),s}function du(e){return`[${Math.floor(e.progress*100)}%] ${Ut(e.deltaMs)} out of ${Ut(e.totalTimeMs)} (${Ut(e.remainingTimeMs)} left) [${Math.round(e.baseTimeMs)} ms each]`}async function fu(e,t,r){for(let s=0;s<r;s++){try{if(await e())return!0}catch{}s<r-1&&await d(t)}return!1}function hu(e,t){const r=[];for(let s=e.length-1;s>=0;s--)t(e[s])&&r.push(e.splice(s,1)[0]);return r}function pu(e){return JSON.parse(JSON.stringify(e))}function mu(e){return Math.ceil((e||Date.now())/1e3)}function gu(e){return(e||new Date).toISOString().slice(0,10)}function yu(e){return(e||new Date).toISOString().slice(0,19).replace(/T|:/g,"-")}function vu(e){const t=new Date(e);return new Date(t.getTime()-t.getTimezoneOffset()*6e4)}function wu(e){return new Date(e)}function ee(e){return String(Math.floor(e)).padStart(2,"0")}function _u(e){let[t,r]=e.split(":");pe(parseInt(t,10))||(t="0"),pe(parseInt(r,10))||(r="0");let s=br(cr(t),0,23),o=br(cr(r),0,59);return`${ee(s)}:${ee(o)}`}function Ut(e){const t=Math.floor(e/36e5);e=e%36e5;const r=Math.floor(e/6e4);e=e%6e4;const s=Math.floor(e/1e3);return t?`${ee(t)}:${ee(r)}:${ee(s)}`:`${ee(r)}:${ee(s)}`}function Ee(e){return Math.floor((De(e)?e.getTime():e)/864e5)}const bu={today:(e,t)=>ee(e)+":"+ee(t),yesterday:()=>"Yesterday",monday:()=>"Mon",tuesday:()=>"Tue",wednesday:()=>"Wed",thursday:()=>"Thu",friday:()=>"Fri",saturday:()=>"Sat",sunday:()=>"Sun",weeks:e=>`${e}w`};function xu(e,t){const r=new Date((t==null?void 0:t.now)||Date.now()),s=(t==null?void 0:t.labels)||bu,o=De(e)?e:new Date(e);if(Ee(r)===Ee(o))return s.today(o.getUTCHours(),o.getUTCMinutes(),o.getUTCHours()>12);if(Ee(r)-Ee(o)===1)return s.yesterday();const l=vr(o);return Ee(r)-Ee(o)<7?s[l.day]():s.weeks(Math.round((r.getTime()-o.getTime())/6048e5))}const Is={now:()=>"A few seconds",seconds:e=>`${e} seconds`,minutes:e=>`${e} minutes`,hours:e=>`${e} hours`,days:e=>`${e} days`,weeks:e=>`${e} weeks`};function Ms(e,t){const r=(t==null?void 0:t.now)??Date.now(),s=(t==null?void 0:t.labels)||Is,o=a.Types.isDate(e)?e.getTime():e;let l=(r-o)/1e3;return l<10?s.now():l<120?s.seconds(Math.floor(l)):(l/=60,l<120?s.minutes(Math.floor(l)):(l/=60,l<48?s.hours(Math.floor(l)):(l/=24,l<14?s.days(Math.floor(l)):(l/=7,s.weeks(Math.floor(l))))))}function ku(e,t=Is){return Ms(0,{now:e*1e3,labels:t})}function Eu(e,t,r){const s=((r==null?void 0:r.now)??Date.now())-e,o=Math.floor(s/t),l=t/((r==null?void 0:r.precision)??1)-Math.ceil(s%t/((r==null?void 0:r.precision)??1));return{cycles:o,remaining:l}}const yr={};function Au(e,t){return!yr[e]||Date.now()>yr[e]?(yr[e]=Date.now()+t,!0):!1}const Su={s:1e3,m:6e4,h:36e5,d:864e5};function Tu(e,t,r){return t=De(t)?t.getTime():t,r=r?De(r)?r.getTime():r:Date.now(),(r-t)/Su[e]}function Ou(e,t,r,s){s||(s=Date.now());const o=t/r,l=s-e,f=l/t,g=f*r,m=g-l;return{deltaMs:l,progress:o,baseTimeMs:f,totalTimeMs:g,remainingTimeMs:m}}const Iu={0:"sunday",1:"monday",2:"tuesday",3:"wednesday",4:"thursday",5:"friday",6:"saturday"};function $s(e){return{zeroBasedIndex:e,day:Iu[e]}}function vr(e){return $s(e.getDay())}function Mu(e){return vr(new Date(e))}function $u(e){return e*1e3}function Cu(e){return e*6e4}function Nu(e){return e*36e5}function Ru(e){return e*864e5}const Du={ms:1,milli:1,millis:1,millisecond:1,milliseconds:1,s:1e3,sec:1e3,second:1e3,seconds:1e3,m:6e4,min:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,month:2592e6,months:2592e6,y:31536e6,year:31536e6,years:31536e6};function ju(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Du[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}const Uu={b:1,byte:1,bytes:1,kb:1024,kilobyte:1024,kilobytes:1024,mb:1024**2,megabyte:1024**2,megabytes:1024**2,gb:1024**3,gigabyte:1024**3,gigabytes:1024**3,tb:1024**4,terabyte:1024**4,terabytes:1024**4};function Pu(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeDate got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim().toLowerCase(),s=Uu[r];if(!s)throw Error(`Unknown unit: "${r}"`);return t*s}function Zu(e){return e.replace(/ +/g," ").replace(/^ /gm,"")}const wr={};async function Bu(e,t,r){const s=Date.now(),o=wr[e];if(o&&o.validUntil>s)return o.value;const l=await r(),f=s+t;return wr[e]={value:l,validUntil:f},l}function Lu(e){delete wr[e]}function Cs(...e){return e.filter(t=>t).join("/").replace(new RegExp("(?<!:)\\/+","g"),"/")}function Fu(e,t,r,s,o=!0){const l=e.indexOf(t),f=e.indexOf(r,l+t.length);if(l===-1||f===-1)throw Error("Start or end not found");return o?e.substring(0,l+t.length)+s+e.substring(f):e.substring(0,l)+s+e.substring(f+r.length)}function zu(e){let t="p";e.startsWith("#")?(t="h1",e=e.slice(1).trim()):e.startsWith("-")&&(t="li",e=e.slice(1).trim());const r=e[0]===e[0].toUpperCase(),s=/[.?!]$/.test(e),o=/:$/.test(e);return{type:t,isCapitalized:r,hasPunctuation:s,endsWithColon:o}}function Vu(e,t="(",r=")"){let s=0,o=0;for(;o<e.length;)if(e.startsWith(t,o)?(s++,o+=t.length):e.startsWith(r,o)?(s--,o+=r.length):o++,s<0)return!1;return t===r?s%2===0:s===0}function Wu(e){e=e.normalize("NFD").replace(/[\u0300-\u036f]/g,"");let t=e.length;for(;e=e.replace(/(\w+)[\s,']+\w+/g,"$1"),e.length!==t;)t=e.length;return e=e.replaceAll(/[A-Z][a-zA-Z0-9]*/g,"A"),e=e.replaceAll(/[a-z][a-zA-Z0-9]*/g,"a"),e=e.replaceAll(/[\u4E00-\u9FA5]+/g,"Z"),e}function Ns(e){const t=Object.keys(e).sort((s,o)=>s.localeCompare(o)),r={};for(const s of t)r[s]=Ae(e[s]);return r}function Rs(e){const t=[];return e.sort((r,s)=>JSON.stringify(Ae(r)).localeCompare(JSON.stringify(Ae(s)))).forEach(r=>t.push(Ae(r))),t}function Ae(e){return Array.isArray(e)?Rs(e):he(e)?Ns(e):e}function Ds(e,t){return JSON.stringify(Ae(e))===JSON.stringify(Ae(t))}function Hu(...e){for(let t=1;t<e.length;t++)if(!Ds(e[t-1],e[t]))return!1;return!0}function qu(e){try{return JSON.parse(e)}catch{return null}}function Gu(){let e=0;return{next:()=>e++}}function Ku(e){let t=0;return{next:()=>e[t++%e.length]}}function Yu(e){let t;return r=>{const s=r===e&&t!==e;return t=r,s}}function Qu(e,t,r,s,o){const l={};for(const f of Object.keys(t))l[f]=[];l[s]=[],o&&(e=e.sort(o));for(const f of e){const g=f[r],m=t[g]?g:s;l[m].length>=t[m]?l[s].push(f):l[m].push(f)}return l}function Xu(e,t){const r=Object.keys(e),s=Object.keys(t);return{uniqueToA:r.filter(o=>!s.includes(o)),uniqueToB:s.filter(o=>!r.includes(o))}}function js(e){const t=Object.keys(e);return t[Math.floor(Math.random()*t.length)]}function Ju(e,t){const r=js(e);return e[r]=t(e[r]),r}function el(e){return e=e.replace(/\r\n/g,`
10
+ `),e=e.replace(/(\w+)\((.+)\)/g,(t,r,s)=>`${r}(${s.replaceAll(",","&comma;")})`),e=e.replace(/(,)(\s+})/g,"$2"),e=e.replace(/\.\.\..+?,/g,""),e=e.replace(/({\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/(,\s+)([a-zA-Z]\w+),/g,"$1$2: '$2',"),e=e.replace(/:(.+)\?(.+):/g,(t,r,s)=>`: (${r.trim()} && ${s.trim()}) ||`),e=e.replace(/([a-zA-Z0-9]+)( ?: ?{)/g,'"$1"$2'),e=e.replace(/([a-zA-Z0-9]+) ?: ?(.+?)(,|\n|})/g,(t,r,s,o)=>`"${r}":"${s.trim()}"${o}`),e=e.replace(/("'|'")/g,'"'),e=e.replaceAll("&comma;",","),JSON.parse(e)}const me=[1e3,1e6,1e9,1e12,1e15,1e18,1e21,1e24,1e27,1e30,1e9,1e16,1e18,1e18,1e18,1e33],tl=["thousand","million","billion","trillion","quadrillion","quintillion","sextillion","septillion","octillion","nonillion","gwei","bzz","btc","eth","dai","decillion"],Us=["K","M","B","T","Qa","Qi","Sx","Sp","O","N","gwei","bzz","eth","btc","dai","D"];function rl(e,t,r){let s=e.length-t;if(s<=0)return"0."+"0".repeat(-s)+e+(r?" "+r:"");let o=e.substring(0,s),l=e.substring(s);return o===""&&(o="0"),o+"."+l+(r?" "+r:"")}function nl(e,t){const r=(t==null?void 0:t.longForm)??!1,s=t!=null&&t.unit?` ${t.unit}`:"",o=r?tl:Us,l=(t==null?void 0:t.precision)??1;if(e<me[0])return`${e}${s}`;for(let f=0;f<me.length-1;f++)if(e<me[f+1])return`${(e/me[f]).toFixed(l)}${r?" ":""}${o[f]}${s}`;return`${(e/me[me.length-1]).toFixed(l)}${r?" ":""}${o[me.length-1]}${s}`}function _r(e){const t=parseFloat(e);if(isNaN(t))throw Error("makeNumber got NaN for input");const r=e.replace(/^-?[0-9.]+/,"").trim(),s=Us.findIndex(o=>o.toLowerCase()===r.toLowerCase());return s===-1?t:t*me[s]}function br(e,t,r){return e<t?t:e>r?r:e}function sl(e,t,r){const s=e+t;return s>r?r:s}function il(e,t,r){const s=e-t;return s<r?r:s}function al(e,t){return t(e),e}function ol(e,t){e&&t(e)}function cl(e,t){const r=Object.keys(t);for(const s of r)Array.isArray(t[s])&&Array.isArray(e[s])&&Nt(e[s],t[s])}function ul(e){return e.splice(0,e.length),e}function ll(e){for(const t of Object.keys(e))(Yn(e[t])||Array.isArray(e[t])&&e[t].every(r=>r==null))&&delete e[t];return e}function dl(e){for(const t of Object.entries(e))(t[1]===null||t[1]===void 0||V(t[1])&&Mt(t[1]))&&delete e[t[0]];return e}function fl(e,t){const r={};for(const[s,o]of Object.entries(e))t(s)&&(r[s]=o);return r}function hl(e,t){const r={};for(const[s,o]of Object.entries(e))t(o)&&(r[s]=o);return r}function pl(e,t){const r={};for(const s of Object.entries(e))r[s[0]]=t(s[1]);return r}function ml(e,t){const r=[];let s=0;for(const o of e)r.push(t(o,s++));return r}async function gl(e,t){try{return await e()}catch{throw t}}function yl(e,t,r){r!=null&&(e[t]=r)}function vl(e,t,r,s){const o=be(r,s);o!=null&&xe(e,t,o)}function wl(e){const t={};for(const[r,s]of Object.entries(e))t[s]=r;return t}function _l(e){const t=Object.keys(e),r=t.map(g=>e[g].length),s=r.reduce((g,m)=>g*=m);let o=1;const l=[1];for(let g=0;g<r.length-1;g++)o*=r[g],l.push(o);const f=[];for(let g=0;g<s;g++){const m={};for(let k=0;k<t.length;k++){const $=e[t[k]],U=Math.floor(g/l[k])%$.length;m[t[k]]=$[U]}f.push(m)}return f}function bl(e){return Object.values(e).filter(t=>t).length}function xl(e,t,r){return e+(r?"["+t+"]":(e.length?".":"")+t)}function Pt(e,t,r,s,o){if(!he(t))return t;for(const[l,f]of Object.entries(t)){const g=xl(r,l,s);Array.isArray(f)?o?Pt(e,f,g,!0,o):e[g]=f.map(m=>Pt(Array.isArray(m)?[]:{},m,"",!1,o)):he(f)?Pt(e,f,g,!1,o):e[g]=f}return e}function kl(e,t=!1,r){return Pt({},e,r||"",!1,t)}function Ps(e){if(!he(e))return e;const t=Array.isArray(e)?[]:{};for(const[r,s]of Object.entries(e))Array.isArray(s)?xe(t,r,s.map(o=>Ps(o))):xe(t,r,s);return t}function El(e,t,r){return t[e]?t[e]:r}function Zs(e,t){const r={};for(const s of e){const o=t(s);r[o]=s}return r}function Al(e,t){const r={};for(const s of e){const o=t(s);r[o]||(r[o]=[]),r[o].push(s)}return r}function Sl(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r}function Bs(e,t){const r=Math.ceil(e.length/t),s=[];for(let o=0;o<e.length;o+=r)s.push(e.slice(o,o+r));return s}function Ls(e,t){const r=[],s=Math.ceil(e.length/t);for(let o=0;o<s;o++)r.push(e.slice(o*t,o*t+t));return r}function Tl(e,t){const r=Math.ceil(e.length/t);return Ls(e,r)}function Ol(e,t){return Object.values(Zs(e,t))}function Il(e,t,r,s,o){const l=t?e.map(t):e,f={};for(const m of l)f[m]=(f[m]||0)+1;const g=s?Fs(f,o?(m,k)=>m[1]-k[1]:(m,k)=>k[1]-m[1]):f;return r?Object.keys(g):g}function Fs(e,t){return Object.fromEntries(Object.entries(e).sort(t))}function Ml(e){const t=[],r=Object.keys(e),s=e[r[0]].length;for(let o=0;o<s;o++){const l={};for(const f of r)l[f]=e[f][o];t.push(l)}return t}function $l(e,t,r=1){for(const s of e)s[t]+=r}function Cl(e,t,r){for(const s of e)s[t]=r}function xr(e,t){const r=[];let s=[];return e.forEach((o,l)=>{(l===0||!t(o,e[l-1]))&&(s=[],r.push(s)),s.push(o)}),r}function Nl(){return{map:new Map,keys:[]}}function Rl(){return{map:new Map,keys:[]}}function zs(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.push(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function Dl(e,t,r,s=100){if(e.map.has(t)){const o=e.keys.indexOf(t);e.keys.splice(o,1)}if(e.map.set(t,r),e.keys.unshift(t),e.keys.length>s){const o=e.keys.shift();o&&e.map.delete(o)}}function jl(e,t,r,s,o=100){zs(e,t,{validUntil:Date.now()+s,data:r},o)}function Ul(e,t){const r=e.map.get(t);return r&&r.validUntil>Date.now()?r.data:null}class ge{constructor(t){this.value=t}static of(t){return new ge(t)}static empty(){return new ge(null)}map(t){return new ge(this.value!==null&&this.value!==void 0?t(this.value):null)}mapAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(r=>ge.of(r)):Promise.resolve(ge.empty())}ifPresent(t){return this.value!==null&&this.value!==void 0&&t(this.value),this}ifPresentAsync(t){return this.value!==null&&this.value!==void 0?t(this.value).then(()=>this):Promise.resolve(this)}ifAbsent(t){return(this.value===null||this.value===void 0)&&t(),this}ifAbsentAsync(t){return this.value===null||this.value===void 0?t().then(()=>this):Promise.resolve(this)}getOrFallback(t){return this.value??t()}getOrFallbackAsync(t){return this.value!==null&&this.value!==void 0?Promise.resolve(this.value):t()}getOrThrow(){if(this.value===null||this.value===void 0)throw Error("Optional.value is empty");return this.value}}a.Optional=ge;class Pl{constructor(t){this.supplier=t,this.value=null}get(){return this.value||(this.value=this.supplier()),this.value}}a.Lazy=Pl;class Zl{constructor(t){this.supplier=t,this.value=null}async get(){return this.value||(this.value=await this.supplier()),this.value}}a.AsyncLazy=Zl;function Bl(e){return()=>e.forEach(t=>t())}function Ll(e,t){return e.reduce((r,s)=>t(r)>t(s)?r:s)}function Fl(e,t){const r=e.find(s=>s instanceof t);return ge.of(r)}function zl(e,t){return e.filter(r=>r instanceof t)}function Vl(e,t){const r=[],s=Math.max(e.length,t.length);for(let o=0;o<s;o++)e[o]&&r.push(e[o]),t[o]&&r.push(t[o]);return r}function Wl(e,t){return e.includes(t)?e.filter(r=>r!==t):[...e,t]}class Hl{constructor(t){this.value=t,this.children=[]}}function ql(e,t,r,s,o=!1){const l=new Map,f=[];e.forEach(m=>{const k=new Hl(m);l.set(m[t],k)}),e.forEach(m=>{const k=l.get(m[t]);if(!k)return;const $=m[r];if($){const U=l.get($);U&&U.children.push(k)}else f.push(k)});const g=m=>{m.children.sort((k,$)=>{const U=k.value[s],Be=$.value[s];return o?Be-U:U-Be}),m.children.forEach(g)};return f.forEach(g),f}function Vs(e,t){if(Math.log2(e.length)%1!==0)throw new Error("Array length must be a power of 2");let r=[...e];for(;r.length>1;){const s=[];for(let o=0;o<r.length;o+=2){const l=r[o+1];s.push(t(r[o],l))}r=s}return r[0]}function Ue(...e){const t=e.reduce((o,l)=>o+l.length,0),r=new Uint8Array(t);let s=0;return e.forEach(o=>{r.set(o,s),s+=o.length}),r}function Ws(e){return e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function Hs(e){return e[0]===255&&e[1]===216}function qs(e){return e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function Gl(e){return Ws(e)||Hs(e)||qs(e)}function Kl(e){return new Uint8Array([e])}function Yl(e){return e[0]}function Ql(e,t){const r=new ArrayBuffer(2);return new DataView(r).setUint16(0,e,t==="LE"),new Uint8Array(r)}function Xl(e,t){return new DataView(e.buffer).getUint16(e.byteOffset,t==="LE")}function Jl(e,t){const r=new ArrayBuffer(4);return new DataView(r).setUint32(0,e,t==="LE"),new Uint8Array(r)}function ed(e,t){return new DataView(e.buffer).getUint32(e.byteOffset,t==="LE")}function kr(e,t){const r=new ArrayBuffer(8);return new DataView(r).setBigUint64(0,BigInt(e),t==="LE"),new Uint8Array(r)}function td(e,t){return new DataView(e.buffer).getBigUint64(e.byteOffset,t==="LE")}function Pe(e,t){const r=new Uint8Array(32);let s=e;if(t==="LE"){for(let o=0;o<32;o++)r[o]=Number(s&0xffn),s>>=8n;return r}for(let o=31;o>=0;o--)r[o]=Number(s&0xffn),s>>=8n;return r}function Ze(e,t){let r=0n;if(t==="LE"){for(let s=31;s>=0;s--)r=r<<8n|BigInt(e[s]);return r}for(let s=0;s<32;s++)r=r<<8n|BigInt(e[s]);return r}function rd(e,t){const r=[];let s=0;for(const o of t)r.push(e.subarray(s,s+o)),s+=o;return r}function Er(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.subarray(s,s+t));return r}const Gs=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function nd(e){for(let t=0;t<24;t++){const r=e[0]^e[10]^e[20]^e[30]^e[40],s=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],l=e[3]^e[13]^e[23]^e[33]^e[43],f=e[4]^e[14]^e[24]^e[34]^e[44],g=e[5]^e[15]^e[25]^e[35]^e[45],m=e[6]^e[16]^e[26]^e[36]^e[46],k=e[7]^e[17]^e[27]^e[37]^e[47],$=e[8]^e[18]^e[28]^e[38]^e[48],U=e[9]^e[19]^e[29]^e[39]^e[49],Be=o<<1|l>>>31,Zd=l<<1|o>>>31,dt=$^Be,ft=U^Zd,Bd=f<<1|g>>>31,Ld=g<<1|f>>>31,ht=r^Bd,pt=s^Ld,Fd=m<<1|k>>>31,zd=k<<1|m>>>31,mt=o^Fd,gt=l^zd,Vd=$<<1|U>>>31,Wd=U<<1|$>>>31,yt=f^Vd,vt=g^Wd,Hd=r<<1|s>>>31,qd=s<<1|r>>>31,wt=m^Hd,_t=k^qd;e[0]^=dt,e[1]^=ft,e[2]^=ht,e[3]^=pt,e[4]^=mt,e[5]^=gt,e[6]^=yt,e[7]^=vt,e[8]^=wt,e[9]^=_t,e[10]^=dt,e[11]^=ft,e[12]^=ht,e[13]^=pt,e[14]^=mt,e[15]^=gt,e[16]^=yt,e[17]^=vt,e[18]^=wt,e[19]^=_t,e[20]^=dt,e[21]^=ft,e[22]^=ht,e[23]^=pt,e[24]^=mt,e[25]^=gt,e[26]^=yt,e[27]^=vt,e[28]^=wt,e[29]^=_t,e[30]^=dt,e[31]^=ft,e[32]^=ht,e[33]^=pt,e[34]^=mt,e[35]^=gt,e[36]^=yt,e[37]^=vt,e[38]^=wt,e[39]^=_t,e[40]^=dt,e[41]^=ft,e[42]^=ht,e[43]^=pt,e[44]^=mt,e[45]^=gt,e[46]^=yt,e[47]^=vt,e[48]^=wt,e[49]^=_t;const Mr=e[0],$r=e[1],Cr=e[2]<<1|e[3]>>>31,Nr=e[3]<<1|e[2]>>>31,Rr=e[5]<<30|e[4]>>>2,Dr=e[4]<<30|e[5]>>>2,jr=e[6]<<28|e[7]>>>4,Ur=e[7]<<28|e[6]>>>4,Pr=e[8]<<27|e[9]>>>5,Zr=e[9]<<27|e[8]>>>5,Br=e[11]<<4|e[10]>>>28,Lr=e[10]<<4|e[11]>>>28,Fr=e[13]<<12|e[12]>>>20,zr=e[12]<<12|e[13]>>>20,Vr=e[14]<<6|e[15]>>>26,Wr=e[15]<<6|e[14]>>>26,Hr=e[17]<<23|e[16]>>>9,qr=e[16]<<23|e[17]>>>9,Gr=e[18]<<20|e[19]>>>12,Kr=e[19]<<20|e[18]>>>12,Yr=e[20]<<3|e[21]>>>29,Qr=e[21]<<3|e[20]>>>29,Xr=e[22]<<10|e[23]>>>22,Jr=e[23]<<10|e[22]>>>22,en=e[25]<<11|e[24]>>>21,tn=e[24]<<11|e[25]>>>21,rn=e[26]<<25|e[27]>>>7,nn=e[27]<<25|e[26]>>>7,sn=e[29]<<7|e[28]>>>25,an=e[28]<<7|e[29]>>>25,on=e[31]<<9|e[30]>>>23,cn=e[30]<<9|e[31]>>>23,un=e[33]<<13|e[32]>>>19,ln=e[32]<<13|e[33]>>>19,dn=e[34]<<15|e[35]>>>17,fn=e[35]<<15|e[34]>>>17,hn=e[36]<<21|e[37]>>>11,pn=e[37]<<21|e[36]>>>11,mn=e[38]<<8|e[39]>>>24,gn=e[39]<<8|e[38]>>>24,yn=e[40]<<18|e[41]>>>14,vn=e[41]<<18|e[40]>>>14,wn=e[42]<<2|e[43]>>>30,_n=e[43]<<2|e[42]>>>30,bn=e[45]<<29|e[44]>>>3,xn=e[44]<<29|e[45]>>>3,kn=e[47]<<24|e[46]>>>8,En=e[46]<<24|e[47]>>>8,An=e[48]<<14|e[49]>>>18,Sn=e[49]<<14|e[48]>>>18;e[0]=Mr^~Fr&en,e[1]=$r^~zr&tn,e[2]=Fr^~en&hn,e[3]=zr^~tn&pn,e[4]=en^~hn&An,e[5]=tn^~pn&Sn,e[6]=hn^~An&Mr,e[7]=pn^~Sn&$r,e[8]=An^~Mr&Fr,e[9]=Sn^~$r&zr,e[10]=jr^~Gr&Yr,e[11]=Ur^~Kr&Qr,e[12]=Gr^~Yr&un,e[13]=Kr^~Qr&ln,e[14]=Yr^~un&bn,e[15]=Qr^~ln&xn,e[16]=un^~bn&jr,e[17]=ln^~xn&Ur,e[18]=bn^~jr&Gr,e[19]=xn^~Ur&Kr,e[20]=Cr^~Vr&rn,e[21]=Nr^~Wr&nn,e[22]=Vr^~rn&mn,e[23]=Wr^~nn&gn,e[24]=rn^~mn&yn,e[25]=nn^~gn&vn,e[26]=mn^~yn&Cr,e[27]=gn^~vn&Nr,e[28]=yn^~Cr&Vr,e[29]=vn^~Nr&Wr,e[30]=Pr^~Br&Xr,e[31]=Zr^~Lr&Jr,e[32]=Br^~Xr&dn,e[33]=Lr^~Jr&fn,e[34]=Xr^~dn&kn,e[35]=Jr^~fn&En,e[36]=dn^~kn&Pr,e[37]=fn^~En&Zr,e[38]=kn^~Pr&Br,e[39]=En^~Zr&Lr,e[40]=Rr^~Hr&sn,e[41]=Dr^~qr&an,e[42]=Hr^~sn&on,e[43]=qr^~an&cn,e[44]=sn^~on&wn,e[45]=an^~cn&_n,e[46]=on^~wn&Rr,e[47]=cn^~_n&Dr,e[48]=wn^~Rr&Hr,e[49]=_n^~Dr&qr,e[0]^=Gs[t*2],e[1]^=Gs[t*2+1]}}function Ks(e){const t=[];for(let r=0;r<e.length;r+=4)t.push(e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24);return t}function Ys(e,t){if(!e.length){const o=new Uint8Array(136);return o[0]=t,o[135]=128,[Ks(o)]}const r=Er(e,136),s=r[r.length-1];if(s.length<136){const o=new Uint8Array(136);o.set(s),o[s.length]=t,o[135]|=128,r[r.length-1]=o}if(s.length===136){const o=new Uint8Array(136);o[0]=t,o[135]=128,r.push(o)}return r.map(Ks)}function Qs(e,t){for(const r of t){for(let s=0;s<34;s+=2)e[s]^=r[s+1],e[s+1]^=r[s];nd(e)}return e}function Xs(e){return new Uint8Array([e[1],e[1]>>-24,e[1]>>-16,e[1]>>-8,e[0],e[0]>>8,e[0]>>16,e[0]>>24,e[3],e[3]>>-24,e[3]>>-16,e[3]>>-8,e[2],e[2]>>8,e[2]>>16,e[2]>>24,e[5],e[5]>>-24,e[5]>>-16,e[5]>>-8,e[4],e[4]>>8,e[4]>>16,e[4]>>24,e[7],e[7]>>-24,e[7]>>-16,e[7]>>-8,e[6],e[6]>>8,e[6]>>16,e[6]>>24])}function oe(e){return Xs(Qs(new Array(50).fill(0),Ys(e,1)))}function sd(e){return Xs(Qs(new Array(50).fill(0),Ys(e,6)))}function id(e,t,r){const s=Math.min(e.length,t.length,r/8+1);for(let o=0;o<s;o++){const l=e[o]^t[o];for(let f=0;f<8;f++)if(l>>7-f&1)return o*8+f}return r}function ad(e,t){const r=Math.min(e.length,t.length);for(let s=0;s<r;s++)if(e[s]!==t[s])return e.subarray(0,s);return e.subarray(0,r)}function od(e,t,r,s){const o=Math.floor(t/8),l=t%8;r===1?e[o]|=1<<(s==="BE"?7-l:l):e[o]&=~(1<<(s==="BE"?7-l:l))}function cd(e,t,r){const s=Math.floor(t/8),o=t%8;return e[s]>>(r==="BE"?7-o:o)&1}function ud(e,t,r=0){for(let s=r;s<e.length;s++)for(let o=0;o<t.length&&e[s+o]===t[o];o++)if(o===t.length-1)return s;return-1}function Js(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,t-e.length),s}function ld(e,t,r=0){const s=e.length%t;return s===0?e:Js(e,e.length+t-s,r)}function ei(e,t,r=0){if(e.length>=t)return e;const s=new Uint8Array(t);return s.fill(r),s.set(e,0),s}function dd(e,t,r=0){const s=e.length%t;return s===0?e:ei(e,e.length+t-s,r)}function fd(e,t){const r=new Uint8Array(e.length);for(let s=0;s<e.length;s++)r[s]=e[s]^t[s%t.length];return r}function hd(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function C(e,t){return(e%t+t)%t}function ut(e,t){e=C(e,t);let[r,s]=[0n,1n],[o,l]=[t,e];for(;l!==0n;){const f=o/l;[r,s]=[s,r-f*s],[o,l]=[l,o-f*l]}if(o>1n)throw new Error("a is not invertible");return r<0n&&(r+=t),r}function pd(e,t,r){let s=1n;for(e=C(e,r);t>0;)t%2n===1n&&(s=C(s*e,r)),e=C(e*e,r),t=t/2n;return s}function ti(e,t){return C(e,t)===0n?0n:t%4n===3n?pd(e,(t+1n)/4n,t):null}const L=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,j=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,Zt=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,Bt=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;function Ar(e,t,r){if(t===0n)return[0n,0n];const s=C(3n*e*e*ut(2n*t,r),r),o=C(s*s-2n*e,r),l=C(s*(e-o)-t,r);return[o,l]}function Lt(e,t,r,s,o){if(e===0n&&t===0n)return[r,s];if(r===0n&&s===0n)return[e,t];if(e===r&&t===C(-s,o))return[0n,0n];if(e===r&&t===s)return Ar(e,t,o);const l=C((s-t)*ut(r-e,o),o),f=C(l*l-e-r,o),g=C(l*(e-f)-t,o);return[f,g]}function md(e){if(e<=0n||e>=j)throw new Error("Invalid private key");return Se(Zt,Bt,e,L)}function gd(e){const t=e[1]%2n===0n?2:3;return new Uint8Array([t,...Pe(e[0],"BE")])}function yd(e){if(e.length!==33||e[0]!==2&&e[0]!==3)throw new Error("Invalid compressed public key");const t=Ze(e.slice(1),"BE"),r=ti(C(t**3n+7n,L),L);if(!r)throw Error("Invalid x: does not correspond to a valid curve point");const s=C(-r,L),o=r%2n===0n;return[t,e[0]===2?o?r:s:o?s:r]}function vd(e){const t=new Uint8Array(20),r=oe(Ue(Pe(e[0],"BE"),Pe(e[1],"BE")));return t.set(r.subarray(12)),t}function wd(e){const t=a.Binary.uint8ArrayToHex(e),r=a.Binary.uint8ArrayToHex(a.Binary.keccak256(new Uint8Array([...t].map(o=>o.charCodeAt(0)))));let s="0x";for(let o=0;o<t.length;o++)parseInt(r[o],16)>7?s+=t[o].toUpperCase():s+=t[o];return s}function Se(e,t,r,s){let o=[0n,0n],l=[e,t];const f=r.toString(2);for(const g of f)g==="0"?(l=Lt(o[0],o[1],l[0],l[1],s),o=Ar(o[0],o[1],s)):(o=Lt(o[0],o[1],l[0],l[1],s),l=Ar(l[0],l[1],s));return o}function _d(e,t,r){return ri(Ze(oe(e),"BE"),t,r)}function ri(e,t,r){if(t<=0n||t>=j)throw new Error("Invalid private key");if(r||(r=C(Ze(oe(Ue(oe(Pe(t,"BE")),Pe(e,"BE"))),"BE"),j)),r<=0n||r>=j)throw new Error("Invalid nonce");const s=C(e,j),o=Se(Zt,Bt,r,L),l=C(o[0],j);let f=C((s+C(l,j)*t)*ut(r,j),j);if(l===0n||f===0n)throw new Error("Invalid r or s value");let g=o[1]%2n===0n?27n:28n;return f>j/2n&&(f=j-f,g=g===27n?28n:27n),[l,f,g]}function bd(e,t,r,s){const o=ti(C(t**3n+7n,L),L);if(!o)throw new Error("Invalid r: does not correspond to a valid curve point");const l=s===27n?0n:1n,f=o%2n===l?o:L-o,g=C(Ze(oe(e),"BE"),j),m=Se(t,f,r,L),k=Se(Zt,Bt,g,L),$=Lt(m[0],m[1],k[0],C(-k[1],L),L);return Se($[0],$[1],ut(t,j),L)}function xd(e,t,r,s){const o=C(Ze(oe(e),"BE"),j),l=ut(s,j),f=C(o*l,j),g=C(r*l,j),m=Se(Zt,Bt,f,L),k=Se(t[0],t[1],g,L),$=Lt(m[0],m[1],k[0],k[1],L);return r===C($[0],j)}class ni{constructor(t){this.cursor=0,this.buffer=t}read(t){const r=this.buffer.subarray(this.cursor,this.cursor+t);return this.cursor+=t,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayReader=ni;class si{constructor(t){this.buffer=t,this.cursor=0}write(t){const r=Math.min(this.max(),t.max());return this.buffer.set(t.read(r),this.cursor),this.cursor+=r,r}max(){return this.buffer.length-this.cursor}}a.Uint8ArrayWriter=si;class Ft{constructor(t,r=0n){this.span=r,this.writer=new si(new Uint8Array(t))}build(){return Ue(kr(this.span,"LE"),this.writer.buffer)}hash(){const t=Vs(Er(this.writer.buffer,32),(r,s)=>oe(Ue(r,s)));return oe(Ue(kr(this.span,"LE"),t))}}a.Chunk=Ft;class Sr{constructor(t,r=4096){this.counters=[1],this.capacity=r,this.chunks=[new Ft(r)],this.onChunk=t}static async root(t,r=4096){const s=new n(n.NOOP,r);return await s.append(t),s.finalize()}async append(t,r=0,s=0n){const o=new ni(t);for(;o.max()>0;){this.chunks[r].writer.max()===0&&await this.elevate(r);const l=this.chunks[r].writer.write(o);s?this.chunks[r].span+=s:this.chunks[0].span+=BigInt(l)}}async elevate(t){this.counters[t]=++this.counters[t]%(this.capacity/32),this.chunks[t+1]||(this.chunks.push(new Ft(this.capacity)),this.counters.push(1)),await this.append(this.chunks[t].hash(),t+1,this.chunks[t].span),await this.onChunk(this.chunks[t]),this.chunks[t]=new Ft(this.capacity)}async finalize(t=0){return this.chunks[t+1]?this.counters[t]===1?(await this.elevate(t+1),this.chunks[t+1]=this.chunks[t],this.finalize(t+1)):(await this.elevate(t),this.finalize(t+1)):(await this.onChunk(this.chunks[t]),this.chunks[t])}}a.MerkleTree=Sr,n=Sr,Sr.NOOP=async e=>{};class te{constructor(t,r){if(r<0)throw Error("Scale must be non-negative");this.value=BigInt(t),this.scale=r}static fromDecimalString(t,r){let[s,o]=t.split(".");return o=(o||"").padEnd(r,"0").slice(0,r),new te(BigInt(s+o),r)}add(t){return this.assertSameScale(t),new te(this.value+t.value,this.scale)}subtract(t){return this.assertSameScale(t),new te(this.value-t.value,this.scale)}multiply(t){return new te(this.value*t,this.scale)}divmod(t){if(t===0n)throw new Error("Division by zero is not allowed");const r=this.value/t,s=this.value%t;return[new te(r,this.scale),new te(s,this.scale)]}exchange(t,r,s){if(t==="*"){const l=this.value*r.value/10n**BigInt(this.scale);return new te(l,s)}this.assertSameScale(r);const o=this.value*10n**BigInt(s)/r.value;return new te(o,s)}compare(t){return this.assertSameScale(t),this.value>t.value?1:this.value<t.value?-1:0}toDecimalString(){if(this.scale===0)return this.value.toString();const t=this.value.toString(),r=t.slice(0,-this.scale)||"0",s=t.slice(-this.scale).padStart(this.scale,"0");return`${r}.${s}`}toString(){return this.value.toString()}toJSON(){return this.toString()}assertSameScale(t){if(this.scale!==t.scale)throw new Error(`Scale mismatch: expected ${this.scale}, but got ${t.scale}`)}}a.FixedPointNumber=te;function kd(e){if(e.length===0)return null;const t=e[0];return t.ttlMax?--t.ttl<=0&&e.shift():t.ttlMax=t.ttl,{progress:(t.ttlMax-t.ttl)/t.ttlMax,data:t.data}}function zt(e,t,r,s){const o=e.findIndex(g=>g===`--${t}`||g.startsWith(`--${t}=`)),l=e[o];if(!l)return(r||{})[s||t||""]||null;if(l.includes("="))return l.split("=")[1];const f=e[o+1];return f&&!f.startsWith("-")?f:(r||{})[s||t||""]||null}function Ed(e,t,r,s){const o=zt(e,t,r,s);if(!o)return null;try{return _r(o)}catch{throw new Error(`Invalid number argument ${t}: ${o}`)}}function Ad(e,t,r,s){const o=e.some(m=>m.endsWith("-"+t)),l=zt(e,t,r,s);if(!l&&o)return!0;if(!l&&!o)return null;const f=["true","1","yes","y","on"],g=["false","0","no","n","off"];if(f.includes(l.toLowerCase()))return!0;if(g.includes(l.toLowerCase()))return!1;throw Error(`Invalid boolean argument ${t}: ${l}`)}function ii(e,t,r,s){const o=zt(e,t,r,s);if(!o)throw new Error(`Missing argument ${t}`);return o}function Sd(e,t,r,s){const o=ii(e,t,r,s);try{return _r(o)}catch{throw new Error(`Invalid argument ${t}: ${o}`)}}function ai(e,t){const r=e[t];e.splice(t,1),e.unshift(r)}function Td(e,t){const r=[...e];return ai(r,t),r}function oi(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Od(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Tr(e,t){return{x:e.x*t,y:e.y*t}}function Id(e){const t=Math.sqrt(e.x*e.x+e.y*e.y);return{x:e.x/t,y:e.y/t}}function ci(e,t,r){return{x:e.x+Math.cos(t)*r,y:e.y+Math.sin(t)*r}}function ui(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function lt(e,t,r="row-first"){const s=[];if(r==="column-first")for(let o=0;o<e.length;o++)for(let l=0;l<e[0].length;l++)t(o,l)&&s.push({x:o,y:l});else for(let o=0;o<e[0].length;o++)for(let l=0;l<e.length;l++)t(l,o)&&s.push({x:l,y:o});return s}function Md(e,t,r){var s,o;return((s=e[t+1])==null?void 0:s[r])&&((o=e[t-1])==null?void 0:o[r])&&!e[t][r-1]&&!e[t][r+1]}function $d(e,t,r){var s,o;return e[t][r+1]&&e[t][r-1]&&!((s=e[t-1])!=null&&s[r])&&!((o=e[t+1])!=null&&o[r])}function li(e,t,r){var s;return!((s=e[t-1])!=null&&s[r])}function di(e,t,r){var s;return!((s=e[t+1])!=null&&s[r])}function fi(e,t,r){return!e[t][r-1]}function hi(e,t,r){return!e[t][r+1]}function Cd(e,t,r){var o,l,f,g,m,k,$,U;const s=[];return e[t][r]?Md(e,t,r)||$d(e,t,r)?[]:(!((o=e[t-1])!=null&&o[r-1])&&li(e,t,r)&&fi(e,t,r)&&s.push({x:t,y:r}),!((l=e[t+1])!=null&&l[r-1])&&di(e,t,r)&&fi(e,t,r)&&s.push({x:t+1,y:r}),!((f=e[t-1])!=null&&f[r+1])&&li(e,t,r)&&hi(e,t,r)&&s.push({x:t,y:r+1}),!((g=e[t+1])!=null&&g[r+1])&&di(e,t,r)&&hi(e,t,r)&&s.push({x:t+1,y:r+1}),s):((m=e[t-1])!=null&&m[r]&&e[t][r-1]&&s.push({x:t,y:r}),(k=e[t+1])!=null&&k[r]&&e[t][r-1]&&s.push({x:t+1,y:r}),($=e[t-1])!=null&&$[r]&&e[t][r+1]&&s.push({x:t,y:r+1}),(U=e[t+1])!=null&&U[r]&&e[t][r+1]&&s.push({x:t+1,y:r+1}),s)}function Nd(e,t,r,s){const o=[{x:0,y:0},{x:r,y:0},{x:0,y:s},{x:r,y:s}];for(let l=0;l<e.length;l++)for(let f=0;f<e[0].length;f++){const g=Cd(e,l,f);for(const m of g)o.some(k=>k.x===m.x&&k.y===m.y)||o.push(m)}return o.map(l=>({x:l.x*t,y:l.y*t}))}function Rd(e,t){const r=lt(e,(m,k)=>e[m][k]===0&&e[m][k+1]!==0,"row-first").map(m=>({...m,dx:1,dy:0})),s=lt(e,(m,k)=>e[m][k]===0&&e[m][k-1]!==0,"row-first").map(m=>({...m,dx:1,dy:0})),o=lt(e,(m,k)=>{var $;return e[m][k]===0&&(($=e[m-1])==null?void 0:$[k])!==0},"column-first").map(m=>({...m,dx:0,dy:1})),l=lt(e,(m,k)=>{var $;return e[m][k]===0&&(($=e[m+1])==null?void 0:$[k])!==0},"column-first").map(m=>({...m,dx:0,dy:1}));r.forEach(m=>m.y++),l.forEach(m=>m.x++);const f=xr([...o,...l],(m,k)=>m.x===k.x&&m.y-1===k.y),g=xr([...s,...r],(m,k)=>m.y===k.y&&m.x-1===k.x);return[...f,...g].map(m=>({start:m[0],end:it(m)})).map(m=>({start:Tr(m.start,t),end:Tr(oi(m.end,{x:m.start.dx,y:m.start.dy}),t)}))}function Dd(e,t){return Math.atan2(t.y-e.y,t.x-e.x)}function jd(e,t){return t.map(r=>Dd(e,r)).sort((r,s)=>r-s)}function pi(e,t,r,s){const o=(s.y-r.y)*(t.x-e.x)-(s.x-r.x)*(t.y-e.y);if(o===0)return null;let l=e.y-r.y,f=e.x-r.x;const g=(s.x-r.x)*l-(s.y-r.y)*f,m=(t.x-e.x)*l-(t.y-e.y)*f;return l=g/o,f=m/o,l>0&&l<1&&f>0&&f<1?{x:e.x+l*(t.x-e.x),y:e.y+l*(t.y-e.y)}:null}function Or(e,t,r){const s=[],o=ci(e,r,1e4);for(const l of t){const f=pi(e,o,l.start,l.end);f&&s.push(f)}return s.length?s.reduce((l,f)=>{const g=ui(e,f),m=ui(e,l);return g<m?f:l}):null}function Ud(e,t,r){const s=jd(e,r),o=[];for(const l of s){const f=Or(e,t,l-.001),g=Or(e,t,l+.001);f&&o.push(f),g&&o.push(g)}return o}class Ir{constructor(){this.subscribers=[]}subscribe(t){return this.subscribers.push(t),()=>{this.subscribers=this.subscribers.filter(r=>r!==t)}}publish(t){this.subscribers.forEach(r=>r(t))}clear(){this.subscribers=[]}getSubscriberCount(){return this.subscribers.length}}a.PubSubChannel=Ir;class Pd{constructor(t,r){this.queue=[],this.running=0,this.onProcessed=new Ir,this.onDrained=new Ir,this.concurrency=t,this.capacity=r}process(){if(this.running>=this.concurrency)return;const t=this.queue.shift();t&&(this.running++,t().finally(()=>{this.running--,this.process(),this.onProcessed.publish(),this.running===0&&this.onDrained.publish()}))}enqueue(t){if(this.queue.length<this.capacity)return this.queue.push(t),this.process(),Promise.resolve();if(this.onProcessed.getSubscriberCount())throw Error("Queue capacity is full");return new Promise(r=>{this.onProcessed.subscribe(()=>{this.queue.length<this.capacity&&(this.queue.push(t),this.process(),this.onProcessed.clear(),r())})})}drain(){if(this.running===0)return Promise.resolve();if(this.onDrained.getSubscriberCount())throw Error("Already draining");return new Promise(t=>{this.onDrained.subscribe(()=>{this.onDrained.clear(),t()})})}}a.AsyncQueue=Pd,a.Binary={hexToUint8Array:zc,uint8ArrayToHex:Vc,base64ToUint8Array:Zc,uint8ArrayToBase64:Bc,base32ToUint8Array:Lc,uint8ArrayToBase32:Fc,log2Reduce:Vs,partition:Er,concatBytes:Ue,numberToUint8:Kl,uint8ToNumber:Yl,numberToUint16:Ql,uint16ToNumber:Xl,numberToUint32:Jl,uint32ToNumber:ed,numberToUint64:kr,uint64ToNumber:td,numberToUint256:Pe,uint256ToNumber:Ze,sliceBytes:rd,keccak256:oe,sha3_256:sd,proximity:id,commonPrefix:ad,setBit:od,getBit:cd,indexOf:ud,equals:hd,padStart:Js,padStartToMultiple:ld,padEnd:ei,padEndToMultiple:dd,xorCypher:fd},a.Elliptic={privateKeyToPublicKey:md,compressPublicKey:gd,publicKeyFromCompressed:yd,publicKeyToAddress:vd,signMessage:_d,signHash:ri,verifySignature:xd,recoverPublicKey:bd,checksumEncode:wd},a.Random={intBetween:st,floatBetween:qn,chance:Gn,signed:ja,makeSeededRng:tr,point:Pa,procs:Za},a.Arrays={countUnique:Il,makeUnique:Ol,splitBySize:Sl,splitByCount:Bs,index:Zs,indexCollection:Al,onlyOrThrow:p,onlyOrNull:w,firstOrThrow:E,firstOrNull:v,shuffle:h,initialize:D,initialize2D:ae,rotate2D:ie,containsShape:nt,glue:Go,pluck:er,pick:rr,pickMany:Ba,pickManyUnique:La,pickWeighted:Va,pickRandomIndices:Ne,pickGuaranteed:Fa,last:it,pipe:Kn,makePipe:za,sortWeighted:Wa,pushAll:Nt,unshiftAll:Ho,filterAndRemove:hu,merge:cl,empty:ul,pushToBucket:zo,unshiftAndLimit:Vo,atRolling:Wo,group:xr,createOscillator:Ku,organiseWithLimits:Qu,tickPlaybook:kd,getArgument:zt,getBooleanArgument:Ad,getNumberArgument:Ed,requireStringArgument:ii,requireNumberArgument:Sd,bringToFront:Td,bringToFrontInPlace:ai,findInstance:Fl,filterInstances:zl,interleave:Vl,toggle:Wl,createHierarchy:ql,multicall:Bl,maxBy:Ll},a.System={sleepMillis:d,forever:Qa,scheduleMany:tc,waitFor:fu,expandError:Zo,runAndSetInterval:Xa},a.Numbers={make:_r,sum:nc,average:sc,median:ic,getDistanceFromMidpoint:ac,clamp:br,range:cs,interpolate:rc,createSequence:Gu,increment:sl,decrement:il,format:nl,fromDecimals:rl,makeStorage:Pu,asMegabytes:Ja,convertBytes:eo,hexToRgb:to,rgbToHex:ro,haversineDistanceToMeters:no,roundToNearest:It,formatDistance:so,triangularNumber:io,searchFloat:ao},a.Promises={raceFulfilled:c,invert:i,runInParallelBatches:u},a.Dates={getTimestamp:xu,getTimeDelta:Ms,secondsToHumanTime:ku,countCycles:Eu,isoDate:gu,throttle:Au,timeSince:Tu,dateTimeSlug:yu,unixTimestamp:mu,fromUtcString:vu,fromMillis:wu,getProgress:Ou,humanizeTime:Ut,humanizeProgress:du,createTimeDigits:ee,mapDayNumber:$s,getDayInfoFromDate:vr,getDayInfoFromDateTimeString:Mu,seconds:$u,minutes:Cu,hours:Nu,days:Ru,make:ju,normalizeTime:_u,absoluteDays:Ee},a.Objects={safeParse:qu,deleteDeep:Ga,getDeep:be,setDeep:xe,incrementDeep:Ha,ensureDeep:qa,replaceDeep:Ka,getFirstDeep:Ya,deepMergeInPlace:ke,deepMerge2:Bo,deepMerge3:Lo,mapAllAsync:qo,cloneWithJson:pu,sortObject:Ns,sortArray:Rs,sortAny:Ae,deepEquals:Ds,deepEqualsEvery:Hu,runOn:al,ifPresent:ol,zip:os,zipSum:Fo,removeEmptyArrays:ll,removeEmptyValues:dl,flatten:kl,unflatten:Ps,match:El,sort:Fs,map:pl,mapIterable:ml,filterKeys:fl,filterValues:hl,rethrow:gl,setSomeOnObject:yl,setSomeDeep:vl,flip:wl,getAllPermutations:_l,countTruthyValues:bl,transformToArray:Ml,setMulti:Cl,incrementMulti:$l,createBidirectionalMap:Nl,createTemporalBidirectionalMap:Rl,pushToBidirectionalMap:zs,unshiftToBidirectionalMap:Dl,addToTemporalBidirectionalMap:jl,getFromTemporalBidirectionalMap:Ul,createStatefulToggle:Yu,diffKeys:Xu,pickRandomKey:js,mapRandomKey:Ju,fromObjectString:el,toQueryString:Os,parseQueryString:nu,hasKey:su,selectMax:iu,reposition:au,unwrapSingleKey:ou,parseKeyValues:cu},a.Types={isFunction:sr,isObject:he,isStrictlyObject:Re,isEmptyArray:Yn,isEmptyObject:oo,isUndefined:nr,isString:V,isNumber:pe,isBoolean:Qn,isDate:De,isBlank:Mt,isId:ir,isIntegerString:Xn,isHexString:Jn,isUrl:is,isNullable:Do,asString:ns,asHexString:bo,asSafeString:xo,asIntegerString:_o,asNumber:$t,asFunction:ko,asInteger:cr,asBoolean:Eo,asDate:Ao,asNullableString:So,asEmptiableString:To,asId:Oo,asTime:Io,asArray:Mo,asObject:Ct,asNullableObject:$o,asStringMap:Co,asNumericDictionary:No,asUrl:Ro,asNullable:jo,asOptional:Uo,enforceObjectShape:as,enforceArrayShape:Po,isPng:Ws,isJpg:Hs,isWebp:qs,isImage:Gl},a.Strings={tokenizeByCount:Tl,tokenizeByLength:Ls,searchHex:yo,searchSubstring:vo,randomHex:wo,randomLetter:ho,randomAlphanumeric:po,randomRichAscii:mo,randomUnicode:go,includesAny:oc,slugify:ur,normalForm:uc,enumify:mc,escapeHtml:yc,decodeHtmlEntities:wc,after:lr,afterLast:ls,before:us,beforeLast:dr,betweenWide:_c,betweenNarrow:bc,getPreLine:Zu,containsWord:gr,containsWords:Jc,joinUrl:Cs,getFuzzyMatchScore:Rt,sortByFuzzyScore:gc,splitOnce:fr,splitAll:ds,randomize:Ac,expand:fs,shrinkTrim:ot,capitalize:Dt,decapitalize:hs,csvEscape:$c,parseCsv:lu,surroundInOut:pc,getExtension:hr,getBasename:pr,normalizeEmail:xc,normalizeFilename:kc,parseFilename:Ec,camelToTitle:lc,slugToTitle:dc,slugToCamel:fc,joinHumanly:hc,findWeightedPair:ws,extractBlock:_s,extractAllBlocks:Rc,replaceBlocks:Dc,indexOfEarliest:je,lastIndexOfBefore:vs,parseHtmlAttributes:eu,readNextWord:jt,resolveVariables:tu,resolveVariableWithDefaultSyntax:Ss,resolveRemainingVariablesWithDefaults:Ts,isLetter:ps,isDigit:ms,isLetterOrDigit:ct,isValidObjectPathCharacter:Oc,insert:Ic,indexOfRegex:gs,lineMatches:ys,linesMatchInOrder:Mc,represent:at,resolveMarkdownLinks:ru,buildUrl:uu,isChinese:cc,replaceBetweenStrings:Fu,describeMarkdown:zu,isBalanced:Vu,textToFormat:Wu,splitFormatting:jc,splitHashtags:Uc,splitUrls:Pc,route:Wc,explodeReplace:mr,generateVariants:Hc,replaceWord:qc,replacePascalCaseWords:Gc,stripHtml:Kc,breakLine:As,measureTextWidth:Yc,toLines:Qc,levenshteinDistance:Xc},a.Assertions={asEqual:Ko,asTrue:Yo,asTruthy:Qo,asFalse:Xo,asFalsy:Jo,asEither:ec},a.Cache={get:Bu,invalidate:Lu},a.Vector={addPoint:oi,subtractPoint:Od,multiplyPoint:Tr,normalizePoint:Id,pushPoint:ci,filterCoordinates:lt,findCorners:Nd,findLines:Rd,raycast:Or,raycastCircle:Ud,getLineIntersectionPoint:pi}})(On);const N=wi(On);N.Arrays,N.Assertions;const Z=N.Binary;N.Cache,N.Dates,N.Elliptic,N.Numbers,N.Objects,N.Pagination,N.Promises,N.Random,N.Strings,N.System,N.Types,N.Optional,N.Vector,N.PubSubChannel,N.Chunk;const _i=N.MerkleTree;N.FixedPointNumber,N.Lazy,N.AsyncLazy,N.AsyncQueue,N.Uint8ArrayReader,N.Uint8ArrayWriter;const bi=new TextEncoder,In=1,Mn=4096,Wt=4096,xi=32;function $n(a,n){return n=typeof n=="number"?T.FeedIndex.fromBigInt(BigInt(n)):n,new T.Identifier(Z.keccak256(Z.concatBytes(a.toUint8Array(),n.toUint8Array())))}function ki(a){const n=a.slice(0,T.Span.LENGTH),i=a.slice(T.Span.LENGTH),c=Ei(i),u=Z.keccak256(Z.concatBytes(n,c));return new T.Reference(u)}function Ei(a){if(a.length>Wt)throw new T.BeeArgumentError(`payload size ${a.length} exceeds maximum chunk payload size ${Wt}`,a);const n=new Uint8Array(Wt);return n.set(a),Z.log2Reduce(Z.partition(n,xi),(i,c)=>Z.keccak256(Z.concatBytes(i,c)))}function Cn(a){if(a instanceof Uint8Array||(a=bi.encode(a)),a.length<In||a.length>Mn)throw new RangeError(`payload size ${a.length} exceeds limits [${In}, ${Mn}]`);const n=T.Span.fromBigInt(BigInt(a.length)),i=Z.concatBytes(n.toUint8Array(),a);return{data:i,span:n,payload:T.Bytes.fromSlice(i,T.Span.LENGTH),address:ki(i)}}function Ai(a,n){return new T.Reference(Z.keccak256(Z.concatBytes(a.toUint8Array(),n.toUint8Array())))}function Nn(a,n,i){n=new T.Identifier(n),i=new T.PrivateKey(i);const c=Ai(n,i.publicKey().address()),u=i.sign(Z.concatBytes(n.toUint8Array(),a.address.toUint8Array())),d=Z.concatBytes(n.toUint8Array(),u.toUint8Array(),a.data),h=T.Span.fromSlice(a.data,0),p=T.Bytes.fromSlice(a.data,T.Span.LENGTH);return{data:d,identifier:n,signature:u,span:h,payload:p,address:c,owner:i.publicKey().address()}}function Ht(a){return(a.startsWith("0x")?a.slice(2):a).toLowerCase()}class K{constructor(){}static getInstance(){return K.instance||(K.instance=new K),K.instance}formatMessage(n,...i){return`[${new Date().toISOString()}] [${n.toUpperCase()}] - ${i.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ")}`}log(...n){console.log(this.formatMessage("log",...n))}info(...n){console.info(this.formatMessage("info",...n))}warn(...n){console.warn(this.formatMessage("warn",...n))}error(...n){console.error(this.formatMessage("error",...n))}debug(...n){console.debug(this.formatMessage("debug",...n))}}class qt{constructor(){this.logger=K.getInstance()}handleError(n,i){const c=n instanceof Error?n.message:"Unknown error occurred",u=n instanceof Error?n.stack:null;this.logger.error(`Error in ${i||"unknown context"}: ${c}`,{stack:u})}}class Si{constructor(){this.events={},this.on=this.on.bind(this),this.off=this.off.bind(this),this.cleanAll=this.cleanAll.bind(this),this.emit=this.emit.bind(this)}on(n,i){this.events[n]||(this.events[n]=[]),this.events[n].push(i)}off(n,i){if(!this.events[n])return;const c=this.events[n].indexOf(i);c>-1&&this.events[n].splice(c,1)}cleanAll(){this.events={}}emit(n,i){this.events[n]&&this.events[n].forEach(c=>c(i))}}var M;(function(a){a.assertEqual=u=>u;function n(u){}a.assertIs=n;function i(u){throw new Error}a.assertNever=i,a.arrayToEnum=u=>{const d={};for(const h of u)d[h]=h;return d},a.getValidEnumValues=u=>{const d=a.objectKeys(u).filter(p=>typeof u[u[p]]!="number"),h={};for(const p of d)h[p]=u[p];return a.objectValues(h)},a.objectValues=u=>a.objectKeys(u).map(function(d){return u[d]}),a.objectKeys=typeof Object.keys=="function"?u=>Object.keys(u):u=>{const d=[];for(const h in u)Object.prototype.hasOwnProperty.call(u,h)&&d.push(h);return d},a.find=(u,d)=>{for(const h of u)if(d(h))return h},a.isInteger=typeof Number.isInteger=="function"?u=>Number.isInteger(u):u=>typeof u=="number"&&isFinite(u)&&Math.floor(u)===u;function c(u,d=" | "){return u.map(h=>typeof h=="string"?`'${h}'`:h).join(d)}a.joinValues=c,a.jsonStringifyReplacer=(u,d)=>typeof d=="bigint"?d.toString():d})(M||(M={}));var Gt;(function(a){a.mergeShapes=(n,i)=>({...n,...i})})(Gt||(Gt={}));const b=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),re=a=>{switch(typeof a){case"undefined":return b.undefined;case"string":return b.string;case"number":return isNaN(a)?b.nan:b.number;case"boolean":return b.boolean;case"function":return b.function;case"bigint":return b.bigint;case"symbol":return b.symbol;case"object":return Array.isArray(a)?b.array:a===null?b.null:a.then&&typeof a.then=="function"&&a.catch&&typeof a.catch=="function"?b.promise:typeof Map<"u"&&a instanceof Map?b.map:typeof Set<"u"&&a instanceof Set?b.set:typeof Date<"u"&&a instanceof Date?b.date:b.object;default:return b.unknown}},y=M.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Ti=a=>JSON.stringify(a,null,2).replace(/"([^"]+)":/g,"$1:");class z extends Error{get errors(){return this.issues}constructor(n){super(),this.issues=[],this.addIssue=c=>{this.issues=[...this.issues,c]},this.addIssues=(c=[])=>{this.issues=[...this.issues,...c]};const i=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,i):this.__proto__=i,this.name="ZodError",this.issues=n}format(n){const i=n||function(d){return d.message},c={_errors:[]},u=d=>{for(const h of d.issues)if(h.code==="invalid_union")h.unionErrors.map(u);else if(h.code==="invalid_return_type")u(h.returnTypeError);else if(h.code==="invalid_arguments")u(h.argumentsError);else if(h.path.length===0)c._errors.push(i(h));else{let p=c,w=0;for(;w<h.path.length;){const v=h.path[w];w===h.path.length-1?(p[v]=p[v]||{_errors:[]},p[v]._errors.push(i(h))):p[v]=p[v]||{_errors:[]},p=p[v],w++}}};return u(this),c}static assert(n){if(!(n instanceof z))throw new Error(`Not a ZodError: ${n}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(n=i=>i.message){const i={},c=[];for(const u of this.issues)u.path.length>0?(i[u.path[0]]=i[u.path[0]]||[],i[u.path[0]].push(n(u))):c.push(n(u));return{formErrors:c,fieldErrors:i}}get formErrors(){return this.flatten()}}z.create=a=>new z(a);const Te=(a,n)=>{let i;switch(a.code){case y.invalid_type:a.received===b.undefined?i="Required":i=`Expected ${a.expected}, received ${a.received}`;break;case y.invalid_literal:i=`Invalid literal value, expected ${JSON.stringify(a.expected,M.jsonStringifyReplacer)}`;break;case y.unrecognized_keys:i=`Unrecognized key(s) in object: ${M.joinValues(a.keys,", ")}`;break;case y.invalid_union:i="Invalid input";break;case y.invalid_union_discriminator:i=`Invalid discriminator value. Expected ${M.joinValues(a.options)}`;break;case y.invalid_enum_value:i=`Invalid enum value. Expected ${M.joinValues(a.options)}, received '${a.received}'`;break;case y.invalid_arguments:i="Invalid function arguments";break;case y.invalid_return_type:i="Invalid function return type";break;case y.invalid_date:i="Invalid date";break;case y.invalid_string:typeof a.validation=="object"?"includes"in a.validation?(i=`Invalid input: must include "${a.validation.includes}"`,typeof a.validation.position=="number"&&(i=`${i} at one or more positions greater than or equal to ${a.validation.position}`)):"startsWith"in a.validation?i=`Invalid input: must start with "${a.validation.startsWith}"`:"endsWith"in a.validation?i=`Invalid input: must end with "${a.validation.endsWith}"`:M.assertNever(a.validation):a.validation!=="regex"?i=`Invalid ${a.validation}`:i="Invalid";break;case y.too_small:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at least":"more than"} ${a.minimum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at least":"over"} ${a.minimum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${a.minimum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly equal to ":a.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(a.minimum))}`:i="Invalid input";break;case y.too_big:a.type==="array"?i=`Array must contain ${a.exact?"exactly":a.inclusive?"at most":"less than"} ${a.maximum} element(s)`:a.type==="string"?i=`String must contain ${a.exact?"exactly":a.inclusive?"at most":"under"} ${a.maximum} character(s)`:a.type==="number"?i=`Number must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="bigint"?i=`BigInt must be ${a.exact?"exactly":a.inclusive?"less than or equal to":"less than"} ${a.maximum}`:a.type==="date"?i=`Date must be ${a.exact?"exactly":a.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(a.maximum))}`:i="Invalid input";break;case y.custom:i="Invalid input";break;case y.invalid_intersection_types:i="Intersection results could not be merged";break;case y.not_multiple_of:i=`Number must be a multiple of ${a.multipleOf}`;break;case y.not_finite:i="Number must be finite";break;default:i=n.defaultError,M.assertNever(a)}return{message:i}};let Rn=Te;function Oi(a){Rn=a}function bt(){return Rn}const xt=a=>{const{data:n,path:i,errorMaps:c,issueData:u}=a,d=[...i,...u.path||[]],h={...u,path:d};if(u.message!==void 0)return{...u,path:d,message:u.message};let p="";const w=c.filter(v=>!!v).slice().reverse();for(const v of w)p=v(h,{data:n,defaultError:p}).message;return{...u,path:d,message:p}},Ii=[];function _(a,n){const i=bt(),c=xt({issueData:n,data:a.data,path:a.path,errorMaps:[a.common.contextualErrorMap,a.schemaErrorMap,i,i===Te?void 0:Te].filter(u=>!!u)});a.common.issues.push(c)}class B{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(n,i){const c=[];for(const u of i){if(u.status==="aborted")return S;u.status==="dirty"&&n.dirty(),c.push(u.value)}return{status:n.value,value:c}}static async mergeObjectAsync(n,i){const c=[];for(const u of i){const d=await u.key,h=await u.value;c.push({key:d,value:h})}return B.mergeObjectSync(n,c)}static mergeObjectSync(n,i){const c={};for(const u of i){const{key:d,value:h}=u;if(d.status==="aborted"||h.status==="aborted")return S;d.status==="dirty"&&n.dirty(),h.status==="dirty"&&n.dirty(),d.value!=="__proto__"&&(typeof h.value<"u"||u.alwaysSet)&&(c[d.value]=h.value)}return{status:n.value,value:c}}}const S=Object.freeze({status:"aborted"}),Oe=a=>({status:"dirty",value:a}),F=a=>({status:"valid",value:a}),Kt=a=>a.status==="aborted",Yt=a=>a.status==="dirty",ye=a=>a.status==="valid",Le=a=>typeof Promise<"u"&&a instanceof Promise;function kt(a,n,i,c){if(typeof n=="function"?a!==n||!c:!n.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n.get(a)}function Dn(a,n,i,c,u){if(typeof n=="function"?a!==n||!u:!n.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n.set(a,i),i}typeof SuppressedError=="function"&&SuppressedError;var x;(function(a){a.errToObj=n=>typeof n=="string"?{message:n}:n||{},a.toString=n=>typeof n=="string"?n:n==null?void 0:n.message})(x||(x={}));var Fe,ze;class Y{constructor(n,i,c,u){this._cachedPath=[],this.parent=n,this.data=i,this._path=c,this._key=u}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const jn=(a,n)=>{if(ye(n))return{success:!0,data:n.value};if(!a.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const i=new z(a.common.issues);return this._error=i,this._error}}};function O(a){if(!a)return{};const{errorMap:n,invalid_type_error:i,required_error:c,description:u}=a;if(n&&(i||c))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return n?{errorMap:n,description:u}:{errorMap:(h,p)=>{var w,v;const{message:E}=a;return h.code==="invalid_enum_value"?{message:E??p.defaultError}:typeof p.data>"u"?{message:(w=E??c)!==null&&w!==void 0?w:p.defaultError}:h.code!=="invalid_type"?{message:p.defaultError}:{message:(v=E??i)!==null&&v!==void 0?v:p.defaultError}},description:u}}class I{get description(){return this._def.description}_getType(n){return re(n.data)}_getOrReturnCtx(n,i){return i||{common:n.parent.common,data:n.data,parsedType:re(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}_processInputParams(n){return{status:new B,ctx:{common:n.parent.common,data:n.data,parsedType:re(n.data),schemaErrorMap:this._def.errorMap,path:n.path,parent:n.parent}}}_parseSync(n){const i=this._parse(n);if(Le(i))throw new Error("Synchronous parse encountered promise.");return i}_parseAsync(n){const i=this._parse(n);return Promise.resolve(i)}parse(n,i){const c=this.safeParse(n,i);if(c.success)return c.data;throw c.error}safeParse(n,i){var c;const u={common:{issues:[],async:(c=i==null?void 0:i.async)!==null&&c!==void 0?c:!1,contextualErrorMap:i==null?void 0:i.errorMap},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:re(n)},d=this._parseSync({data:n,path:u.path,parent:u});return jn(u,d)}"~validate"(n){var i,c;const u={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:re(n)};if(!this["~standard"].async)try{const d=this._parseSync({data:n,path:[],parent:u});return ye(d)?{value:d.value}:{issues:u.common.issues}}catch(d){!((c=(i=d==null?void 0:d.message)===null||i===void 0?void 0:i.toLowerCase())===null||c===void 0)&&c.includes("encountered")&&(this["~standard"].async=!0),u.common={issues:[],async:!0}}return this._parseAsync({data:n,path:[],parent:u}).then(d=>ye(d)?{value:d.value}:{issues:u.common.issues})}async parseAsync(n,i){const c=await this.safeParseAsync(n,i);if(c.success)return c.data;throw c.error}async safeParseAsync(n,i){const c={common:{issues:[],contextualErrorMap:i==null?void 0:i.errorMap,async:!0},path:(i==null?void 0:i.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:n,parsedType:re(n)},u=this._parse({data:n,path:c.path,parent:c}),d=await(Le(u)?u:Promise.resolve(u));return jn(c,d)}refine(n,i){const c=u=>typeof i=="string"||typeof i>"u"?{message:i}:typeof i=="function"?i(u):i;return this._refinement((u,d)=>{const h=n(u),p=()=>d.addIssue({code:y.custom,...c(u)});return typeof Promise<"u"&&h instanceof Promise?h.then(w=>w?!0:(p(),!1)):h?!0:(p(),!1)})}refinement(n,i){return this._refinement((c,u)=>n(c)?!0:(u.addIssue(typeof i=="function"?i(c,u):i),!1))}_refinement(n){return new q({schema:this,typeName:A.ZodEffects,effect:{type:"refinement",refinement:n}})}superRefine(n){return this._refinement(n)}constructor(n){this.spa=this.safeParseAsync,this._def=n,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:i=>this["~validate"](i)}}optional(){return X.create(this,this._def)}nullable(){return fe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return H.create(this)}promise(){return Ce.create(this,this._def)}or(n){return qe.create([this,n],this._def)}and(n){return Ge.create(this,n,this._def)}transform(n){return new q({...O(this._def),schema:this,typeName:A.ZodEffects,effect:{type:"transform",transform:n}})}default(n){const i=typeof n=="function"?n:()=>n;return new Je({...O(this._def),innerType:this,defaultValue:i,typeName:A.ZodDefault})}brand(){return new Jt({typeName:A.ZodBranded,type:this,...O(this._def)})}catch(n){const i=typeof n=="function"?n:()=>n;return new et({...O(this._def),innerType:this,catchValue:i,typeName:A.ZodCatch})}describe(n){const i=this.constructor;return new i({...this._def,description:n})}pipe(n){return tt.create(this,n)}readonly(){return rt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Mi=/^c[^\s-]{8,}$/i,$i=/^[0-9a-z]+$/,Ci=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ni=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Ri=/^[a-z0-9_-]{21}$/i,Di=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ji=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Ui=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Pi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Qt;const Zi=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Bi=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Li=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Fi=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,zi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Vi=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Un="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Wi=new RegExp(`^${Un}$`);function Pn(a){let n="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return a.precision?n=`${n}\\.\\d{${a.precision}}`:a.precision==null&&(n=`${n}(\\.\\d+)?`),n}function Hi(a){return new RegExp(`^${Pn(a)}$`)}function Zn(a){let n=`${Un}T${Pn(a)}`;const i=[];return i.push(a.local?"Z?":"Z"),a.offset&&i.push("([+-]\\d{2}:?\\d{2})"),n=`${n}(${i.join("|")})`,new RegExp(`^${n}$`)}function qi(a,n){return!!((n==="v4"||!n)&&Zi.test(a)||(n==="v6"||!n)&&Li.test(a))}function Gi(a,n){if(!Di.test(a))return!1;try{const[i]=a.split("."),c=i.replace(/-/g,"+").replace(/_/g,"/").padEnd(i.length+(4-i.length%4)%4,"="),u=JSON.parse(atob(c));return!(typeof u!="object"||u===null||!u.typ||!u.alg||n&&u.alg!==n)}catch{return!1}}function Ki(a,n){return!!((n==="v4"||!n)&&Bi.test(a)||(n==="v6"||!n)&&Fi.test(a))}class W extends I{_parse(n){if(this._def.coerce&&(n.data=String(n.data)),this._getType(n)!==b.string){const d=this._getOrReturnCtx(n);return _(d,{code:y.invalid_type,expected:b.string,received:d.parsedType}),S}const c=new B;let u;for(const d of this._def.checks)if(d.kind==="min")n.data.length<d.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_small,minimum:d.value,type:"string",inclusive:!0,exact:!1,message:d.message}),c.dirty());else if(d.kind==="max")n.data.length>d.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_big,maximum:d.value,type:"string",inclusive:!0,exact:!1,message:d.message}),c.dirty());else if(d.kind==="length"){const h=n.data.length>d.value,p=n.data.length<d.value;(h||p)&&(u=this._getOrReturnCtx(n,u),h?_(u,{code:y.too_big,maximum:d.value,type:"string",inclusive:!0,exact:!0,message:d.message}):p&&_(u,{code:y.too_small,minimum:d.value,type:"string",inclusive:!0,exact:!0,message:d.message}),c.dirty())}else if(d.kind==="email")Ui.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"email",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="emoji")Qt||(Qt=new RegExp(Pi,"u")),Qt.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"emoji",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="uuid")Ni.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"uuid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="nanoid")Ri.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"nanoid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="cuid")Mi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"cuid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="cuid2")$i.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"cuid2",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="ulid")Ci.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"ulid",code:y.invalid_string,message:d.message}),c.dirty());else if(d.kind==="url")try{new URL(n.data)}catch{u=this._getOrReturnCtx(n,u),_(u,{validation:"url",code:y.invalid_string,message:d.message}),c.dirty()}else d.kind==="regex"?(d.regex.lastIndex=0,d.regex.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"regex",code:y.invalid_string,message:d.message}),c.dirty())):d.kind==="trim"?n.data=n.data.trim():d.kind==="includes"?n.data.includes(d.value,d.position)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:{includes:d.value,position:d.position},message:d.message}),c.dirty()):d.kind==="toLowerCase"?n.data=n.data.toLowerCase():d.kind==="toUpperCase"?n.data=n.data.toUpperCase():d.kind==="startsWith"?n.data.startsWith(d.value)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:{startsWith:d.value},message:d.message}),c.dirty()):d.kind==="endsWith"?n.data.endsWith(d.value)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:{endsWith:d.value},message:d.message}),c.dirty()):d.kind==="datetime"?Zn(d).test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:"datetime",message:d.message}),c.dirty()):d.kind==="date"?Wi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:"date",message:d.message}),c.dirty()):d.kind==="time"?Hi(d).test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{code:y.invalid_string,validation:"time",message:d.message}),c.dirty()):d.kind==="duration"?ji.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"duration",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="ip"?qi(n.data,d.version)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"ip",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="jwt"?Gi(n.data,d.alg)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"jwt",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="cidr"?Ki(n.data,d.version)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"cidr",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="base64"?zi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"base64",code:y.invalid_string,message:d.message}),c.dirty()):d.kind==="base64url"?Vi.test(n.data)||(u=this._getOrReturnCtx(n,u),_(u,{validation:"base64url",code:y.invalid_string,message:d.message}),c.dirty()):M.assertNever(d);return{status:c.value,value:n.data}}_regex(n,i,c){return this.refinement(u=>n.test(u),{validation:i,code:y.invalid_string,...x.errToObj(c)})}_addCheck(n){return new W({...this._def,checks:[...this._def.checks,n]})}email(n){return this._addCheck({kind:"email",...x.errToObj(n)})}url(n){return this._addCheck({kind:"url",...x.errToObj(n)})}emoji(n){return this._addCheck({kind:"emoji",...x.errToObj(n)})}uuid(n){return this._addCheck({kind:"uuid",...x.errToObj(n)})}nanoid(n){return this._addCheck({kind:"nanoid",...x.errToObj(n)})}cuid(n){return this._addCheck({kind:"cuid",...x.errToObj(n)})}cuid2(n){return this._addCheck({kind:"cuid2",...x.errToObj(n)})}ulid(n){return this._addCheck({kind:"ulid",...x.errToObj(n)})}base64(n){return this._addCheck({kind:"base64",...x.errToObj(n)})}base64url(n){return this._addCheck({kind:"base64url",...x.errToObj(n)})}jwt(n){return this._addCheck({kind:"jwt",...x.errToObj(n)})}ip(n){return this._addCheck({kind:"ip",...x.errToObj(n)})}cidr(n){return this._addCheck({kind:"cidr",...x.errToObj(n)})}datetime(n){var i,c;return typeof n=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:n}):this._addCheck({kind:"datetime",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,offset:(i=n==null?void 0:n.offset)!==null&&i!==void 0?i:!1,local:(c=n==null?void 0:n.local)!==null&&c!==void 0?c:!1,...x.errToObj(n==null?void 0:n.message)})}date(n){return this._addCheck({kind:"date",message:n})}time(n){return typeof n=="string"?this._addCheck({kind:"time",precision:null,message:n}):this._addCheck({kind:"time",precision:typeof(n==null?void 0:n.precision)>"u"?null:n==null?void 0:n.precision,...x.errToObj(n==null?void 0:n.message)})}duration(n){return this._addCheck({kind:"duration",...x.errToObj(n)})}regex(n,i){return this._addCheck({kind:"regex",regex:n,...x.errToObj(i)})}includes(n,i){return this._addCheck({kind:"includes",value:n,position:i==null?void 0:i.position,...x.errToObj(i==null?void 0:i.message)})}startsWith(n,i){return this._addCheck({kind:"startsWith",value:n,...x.errToObj(i)})}endsWith(n,i){return this._addCheck({kind:"endsWith",value:n,...x.errToObj(i)})}min(n,i){return this._addCheck({kind:"min",value:n,...x.errToObj(i)})}max(n,i){return this._addCheck({kind:"max",value:n,...x.errToObj(i)})}length(n,i){return this._addCheck({kind:"length",value:n,...x.errToObj(i)})}nonempty(n){return this.min(1,x.errToObj(n))}trim(){return new W({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new W({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new W({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(n=>n.kind==="datetime")}get isDate(){return!!this._def.checks.find(n=>n.kind==="date")}get isTime(){return!!this._def.checks.find(n=>n.kind==="time")}get isDuration(){return!!this._def.checks.find(n=>n.kind==="duration")}get isEmail(){return!!this._def.checks.find(n=>n.kind==="email")}get isURL(){return!!this._def.checks.find(n=>n.kind==="url")}get isEmoji(){return!!this._def.checks.find(n=>n.kind==="emoji")}get isUUID(){return!!this._def.checks.find(n=>n.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(n=>n.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(n=>n.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(n=>n.kind==="cuid2")}get isULID(){return!!this._def.checks.find(n=>n.kind==="ulid")}get isIP(){return!!this._def.checks.find(n=>n.kind==="ip")}get isCIDR(){return!!this._def.checks.find(n=>n.kind==="cidr")}get isBase64(){return!!this._def.checks.find(n=>n.kind==="base64")}get isBase64url(){return!!this._def.checks.find(n=>n.kind==="base64url")}get minLength(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxLength(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}W.create=a=>{var n;return new W({checks:[],typeName:A.ZodString,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};function Yi(a,n){const i=(a.toString().split(".")[1]||"").length,c=(n.toString().split(".")[1]||"").length,u=i>c?i:c,d=parseInt(a.toFixed(u).replace(".","")),h=parseInt(n.toFixed(u).replace(".",""));return d%h/Math.pow(10,u)}class ue extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(n){if(this._def.coerce&&(n.data=Number(n.data)),this._getType(n)!==b.number){const d=this._getOrReturnCtx(n);return _(d,{code:y.invalid_type,expected:b.number,received:d.parsedType}),S}let c;const u=new B;for(const d of this._def.checks)d.kind==="int"?M.isInteger(n.data)||(c=this._getOrReturnCtx(n,c),_(c,{code:y.invalid_type,expected:"integer",received:"float",message:d.message}),u.dirty()):d.kind==="min"?(d.inclusive?n.data<d.value:n.data<=d.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_small,minimum:d.value,type:"number",inclusive:d.inclusive,exact:!1,message:d.message}),u.dirty()):d.kind==="max"?(d.inclusive?n.data>d.value:n.data>=d.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_big,maximum:d.value,type:"number",inclusive:d.inclusive,exact:!1,message:d.message}),u.dirty()):d.kind==="multipleOf"?Yi(n.data,d.value)!==0&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.not_multiple_of,multipleOf:d.value,message:d.message}),u.dirty()):d.kind==="finite"?Number.isFinite(n.data)||(c=this._getOrReturnCtx(n,c),_(c,{code:y.not_finite,message:d.message}),u.dirty()):M.assertNever(d);return{status:u.value,value:n.data}}gte(n,i){return this.setLimit("min",n,!0,x.toString(i))}gt(n,i){return this.setLimit("min",n,!1,x.toString(i))}lte(n,i){return this.setLimit("max",n,!0,x.toString(i))}lt(n,i){return this.setLimit("max",n,!1,x.toString(i))}setLimit(n,i,c,u){return new ue({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(n){return new ue({...this._def,checks:[...this._def.checks,n]})}int(n){return this._addCheck({kind:"int",message:x.toString(n)})}positive(n){return this._addCheck({kind:"min",value:0,inclusive:!1,message:x.toString(n)})}negative(n){return this._addCheck({kind:"max",value:0,inclusive:!1,message:x.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:0,inclusive:!0,message:x.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:0,inclusive:!0,message:x.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:x.toString(i)})}finite(n){return this._addCheck({kind:"finite",message:x.toString(n)})}safe(n){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:x.toString(n)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:x.toString(n)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}get isInt(){return!!this._def.checks.find(n=>n.kind==="int"||n.kind==="multipleOf"&&M.isInteger(n.value))}get isFinite(){let n=null,i=null;for(const c of this._def.checks){if(c.kind==="finite"||c.kind==="int"||c.kind==="multipleOf")return!0;c.kind==="min"?(i===null||c.value>i)&&(i=c.value):c.kind==="max"&&(n===null||c.value<n)&&(n=c.value)}return Number.isFinite(i)&&Number.isFinite(n)}}ue.create=a=>new ue({checks:[],typeName:A.ZodNumber,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class le extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(n){if(this._def.coerce)try{n.data=BigInt(n.data)}catch{return this._getInvalidInput(n)}if(this._getType(n)!==b.bigint)return this._getInvalidInput(n);let c;const u=new B;for(const d of this._def.checks)d.kind==="min"?(d.inclusive?n.data<d.value:n.data<=d.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_small,type:"bigint",minimum:d.value,inclusive:d.inclusive,message:d.message}),u.dirty()):d.kind==="max"?(d.inclusive?n.data>d.value:n.data>=d.value)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.too_big,type:"bigint",maximum:d.value,inclusive:d.inclusive,message:d.message}),u.dirty()):d.kind==="multipleOf"?n.data%d.value!==BigInt(0)&&(c=this._getOrReturnCtx(n,c),_(c,{code:y.not_multiple_of,multipleOf:d.value,message:d.message}),u.dirty()):M.assertNever(d);return{status:u.value,value:n.data}}_getInvalidInput(n){const i=this._getOrReturnCtx(n);return _(i,{code:y.invalid_type,expected:b.bigint,received:i.parsedType}),S}gte(n,i){return this.setLimit("min",n,!0,x.toString(i))}gt(n,i){return this.setLimit("min",n,!1,x.toString(i))}lte(n,i){return this.setLimit("max",n,!0,x.toString(i))}lt(n,i){return this.setLimit("max",n,!1,x.toString(i))}setLimit(n,i,c,u){return new le({...this._def,checks:[...this._def.checks,{kind:n,value:i,inclusive:c,message:x.toString(u)}]})}_addCheck(n){return new le({...this._def,checks:[...this._def.checks,n]})}positive(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:x.toString(n)})}negative(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:x.toString(n)})}nonpositive(n){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:x.toString(n)})}nonnegative(n){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:x.toString(n)})}multipleOf(n,i){return this._addCheck({kind:"multipleOf",value:n,message:x.toString(i)})}get minValue(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n}get maxValue(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n}}le.create=a=>{var n;return new le({checks:[],typeName:A.ZodBigInt,coerce:(n=a==null?void 0:a.coerce)!==null&&n!==void 0?n:!1,...O(a)})};class Ve extends I{_parse(n){if(this._def.coerce&&(n.data=!!n.data),this._getType(n)!==b.boolean){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.boolean,received:c.parsedType}),S}return F(n.data)}}Ve.create=a=>new Ve({typeName:A.ZodBoolean,coerce:(a==null?void 0:a.coerce)||!1,...O(a)});class ve extends I{_parse(n){if(this._def.coerce&&(n.data=new Date(n.data)),this._getType(n)!==b.date){const d=this._getOrReturnCtx(n);return _(d,{code:y.invalid_type,expected:b.date,received:d.parsedType}),S}if(isNaN(n.data.getTime())){const d=this._getOrReturnCtx(n);return _(d,{code:y.invalid_date}),S}const c=new B;let u;for(const d of this._def.checks)d.kind==="min"?n.data.getTime()<d.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_small,message:d.message,inclusive:!0,exact:!1,minimum:d.value,type:"date"}),c.dirty()):d.kind==="max"?n.data.getTime()>d.value&&(u=this._getOrReturnCtx(n,u),_(u,{code:y.too_big,message:d.message,inclusive:!0,exact:!1,maximum:d.value,type:"date"}),c.dirty()):M.assertNever(d);return{status:c.value,value:new Date(n.data.getTime())}}_addCheck(n){return new ve({...this._def,checks:[...this._def.checks,n]})}min(n,i){return this._addCheck({kind:"min",value:n.getTime(),message:x.toString(i)})}max(n,i){return this._addCheck({kind:"max",value:n.getTime(),message:x.toString(i)})}get minDate(){let n=null;for(const i of this._def.checks)i.kind==="min"&&(n===null||i.value>n)&&(n=i.value);return n!=null?new Date(n):null}get maxDate(){let n=null;for(const i of this._def.checks)i.kind==="max"&&(n===null||i.value<n)&&(n=i.value);return n!=null?new Date(n):null}}ve.create=a=>new ve({checks:[],coerce:(a==null?void 0:a.coerce)||!1,typeName:A.ZodDate,...O(a)});class Et extends I{_parse(n){if(this._getType(n)!==b.symbol){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.symbol,received:c.parsedType}),S}return F(n.data)}}Et.create=a=>new Et({typeName:A.ZodSymbol,...O(a)});class We extends I{_parse(n){if(this._getType(n)!==b.undefined){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.undefined,received:c.parsedType}),S}return F(n.data)}}We.create=a=>new We({typeName:A.ZodUndefined,...O(a)});class He extends I{_parse(n){if(this._getType(n)!==b.null){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.null,received:c.parsedType}),S}return F(n.data)}}He.create=a=>new He({typeName:A.ZodNull,...O(a)});class Ie extends I{constructor(){super(...arguments),this._any=!0}_parse(n){return F(n.data)}}Ie.create=a=>new Ie({typeName:A.ZodAny,...O(a)});class we extends I{constructor(){super(...arguments),this._unknown=!0}_parse(n){return F(n.data)}}we.create=a=>new we({typeName:A.ZodUnknown,...O(a)});class ne extends I{_parse(n){const i=this._getOrReturnCtx(n);return _(i,{code:y.invalid_type,expected:b.never,received:i.parsedType}),S}}ne.create=a=>new ne({typeName:A.ZodNever,...O(a)});class At extends I{_parse(n){if(this._getType(n)!==b.undefined){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.void,received:c.parsedType}),S}return F(n.data)}}At.create=a=>new At({typeName:A.ZodVoid,...O(a)});class H extends I{_parse(n){const{ctx:i,status:c}=this._processInputParams(n),u=this._def;if(i.parsedType!==b.array)return _(i,{code:y.invalid_type,expected:b.array,received:i.parsedType}),S;if(u.exactLength!==null){const h=i.data.length>u.exactLength.value,p=i.data.length<u.exactLength.value;(h||p)&&(_(i,{code:h?y.too_big:y.too_small,minimum:p?u.exactLength.value:void 0,maximum:h?u.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:u.exactLength.message}),c.dirty())}if(u.minLength!==null&&i.data.length<u.minLength.value&&(_(i,{code:y.too_small,minimum:u.minLength.value,type:"array",inclusive:!0,exact:!1,message:u.minLength.message}),c.dirty()),u.maxLength!==null&&i.data.length>u.maxLength.value&&(_(i,{code:y.too_big,maximum:u.maxLength.value,type:"array",inclusive:!0,exact:!1,message:u.maxLength.message}),c.dirty()),i.common.async)return Promise.all([...i.data].map((h,p)=>u.type._parseAsync(new Y(i,h,i.path,p)))).then(h=>B.mergeArray(c,h));const d=[...i.data].map((h,p)=>u.type._parseSync(new Y(i,h,i.path,p)));return B.mergeArray(c,d)}get element(){return this._def.type}min(n,i){return new H({...this._def,minLength:{value:n,message:x.toString(i)}})}max(n,i){return new H({...this._def,maxLength:{value:n,message:x.toString(i)}})}length(n,i){return new H({...this._def,exactLength:{value:n,message:x.toString(i)}})}nonempty(n){return this.min(1,n)}}H.create=(a,n)=>new H({type:a,minLength:null,maxLength:null,exactLength:null,typeName:A.ZodArray,...O(n)});function Me(a){if(a instanceof R){const n={};for(const i in a.shape){const c=a.shape[i];n[i]=X.create(Me(c))}return new R({...a._def,shape:()=>n})}else return a instanceof H?new H({...a._def,type:Me(a.element)}):a instanceof X?X.create(Me(a.unwrap())):a instanceof fe?fe.create(Me(a.unwrap())):a instanceof Q?Q.create(a.items.map(n=>Me(n))):a}class R extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const n=this._def.shape(),i=M.objectKeys(n);return this._cached={shape:n,keys:i}}_parse(n){if(this._getType(n)!==b.object){const v=this._getOrReturnCtx(n);return _(v,{code:y.invalid_type,expected:b.object,received:v.parsedType}),S}const{status:c,ctx:u}=this._processInputParams(n),{shape:d,keys:h}=this._getCached(),p=[];if(!(this._def.catchall instanceof ne&&this._def.unknownKeys==="strip"))for(const v in u.data)h.includes(v)||p.push(v);const w=[];for(const v of h){const E=d[v],D=u.data[v];w.push({key:{status:"valid",value:v},value:E._parse(new Y(u,D,u.path,v)),alwaysSet:v in u.data})}if(this._def.catchall instanceof ne){const v=this._def.unknownKeys;if(v==="passthrough")for(const E of p)w.push({key:{status:"valid",value:E},value:{status:"valid",value:u.data[E]}});else if(v==="strict")p.length>0&&(_(u,{code:y.unrecognized_keys,keys:p}),c.dirty());else if(v!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const v=this._def.catchall;for(const E of p){const D=u.data[E];w.push({key:{status:"valid",value:E},value:v._parse(new Y(u,D,u.path,E)),alwaysSet:E in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const v=[];for(const E of w){const D=await E.key,ie=await E.value;v.push({key:D,value:ie,alwaysSet:E.alwaysSet})}return v}).then(v=>B.mergeObjectSync(c,v)):B.mergeObjectSync(c,w)}get shape(){return this._def.shape()}strict(n){return x.errToObj,new R({...this._def,unknownKeys:"strict",...n!==void 0?{errorMap:(i,c)=>{var u,d,h,p;const w=(h=(d=(u=this._def).errorMap)===null||d===void 0?void 0:d.call(u,i,c).message)!==null&&h!==void 0?h:c.defaultError;return i.code==="unrecognized_keys"?{message:(p=x.errToObj(n).message)!==null&&p!==void 0?p:w}:{message:w}}}:{}})}strip(){return new R({...this._def,unknownKeys:"strip"})}passthrough(){return new R({...this._def,unknownKeys:"passthrough"})}extend(n){return new R({...this._def,shape:()=>({...this._def.shape(),...n})})}merge(n){return new R({unknownKeys:n._def.unknownKeys,catchall:n._def.catchall,shape:()=>({...this._def.shape(),...n._def.shape()}),typeName:A.ZodObject})}setKey(n,i){return this.augment({[n]:i})}catchall(n){return new R({...this._def,catchall:n})}pick(n){const i={};return M.objectKeys(n).forEach(c=>{n[c]&&this.shape[c]&&(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}omit(n){const i={};return M.objectKeys(this.shape).forEach(c=>{n[c]||(i[c]=this.shape[c])}),new R({...this._def,shape:()=>i})}deepPartial(){return Me(this)}partial(n){const i={};return M.objectKeys(this.shape).forEach(c=>{const u=this.shape[c];n&&!n[c]?i[c]=u:i[c]=u.optional()}),new R({...this._def,shape:()=>i})}required(n){const i={};return M.objectKeys(this.shape).forEach(c=>{if(n&&!n[c])i[c]=this.shape[c];else{let d=this.shape[c];for(;d instanceof X;)d=d._def.innerType;i[c]=d}}),new R({...this._def,shape:()=>i})}keyof(){return Bn(M.objectKeys(this.shape))}}R.create=(a,n)=>new R({shape:()=>a,unknownKeys:"strip",catchall:ne.create(),typeName:A.ZodObject,...O(n)}),R.strictCreate=(a,n)=>new R({shape:()=>a,unknownKeys:"strict",catchall:ne.create(),typeName:A.ZodObject,...O(n)}),R.lazycreate=(a,n)=>new R({shape:a,unknownKeys:"strip",catchall:ne.create(),typeName:A.ZodObject,...O(n)});class qe extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=this._def.options;function u(d){for(const p of d)if(p.result.status==="valid")return p.result;for(const p of d)if(p.result.status==="dirty")return i.common.issues.push(...p.ctx.common.issues),p.result;const h=d.map(p=>new z(p.ctx.common.issues));return _(i,{code:y.invalid_union,unionErrors:h}),S}if(i.common.async)return Promise.all(c.map(async d=>{const h={...i,common:{...i.common,issues:[]},parent:null};return{result:await d._parseAsync({data:i.data,path:i.path,parent:h}),ctx:h}})).then(u);{let d;const h=[];for(const w of c){const v={...i,common:{...i.common,issues:[]},parent:null},E=w._parseSync({data:i.data,path:i.path,parent:v});if(E.status==="valid")return E;E.status==="dirty"&&!d&&(d={result:E,ctx:v}),v.common.issues.length&&h.push(v.common.issues)}if(d)return i.common.issues.push(...d.ctx.common.issues),d.result;const p=h.map(w=>new z(w));return _(i,{code:y.invalid_union,unionErrors:p}),S}}get options(){return this._def.options}}qe.create=(a,n)=>new qe({options:a,typeName:A.ZodUnion,...O(n)});const se=a=>a instanceof Ye?se(a.schema):a instanceof q?se(a.innerType()):a instanceof Qe?[a.value]:a instanceof de?a.options:a instanceof Xe?M.objectValues(a.enum):a instanceof Je?se(a._def.innerType):a instanceof We?[void 0]:a instanceof He?[null]:a instanceof X?[void 0,...se(a.unwrap())]:a instanceof fe?[null,...se(a.unwrap())]:a instanceof Jt||a instanceof rt?se(a.unwrap()):a instanceof et?se(a._def.innerType):[];class St extends I{_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==b.object)return _(i,{code:y.invalid_type,expected:b.object,received:i.parsedType}),S;const c=this.discriminator,u=i.data[c],d=this.optionsMap.get(u);return d?i.common.async?d._parseAsync({data:i.data,path:i.path,parent:i}):d._parseSync({data:i.data,path:i.path,parent:i}):(_(i,{code:y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[c]}),S)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(n,i,c){const u=new Map;for(const d of i){const h=se(d.shape[n]);if(!h.length)throw new Error(`A discriminator value for key \`${n}\` could not be extracted from all schema options`);for(const p of h){if(u.has(p))throw new Error(`Discriminator property ${String(n)} has duplicate value ${String(p)}`);u.set(p,d)}}return new St({typeName:A.ZodDiscriminatedUnion,discriminator:n,options:i,optionsMap:u,...O(c)})}}function Xt(a,n){const i=re(a),c=re(n);if(a===n)return{valid:!0,data:a};if(i===b.object&&c===b.object){const u=M.objectKeys(n),d=M.objectKeys(a).filter(p=>u.indexOf(p)!==-1),h={...a,...n};for(const p of d){const w=Xt(a[p],n[p]);if(!w.valid)return{valid:!1};h[p]=w.data}return{valid:!0,data:h}}else if(i===b.array&&c===b.array){if(a.length!==n.length)return{valid:!1};const u=[];for(let d=0;d<a.length;d++){const h=a[d],p=n[d],w=Xt(h,p);if(!w.valid)return{valid:!1};u.push(w.data)}return{valid:!0,data:u}}else return i===b.date&&c===b.date&&+a==+n?{valid:!0,data:a}:{valid:!1}}class Ge extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=(d,h)=>{if(Kt(d)||Kt(h))return S;const p=Xt(d.value,h.value);return p.valid?((Yt(d)||Yt(h))&&i.dirty(),{status:i.value,value:p.data}):(_(c,{code:y.invalid_intersection_types}),S)};return c.common.async?Promise.all([this._def.left._parseAsync({data:c.data,path:c.path,parent:c}),this._def.right._parseAsync({data:c.data,path:c.path,parent:c})]).then(([d,h])=>u(d,h)):u(this._def.left._parseSync({data:c.data,path:c.path,parent:c}),this._def.right._parseSync({data:c.data,path:c.path,parent:c}))}}Ge.create=(a,n,i)=>new Ge({left:a,right:n,typeName:A.ZodIntersection,...O(i)});class Q extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.array)return _(c,{code:y.invalid_type,expected:b.array,received:c.parsedType}),S;if(c.data.length<this._def.items.length)return _(c,{code:y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),S;!this._def.rest&&c.data.length>this._def.items.length&&(_(c,{code:y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),i.dirty());const d=[...c.data].map((h,p)=>{const w=this._def.items[p]||this._def.rest;return w?w._parse(new Y(c,h,c.path,p)):null}).filter(h=>!!h);return c.common.async?Promise.all(d).then(h=>B.mergeArray(i,h)):B.mergeArray(i,d)}get items(){return this._def.items}rest(n){return new Q({...this._def,rest:n})}}Q.create=(a,n)=>{if(!Array.isArray(a))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Q({items:a,typeName:A.ZodTuple,rest:null,...O(n)})};class Ke extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.object)return _(c,{code:y.invalid_type,expected:b.object,received:c.parsedType}),S;const u=[],d=this._def.keyType,h=this._def.valueType;for(const p in c.data)u.push({key:d._parse(new Y(c,p,c.path,p)),value:h._parse(new Y(c,c.data[p],c.path,p)),alwaysSet:p in c.data});return c.common.async?B.mergeObjectAsync(i,u):B.mergeObjectSync(i,u)}get element(){return this._def.valueType}static create(n,i,c){return i instanceof I?new Ke({keyType:n,valueType:i,typeName:A.ZodRecord,...O(c)}):new Ke({keyType:W.create(),valueType:n,typeName:A.ZodRecord,...O(i)})}}class Tt extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.map)return _(c,{code:y.invalid_type,expected:b.map,received:c.parsedType}),S;const u=this._def.keyType,d=this._def.valueType,h=[...c.data.entries()].map(([p,w],v)=>({key:u._parse(new Y(c,p,c.path,[v,"key"])),value:d._parse(new Y(c,w,c.path,[v,"value"]))}));if(c.common.async){const p=new Map;return Promise.resolve().then(async()=>{for(const w of h){const v=await w.key,E=await w.value;if(v.status==="aborted"||E.status==="aborted")return S;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),p.set(v.value,E.value)}return{status:i.value,value:p}})}else{const p=new Map;for(const w of h){const v=w.key,E=w.value;if(v.status==="aborted"||E.status==="aborted")return S;(v.status==="dirty"||E.status==="dirty")&&i.dirty(),p.set(v.value,E.value)}return{status:i.value,value:p}}}}Tt.create=(a,n,i)=>new Tt({valueType:n,keyType:a,typeName:A.ZodMap,...O(i)});class _e extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.parsedType!==b.set)return _(c,{code:y.invalid_type,expected:b.set,received:c.parsedType}),S;const u=this._def;u.minSize!==null&&c.data.size<u.minSize.value&&(_(c,{code:y.too_small,minimum:u.minSize.value,type:"set",inclusive:!0,exact:!1,message:u.minSize.message}),i.dirty()),u.maxSize!==null&&c.data.size>u.maxSize.value&&(_(c,{code:y.too_big,maximum:u.maxSize.value,type:"set",inclusive:!0,exact:!1,message:u.maxSize.message}),i.dirty());const d=this._def.valueType;function h(w){const v=new Set;for(const E of w){if(E.status==="aborted")return S;E.status==="dirty"&&i.dirty(),v.add(E.value)}return{status:i.value,value:v}}const p=[...c.data.values()].map((w,v)=>d._parse(new Y(c,w,c.path,v)));return c.common.async?Promise.all(p).then(w=>h(w)):h(p)}min(n,i){return new _e({...this._def,minSize:{value:n,message:x.toString(i)}})}max(n,i){return new _e({...this._def,maxSize:{value:n,message:x.toString(i)}})}size(n,i){return this.min(n,i).max(n,i)}nonempty(n){return this.min(1,n)}}_e.create=(a,n)=>new _e({valueType:a,minSize:null,maxSize:null,typeName:A.ZodSet,...O(n)});class $e extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==b.function)return _(i,{code:y.invalid_type,expected:b.function,received:i.parsedType}),S;function c(p,w){return xt({data:p,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,bt(),Te].filter(v=>!!v),issueData:{code:y.invalid_arguments,argumentsError:w}})}function u(p,w){return xt({data:p,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,bt(),Te].filter(v=>!!v),issueData:{code:y.invalid_return_type,returnTypeError:w}})}const d={errorMap:i.common.contextualErrorMap},h=i.data;if(this._def.returns instanceof Ce){const p=this;return F(async function(...w){const v=new z([]),E=await p._def.args.parseAsync(w,d).catch(ae=>{throw v.addIssue(c(w,ae)),v}),D=await Reflect.apply(h,this,E);return await p._def.returns._def.type.parseAsync(D,d).catch(ae=>{throw v.addIssue(u(D,ae)),v})})}else{const p=this;return F(function(...w){const v=p._def.args.safeParse(w,d);if(!v.success)throw new z([c(w,v.error)]);const E=Reflect.apply(h,this,v.data),D=p._def.returns.safeParse(E,d);if(!D.success)throw new z([u(E,D.error)]);return D.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...n){return new $e({...this._def,args:Q.create(n).rest(we.create())})}returns(n){return new $e({...this._def,returns:n})}implement(n){return this.parse(n)}strictImplement(n){return this.parse(n)}static create(n,i,c){return new $e({args:n||Q.create([]).rest(we.create()),returns:i||we.create(),typeName:A.ZodFunction,...O(c)})}}class Ye extends I{get schema(){return this._def.getter()}_parse(n){const{ctx:i}=this._processInputParams(n);return this._def.getter()._parse({data:i.data,path:i.path,parent:i})}}Ye.create=(a,n)=>new Ye({getter:a,typeName:A.ZodLazy,...O(n)});class Qe extends I{_parse(n){if(n.data!==this._def.value){const i=this._getOrReturnCtx(n);return _(i,{received:i.data,code:y.invalid_literal,expected:this._def.value}),S}return{status:"valid",value:n.data}}get value(){return this._def.value}}Qe.create=(a,n)=>new Qe({value:a,typeName:A.ZodLiteral,...O(n)});function Bn(a,n){return new de({values:a,typeName:A.ZodEnum,...O(n)})}class de extends I{constructor(){super(...arguments),Fe.set(this,void 0)}_parse(n){if(typeof n.data!="string"){const i=this._getOrReturnCtx(n),c=this._def.values;return _(i,{expected:M.joinValues(c),received:i.parsedType,code:y.invalid_type}),S}if(kt(this,Fe)||Dn(this,Fe,new Set(this._def.values)),!kt(this,Fe).has(n.data)){const i=this._getOrReturnCtx(n),c=this._def.values;return _(i,{received:i.data,code:y.invalid_enum_value,options:c}),S}return F(n.data)}get options(){return this._def.values}get enum(){const n={};for(const i of this._def.values)n[i]=i;return n}get Values(){const n={};for(const i of this._def.values)n[i]=i;return n}get Enum(){const n={};for(const i of this._def.values)n[i]=i;return n}extract(n,i=this._def){return de.create(n,{...this._def,...i})}exclude(n,i=this._def){return de.create(this.options.filter(c=>!n.includes(c)),{...this._def,...i})}}Fe=new WeakMap,de.create=Bn;class Xe extends I{constructor(){super(...arguments),ze.set(this,void 0)}_parse(n){const i=M.getValidEnumValues(this._def.values),c=this._getOrReturnCtx(n);if(c.parsedType!==b.string&&c.parsedType!==b.number){const u=M.objectValues(i);return _(c,{expected:M.joinValues(u),received:c.parsedType,code:y.invalid_type}),S}if(kt(this,ze)||Dn(this,ze,new Set(M.getValidEnumValues(this._def.values))),!kt(this,ze).has(n.data)){const u=M.objectValues(i);return _(c,{received:c.data,code:y.invalid_enum_value,options:u}),S}return F(n.data)}get enum(){return this._def.values}}ze=new WeakMap,Xe.create=(a,n)=>new Xe({values:a,typeName:A.ZodNativeEnum,...O(n)});class Ce extends I{unwrap(){return this._def.type}_parse(n){const{ctx:i}=this._processInputParams(n);if(i.parsedType!==b.promise&&i.common.async===!1)return _(i,{code:y.invalid_type,expected:b.promise,received:i.parsedType}),S;const c=i.parsedType===b.promise?i.data:Promise.resolve(i.data);return F(c.then(u=>this._def.type.parseAsync(u,{path:i.path,errorMap:i.common.contextualErrorMap})))}}Ce.create=(a,n)=>new Ce({type:a,typeName:A.ZodPromise,...O(n)});class q extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===A.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(n){const{status:i,ctx:c}=this._processInputParams(n),u=this._def.effect||null,d={addIssue:h=>{_(c,h),h.fatal?i.abort():i.dirty()},get path(){return c.path}};if(d.addIssue=d.addIssue.bind(d),u.type==="preprocess"){const h=u.transform(c.data,d);if(c.common.async)return Promise.resolve(h).then(async p=>{if(i.value==="aborted")return S;const w=await this._def.schema._parseAsync({data:p,path:c.path,parent:c});return w.status==="aborted"?S:w.status==="dirty"||i.value==="dirty"?Oe(w.value):w});{if(i.value==="aborted")return S;const p=this._def.schema._parseSync({data:h,path:c.path,parent:c});return p.status==="aborted"?S:p.status==="dirty"||i.value==="dirty"?Oe(p.value):p}}if(u.type==="refinement"){const h=p=>{const w=u.refinement(p,d);if(c.common.async)return Promise.resolve(w);if(w instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return p};if(c.common.async===!1){const p=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});return p.status==="aborted"?S:(p.status==="dirty"&&i.dirty(),h(p.value),{status:i.value,value:p.value})}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(p=>p.status==="aborted"?S:(p.status==="dirty"&&i.dirty(),h(p.value).then(()=>({status:i.value,value:p.value}))))}if(u.type==="transform")if(c.common.async===!1){const h=this._def.schema._parseSync({data:c.data,path:c.path,parent:c});if(!ye(h))return h;const p=u.transform(h.value,d);if(p instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:i.value,value:p}}else return this._def.schema._parseAsync({data:c.data,path:c.path,parent:c}).then(h=>ye(h)?Promise.resolve(u.transform(h.value,d)).then(p=>({status:i.value,value:p})):h);M.assertNever(u)}}q.create=(a,n,i)=>new q({schema:a,typeName:A.ZodEffects,effect:n,...O(i)}),q.createWithPreprocess=(a,n,i)=>new q({schema:n,effect:{type:"preprocess",transform:a},typeName:A.ZodEffects,...O(i)});class X extends I{_parse(n){return this._getType(n)===b.undefined?F(void 0):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}X.create=(a,n)=>new X({innerType:a,typeName:A.ZodOptional,...O(n)});class fe extends I{_parse(n){return this._getType(n)===b.null?F(null):this._def.innerType._parse(n)}unwrap(){return this._def.innerType}}fe.create=(a,n)=>new fe({innerType:a,typeName:A.ZodNullable,...O(n)});class Je extends I{_parse(n){const{ctx:i}=this._processInputParams(n);let c=i.data;return i.parsedType===b.undefined&&(c=this._def.defaultValue()),this._def.innerType._parse({data:c,path:i.path,parent:i})}removeDefault(){return this._def.innerType}}Je.create=(a,n)=>new Je({innerType:a,typeName:A.ZodDefault,defaultValue:typeof n.default=="function"?n.default:()=>n.default,...O(n)});class et extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c={...i,common:{...i.common,issues:[]}},u=this._def.innerType._parse({data:c.data,path:c.path,parent:{...c}});return Le(u)?u.then(d=>({status:"valid",value:d.status==="valid"?d.value:this._def.catchValue({get error(){return new z(c.common.issues)},input:c.data})})):{status:"valid",value:u.status==="valid"?u.value:this._def.catchValue({get error(){return new z(c.common.issues)},input:c.data})}}removeCatch(){return this._def.innerType}}et.create=(a,n)=>new et({innerType:a,typeName:A.ZodCatch,catchValue:typeof n.catch=="function"?n.catch:()=>n.catch,...O(n)});class Ot extends I{_parse(n){if(this._getType(n)!==b.nan){const c=this._getOrReturnCtx(n);return _(c,{code:y.invalid_type,expected:b.nan,received:c.parsedType}),S}return{status:"valid",value:n.data}}}Ot.create=a=>new Ot({typeName:A.ZodNaN,...O(a)});const Qi=Symbol("zod_brand");class Jt extends I{_parse(n){const{ctx:i}=this._processInputParams(n),c=i.data;return this._def.type._parse({data:c,path:i.path,parent:i})}unwrap(){return this._def.type}}class tt extends I{_parse(n){const{status:i,ctx:c}=this._processInputParams(n);if(c.common.async)return(async()=>{const d=await this._def.in._parseAsync({data:c.data,path:c.path,parent:c});return d.status==="aborted"?S:d.status==="dirty"?(i.dirty(),Oe(d.value)):this._def.out._parseAsync({data:d.value,path:c.path,parent:c})})();{const u=this._def.in._parseSync({data:c.data,path:c.path,parent:c});return u.status==="aborted"?S:u.status==="dirty"?(i.dirty(),{status:"dirty",value:u.value}):this._def.out._parseSync({data:u.value,path:c.path,parent:c})}}static create(n,i){return new tt({in:n,out:i,typeName:A.ZodPipeline})}}class rt extends I{_parse(n){const i=this._def.innerType._parse(n),c=u=>(ye(u)&&(u.value=Object.freeze(u.value)),u);return Le(i)?i.then(u=>c(u)):c(i)}unwrap(){return this._def.innerType}}rt.create=(a,n)=>new rt({innerType:a,typeName:A.ZodReadonly,...O(n)});function Ln(a,n={},i){return a?Ie.create().superRefine((c,u)=>{var d,h;if(!a(c)){const p=typeof n=="function"?n(c):typeof n=="string"?{message:n}:n,w=(h=(d=p.fatal)!==null&&d!==void 0?d:i)!==null&&h!==void 0?h:!0,v=typeof p=="string"?{message:p}:p;u.addIssue({code:"custom",...v,fatal:w})}}):Ie.create()}const Xi={object:R.lazycreate};var A;(function(a){a.ZodString="ZodString",a.ZodNumber="ZodNumber",a.ZodNaN="ZodNaN",a.ZodBigInt="ZodBigInt",a.ZodBoolean="ZodBoolean",a.ZodDate="ZodDate",a.ZodSymbol="ZodSymbol",a.ZodUndefined="ZodUndefined",a.ZodNull="ZodNull",a.ZodAny="ZodAny",a.ZodUnknown="ZodUnknown",a.ZodNever="ZodNever",a.ZodVoid="ZodVoid",a.ZodArray="ZodArray",a.ZodObject="ZodObject",a.ZodUnion="ZodUnion",a.ZodDiscriminatedUnion="ZodDiscriminatedUnion",a.ZodIntersection="ZodIntersection",a.ZodTuple="ZodTuple",a.ZodRecord="ZodRecord",a.ZodMap="ZodMap",a.ZodSet="ZodSet",a.ZodFunction="ZodFunction",a.ZodLazy="ZodLazy",a.ZodLiteral="ZodLiteral",a.ZodEnum="ZodEnum",a.ZodEffects="ZodEffects",a.ZodNativeEnum="ZodNativeEnum",a.ZodOptional="ZodOptional",a.ZodNullable="ZodNullable",a.ZodDefault="ZodDefault",a.ZodCatch="ZodCatch",a.ZodPromise="ZodPromise",a.ZodBranded="ZodBranded",a.ZodPipeline="ZodPipeline",a.ZodReadonly="ZodReadonly"})(A||(A={}));const Ji=(a,n={message:`Input not instance of ${a.name}`})=>Ln(i=>i instanceof a,n),Fn=W.create,zn=ue.create,ea=Ot.create,ta=le.create,Vn=Ve.create,ra=ve.create,na=Et.create,sa=We.create,ia=He.create,aa=Ie.create,oa=we.create,ca=ne.create,ua=At.create,la=H.create,da=R.create,fa=R.strictCreate,ha=qe.create,pa=St.create,ma=Ge.create,ga=Q.create,ya=Ke.create,va=Tt.create,wa=_e.create,_a=$e.create,ba=Ye.create,xa=Qe.create,ka=de.create,Ea=Xe.create,Aa=Ce.create,Wn=q.create,Sa=X.create,Ta=fe.create,Oa=q.createWithPreprocess,Ia=tt.create;var J=Object.freeze({__proto__:null,defaultErrorMap:Te,setErrorMap:Oi,getErrorMap:bt,makeIssue:xt,EMPTY_PATH:Ii,addIssueToContext:_,ParseStatus:B,INVALID:S,DIRTY:Oe,OK:F,isAborted:Kt,isDirty:Yt,isValid:ye,isAsync:Le,get util(){return M},get objectUtil(){return Gt},ZodParsedType:b,getParsedType:re,ZodType:I,datetimeRegex:Zn,ZodString:W,ZodNumber:ue,ZodBigInt:le,ZodBoolean:Ve,ZodDate:ve,ZodSymbol:Et,ZodUndefined:We,ZodNull:He,ZodAny:Ie,ZodUnknown:we,ZodNever:ne,ZodVoid:At,ZodArray:H,ZodObject:R,ZodUnion:qe,ZodDiscriminatedUnion:St,ZodIntersection:Ge,ZodTuple:Q,ZodRecord:Ke,ZodMap:Tt,ZodSet:_e,ZodFunction:$e,ZodLazy:Ye,ZodLiteral:Qe,ZodEnum:de,ZodNativeEnum:Xe,ZodPromise:Ce,ZodEffects:q,ZodTransformer:q,ZodOptional:X,ZodNullable:fe,ZodDefault:Je,ZodCatch:et,ZodNaN:Ot,BRAND:Qi,ZodBranded:Jt,ZodPipeline:tt,ZodReadonly:rt,custom:Ln,Schema:I,ZodSchema:I,late:Xi,get ZodFirstPartyTypeKind(){return A},coerce:{string:a=>W.create({...a,coerce:!0}),number:a=>ue.create({...a,coerce:!0}),boolean:a=>Ve.create({...a,coerce:!0}),bigint:a=>le.create({...a,coerce:!0}),date:a=>ve.create({...a,coerce:!0})},any:aa,array:la,bigint:ta,boolean:Vn,date:ra,discriminatedUnion:pa,effect:Wn,enum:ka,function:_a,instanceof:Ji,intersection:ma,lazy:ba,literal:xa,map:va,nan:ea,nativeEnum:Ea,never:ca,null:ia,nullable:Ta,number:zn,object:da,oboolean:()=>Vn().optional(),onumber:()=>zn().optional(),optional:Sa,ostring:()=>Fn().optional(),pipeline:Ia,preprocess:Oa,promise:Aa,record:ya,set:wa,strictObject:fa,string:Fn,symbol:na,transformer:Wn,tuple:ga,undefined:sa,union:ha,unknown:oa,void:ua,NEVER:S,ZodIssueCode:y,quotelessJson:Ti,ZodError:z});const Hn=K.getInstance(),Ma=J.object({id:J.string(),message:J.string(),username:J.string(),address:J.string(),timestamp:J.number(),signature:J.string(),index:J.number(),chatTopic:J.string(),userTopic:J.string()});function $a(a){const n=Ma.safeParse(a);return n.success?Ca(a)?!0:(console.warn("Invalid messageSender"),!1):(Hn.warn(n.error.format()),!1)}function Ca(a){try{const n={username:a.username,address:a.address,timestamp:a.timestamp},i=new TextEncoder,c=Z.concatBytes(i.encode(`Ethereum Signed Message:
11
+ 32`),Z.keccak256(i.encode(JSON.stringify(n))));if(new T.Signature(a.signature).isValid(c,a.address))throw new Error("Signature verification failed!");return!0}catch(n){return Hn.warn("Error in validateUserSignature",n),!1}}const G={LOADING_INIT:"loadingInit",LOADING_PREVIOUS_MESSAGES:"loadingPreviousMessages",MESSAGE_RECEIVED:"messageReceived",MESSAGE_REQUEST_INITIATED:"messageRequestInitiated",MESSAGE_REQUEST_UPLOADED:"messageRequestUploaded",MESSAGE_REQUEST_ERROR:"messageRequestError",CRITICAL_ERROR:"criticalError"};class Na{constructor(n,i){this.utils=n,this.emitter=i,this.logger=K.getInstance(),this.errorHandler=new qt,this.historyIndex=null}async init(){try{const n=await this.utils.fetchLatestChatMessage();return this.historyIndex=n.index,await this.fetchPreviousMessages(),n.index}catch(n){return this.errorHandler.handleError(n,"SwarmHistory.init"),T.FeedIndex.fromBigInt(0n)}}async fetchPreviousMessages(n=10){try{if(!this.historyIndex){this.logger.warn("History index is not set. Cannot fetch previous messages.");return}if(this.historyIndex.toBigInt()===0n){this.logger.warn("No previous messages to fetch.");return}const i=this.historyIndex.toBigInt(),c=i>BigInt(n)?i-BigInt(n):0n;for(let u=i-1n;u>=c;u--){const d=await this.utils.fetchChatMessage(T.FeedIndex.fromBigInt(u));if(this.emitter.emit(G.MESSAGE_RECEIVED,d),this.historyIndex=T.FeedIndex.fromBigInt(u),u===0n)break}}catch(i){this.errorHandler.handleError(i,"SwarmHistory.fetchPreviousMessages")}}}class Ra{constructor(n,i){this.userDetails=n,this.swarmSettings=i,this.depth=24,this.logger=K.getInstance(),this.errorHandler=new qt,this.UPLOAD_GSOC_TIMEOUT=2e3}async writeOwnFeedDataByIndex(n,i){const{enveloped:c,stamp:u}=this.swarmSettings;if(!c)await this.writeOwnFeedDataByIndexOwned(n,i);else if(u)await this.writeOwnFeedDataByIndexEnvelope(n,i);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async writeOwnFeedDataByIndexOwned(n,i){const{bee:c,stamp:u,chatTopic:d}=this.swarmSettings,{privateKey:h,ownAddress:p}=this.userDetails,w=this.generateUserOwnedFeedId(d,p),v=T.Topic.fromString(w);console.log("DEBUG: feedID write",v.toString(),p,n,w),await c.makeFeedWriter(v,new T.PrivateKey(h)).uploadPayload(u,JSON.stringify(i),{index:n})}async writeOwnFeedDataByIndexEnvelope(n,i){const{bee:c,stamp:u,chatTopic:d}=this.swarmSettings,{privateKey:h,ownAddress:p}=this.userDetails,w=new T.PrivateKey(h),v=T.Stamper.fromBlank(h,u,this.depth),E=this.generateUserOwnedFeedId(d,p),D=T.Topic.fromString(E),ie=$n(D,n),ae=Cn(i),nt=Nn(ae,ie,w),Ne={hash:()=>nt.address.toUint8Array()},er=v.stamp(Ne),{upload:tr}=c.makeSOCWriter(w),st=T.Bytes.fromUtf8(i);return(await tr(er,ie,st.toUint8Array())).reference.toHex()}orderMessages(n){return n.sort((i,c)=>i.timestamp-c.timestamp)}async retryAwaitableAsync(n,i=3,c=250){return new Promise((u,d)=>{n().then(u).catch(h=>{i>0?(this.logger.info(`Retrying... Attempts left: ${i}. Error: ${h.message}`),setTimeout(()=>{this.retryAwaitableAsync(n,i-1,c).then(u).catch(d)},c)):(this.errorHandler.handleError(h,"Utils.retryAwaitableAsync"),d(h))})})}async uploadObjectToBee(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(i){if(c)return this.uploadObjectToBeeEnvelope(n);throw new Error("Enveloped mode is enabled, but stamp is not provided")}else return this.uploadObjectToBeeOwn(n)}async uploadObjectToBeeOwn(n){try{const{bee:i,stamp:c}=this.swarmSettings,u=await i.uploadData(c,JSON.stringify(n),{redundancyLevel:4});return console.log("DEBUG: result",u.reference.toString()),u.reference.toString()}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async uploadObjectToBeeEnvelope(n){try{const{bee:i,stamp:c}=this.swarmSettings,{privateKey:u}=this.userDetails,d=T.Stamper.fromBlank(u,c,this.depth),h=T.Bytes.fromUtf8(JSON.stringify(n)),p=new _i(async v=>{await i.uploadChunk(d.stamp(v),v.build())});await p.append(h.toUint8Array());const w=await p.finalize();return Z.uint8ArrayToHex(w.hash())}catch(i){return this.errorHandler.handleError(i,"Utils.uploadObjectToBee"),null}}async getOwnLatestFeedIndex(){try{const{bee:n,chatTopic:i}=this.swarmSettings,{ownAddress:c}=this.userDetails,u=this.generateUserOwnedFeedId(i,c),d=T.Topic.fromString(u),p=await n.makeFeedReader(d,c).downloadPayload(),w=Number(p.feedIndex.toBigInt()),v=w+1;return console.log("DEBUG: getLatestFeedIndex",w,v),{latestIndex:w,nextIndex:v}}catch(n){if(this.isNotFoundError(n))return{latestIndex:-1,nextIndex:0};throw n}}async fetchLatestChatMessage(){const{bee:n,chatTopic:i,chatAddress:c}=this.swarmSettings,d=await n.makeFeedReader(T.Topic.fromString(i),Ht(c)).downloadPayload();return{message:d.payload.toJSON(),index:d.feedIndex}}async fetchChatMessage(n){const{bee:i,chatTopic:c,chatAddress:u}=this.swarmSettings;return(await i.makeFeedReader(T.Topic.fromString(c),Ht(u)).downloadPayload({index:n})).payload.toJSON()}async sendMessageToGsoc(n){const{enveloped:i,stamp:c}=this.swarmSettings;if(!i)await this.sendMessageToGsocOwn(n);else if(c)await this.sendMessageToGsocEnvelope(n);else throw new Error("Enveloped mode is enabled, but stamp is not provided")}async rawSocDownload(n,i){const{beeUrl:c}=this.swarmSettings,u=await fetch(`${c}/soc/${n}/${i}`,{headers:{"swarm-chunk-retrieval-timeout":"2000ms"}});if(!u.ok)throw new Error(`Failed to fetch: ${n}/${i}`);return u.text()}async sendMessageToGsocOwn(n){this.logger.debug("sendMessageToGsoc entry CALLED");const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:d}=this.swarmSettings,h=new T.PrivateKey(d),p=T.Identifier.fromString(u),w=T.Bytes.fromUtf8(n),{upload:v}=i.makeSOCWriter(h,{timeout:this.UPLOAD_GSOC_TIMEOUT});await v(c,p,w.toUint8Array()),this.logger.debug("sendMessageToGsoc end CALLED")}async sendMessageToGsocEnvelope(n){this.logger.debug("sendMessageToGsoc entry CALLED");const{bee:i,stamp:c,gsocTopic:u,gsocResourceId:d}=this.swarmSettings,{privateKey:h}=this.userDetails,p=T.Stamper.fromBlank(h,c,this.depth),w=new T.PrivateKey(d),v=T.Identifier.fromString(u),E=T.Bytes.fromUtf8(n),D=Cn(E.toUint8Array()),ie=Nn(D,v,w),ae={hash:()=>ie.address.toUint8Array()},nt=p.stamp(ae),{upload:Ne}=i.makeSOCWriter(w,{timeout:this.UPLOAD_GSOC_TIMEOUT});await Ne(nt,v,E.toUint8Array()),this.logger.debug("sendMessageToGsoc end CALLED")}generateUserOwnedFeedId(n,i){return`${n}_EthercastChat_${i}`}isNotFoundError(n){return n.stack.includes("404")||n.message.includes("Not Found")||n.message.includes("404")||n.code===404}}class Da{constructor(n){this.logger=K.getInstance(),this.errorHandler=new qt,this.gsocIndex=null,this.fetchProcessRunning=!1,this.stopFetch=!1;const i=new T.PrivateKey(Ht(n.user.privateKey));this.userDetails={privateKey:n.user.privateKey,ownAddress:i.publicKey().address().toString(),nickname:n.user.nickname,ownIndex:-1},this.swarmSettings={bee:new T.Bee(n.infra.beeUrl),beeUrl:n.infra.beeUrl,stamp:n.infra.stamp||"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",enveloped:n.infra.enveloped,gsocTopic:n.infra.gsocTopic,gsocResourceId:n.infra.gsocResourceId,chatTopic:n.infra.chatTopic,chatAddress:n.infra.chatAddress},this.emitter=new Si,this.utils=new Ra(this.userDetails,this.swarmSettings),this.history=new Na(this.utils,this.emitter)}start(){this.init(),this.startMessagesFetchProcess()}stop(){this.emitter.cleanAll(),this.stopMessagesFetchProcess()}getEmitter(){return this.emitter}orderMessages(n){return this.utils.orderMessages(n)}async sendMessage(n,i){const c=this.userDetails.ownIndex===-1?0:this.userDetails.ownIndex+1,u={id:i||vi(),username:this.userDetails.nickname,address:this.userDetails.ownAddress,chatTopic:this.swarmSettings.chatTopic,userTopic:this.utils.generateUserOwnedFeedId(this.swarmSettings.chatTopic,this.userDetails.ownAddress),signature:this.getSignature(),timestamp:Date.now(),index:c,message:n};try{this.emitter.emit(G.MESSAGE_REQUEST_INITIATED,u),await this.utils.writeOwnFeedDataByIndex(c,JSON.stringify(u)),this.userDetails.ownIndex=c,this.emitter.emit(G.MESSAGE_REQUEST_UPLOADED,u),await this.broadcastUserMessage(u)}catch(d){this.emitter.emit(G.MESSAGE_REQUEST_ERROR,u),this.errorHandler.handleError(d,"Chat.sendMessage")}}async fetchPreviousMessages(){try{return this.emitter.emit(G.LOADING_PREVIOUS_MESSAGES,!0),await this.history.fetchPreviousMessages()}finally{this.emitter.emit(G.LOADING_PREVIOUS_MESSAGES,!1)}}async retrySendMessage(n){this.sendMessage(n.message,n.id)}async retryBroadcastUserMessage(n){this.broadcastUserMessage(n)}async init(){try{this.emitter.emit(G.LOADING_INIT,!0);const[n,i]=await Promise.allSettled([this.initOwnIndex(),this.history.init()]);if(n.status==="rejected")throw n.reason;i.status==="fulfilled"&&(this.gsocIndex=i.value),this.emitter.emit(G.LOADING_INIT,!1)}catch(n){this.errorHandler.handleError(n,"Chat.initSelfState"),this.emitter.emit(G.CRITICAL_ERROR,n)}}async initOwnIndex(){const{latestIndex:c}=await this.utils.retryAwaitableAsync(()=>this.utils.getOwnLatestFeedIndex(),10,1e3);this.userDetails.ownIndex=c}async fetchLatestMessage(){try{if(!this.gsocIndex)return;const n=T.Topic.fromString(this.swarmSettings.chatTopic),i=$n(n,this.gsocIndex),c=await this.utils.rawSocDownload(this.swarmSettings.chatAddress,i.toString()),u=JSON.parse(c);if(this.logger.debug("fetchLatestMessage entry CALLED",c),!$a(u)){this.logger.warn("Invalid GSOC message during fetching");return}this.emitter.emit(G.MESSAGE_RECEIVED,u),this.gsocIndex=this.gsocIndex.next()}catch(n){if(this.utils.isNotFoundError(n)||n.message.includes("Failed to fetch"))return;this.errorHandler.handleError(n,"Chat.fetchLatestMessage")}}async broadcastUserMessage(n){try{return this.logger.debug("broadcastUserMessage entry CALLED"),console.log("DEBUG broadcastUserMessage",n),this.utils.retryAwaitableAsync(()=>this.utils.sendMessageToGsoc(JSON.stringify(n)))}catch(i){this.errorHandler.handleError(i,"Chat.broadcastUserMessage")}}getSignature(){const{ownAddress:n,privateKey:i,nickname:c}=this.userDetails,u=new T.EthAddress(n).toString(),d=new T.PrivateKey(i);if(d.publicKey().address().toString()!==u)throw new Error("The provided address does not match the address derived from the private key");const p=Date.now();return d.sign(JSON.stringify({username:c,address:u,timestamp:p})).toHex()}async startMessagesFetchProcess(){if(this.fetchProcessRunning)return;this.fetchProcessRunning=!0,this.stopFetch=!1;const n=async()=>{if(this.stopFetch){this.fetchProcessRunning=!1;return}await this.fetchLatestMessage(),setTimeout(n,200)};n()}stopMessagesFetchProcess(){this.stopFetch=!0}}ce.EVENTS=G,ce.SwarmChat=Da,Object.defineProperty(ce,Symbol.toStringTag,{value:"Module"})});