@powerhousedao/desktop 6.2.3-dev.88 → 6.2.3-dev.90

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.
@@ -0,0 +1,325 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,o)=>(o=n==null?{}:e(i(n)),l(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));const d=`eip155`,f={EIP712Domain:[{name:`version`,type:`string`},{name:`chainId`,type:`uint256`}],VerifiableCredential:[{name:`@context`,type:`string[]`},{name:`type`,type:`string[]`},{name:`id`,type:`string`},{name:`issuer`,type:`Issuer`},{name:`credentialSubject`,type:`CredentialSubject`},{name:`credentialSchema`,type:`CredentialSchema`},{name:`issuanceDate`,type:`string`},{name:`expirationDate`,type:`string`}],CredentialSchema:[{name:`id`,type:`string`},{name:`type`,type:`string`}],CredentialSubject:[{name:`app`,type:`string`},{name:`id`,type:`string`}],Issuer:[{name:`id`,type:`string`},{name:`ethereumAddress`,type:`string`}]};var p=/* @__PURE__ */ u((/* @__PURE__ */ s(((e,t)=>{let{hasOwnProperty:n}=Object.prototype,r=_();r.configure=_,r.stringify=r,r.default=r,e.stringify=r,e.configure=_,t.exports=r;let i=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;function a(e){return e.length<5e3&&!i.test(e)?`"${e}"`:JSON.stringify(e)}function o(e,t){if(e.length>200||t)return e.sort(t);for(let t=1;t<e.length;t++){let n=e[t],r=t;for(;r!==0&&e[r-1]>n;)e[r]=e[r-1],r--;e[r]=n}return e}let s=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(/* @__PURE__ */ new Int8Array)),Symbol.toStringTag).get;function c(e){return s.call(e)!==void 0&&e.length!==0}function l(e,t,n){e.length<n&&(n=e.length);let r=t===`,`?``:` `,i=`"0":${r}${e[0]}`;for(let a=1;a<n;a++)i+=`${t}"${a}":${r}${e[a]}`;return i}function u(e){if(n.call(e,`circularValue`)){let t=e.circularValue;if(typeof t==`string`)return`"${t}"`;if(t==null)return t;if(t===Error||t===TypeError)return{toString(){throw TypeError(`Converting circular structure to JSON`)}};throw TypeError(`The "circularValue" argument must be of type string or the value null or undefined`)}return`"[Circular]"`}function d(e){let t;if(n.call(e,`deterministic`)&&(t=e.deterministic,typeof t!=`boolean`&&typeof t!=`function`))throw TypeError(`The "deterministic" argument must be of type boolean or comparator function`);return t===void 0||t}function f(e,t){let r;if(n.call(e,t)&&(r=e[t],typeof r!=`boolean`))throw TypeError(`The "${t}" argument must be of type boolean`);return r===void 0||r}function p(e,t){let r;if(n.call(e,t)){if(r=e[t],typeof r!=`number`)throw TypeError(`The "${t}" argument must be of type number`);if(!Number.isInteger(r))throw TypeError(`The "${t}" argument must be an integer`);if(r<1)throw RangeError(`The "${t}" argument must be >= 1`)}return r===void 0?1/0:r}function m(e){return e===1?`1 item`:`${e} items`}function h(e){let t=/* @__PURE__ */ new Set;for(let n of e)(typeof n==`string`||typeof n==`number`)&&t.add(String(n));return t}function g(e){if(n.call(e,`strict`)){let t=e.strict;if(typeof t!=`boolean`)throw TypeError(`The "strict" argument must be of type boolean`);if(t)return e=>{let t=`Object can not safely be stringified. Received type ${typeof e}`;throw typeof e!=`function`&&(t+=` (${e.toString()})`),Error(t)}}}function _(e){e={...e};let t=g(e);t&&(e.bigint===void 0&&(e.bigint=!1),`circularValue`in e||(e.circularValue=Error));let n=u(e),r=f(e,`bigint`),i=d(e),s=typeof i==`function`?i:void 0,_=p(e,`maximumDepth`),v=p(e,`maximumBreadth`);function y(e,l,u,d,f,p){let h=l[e];switch(typeof h==`object`&&h&&typeof h.toJSON==`function`&&(h=h.toJSON(e)),h=d.call(l,e,h),typeof h){case`string`:return a(h);case`object`:{if(h===null)return`null`;if(u.indexOf(h)!==-1)return n;let e=``,t=`,`,r=p;if(Array.isArray(h)){if(h.length===0)return`[]`;if(_<u.length+1)return`"[Array]"`;u.push(h),f!==``&&(p+=f,e+=`\n${p}`,t=`,\n${p}`);let n=Math.min(h.length,v),i=0;for(;i<n-1;i++){let n=y(String(i),h,u,d,f,p);e+=n===void 0?`null`:n,e+=t}let a=y(String(i),h,u,d,f,p);if(e+=a===void 0?`null`:a,h.length-1>v){let n=h.length-v-1;e+=`${t}"... ${m(n)} not stringified"`}return f!==``&&(e+=`\n${r}`),u.pop(),`[${e}]`}let l=Object.keys(h),g=l.length;if(g===0)return`{}`;if(_<u.length+1)return`"[Object]"`;let b=``,x=``;f!==``&&(p+=f,t=`,\n${p}`,b=` `);let S=Math.min(g,v);i&&!c(h)&&(l=o(l,s)),u.push(h);for(let n=0;n<S;n++){let r=l[n],i=y(r,h,u,d,f,p);i!==void 0&&(e+=`${x}${a(r)}:${b}${i}`,x=t)}if(g>v){let n=g-v;e+=`${x}"...":${b}"${m(n)} not stringified"`,x=t}return f!==``&&x.length>1&&(e=`\n${p}${e}\n${r}`),u.pop(),`{${e}}`}case`number`:return isFinite(h)?String(h):t?t(h):`null`;case`boolean`:return h===!0?`true`:`false`;case`undefined`:return;case`bigint`:if(r)return String(h);default:return t?t(h):void 0}}function b(e,i,o,s,c,l){switch(typeof i==`object`&&i&&typeof i.toJSON==`function`&&(i=i.toJSON(e)),typeof i){case`string`:return a(i);case`object`:{if(i===null)return`null`;if(o.indexOf(i)!==-1)return n;let e=l,t=``,r=`,`;if(Array.isArray(i)){if(i.length===0)return`[]`;if(_<o.length+1)return`"[Array]"`;o.push(i),c!==``&&(l+=c,t+=`\n${l}`,r=`,\n${l}`);let n=Math.min(i.length,v),a=0;for(;a<n-1;a++){let e=b(String(a),i[a],o,s,c,l);t+=e===void 0?`null`:e,t+=r}let u=b(String(a),i[a],o,s,c,l);if(t+=u===void 0?`null`:u,i.length-1>v){let e=i.length-v-1;t+=`${r}"... ${m(e)} not stringified"`}return c!==``&&(t+=`\n${e}`),o.pop(),`[${t}]`}o.push(i);let u=``;c!==``&&(l+=c,r=`,\n${l}`,u=` `);let d=``;for(let e of s){let n=b(e,i[e],o,s,c,l);n!==void 0&&(t+=`${d}${a(e)}:${u}${n}`,d=r)}return c!==``&&d.length>1&&(t=`\n${l}${t}\n${e}`),o.pop(),`{${t}}`}case`number`:return isFinite(i)?String(i):t?t(i):`null`;case`boolean`:return i===!0?`true`:`false`;case`undefined`:return;case`bigint`:if(r)return String(i);default:return t?t(i):void 0}}function x(e,u,d,f,p){switch(typeof u){case`string`:return a(u);case`object`:{if(u===null)return`null`;if(typeof u.toJSON==`function`){if(u=u.toJSON(e),typeof u!=`object`)return x(e,u,d,f,p);if(u===null)return`null`}if(d.indexOf(u)!==-1)return n;let t=p;if(Array.isArray(u)){if(u.length===0)return`[]`;if(_<d.length+1)return`"[Array]"`;d.push(u),p+=f;let e=`\n${p}`,n=`,\n${p}`,r=Math.min(u.length,v),i=0;for(;i<r-1;i++){let t=x(String(i),u[i],d,f,p);e+=t===void 0?`null`:t,e+=n}let a=x(String(i),u[i],d,f,p);if(e+=a===void 0?`null`:a,u.length-1>v){let t=u.length-v-1;e+=`${n}"... ${m(t)} not stringified"`}return e+=`\n${t}`,d.pop(),`[${e}]`}let r=Object.keys(u),h=r.length;if(h===0)return`{}`;if(_<d.length+1)return`"[Object]"`;p+=f;let g=`,\n${p}`,y=``,b=``,S=Math.min(h,v);c(u)&&(y+=l(u,g,v),r=r.slice(u.length),S-=u.length,b=g),i&&(r=o(r,s)),d.push(u);for(let e=0;e<S;e++){let t=r[e],n=x(t,u[t],d,f,p);n!==void 0&&(y+=`${b}${a(t)}: ${n}`,b=g)}if(h>v){let e=h-v;y+=`${b}"...": "${m(e)} not stringified"`,b=g}return b!==``&&(y=`\n${p}${y}\n${t}`),d.pop(),`{${y}}`}case`number`:return isFinite(u)?String(u):t?t(u):`null`;case`boolean`:return u===!0?`true`:`false`;case`undefined`:return;case`bigint`:if(r)return String(u);default:return t?t(u):void 0}}function S(e,u,d){switch(typeof u){case`string`:return a(u);case`object`:{if(u===null)return`null`;if(typeof u.toJSON==`function`){if(u=u.toJSON(e),typeof u!=`object`)return S(e,u,d);if(u===null)return`null`}if(d.indexOf(u)!==-1)return n;let t=``,r=u.length!==void 0;if(r&&Array.isArray(u)){if(u.length===0)return`[]`;if(_<d.length+1)return`"[Array]"`;d.push(u);let e=Math.min(u.length,v),n=0;for(;n<e-1;n++){let e=S(String(n),u[n],d);t+=e===void 0?`null`:e,t+=`,`}let r=S(String(n),u[n],d);if(t+=r===void 0?`null`:r,u.length-1>v){let e=u.length-v-1;t+=`,"... ${m(e)} not stringified"`}return d.pop(),`[${t}]`}let f=Object.keys(u),p=f.length;if(p===0)return`{}`;if(_<d.length+1)return`"[Object]"`;let h=``,g=Math.min(p,v);r&&c(u)&&(t+=l(u,`,`,v),f=f.slice(u.length),g-=u.length,h=`,`),i&&(f=o(f,s)),d.push(u);for(let e=0;e<g;e++){let n=f[e],r=S(n,u[n],d);r!==void 0&&(t+=`${h}${a(n)}:${r}`,h=`,`)}if(p>v){let e=p-v;t+=`${h}"...":"${m(e)} not stringified"`}return d.pop(),`{${t}}`}case`number`:return isFinite(u)?String(u):t?t(u):`null`;case`boolean`:return u===!0?`true`:`false`;case`undefined`:return;case`bigint`:if(r)return String(u);default:return t?t(u):void 0}}function C(e,t,n){if(arguments.length>1){let r=``;if(typeof n==`number`?r=` `.repeat(Math.min(n,10)):typeof n==`string`&&(r=n.slice(0,10)),t!=null){if(typeof t==`function`)return y(``,{"":e},[],t,r,``);if(Array.isArray(t))return b(``,e,[],h(t),r,``)}if(r.length!==0)return x(``,e,[],r,``)}return S(``,e,[])}return C}})))());p.configure;const m=p.default,h=[1518500249,1859775393,-1894007588,-899497514],g={sha1:1};function _(e){if(e&&!g[e]&&!g[e.toLowerCase()])throw Error(`Digest method not supported`);return new v}var v=class{constructor(){this.A=1732584193,this.B=-271733879,this.C=-1732584194,this.D=271733878,this.E=-1009589776,this._size=0,this._sp=0,(!b||x>=8e3)&&(b=/* @__PURE__ */ new ArrayBuffer(8e3),x=0),this._byte=new Uint8Array(b,x,80),this._word=new Int32Array(b,x,20),x+=80}update(e){if(typeof e==`string`)return this._utf8(e);if(e==null)throw TypeError(`Invalid type: `+typeof e);let t=e.byteOffset,n=e.byteLength,r=n/64|0,i=0;if(r&&!(t&3)&&!(this._size%64)){let n=new Int32Array(e.buffer,t,r*16);for(;r--;)this._int32(n,i>>2),i+=64;this._size+=i}if(e.BYTES_PER_ELEMENT!==1&&e.buffer){let r=new Uint8Array(e.buffer,t+i,n-i);return this._uint8(r)}return i===n?this:this._uint8(e,i)}_uint8(e,t){let{_byte:n,_word:r}=this,i=e.length;for(t|=0;t<i;){let a=this._size%64,o=a;for(;t<i&&o<64;)n[o++]=e[t++];o>=64&&this._int32(r),this._size+=o-a}return this}_utf8(e){let{_byte:t,_word:n}=this,r=e.length,i=this._sp;for(let a=0;a<r;){let o=this._size%64,s=o;for(;a<r&&s<64;){let n=e.charCodeAt(a++)|0;n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<55296||n>57343?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):i?(n=((i&1023)<<10)+(n&1023)+65536,t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63,i=0):i=n}s>=64&&(this._int32(n),n[0]=n[16]),this._size+=s-o}return this._sp=i,this}_int32(e,t){let{A:n,B:r,C:i,D:a,E:o}=this,s=0;for(t|=0;s<16;)y[s++]=C(e[t++]);for(s=16;s<80;s++)y[s]=w(y[s-3]^y[s-8]^y[s-14]^y[s-16]);for(s=0;s<80;s++){let e=s/20|0,t=T(n)+te(e,r,i,a)+o+y[s]+h[e]|0;o=a,a=i,i=ee(r),r=n,n=t}this.A=n+this.A|0,this.B=r+this.B|0,this.C=i+this.C|0,this.D=a+this.D|0,this.E=o+this.E|0}digest(e){let{_byte:t,_word:n}=this,r=this._size%64|0;for(t[r++]=128;r&3;)t[r++]=0;if(r>>=2,r>14){for(;r<16;)n[r++]=0;r=0,this._int32(n)}for(;r<16;)n[r++]=0;let i=this._size*8,a=(i&4294967295)>>>0,o=(i-a)/4294967296;return o&&(n[14]=C(o)),a&&(n[15]=C(a)),this._int32(n),e===`hex`?this._hex():this._bin()}_hex(){let{A:e,B:t,C:n,D:r,E:i}=this;return S(e)+S(t)+S(n)+S(r)+S(i)}_bin(){let{A:e,B:t,C:n,D:r,E:i,_byte:a,_word:o}=this;return o[0]=C(e),o[1]=C(t),o[2]=C(n),o[3]=C(r),o[4]=C(i),a.slice(0,20)}};const y=/* @__PURE__ */ new Int32Array(80);let b,x=0;const S=e=>(e+4294967296).toString(16).substr(-8),C=ne()?(e=>e):(e=>e<<24&4278190080|e<<8&16711680|e>>8&65280|e>>24&255),w=e=>e<<1|e>>>31,T=e=>e<<5|e>>>27,ee=e=>e<<30|e>>>2;function te(e,t,n,r){return e===0?t&n|~t&r:e===2?t&n|t&r|n&r:t^n^r}function ne(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254}const re=(e,t=`sha1`,n=`base64`,r)=>{if(![`sha1`].includes(t))throw Error(`Hashing algorithm not supported: "${t}". Available: sha1`);if(![`base64`,`hex`].includes(n))throw Error(`Hash encoding not supported: "${n}". Available: base64, hex`);let i=oe(e,t);return n===`hex`?ae(i):ie(i)};function ie(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function ae(e){return Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``)}function oe(e,t=`sha1`){if(![`sha1`].includes(t))throw Error(`Hashing algorithm not supported: Available: sha1`);return _(`sha1`).update(e).digest()}const se=new TextEncoder;function ce(e){let t=e.join(``),n=`Signed Operation:
2
+ `+t.length.toString();return se.encode(n+t)}function le(e){let t=[];for(let n of e){let e=`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`.indexOf(n);if(e===-1)return null;for(let n=0;n<t.length;n++)e+=t[n]*58,t[n]=e&255,e>>=8;for(;e>0;)t.push(e&255),e>>=8}for(let n=0;n<e.length&&e[n]===`1`;n++)t.push(0);return Uint8Array.from(t.reverse())}function ue(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r;r=typeof atob==`function`?atob(n):Buffer.from(n,`base64`).toString(`binary`);let i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}function de(e,t,n,r){let i=`${e}:${t}:${n}:${r}`;return re(i,`sha1`,`hex`).slice(0,32)}const fe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function pe(e={}){let t=e.now??(()=>Date.now()),n=e.random??(e=>{globalThis.crypto.getRandomValues(e)}),r=/* @__PURE__ */ new Uint8Array(16),i=-1,a=0;return()=>{let e=t();n(r);let o=(r[6]&7)<<8|r[7];e>i?(i=e,a=o):a<4095?a++:(i++,a=o);let s=i;for(let e=5;e>=0;e--)r[e]=s%256,s=Math.floor(s/256);r[6]=112|a>>8,r[7]=a&255,r[8]=128|r[8]&63;let c=``;for(let e=0;e<16;e++)(e===4||e===6||e===8||e===10)&&(c+=`-`),c+=fe[r[e]];return c}}const me=pe();let he=0,ge=0;function _e(){let e=Date.now();return ge=e<he||e>ge?e:ge+1,he=e,new Date(ge).toISOString()}var ve,ye=o((()=>{ve=typeof globalThis==`object`&&`crypto`in globalThis?globalThis.crypto:void 0}));
3
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
4
+ function be(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function xe(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function Se(e,...t){if(!be(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function Ce(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash should be wrapped by utils.createHasher`);xe(e.outputLen),xe(e.blockLen)}function we(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function Te(e,t){Se(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function Ee(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function De(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Oe(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ke(e,t){return e<<32-t|e>>>t}function Ae(e,t){return e<<t|e>>>32-t>>>0}function je(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Me(e){for(let t=0;t<e.length;t++)e[t]=je(e[t]);return e}function Ne(e){if(Se(e),Ue)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=We[e[n]];return t}function Pe(e){if(e>=Ge._0&&e<=Ge._9)return e-Ge._0;if(e>=Ge.A&&e<=Ge.F)return e-(Ge.A-10);if(e>=Ge.a&&e<=Ge.f)return e-(Ge.a-10)}function Fe(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(Ue)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=Pe(e.charCodeAt(i)),a=Pe(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function Ie(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function Le(e){return typeof e==`string`&&(e=Ie(e)),Se(e),e}function Re(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];Se(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function ze(e){let t=t=>e().update(Le(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Be(e=32){if(ve&&typeof ve.getRandomValues==`function`)return ve.getRandomValues(new Uint8Array(e));if(ve&&typeof ve.randomBytes==`function`)return Uint8Array.from(ve.randomBytes(e));throw Error(`crypto.getRandomValues must be defined`)}var Ve,He,Ue,We,Ge,Ke,qe=o((()=>{ye(),Ve=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,He=Ve?e=>e:Me,Ue=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,We=/* @__PURE__ */ Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),Ge={_0:48,_9:57,A:65,F:70,a:97,f:102},Ke=class{}}));function Je(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function Ye(e,t,n){return e&t^~e&n}function Xe(e,t,n){return e&t^e&n^t&n}var Ze,Qe,E,D,$e=o((()=>{qe(),Ze=class extends Ke{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Oe(this.buffer)}update(e){we(this),e=Le(e),Se(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=Oe(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){we(this),Te(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,De(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;Je(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=Oe(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Qe=/* @__PURE__ */ Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),E=/* @__PURE__ */ Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),D=/* @__PURE__ */ Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209])}));function et(e,t=!1){return t?{h:Number(e&rt),l:Number(e>>it&rt)}:{h:Number(e>>it&rt)|0,l:Number(e&rt)|0}}function tt(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=et(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}function nt(e,t,n,r){let i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}var rt,it,at,ot,st,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt=o((()=>{rt=/* @__PURE__ */ BigInt(2**32-1),it=/* @__PURE__ */ BigInt(32),at=(e,t,n)=>e>>>n,ot=(e,t,n)=>e<<32-n|t>>>n,st=(e,t,n)=>e>>>n|t<<32-n,ct=(e,t,n)=>e<<32-n|t>>>n,lt=(e,t,n)=>e<<64-n|t>>>n-32,ut=(e,t,n)=>e>>>n-32|t<<64-n,dt=(e,t,n)=>e<<n|t>>>32-n,ft=(e,t,n)=>t<<n|e>>>32-n,pt=(e,t,n)=>t<<n-32|e>>>64-n,mt=(e,t,n)=>e<<n-32|t>>>64-n,ht=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),gt=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,_t=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),vt=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,yt=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),bt=(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0})),St,Ct,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft=o((()=>{$e(),xt(),qe(),St=/* @__PURE__ */ Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ct=/* @__PURE__ */ new Uint32Array(64),wt=class extends Ze{constructor(e=32){super(64,e,8,!1),this.A=Qe[0]|0,this.B=Qe[1]|0,this.C=Qe[2]|0,this.D=Qe[3]|0,this.E=Qe[4]|0,this.F=Qe[5]|0,this.G=Qe[6]|0,this.H=Qe[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)Ct[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Ct[e-15],n=Ct[e-2],r=ke(t,7)^ke(t,18)^t>>>3,i=ke(n,17)^ke(n,19)^n>>>10;Ct[e]=i+Ct[e-7]+r+Ct[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=ke(o,6)^ke(o,11)^ke(o,25),u=l+t+Ye(o,s,c)+St[e]+Ct[e]|0,d=(ke(n,2)^ke(n,13)^ke(n,22))+Xe(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){De(Ct)}destroy(){this.set(0,0,0,0,0,0,0,0),De(this.buffer)}},Tt=/* @__PURE__ */ tt((/* @__PURE__ */ `0x428a2f98d728ae22.0x7137449123ef65cd.0xb5c0fbcfec4d3b2f.0xe9b5dba58189dbbc.0x3956c25bf348b538.0x59f111f1b605d019.0x923f82a4af194f9b.0xab1c5ed5da6d8118.0xd807aa98a3030242.0x12835b0145706fbe.0x243185be4ee4b28c.0x550c7dc3d5ffb4e2.0x72be5d74f27b896f.0x80deb1fe3b1696b1.0x9bdc06a725c71235.0xc19bf174cf692694.0xe49b69c19ef14ad2.0xefbe4786384f25e3.0x0fc19dc68b8cd5b5.0x240ca1cc77ac9c65.0x2de92c6f592b0275.0x4a7484aa6ea6e483.0x5cb0a9dcbd41fbd4.0x76f988da831153b5.0x983e5152ee66dfab.0xa831c66d2db43210.0xb00327c898fb213f.0xbf597fc7beef0ee4.0xc6e00bf33da88fc2.0xd5a79147930aa725.0x06ca6351e003826f.0x142929670a0e6e70.0x27b70a8546d22ffc.0x2e1b21385c26c926.0x4d2c6dfc5ac42aed.0x53380d139d95b3df.0x650a73548baf63de.0x766a0abb3c77b2a8.0x81c2c92e47edaee6.0x92722c851482353b.0xa2bfe8a14cf10364.0xa81a664bbc423001.0xc24b8b70d0f89791.0xc76c51a30654be30.0xd192e819d6ef5218.0xd69906245565a910.0xf40e35855771202a.0x106aa07032bbd1b8.0x19a4c116b8d2d0c8.0x1e376c085141ab53.0x2748774cdf8eeb99.0x34b0bcb5e19b48a8.0x391c0cb3c5c95a63.0x4ed8aa4ae3418acb.0x5b9cca4f7763e373.0x682e6ff3d6b2b8a3.0x748f82ee5defb2fc.0x78a5636f43172f60.0x84c87814a1f0ab72.0x8cc702081a6439ec.0x90befffa23631e28.0xa4506cebde82bde9.0xbef9a3f7b2c67915.0xc67178f2e372532b.0xca273eceea26619c.0xd186b8c721c0c207.0xeada7dd6cde0eb1e.0xf57d4f7fee6ed178.0x06f067aa72176fba.0x0a637dc5a2c898a6.0x113f9804bef90dae.0x1b710b35131c471b.0x28db77f523047d84.0x32caab7b40c72493.0x3c9ebe0a15c9bebc.0x431d67c49c100d4c.0x4cc5d4becb3e42b6.0x597f299cfc657e2a.0x5fcb6fab3ad6faec.0x6c44198c4a475817`.split(`.`)).map(e=>BigInt(e))),Et=Tt[0],Dt=Tt[1],Ot=/* @__PURE__ */ new Uint32Array(80),kt=/* @__PURE__ */ new Uint32Array(80),At=class extends Ze{constructor(e=64){super(128,e,16,!1),this.Ah=D[0]|0,this.Al=D[1]|0,this.Bh=D[2]|0,this.Bl=D[3]|0,this.Ch=D[4]|0,this.Cl=D[5]|0,this.Dh=D[6]|0,this.Dl=D[7]|0,this.Eh=D[8]|0,this.El=D[9]|0,this.Fh=D[10]|0,this.Fl=D[11]|0,this.Gh=D[12]|0,this.Gl=D[13]|0,this.Hh=D[14]|0,this.Hl=D[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:a,Dh:o,Dl:s,Eh:c,El:l,Fh:u,Fl:d,Gh:f,Gl:p,Hh:m,Hl:h}=this;return[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=r|0,this.Ch=i|0,this.Cl=a|0,this.Dh=o|0,this.Dl=s|0,this.Eh=c|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=f|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}process(e,t){for(let n=0;n<16;n++,t+=4)Ot[n]=e.getUint32(t),kt[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=Ot[e-15]|0,n=kt[e-15]|0,r=st(t,n,1)^st(t,n,8)^at(t,n,7),i=ct(t,n,1)^ct(t,n,8)^ot(t,n,7),a=Ot[e-2]|0,o=kt[e-2]|0,s=st(a,o,19)^lt(a,o,61)^at(a,o,6),c=ct(a,o,19)^ut(a,o,61)^ot(a,o,6),l=_t(i,c,kt[e-7],kt[e-16]),u=vt(l,r,s,Ot[e-7],Ot[e-16]);Ot[e]=u|0,kt[e]=l|0}let{Ah:n,Al:r,Bh:i,Bl:a,Ch:o,Cl:s,Dh:c,Dl:l,Eh:u,El:d,Fh:f,Fl:p,Gh:m,Gl:h,Hh:g,Hl:_}=this;for(let e=0;e<80;e++){let t=st(u,d,14)^st(u,d,18)^lt(u,d,41),v=ct(u,d,14)^ct(u,d,18)^ut(u,d,41),y=u&f^~u&m,b=d&p^~d&h,x=yt(_,v,b,Dt[e],kt[e]),S=bt(x,g,t,y,Et[e],Ot[e]),C=x|0,w=st(n,r,28)^lt(n,r,34)^lt(n,r,39),T=ct(n,r,28)^ut(n,r,34)^ut(n,r,39),ee=n&i^n&o^i&o,te=r&a^r&s^a&s;g=m|0,_=h|0,m=f|0,h=p|0,f=u|0,p=d|0,{h:u,l:d}=nt(c|0,l|0,S|0,C|0),c=o|0,l=s|0,o=i|0,s=a|0,i=n|0,a=r|0;let ne=ht(C,T,te);n=gt(ne,S,w,ee),r=ne|0}({h:n,l:r}=nt(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=nt(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=nt(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=nt(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=nt(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=nt(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=nt(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=nt(this.Hh|0,this.Hl|0,g|0,_|0),this.set(n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_)}roundClean(){De(Ot,kt)}destroy(){De(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},jt=class extends At{constructor(){super(48),this.Ah=E[0]|0,this.Al=E[1]|0,this.Bh=E[2]|0,this.Bl=E[3]|0,this.Ch=E[4]|0,this.Cl=E[5]|0,this.Dh=E[6]|0,this.Dl=E[7]|0,this.Eh=E[8]|0,this.El=E[9]|0,this.Fh=E[10]|0,this.Fl=E[11]|0,this.Gh=E[12]|0,this.Gl=E[13]|0,this.Hh=E[14]|0,this.Hl=E[15]|0}},Mt=/* @__PURE__ */ ze(()=>new wt),Nt=/* @__PURE__ */ ze(()=>new At),Pt=/* @__PURE__ */ ze(()=>new jt)}));const It=/\p{Cs}/u,Lt=[`version`,`documentId`,`branch`,`scope`,`type`,`id`,`timestampUtcMs`,`input`,`signer.user.address`,`signer.user.networkId`,`signer.user.chainId`,`signer.app.key`];var Rt=class extends Error{constructor(e,t){super(`Cannot canonicalize ${e}: ${t}`),this.name=`CanonicalJsonError`}};function zt(e){return{user:{address:e.user?.address??``,networkId:e.user?.networkId??``,chainId:e.user?.chainId??0},app:{name:e.app?.name??``,key:e.app?.key??``}}}function Bt(e,t,n){if(!t.documentId)throw new Rt(`documentId`,`must not be empty`);if(!t.branch)throw new Rt(`branch`,`must not be empty`);if(e.input===void 0)throw new Rt(`input`,`action ${e.id} (${e.type}) has no input`);let r=[`v2`,t.documentId,t.branch,e.scope,e.type,e.id,e.timestampUtcMs,e.input,n.user.address,n.user.networkId,n.user.chainId,n.app.key];return r.forEach((e,t)=>{Ut(e,Lt[t],/* @__PURE__ */ new Set)}),m(r)}async function Vt(e,t,n){let r=Bt(e,t,n),i=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(r));return`v2:`+Wt(new Uint8Array(i))}async function Ht(e){let{action:t,target:n,signer:r,sign:i}=e,a=e.previousStateHash??``;if(a.includes(`, `))throw Error(`Cannot sign action ${t.id}: the previous state hash contains ", "`);let o=[(Date.now()/1e3).toFixed(0),r.app.key,await Vt(t,n,r),a],s=await i(ce(o));if(s.length!==64)throw Error(`Cannot sign action ${t.id}: expected a 64-byte P-256 signature, got ${s.length} bytes`);return[...o,`0x${Gt(s)}`]}function Ut(e,t,n){switch(typeof e){case`string`:if(It.test(e))throw new Rt(t,`string holds a lone surrogate`);return;case`boolean`:return;case`number`:if(!Number.isFinite(e))throw new Rt(t,`${e} is not a JSON number`);return;case`undefined`:throw new Rt(t,`undefined is not a JSON value`);case`bigint`:throw new Rt(t,`BigInt is not a JSON value`);case`function`:case`symbol`:throw new Rt(t,`${typeof e} is not a JSON value`)}if(e===null)return;let r=e;if(n.has(r))throw new Rt(t,`value is circular`);let i=r.toJSON;if(typeof i==`function`){Ut(i.call(r),t,new Set(n).add(r));return}if(n.add(r),Array.isArray(r))for(let e=0;e<r.length;e++){if(!(e in r))throw new Rt(`${t}[${e}]`,`array is sparse`);Ut(r[e],`${t}[${e}]`,n)}else for(let[e,i]of Object.entries(r)){if(It.test(e))throw new Rt(t,`key holds a lone surrogate`);i!==void 0&&Ut(i,`${t}.${e}`,n)}n.delete(r)}function Wt(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Gt(e){return Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``)}const Kt=Symbol.for(`powerhouse.stateReducer`);function qt(e,t){return Object.assign(e,{[Kt]:t})}function Jt(e){return e[Kt]}const Yt=[1,2,3],Xt={1:{version:1,undo:`skip`,derivation:`replay`,skip:`undo-or-rewind`,tieOrder:`rank-locale`,synthesizedId:`hashed`,replayHash:`sender`,reducerContract:`any`,gatedBy:null},2:{version:2,undo:`noop-chain`,derivation:`replay`,skip:`undo-or-rewind`,tieOrder:`rank-locale`,synthesizedId:`hashed`,replayHash:`sender`,reducerContract:`any`,gatedBy:null},3:{version:3,undo:`retraction`,derivation:`retraction-rule`,skip:`rewind`,tieOrder:`canonical`,synthesizedId:`none`,replayHash:`receiver`,reducerContract:`state-reducer`,gatedBy:`undoV3`}};function Zt(e){return Yt.filter(t=>{let n=Xt[t].gatedBy;return n===null||e[n]===!0})}Object.fromEntries(Yt.flatMap(e=>{let t=Xt[e].gatedBy;return t===null?[]:[[t,!0]]}));const Qt=/* @__PURE__ */ new Set([`auth`,`document`]);function $t(e,t){throw Error(`Unhandled ${t}: ${String(e)}`)}function en(e){return Yt.includes(e)}function tn(e){return Xt[e]}function nn(e){let t=e.protocolVersions?.[`base-reducer`];if(typeof t!=`number`)throw Error(`Document ${e.id} carries no base-reducer protocol version`);if(!en(t))throw Error(`Document ${e.id} carries unknown base-reducer protocol version ${t}`);return t}function rn(e){return tn(nn(e))}function an(e){if(e.protocolVersions?.[`base-reducer`]!==void 0)return rn(e)}const on={usesRetractionRule:{replay:!1,"retraction-rule":!0},needsTaggedModel:{any:!1,"state-reducer":!0},sortsJobsCanonically:{"rank-locale":!1,canonical:!0},conflictWindowMovesEveryRow:{"rank-locale":!1,canonical:!0},skipMayUndo:{"undo-or-rewind":!0,rewind:!1}},sn=Xt[1];function cn(e){return on.usesRetractionRule[(e??sn).derivation]}function ln(e,t){return cn(e)&&!Qt.has(t)}function un(e,t){return!ln(e,t)}[{kind:`protocol`,name:`base-reducer`,baseline:[1,2],supported:Zt,preferred:e=>Math.max(...Zt(e)),selection:e=>en(e)&&tn(e).gatedBy!==null?`creator`:`agreed`,optional:!1},{kind:`protocol`,name:`signature`,baseline:[2],supported:()=>[2],optional:!0},{kind:`protocol`,name:`document-purge`,baseline:[],supported:()=>[1],optional:!0},{kind:`feature`,name:`marker-refusal`,baseline:[],supported:()=>[1]}].find(e=>e.kind===`protocol`&&e.name===`base-reducer`).preferred({});var dn=class extends Error{data;constructor(e){super(),this.name=`InvalidActionInputError`,this.data=e,this.message=this.message||`Invalid action input: ${JSON.stringify(e,null,2)}`}},fn=class extends dn{issues;constructor(e){super(e),this.issues=e,this.name=`InvalidActionInputZodError`}},pn=class extends Error{documentType;version;constructor(e,t){let n=t===void 0?e:`${e} v${t}`;super(`Cannot replay ${n} on base-reducer 3: its reducer was not built by createReducer`),this.name=`MissingStateReducerError`,this.documentType=e,this.version=t}static isError(e){return e instanceof Error&&e.name===`MissingStateReducerError`}},mn=class extends Error{documentId;actionType;constructor(e,t){super(`${t} cannot be submitted to document ${e}: its base reducer undoes by RETRACT of a target, which IReactorClient.undo and redo resolve and sign`),this.name=`SubmittedUndoRefusedError`,this.documentId=e,this.actionType=t}static isError(e){return e instanceof Error&&e.name===`SubmittedUndoRefusedError`}},hn=class extends Error{documentId;constructor(e){super(`Auth scope already initialized for document ${e}: INITIALIZE_AUTH is valid only at auth revision zero`),this.name=`AuthAlreadyInitializedError`,this.documentId=e}},gn=class extends Error{documentId;constructor(e){super(`INITIALIZE_AUTH for document ${e} must be signed by the document creator`),this.name=`AuthInitializerNotCreatorError`,this.documentId=e}},_n=class extends Error{documentId;version;constructor(e,t){super(`Invalid auth policy version ${t} for document ${e}: INITIALIZE_AUTH requires an integer version >= 1`),this.name=`InvalidAuthVersionError`,this.documentId=e,this.version=t}},vn=class extends Error{grantId;constructor(e){super(`Grant not found in auth scope: ${e}`),this.name=`GrantNotFoundError`,this.grantId=e}},yn=class extends Error{actionType;constructor(e){super(`${e} is not permitted on the auth scope`),this.name=`AuthActionNotAllowedError`,this.actionType=e}},bn=class extends Error{_scope;_document;_operation;constructor(e,t,n){super(),this.name=`HashMismatchError`,this._document=t,this._scope=e,this._operation=n,this.message=JSON.stringify({error:`Hash mismatch on document ${t.header.id}, scope ${e}, index ${n.index}`,document:t,operation:n},null,1)}get document(){return this._document}get scope(){return this._scope}get operation(){return this._operation}};function xn(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Sn(e,t=`|`){return e.map(e=>qn(e)).join(t)}function Cn(e,t){return typeof t==`bigint`?t.toString():t}var wn=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function Tn(e){return new wn(e)}function En(e){return e==null}function Dn(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function On(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function kn(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function An(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function jn(e){return An(e._zod.def)??e._zod.def.shape}function Mn(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return kn(this,t,e),e},enumerable:!0,configurable:!0})}function Nn(e,t,n){t in e?kn(e,t,n):e[t]=n}function Pn(e,t,n,r){let i=jn(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?Mn(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):Nn(e,a,r?r(n.value,a):n.value))}}function Fn(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?Mn(e,n,()=>t[n]):Nn(e,n,r.value))}}function In(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ln(e){return JSON.stringify(e)}function Rn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const zn=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Bn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Vn=/* @__PURE__*/ Tn(()=>{if(Pr.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Hn(e){if(Bn(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return Bn(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function Un(e){return Hn(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Wn=/* @__PURE__*/ new Set([`string`,`number`,`symbol`]);function Gn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Kn(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function O(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function qn(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function Jn(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}const Yn={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},Xn={int64:[/* @__PURE__*/ BigInt(`-9223372036854775808`),/* @__PURE__*/ BigInt(`9223372036854775807`)],uint64:[/* @__PURE__*/ BigInt(0),/* @__PURE__*/ BigInt(`18446744073709551615`)]};function Zn(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return Pn(i,e,Qn(e,t)),Kn(e,In(n,{shape:i,checks:[]}))}function Qn(e,t){let n=jn(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function $n(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(Qn(e,t)),a={};return Pn(a,e,Reflect.ownKeys(jn(e)).filter(e=>!i.has(e))),Kn(e,In(n,{shape:a,checks:[]}))}function er(e,t){if(!Hn(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=jn(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Kn(e,In(e._zod.def,{shape:tr(e,t)}))}function tr(e,t){let n={};return Pn(n,e,Reflect.ownKeys(jn(e))),Fn(n,t),n}function nr(e,t){if(!Hn(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Kn(e,In(e._zod.def,{shape:tr(e,t)}))}function rr(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return Pn(n,e,Reflect.ownKeys(jn(e))),Pn(n,t,Reflect.ownKeys(jn(t))),Kn(e,In(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function ir(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(Qn(t,n)):void 0,o={};return Pn(o,t,Reflect.ownKeys(jn(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),Kn(t,In(t._zod.def,{shape:o,checks:[]}))}function ar(e,t,n){let r=n?new Set(Qn(t,n)):void 0,i={};return Pn(i,t,Reflect.ownKeys(jn(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),Kn(t,In(t._zod.def,{shape:i}))}function or(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function sr(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function cr(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function lr(e){return typeof e==`string`?e:e?.message}function ur(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function dr(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:lr(e.inst?._zod.def?.error?.(e))??lr(a?.(e))??lr(t?.error?.(e))??lr(n.customError?.(e))??lr(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}const fr=/[\uD800-\uDBFF]/;function pr(e){let t=e.length;if(!fr.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function mr(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function hr(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function gr(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function _r(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):xr(e,n,r.value)}}function vr(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function yr(e,t,n){return vr(e,t,n,!1)}function br(e,t){for(let n in e){let r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return vr(this,n,r(this))},set(e){vr(this,n,e)}})}return t}function xr(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:vr(this,t,n.bind(this))},set(e){vr(this,t,e)}})}function Sr(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let Cr,wr=!1;const Tr={configurable:!0,get(){wr=!0}};function k(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&Cr!==e._zod){Cr=void 0;return}Cr=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,Tr);let e=wr;wr=!1;try{let r=n(this);return wr?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),wr||=e,r}catch(n){throw delete this[t],wr||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function Er(e,t,n,r){let i=Sr(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}function Dr(e){let t=()=>e;return t[`~constantCatch`]=!0,t}var Or;const kr={value:void 0,enumerable:!1};let Ar=`captureStackTrace`in Error?Error:null;function jr(e){let t=Ar;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Ar=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function A(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=/* @__PURE__ */ new Set}a.prototype=i;let o=n,s=o&&/* @__PURE__ */ new WeakSet;function c(n,r){if(!n._zod){kr.value=new a(r);try{Object.defineProperty(n,"_zod",kr)}finally{kr.value=void 0}}else if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),_r(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?jr(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var Mr=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Nr=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Or=globalThis).__zod_globalConfig??(Or.__zod_globalConfig={});const Pr=globalThis.__zod_globalConfig;function Fr(e){return e&&Object.assign(Pr,e),Pr}function Ir(){let e=this._zod;return e.message??=JSON.stringify(e.def,Cn,2),e.message}function Lr(e){this._zod.message=e}const Rr={get:Ir,set:Lr,enumerable:!0,configurable:!0},zr={value:void 0,enumerable:!1},Br=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]),Vr=(e,t)=>{e.name=`$ZodError`,zr.value=t,Object.defineProperty(e,"issues",zr),zr.value=void 0,Object.defineProperty(e,"message",Rr);let n=Object.getPrototypeOf(e);Br.has(n)||(Br.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},Hr=A(`$ZodError`,Vr);A(`$ZodError`,Vr,void 0,{Parent:Error});function Ur(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t===`__proto__`?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function Wr(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?Ur(n,i.path[0],()=>[]).push(t(i)):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Gr(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i],o=i===e.length-1;if(n===`_errors`){o&&r._errors.push(t(a)),i++;continue}Object.prototype.hasOwnProperty.call(r,n)||Object.defineProperty(r,n,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let s=r[n];o&&s._errors.push(t(a)),r=s,i++}}}};return r(e),n}function Kr(e,t){return{callee:t?.callee??e,Err:t?.Err}}const qr=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Mr;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>dr(e,o,Fr())));throw zn(n,a?.callee??t),n}return s.value};return t},Jr=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>dr(e,o,Fr())));throw zn(n,a?.callee??t),n}return s.value};return t},Yr=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Mr;return a.issues.length?Xr(e,a.issues,i):{success:!0,data:a.value}};function Xr(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>dr(e,n,Fr()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}const Zr=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?Xr(e,a.issues,i):{success:!0,data:a.value}},Qr=/* @__PURE__ */ Symbol.for(`zod.compile.invalid`),$r=/* @__PURE__ */ Symbol.for(`zod.compile.fallback`),ei=((e,t,n)=>{let r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==Qr)return!0;if(r.definite===!0&&n===void 0)return!1}return ti(e,t,n)});function ti(e,t,n){let r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},i=e._zod.bag.fallbackRun,a;if(i?(r[$r]=!0,a=i({value:t,issues:[]},r)):a=e._zod.run({value:t,issues:[]},r),a instanceof Promise)throw new Mr;return a.issues.length===0}const ni=async(e,t,n)=>{let r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},i=e._zod.run({value:t,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length===0},ri=e=>{let t=qr(e),n=(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return t(e,r,o,Kr(n,a))};return n},ii=e=>{let t=qr(e),n=(e,r,i,a)=>t(e,r,i,Kr(n,a));return n},ai=e=>{let t=Jr(e),n=async(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return await t(e,r,o,Kr(n,a))};return n},oi=e=>{let t=Jr(e),n=async(e,r,i,a)=>await t(e,r,i,Kr(n,a));return n},si=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Yr(e)(t,n,i)},ci=e=>(t,n,r)=>Yr(e)(t,n,r),li=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Zr(e)(t,n,i)},ui=e=>async(t,n,r)=>Zr(e)(t,n,r),di=/^[cC][0-9a-z]{6,}$/,fi=/^[0-9a-z]+$/,pi=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,mi=/^[0-9a-vA-V]{20}$/,hi=/^[A-Za-z0-9]{27}$/,gi=/^[a-zA-Z0-9_-]{21}$/;function _i(e){return RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}const vi=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,yi=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,bi=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,xi=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function Si(){return RegExp(`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,`u`)}const Ci=/^(?:(?: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])$/,wi=/^(([0-9a-fA-F]{1,4}:){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}|:))$/,Ti=/^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/,Ei=/^(([0-9a-fA-F]{1,4}:){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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Di=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Oi=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,ki=/^https?$/,Ai=/^\+[1-9]\d{6,14}$/,ji=`(?:(?:\\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])))`;function Mi(e){return RegExp(`^${e}$`)}const Ni=/*@__PURE__*/ Mi(ji);function Pi(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Fi(e){return RegExp(`^${Pi(e)}$`)}function Ii(e){let t=[`Z`];e.offset&&t.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let n=`${Pi({precision:e.precision,seconds:!0})}(?:${t.join(`|`)})`,r=e.local?`${n}|${Pi({precision:e.precision})}`:n;return RegExp(`^${ji}T(?:${r})$`)}const Li=/^[\s\S]{0,}$/,Ri=/^-?\d+$/,zi=/^-?\d+(?:\.\d+)?$/,Bi=/^(?:true|false)$/i,Vi=/^[^A-Z]*$/,Hi=/^[^a-z]*$/,Ui=/*@__PURE__*/ A(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Wi=e=>{let t=e.value;return!En(t)&&t.length!==void 0},Gi={number:`number`,bigint:`bigint`,object:`date`},Ki=/*@__PURE__*/ A(`$ZodCheckLessThan`,(e,t)=>{Ui.init(e,t);let n=Gi[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:Gi[typeof r.value]??n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),qi=/*@__PURE__*/ A(`$ZodCheckGreaterThan`,(e,t)=>{Ui.init(e,t);let n=Gi[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:Gi[typeof r.value]??n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ji=/*@__PURE__*/ A(`$ZodCheckMultipleOf`,(e,t)=>{Ui.init(e,t),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?t.value!==BigInt(0)&&n.value%t.value===BigInt(0):On(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Yi=/*@__PURE__*/ A(`$ZodCheckNumberFormat`,(e,t)=>{Ui.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Yn[t.format];e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Xi=/*@__PURE__*/ A(`$ZodCheckMaxLength`,(e,t)=>{var n;Ui.init(e,t),(n=e._zod.def).when??(n.when=Wi),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>t.maximum?pr(r):i)<=t.maximum)return;let a=mr(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Zi=/*@__PURE__*/ A(`$ZodCheckMinLength`,(e,t)=>{var n;Ui.init(e,t),(n=e._zod.def).when??(n.when=Wi),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?pr(r):i)>=t.minimum)return;let a=mr(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Qi=/*@__PURE__*/ A(`$ZodCheckLengthEquals`,(e,t)=>{var n;Ui.init(e,t),(n=e._zod.def).when??(n.when=Wi),e._zod.check=n=>{let r=n.value,i=r.length,a=typeof r==`string`&&i>=t.length&&i<=t.length*2?pr(r):i;if(a===t.length)return;let o=mr(r),s=a>t.length;n.issues.push({origin:o,...s?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),$i=/*@__PURE__*/ A(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Ui.init(e,t),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),ea=/*@__PURE__*/ A(`$ZodCheckRegex`,(e,t)=>{$i.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),ta=/*@__PURE__*/ A(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Vi,$i.init(e,t)}),na=/*@__PURE__*/ A(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Hi,$i.init(e,t)}),ra=/*@__PURE__*/ A(`$ZodCheckIncludes`,(e,t)=>{Ui.init(e,t);let n=Gn(t.includes);t.pattern=new RegExp(typeof t.position==`number`?`^.{${t.position},}${n}`:n),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),ia=/*@__PURE__*/ A(`$ZodCheckStartsWith`,(e,t)=>{Ui.init(e,t);let n=RegExp(`^${Gn(t.prefix)}.*`);t.pattern??=n,e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),aa=/*@__PURE__*/ A(`$ZodCheckEndsWith`,(e,t)=>{Ui.init(e,t);let n=RegExp(`.*${Gn(t.suffix)}$`);t.pattern??=n,e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),oa=/*@__PURE__*/ A(`$ZodCheckOverwrite`,(e,t)=>{Ui.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var sa=class{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{--this.indent}}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
5
+ `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.content??[``];return new e(...Object.keys(this.closed),`return function (${this.args.join(`, `)}) {\n${t.join(`
6
+ `)}\n};`)(...Object.values(this.closed))}};const ca={major:4,minor:6,patch:5},j=/*@__PURE__*/ A(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=ca;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=or(t),a;for(let o of n){if(o._zod.def.when){if(sr(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new Mr;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(ur(t.issues,n,e),i||=or(t,n))});else{if(t.issues.length===n)continue;ur(t.issues,n,e),i||=or(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(or(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new Mr;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new Mr;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return yr(this,`~standard`,da(this))},set"~standard"(e){vr(this,`~standard`,e)}}),la=(e,t)=>e.issues.length?{issues:e.issues.map(e=>dr(e,t,Fr()))}:{value:e.value};async function ua(e,t){let n={async:!0};return la(await e._zod.run({value:t,issues:[]},n),n)}function da(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return la(r,n)}catch{}return ua(e,t)},vendor:`zod`,version:1}}const fa=/*@__PURE__*/ A(`$ZodString`,(e,t)=>{j.init(e,t),e._zod.pattern=t.pattern??Li,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),M=/*@__PURE__*/ A(`$ZodStringFormat`,(e,t)=>{$i.init(e,t),fa.init(e,t)}),pa=/*@__PURE__*/ A(`$ZodGUID`,(e,t)=>{t.pattern??=yi,M.init(e,t)}),ma=/*@__PURE__*/ A(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=bi(e)}else t.pattern??=bi();M.init(e,t)}),ha=/*@__PURE__*/ A(`$ZodEmail`,(e,t)=>{t.pattern??=xi,M.init(e,t)});function ga(e){try{return typeof URL<`u`&&typeof URL.canParse==`function`?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function _a(e,t){return!(`normalize`in t)&&!(`hostname`in t)&&!(`protocol`in t)?ga(e)||2:va(e,t)}function va(e,t){if(!t.normalize&&t.protocol?.source===ki.source&&!/^https?:\/\//i.test(e))return 1;try{if(typeof URL<`u`){let t=URL;if(typeof t.parse==`function`)return t.parse(e)??2}return new URL(e)}catch{return 2}}const ya=/[\t\n\r]/g;function ba(e){return e.replace(ya,``)}function xa(e,t){return t.lastIndex=0,t.test(e.hostname)}function Sa(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(`:`)?e.protocol.slice(0,-1):e.protocol)}const Ca=/*@__PURE__*/ A(`$ZodURL`,(e,t)=>{M.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=_a(r,t);if(i===1){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}if(i===2){n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort});return}if(i===!0){n.value=ba(r);return}t.hostname&&!xa(i,t.hostname)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!Sa(i,t.protocol)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?i.href:ba(r);return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),wa=/*@__PURE__*/ A(`$ZodEmoji`,(e,t)=>{t.pattern??=Si(),M.init(e,t)}),Ta=/*@__PURE__*/ A(`$ZodNanoID`,(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??=t.length===void 0?gi:_i(t.length),M.init(e,t)}),Ea=/*@__PURE__*/ A(`$ZodCUID`,(e,t)=>{t.pattern??=di,M.init(e,t)}),Da=/*@__PURE__*/ A(`$ZodCUID2`,(e,t)=>{t.pattern??=fi,M.init(e,t)}),Oa=/*@__PURE__*/ A(`$ZodULID`,(e,t)=>{t.pattern??=pi,M.init(e,t)}),ka=/*@__PURE__*/ A(`$ZodXID`,(e,t)=>{t.pattern??=mi,M.init(e,t)}),Aa=/*@__PURE__*/ A(`$ZodKSUID`,(e,t)=>{t.pattern??=hi,M.init(e,t)}),ja=/*@__PURE__*/ A(`$ZodISODateTime`,(e,t)=>{t.pattern??=Ii(t),M.init(e,t)}),Ma=/*@__PURE__*/ A(`$ZodISODate`,(e,t)=>{t.pattern??=Ni,M.init(e,t)}),Na=/*@__PURE__*/ A(`$ZodISOTime`,(e,t)=>{t.pattern??=Fi(t),M.init(e,t)}),Pa=/*@__PURE__*/ A(`$ZodISODuration`,(e,t)=>{t.pattern??=vi,M.init(e,t)}),Fa=/*@__PURE__*/ A(`$ZodIPv4`,(e,t)=>{t.pattern??=Ci,M.init(e,t)}),Ia=/^[0-9a-fA-F:.]+$/;function La(e){return Ia.test(e)?ga(`http://[${e}]`):!1}const Ra=/*@__PURE__*/ A(`$ZodIPv6`,(e,t)=>{t.pattern??=wi,M.init(e,t),e._zod.check=n=>{La(n.value)||n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}),za=/*@__PURE__*/ A(`$ZodCIDRv4`,(e,t)=>{t.pattern??=Ti,M.init(e,t)});function Ba(e){let t=e.split(`/`);if(t.length!==2)return!1;let[n,r]=t;if(!r)return!1;let i=Number(r);return`${i}`!==r||i<0||i>128?!1:La(n)}const Va=/*@__PURE__*/ A(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Ei,M.init(e,t),e._zod.check=n=>{Ba(n.value)||n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}});function Ha(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Ua=/^[0-9a-zA-Z+/]*={0,2}$/,Wa=/*@__PURE__*/ A(`$ZodBase64`,(e,t)=>{t.pattern??=Ua,M.init(e,t),e._zod.check=n=>{Ha(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),Ga=/^[A-Za-z0-9_-]*$/;function Ka(e){if(!Ga.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Ha(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const qa=/*@__PURE__*/ A(`$ZodBase64URL`,(e,t)=>{t.pattern??=Ga,M.init(e,t),e._zod.check=n=>{Ka(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Ja=/*@__PURE__*/ A(`$ZodE164`,(e,t)=>{t.pattern??=Ai,M.init(e,t)});function Ya(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Xa=/*@__PURE__*/ A(`$ZodJWT`,(e,t)=>{M.init(e,t),e._zod.check=n=>{Ya(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Za=/*@__PURE__*/ A(`$ZodNumber`,(e,t)=>{j.init(e,t),e._zod.pattern=zi,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Qa=/*@__PURE__*/ A(`$ZodNumberFormat`,(e,t)=>{Yi.init(e,t),Za.init(e,t)}),$a=/*@__PURE__*/ A(`$ZodBoolean`,(e,t)=>{j.init(e,t),e._zod.pattern=Bi,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),eo=/*@__PURE__*/ A(`$ZodAny`,(e,t)=>{j.init(e,t),e._zod.parse=e=>e}),to=/*@__PURE__*/ A(`$ZodUnknown`,(e,t)=>{j.init(e,t),e._zod.parse=e=>e}),no=/*@__PURE__*/ A(`$ZodNever`,(e,t)=>{j.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function ro(e,t,n){e.issues.length&&t.issues.push(...cr(n,e.issues)),t.value[n]=e.value}const io=/*@__PURE__*/ A(`$ZodArray`,(e,t)=>{j.init(e,t);let n=Pr.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>ro(t,r,e)));else if(ro(c,r,e),s&&c.issues.length!==0&&or(c))break}return o.length?Promise.all(o).then(()=>r):r}});function ao(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...cr(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}const oo=[];function so(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:oo,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=Jn(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function co(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(or(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>ao(e,n,i,t,d,f))):ao(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const lo=/*@__PURE__*/ A(`$ZodObject`,(e,t)=>{j.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,"shape",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,"shape",{get:e})}let i=Tn(()=>so(t));k(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||kn(n,e,/* @__PURE__ */ new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=Bn,o=t.catchall,s,c=Pr.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(or(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>ao(n,t,e,r,a,o))):ao(s,t,e,r,a,o)}return o?co(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),uo=/*@__PURE__*/ A(`$ZodObjectJIT`,(e,t)=>{lo.init(e,t);let n=e._zod.parse,r=Tn(()=>so(t)),i=Pr.memoizer,a=t=>{let n=r.value,a=n.symbolKeys,o=new sa([`payload`,`ctx`],{shape:t,inst:e,memo:i,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,c=(e,t)=>`
7
+ let ${e}_ab = false;
8
+ for (let i = 0; i < ${e}.issues.length; i++) {
9
+ const iss = ${e}.issues[i];
10
+ iss.path = iss.path ? [${t}, ...iss.path] : [${t}];
11
+ payload.issues.push(iss);
12
+ if (iss.continue !== true) ${e}_ab = true;
13
+ }
14
+ if (${e}_ab && ctx && ctx.abortEarly) {
15
+ payload.value = newResult;
16
+ return payload;
17
+ }`;o.write(`const input = payload.value;`);let l=Object.create(null),u=0;for(let e of n.allKeys)l[e]=`key_${u++}`;o.write(i?`const newResult = memo.alloc(inst, payload, {}, ctx);`:`const newResult = {};`);for(let e of n.allKeys){if(e===`__proto__`)continue;let n=l[e],r=typeof e==`symbol`?`syms[${a.indexOf(e)}]`:Ln(e),i=`${r} in input`,u=t[e],d=u?._zod?.optin,f=d!==void 0,p=u?._zod?.optout===`optional`;if(o.write(`const ${n} = ${s(r)};`),f&&p){let e=d===`optional`?`${n}_present`:`${n}.value !== undefined || ${n}_present`;o.write(`
18
+ const ${n}_present = ${i};
19
+ if (!${n}.issues.length || ${n}_present) {
20
+ if (${n}.issues.length) {${c(n,r)}
21
+ }
22
+
23
+ if (${e}) {
24
+ newResult[${r}] = ${n}.value;
25
+ }
26
+ }
27
+
28
+ `)}else f?(o.write(`
29
+ if (${n}.issues.length) {${c(n,r)}
30
+ }
31
+ `),d===`defaulted`?o.write(`newResult[${r}] = ${n}.value;`):o.write(`
32
+ if (${n}.value !== undefined || ${i}) {
33
+ newResult[${r}] = ${n}.value;
34
+ }
35
+ `)):o.write(`
36
+ const ${n}_present = ${i};
37
+ if (${n}.issues.length) {${c(n,r)}
38
+ }
39
+ if (!${n}_present && !${n}.issues.length) {
40
+ payload.issues.push({
41
+ code: "invalid_type",
42
+ expected: "nonoptional",
43
+ input: undefined,
44
+ path: [${r}]
45
+ });
46
+ if (ctx && ctx.abortEarly) {
47
+ payload.value = newResult;
48
+ return payload;
49
+ }
50
+ }
51
+
52
+ if (${n}_present) {
53
+ newResult[${r}] = ${n}.value;
54
+ }
55
+
56
+ `)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=Bn,c=!Pr.jitless,l=c&&Vn.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?co([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function fo(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!or(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>dr(e,r,Fr())))}),t)}const po=/*@__PURE__*/ A(`$ZodUnion`,(e,t)=>{j.init(e,t),k(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),k(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),k(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>Dn(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>fo(t,r,e,i)):fo(o,r,e,i)}}),mo=/*@__PURE__*/ A(`$ZodIntersection`,(e,t)=>{j.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>go(e,t,n)):go(e,i,a)}});function ho(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Hn(e)&&Hn(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=ho(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ho(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function go(e,t,n){let r=/* @__PURE__ */ new Map,i,a=/* @__PURE__ */ new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=ho(t.value,n.value);if(!c.valid){if(or(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}const _o=/*@__PURE__*/ A(`$ZodRecord`,(e,t)=>{j.init(e,t);let n=Pr.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Hn(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=/* @__PURE__ */ new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>dr(e,i,Fr())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...cr(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...cr(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&zi.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>dr(e,i,Fr())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...cr(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...cr(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),vo=/*@__PURE__*/ A(`$ZodEnum`,(e,t)=>{j.init(e,t);let n=xn(t.entries),r=new Set(n);e._zod.values=r,k(e,`pattern`,e=>{let t=xn(e.def.entries).filter(e=>Wn.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Gn(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),yo=/*@__PURE__*/ A(`$ZodLiteral`,(e,t)=>{j.init(e,t);let n=new Set(t.values);e._zod.values=n,k(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?Gn(e):e?Gn(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),bo=/*@__PURE__*/ A(`$ZodTransform`,(e,t)=>{j.init(e,t),e._zod.optin=`optional`,Pr.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Nr(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new Mr;return n.value=i,n}});function xo(e,t){return e.value=t.issues.length?void 0:t.value,e}const So=/*@__PURE__*/ A(`$ZodOptional`,(e,t)=>{j.init(e,t),k(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,k(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?/* @__PURE__ */ new Set([...t,void 0]):void 0}),k(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Dn(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>xo(e,t)):xo(e,r)}return t.innerType._zod.run(e,n)}}),Co=/*@__PURE__*/ A(`$ZodExactOptional`,(e,t)=>{So.init(e,t),k(e,`values`,e=>e.def.innerType._zod.values),k(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),wo=/*@__PURE__*/ A(`$ZodNullable`,(e,t)=>{j.init(e,t),k(e,`optin`,e=>e.def.innerType._zod.optin),k(e,`optout`,e=>e.def.innerType._zod.optout),k(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Dn(t.source)}|null)$`):void 0}),k(e,`values`,e=>e.def.innerType._zod.values?/* @__PURE__ */ new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),To=/*@__PURE__*/ A(`$ZodDefault`,(e,t)=>{j.init(e,t),e._zod.optin=`defaulted`,k(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Eo(e,t)):Eo(r,t)}});function Eo(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Do=/*@__PURE__*/ A(`$ZodPrefault`,(e,t)=>{j.init(e,t),e._zod.optin=`defaulted`,k(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Oo=/*@__PURE__*/ A(`$ZodNonOptional`,(e,t)=>{j.init(e,t),k(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>ko(t,e)):ko(i,e)}});function ko(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function Ao(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>dr(e,r,Fr()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}const jo=/*@__PURE__*/ A(`$ZodCatch`,(e,t)=>{j.init(e,t),k(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),k(e,`optout`,e=>e.def.innerType._zod.optout),k(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>Ao(e,r,t,n)):Ao(e,r,t,n)}}),Mo=/*@__PURE__*/ A(`$ZodPipe`,(e,t)=>{j.init(e,t),k(e,`values`,e=>e.def.in._zod.values),k(e,`optin`,e=>e.def.in._zod.optin),k(e,`optout`,e=>e.def.out._zod.optout),k(e,`propValues`,e=>e.def.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>No(e,t.in,n)):No(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>No(e,t.out,n)):No(r,t.out,n)}});function No(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Po=/*@__PURE__*/ A(`$ZodReadonly`,(e,t)=>{j.init(e,t),k(e,`propValues`,e=>e.def.innerType._zod.propValues),k(e,`values`,e=>e.def.innerType._zod.values),k(e,`optin`,e=>e.def.innerType?._zod?.optin),k(e,`optout`,e=>e.def.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Fo):Fo(r)}});function Fo(e){return e.memo||(e.value=Object.freeze(e.value)),e}const Io=/*@__PURE__*/ A(`$ZodCustom`,(e,t)=>{Ui.init(e,t),j.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Lo(t,n,r,e));Lo(i,n,r,e)}});function Lo(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(gr(e))}}var Ro=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}};const zo=`~memo`,Bo=[];function Vo(e){return typeof e==`object`&&!!e}function Ho(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}const Uo=/*@__PURE__*/ new WeakMap;function Wo(e,t,n){let r=Uo.get(e);if(r!==void 0)return r?2:0;if(t.has(e))return 2;t.add(e);let i=0,a=e=>{if(i!==2&&e?._zod){let r=Wo(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=0;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?1:o.value?._zod?Wo(o.value,t,n):0;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=An(c);s(e?o(e,!0):1),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?Wo(r,t,!1):1);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),Go(e,i)}function Go(e,t){return t!==1&&Uo.set(e,t===2),t}function Ko(e,t){let n=e.buckets.get(t);return n||(n=/* @__PURE__ */ new WeakMap,e.buckets.set(t,n)),n}let qo;const Jo=[],Yo={alloc(e,t,n){let r=qo;if(!r)return n;qo=void 0;let i={value:n,issues:null};return r.set(t.value,i),Jo.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&Zo(n,e.value))throw new Ro;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=Wo(e,/* @__PURE__ */ new Set,!1);if(i===0)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===2||r?n=!0:r=!0}let l=s.value;if(!Vo(l))return t(s,c);let u=c[zo];u||(u={buckets:/* @__PURE__ */ new WeakMap,backEdges:void 0},c[zo]=u);let d;i===c?d=a:(d=Ko(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...Ho(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=/* @__PURE__ */ new WeakSet),u.backEdges.add(f.value)),s;qo=d;let p=Jo.length,m=t(s,c);qo=void 0;let h=Jo.length>p?Jo.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?Ho(e.issues):Bo),e)):(h&&(h.issues=m.issues.length?Ho(m.issues):Bo),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function Xo(){return Yo}function Zo(e,t){let n=e[zo]?.backEdges;return n!==void 0&&Vo(t)&&n.has(t)}const Qo=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(hr(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${qn(e.values[0])}`:`Invalid option: expected one of ${Sn(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${Sn(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function $o(){return{localeError:Qo()}}var es,ts=class{constructor(){this._map=/* @__PURE__ */ new WeakMap,this._idmap=/* @__PURE__ */ new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=/* @__PURE__ */ new WeakMap,this._idmap=/* @__PURE__ */ new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function ns(){return new ts}(es=globalThis).__zod_globalRegistry??(es.__zod_globalRegistry=ns());const rs=globalThis.__zod_globalRegistry;function is(e){return e.checks&&=[...e.checks],e}// @__NO_SIDE_EFFECTS__
57
+ function as(e,t){return new e(is({type:`string`,...O(t)}))}// @__NO_SIDE_EFFECTS__
58
+ function os(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
59
+ function ss(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
60
+ function cs(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
61
+ function ls(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...O(t)})}// @__NO_SIDE_EFFECTS__
62
+ function us(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...O(t)})}// @__NO_SIDE_EFFECTS__
63
+ function ds(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...O(t)})}// @__NO_SIDE_EFFECTS__
64
+ function fs(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
65
+ function ps(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
66
+ function ms(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
67
+ function hs(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
68
+ function gs(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
69
+ function _s(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
70
+ function vs(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
71
+ function ys(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
72
+ function bs(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
73
+ function xs(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
74
+ function Ss(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
75
+ function Cs(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
76
+ function ws(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
77
+ function Ts(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
78
+ function Es(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
79
+ function Ds(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...O(t)})}// @__NO_SIDE_EFFECTS__
80
+ function Os(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...O(t)})}// @__NO_SIDE_EFFECTS__
81
+ function ks(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...O(t)})}// @__NO_SIDE_EFFECTS__
82
+ function As(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...O(t)})}// @__NO_SIDE_EFFECTS__
83
+ function js(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...O(t)})}// @__NO_SIDE_EFFECTS__
84
+ function Ms(e,t){return new e(is({type:`number`,checks:[],...O(t)}))}// @__NO_SIDE_EFFECTS__
85
+ function Ns(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...O(t)})}// @__NO_SIDE_EFFECTS__
86
+ function Ps(e,t){return new e({type:`boolean`,...O(t)})}// @__NO_SIDE_EFFECTS__
87
+ function Fs(e){return new e({type:`any`})}// @__NO_SIDE_EFFECTS__
88
+ function Is(e){return new e({type:`unknown`})}// @__NO_SIDE_EFFECTS__
89
+ function Ls(e,t){return new e({type:`never`,...O(t)})}// @__NO_SIDE_EFFECTS__
90
+ function Rs(e,t){return new Ki({check:`less_than`,...O(t),value:e,inclusive:!1})}// @__NO_SIDE_EFFECTS__
91
+ function zs(e,t){return new Ki({check:`less_than`,...O(t),value:e,inclusive:!0})}// @__NO_SIDE_EFFECTS__
92
+ function Bs(e,t){return new qi({check:`greater_than`,...O(t),value:e,inclusive:!1})}// @__NO_SIDE_EFFECTS__
93
+ function Vs(e,t){return new qi({check:`greater_than`,...O(t),value:e,inclusive:!0})}// @__NO_SIDE_EFFECTS__
94
+ function Hs(e,t){return new Ji({check:`multiple_of`,...O(t),value:e})}// @__NO_SIDE_EFFECTS__
95
+ function Us(e,t){return new Xi({check:`max_length`,...O(t),maximum:e})}// @__NO_SIDE_EFFECTS__
96
+ function Ws(e,t){return new Zi({check:`min_length`,...O(t),minimum:e})}// @__NO_SIDE_EFFECTS__
97
+ function Gs(e,t){return new Qi({check:`length_equals`,...O(t),length:e})}// @__NO_SIDE_EFFECTS__
98
+ function Ks(e,t){return new ea({check:`string_format`,format:`regex`,...O(t),pattern:e})}// @__NO_SIDE_EFFECTS__
99
+ function qs(e){return new ta({check:`string_format`,format:`lowercase`,...O(e)})}// @__NO_SIDE_EFFECTS__
100
+ function Js(e){return new na({check:`string_format`,format:`uppercase`,...O(e)})}// @__NO_SIDE_EFFECTS__
101
+ function Ys(e,t){return new ra({check:`string_format`,format:`includes`,...O(t),includes:e})}// @__NO_SIDE_EFFECTS__
102
+ function Xs(e,t){return new ia({check:`string_format`,format:`starts_with`,...O(t),prefix:e})}// @__NO_SIDE_EFFECTS__
103
+ function Zs(e,t){return new aa({check:`string_format`,format:`ends_with`,...O(t),suffix:e})}// @__NO_SIDE_EFFECTS__
104
+ function Qs(e){return new oa({check:`overwrite`,tx:e})}// @__NO_SIDE_EFFECTS__
105
+ function $s(e){return/* @__PURE__ */ Qs(t=>t.normalize(e))}// @__NO_SIDE_EFFECTS__
106
+ function ec(){return/* @__PURE__ */ Qs(e=>e.trim())}// @__NO_SIDE_EFFECTS__
107
+ function tc(){return/* @__PURE__ */ Qs(e=>e.toLowerCase())}// @__NO_SIDE_EFFECTS__
108
+ function nc(){return/* @__PURE__ */ Qs(e=>e.toUpperCase())}// @__NO_SIDE_EFFECTS__
109
+ function rc(){return/* @__PURE__ */ Qs(e=>Rn(e))}// @__NO_SIDE_EFFECTS__
110
+ function ic(e,t,n){return new e({type:`array`,element:t,...O(n)})}// @__NO_SIDE_EFFECTS__
111
+ function ac(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...O(n)})}// @__NO_SIDE_EFFECTS__
112
+ function oc(e,t){let n=/* @__PURE__ */ sc(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(gr(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(gr(r))}},e(t.value,t)),t);return n}// @__NO_SIDE_EFFECTS__
113
+ function sc(e,t){let n=new Ui({check:`custom`,...O(t)});return n._zod.check=e,n}function cc(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&kn(e,t,n[t]);return e}function lc(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??rs,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:/* @__PURE__ */ new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function uc(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function N(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,N(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&cc(o.schema,c),t.io===`input`&&bc(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function dc(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function fc(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=/* @__PURE__ */ new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${dc(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+dc(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
114
+
115
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function pc(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;pc(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const mc=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),hc=[`oneOf`,`anyOf`];function gc(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function _c(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!mc.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??gc(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}kn(n,r,e.length===1?e[0]:_c(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=gc(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function vc(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of mc)if(t in e)return;let n=t.filter(e=>hc.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=_c(t);else{let e=n[0],i=hc.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>_c([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,cc(e,r))}function yc(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):cc(i,s),cc(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())pc(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])vc(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}cc(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,kn(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Sc(t,`input`,e.processors),output:Sc(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function bc(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return bc(r.element,n);if(r.type===`set`)return bc(r.valueType,n);if(r.type===`lazy`)return bc(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return bc(r.innerType,n);if(r.type===`intersection`)return bc(r.left,n)||bc(r.right,n);if(r.type===`record`||r.type===`map`)return bc(r.keyType,n)||bc(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:bc(r.in,n)||bc(r.out,n);if(r.type===`object`){for(let e in r.shape)if(bc(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(bc(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(bc(e,n))return!0;return!!(r.rest&&bc(r.rest,n))}return!1}const xc=(e,t={})=>n=>{let r=lc({...n,processors:t});return N(e,r),fc(r,e),yc(r,e)},Sc=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=lc({...i??{},target:a,io:t,processors:n});return N(e,o),fc(o,e),yc(o,e)},Cc=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},wc=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Tc=(e,t)=>{Cc(e,`minimum`,t),wc(e,`maximum`,t)},Ec=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Dc=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},Oc=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},kc=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ac=(e,t)=>Cc(e,`minimum`,t.minimum),jc=(e,t)=>wc(e,`maximum`,t.maximum),Mc=e=>(t,n)=>{kc(t,n.format);let[r,i]=e[n.format];Cc(t,`minimum`,r),wc(t,`maximum`,i)},Nc={greater_than:(e,t)=>Cc(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>wc(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Ec(e,t.value),number_format:Mc(Yn),bigint_format:Mc(Xn),min_length:Ac,max_length:jc,length_equals:(e,t)=>Tc(e,t.length),min_size:Ac,max_size:jc,size_equals:(e,t)=>Tc(e,t.size),string_format:(e,t)=>{kc(e,t.format),t.pattern&&Dc(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Oc(e,t.mime)};function Pc(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Nc[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Cc(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Cc(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&wc(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&wc(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Ec(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Oc(t,i.mime);for(let e of i.patterns??[])Dc(t,e);return t}const Fc={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Ic=/* @__PURE__ */ new Map([[Ua,Di],[Ga,Oi]]),Lc=e=>Ic.get(e)??e,Rc=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Pc(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Fc[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Lc);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},zc=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Pc(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):uc(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},Bc=(e,t,n,r)=>{n.type=`boolean`},Vc=(e,t,n,r)=>{n.not={}},Hc=(e,t,n,r)=>{let i=e._zod.def,a=xn(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Uc=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(uc(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(uc(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Wc=(e,t,n,r)=>{uc(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Gc=(e,t,n,r)=>{uc(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Kc=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Pc(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=N(a.element,t,{...r,path:[...r.path,`items`]})};function qc(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?qc(t.out):t.type===`catch`?qc(t.innerType):e._zod.optin}const Jc=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&uc(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)kn(i.properties,e,N(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?qc(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=N(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Yc=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>N(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Xc=(e,t,n,r)=>{let i=e._zod.def,a=N(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=N(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function Zc(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=Zc(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>Zc(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?zi:Ri).source),p):p}const Qc=/* @__PURE__ */ new WeakMap;function $c(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of Qc.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Zc(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const el=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=Pc(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=N(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)kn(i.patternProperties,Lc(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=N(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Qc.get(t);n||(n=[],Qc.set(t,n),t.deferred.push(()=>$c(t))),n.push(e)}i.additionalProperties=N(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&qc(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},tl=(e,t,n,r)=>{let i=e._zod.def,a=N(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},nl=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},rl=Symbol();function il(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(uc(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),rl):JSON.parse(o)}const al=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=il(i.defaultValue,e,t,n,r);o!==rl&&(n.default=o)},ol=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=il(i.defaultValue,e,t,n,r);o!==rl&&(n._prefault=o)},sl=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{uc(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},cl=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;N(o,t,r);let s=t.seen.get(e);s.ref=o},ll=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},ul=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},dl=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function fl(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const pl=(e,t)=>{Hr.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);dl.has(n)||(dl.add(n),fl(n,`format`,e=>t=>Gr(e,t)),fl(n,`flatten`,e=>t=>Wr(e,t)),fl(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Cn,2)}),fl(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Cn,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},ml=/*@__PURE__*/ A(`ZodError`,pl),hl=/*@__PURE__*/ A(`ZodError`,pl,void 0,{Parent:Error}),gl=/* @__PURE__ */ qr(hl),_l=/* @__PURE__ */ Jr(hl),vl=/* @__PURE__ */ Yr(hl),yl=/* @__PURE__ */ Zr(hl),bl=/* @__PURE__ */ ri(hl),xl=/* @__PURE__ */ ii(hl),Sl=/* @__PURE__ */ ai(hl),Cl=/* @__PURE__ */ oi(hl),wl=/* @__PURE__ */ si(hl),Tl=/* @__PURE__ */ ci(hl),El=/* @__PURE__ */ li(hl),Dl=/* @__PURE__ */ ui(hl);function Ol(){Pr.localeError||Fr($o())}function kl(){Pr.memoizer||Fr({memoizer:Xo()})}const P=/*@__PURE__*/ A(`ZodType`,(e,t)=>(Ol(),j.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(In(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Kn(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Ku(e,t))},superRefine(e,t){return this.check(qu(e,t))},overwrite(e){return this.check(/* @__PURE__ */ Qs(e))},optional(){return Ou(this)},exactOptional(){return Au(this)},nullable(){return Mu(this)},nullish(){return Ou(Mu(this))},nonoptional(e){return Ru(this,e)},array(){return L(this)},or(e){return _u([this,e])},and(e){return yu(this,e)},transform(e){return Hu(this,Eu(e))},default(e){return Pu(this,e)},prefault(e){return Iu(this,e)},catch(e){return Bu(this,e)},pipe(e){return Hu(this,e)},readonly(){return Wu(this)},describe(e){let t=this.clone();return rs.add(t,{description:e}),t},meta(...e){if(e.length===0)return rs.get(this);let t=this.clone();return rs.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return yr(this,`~standard`,{...da(this),jsonSchema:{input:Sc(this,`input`),output:Sc(this,`output`)}})},set"~standard"(e){vr(this,`~standard`,e)},parse:function e(t,n){return gl(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await _l(this,t,n,{callee:e})},safeParse(e,t){return vl(this,e,t)},async safeParseAsync(e,t){return yl(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){vr(this,`spa`,e)},validate(e,t){return ei(this,e,t)},validateAsync(e,t){return ni(this,e,t)},encode:function e(t,n){return bl(this,t,n,{callee:e})},decode:function e(t,n){return xl(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await Sl(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await Cl(this,t,n,{callee:e})},safeEncode(e,t){return wl(this,e,t)},safeDecode(e,t){return Tl(this,e,t)},async safeEncodeAsync(e,t){return El(this,e,t)},async safeDecodeAsync(e,t){return Dl(this,e,t)},toJSONSchema(e){return xc(this,{})(e)},get description(){return rs.get(this)?.description},get _def(){return this._zod.def}}),Al=/*@__PURE__*/ A(`_ZodString`,(e,t)=>{fa.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Rc(e,t,n,r)},/*@__PURE__*/ br({format:e=>Pc(e).format??null,minLength:e=>Pc(e).minimum??null,maxLength:e=>Pc(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ Ks(...e))},includes(...e){return this.check(/* @__PURE__ */ Ys(...e))},startsWith(...e){return this.check(/* @__PURE__ */ Xs(...e))},endsWith(...e){return this.check(/* @__PURE__ */ Zs(...e))},min(...e){return this.check(/* @__PURE__ */ Ws(...e))},max(...e){return this.check(/* @__PURE__ */ Us(...e))},length(...e){return this.check(/* @__PURE__ */ Gs(...e))},nonempty(...e){return this.check(/* @__PURE__ */ Ws(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ qs(e))},uppercase(e){return this.check(/* @__PURE__ */ Js(e))},trim(){return this.check(/* @__PURE__ */ ec())},normalize(...e){return this.check(/* @__PURE__ */ $s(...e))},toLowerCase(){return this.check(/* @__PURE__ */ tc())},toUpperCase(){return this.check(/* @__PURE__ */ nc())},slugify(){return this.check(/* @__PURE__ */ rc())}})),jl=/*@__PURE__*/ A(`ZodString`,(e,t)=>{fa.init(e,t),Al.init(e,t)},{email(e){return this.check(/* @__PURE__ */ os(Il,e))},url(e){return this.check(/* @__PURE__ */ fs(zl,e))},jwt(e){return this.check(/* @__PURE__ */ Ds(eu,e))},emoji(e){return this.check(/* @__PURE__ */ ps(Bl,e))},guid(e){return this.check(/* @__PURE__ */ ss(Ll,e))},uuid(e){return this.check(/* @__PURE__ */ cs(Rl,e))},uuidv4(e){return this.check(/* @__PURE__ */ ls(Rl,e))},uuidv6(e){return this.check(/* @__PURE__ */ us(Rl,e))},uuidv7(e){return this.check(/* @__PURE__ */ ds(Rl,e))},nanoid(e){return this.check(/* @__PURE__ */ ms(Vl,e))},cuid(e){return this.check(/* @__PURE__ */ hs(Hl,e))},cuid2(e){return this.check(/* @__PURE__ */ gs(Ul,e))},ulid(e){return this.check(/* @__PURE__ */ _s(Wl,e))},base64(e){return this.check(/* @__PURE__ */ ws(Zl,e))},base64url(e){return this.check(/* @__PURE__ */ Ts(Ql,e))},xid(e){return this.check(/* @__PURE__ */ vs(Gl,e))},ksuid(e){return this.check(/* @__PURE__ */ ys(Kl,e))},ipv4(e){return this.check(/* @__PURE__ */ bs(ql,e))},ipv6(e){return this.check(/* @__PURE__ */ xs(Jl,e))},cidrv4(e){return this.check(/* @__PURE__ */ Ss(Yl,e))},cidrv6(e){return this.check(/* @__PURE__ */ Cs(Xl,e))},e164(e){return this.check(/* @__PURE__ */ Es($l,e))},datetime(e){return this.check(/* @__PURE__ */ Os(Ml,e))},date(e){return this.check(/* @__PURE__ */ ks(Nl,e))},time(e){return this.check(/* @__PURE__ */ As(Pl,e))},duration(e){return this.check(/* @__PURE__ */ js(Fl,e))}});function F(e){return/* @__PURE__ */ as(jl,e)}const I=/*@__PURE__*/ A(`ZodStringFormat`,(e,t)=>{M.init(e,t),Al.init(e,t)}),Ml=/*@__PURE__*/ A(`ZodISODateTime`,(e,t)=>{ja.init(e,t),I.init(e,t)}),Nl=/*@__PURE__*/ A(`ZodISODate`,(e,t)=>{Ma.init(e,t),I.init(e,t)}),Pl=/*@__PURE__*/ A(`ZodISOTime`,(e,t)=>{Na.init(e,t),I.init(e,t)}),Fl=/*@__PURE__*/ A(`ZodISODuration`,(e,t)=>{Pa.init(e,t),I.init(e,t)}),Il=/*@__PURE__*/ A(`ZodEmail`,(e,t)=>{ha.init(e,t),I.init(e,t)}),Ll=/*@__PURE__*/ A(`ZodGUID`,(e,t)=>{pa.init(e,t),I.init(e,t)}),Rl=/*@__PURE__*/ A(`ZodUUID`,(e,t)=>{ma.init(e,t),I.init(e,t)}),zl=/*@__PURE__*/ A(`ZodURL`,(e,t)=>{Ca.init(e,t),I.init(e,t)}),Bl=/*@__PURE__*/ A(`ZodEmoji`,(e,t)=>{wa.init(e,t),I.init(e,t)}),Vl=/*@__PURE__*/ A(`ZodNanoID`,(e,t)=>{Ta.init(e,t),I.init(e,t)}),Hl=/*@__PURE__*/ A(`ZodCUID`,(e,t)=>{Ea.init(e,t),I.init(e,t)}),Ul=/*@__PURE__*/ A(`ZodCUID2`,(e,t)=>{Da.init(e,t),I.init(e,t)}),Wl=/*@__PURE__*/ A(`ZodULID`,(e,t)=>{Oa.init(e,t),I.init(e,t)}),Gl=/*@__PURE__*/ A(`ZodXID`,(e,t)=>{ka.init(e,t),I.init(e,t)}),Kl=/*@__PURE__*/ A(`ZodKSUID`,(e,t)=>{Aa.init(e,t),I.init(e,t)}),ql=/*@__PURE__*/ A(`ZodIPv4`,(e,t)=>{Fa.init(e,t),I.init(e,t)}),Jl=/*@__PURE__*/ A(`ZodIPv6`,(e,t)=>{Ra.init(e,t),I.init(e,t)}),Yl=/*@__PURE__*/ A(`ZodCIDRv4`,(e,t)=>{za.init(e,t),I.init(e,t)}),Xl=/*@__PURE__*/ A(`ZodCIDRv6`,(e,t)=>{Va.init(e,t),I.init(e,t)}),Zl=/*@__PURE__*/ A(`ZodBase64`,(e,t)=>{Wa.init(e,t),I.init(e,t)}),Ql=/*@__PURE__*/ A(`ZodBase64URL`,(e,t)=>{qa.init(e,t),I.init(e,t)}),$l=/*@__PURE__*/ A(`ZodE164`,(e,t)=>{Ja.init(e,t),I.init(e,t)}),eu=/*@__PURE__*/ A(`ZodJWT`,(e,t)=>{Xa.init(e,t),I.init(e,t)}),tu=/*@__PURE__*/ A(`ZodNumber`,(e,t)=>{Za.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zc(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ br({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Pc(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Pc(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Pc(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Pc(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ Bs(e,t))},gte(e,t){return this.check(/* @__PURE__ */ Vs(e,t))},min(e,t){return this.check(/* @__PURE__ */ Vs(e,t))},lt(e,t){return this.check(/* @__PURE__ */ Rs(e,t))},lte(e,t){return this.check(/* @__PURE__ */ zs(e,t))},max(e,t){return this.check(/* @__PURE__ */ zs(e,t))},int(e){return this.check(iu(e))},safe(e){return this.check(iu(e))},positive(e){return this.check(/* @__PURE__ */ Bs(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ Vs(0,e))},negative(e){return this.check(/* @__PURE__ */ Rs(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ zs(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ Hs(e,t))},step(e,t){return this.check(/* @__PURE__ */ Hs(e,t))},finite(){return this}}));function nu(e){return/* @__PURE__ */ Ms(tu,e)}const ru=/*@__PURE__*/ A(`ZodNumberFormat`,(e,t)=>{Qa.init(e,t),tu.init(e,t)});function iu(e){return/* @__PURE__ */ Ns(ru,e)}const au=/*@__PURE__*/ A(`ZodBoolean`,(e,t)=>{$a.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bc(e,t,n,r)});function ou(e){return/* @__PURE__ */ Ps(au,e)}const su=/*@__PURE__*/ A(`ZodAny`,(e,t)=>{eo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function cu(){return/* @__PURE__ */ Fs(su)}const lu=/*@__PURE__*/ A(`ZodUnknown`,(e,t)=>{to.init(e,t),P.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function uu(){return/* @__PURE__ */ Is(lu)}const du=/*@__PURE__*/ A(`ZodNever`,(e,t)=>{no.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vc(e,t,n,r)});function fu(e){return/* @__PURE__ */ Ls(du,e)}const pu=/*@__PURE__*/ A(`ZodArray`,(e,t)=>{kl(),io.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kc(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ Ws(e,t))},nonempty(e){return this.check(/* @__PURE__ */ Ws(1,e))},max(e,t){return this.check(/* @__PURE__ */ Us(e,t))},length(e,t){return this.check(/* @__PURE__ */ Gs(e,t))},unwrap(){return this.element}});function L(e,t){return/* @__PURE__ */ ic(pu,e,t)}const mu=/*@__PURE__*/ A(`ZodObject`,(e,t)=>{kl(),uo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jc(e,t,n,r),Er(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Cu(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(In(this._zod.def,{catchall:e}))},passthrough(){return this.clone(In(this._zod.def,{catchall:uu()}))},loose(){return this.clone(In(this._zod.def,{catchall:uu()}))},strict(){return this.clone(In(this._zod.def,{catchall:fu()}))},strip(){return this.clone(In(this._zod.def,{catchall:void 0}))},extend(e){return er(this,e)},safeExtend(e){return nr(this,e)},merge(e){return rr(this,e)},pick(e){return Zn(this,e)},omit(e){return $n(this,e)},partial(...e){return ir(Du,this,e[0])},exactPartial(...e){return ir(ku,this,e[0],`exactPartial`)},required(...e){return ar(Lu,this,e[0])}});function R(e,t){let n={type:`object`,shape:e??{},...O(t)};return new mu(n)}function hu(e,t){return new mu({type:`object`,shape:e,catchall:fu(),...O(t)})}const gu=/*@__PURE__*/ A(`ZodUnion`,(e,t)=>{po.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yc(e,t,n,r),e.options=t.options});function _u(e,t){return new gu({type:`union`,options:e,...O(t)})}const vu=/*@__PURE__*/ A(`ZodIntersection`,(e,t)=>{mo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xc(e,t,n,r)});function yu(e,t){return new vu({type:`intersection`,left:e,right:t})}const bu=/*@__PURE__*/ A(`ZodRecord`,(e,t)=>{kl(),_o.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>el(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function xu(e,t,n){return!t||!t._zod?new bu({type:`record`,keyType:F(),valueType:e,...O(t)}):new bu({type:`record`,keyType:e,valueType:t,...O(n)})}const Su=/*@__PURE__*/ A(`ZodEnum`,(e,t)=>{vo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hc(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Su({...t,checks:[],...O(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Su({...t,checks:[],...O(r),entries:i})}});function Cu(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Su({type:`enum`,entries:n,...O(t)})}const wu=/*@__PURE__*/ A(`ZodLiteral`,(e,t)=>{yo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uc(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function z(e,t){return new wu({type:`literal`,values:Array.isArray(e)?e:[e],...O(t)})}const Tu=/*@__PURE__*/ A(`ZodTransform`,(e,t)=>{kl(),bo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gc(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Nr(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(gr(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(gr(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Eu(e){return new Tu({type:`transform`,transform:e})}const Du=/*@__PURE__*/ A(`ZodOptional`,(e,t)=>{So.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ul(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ou(e){return new Du({type:`optional`,innerType:e})}const ku=/*@__PURE__*/ A(`ZodExactOptional`,(e,t)=>{Co.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ul(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Au(e){return new ku({type:`optional`,innerType:e})}const ju=/*@__PURE__*/ A(`ZodNullable`,(e,t)=>{wo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>tl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mu(e){return new ju({type:`nullable`,innerType:e})}const Nu=/*@__PURE__*/ A(`ZodDefault`,(e,t)=>{To.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>al(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Pu(e,t){return new Nu({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Un(t)}})}const Fu=/*@__PURE__*/ A(`ZodPrefault`,(e,t)=>{Do.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ol(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Iu(e,t){return new Fu({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Un(t)}})}const Lu=/*@__PURE__*/ A(`ZodNonOptional`,(e,t)=>{Oo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>nl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ru(e,t){return new Lu({type:`nonoptional`,innerType:e,...O(t)})}const zu=/*@__PURE__*/ A(`ZodCatch`,(e,t)=>{jo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>sl(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Bu(e,t){return new zu({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Dr(t)})}const Vu=/*@__PURE__*/ A(`ZodPipe`,(e,t)=>{Mo.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cl(e,t,n,r),e.in=t.in,e.out=t.out});function Hu(e,t){return new Vu({type:`pipe`,in:e,out:t})}const Uu=/*@__PURE__*/ A(`ZodReadonly`,(e,t)=>{Po.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ll(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Wu(e){return new Uu({type:`readonly`,innerType:e})}const Gu=/*@__PURE__*/ A(`ZodCustom`,(e,t)=>{Io.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wc(e,t,n,r)});function Ku(e,t={}){return/* @__PURE__ */ ac(Gu,e,t)}function qu(e,t){return/* @__PURE__ */ oc(e,t)}const B={Remove:`remove`,Replace:`replace`,Add:`add`},Ju=Symbol.for(`__MUTATIVE_PROXY_DRAFT__`),Yu=Symbol(`__MUTATIVE_RAW_RETURN_SYMBOL__`),Xu=Symbol.iterator,Zu={mutable:`mutable`,immutable:`immutable`},Qu={};function $u(e,t){return e instanceof Map?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function ed(e,t){if(t in e){let n=Reflect.getPrototypeOf(e);for(;n;){let e=Reflect.getOwnPropertyDescriptor(n,t);if(e)return e;n=Reflect.getPrototypeOf(n)}}}function td(e){return Object.getPrototypeOf(e)===Set.prototype}function nd(e){return Object.getPrototypeOf(e)===Map.prototype}function rd(e){return e.copy??e.original}function id(e){return!!V(e)}function V(e){return typeof e==`object`?e?.[Ju]:null}function ad(e){let t=V(e);return t?t.copy??t.original:e}function od(e,t){if(!e||typeof e!=`object`)return!1;let n;return Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||!!t?.mark&&((n=t.mark(e,Zu))===Zu.immutable||typeof n==`function`)}function sd(e,t=[]){if(Object.hasOwnProperty.call(e,`key`)){let n=e.parent.copy,r=V(ld(n,e.key));if(r!==null&&r?.original!==e.original)return null;let i=e.parent.type===3,a=i?Array.from(e.parent.setMap.keys()).indexOf(e.key):e.key;if(!(i&&n.size>a||$u(n,a)))return null;t.push(a)}if(e.parent)return sd(e.parent,t);t.reverse();try{hd(e.copy,t)}catch{return null}return t}function cd(e){return Array.isArray(e)?1:e instanceof Map?2:e instanceof Set?3:0}function ld(e,t){return cd(e)===2?e.get(t):e[t]}function ud(e,t,n){cd(e)===2?e.set(t,n):e[t]=n}function dd(e,t){let n=V(e);return(n?rd(n):e)[t]}function fd(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}function pd(e){if(e)for(;e.finalities.revoke.length>0;)e.finalities.revoke.pop()()}function md(e,t){return t?e:[``].concat(e).map(e=>{let t=`${e}`;return t.indexOf(`/`)===-1&&t.indexOf(`~`)===-1?t:t.replace(/~/g,`~0`).replace(/\//g,`~1`)}).join(`/`)}function hd(e,t){for(let n=0;n<t.length-1;n+=1){let r=t[n];if(e=ld(cd(e)===3?Array.from(e):e,r),typeof e!=`object`)throw Error(`Cannot resolve patch at '${t.join(`/`)}'.`)}return e}function gd(e){let t=Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach(n=>{let r=Reflect.getOwnPropertyDescriptor(e,n);if(r.enumerable&&r.configurable&&r.writable){t[n]=e[n];return}r.writable||(r.writable=!0,r.configurable=!0),(r.get||r.set)&&(r={configurable:!0,writable:!0,enumerable:r.enumerable,value:e[n]}),Reflect.defineProperty(t,n,r)}),t}const _d=Object.prototype.propertyIsEnumerable;function vd(e,t){let n;if(Array.isArray(e))return Array.prototype.concat.call(e);if(e instanceof Set){if(!td(e)){let t=Object.getPrototypeOf(e).constructor;return new t(e.values())}return Set.prototype.difference?Set.prototype.difference.call(e,/* @__PURE__ */ new Set):new Set(e.values())}if(e instanceof Map){if(!nd(e)){let t=Object.getPrototypeOf(e).constructor;return new t(e)}return new Map(e)}if(t?.mark&&(n=t.mark(e,Zu),n!==void 0)&&n!==Zu.mutable){if(n===Zu.immutable)return gd(e);if(typeof n==`function`){if(t.enablePatches||t.enableAutoFreeze)throw Error(`You can't use mark and patches or auto freeze together.`);return n()}throw Error(`Unsupported mark result: ${n}`)}if(typeof e==`object`&&Object.getPrototypeOf(e)===Object.prototype){let t={};return Object.keys(e).forEach(n=>{t[n]=e[n]}),Object.getOwnPropertySymbols(e).forEach(n=>{_d.call(e,n)&&(t[n]=e[n])}),t}throw Error(`Please check mark() to ensure that it is a stable marker draftable function.`)}function yd(e){e.copy||=vd(e.original,e.options)}function bd(e){if(!od(e))return ad(e);if(Array.isArray(e))return e.map(bd);if(e instanceof Map){let t=Array.from(e.entries()).map(([e,t])=>[e,bd(t)]);if(!nd(e)){let n=Object.getPrototypeOf(e).constructor;return new n(t)}return new Map(t)}if(e instanceof Set){let t=Array.from(e).map(bd);if(!td(e)){let n=Object.getPrototypeOf(e).constructor;return new n(t)}return new Set(t)}let t=Object.create(Object.getPrototypeOf(e));for(let n in e)t[n]=bd(e[n]);return t}function xd(e){return id(e)?bd(e):e}function Sd(e){e.assignedMap=e.assignedMap??/* @__PURE__ */ new Map,e.operated||(e.operated=!0,e.parent&&Sd(e.parent))}function Cd(){throw Error(`Cannot modify frozen object`)}function wd(e,t,n,r,i){{n??=/* @__PURE__ */ new WeakMap,r??=[],i??=[];let a=n.has(e)?n.get(e):e;if(r.length>0){let e=r.indexOf(a);if(a&&typeof a==`object`&&e!==-1)throw r[0]===a?Error(`Forbids circular reference`):Error(`Forbids circular reference: ~/${i.slice(0,e).map((e,t)=>{if(typeof e==`symbol`)return`[${e.toString()}]`;let n=r[t];return typeof e==`object`&&(n instanceof Map||n instanceof Set)?Array.from(n.keys()).indexOf(e):e}).join(`/`)}`);r.push(a),i.push(t)}else r.push(a)}if(Object.isFrozen(e)||id(e)){r.pop(),i.pop();return}switch(cd(e)){case 2:for(let[t,a]of e)wd(t,t,n,r,i),wd(a,t,n,r,i);e.set=e.clear=e.delete=Cd;break;case 3:for(let t of e)wd(t,t,n,r,i);e.add=e.clear=e.delete=Cd;break;case 1:Object.freeze(e);let t=0;for(let a of e)wd(a,t,n,r,i),t+=1;break;default:Object.freeze(e),Object.keys(e).forEach(t=>{let a=e[t];wd(a,t,n,r,i)})}r.pop(),i.pop()}function Td(e,t){let n=cd(e);if(n===0)Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)});else if(n===1){let n=0;for(let r of e)t(n,r,e),n+=1}else e.forEach((n,r)=>t(r,n,e))}function Ed(e,t,n){if(id(e)||!od(e,n)||t.has(e)||Object.isFrozen(e))return;let r=e instanceof Set,i=r?/* @__PURE__ */ new Map:void 0;if(t.add(e),Td(e,(a,o)=>{if(id(o)){let t=V(o);yd(t);let n=t.assignedMap?.size||t.operated?t.copy:t.original;ud(r?i:e,a,n)}else Ed(o,t,n)}),i){let t=e,n=Array.from(t);t.clear(),n.forEach(e=>{t.add(i.has(e)?i.get(e):e)})}}function Dd(e,t){let n=e.type===3?e.setMap:e.copy;e.finalities.revoke.length>1&&e.assignedMap.get(t)&&n&&Ed(ld(n,t),e.finalities.handledSet,e.options)}function Od(e){e.type===3&&e.copy&&(e.copy.clear(),e.setMap.forEach(t=>{e.copy.add(ad(t))}))}function kd(e,t,n,r){if(e.operated&&e.assignedMap&&e.assignedMap.size>0&&!e.finalized){if(n&&r){let i=sd(e);i&&t(e,i,n,r)}e.finalized=!0}}function Ad(e,t,n,r){let i=V(n);i&&(i.callbacks||=[],i.callbacks.push((a,o)=>{let s=e.type===3?e.setMap:e.copy;if(fd(ld(s,t),n)){let n=i.original;i.copy&&(n=i.copy),Od(e),kd(e,r,a,o),e.options.enableAutoFreeze&&(e.options.updatedValues=e.options.updatedValues??/* @__PURE__ */ new WeakMap,e.options.updatedValues.set(n,i.original)),ud(s,t,n)}}),e.options.enableAutoFreeze&&i.finalities!==e.finalities&&(e.options.enableAutoFreeze=!1)),od(n,e.options)&&e.finalities.draft.push(()=>{fd(ld(e.type===3?e.setMap:e.copy,t),n)&&Dd(e,t)})}function jd(e,t,n,r,i){let{original:a,assignedMap:o,options:s}=e,c=e.copy;c.length<a.length&&([a,c]=[c,a],[n,r]=[r,n]);for(let e=0;e<a.length;e+=1)if(o.get(e.toString())&&c[e]!==a[e]){let o=md(t.concat([e]),i);n.push({op:B.Replace,path:o,value:xd(c[e])}),r.push({op:B.Replace,path:o,value:xd(a[e])})}for(let e=a.length;e<c.length;e+=1){let r=md(t.concat([e]),i);n.push({op:B.Add,path:r,value:xd(c[e])})}if(a.length<c.length){let{arrayLengthAssignment:e=!0}=s.enablePatches;if(e){let e=md(t.concat([`length`]),i);r.push({op:B.Replace,path:e,value:a.length})}else for(let e=c.length;a.length<e;--e){let n=md(t.concat([e-1]),i);r.push({op:B.Remove,path:n})}}}function Md({original:e,copy:t,assignedMap:n},r,i,a,o){n.forEach((n,s)=>{let c=ld(e,s),l=xd(ld(t,s)),u=n?$u(e,s)?B.Replace:B.Add:B.Remove;if(fd(c,l)&&u===B.Replace)return;let d=md(r.concat(s),o);i.push(u===B.Remove?{op:u,path:d}:{op:u,path:d,value:l}),a.push(u===B.Add?{op:B.Remove,path:d}:u===B.Remove?{op:B.Add,path:d,value:c}:{op:B.Replace,path:d,value:c})})}function Nd({original:e,copy:t},n,r,i,a){let o=0;e.forEach(e=>{if(!t.has(e)){let t=md(n.concat([o]),a);r.push({op:B.Remove,path:t,value:e}),i.unshift({op:B.Add,path:t,value:e})}o+=1}),o=0,t.forEach(t=>{if(!e.has(t)){let e=md(n.concat([o]),a);r.push({op:B.Add,path:e,value:t}),i.unshift({op:B.Remove,path:e,value:t})}o+=1})}function Pd(e,t,n,r){let{pathAsArray:i=!0}=e.options.enablePatches;switch(e.type){case 0:case 2:return Md(e,t,n,r,i);case 1:return jd(e,t,n,r,i);case 3:return Nd(e,t,n,r,i)}}let Fd=!1;const Id=(e,t,n=!1)=>{if(typeof e==`object`&&e&&(!od(e,t)||n)&&!Fd)throw Error(`Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.`)};function Ld(e){Fd=!0;let t;try{t=e()}finally{Fd=!1}return t}const Rd={get size(){return rd(V(this)).size},has(e){return rd(V(this)).has(e)},set(e,t){let n=V(this),r=rd(n);return(!r.has(e)||!fd(r.get(e),t))&&(yd(n),Sd(n),n.assignedMap.set(e,!0),n.copy.set(e,t),Ad(n,e,t,Pd)),this},delete(e){if(!this.has(e))return!1;let t=V(this);return yd(t),Sd(t),t.original.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.copy.delete(e),!0},clear(){let e=V(this);if(this.size){yd(e),Sd(e),e.assignedMap=/* @__PURE__ */ new Map;for(let[t]of e.original)e.assignedMap.set(t,!1);e.copy.clear()}},forEach(e,t){rd(V(this)).forEach((n,r)=>{e.call(t,this.get(r),r,this)})},get(e){var t;let n=V(this),r=rd(n).get(e),i=(t=n.options).mark?.call(t,r,Zu)===Zu.mutable;if(n.options.strict&&Id(r,n.options,i),i||n.finalized||!od(r,n.options)||r!==n.original.get(e))return r;let a=Qu.createDraft({original:r,parentDraft:n,key:e,finalities:n.finalities,options:n.options});return yd(n),n.copy.set(e,a),a},keys(){return rd(V(this)).keys()},values(){let e=this.keys();return{[Xu]:()=>this.values(),next:()=>{let t=e.next();return t.done?t:{done:!1,value:this.get(t.value)}}}},entries(){let e=this.keys();return{[Xu]:()=>this.entries(),next:()=>{let t=e.next();if(t.done)return t;let n=this.get(t.value);return{done:!1,value:[t.value,n]}}}},[Xu](){return this.entries()}},zd=Reflect.ownKeys(Rd),Bd=(e,t,{isValuesIterator:n})=>()=>{var r;let i=t.next();if(i.done)return i;let a=i.value,o=e.setMap.get(a),s=V(o),c=(r=e.options).mark?.call(r,o,Zu)===Zu.mutable;if(e.options.strict&&Id(a,e.options,c),!c&&!s&&od(a,e.options)&&!e.finalized&&e.original.has(a)){let t=Qu.createDraft({original:a,parentDraft:e,key:a,finalities:e.finalities,options:e.options});e.setMap.set(a,t),o=t}else s&&(o=s.proxy);return{done:!1,value:n?o:[o,o]}},Vd={get size(){return V(this).setMap.size},has(e){let t=V(this);if(t.setMap.has(e))return!0;yd(t);let n=V(e);return!!(n&&t.setMap.has(n.original))},add(e){let t=V(this);return this.has(e)||(yd(t),Sd(t),t.assignedMap.set(e,!0),t.setMap.set(e,e),Ad(t,e,e,Pd)),this},delete(e){if(!this.has(e))return!1;let t=V(this);yd(t),Sd(t);let n=V(e);return n&&t.setMap.has(n.original)?(t.assignedMap.set(n.original,!1),t.setMap.delete(n.original)):(!n&&t.setMap.has(e)?t.assignedMap.set(e,!1):t.assignedMap.delete(e),t.setMap.delete(e))},clear(){if(!this.size)return;let e=V(this);yd(e),Sd(e);for(let t of e.original)e.assignedMap.set(t,!1);e.setMap.clear()},values(){let e=V(this);yd(e);let t=e.setMap.keys();return{[Symbol.iterator]:()=>this.values(),next:Bd(e,t,{isValuesIterator:!0})}},entries(){let e=V(this);yd(e);let t=e.setMap.keys();return{[Symbol.iterator]:()=>this.entries(),next:Bd(e,t,{isValuesIterator:!1})}},keys(){return this.values()},[Xu](){return this.values()},forEach(e,t){let n=this.values(),r=n.next();for(;!r.done;)e.call(t,r.value,r.value,this),r=n.next()}};Set.prototype.difference&&Object.assign(Vd,{intersection(e){return Set.prototype.intersection.call(new Set(this.values()),e)},union(e){return Set.prototype.union.call(new Set(this.values()),e)},difference(e){return Set.prototype.difference.call(new Set(this.values()),e)},symmetricDifference(e){return Set.prototype.symmetricDifference.call(new Set(this.values()),e)},isSubsetOf(e){return Set.prototype.isSubsetOf.call(new Set(this.values()),e)},isSupersetOf(e){return Set.prototype.isSupersetOf.call(new Set(this.values()),e)},isDisjointFrom(e){return Set.prototype.isDisjointFrom.call(new Set(this.values()),e)}});const Hd=Reflect.ownKeys(Vd),Ud={get(e,t,n){let r=e.copy?.[t];if(r&&e.finalities.draftsCache.has(r))return r;if(t===Ju)return e;let i;if(e.options.mark){let r=t===`size`&&(e.original instanceof Map||e.original instanceof Set)?Reflect.get(e.original,t):Reflect.get(e.original,t,n);if(i=e.options.mark(r,Zu),i===Zu.mutable)return e.options.strict&&Id(r,e.options,!0),r}let a=rd(e);if(a instanceof Map&&zd.includes(t))return t===`size`?Object.getOwnPropertyDescriptor(Rd,`size`).get.call(e.proxy):Rd[t].bind(e.proxy);if(a instanceof Set&&Hd.includes(t))return t===`size`?Object.getOwnPropertyDescriptor(Vd,`size`).get.call(e.proxy):Vd[t].bind(e.proxy);if(!$u(a,t)){let n=ed(a,t);return n?`value`in n?n.value:n.get?.call(e.proxy):void 0}let o=a[t];if(e.options.strict&&Id(o,e.options),e.finalized||!od(o,e.options))return o;if(o===dd(e.original,t)){if(yd(e),e.copy[t]=Wd({original:e.original[t],parentDraft:e,key:e.type===1?Number(t):t,finalities:e.finalities,options:e.options}),typeof i==`function`){let n=V(e.copy[t]);return yd(n),Sd(n),n.copy}return e.copy[t]}return id(o)&&e.finalities.draftsCache.add(o),o},set(e,t,n){if(e.type===3||e.type===2)throw Error(`Map/Set draft does not support any property assignment.`);let r;if(e.type===1&&t!==`length`&&!(Number.isInteger(r=Number(t))&&r>=0&&(t===0||r===0||String(r)===String(t))))throw Error(`Only supports setting array indices and the 'length' property.`);let i=ed(rd(e),t);if(i?.set)return i.set.call(e.proxy,n),!0;let a=dd(rd(e),t),o=V(a);return o&&fd(o.original,n)?(e.copy[t]=n,e.assignedMap=e.assignedMap??/* @__PURE__ */ new Map,e.assignedMap.set(t,!1),!0):fd(n,a)&&(n!==void 0||$u(e.original,t))?!0:(yd(e),Sd(e),$u(e.original,t)&&fd(n,e.original[t])?e.assignedMap.delete(t):e.assignedMap.set(t,!0),e.copy[t]=n,Ad(e,t,n,Pd),!0)},has(e,t){return t in rd(e)},ownKeys(e){return Reflect.ownKeys(rd(e))},getOwnPropertyDescriptor(e,t){let n=rd(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type!==1||t!==`length`,enumerable:r.enumerable,value:n[t]}},getPrototypeOf(e){return Reflect.getPrototypeOf(e.original)},setPrototypeOf(){throw Error(`Cannot call 'setPrototypeOf()' on drafts`)},defineProperty(){throw Error(`Cannot call 'defineProperty()' on drafts`)},deleteProperty(e,t){return e.type===1?Ud.set.call(this,e,t,void 0,e.proxy):(dd(e.original,t)!==void 0||t in e.original?(yd(e),Sd(e),e.assignedMap.set(t,!1)):(e.assignedMap=e.assignedMap??/* @__PURE__ */ new Map,e.assignedMap.delete(t)),e.copy&&delete e.copy[t],!0)}};function Wd(e){let{original:t,parentDraft:n,key:r,finalities:i,options:a}=e,o=cd(t),s={type:o,finalized:!1,parent:n,original:t,copy:null,proxy:null,finalities:i,options:a,setMap:o===3?new Map(t.entries()):void 0};(r||`key`in e)&&(s.key=r);let{proxy:c,revoke:l}=Proxy.revocable(o===1?Object.assign([],s):s,Ud);if(i.revoke.push(l),s.proxy=c,n){let e=n;e.finalities.draft.push((t,n)=>{var i;let a=V(c),o=e.type===3?e.setMap:e.copy,s=ld(o,r),l=V(s);if(l){let i=l.original;l.operated&&(i=ad(s)),Od(l),kd(l,Pd,t,n),e.options.enableAutoFreeze&&(e.options.updatedValues=e.options.updatedValues??/* @__PURE__ */ new WeakMap,e.options.updatedValues.set(i,l.original)),ud(o,r,i)}(i=a.callbacks)==null||i.forEach(e=>{e(t,n)})})}else{let e=V(c);e.finalities.draft.push((t,n)=>{Od(e),kd(e,Pd,t,n)})}return c}Qu.createDraft=Wd;function Gd(e,t,n,r,i){let a=V(e),o=a?.original??e,s=!!t.length;if(a?.operated)for(;a.finalities.draft.length>0;)a.finalities.draft.pop()(n,r);let c=s?t[0]:a?a.operated?a.copy:a.original:e;return a&&pd(a),i&&wd(c,c,a?.options.updatedValues),[c,n&&s?[{op:B.Replace,path:[],value:t[0]}]:n,r&&s?[{op:B.Replace,path:[],value:o}]:r]}function Kd(e,t){let n={draft:[],revoke:[],handledSet:/* @__PURE__ */ new WeakSet,draftsCache:/* @__PURE__ */ new WeakSet},r,i;t.enablePatches&&(r=[],i=[]);let a=t.mark?.call(t,e,Zu)===Zu.mutable||!od(e,t)?e:Wd({original:e,parentDraft:null,finalities:n,options:t});return[a,(e=[])=>{let[n,o,s]=Gd(a,e,r,i,t.enableAutoFreeze);return t.enablePatches?[n,o,s]:n}]}function qd(e){let{rootDraft:t,value:n,useRawReturn:r=!1,isRoot:i=!0}=e;Td(n,(n,r,i)=>{let a=V(r);if(a&&t&&a.finalities===t.finalities){e.isContainDraft=!0;let t=a.original;if(i instanceof Set){let e=Array.from(i);i.clear(),e.forEach(e=>i.add(n===e?t:e))}else ud(i,n,t)}else typeof r==`object`&&r&&(e.value=r,e.isRoot=!1,qd(e))}),i&&(e.isContainDraft||console.warn(`The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance.`),r&&console.warn(`The return value contains drafts, please don't use 'rawReturn()' to wrap the return value.`))}function Jd(e){let t=V(e);if(!od(e,t?.options))return e;let n=cd(e);if(t&&!t.operated)return t.original;let r;function i(){r=n===2?nd(e)?new Map(e):new(Object.getPrototypeOf(e)).constructor(e):n===3?Array.from(t.setMap.values()):vd(e,t?.options)}if(t){t.finalized=!0;try{i()}finally{t.finalized=!1}}else r=e;if(Td(r,(n,a)=>{if(t&&fd(ld(t.original,n),a))return;let o=Jd(a);o!==a&&(r===e&&i(),ud(r,n,o))}),n===3){let e=t?.original??r;return td(e)?new Set(r):new(Object.getPrototypeOf(e)).constructor(r)}return r}function Yd(e){if(!id(e))throw Error(`current() is only used for Draft, parameter: ${e}`);return Jd(e)}const Xd=(e=>{if(e!==void 0&&Object.prototype.toString.call(e)!==`[object Object]`)throw Error(`Invalid options: ${String(e)}, 'options' should be an object.`);return function t(n,r,i){if(typeof n==`function`&&typeof r!=`function`)return function(e,...i){return t(e,e=>n.call(this,e,...i),r)};let a=n,o=r,s=i;if(typeof r!=`function`&&(s=r),s!==void 0&&Object.prototype.toString.call(s)!==`[object Object]`)throw Error(`Invalid options: ${s}, 'options' should be an object.`);s=Object.assign(Object.assign({},e),s);let c=id(a)?Yd(a):a,l=Array.isArray(s.mark)?((e,t)=>{for(let n of s.mark){if(typeof n!=`function`)throw Error(`Invalid mark: ${n}, 'mark' should be a function.`);let r=n(e,t);if(r)return r}}):s.mark,u=s.enablePatches??!1,d=s.strict??!1,f={enableAutoFreeze:s.enableAutoFreeze??!1,mark:l,strict:d,enablePatches:u};if(!od(c,f)&&typeof c==`object`&&c)throw Error(`Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.`);let[p,m]=Kd(c,f);if(typeof r!=`function`){if(!od(c,f))throw Error(`Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.`);return[p,m]}let h;try{h=o(p)}catch(e){throw pd(V(p)),e}let g=e=>{let t=V(p);if(!id(e)){if(e!==void 0&&!fd(e,p)&&t?.operated)throw Error(`Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.`);let n=e?.[Yu];if(n){let r=n[0];return f.strict&&typeof e==`object`&&e&&qd({rootDraft:t,value:e,useRawReturn:!0}),m([r])}if(e!==void 0)return typeof e==`object`&&e&&qd({rootDraft:t,value:e}),m([e])}if(e===p||e===void 0)return m([]);let n=V(e);if(f===n.options){if(n.operated)throw Error(`Cannot return a modified child draft.`);return m([Yd(e)])}return m([e])};return h instanceof Promise?h.then(g,e=>{throw pd(V(p)),e}):g(h)}})();function Zd(e){let t=V(e);if(!t)throw Error(`original() is only used for a draft, parameter: ${e}`);return t.original}Object.prototype.constructor.toString();function Qd(e){return e}const $d=/([\p{Ll}\d])(\p{Lu})/gu,ef=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,tf=/(\d)\p{Ll}|(\p{L})\d/u,nf=/[^\p{L}\d]+/giu,rf=`$1\0$2`;function af(e){let t=e.trim();t=t.replace($d,rf).replace(ef,rf),t=t.replace(nf,`\0`);let n=0,r=t.length;for(;t.charAt(n)===`\0`;)n++;if(n===r)return[];for(;t.charAt(r-1)===`\0`;)r--;return t.slice(n,r).split(/\0/g)}function of(e){let t=af(e);for(let e=0;e<t.length;e++){let n=t[e],r=tf.exec(n);if(r){let i=r.index+(r[1]??r[2]).length;t.splice(e,1,n.slice(0,i),n.slice(i))}}return t}function sf(e,t){let[n,r,i]=lf(e,t);return n+r.map(cf(t?.locale)).join(t?.delimiter??`_`)+i}function cf(e){return e===!1?e=>e.toUpperCase():t=>t.toLocaleUpperCase(e)}function lf(e,t={}){let n=t.split??(t.separateNumbers?of:af),r=t.prefixCharacters??``,i=t.suffixCharacters??``,a=0,o=e.length;for(;a<e.length;){let t=e.charAt(a);if(!r.includes(t))break;a++}for(;o>a;){let t=o-1,n=e.charAt(t);if(!i.includes(n))break;o=t}return[e.slice(0,a),n(e.slice(a,o)),e.slice(o)]}const uf=e=>e!=null;cu().refine(e=>uf(e));const df=Cu([`REDO`]),ff=Cu([`SET_NAME`]),pf=Cu([`SET_PREFERRED_EDITOR`]),mf=Cu([`SET_SLUG`]),hf=Cu([`UNDO`]);function gf(){return F()}function _f(){return _u([yf(),xf(),Cf(),Tf(),Df()])}function vf(){return R({count:nu()})}function yf(){return R({id:F(),timestampUtcMs:F().datetime(),input:vf(),type:df,scope:gf()})}function bf(){return R({name:F()})}function xf(){return R({id:F(),timestampUtcMs:F().datetime(),input:bf(),type:ff,scope:z(`global`)})}function Sf(){return R({preferredEditor:F().nullable()})}function Cf(){return R({id:F(),timestampUtcMs:F().datetime(),input:Sf(),type:pf,scope:z(`header`)})}function wf(){return R({slug:F().min(1)})}function Tf(){return R({id:F(),timestampUtcMs:F().datetime(),input:wf(),type:mf,scope:z(`header`)})}function Ef(){return R({count:nu()})}function Df(){return R({id:F(),timestampUtcMs:F().datetime(),input:Ef(),type:hf,scope:gf()})}function Of(){return R({__typename:z(`AddChangeLogItemInput`).optional(),content:F(),id:F(),insertBefore:F().nullable()})}function kf(){return R({description:F().nullish(),id:F(),name:F()})}function Af(){return R({errorCode:F().nullish(),errorDescription:F().nullish(),errorName:F().nullish(),errorTemplate:F().nullish(),id:F(),operationId:F()})}function jf(){return R({example:F(),id:F(),operationId:F()})}function Mf(){return R({description:F().nullish(),id:F(),moduleId:F(),name:F(),reducer:F().nullish(),schema:F().nullish(),template:F().nullish(),scope:gf().nullish()})}function Nf(){return R({scope:F(),example:F(),id:F(),insertBefore:F().nullish()})}function Pf(){return R({__typename:z(`Author`).optional(),name:F(),website:F().nullable()})}function Ff(){return R({__typename:z(`CodeExample`).optional(),id:F(),value:F()})}function If(){return R({__typename:z(`DeleteChangeLogItemInput`).optional(),id:F()})}function Lf(){return R({id:F()})}function Rf(){return R({id:F()})}function zf(){return R({id:F()})}function Bf(){return R({id:F()})}function Vf(){return R({scope:F(),id:F()})}function Hf(){return R({__typename:z(`DocumentModelGlobalState`).optional(),id:F(),name:F(),author:Pf(),extension:F(),description:F(),specifications:L(Uf())})}function Uf(){return R({__typename:z(`DocumentSpecification`).optional(),state:xp(),modules:L(Wf()),version:nu().int(),changeLog:L(F())})}function Wf(){return R({__typename:z(`ModuleSpecification`).optional(),id:F(),name:F(),description:F().nullable(),operations:L(Kf())})}function Gf(){return R({newModuleId:F(),operationId:F()})}function Kf(){return R({__typename:z(`OperationSpecification`).optional(),id:F(),name:F().nullable(),description:F().nullable(),schema:F().nullable(),template:F().nullable(),reducer:F().nullable(),errors:L(qf()),examples:L(Ff()),scope:gf()})}function qf(){return R({__typename:z(`OperationErrorSpecification`).optional(),id:F(),name:F().nullable(),code:F().nullable(),description:F().nullable(),template:F().nullable()})}function Jf(){return R({__typename:z(`ReorderChangeLogItemsInput`).optional(),order:L(F())})}function Yf(){return R({moduleId:F(),order:L(F())})}function Xf(){return R({order:L(F())})}function Zf(){return R({operationId:F(),order:L(F())})}function Qf(){return R({operationId:F(),order:L(F())})}function $f(){return R({scope:F(),order:L(F())})}function ep(){return R({authorName:F()})}function tp(){return R({authorWebsite:F()})}function np(){return R({scope:F(),initialValue:F()})}function rp(){return R({description:F()})}function ip(){return R({extension:F()})}function ap(){return R({id:F()})}function op(){return R({name:F()})}function sp(){return R({description:F().nullish(),id:F()})}function cp(){return R({id:F(),name:F().nullish()})}function lp(){return R({description:F().nullish(),id:F()})}function up(){return R({errorCode:F().nullish(),id:F()})}function dp(){return R({errorDescription:F().nullish(),id:F()})}function fp(){return R({errorName:F().nullish(),id:F()})}function pp(){return R({errorTemplate:F().nullish(),id:F()})}function mp(){return R({id:F(),name:F().nullish()})}function hp(){return R({id:F(),scope:gf()})}function gp(){return R({id:F(),reducer:F().nullish()})}function _p(){return R({id:F(),schema:F().nullish()})}function vp(){return R({id:F(),template:F().nullish()})}function yp(){return R({scope:F(),schema:F()})}function bp(){return R({__typename:z(`State`).optional(),schema:F(),examples:L(Ff()),initialValue:F()})}function xp(){return R({local:bp(),global:bp()})}function Sp(){return R({__typename:z(`UpdateChangeLogItemInput`).optional(),id:F(),newContent:F()})}function Cp(){return R({example:F(),id:F()})}function wp(){return R({scope:F(),id:F(),newExample:F()})}const Tp=R({id:F(),name:F(),documentTypes:L(F()).optional()}),Ep=L(Tp).optional(),Dp=L(Tp.extend({version:F().optional(),description:F().optional(),bundle:F().optional(),descriptor:F().optional()})).optional(),Op=R({name:F().optional(),url:F().optional()}),kp=_u([z(`var`),z(`secret`)]),Ap=R({name:F(),type:kp,description:F().optional(),required:ou().optional(),default:F().optional()}),jp=_u([F(),hu({source:F(),flags:F().optional()}).refine(e=>{try{return new RegExp(e.source,e.flags),!0}catch{return!1}},{message:`source/flags do not compile to a valid RegExp`})]),Mp=hu({urlPattern:jp,handler:Cu([`CacheFirst`,`CacheOnly`,`NetworkFirst`,`NetworkOnly`,`StaleWhileRevalidate`]),method:Cu([`GET`,`POST`,`PUT`,`DELETE`,`HEAD`,`PATCH`]).optional(),options:hu({cacheName:F().optional(),networkTimeoutSeconds:nu().optional(),expiration:hu({maxEntries:nu().optional(),maxAgeSeconds:nu().optional()}).optional(),cacheableResponse:hu({statuses:L(nu()).optional(),headers:xu(F(),F()).optional()}).optional()}).optional()}),Np=hu({src:F(),sizes:F().optional(),type:F().optional(),purpose:F().optional()}),Pp=hu({accept:xu(F(),L(F().regex(/^\./,`file extensions must start with '.'`))),icons:L(Np).optional(),launch_type:Cu([`single-client`,`multiple-clients`]).optional()}),Fp=hu({manifest:hu({name:F().optional(),short_name:F().optional(),description:F().optional(),theme_color:F().optional(),background_color:F().optional(),display:Cu([`fullscreen`,`standalone`,`minimal-ui`,`browser`]).optional(),start_url:F().optional(),scope:F().optional(),icons:L(Np).optional(),file_handlers:L(Pp).optional(),launch_handler:hu({client_mode:Cu([`auto`,`focus-existing`,`navigate-existing`,`navigate-new`])}).optional()}).optional(),globPatterns:L(F()).optional(),globIgnores:L(F()).optional(),maximumFileSizeToCacheInBytes:nu().optional(),runtimeCaching:L(Mp).optional(),navigateFallbackDenylist:L(jp).optional()});R({name:F(),description:F().optional(),category:F().optional(),image:F().optional(),publisher:Op.optional(),documentModels:Ep,apps:Ep,editors:Ep,processors:Ep,subgraphs:Ep,pieces:Dp,externalDependencies:xu(F(),F()).optional(),config:L(Ap).optional(),pwa:Fp.optional(),connectRoutes:ou().optional()});const Ip=(e=1,t=`global`)=>H(`UNDO`,{count:e},void 0,Ef,t),Lp=(e=1,t=`global`)=>H(`REDO`,{count:e},void 0,vf,t),Rp=(e=`global`)=>H(`NOOP`,{},void 0,void 0,e);function H(e,t,n,r,i=`global`){if(!e)throw Error(`Empty action type`);if(typeof e!=`string`)throw Error(`Invalid action type: ${JSON.stringify(e)}`);let a={id:me(),timestampUtcMs:i===`auth`?_e():(/* @__PURE__ */ new Date()).toISOString(),type:e,input:t,scope:i};try{r?.().parse(a.input)}catch(e){throw e instanceof ml?new fn(e.issues):new dn(e)}return a}const zp=e=>({id:e.id,timestampUtcMs:e.timestampUtcMs,type:e.type,input:e.input,scope:e.scope,context:e.context}),Bp=(e,t,n,r)=>({...e,action:e,id:de(r.documentId,r.scope,r.branch,e.id),timestampUtcMs:e.timestampUtcMs,hash:``,error:void 0,index:t,skip:n}),Vp=(e,t,n,r)=>{let i=de(r.documentId,r.scope,r.branch,e.action.id);return{...e,hash:``,error:void 0,index:t,skip:n,id:i}},Hp=e=>H(`SET_NAME`,typeof e==`string`?{name:e}:e,void 0,bf,`global`),Up=e=>H(`SET_PREFERRED_EDITOR`,typeof e==`object`&&e?e:{preferredEditor:e},void 0,Sf,`header`),Wp=e=>H(`SET_SLUG`,{slug:e},void 0,wf,`header`),Gp=e=>H(`SET_MODEL_NAME`,{...e},void 0,op,`global`),Kp=e=>H(`SET_MODEL_ID`,{...e},void 0,ap,`global`),qp=e=>H(`SET_MODEL_EXTENSION`,{...e},void 0,ip,`global`),Jp=e=>H(`SET_MODEL_DESCRIPTION`,{...e},void 0,rp,`global`),Yp=e=>H(`SET_AUTHOR_NAME`,{...e},void 0,ep,`global`),Xp=e=>H(`SET_AUTHOR_WEBSITE`,{...e},void 0,tp,`global`),Zp=e=>H(`ADD_MODULE`,{...e},void 0,kf,`global`),Qp=e=>H(`SET_MODULE_NAME`,{...e},void 0,cp,`global`),$p=e=>H(`SET_MODULE_DESCRIPTION`,{...e},void 0,sp,`global`),em=e=>H(`DELETE_MODULE`,{...e},void 0,Lf,`global`),tm=e=>H(`REORDER_MODULES`,{...e},void 0,Xf,`global`),nm=e=>H(`ADD_OPERATION`,{...e},void 0,Mf,`global`),rm=e=>H(`SET_OPERATION_NAME`,{...e},void 0,mp,`global`),im=e=>H(`SET_OPERATION_SCOPE`,{...e},void 0,hp,`global`),am=e=>H(`SET_OPERATION_SCHEMA`,{...e},void 0,_p,`global`),om=e=>H(`SET_OPERATION_DESCRIPTION`,{...e},void 0,lp,`global`),sm=e=>H(`SET_OPERATION_TEMPLATE`,{...e},void 0,vp,`global`),cm=e=>H(`SET_OPERATION_REDUCER`,{...e},void 0,gp,`global`),lm=e=>H(`MOVE_OPERATION`,{...e},void 0,Gf,`global`),um=e=>H(`DELETE_OPERATION`,{...e},void 0,Bf,`global`),dm=e=>H(`REORDER_MODULE_OPERATIONS`,{...e},void 0,Yf,`global`),fm=e=>H(`ADD_OPERATION_ERROR`,{...e},void 0,Af,`global`),pm=e=>H(`SET_OPERATION_ERROR_CODE`,{...e},void 0,up,`global`),mm=e=>H(`SET_OPERATION_ERROR_NAME`,{...e},void 0,fp,`global`),hm=e=>H(`SET_OPERATION_ERROR_DESCRIPTION`,{...e},void 0,dp,`global`),gm=e=>H(`SET_OPERATION_ERROR_TEMPLATE`,{...e},void 0,pp,`global`),_m=e=>H(`DELETE_OPERATION_ERROR`,{...e},void 0,Rf,`global`),vm=e=>H(`REORDER_OPERATION_ERRORS`,{...e},void 0,Zf,`global`),ym=e=>H(`ADD_OPERATION_EXAMPLE`,{...e},void 0,jf,`global`),bm=e=>H(`UPDATE_OPERATION_EXAMPLE`,{...e},void 0,Cp,`global`),xm=e=>H(`DELETE_OPERATION_EXAMPLE`,{...e},void 0,zf,`global`),Sm=e=>H(`REORDER_OPERATION_EXAMPLES`,{...e},void 0,Qf,`global`),Cm=e=>H(`SET_STATE_SCHEMA`,{...e},void 0,yp,`global`),wm=e=>H(`SET_INITIAL_STATE`,{...e},void 0,np,`global`),Tm=e=>H(`ADD_STATE_EXAMPLE`,{...e},void 0,Nf,`global`),Em=e=>H(`UPDATE_STATE_EXAMPLE`,{...e},void 0,wp,`global`),Dm=e=>H(`DELETE_STATE_EXAMPLE`,{...e},void 0,Vf,`global`),Om=e=>H(`REORDER_STATE_EXAMPLES`,{...e},void 0,$f,`global`),km=e=>H(`ADD_CHANGE_LOG_ITEM`,{...e},void 0,Of,`global`),Am=e=>H(`UPDATE_CHANGE_LOG_ITEM`,{...e},void 0,Sp,`global`),jm=e=>H(`DELETE_CHANGE_LOG_ITEM`,{...e},void 0,If,`global`),Mm=e=>H(`REORDER_CHANGE_LOG_ITEMS`,{...e},void 0,Jf,`global`),Nm=()=>H(`RELEASE_NEW_VERSION`,{},void 0,void 0,`global`),Pm={setName:Hp,setPreferredEditor:Up,setSlug:Wp,undo:Ip,redo:Lp,noop:Rp},Fm={setModelName:Gp,setModelId:Kp,setModelExtension:qp,setModelDescription:Jp,setAuthorName:Yp,setAuthorWebsite:Xp,addModule:Zp,setModuleName:Qp,setModuleDescription:$p,deleteModule:em,reorderModules:tm,addOperation:nm,setOperationName:rm,setOperationScope:im,setOperationSchema:am,setOperationDescription:om,setOperationTemplate:sm,setOperationReducer:cm,moveOperation:lm,deleteOperation:um,reorderModuleOperations:dm,addOperationError:fm,setOperationErrorCode:pm,setOperationErrorName:mm,setOperationErrorDescription:hm,setOperationErrorTemplate:gm,deleteOperationError:_m,reorderOperationErrors:vm,addOperationExample:ym,updateOperationExample:bm,deleteOperationExample:xm,reorderOperationExamples:Sm,setStateSchema:Cm,setInitialState:wm,addStateExample:Tm,updateStateExample:Em,deleteStateExample:Dm,reorderStateExamples:Om,addChangeLogItem:km,updateChangeLogItem:Am,deleteChangeLogItem:jm,reorderChangeLogItems:Mm,releaseNewVersion:Nm};({...Pm,...Fm});var Im=class extends Error{grantId;constructor(e,t){super(`Invalid grant "${e}": ${t}`),this.name=`InvalidGrantError`,this.grantId=e}},Lm=class extends Error{grantId;constructor(e){super(`Grant "${e}" uses a group principal on a group document: a group's auth scope cannot reference other groups`),this.name=`GroupPrincipalNotAllowedError`,this.grantId=e}},Rm=class extends Error{grantId;constructor(e){super(`Change to grant "${e}" would leave no reachable grant permitting execute on the auth scope: a policy with no creator must always retain one`),this.name=`AuthAdministrationLockoutError`,this.grantId=e}},zm=class extends Error{constructor(){super(`Initial grants include no reachable grant permitting execute on the auth scope: a policy with no creator must always include one`),this.name=`AuthAdministrationMissingError`}};const Bm=/* @__PURE__ */ new Set([`id`,`description`,`effect`,`principal`,`capability`,`where`]),Vm=/* @__PURE__ */ new Set([`anyone`,`address`,`group`,`match`]),Hm=/* @__PURE__ */ new Set([`eq`,`ne`,`lt`,`lte`,`gt`,`gte`]);function Um(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Wm(e,t,n){if(--n.nodes,n.nodes<0)return`condition exceeds 100 nodes`;if(!Um(e))return`operand must be an object`;let r=Object.keys(e);if(r.length!==1)return`operand must have exactly one of attr or lit`;if(r[0]===`attr`){let n=e.attr;if(typeof n!=`string`||n.length===0)return`attr must be a non-empty string`;if(t!==void 0&&t!==`*`&&n.startsWith(`doc.`)){let e=n.split(`.`)[1]??``;if(e!==t)return`condition path "${n}" reads scope "${e}" but the capability covers only scope "${t}"`}return null}if(r[0]===`lit`){let t=e.lit;return t!==null&&typeof t!=`string`&&typeof t!=`number`&&typeof t!=`boolean`?`lit must be a string, number, boolean, or null`:typeof t==`number`&&!Number.isFinite(t)?`lit must be a finite number`:typeof t==`number`&&Object.is(t,-0)?`lit must not be negative zero`:null}return`unknown operand kind "${r[0]}"`}function Gm(e,t,n,r){if(n>10)return`condition exceeds depth 10`;if(--r.nodes,r.nodes<0)return`condition exceeds 100 nodes`;if(!Um(e))return`condition must be an object`;let i=Object.keys(e);if(i.length!==1)return`condition must have exactly one operator`;let a=i[0],o=e[a];if(Hm.has(a)){if(!Array.isArray(o)||o.length!==2)return`${a} requires a pair of operands`;for(let e of o){let n=Wm(e,t,r);if(n!==null)return n}return null}if(a===`in`||a===`notIn`){if(!Array.isArray(o)||o.length!==2||!Array.isArray(o[1]))return`${a} requires an operand and an operand list`;let e=Wm(o[0],t,r);if(e!==null)return e;for(let e of o[1]){let n=Wm(e,t,r);if(n!==null)return n}return null}if(a===`exists`)return Wm(o,t,r);if(a===`and`||a===`or`){if(!Array.isArray(o))return`${a} requires a condition list`;for(let e of o){let i=Gm(e,t,n+1,r);if(i!==null)return i}return null}return a===`not`?Gm(o,t,n+1,r):`unknown condition operator "${a}"`}function Km(e,t){if(!Um(e))return`principal must be an object`;let n=Object.keys(e);if(n.length!==1||!Vm.has(n[0]))return`principal must have exactly one of anyone, address, group, or match`;let r=n[0];if(r===`anyone`&&e.anyone!==!0)return`anyone must be true`;if(r===`address`){let t=e.address;if(typeof t!=`string`||t.length===0)return`address must be a non-empty string`}if(r===`group`){let t=e.group;if(typeof t!=`string`||t.length===0)return`group must be a non-empty string`}return r===`match`?Gm(e.match,t,1,{nodes:100}):null}function qm(e){if(!Um(e))return`capability must be an object`;let t=e.can;if(t!==`read`&&t!==`execute`)return`capability.can must be read or execute`;let n=t===`execute`?[`can`,`scope`,`operation`]:[`can`,`scope`],r=Object.keys(e).filter(e=>!n.includes(e)).sort();if(r.length>0)return`unknown capability key "${r[0]}"`;if(e.scope!==void 0&&(typeof e.scope!=`string`||e.scope.length===0))return`capability.scope must be a non-empty string`;if(t===`execute`&&e.operation!==void 0){let t=e.operation;if(!Array.isArray(t))return`capability.operation must be an array`;if(t.length>100)return`capability.operation exceeds 100 entries`;for(let e of t)if(typeof e!=`string`||e.length===0)return`capability.operation entries must be non-empty strings`}return null}function Jm(e){if(!Um(e))return`grant must be an object`;let t=Object.keys(e).filter(e=>!Bm.has(e)).sort();if(t.length>0)return`unknown grant key "${t[0]}"`;if(typeof e.id!=`string`||e.id.length===0)return`id must be a non-empty string`;if(typeof e.description!=`string`)return`description must be a string`;if(e.effect!==`allow`&&e.effect!==`deny`)return`effect must be allow or deny`;let n=e.capability,r=qm(n);if(r!==null)return r;let i=n.scope,a=Km(e.principal,i);return a===null?e.where===void 0?null:Gm(e.where,i,1,{nodes:100}):a}function Ym(e,t){let n=Um(e)&&typeof e.id==`string`?e.id:``,r=Jm(e);if(r!==null)throw new Im(n,r);if(t===`powerhouse/reactor-group`&&`group`in e.principal)throw new Lm(n)}function Xm(e,t,n){if(e.length>100)throw new Im(``,`policy exceeds 100 grants`);for(let n of e)Ym(n,t);if(n===void 0&&!$m(e))throw new zm}function Zm(e,t,n,r){Ym(e,n);let i=t.some(t=>t.id===e.id);if(!i&&t.length>=100)throw new Im(e.id,`policy exceeds 100 grants`);eh(r,t,i?t.map(t=>t.id===e.id?e:t):[...t,e],e.id)}const Qm={verb:`execute`,scope:`auth`,operation:`SET_GRANT`};function $m(e){let t=/* @__PURE__ */ new Set;for(let n=e.length-1;n>=0;--n){let r=e[n];if(r.where!==void 0||!nh(r,Qm))continue;let i=r.effect===`allow`;if(`anyone`in r.principal)return i;if(!(`address`in r.principal))continue;let a=r.principal.address.toLowerCase();if(!t.has(a)){if(i)return!0;t.add(a)}}return!1}function eh(e,t,n,r){if(e===void 0&&$m(t)&&!$m(n))throw new Rm(r)}function th(e,t){return e===void 0||e===`*`||e===t}function nh(e,t){return rh(e.capability,t)?!0:t.verb===`read`&&e.effect===`allow`&&e.capability.can===`execute`&&th(e.capability.scope,t.scope)}function rh(e,t){return e.can!==t.verb||!th(e.scope,t.scope)?!1:e.can!==`execute`||e.operation===void 0||t.operation!==void 0&&e.operation.includes(t.operation)}function ih(){return{version:0,grants:[]}}function ah(e){return{...ih(),...e}}function oh(e){return{...e,auth:ah(e.auth)}}function sh(e){if(!Um(e))throw new dn({input:`must be an object`})}function ch(e,t){return{...e,state:{...e.state,auth:{...e.state.auth,grants:t}}}}const lh=[128,36];function uh(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function dh(e,t){if(!e?.x||!e.y||!t||!t.startsWith(`did:key:z`))return!1;let n=le(t.slice(9));if(!n||n.length!==35||n[0]!==lh[0]||n[1]!==lh[1])return!1;let r=n[2];if(r!==2&&r!==3)return!1;let i=n.subarray(3,35),a=ue(e.x),o=ue(e.y);return a.length!==32||o.length!==32||!uh(i,a)?!1:(o[31]&1)==1==(r===3)}function fh(e,t){sh(t.input);let{version:n,grants:r}=t.input;if(!Number.isInteger(n)||n<1)throw new _n(e.header.id,n);if(e.state.auth.version!==0)throw new hn(e.header.id);if(!Array.isArray(r))throw new dn({grants:`must be an array`});let i=e.header.sig.publicKey,a=t.context?.signer?.app.key,o=!!(i.kty||i.x||i.y);if(o&&!dh(i,a))throw new gn(e.header.id);let s=o?a:void 0;return Xm(r,e.header.documentType,s),{...e,state:{...e.state,auth:ah(s?{version:n,grants:r,creator:s}:{version:n,grants:r})}}}function ph(e,t){sh(t.input);let{grant:n}=t.input,r=e.state.auth.grants;return Zm(n,r,e.header.documentType,e.state.auth.creator),ch(e,r.some(e=>e.id===n.id)?r.map(e=>e.id===n.id?n:e):[...r,n])}function mh(e,t){sh(t.input);let{id:n}=t.input,{grants:r,creator:i}=e.state.auth;if(!r.some(e=>e.id===n))throw new vn(n);let a=r.filter(e=>e.id!==n);return eh(i,r,a,n),ch(e,a)}function hh(e,t){sh(t.input);let{id:n,index:r}=t.input,{grants:i,creator:a}=e.state.auth,o=i.findIndex(e=>e.id===n);if(o===-1)throw new vn(n);let s=[...i],[c]=s.splice(o,1),l=Math.max(0,Math.min(r,s.length));return s.splice(l,0,c),eh(a,i,s,n),ch(e,s)}function gh(e,t){switch(t.type){case`INITIALIZE_AUTH`:return fh(e,t);case`SET_GRANT`:return ph(e,t);case`REMOVE_GRANT`:return mh(e,t);case`MOVE_GRANT`:return hh(e,t);default:return e}}function _h(e){if(e.scope===`auth`&&[`UNDO`,`REDO`].includes(e.type))throw new yn(e.type)}function vh(e){return e.deniedReason!==void 0}const yh=R({id:F(),name:F(),createdAtUtcIso:F(),lastModifiedAtUtcIso:F(),documentType:F()}),bh=R({global:uu()}),xh=yh.extend({documentType:z(`powerhouse/document-model`)}),Sh=bh.extend({global:Hf()});R({header:xh,state:Sh,initialState:Sh});function Ch(e){return[`SET_NAME`,`SET_PREFERRED_EDITOR`,`SET_SLUG`,`UNDO`,`REDO`].includes(e.type)}function wh(e){let t=[],n=e.length-1;for(;n>-1;){t.unshift(e[n]);let r=(e[n]?.index||0)-(e[n]?.skip||0)-1,i=n-1;for(;i>-1&&(e[i]?.index||0)>r;)i--;n=i}return t}function Th(e){return e.slice().sort((e,t)=>e.skip-t.skip).sort((e,t)=>e.index-t.index)}function Eh(e){if(e.length<1)return-1;let t=wh(e),n=(t[t.length-1]?.skip||0)+1;return t.length>1&&(n+=t[t.length-2]?.skip||0),(t[t.length-1]?.index||-1)<n?-1:n}function Dh(e){return{id:me(),timestampUtcMs:(/* @__PURE__ */ new Date()).toISOString(),type:`NOOP`,input:{},scope:e}}function Oh(e,t){return{...e,header:{...e.header,name:t.name}}}function kh(e,t){let n=e.header.meta??{};if(t.preferredEditor)return{...e,header:{...e.header,meta:{...n,preferredEditor:t.preferredEditor}}};let{preferredEditor:r,...i}=n;return{...e,header:{...e.header,meta:i}}}function Ah(e,t){return{...e,header:{...e.header,slug:t.slug}}}function jh(e,t,n){let{scope:r}=t;return Xd({document:e,action:t,skip:n,reuseLastOperationIndex:!1},t=>{let n=Th([...e.operations[r]]);t.action=Dh(r);let i=n.at(-1),a=i?.index??-1,o=i?.action.type!==`NOOP`;if(o?a+=1:t.reuseLastOperationIndex=!0,t.skip=Eh(o?[...n,{index:a,skip:0}]:n),i&&t.skip>i.skip+1&&(t.skip+=1),t.skip<0)throw Error(`Cannot undo: you can't undo more operations than the ones in the scope history`)})}function Mh(e,t,n){let{scope:r}=t;return Xd({document:e,action:t,skip:n,reuseLastOperationIndex:!1},t=>{let n=Th([...e.operations[r]||[]]),i=n.filter(e=>e.action.type!==`NOOP`),a=0;for(let e=n.length-1;e>=0&&n[e].action.type===`NOOP`;e--)a++;if(i.length<=a)throw Error(`Cannot undo: no more operations to undo in scope history`);t.action=Dh(r),t.skip=1})}function Nh(e,t,n){let{scope:r,input:i}=t;return Xd({document:e,action:t,skip:n,reuseLastOperationIndex:!1},e=>{if(e.skip>0)throw Error(`Cannot redo: skip value from reducer cannot be used with REDO action`);let t=typeof i==`object`&&i&&`count`in i?i.count:i;if(typeof t!=`number`||t>1)throw Error(`Cannot redo: you can only redo one operation at a time`);if(typeof t!=`number`||t<1)throw Error(`Invalid REDO action: invalid redo input value`);if(e.document.clipboard.length<1)throw Error(`Cannot redo: no operations in the clipboard`);let n=e.document.clipboard.findLastIndex(e=>e.action.scope===r);if(n<0)throw Error(`Cannot redo: no operations in clipboard for scope "${r}"`);let a=e.document.clipboard.splice(n,1)[0];e.action=Qd({type:a.action.type,scope:a.action.scope,input:a.action.input})})}function Ph(e,t){let n=_f().parse(t);switch(n.type){case`SET_NAME`:return Oh(e,n.input);case`SET_PREFERRED_EDITOR`:return kh(e,n.input);case`SET_SLUG`:return Ah(e,n.input);default:return e}}function Fh(e){return wh(Th([...e]))}function Ih(e,t){return e.action.type===`RETRACT`||t(e.action.id)}function Lh(e,t){return e.skip>0||Ih(e,t)}function Rh(e){return zh(e.action)}function zh(e){if(e.type!==`RETRACT`)return;let t=e.input;return typeof t?.target==`string`?t.target:void 0}function Bh(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set;for(let r of e){let e=r.action.id;t.has(e)&&n.add(e),t.set(e,r)}let r=/* @__PURE__ */ new Map;for(let i of e){if(vh(i)||n.has(i.action.id))continue;let e=Rh(i);e!==void 0&&e!==i.action.id&&t.has(e)&&!Ch(t.get(e).action)&&r.set(i.action.id,e)}for(let e of Vh(r))r.delete(e);let i=/* @__PURE__ */ new Map;for(let e of r.values())i.set(e,(i.get(e)??0)+1);let a=/* @__PURE__ */ new Set,o=[...t.keys()].filter(e=>!i.has(e));for(;o.length>0;){let e=o.pop(),t=r.get(e);if(t===void 0)continue;a.has(e)||a.add(t);let n=i.get(t)-1;i.set(t,n),n===0&&o.push(t)}return a}function Vh(e){let t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new Set;for(let r of e.keys()){if(n.has(r))continue;let i=[],a=/* @__PURE__ */ new Set,o=r;for(;o!==void 0&&!n.has(o)&&!a.has(o);)i.push(o),a.add(o),o=e.get(o);if(o!==void 0&&a.has(o))for(let e=i.indexOf(o);e<i.length;e++)t.add(i[e]);for(let e of i)n.add(e)}return t}function Hh(e){let t=Fh(e),n=Bh(t);return t.filter(e=>!n.has(e.action.id)&&e.action.type!==`RETRACT`&&!vh(e))}function Uh(e,t,n){return qh(t.action.scope),Yh(e,t,Jh(t,n))}function Wh(e,t){let n=new Set(Hh(e)),r=/* @__PURE__ */ new Set;return{applied:r,advance(e,i,a){let o=e;for(let e of i){if(!n.has(e))continue;qh(e.action.scope);let i=Jh(e,a);try{o=Yh(o,e,i),r.add(e.action.id)}catch(n){t?.(e,n)}}return o}}}function Gh(e,t){qh(t);let n=e.initialState[t];return{...e,state:{...e.state,[t]:n}}}function Kh(e,t,n,r=t.at(0)?.action.scope,i){if(r===void 0)return{document:e,applied:/* @__PURE__ */ new Set};let a=Wh(t,i);return{document:a.advance(Gh(e,r),Fh(t),n),applied:a.applied}}function qh(e){if(Qt.has(e))throw Error(`Base-reducer 3 does not derive the ${e} scope`)}function Jh(e,t){let n=e.action;if(!(n.type===`NOOP`||n.type===`RETRACT`||Ch(n)))return t(e)}function Yh(e,t,n){let r=t.action;return Ch(r)?Ph(e,r):n===void 0?e:Xd(e,e=>{let t=n(e.state,r);t&&Ld(()=>{e.state=Qd(t)})})}function Xh(e,t){return!e.some(e=>Lh(e,t.named))}function Zh(e){return[`UNDO`,`REDO`].includes(e.type)}function Qh(e){return e.type===`UNDO`}function $h(e,t=`global`){let n=m(e.state[t]||``);return re(n)}function eg(e){let t=[],n=0;for(let r=e.length-1;r>=0;r--){let i=e[r];`action`in i&&i.action.type===`NOOP`&&i.skip>0?(n++,t.unshift(i)):n>0?n--:t.unshift(i)}return t}const tg=e=>e;function ng(e,t,n=t.action.scope){return{...e,operations:{...e.operations,[n]:[...e.operations[n]??[],t]}}}function rg(e,t,n){let r=Jt(e);if(r===void 0)throw new pn(t,n);return r}function ig(e,t,n,r,i,a,o){return vh(t)?hg(ng(e,t),t.action.scope,t.timestampUtcMs):n(e,t.action,r,{ignoreSkipOperations:!0,checkHashes:i,skipIndexValidation:a,protocolVersion:o,replayOptions:{operation:t}})}function ag(e){let t=-1;for(let n of e){if(n.index-n.skip>t+1)throw Error(`Missing operations: expected ${t+1} with skip 0 or equivalent, got index ${n.index} with skip ${n.skip}`);t=n.index}}function og(e,t,n,r,i,a,o,s){let c,l=t;for(let[u,d=[]]of Object.entries(n))if(d.length!==0){if(!ln(e,u)){for(let e of d)l=ig(l,e,r,i,a,o,s);continue}if(o||ag(d),l=hg(sg(l,u,d),u,d.at(-1).timestampUtcMs),c===void 0){let e=rg(r,t.header.documentType);c=()=>e}l=Kh(l,d,c,u).document}return l}function sg(e,t,n){return{...e,operations:{...e.operations,[t]:[...e.operations[t]??[],...n]}}}function cg(e,t,n,r,i,a={},o){let{checkHashes:s=!0,reuseOperationResultingState:c,operationResultingStateParser:l=lg,skipIndexValidation:u,protocolVersion:d}=o||{},f=r.protocolVersions?.[`base-reducer`],p=typeof f==`number`&&!en(f)?d:void 0,m=p===void 0?an(r):tn(p),h=cn(m),g=oh(e),_=g,v=[],y=/* @__PURE__ */ new Set([...Object.keys(t),`global`,`local`]),b={};for(let e of y)b[e]=[];if(c&&!h)for(let[e,n]of Object.entries(t)){if(!n)continue;let t=n.findLastIndex(e=>!!e.resultingState);if(t<0){v.push(...n);continue}let r=n[t];if(r&&r.resultingState)try{let i=l(r.resultingState);_={..._,[e]:i};let a=b[e];a&&a.push(...n.slice(0,t+1)),v.push(...n.slice(t+1))}catch{v.push(...n)}}else v.push(...Object.values(t).flatMap(e=>e||[]));let x={header:r,state:tg(_),initialState:g,operations:b,clipboard:[]},S=x;if(v.length&&m&&cn(m))S=og(m,x,t,n,i,s,u,p);else if(v.length)S=v.reduce((e,t)=>ig(e,t,n,i,s,u,p),x);else for(let e of Object.values(b)){if(!e)continue;let t=e.at(-1);t&&(S=hg(S,t.action.scope,t.timestampUtcMs))}if(!s&&h)for(let e of Object.keys(S.state)){let n=Fh(t[e]??[]).at(-1);if(n&&n.hash!==$h(S,e))throw new bn(e,S,n)}else if(!s)for(let e of Object.keys(S.state))for(let t=v.length-1;t>=0;t--){let n=v[t];if(n.action.scope===e){if(n.hash!==$h(S,e))throw new bn(e,S,n);break}}let C=/* @__PURE__ */ new Set([...Object.keys(S.operations),...Object.keys(t),`global`,`local`]),w={};for(let e of C)w[e]=[];let T=Array.from(C).reduce((e,n)=>{let r=S.operations[n]||[];return{...e,[n]:[...r.map((e,r)=>({...e,timestamp:t[n]?.[r]?.timestampUtcMs??e.timestampUtcMs}))]}},w),ee=r?r.lastModifiedAtUtcIso:Object.values(T).reduce((e,t)=>{if(!t)return e;let n=t.at(-1);return n&&n.timestampUtcMs>e?n.timestampUtcMs:e},x.header.lastModifiedAtUtcIso);return r&&(S.header={...r,revision:S.header.revision,lastModifiedAtUtcIso:ee}),{...S,operations:T}}function lg(e){let t=typeof e;if(t===`string`)return JSON.parse(e);if(t===`object`)return e;throw Error(`Providing resulting state is of type: ${t}`)}function ug(e,t){let n=Th(e).at(-1)?.index??-1,r=n+1,i={...t,index:t.index??r};if(i.index<n)throw Error(`The skip header operation index must be greater than or equal to ${n}`);return wh(Th([...e,i])).slice(0,-1)}function dg(e){return Object.entries(e).reduce((e,t)=>{let[n,r]=t;return r?{...e,[n]:wh(Th(r))}:e},{})}function fg(e,t){return e.filter(e=>!t.some(t=>e.index===t.index))}function pg(e){let t;for(let n of Object.values(e.operations))if(n)for(let e of n)(!t||e.index>t.index||e.index===t.index&&e.skip>t.skip)&&(t=e);return t?.timestampUtcMs||e.header.lastModifiedAtUtcIso}function mg(e,t){return(e.operations[t]?.at(-1)?.index??-1)+1}function hg(e,t,n){let r=n??pg(e),i=e.header.lastModifiedAtUtcIso,a={...e.header,revision:{...e.header.revision,[t]:mg(e,t)},lastModifiedAtUtcIso:!i||r>i?r:i};return{...e,header:a}}function gg(e,t,n,r,i,a=Cg,o={},s){return cg(e,t,Eg(n,a),r,i,o,s)}function _g(e,t,n,r,i){if([`UNDO`,`REDO`].includes(t.type))return e;let a=t.scope,o=e.operations[a],s=o?.at(-1)?.index??-1,c=n?s:s+1,l=Bp(t,c,r,i),u=[...o??[],l];return{...e,operations:{...e.operations,[a]:u}}}function vg(e,t,n,r,i,a){let o=t.action.scope,s=e.operations[o],c=s?.at(-1)?.index??-1,l=n?c:c+1;if(!a&&t.index-r>l)throw Error(`Missing operations: expected ${l} with skip 0 or equivalent, got index ${t.index} with skip ${r}`);let u=Vp(t,t.index,r,i),d=[...s??[],u];return{...e,operations:{...e.operations,[o]:d}}}function yg(e,t,n,r,i,a,o){let s;return s=a?vg(e,a,n,r,i,o):_g(e,t,n,r,i),s=hg(s,t.scope,t.timestampUtcMs),s}function bg(e,t,n,r=1){if(t.type!==`UNDO`&&t.type!==`REDO`)return{document:e,action:t,skip:n,reuseLastOperationIndex:!1};let{undo:i}=tn(r);switch(i){case`skip`:return t.type===`UNDO`?jh(e,t,n):Nh(e,t,n);case`noop-chain`:return t.type===`UNDO`?Mh(e,t,n):Nh(e,t,n);case`retraction`:throw new mn(e.header.id,t.type);default:return $t(i,`undo model`)}}function xg(e,t,n,r,i,a=!1,o=lg){let s=t.scope,c=e.operations[s];if(!c)return e;let l=c.at(-1);if(!l)return e;let u=dg({...e.operations,[s]:ug(c,l)}),d,f=u[s]?.at(-1);if(a&&f?.resultingState)d=o(f.resultingState);else{let{state:t}=gg(e.initialState,u,n,e.header,void 0,void 0,void 0,{reuseOperationResultingState:a,operationResultingStateParser:o,skipIndexValidation:!0,protocolVersion:i});d=t[s]}return{...e,state:{...e.state,[s]:d},operations:dg({...e.operations})}}function Sg(e,t,n,r,i=!1,a=lg){let o=e.operations[t];if(!o)return e;let s=Th([...o]);s.pop();let c=dg({...e.operations}),l=c[t];if(!l)return e;let u=[...l],d=fg(wh(s),u),f=gg(e.initialState,c,n,e.header,void 0,void 0,void 0,{reuseOperationResultingState:i,operationResultingStateParser:a,protocolVersion:r}),p=Th([...e.clipboard,...d].filter(e=>e.action.type!==`NOOP`)).reverse();return{...f,clipboard:p}}function Cg(e,t,n,r,i={}){let{skip:a,ignoreSkipOperations:o=!1,reuseOperationResultingState:s=!1,operationResultingStateParser:c,pruneOnSkip:l=!0,branch:u=`main`}=i,d=zp(t);_h(d);let f=i.protocolVersion??nn(e.header),p=tn(f),m=ln(p,d.scope),h=a??i.replayOptions?.operation.skip??0,g={...e},_=!1,v=un(p,d.scope)&&!o&&h>0;if(Zh(d)){let{skip:t,action:n,document:r,reuseLastOperationIndex:i}=bg(e,d,h,f);d=n,h=t,g=r,_=i}else g={...g,clipboard:[]};!m&&Ch(d)&&(g=Ph(g,d));let y={documentId:e.header.id,scope:d.scope,branch:u};if(g=yg(g,d,_,h,y,i.replayOptions?.operation,i.skipIndexValidation),m)return wg(g,d.scope,n,r,h,i);let b=d.type===`NOOP`&&h>0,x=p.undo;switch(x){case`skip`:if(Qh(t))return Sg(g,t.scope,n,f);break;case`noop-chain`:if(Qh(t)||b){let e=d.scope,t=eg(Th([...g.operations[e]||[]])).filter(e=>e.action.type!==`NOOP`),i={...g.operations,[e]:t};return{...gg(g.initialState,i,n,g.header,r,Cg,{},{skipIndexValidation:!0,protocolVersion:f}),operations:g.operations,clipboard:[]}}break;case`retraction`:break;default:$t(x,`undo model`)}if(v){let e=xg(g,d,n,h,f,s,c);g=l?e:{...e,operations:g.operations}}if(g=Xd(g,e=>{try{if(d.scope===`auth`){let t=gh(g,d).state;Ld(()=>{e.state=Qd(t)});return}let t=n(e.state,d,r);t&&Ld(()=>{e.state=Qd(t)})}catch(t){let n=g.operations[d.scope];if(!n)throw Error(`No operations found for scope: ${d.scope}`,{cause:t});let r=n.length-1,i=e.operations[d.scope];if(!i)throw Error(`No operations found in draft for scope: ${d.scope}`,{cause:t});let a=i[r];a.error=t.message;let{name:o,code:s}=Dg(t);o!==void 0&&(a.errorName=o),s!==void 0&&(a.errorCode=s),v?e.state=Qd({...g.state}):i[r].skip=0}}),[`UNDO`,`REDO`].includes(d.type))return g;let S=d.scope||`global`,C=i.replayOptions?.operation.hash||$h(g,S),w=g.operations[S]?.at(-1);return w&&(w.hash=C,s&&(w.resultingState=JSON.stringify(g.state[S]))),g}function wg(e,t,n,r,i,a){let o=e.operations[t]??[],s=o.at(-1);if(!s)throw Error(`No operations found for scope: ${t}`);let c=s.action.id,l=(e,t)=>n(e,t,r),u=e=>e.action.id===c?l:n,d=a.targeted??Bh(Fh(o)),f=!Xh([{skip:i,action:s.action}],{named:e=>d.has(e)}),p=e,m;if(f){let n,r=(e,t)=>{e.action.id===c&&(n=t)},i=a.deriveScope?a.deriveScope(e,o,t,r):Kh(e,o,u,t,r);p=i.document,!i.applied.has(c)&&Hh(o).some(e=>e.action.id===c)&&(m=Tg(n))}else if(!vh(s))try{p=Uh(e,s,u)}catch(e){m=Tg(e)}let h=a.replayOptions?.operation.hash,g={...s,hash:h||$h(p,t),...m===void 0?{}:{error:m},...a.reuseOperationResultingState?{resultingState:JSON.stringify(p.state[t])}:{}};return{...p,operations:{...p.operations,[t]:[...o.slice(0,-1),g]}}}function Tg(e){return e instanceof Error?e.message:typeof e==`string`?e:`Action failed`}function Eg(e,t=Cg){return qt((n,r,i,a)=>t(n,r,e,i,a),e)}function Dg(e){if(typeof e!=`object`||!e)return{};let{name:t,errorCode:n}=e,r=[t,e.constructor.name].find(e=>typeof e==`string`&&e!==``&&e!==`Error`&&e!==`Object`);return{...r!==void 0&&{name:r},...typeof n==`string`&&{code:n}}}const Og=[`UNDO`,`REDO`,`SET_NAME`,`SET_PREFERRED_EDITOR`,`SET_SLUG`,`NOOP`,`PURGE_DOCUMENT`,`RETRACT`],kg=/^[A-Z][A-Z0-9_]*$/;function Ag(e){return kg.test(e)}function jg(e){return Og.includes(e.toUpperCase())}function Mg(e,t){let n=e.specifications[e.specifications.length-1];if(!n)return[];let r=[];for(let e of n.modules)for(let n of e.operations)t&&n.id===t||n.name&&r.push(n.name.toUpperCase());return r}function Ng(e,t,n){if(!e)return;if(!Ag(e)){let t=sf(e),n=t&&t!==e&&Ag(t)?` Did you mean "${t}"?`:``;throw Error(`Operation name "${e}" is invalid. Names must be SCREAMING_SNAKE_CASE (matching ${kg.source}).${n}`)}let r=e.toUpperCase();if(jg(e))throw Error(`Operation name "${e}" is reserved. Please use a different name.`);if(Mg(t,n).includes(r))throw Error(`Operation name "${e}" is already used by another operation. Operation names must be unique across all modules.`)}function Pg(e,t){let n=e.specifications[e.specifications.length-1]?.modules.find(e=>e.id===t);if(!n)throw Error(`Module "${t}" not found in the latest specification`);return n}function Fg(e,t){let n=e.specifications[e.specifications.length-1];if(n)for(let e of n.modules){let n=e.operations.find(e=>e.id===t);if(n)return n}throw Error(`Operation "${t}" not found in the latest specification`)}function Ig(e,t){let n=e.specifications[e.specifications.length-1]?.modules.flatMap(e=>e.operations.flatMap(e=>e.errors.filter(e=>e.id===t)))??[];if(n.length===0)throw Error(`Operation error "${t}" not found in the latest specification`);if(n.length>1)throw Error(`Operation error "${t}" is duplicated in the latest specification`);return n[0]}function Lg(e,t){let n=e.specifications[e.specifications.length-1]?.modules.flatMap(e=>e.operations.flatMap(e=>e.examples.filter(e=>e.id===t)))??[];if(n.length===0)throw Error(`Operation example "${t}" not found in the latest specification`);if(n.length>1)throw Error(`Operation example "${t}" is duplicated in the latest specification`);return n[0]}function Rg(e,t){if(e.specifications[e.specifications.length-1]?.modules.some(e=>e.id===t))throw Error(`Module "${t}" already exists in the latest specification`)}function zg(e,t){if(e.specifications[e.specifications.length-1]?.modules.some(e=>e.operations.some(e=>e.id===t)))throw Error(`Operation "${t}" already exists in the latest specification`)}function Bg(e,t){if(e.specifications[e.specifications.length-1]?.modules.some(e=>e.operations.some(e=>e.errors.some(e=>e.id===t))))throw Error(`Operation error "${t}" already exists in the latest specification`)}function Vg(e,t){if(e.specifications[e.specifications.length-1]?.modules.some(e=>e.operations.some(e=>e.examples.some(e=>e.id===t))))throw Error(`Operation example "${t}" already exists in the latest specification`)}function Hg(e,t){let n=new Set(e.map(e=>e.id));for(let e of t)if(!n.has(e))throw Error(`Cannot reorder: unknown id "${e}"`);let r=new Map(t.map((e,t)=>[e,t]));return e.map((e,t)=>({item:e,index:t})).sort((e,t)=>(r.get(e.item.id)??2**53-1)-(r.get(t.item.id)??2**53-1)||e.index-t.index).map(({item:e})=>e)}function Ug(e){return id(e)?Zd(e):e}const Wg={setModelNameOperation(e,t){e.name=t.input.name},setModelIdOperation(e,t){e.id=t.input.id},setModelExtensionOperation(e,t){e.extension=t.input.extension},setModelDescriptionOperation(e,t){e.description=t.input.description},setAuthorNameOperation(e,t){e.author=e.author||{name:``,website:null},e.author.name=t.input.authorName},setAuthorWebsiteOperation(e,t){e.author=e.author||{name:``,website:null},e.author.website=t.input.authorWebsite}},Gg={addModuleOperation(e,t){Rg(e,t.input.id),e.specifications[e.specifications.length-1].modules.push({id:t.input.id,name:t.input.name,description:t.input.description||``,operations:[]})},setModuleNameOperation(e,t){let n=Pg(e,t.input.id);n.name=t.input.name||``},setModuleDescriptionOperation(e,t){let n=Pg(e,t.input.id);n.description=t.input.description||``},deleteModuleOperation(e,t){Pg(e,t.input.id);let n=e.specifications[e.specifications.length-1],r=Ug(n).modules.filter(e=>e.id!=t.input.id);n.modules=Object.freeze(r)},reorderModulesOperation(e,t){let n=e.specifications[e.specifications.length-1];n.modules=Hg(n.modules,t.input.order)}},Kg={addOperationErrorOperation(e,t){let n=Fg(e,t.input.operationId);Bg(e,t.input.id),n.errors.push({id:t.input.id,name:t.input.errorName||``,code:t.input.errorCode||``,description:t.input.errorDescription||``,template:t.input.errorTemplate||``})},setOperationErrorCodeOperation(e,t){let n=Ig(e,t.input.id);n.code=t.input.errorCode||``},setOperationErrorNameOperation(e,t){let n=Ig(e,t.input.id);n.name=t.input.errorName||``},setOperationErrorDescriptionOperation(e,t){let n=Ig(e,t.input.id);n.description=t.input.errorDescription||``},setOperationErrorTemplateOperation(e,t){let n=Ig(e,t.input.id);n.template=t.input.errorTemplate||``},deleteOperationErrorOperation(e,t){let n=e.specifications[e.specifications.length-1];if(!n.modules.some(e=>e.operations.some(e=>e.errors.some(e=>e.id===t.input.id))))throw Error(`Operation error "${t.input.id}" not found in the latest specification`);for(let e of n.modules)for(let n of e.operations)n.errors=n.errors.filter(e=>e.id!=t.input.id)},reorderOperationErrorsOperation(e,t){let n=Fg(e,t.input.operationId);n.errors=Hg(n.errors,t.input.order)}},qg={addOperationExampleOperation(e,t){let n=Fg(e,t.input.operationId);Vg(e,t.input.id),n.examples.push({id:t.input.id,value:t.input.example})},updateOperationExampleOperation(e,t){let n=Lg(e,t.input.id);n.value=t.input.example},deleteOperationExampleOperation(e,t){let n=e.specifications[e.specifications.length-1];if(!n.modules.some(e=>e.operations.some(e=>e.examples.some(e=>e.id===t.input.id))))throw Error(`Operation example "${t.input.id}" not found in the latest specification`);for(let e of n.modules)for(let n of e.operations)n.examples=n.examples.filter(e=>e.id!=t.input.id)},reorderOperationExamplesOperation(e,t){let n=Fg(e,t.input.operationId);n.examples=Hg(n.examples,t.input.order)}},Jg={addOperationOperation(e,t){Ng(t.input.name,e),zg(e,t.input.id),Pg(e,t.input.moduleId).operations.push({id:t.input.id,name:t.input.name,description:t.input.description||``,schema:t.input.schema||``,template:t.input.template||t.input.description||``,reducer:t.input.reducer||``,errors:[],examples:[],scope:t.input.scope||`global`})},setOperationNameOperation(e,t){t.input.name&&Ng(t.input.name,e,t.input.id);let n=Fg(e,t.input.id);n.name=t.input.name||``},setOperationScopeOperation(e,t){let n=Fg(e,t.input.id),r=e.specifications[e.specifications.length-1],i=Object.keys(r.state);if(t.input.scope&&!i.includes(t.input.scope))throw Error(`Invalid scope: ${t.input.scope}`);n.scope=t.input.scope||`global`},setOperationSchemaOperation(e,t){let n=Fg(e,t.input.id);n.schema=t.input.schema||``},setOperationDescriptionOperation(e,t){let n=Fg(e,t.input.id);n.description=t.input.description||``},setOperationTemplateOperation(e,t){let n=Fg(e,t.input.id);n.template=t.input.template||``},setOperationReducerOperation(e,t){let n=Fg(e,t.input.id);n.reducer=t.input.reducer||``},moveOperationOperation(e,t){let n=Pg(e,t.input.newModuleId),r=e.specifications[e.specifications.length-1],i=r.modules.flatMap(e=>e.operations.filter(e=>e.id===t.input.operationId));if(i.length===0)throw Error(`Operation "${t.input.operationId}" not found in the latest specification`);if(i.length>1)throw Error(`Operation "${t.input.operationId}" is duplicated in the latest specification`);let a=Ug(i[0]);for(let e of r.modules){let r=Ug(e).operations.filter(e=>e.id!==t.input.operationId);e===n&&r.push(a),e.operations=Object.freeze(r)}},deleteOperationOperation(e,t){Fg(e,t.input.id);let n=e.specifications[e.specifications.length-1];for(let e of n.modules){let n=Ug(e).operations.filter(e=>e.id!=t.input.id);e.operations=Object.freeze(n)}},reorderModuleOperationsOperation(e,t){let n=Pg(e,t.input.moduleId);n.operations=Hg(n.operations,t.input.order)}},Yg={setStateSchemaOperation(e,t){let n=e.specifications[e.specifications.length-1];if(Object.keys(n.state).includes(t.input.scope))n.state[t.input.scope].schema=t.input.schema;else throw Error(`Invalid scope: ${t.input.scope}`)},setInitialStateOperation(e,t){let n=e.specifications[e.specifications.length-1];if(Object.keys(n.state).includes(t.input.scope))n.state[t.input.scope].initialValue=t.input.initialValue;else throw Error(`Invalid scope: ${t.input.scope}`)},addStateExampleOperation(e,t){let n=e.specifications[e.specifications.length-1];if(Object.keys(n.state).includes(t.input.scope))n.state[t.input.scope].examples.push({id:t.input.id,value:t.input.example});else throw Error(`Invalid scope: ${t.input.scope}`)},updateStateExampleOperation(e,t){let n=e.specifications[e.specifications.length-1];if(!Object.keys(n.state).includes(t.input.scope))throw Error(`Invalid scope: ${t.input.scope}`);let r=n.state[t.input.scope].examples.find(e=>e.id==t.input.id);if(!r)throw Error(`State example "${t.input.id}" not found in scope "${t.input.scope}"`);r.value=t.input.newExample},deleteStateExampleOperation(e,t){let n=e.specifications[e.specifications.length-1];if(!Object.keys(n.state).includes(t.input.scope))throw Error(`Invalid scope: ${t.input.scope}`);let r=n.state[t.input.scope];if(!r.examples.some(e=>e.id==t.input.id))throw Error(`State example "${t.input.id}" not found in scope "${t.input.scope}"`);let i=Ug(r).examples.filter(e=>e.id!=t.input.id);r.examples=Object.freeze(i)},reorderStateExamplesOperation(e,t){let n=e.specifications[e.specifications.length-1];if(!Object.keys(n.state).includes(t.input.scope))throw Error(`Invalid scope: ${t.input.scope}`);let r=n.state[t.input.scope];r.examples=Hg(r.examples,t.input.order)}},Xg={addChangeLogItemOperation(e,t){throw Error(`Reducer "addChangeLogItemOperation" not yet implemented`)},updateChangeLogItemOperation(e,t){throw Error(`Reducer "updateChangeLogItemOperation" not yet implemented`)},deleteChangeLogItemOperation(e,t){throw Error(`Reducer "deleteChangeLogItemOperation" not yet implemented`)},reorderChangeLogItemsOperation(e,t){throw Error(`Reducer "reorderChangeLogItemsOperation" not yet implemented`)},releaseNewVersionOperation(e,t){let n=e.specifications[e.specifications.length-1],r=n.modules.map(e=>({...e,operations:e.operations.map(e=>({...e,errors:e.errors.map(e=>({...e})),examples:e.examples.map(e=>({...e}))}))})),i={global:{...n.state.global,examples:n.state.global.examples.map(e=>({...e}))},local:{...n.state.local,examples:n.state.local.examples.map(e=>({...e}))}},a={version:n.version+1,changeLog:[],state:i,modules:r};e.specifications.push(a)}};Eg((e,t)=>{if(Ch(t))return e;switch(t.type){case`SET_MODEL_NAME`:op().parse(t.input),Wg.setModelNameOperation(e.global,t);break;case`SET_MODEL_ID`:ap().parse(t.input),Wg.setModelIdOperation(e.global,t);break;case`SET_MODEL_EXTENSION`:ip().parse(t.input),Wg.setModelExtensionOperation(e.global,t);break;case`SET_MODEL_DESCRIPTION`:rp().parse(t.input),Wg.setModelDescriptionOperation(e.global,t);break;case`SET_AUTHOR_NAME`:ep().parse(t.input),Wg.setAuthorNameOperation(e.global,t);break;case`SET_AUTHOR_WEBSITE`:tp().parse(t.input),Wg.setAuthorWebsiteOperation(e.global,t);break;case`ADD_CHANGE_LOG_ITEM`:Of().parse(t.input),Xg.addChangeLogItemOperation(e.global,t);break;case`UPDATE_CHANGE_LOG_ITEM`:Sp().parse(t.input),Xg.updateChangeLogItemOperation(e.global,t);break;case`DELETE_CHANGE_LOG_ITEM`:If().parse(t.input),Xg.deleteChangeLogItemOperation(e.global,t);break;case`REORDER_CHANGE_LOG_ITEMS`:Jf().parse(t.input),Xg.reorderChangeLogItemsOperation(e.global,t);break;case`RELEASE_NEW_VERSION`:if(Object.keys(t.input).length>0)throw Error(`Expected empty input for action RELEASE_NEW_VERSION`);Xg.releaseNewVersionOperation(e.global,t);break;case`ADD_MODULE`:kf().parse(t.input),Gg.addModuleOperation(e.global,t);break;case`SET_MODULE_NAME`:cp().parse(t.input),Gg.setModuleNameOperation(e.global,t);break;case`SET_MODULE_DESCRIPTION`:sp().parse(t.input),Gg.setModuleDescriptionOperation(e.global,t);break;case`DELETE_MODULE`:Lf().parse(t.input),Gg.deleteModuleOperation(e.global,t);break;case`REORDER_MODULES`:Xf().parse(t.input),Gg.reorderModulesOperation(e.global,t);break;case`ADD_OPERATION_ERROR`:Af().parse(t.input),Kg.addOperationErrorOperation(e.global,t);break;case`SET_OPERATION_ERROR_CODE`:up().parse(t.input),Kg.setOperationErrorCodeOperation(e.global,t);break;case`SET_OPERATION_ERROR_NAME`:fp().parse(t.input),Kg.setOperationErrorNameOperation(e.global,t);break;case`SET_OPERATION_ERROR_DESCRIPTION`:dp().parse(t.input),Kg.setOperationErrorDescriptionOperation(e.global,t);break;case`SET_OPERATION_ERROR_TEMPLATE`:pp().parse(t.input),Kg.setOperationErrorTemplateOperation(e.global,t);break;case`DELETE_OPERATION_ERROR`:Rf().parse(t.input),Kg.deleteOperationErrorOperation(e.global,t);break;case`REORDER_OPERATION_ERRORS`:Zf().parse(t.input),Kg.reorderOperationErrorsOperation(e.global,t);break;case`ADD_OPERATION_EXAMPLE`:jf().parse(t.input),qg.addOperationExampleOperation(e.global,t);break;case`UPDATE_OPERATION_EXAMPLE`:Cp().parse(t.input),qg.updateOperationExampleOperation(e.global,t);break;case`DELETE_OPERATION_EXAMPLE`:zf().parse(t.input),qg.deleteOperationExampleOperation(e.global,t);break;case`REORDER_OPERATION_EXAMPLES`:Qf().parse(t.input),qg.reorderOperationExamplesOperation(e.global,t);break;case`ADD_OPERATION`:Mf().parse(t.input),Jg.addOperationOperation(e.global,t);break;case`SET_OPERATION_NAME`:mp().parse(t.input),Jg.setOperationNameOperation(e.global,t);break;case`SET_OPERATION_SCOPE`:hp().parse(t.input),Jg.setOperationScopeOperation(e.global,t);break;case`SET_OPERATION_SCHEMA`:_p().parse(t.input),Jg.setOperationSchemaOperation(e.global,t);break;case`SET_OPERATION_DESCRIPTION`:lp().parse(t.input),Jg.setOperationDescriptionOperation(e.global,t);break;case`SET_OPERATION_TEMPLATE`:vp().parse(t.input),Jg.setOperationTemplateOperation(e.global,t);break;case`SET_OPERATION_REDUCER`:gp().parse(t.input),Jg.setOperationReducerOperation(e.global,t);break;case`MOVE_OPERATION`:Gf().parse(t.input),Jg.moveOperationOperation(e.global,t);break;case`DELETE_OPERATION`:Bf().parse(t.input),Jg.deleteOperationOperation(e.global,t);break;case`REORDER_MODULE_OPERATIONS`:Yf().parse(t.input),Jg.reorderModuleOperationsOperation(e.global,t);break;case`SET_STATE_SCHEMA`:yp().parse(t.input),Yg.setStateSchemaOperation(e.global,t);break;case`SET_INITIAL_STATE`:np().parse(t.input),Yg.setInitialStateOperation(e.global,t);break;case`ADD_STATE_EXAMPLE`:Nf().parse(t.input),Yg.addStateExampleOperation(e.global,t);break;case`UPDATE_STATE_EXAMPLE`:wp().parse(t.input),Yg.updateStateExampleOperation(e.global,t);break;case`DELETE_STATE_EXAMPLE`:Vf().parse(t.input),Yg.deleteStateExampleOperation(e.global,t);break;case`REORDER_STATE_EXAMPLES`:$f().parse(t.input),Yg.reorderStateExamplesOperation(e.global,t);break;default:return e}});function Zg(e){return globalThis.Buffer==null?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function Qg(e=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Zg(globalThis.Buffer.allocUnsafe(e)):new Uint8Array(e)}function $g(e,t){t||=e.reduce((e,t)=>e+t.length,0);let n=Qg(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return Zg(n)}function e_(e,t){if(e.length>=255)throw TypeError(`Alphabet too long`);for(var n=/* @__PURE__ */ new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<e.length;i++){var a=e.charAt(i),o=a.charCodeAt(0);if(n[o]!==255)throw TypeError(a+` is ambiguous`);n[o]=i}var s=e.length,c=e.charAt(0),l=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function d(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;for(var n=0,r=0,i=0,a=t.length;i!==a&&t[i]===0;)i++,n++;for(var o=(a-i)*u+1>>>0,l=new Uint8Array(o);i!==a;){for(var d=t[i],f=0,p=o-1;(d!==0||f<r)&&p!==-1;p--,f++)d+=256*l[p]>>>0,l[p]=d%s>>>0,d=d/s>>>0;if(d!==0)throw Error(`Non-zero carry`);r=f,i++}for(var m=o-r;m!==o&&l[m]===0;)m++;for(var h=c.repeat(n);m<o;++m)h+=e.charAt(l[m]);return h}function f(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return/* @__PURE__ */ new Uint8Array;var t=0;if(e[t]!==` `){for(var r=0,i=0;e[t]===c;)r++,t++;for(var a=(e.length-t)*l+1>>>0,o=new Uint8Array(a);e[t];){var u=n[e.charCodeAt(t)];if(u===255)return;for(var d=0,f=a-1;(u!==0||d<i)&&f!==-1;f--,d++)u+=s*o[f]>>>0,o[f]=u%256>>>0,u=u/256>>>0;if(u!==0)throw Error(`Non-zero carry`);i=d,t++}if(e[t]!==` `){for(var p=a-i;p!==a&&o[p]===0;)p++;for(var m=new Uint8Array(r+(a-p)),h=r;p!==a;)m[h++]=o[p++];return m}}}function p(e){var n=f(e);if(n)return n;throw Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:p}}var t_=e_;const n_=e=>{if(e instanceof Uint8Array&&e.constructor.name===`Uint8Array`)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw Error(`Unknown type, must be binary type`)},r_=e=>new TextEncoder().encode(e),i_=e=>new TextDecoder().decode(e);var a_=class{constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error(`Unknown type, must be binary type`)}},o_=class{constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw Error(`Invalid prefix character`);this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e==`string`){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}throw Error(`Can only multibase decode strings`)}or(e){return c_(this,e)}},s_=class{constructor(e){this.decoders=e}or(e){return c_(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};const c_=(e,t)=>new s_({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}});var l_=class{constructor(e,t,n,r){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=r,this.encoder=new a_(e,t,n),this.decoder=new o_(e,t,r)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};const u_=({name:e,prefix:t,encode:n,decode:r})=>new l_(e,t,n,r),d_=({prefix:e,name:t,alphabet:n})=>{let{encode:r,decode:i}=t_(n,t);return u_({prefix:e,name:t,encode:r,decode:e=>n_(i(e))})},f_=(e,t,n,r)=>{let i={};for(let e=0;e<t.length;++e)i[t[e]]=e;let a=e.length;for(;e[a-1]===`=`;)--a;let o=new Uint8Array(a*n/8|0),s=0,c=0,l=0;for(let t=0;t<a;++t){let a=i[e[t]];if(a===void 0)throw SyntaxError(`Non-${r} character`);c=c<<n|a,s+=n,s>=8&&(s-=8,o[l++]=255&c>>s)}if(s>=n||255&c<<8-s)throw SyntaxError(`Unexpected end of data`);return o},p_=(e,t,n)=>{let r=t[t.length-1]===`=`,i=(1<<n)-1,a=``,o=0,s=0;for(let r=0;r<e.length;++r)for(s=s<<8|e[r],o+=8;o>n;)o-=n,a+=t[i&s>>o];if(o&&(a+=t[i&s<<n-o]),r)for(;a.length*n&7;)a+=`=`;return a},U=({name:e,prefix:t,bitsPerChar:n,alphabet:r})=>u_({prefix:t,name:e,encode(e){return p_(e,r,n)},decode(t){return f_(t,r,n,e)}});var m_=/* @__PURE__ */ c({identity:()=>h_});const h_=u_({prefix:`\0`,name:`identity`,encode:e=>i_(e),decode:e=>r_(e)});var g_=/* @__PURE__ */ c({base2:()=>__});const __=U({prefix:`0`,name:`base2`,alphabet:`01`,bitsPerChar:1});var v_=/* @__PURE__ */ c({base8:()=>y_});const y_=U({prefix:`7`,name:`base8`,alphabet:`01234567`,bitsPerChar:3});var b_=/* @__PURE__ */ c({base10:()=>x_});const x_=d_({prefix:`9`,name:`base10`,alphabet:`0123456789`});var S_=/* @__PURE__ */ c({base16:()=>C_,base16upper:()=>w_});const C_=U({prefix:`f`,name:`base16`,alphabet:`0123456789abcdef`,bitsPerChar:4}),w_=U({prefix:`F`,name:`base16upper`,alphabet:`0123456789ABCDEF`,bitsPerChar:4});var T_=/* @__PURE__ */ c({base32:()=>E_,base32hex:()=>A_,base32hexpad:()=>M_,base32hexpadupper:()=>N_,base32hexupper:()=>j_,base32pad:()=>O_,base32padupper:()=>k_,base32upper:()=>D_,base32z:()=>P_});const E_=U({prefix:`b`,name:`base32`,alphabet:`abcdefghijklmnopqrstuvwxyz234567`,bitsPerChar:5}),D_=U({prefix:`B`,name:`base32upper`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,bitsPerChar:5}),O_=U({prefix:`c`,name:`base32pad`,alphabet:`abcdefghijklmnopqrstuvwxyz234567=`,bitsPerChar:5}),k_=U({prefix:`C`,name:`base32padupper`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=`,bitsPerChar:5}),A_=U({prefix:`v`,name:`base32hex`,alphabet:`0123456789abcdefghijklmnopqrstuv`,bitsPerChar:5}),j_=U({prefix:`V`,name:`base32hexupper`,alphabet:`0123456789ABCDEFGHIJKLMNOPQRSTUV`,bitsPerChar:5}),M_=U({prefix:`t`,name:`base32hexpad`,alphabet:`0123456789abcdefghijklmnopqrstuv=`,bitsPerChar:5}),N_=U({prefix:`T`,name:`base32hexpadupper`,alphabet:`0123456789ABCDEFGHIJKLMNOPQRSTUV=`,bitsPerChar:5}),P_=U({prefix:`h`,name:`base32z`,alphabet:`ybndrfg8ejkmcpqxot1uwisza345h769`,bitsPerChar:5});var F_=/* @__PURE__ */ c({base36:()=>I_,base36upper:()=>L_});const I_=d_({prefix:`k`,name:`base36`,alphabet:`0123456789abcdefghijklmnopqrstuvwxyz`}),L_=d_({prefix:`K`,name:`base36upper`,alphabet:`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`});var R_=/* @__PURE__ */ c({base58btc:()=>z_,base58flickr:()=>B_});const z_=d_({name:`base58btc`,prefix:`z`,alphabet:`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`}),B_=d_({name:`base58flickr`,prefix:`Z`,alphabet:`123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ`});var V_=/* @__PURE__ */ c({base64:()=>H_,base64pad:()=>U_,base64url:()=>W_,base64urlpad:()=>G_});const H_=U({prefix:`m`,name:`base64`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,bitsPerChar:6}),U_=U({prefix:`M`,name:`base64pad`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=`,bitsPerChar:6}),W_=U({prefix:`u`,name:`base64url`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,bitsPerChar:6}),G_=U({prefix:`U`,name:`base64urlpad`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=`,bitsPerChar:6});var K_=/* @__PURE__ */ c({base256emoji:()=>Q_});const q_=Array.from(`🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂`),J_=q_.reduce((e,t,n)=>(e[n]=t,e),[]),Y_=q_.reduce((e,t,n)=>(e[t.codePointAt(0)]=n,e),[]);function X_(e){return e.reduce((e,t)=>(e+=J_[t],e),``)}function Z_(e){let t=[];for(let n of e){let e=Y_[n.codePointAt(0)];if(e===void 0)throw Error(`Non-base256emoji character: ${n}`);t.push(e)}return new Uint8Array(t)}const Q_=u_({prefix:`🚀`,name:`base256emoji`,encode:X_,decode:Z_});var $_=rv,ev=128,tv=-128,nv=2**31;function rv(e,t,n){t||=[],n||=0;for(var r=n;e>=nv;)t[n++]=e&255|ev,e/=128;for(;e&tv;)t[n++]=e&255|ev,e>>>=7;return t[n]=e|0,rv.bytes=n-r+1,t}var iv=sv,av=128,ov=127;function sv(e,t){var n=0,t=t||0,r=0,i=t,a,o=e.length;do{if(i>=o)throw sv.bytes=0,RangeError(`Could not decode varint`);a=e[i++],n+=r<28?(a&ov)<<r:(a&ov)*2**r,r+=7}while(a>=av);return sv.bytes=i-t,n}var cv=128,lv=2**14,uv=2**21,dv=2**28,fv=2**35,pv=2**42,mv=2**49,hv=2**56,gv=2**63,_v={encode:$_,decode:iv,encodingLength:function(e){return e<cv?1:e<lv?2:e<uv?3:e<dv?4:e<fv?5:e<pv?6:e<mv?7:e<hv?8:e<gv?9:10}};const vv=(e,t=0)=>[_v.decode(e,t),_v.decode.bytes],yv=(e,t,n=0)=>(_v.encode(e,t,n),t),bv=e=>_v.encodingLength(e),xv=(e,t)=>{let n=t.byteLength,r=bv(e),i=r+bv(n),a=new Uint8Array(i+n);return yv(e,a,0),yv(n,a,r),a.set(t,i),new Sv(e,n,t,a)};var Sv=class{constructor(e,t,n,r){this.code=e,this.size=t,this.digest=n,this.bytes=r}};const Cv=({name:e,code:t,encode:n})=>new wv(e,t,n);var wv=class{constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?xv(this.code,t):t.then(e=>xv(this.code,e))}throw Error(`Unknown type, must be binary type`)}},Tv=/* @__PURE__ */ c({sha256:()=>Dv,sha512:()=>Ov});const Ev=e=>async t=>new Uint8Array(await crypto.subtle.digest(e,t)),Dv=Cv({name:`sha2-256`,code:18,encode:Ev(`SHA-256`)}),Ov=Cv({name:`sha2-512`,code:19,encode:Ev(`SHA-512`)});var kv=/* @__PURE__ */ c({identity:()=>jv});const Av=n_,jv={code:0,name:`identity`,encode:Av,digest:e=>xv(0,Av(e))};new TextEncoder,new TextDecoder;const Mv={...m_,...g_,...v_,...b_,...S_,...T_,...F_,...R_,...V_,...K_};({...Tv,...kv});function Nv(e,t,n,r){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:n},decoder:{decode:r}}}const Pv=Nv(`utf8`,`u`,e=>`u`+new TextDecoder(`utf8`).decode(e),e=>new TextEncoder().encode(e.substring(1))),Fv=Nv(`ascii`,`a`,e=>{let t=`a`;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t},e=>{e=e.substring(1);let t=Qg(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}),Iv={utf8:Pv,"utf-8":Pv,hex:Mv.base16,latin1:Fv,ascii:Fv,binary:Fv,...Mv};function Lv(e,t=`utf8`){let n=Iv[t];if(!n)throw Error(`Unsupported encoding "${t}"`);return(t===`utf8`||t===`utf-8`)&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Zg(globalThis.Buffer.from(e,`utf-8`)):n.decoder.decode(`${n.prefix}${e}`)}function Rv(e,t=`utf8`){let n=Iv[t];if(!n)throw Error(`Unsupported encoding "${t}"`);return(t===`utf8`||t===`utf-8`)&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`utf8`):n.encoder.encode(e).substring(1)}qe();
116
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
117
+ const zv=/* @__PURE__ */ BigInt(0),Bv=/* @__PURE__ */ BigInt(1);function Vv(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}"`;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function Hv(e,t,n=``){let r=be(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function Uv(e){let t=e.toString(16);return t.length&1?`0`+t:t}function Wv(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?zv:BigInt(`0x`+e)}function Gv(e){return Wv(Ne(e))}function Kv(e){return Se(e),Wv(Ne(Uint8Array.from(e).reverse()))}function qv(e,t){return Fe(e.toString(16).padStart(t*2,`0`))}function Jv(e,t){return qv(e,t).reverse()}function Yv(e){return Fe(Uv(e))}function W(e,t,n){let r;if(typeof t==`string`)try{r=Fe(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(be(t))r=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let i=r.length;if(typeof n==`number`&&i!==n)throw Error(e+` of length `+n+` expected, got `+i);return r}function Xv(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function Zv(e){return Uint8Array.from(e)}const Qv=e=>typeof e==`bigint`&&zv<=e;function $v(e,t,n){return Qv(e)&&Qv(t)&&Qv(n)&&t<=e&&e<n}function ey(e,t,n,r){if(!$v(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function ty(e){let t=0;for(;e>zv;e>>=Bv,t+=1);return t}const ny=e=>(Bv<<BigInt(e))-Bv;function ry(e,t,n){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof n!=`function`)throw Error(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e),a=r(e),o=r(e),s=0,c=()=>{a.fill(1),o.fill(0),s=0},l=(...e)=>n(o,a,...e),u=(e=r(0))=>{o=l(i(0),e),a=l(),e.length!==0&&(o=l(i(1),e),a=l())},d=()=>{if(s++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,n=[];for(;e<t;){a=l();let t=a.slice();n.push(t),e+=a.length}return Re(...n)};return(e,t)=>{c(),u(e);let n;for(;!(n=t(d()));)u();return c(),n}}function iy(e,t,n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}const ay=()=>{throw Error(`not implemented`)};function oy(e){let t=/* @__PURE__ */ new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}
118
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
119
+ const sy=BigInt(0),G=BigInt(1),cy=/* @__PURE__ */ BigInt(2),ly=/* @__PURE__ */ BigInt(3),uy=/* @__PURE__ */ BigInt(4),dy=/* @__PURE__ */ BigInt(5),fy=/* @__PURE__ */ BigInt(7),py=/* @__PURE__ */ BigInt(8),my=/* @__PURE__ */ BigInt(9),hy=/* @__PURE__ */ BigInt(16);function K(e,t){let n=e%t;return n>=sy?n:t+n}function q(e,t,n){let r=e;for(;t-->sy;)r*=r,r%=n;return r}function gy(e,t){if(e===sy)throw Error(`invert: expected non-zero number`);if(t<=sy)throw Error(`invert: expected positive modulus, got `+t);let n=K(e,t),r=t,i=sy,a=G,o=G,s=sy;for(;n!==sy;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==G)throw Error(`invert: does not exist`);return K(i,t)}function _y(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function vy(e,t){let n=(e.ORDER+G)/uy,r=e.pow(t,n);return _y(e,r,t),r}function yy(e,t){let n=(e.ORDER-dy)/py,r=e.mul(t,cy),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,cy),i),s=e.mul(a,e.sub(o,e.ONE));return _y(e,s,t),s}function by(e){let t=Ay(e),n=xy(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+fy)/hy;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return _y(e,p,t),p}}function xy(e){if(e<ly)throw Error(`sqrt is not defined for small field`);let t=e-G,n=0;for(;t%cy===sy;)t/=cy,n++;let r=cy,i=Ay(e);for(;Oy(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return vy;let a=i.pow(r,t),o=(t+G)/cy;return function(e,r){if(e.is0(r))return r;if(Oy(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=G<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function Sy(e){return e%uy===ly?vy:e%py===dy?yy:e%hy===my?by(e):xy(e)}const Cy=(e,t)=>(K(e,t)&G)===G,wy=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function Ty(e){return iy(e,wy.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`number`,BITS:`number`})),e}function Ey(e,t,n){if(n<sy)throw Error(`invalid exponent, negatives unsupported`);if(n===sy)return e.ONE;if(n===G)return t;let r=e.ONE,i=t;for(;n>sy;)n&G&&(r=e.mul(r,i)),i=e.sqr(i),n>>=G;return r}function Dy(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function Oy(e,t){let n=(e.ORDER-G)/cy,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function ky(e,t){t!==void 0&&xe(t);let n=t===void 0?e.toString(2).length:t;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Ay(e,t,n=!1,r={}){if(e<=sy)throw Error(`invalid field: expected ORDER > 0, got `+e);let i,a,o=!1,s;if(typeof t==`object`&&t){if(r.sqrt||n)throw Error(`cannot specify opts in two arguments`);let e=t;e.BITS&&(i=e.BITS),e.sqrt&&(a=e.sqrt),typeof e.isLE==`boolean`&&(n=e.isLE),typeof e.modFromBytes==`boolean`&&(o=e.modFromBytes),s=e.allowedLengths}else typeof t==`number`&&(i=t),r.sqrt&&(a=r.sqrt);let{nBitLength:c,nByteLength:l}=ky(e,i);if(l>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let u,d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:l,MASK:ny(c),ZERO:sy,ONE:G,allowedLengths:s,create:t=>K(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return sy<=t&&t<e},is0:e=>e===sy,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&G)===G,neg:t=>K(-t,e),eql:(e,t)=>e===t,sqr:t=>K(t*t,e),add:(t,n)=>K(t+n,e),sub:(t,n)=>K(t-n,e),mul:(t,n)=>K(t*n,e),pow:(e,t)=>Ey(d,e,t),div:(t,n)=>K(t*gy(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>gy(t,e),sqrt:a||(t=>(u||=Sy(e),u(d,t))),toBytes:e=>n?Jv(e,l):qv(e,l),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>l)throw Error(`Field.fromBytes: expected `+s+` bytes, got `+t.length);let e=new Uint8Array(l);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==l)throw Error(`Field.fromBytes: expected `+l+` bytes, got `+t.length);let i=n?Kv(t):Gv(t);if(o&&(i=K(i,e)),!r&&!d.isValid(i))throw Error(`invalid field element: outside of range 0..ORDER`);return i},invertBatch:e=>Dy(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function jy(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function My(e){let t=jy(e);return t+Math.ceil(t/2)}function Ny(e,t,n=!1){let r=e.length,i=jy(t),a=My(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=K(n?Kv(e):Gv(e),t-G)+G;return n?Jv(o,i):qv(o,i)}
120
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
121
+ const Py=BigInt(0),Fy=BigInt(1);function Iy(e,t){let n=t.negate();return e?n:t}function Ly(e,t){let n=Dy(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Ry(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function zy(e,t){Ry(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:ny(e),maxNumber:i,shiftBy:BigInt(e)}}function By(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=Fy);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function Vy(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function Hy(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}const Uy=/* @__PURE__ */ new WeakMap,Wy=/* @__PURE__ */ new WeakMap;function Gy(e){return Wy.get(e)||1}function Ky(e){if(e!==Py)throw Error(`invalid wNAF`)}var qy=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Py;)t&Fy&&(n=n.add(r)),r=r.double(),t>>=Fy;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=zy(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=zy(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=By(n,e,a);n=o,c?i=i.add(Iy(u,t[d])):r=r.add(Iy(l,t[s]))}return Ky(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=zy(e,this.bits);for(let e=0;e<i.windows&&n!==Py;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=By(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return Ky(n),r}getPrecomputes(e,t,n){let r=Uy.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),Uy.set(t,r))),r}cached(e,t,n){let r=Gy(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=Gy(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Ry(t,this.bits),Wy.set(e,t),Uy.delete(e)}hasCache(e){return Gy(e)!==1}};function Jy(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>Py||r>Py;)n&Fy&&(a=a.add(i)),r&Fy&&(o=o.add(i)),i=i.double(),n>>=Fy,r>>=Fy;return{p1:a,p2:o}}function Yy(e,t,n,r){Vy(n,e),Hy(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=ty(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=ny(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Xy(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return Ty(t),t}return Ay(e,{isLE:n})}function Zy(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>Py))throw Error(`CURVE.${e} must be positive bigint`)}let i=Xy(t.p,n.Fp,r),a=Xy(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}
122
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
123
+ const Qy=BigInt(0),J=BigInt(1),$y=BigInt(2),eb=BigInt(8);function tb(e,t,n,r){let i=e.sqr(n),a=e.sqr(r),o=e.add(e.mul(t.a,i),a),s=e.add(e.ONE,e.mul(t.d,e.mul(i,a)));return e.eql(o,s)}function nb(e,t={}){let n=Zy(`edwards`,e,t,t.FpFnLE),{Fp:r,Fn:i}=n,a=n.CURVE,{h:o}=a;iy(t,{},{uvRatio:`function`});let s=$y<<BigInt(i.BYTES*8)-J,c=e=>r.create(e),l=t.uvRatio||((e,t)=>{try{return{isValid:!0,value:r.sqrt(r.div(e,t))}}catch{return{isValid:!1,value:Qy}}});if(!tb(r,a,a.Gx,a.Gy))throw Error(`bad curve params: generator point`);function u(e,t,n=!1){let r=n?J:Qy;return ey(`coordinate `+e,t,r,s),t}function d(e){if(!(e instanceof m))throw Error(`ExtendedPoint expected`)}let f=oy((e,t)=>{let{X:n,Y:i,Z:a}=e,o=e.is0();t??=o?eb:r.inv(a);let s=c(n*t),l=c(i*t),u=r.mul(a,t);if(o)return{x:Qy,y:J};if(u!==J)throw Error(`invZ was invalid`);return{x:s,y:l}}),p=oy(e=>{let{a:t,d:n}=a;if(e.is0())throw Error(`bad point: ZERO`);let{X:r,Y:i,Z:o,T:s}=e,l=c(r*r),u=c(i*i),d=c(o*o),f=c(d*d),p=c(l*t);if(c(d*c(p+u))!==c(f+c(n*c(l*u))))throw Error(`bad point: equation left != right (1)`);if(c(r*i)!==c(o*s))throw Error(`bad point: equation left != right (2)`);return!0});class m{constructor(e,t,n,r){this.X=u(`x`,e),this.Y=u(`y`,t),this.Z=u(`z`,n,!0),this.T=u(`t`,r),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){if(e instanceof m)throw Error(`extended point not allowed`);let{x:t,y:n}=e||{};return u(`x`,t),u(`y`,n),new m(t,n,J,c(t*n))}static fromBytes(e,t=!1){let n=r.BYTES,{a:i,d:o}=a;e=Zv(Hv(e,n,`point`)),Vv(t,`zip215`);let u=Zv(e),d=e[n-1];u[n-1]=d&-129;let f=Kv(u),p=t?s:r.ORDER;ey(`point.y`,f,Qy,p);let h=c(f*f),g=c(h-J),_=c(o*h-i),{isValid:v,value:y}=l(g,_);if(!v)throw Error(`bad point: invalid y coordinate`);let b=(y&J)===J,x=!!(d&128);if(!t&&y===Qy&&x)throw Error(`bad point: x=0 and x_0=1`);return x!==b&&(y=c(-y)),m.fromAffine({x:y,y:f})}static fromHex(e,t=!1){return m.fromBytes(W(`point`,e),t)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return h.createCache(this,e),t||this.multiply($y),this}assertValidity(){p(this)}equals(e){d(e);let{X:t,Y:n,Z:r}=this,{X:i,Y:a,Z:o}=e,s=c(t*o),l=c(i*r),u=c(n*o),f=c(a*r);return s===l&&u===f}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:e}=a,{X:t,Y:n,Z:r}=this,i=c(t*t),o=c(n*n),s=c($y*c(r*r)),l=c(e*i),u=t+n,d=c(c(u*u)-i-o),f=l+o,p=f-s,h=l-o,g=c(d*p),_=c(f*h),v=c(d*h),y=c(p*f);return new m(g,_,y,v)}add(e){d(e);let{a:t,d:n}=a,{X:r,Y:i,Z:o,T:s}=this,{X:l,Y:u,Z:f,T:p}=e,h=c(r*l),g=c(i*u),_=c(s*n*p),v=c(o*f),y=c((r+i)*(l+u)-h-g),b=v-_,x=v+_,S=c(g-t*h),C=c(y*b),w=c(x*S),T=c(y*S),ee=c(b*x);return new m(C,w,ee,T)}subtract(e){return this.add(e.negate())}multiply(e){if(!i.isValidNot0(e))throw Error(`invalid scalar: expected 1 <= sc < curve.n`);let{p:t,f:n}=h.cached(this,e,e=>Ly(m,e));return Ly(m,[t,n])[0]}multiplyUnsafe(e,t=m.ZERO){if(!i.isValid(e))throw Error(`invalid scalar: expected 0 <= sc < curve.n`);return e===Qy?m.ZERO:this.is0()||e===J?this:h.unsafe(this,e,e=>Ly(m,e),t)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return h.unsafe(this,a.n).is0()}toAffine(e){return f(this,e)}clearCofactor(){return o===J?this:this.multiplyUnsafe(o)}toBytes(){let{x:e,y:t}=this.toAffine(),n=r.toBytes(t);return n[n.length-1]|=e&J?128:0,n}toHex(){return Ne(this.toBytes())}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(e){return Ly(m,e)}static msm(e,t){return Yy(m,i,e,t)}_setWindowSize(e){this.precompute(e)}toRawBytes(){return this.toBytes()}}m.BASE=new m(a.Gx,a.Gy,J,c(a.Gx*a.Gy)),m.ZERO=new m(Qy,J,J,Qy),m.Fp=r,m.Fn=i;let h=new qy(m,i.BITS);return m.BASE.precompute(8),m}var rb=class{constructor(e){this.ep=e}static fromBytes(e){ay()}static fromHex(e){ay()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Ne(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.init(this.ep.precompute(e,t))}toRawBytes(){return this.toBytes()}};function ib(e,t,n={}){if(typeof t!=`function`)throw Error(`"hash" function param is required`);iy(n,{},{adjustScalarBytes:`function`,randomBytes:`function`,domain:`function`,prehash:`function`,mapToCurve:`function`});let{prehash:r}=n,{BASE:i,Fp:a,Fn:o}=e,s=n.randomBytes||Be,c=n.adjustScalarBytes||(e=>e),l=n.domain||((e,t,n)=>{if(Vv(n,`phflag`),t.length||n)throw Error(`Contexts/pre-hash are not supported`);return e});function u(e){return o.create(Kv(e))}function d(e){let n=y.secretKey;e=W(`private key`,e,n);let r=W(`hashed private key`,t(e),2*n),i=c(r.slice(0,n));return{head:i,prefix:r.slice(n,2*n),scalar:u(i)}}function f(e){let{head:t,prefix:n,scalar:r}=d(e),a=i.multiply(r);return{head:t,prefix:n,scalar:r,point:a,pointBytes:a.toBytes()}}function p(e){return f(e).pointBytes}function m(e=Uint8Array.of(),...n){let i=Re(...n);return u(t(l(i,W(`context`,e),!!r)))}function h(e,t,n={}){e=W(`message`,e),r&&(e=r(e));let{prefix:a,scalar:s,pointBytes:c}=f(t),l=m(n.context,a,e),u=i.multiply(l).toBytes(),d=m(n.context,u,c,e),p=o.create(l+d*s);if(!o.isValid(p))throw Error(`sign failed: invalid s`);return Hv(Re(u,o.toBytes(p)),y.signature,`result`)}let g={zip215:!0};function _(t,n,a,o=g){let{context:s,zip215:c}=o,l=y.signature;t=W(`signature`,t,l),n=W(`message`,n),a=W(`publicKey`,a,y.publicKey),c!==void 0&&Vv(c,`zip215`),r&&(n=r(n));let u=l/2,d=t.subarray(0,u),f=Kv(t.subarray(u,l)),p,h,_;try{p=e.fromBytes(a,c),h=e.fromBytes(d,c),_=i.multiplyUnsafe(f)}catch{return!1}if(!c&&p.isSmallOrder())return!1;let v=m(s,h.toBytes(),p.toBytes(),n);return h.add(p.multiplyUnsafe(v)).subtract(_).clearCofactor().is0()}let v=a.BYTES,y={secretKey:v,publicKey:v,signature:2*v,seed:v};function b(e=s(y.seed)){return Hv(e,y.seed,`seed`)}function x(e){let t=w.randomSecretKey(e);return{secretKey:t,publicKey:p(t)}}function S(e){return be(e)&&e.length===o.BYTES}function C(t,n){try{return!!e.fromBytes(t,n)}catch{return!1}}let w={getExtendedPublicKey:f,randomSecretKey:b,isValidSecretKey:S,isValidPublicKey:C,toMontgomery(t){let{y:n}=e.fromBytes(t),r=y.publicKey,i=r===32;if(!i&&r!==57)throw Error(`only defined for 25519 and 448`);let o=i?a.div(J+n,J-n):a.div(n-J,n+J);return a.toBytes(o)},toMontgomerySecret(e){let n=y.secretKey;Hv(e,n);let r=t(e.subarray(0,n));return c(r).subarray(0,n)},randomPrivateKey:b,precompute(t=8,n=e.BASE){return n.precompute(t,!1)}};return Object.freeze({keygen:x,getPublicKey:p,sign:h,verify:_,utils:w,Point:e,lengths:y})}function ab(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n={Fp:e.Fp,Fn:Ay(t.n,e.nBitLength,!0),uvRatio:e.uvRatio},r={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:n,hash:e.hash,eddsaOpts:r}}function ob(e,t){let n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function sb(e){let{CURVE:t,curveOpts:n,hash:r,eddsaOpts:i}=ab(e);return ob(e,ib(nb(t,n),r,i))}Ft(),qe();
124
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
125
+ const cb=/* @__PURE__ */ BigInt(0),lb=BigInt(1),ub=BigInt(2),db=BigInt(5),fb=BigInt(8),pb=BigInt(`0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed`),mb={p:pb,n:BigInt(`0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed`),h:fb,a:BigInt(`0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec`),d:BigInt(`0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3`),Gx:BigInt(`0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a`),Gy:BigInt(`0x6666666666666666666666666666666666666666666666666666666666666658`)};function hb(e){let t=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),a=pb,o=e*e%a*e%a,s=q(q(o,ub,a)*o%a,lb,a)*e%a,c=q(s,db,a)*s%a,l=q(c,t,a)*c%a,u=q(l,n,a)*l%a,d=q(u,r,a)*u%a;return{pow_p_5_8:q(q(q(q(d,i,a)*d%a,i,a)*d%a,t,a)*c%a,ub,a)*e%a,b2:o}}function gb(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const _b=/* @__PURE__ */ BigInt(`19681161376707505956807079304988542015446066515923890162744021073123829784752`);function vb(e,t){let n=pb,r=K(t*t*t,n),i=hb(e*K(r*r*t,n)).pow_p_5_8,a=K(e*r*i,n),o=K(t*a*a,n),s=a,c=K(a*_b,n),l=o===e,u=o===K(-e,n),d=o===K(-e*_b,n);return l&&(a=s),(u||d)&&(a=c),Cy(a,n)&&(a=K(-a,n)),{isValid:l||u,value:a}}const yb=/* @__PURE__ */ Ay(mb.p,{isLE:!0}),bb=/* @__PURE__ */ Ay(mb.n,{isLE:!0}),xb=/* @__PURE__ */ sb({...mb,Fp:yb,hash:Nt,adjustScalarBytes:gb,uvRatio:vb}),Sb=_b,Cb=/* @__PURE__ */ BigInt(`25063068953384623474111414158702152701244531502492656460079210482610430750235`),wb=/* @__PURE__ */ BigInt(`54469307008909316920995813868745141605393597292927456921205312896311721017578`),Tb=/* @__PURE__ */ BigInt(`1159843021668779879193775521855586647937357759715417654439879720876111806838`),Eb=/* @__PURE__ */ BigInt(`40440834346308536858101042469323190826248399146238708352240133220865137265952`),Db=e=>vb(lb,e),Ob=/* @__PURE__ */ BigInt(`0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),kb=e=>xb.Point.Fp.create(Kv(e)&Ob);function Ab(e){let{d:t}=mb,n=pb,r=e=>yb.create(e),i=r(Sb*e*e),a=r((i+lb)*Tb),o=BigInt(-1),s=r((o-t*i)*r(i+t)),{isValid:c,value:l}=vb(a,s),u=r(l*e);Cy(u,n)||(u=r(-u)),c||(l=u),c||(o=i);let d=r(o*(i-lb)*Eb-s),f=l*l,p=r((l+l)*s),m=r(d*Cb),h=r(lb-f),g=r(lb+f);return new xb.Point(r(p*g),r(h*m),r(m*g),r(p*h))}function jb(e){Se(e,64);let t=Ab(kb(e.subarray(0,32))),n=Ab(kb(e.subarray(32,64)));return new Mb(t.add(n))}var Mb=class e extends rb{constructor(e){super(e)}static fromAffine(t){return new e(xb.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw Error(`RistrettoPoint expected`)}init(t){return new e(t)}static hashToCurve(e){return jb(W(`ristrettoHash`,e,64))}static fromBytes(t){Se(t,32);let{a:n,d:r}=mb,i=pb,a=e=>yb.create(e),o=kb(t);if(!Xv(yb.toBytes(o),t)||Cy(o,i))throw Error(`invalid ristretto255 encoding 1`);let s=a(o*o),c=a(lb+n*s),l=a(lb-n*s),u=a(c*c),d=a(l*l),f=a(n*r*u-d),{isValid:p,value:m}=Db(a(f*d)),h=a(m*l),g=a(m*h*f),_=a((o+o)*h);Cy(_,i)&&(_=a(-_));let v=a(c*g),y=a(_*v);if(!p||Cy(y,i)||v===cb)throw Error(`invalid ristretto255 encoding 2`);return new e(new xb.Point(_,v,lb,y))}static fromHex(t){return e.fromBytes(W(`ristrettoHex`,t,32))}static msm(t,n){return Yy(e,xb.Point.Fn,t,n)}toBytes(){let{X:e,Y:t,Z:n,T:r}=this.ep,i=pb,a=e=>yb.create(e),o=a(a(n+t)*a(n-t)),s=a(e*t),c=a(s*s),{value:l}=Db(a(o*c)),u=a(l*o),d=a(l*s),f=a(u*d*r),p;if(Cy(r*f,i)){let n=a(t*Sb),r=a(e*Sb);e=n,t=r,p=a(u*wb)}else p=d;Cy(e*f,i)&&(t=a(-t));let m=a((n-t)*p);return Cy(m,i)&&(m=a(-m)),yb.toBytes(m)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:r,Y:i}=e.ep,a=e=>yb.create(e),o=a(t*i)===a(n*r),s=a(n*i)===a(t*r);return o||s}is0(){return this.equals(e.ZERO)}};Mb.BASE=/* @__PURE__ */ new Mb(xb.Point.BASE),Mb.ZERO=/* @__PURE__ */ new Mb(xb.Point.ZERO),Mb.Fp=yb,Mb.Fn=bb;function Nb(e){return xb.utils.toMontgomery(W(`pub`,e))}var Pb=/* @__PURE__ */ s(((e,t)=>{function n(e){if(e.length>=255)throw TypeError(`Alphabet too long`);for(var t=/* @__PURE__ */ new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var r=0;r<e.length;r++){var i=e.charAt(r),a=i.charCodeAt(0);if(t[a]!==255)throw TypeError(i+` is ambiguous`);t[a]=r}var o=e.length,s=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function u(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;for(var n=0,r=0,i=0,a=t.length;i!==a&&t[i]===0;)i++,n++;for(var c=(a-i)*l+1>>>0,u=new Uint8Array(c);i!==a;){for(var d=t[i],f=0,p=c-1;(d!==0||f<r)&&p!==-1;p--,f++)d+=256*u[p]>>>0,u[p]=d%o>>>0,d=d/o>>>0;if(d!==0)throw Error(`Non-zero carry`);r=f,i++}for(var m=c-r;m!==c&&u[m]===0;)m++;for(var h=s.repeat(n);m<c;++m)h+=e.charAt(u[m]);return h}function d(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return/* @__PURE__ */ new Uint8Array;var n=0;if(e[n]!==` `){for(var r=0,i=0;e[n]===s;)r++,n++;for(var a=(e.length-n)*c+1>>>0,l=new Uint8Array(a);e[n];){var u=t[e.charCodeAt(n)];if(u===255)return;for(var d=0,f=a-1;(u!==0||d<i)&&f!==-1;f--,d++)u+=o*l[f]>>>0,l[f]=u%256>>>0,u=u/256>>>0;if(u!==0)throw Error(`Non-zero carry`);i=d,n++}if(e[n]!==` `){for(var p=a-i;p!==a&&l[p]===0;)p++;for(var m=new Uint8Array(r+(a-p)),h=r;p!==a;)m[h++]=l[p++];return m}}}function f(e){var t=d(e);if(t)return t;throw Error(`Non-base`+o+` character`)}return{encode:u,decodeUnsafe:d,decode:f}}t.exports=n})),Fb=/* @__PURE__ */ s(((e,t)=>{let n=new TextDecoder,r=e=>n.decode(e),i=new TextEncoder,a=e=>i.encode(e);function o(e,t){let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}t.exports={decodeText:r,encodeText:a,concat:o}})),Ib=/* @__PURE__ */ s(((e,t)=>{let{encodeText:n}=Fb();t.exports=class{constructor(e,t,r,i){this.name=e,this.code=t,this.codeBuf=n(this.code),this.alphabet=i,this.codec=r(i)}encode(e){return this.codec.encode(e)}decode(e){for(let t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}}})),Lb=/* @__PURE__ */ s(((e,t)=>{let n=(e,t,n)=>{let r={};for(let e=0;e<t.length;++e)r[t[e]]=e;let i=e.length;for(;e[i-1]===`=`;)--i;let a=new Uint8Array(i*n/8|0),o=0,s=0,c=0;for(let t=0;t<i;++t){let i=r[e[t]];if(i===void 0)throw SyntaxError(`Invalid character `+e[t]);s=s<<n|i,o+=n,o>=8&&(o-=8,a[c++]=255&s>>o)}if(o>=n||255&s<<8-o)throw SyntaxError(`Unexpected end of data`);return a},r=(e,t,n)=>{let r=t[t.length-1]===`=`,i=(1<<n)-1,a=``,o=0,s=0;for(let r=0;r<e.length;++r)for(s=s<<8|e[r],o+=8;o>n;)o-=n,a+=t[i&s>>o];if(o&&(a+=t[i&s<<n-o]),r)for(;a.length*n&7;)a+=`=`;return a};t.exports={rfc4648:e=>t=>({encode(n){return r(n,t,e)},decode(r){return n(r,t,e)}})}})),Rb=/* @__PURE__ */ s(((e,t)=>{let n=Pb(),r=Ib(),{rfc4648:i}=Lb(),{decodeText:a,encodeText:o}=Fb(),s=[[`identity`,`\0`,()=>({encode:a,decode:o}),``],[`base2`,`0`,i(1),`01`],[`base8`,`7`,i(3),`01234567`],[`base10`,`9`,n,`0123456789`],[`base16`,`f`,i(4),`0123456789abcdef`],[`base16upper`,`F`,i(4),`0123456789ABCDEF`],[`base32hex`,`v`,i(5),`0123456789abcdefghijklmnopqrstuv`],[`base32hexupper`,`V`,i(5),`0123456789ABCDEFGHIJKLMNOPQRSTUV`],[`base32hexpad`,`t`,i(5),`0123456789abcdefghijklmnopqrstuv=`],[`base32hexpadupper`,`T`,i(5),`0123456789ABCDEFGHIJKLMNOPQRSTUV=`],[`base32`,`b`,i(5),`abcdefghijklmnopqrstuvwxyz234567`],[`base32upper`,`B`,i(5),`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`],[`base32pad`,`c`,i(5),`abcdefghijklmnopqrstuvwxyz234567=`],[`base32padupper`,`C`,i(5),`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=`],[`base32z`,`h`,i(5),`ybndrfg8ejkmcpqxot1uwisza345h769`],[`base36`,`k`,n,`0123456789abcdefghijklmnopqrstuvwxyz`],[`base36upper`,`K`,n,`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`],[`base58btc`,`z`,n,`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`],[`base58flickr`,`Z`,n,`123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ`],[`base64`,`m`,i(6),`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`],[`base64pad`,`M`,i(6),`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=`],[`base64url`,`u`,i(6),`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`],[`base64urlpad`,`U`,i(6),`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=`]],c=s.reduce((e,t)=>(e[t[0]]=new r(t[0],t[1],t[2],t[3]),e),{});t.exports={names:c,codes:s.reduce((e,t)=>(e[t[1]]=c[t[0]],e),{})}})),zb=/* @__PURE__ */ s(((e,t)=>{let n=Rb(),{encodeText:r,decodeText:i,concat:a}=Fb();function o(e,t){if(!t)throw Error(`requires an encoded Uint8Array`);let{name:n,codeBuf:r}=d(e);return u(n,t),a([r,t],r.length+t.length)}function s(e,t){let n=d(e),i=r(n.encode(t));return a([n.codeBuf,i],n.codeBuf.length+i.length)}function c(e){e instanceof Uint8Array&&(e=i(e));let t=e[0];return[`f`,`F`,`v`,`V`,`t`,`T`,`b`,`B`,`c`,`C`,`h`,`k`,`K`].includes(t)&&(e=e.toLowerCase()),d(e[0]).decode(e.substring(1))}function l(e){if(e instanceof Uint8Array&&(e=i(e)),Object.prototype.toString.call(e)!==`[object String]`)return!1;try{return d(e[0]).name}catch{return!1}}function u(e,t){d(e).decode(i(t))}function d(e){if(Object.prototype.hasOwnProperty.call(n.names,e))return n.names[e];if(Object.prototype.hasOwnProperty.call(n.codes,e))return n.codes[e];throw Error(`Unsupported encoding: ${e}`)}function f(e){return e instanceof Uint8Array&&(e=i(e)),d(e[0])}e=t.exports=o,e.encode=s,e.decode=c,e.isEncoded=l,e.encoding=d,e.encodingFromData=f;let p=Object.freeze(n.names),m=Object.freeze(n.codes);e.names=p,e.codes=m})),Bb,Vb,Hb=o((()=>{qe(),Bb=class extends Ke{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,Ce(e);let n=Le(t);if(this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),De(i)}update(e){return we(this),this.iHash.update(e),this}digestInto(e){we(this),Se(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Vb=(e,t,n)=>new Bb(e,t).update(n).digest(),Vb.create=(e,t)=>new Bb(e,t)})),Ub=zb();Hb(),qe();
126
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
127
+ const Wb=(e,t)=>(e+(e>=0?t:-t)/Zb)/t;function Gb(e,t,n){let[[r,i],[a,o]]=t,s=Wb(o*e,n),c=Wb(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<Yb,f=u<Yb;d&&(l=-l),f&&(u=-u);let p=ny(Math.ceil(ty(n)/2))+Xb;if(l<Yb||l>=p||u<Yb||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Kb(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function qb(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return Vv(n.lowS,`lowS`),Vv(n.prehash,`prehash`),n.format!==void 0&&Kb(n.format),n}const Jb={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Jb;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=Uv(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?Uv(i.length/2|128):``;return Uv(e)+a+i+t},decode(e,t){let{Err:n}=Jb,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Jb;if(e<Yb)throw new t(`integer: negative integers are not allowed`);let n=Uv(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Jb;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return Gv(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=Jb,i=W(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=Jb,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Yb=BigInt(0),Xb=BigInt(1),Zb=BigInt(2),Qb=BigInt(3),$b=BigInt(4);function ex(e,t){let{BYTES:n}=e,r;if(typeof t==`bigint`)r=t;else{let i=W(`private key`,t);try{r=e.fromBytes(i)}catch{throw Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw Error(`invalid private key: out of range [1..N-1]`);return r}function tx(e,t={}){let n=Zy(`weierstrass`,e,t),{Fp:r,Fn:i}=n,a=n.CURVE,{h:o,n:s}=a;iy(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,wrapPrivateKey:`boolean`});let{endo:c}=t;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let l=rx(r,i);function u(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function d(e,t,n){let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return Vv(n,`isCompressed`),n?(u(),Re(nx(!r.isOdd(a)),o)):Re(Uint8Array.of(4),o,r.toBytes(a))}function f(e){Hv(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=l,i=e.length,a=e[0],o=e.subarray(1);if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=h(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}u();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!g(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let p=t.toBytes||d,m=t.fromBytes||f;function h(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function g(e,t){let n=r.sqr(t),i=h(e);return r.eql(n,i)}if(!g(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let _=r.mul(r.pow(a.a,Qb),$b),v=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(_,v)))throw Error(`bad curve params: a or b`);function y(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function b(e){if(!(e instanceof T))throw Error(`ProjectivePoint expected`)}function x(e){if(!c||!c.basises)throw Error(`no endo`);return Gb(e,c.basises,i.ORDER)}let S=oy((e,t)=>{let{X:n,Y:i,Z:a}=e;if(r.eql(a,r.ONE))return{x:n,y:i};let o=e.is0();t??=o?r.ONE:r.inv(a);let s=r.mul(n,t),c=r.mul(i,t),l=r.mul(a,t);if(o)return{x:r.ZERO,y:r.ZERO};if(!r.eql(l,r.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),C=oy(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!g(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function w(e,t,n,i,a){return n=new T(r.mul(n.X,e),n.Y,n.Z),t=Iy(i,t),n=Iy(a,n),t.add(n)}class T{constructor(e,t,n){this.X=y(`x`,e),this.Y=y(`y`,t,!0),this.Z=y(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof T)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?T.ZERO:new T(t,n,r.ONE)}static fromBytes(e){let t=T.fromAffine(m(Hv(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return T.fromBytes(W(`pointHex`,e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return te.createCache(this,e),t||this.multiply(Qb),this}assertValidity(){C(this)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){b(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new T(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=a,n=r.mul(t,Qb),{X:i,Y:o,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(o,o),p=r.mul(s,s),m=r.mul(i,o);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(o,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new T(c,l,u)}add(e){b(e);let{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=a.a,p=r.mul(a.b,Qb),m=r.mul(t,o),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(o,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(o,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new T(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(T.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,a,o=e=>te.cached(this,e,e=>Ly(T,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=x(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=w(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return Ly(T,[r,a])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!i.isValid(e))throw Error(`invalid scalar: out of range`);if(e===Yb||r.is0())return T.ZERO;if(e===Xb)return r;if(te.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=x(e),{p1:s,p2:c}=Jy(T,r,i,o);return w(n.beta,s,c,t,a)}return te.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){let r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return S(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return o===Xb?!0:e?e(T,this):te.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===Xb?this:e?e(T,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(e=!0){return Vv(e,`isCompressed`),this.assertValidity(),p(T,this,e)}toHex(e=!0){return Ne(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Ly(T,e)}static msm(e,t){return Yy(T,i,e,t)}static fromPrivateKey(e){return T.BASE.multiply(ex(i,e))}}T.BASE=new T(a.Gx,a.Gy,r.ONE),T.ZERO=new T(r.ZERO,r.ONE,r.ZERO),T.Fp=r,T.Fn=i;let ee=i.BITS,te=new qy(T,t.endo?Math.ceil(ee/2):ee);return T.BASE.precompute(8),T}function nx(e){return Uint8Array.of(e?2:3)}function rx(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ix(e,t={}){let{Fn:n}=e,r=t.randomBytes||Be,i=Object.assign(rx(e.Fp,n),{seed:My(n.ORDER)});function a(e){try{return!!ex(n,e)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e=r(i.seed)){return Ny(Hv(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(ex(n,t)).toBytes(r)}function l(e){let t=s(e);return{secretKey:t,publicKey:c(t)}}function u(t){if(typeof t==`bigint`)return!1;if(t instanceof e)return!0;let{secretKey:r,publicKey:a,publicKeyUncompressed:o}=i;if(n.allowedLengths||r===a)return;let s=W(`key`,t).length;return s===a||s===o}function d(t,r,i=!0){if(u(t)===!0)throw Error(`first arg must be private key`);if(u(r)===!1)throw Error(`second arg must be public key`);let a=ex(n,t);return e.fromHex(r).multiply(a).toBytes(i)}return Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:l,Point:e,utils:{isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s,isValidPrivateKey:a,randomPrivateKey:s,normPrivateKeyToScalar:e=>ex(n,e),precompute(t=8,n=e.BASE){return n.precompute(t,!1)}},lengths:i})}function ax(e,t,n={}){Ce(t),iy(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let r=n.randomBytes||Be,i=n.hmac||((e,...n)=>Vb(t,e,Re(...n))),{Fp:a,Fn:o}=e,{ORDER:s,BITS:c}=o,{keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:p}=ix(e,n),m={prehash:!1,lowS:typeof n.lowS==`boolean`&&n.lowS,format:void 0,extraEntropy:!1},h=`compact`;function g(e){return e>s>>Xb}function _(e,t){if(!o.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function v(e,t){Kb(t);let n=p.signature;return Hv(e,t===`compact`?n:t===`recovered`?n+1:void 0,`${t} signature`)}class y{constructor(e,t,n){this.r=_(`r`,e),this.s=_(`s`,t),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=h){v(e,t);let n;if(t===`der`){let{r:t,s:n}=Jb.toSig(Hv(e));return new y(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=o.BYTES,i=e.subarray(0,r),a=e.subarray(r,r*2);return new y(o.fromBytes(i),o.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(Fe(e),t)}addRecoveryBit(e){return new y(this.r,this.s,e)}recoverPublicKey(t){let n=a.ORDER,{r,s:i,recovery:c}=this;if(c==null||![0,1,2,3].includes(c))throw Error(`recovery id invalid`);if(s*Zb<n&&c>1)throw Error(`recovery id is ambiguous for h>1 curve`);let l=c===2||c===3?r+s:r;if(!a.isValid(l))throw Error(`recovery id 2 or 3 invalid`);let u=a.toBytes(l),d=e.fromBytes(Re(nx(!(c&1)),u)),f=o.inv(l),p=x(W(`msgHash`,t)),m=o.create(-p*f),h=o.create(i*f),g=e.BASE.multiplyUnsafe(m).add(d.multiplyUnsafe(h));if(g.is0())throw Error(`point at infinify`);return g.assertValidity(),g}hasHighS(){return g(this.s)}toBytes(e=h){if(Kb(e),e===`der`)return Fe(Jb.hexFromSig(this));let t=o.toBytes(this.r),n=o.toBytes(this.s);if(e===`recovered`){if(this.recovery==null)throw Error(`recovery bit must be present`);return Re(Uint8Array.of(this.recovery),t,n)}return Re(t,n)}toHex(e){return Ne(this.toBytes(e))}assertValidity(){}static fromCompact(e){return y.fromBytes(W(`sig`,e),`compact`)}static fromDER(e){return y.fromBytes(W(`sig`,e),`der`)}normalizeS(){return this.hasHighS()?new y(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes(`der`)}toDERHex(){return Ne(this.toBytes(`der`))}toCompactRawBytes(){return this.toBytes(`compact`)}toCompactHex(){return Ne(this.toBytes(`compact`))}}let b=n.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=Gv(e),n=e.length*8-c;return n>0?t>>BigInt(n):t},x=n.bits2int_modN||function(e){return o.create(b(e))},S=ny(c);function C(e){return ey(`num < 2^`+c,e,Yb,S),o.toBytes(e)}function w(e,n){return Hv(e,void 0,`message`),n?Hv(t(e),void 0,`prehashed message`):e}function T(t,n,i){if([`recovered`,`canonical`].some(e=>e in i))throw Error(`sign() legacy options not supported`);let{lowS:a,prehash:s,extraEntropy:c}=qb(i,m);t=w(t,s);let l=x(t),u=ex(o,n),d=[C(u),C(l)];if(c!=null&&c!==!1){let e=c===!0?r(p.secretKey):c;d.push(W(`extraEntropy`,e))}let f=Re(...d),h=l;function _(t){let n=b(t);if(!o.isValidNot0(n))return;let r=o.inv(n),i=e.BASE.multiply(n).toAffine(),s=o.create(i.x);if(s===Yb)return;let c=o.create(r*o.create(h+s*u));if(c===Yb)return;let l=(i.x===s?0:2)|Number(i.y&Xb),d=c;return a&&g(c)&&(d=o.neg(c),l^=1),new y(s,d,l)}return{seed:f,k2sig:_}}function ee(e,n,r={}){e=W(`message`,e);let{seed:a,k2sig:s}=T(e,n,r);return ry(t.outputLen,o.BYTES,i)(a,s)}function te(e){let t,n=typeof e==`string`||be(e),r=!n&&typeof e==`object`&&!!e&&typeof e.r==`bigint`&&typeof e.s==`bigint`;if(!n&&!r)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);if(r)t=new y(e.r,e.s);else if(n){try{t=y.fromBytes(W(`sig`,e),`der`)}catch(e){if(!(e instanceof Jb.Err))throw e}if(!t)try{t=y.fromBytes(W(`sig`,e),`compact`)}catch{return!1}}return t||!1}function ne(t,n,r,i={}){let{lowS:a,prehash:s,format:c}=qb(i,m);if(r=W(`publicKey`,r),n=w(W(`message`,n),s),`strict`in i)throw Error(`options.strict was renamed to lowS`);let l=c===void 0?te(t):y.fromBytes(W(`sig`,t),c);if(l===!1)return!1;try{let t=e.fromBytes(r);if(a&&l.hasHighS())return!1;let{r:i,s}=l,c=x(n),u=o.inv(s),d=o.create(c*u),f=o.create(i*u),p=e.BASE.multiplyUnsafe(d).add(t.multiplyUnsafe(f));return!p.is0()&&o.create(p.x)===i}catch{return!1}}function re(e,t,n={}){let{prehash:r}=qb(n,m);return t=w(t,r),y.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:p,Point:e,sign:ee,verify:ne,recoverPublicKey:re,Signature:y,hash:t})}function ox(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:Ay(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function sx(e){let{CURVE:t,curveOpts:n}=ox(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function cx(e,t){let n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,ky(n.Fn.ORDER,n.Fn.BITS))})}function lx(e){let{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=sx(e);return cx(e,ax(tx(t,n),r,i))}
128
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
129
+ function ux(e,t){let n=t=>lx({...e,hash:t});return{...n(t),create:n}}Ft();
130
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
131
+ const dx={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f`),n:BigInt(`0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141`),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt(`0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798`),Gy:BigInt(`0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8`)},fx={beta:BigInt(`0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee`),basises:[[BigInt(`0x3086d221a7d46bcde86c90e49284eb15`),-BigInt(`0xe4437ed6010e88286f547fa90abfe4c3`)],[BigInt(`0x114ca50f7a8e2f3f657c1108d9d44cfd8`),BigInt(`0x3086d221a7d46bcde86c90e49284eb15`)]]},px=/* @__PURE__ */ BigInt(2);function mx(e){let t=dx.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),s=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=q(q(q(u,n,t)*u%t,n,t)*u%t,px,t)*l%t,f=q(d,i,t)*d%t,p=q(f,a,t)*f%t,m=q(p,s,t)*p%t,h=q(q(q(q(q(q(m,c,t)*m%t,s,t)*p%t,n,t)*u%t,o,t)*f%t,r,t)*l%t,px,t);if(!hx.eql(hx.sqr(h),e))throw Error(`Cannot find square root`);return h}const hx=Ay(dx.p,{sqrt:mx}),gx=ux({...dx,Fp:hx,lowS:!0,endo:fx},Mt);Ft();
132
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
133
+ const _x={p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)},vx={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff`),n:BigInt(`0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973`),h:BigInt(1),a:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc`),b:BigInt(`0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef`),Gx:BigInt(`0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7`),Gy:BigInt(`0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f`)},yx={p:BigInt(`0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),n:BigInt(`0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409`),h:BigInt(1),a:BigInt(`0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc`),b:BigInt(`0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00`),Gx:BigInt(`0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66`),Gy:BigInt(`0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650`)},bx=Ay(_x.p),xx=Ay(vx.p),Sx=Ay(yx.p),Cx=ux({..._x,Fp:bx,lowS:!1},Mt),wx=ux({...vx,Fp:xx,lowS:!1},Pt),Tx=ux({...yx,Fp:Sx,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},Nt),Ex=Cx
134
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
135
+ ;Ft();const Dx=Mt;$e(),qe();const Ox=/* @__PURE__ */ Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),kx=/* @__PURE__ */ Uint8Array.from(Array(16).fill(0).map((e,t)=>t)),Ax=/* @__PURE__ */ kx.map(e=>(9*e+5)%16),jx=/* @__PURE__ */ (()=>{let e=[[kx],[Ax]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Ox[e]));return e})(),Mx=jx[0],Nx=jx[1],Px=/* @__PURE__ */ [[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Fx=/* @__PURE__ */ Mx.map((e,t)=>e.map(e=>Px[t][e])),Ix=/* @__PURE__ */ Nx.map((e,t)=>e.map(e=>Px[t][e])),Lx=/* @__PURE__ */ Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Rx=/* @__PURE__ */ Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function zx(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const Bx=/* @__PURE__ */ new Uint32Array(16);var Vx=class extends Ze{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=e|0,this.h1=t|0,this.h2=n|0,this.h3=r|0,this.h4=i|0}process(e,t){for(let n=0;n<16;n++,t+=4)Bx[n]=e.getUint32(t,!0);let n=this.h0|0,r=n,i=this.h1|0,a=i,o=this.h2|0,s=o,c=this.h3|0,l=c,u=this.h4|0,d=u;for(let e=0;e<5;e++){let t=4-e,f=Lx[e],p=Rx[e],m=Mx[e],h=Nx[e],g=Fx[e],_=Ix[e];for(let t=0;t<16;t++){let r=Ae(n+zx(e,i,o,c)+Bx[m[t]]+f,g[t])+u|0;n=u,u=c,c=Ae(o,10)|0,o=i,i=r}for(let e=0;e<16;e++){let n=Ae(r+zx(t,a,s,l)+Bx[h[e]]+p,_[e])+d|0;r=d,d=l,l=Ae(s,10)|0,s=a,a=n}}this.set(this.h1+o+l|0,this.h2+c+d|0,this.h3+u+r|0,this.h4+n+a|0,this.h0+i+s|0)}roundClean(){De(Bx)}destroy(){this.destroyed=!0,De(this.buffer),this.set(0,0,0,0,0)}};const Hx=/* @__PURE__ */ ze(()=>new Vx);function Ux(e,t=24){let n=/* @__PURE__ */ new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let r=(t+8)%10,i=(t+2)%10,a=n[i],o=n[i+1],s=nS(a,o,1)^n[r],c=rS(a,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){let r=Zx[n],a=nS(t,i,r),o=rS(t,i,r),s=Xx[n];t=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=eS[r],e[1]^=tS[r]}De(n)}var Wx,Gx,Kx,qx,Jx,Yx,Xx,Zx,Qx,$x,eS,tS,nS,rS,iS,aS,oS,sS=o((()=>{xt(),qe(),Wx=BigInt(0),Gx=BigInt(1),Kx=BigInt(2),qx=BigInt(7),Jx=BigInt(256),Yx=BigInt(113),Xx=[],Zx=[],Qx=[];for(let e=0,t=Gx,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Xx.push(2*(5*r+n)),Zx.push((e+1)*(e+2)/2%64);let i=Wx;for(let e=0;e<7;e++)t=(t<<Gx^(t>>qx)*Yx)%Jx,t&Kx&&(i^=Gx<<(Gx<</* @__PURE__ */ BigInt(e))-Gx);Qx.push(i)}$x=tt(Qx,!0),eS=$x[0],tS=$x[1],nS=(e,t,n)=>n>32?pt(e,t,n):dt(e,t,n),rS=(e,t,n)=>n>32?mt(e,t,n):ft(e,t,n),iS=class e extends Ke{constructor(e,t,n,r=!1,i=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=i,xe(n),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=/* @__PURE__ */ new Uint8Array(200),this.state32=Ee(this.state)}clone(){return this._cloneInto()}keccak(){He(this.state32),Ux(this.state32,this.rounds),He(this.state32),this.posOut=0,this.pos=0}update(e){we(this),e=Le(e),Se(e);let{blockLen:t,state:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(t-this.pos,r-i);for(let t=0;t<a;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){we(this,!1),Se(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return xe(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Te(e,this),this.finished)throw Error(`digest() was already called`);return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,De(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||=new e(n,r,i,o,a),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}},aS=(e,t,n)=>ze(()=>new iS(t,e,n)),oS=/* @__PURE__ */ aS(1,136,32)})),cS=/* @__PURE__ */ s(((e,t)=>{t.exports=function e(t){if(typeof t==`number`&&isNaN(t))throw Error(`NaN is not allowed`);if(typeof t==`number`&&!isFinite(t))throw Error(`Infinity is not allowed`);return typeof t!=`object`||!t?JSON.stringify(t):t.toJSON instanceof Function?e(t.toJSON()):Array.isArray(t)?`[${t.reduce((t,n,r)=>`${t}${r===0?``:`,`}${e(n===void 0||typeof n==`symbol`?null:n)}`,``)}]`:`{${Object.keys(t).sort().reduce((n,r)=>t[r]===void 0||typeof t[r]==`symbol`?n:`${n}${n.length===0?``:`,`}${e(r)}:${e(t[r])}`,``)}}`}}));sS();var lS=/* @__PURE__ */ u(cS(),1);function uS(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function dS(){let e=/* @__PURE__ */ new Map;return function(t,n){try{let r;function i(i){if(r)return i;let a=e.get(t.didUrl);return a===void 0?Promise.resolve(n()).then(function(n){return n.didResolutionMetadata?.error!==`notFound`&&e.set(t.didUrl,n),n}):a}let a=function(){if(t.params&&t.params[`no-cache`]===`true`)return Promise.resolve(n()).then(function(e){return r=1,e})}();return Promise.resolve(a&&a.then?a.then(i):i(a))}catch(e){return Promise.reject(e)}}}function fS(e,t){return t()}const pS=`(?:[a-zA-Z0-9._-]|(?:%[0-9a-fA-F]{2}))`,mS=`((?:${pS}*:)*(${pS}+))`,hS=`[a-zA-Z0-9_.:%-]`,gS=RegExp(`^did:([a-z0-9]+):${mS}${`((${`;${hS}+=${hS}*`})*)`}(/[^#?]*)?([?][^#]*)?(#.*)?$`);function _S(e){if(e===``||!e)return null;let t=e.match(gS);if(t){let n={did:`did:${t[1]}:${t[2]}`,method:t[1],id:t[2],didUrl:e};if(t[4]){let e=t[4].slice(1).split(`;`);n.params={};for(let t of e){let e=t.split(`=`);n.params[e[0]]=e[1]}}return t[6]&&(n.path=t[6]),t[7]&&(n.query=t[7].slice(1)),t[8]&&(n.fragment=t[8].slice(1)),n}return null}const vS={didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};function yS(e){return function(t,n,r){try{return Promise.resolve(uS(function(){return Promise.resolve(e(t,n,r)).then(function(e){return{...vS,didResolutionMetadata:{contentType:`application/did+ld+json`},didDocument:e}})},function(e){return{...vS,didResolutionMetadata:{error:`notFound`,message:e.toString()}}}))}catch(e){return Promise.reject(e)}}}var bS=class{constructor(e={},t={}){this.registry=void 0,this.cache=void 0,this.registry=e,this.cache=t.cache===!0?dS():t.cache||fS,t.legacyResolvers&&Object.keys(t.legacyResolvers).map(e=>{this.registry[e]||(this.registry[e]=yS(t.legacyResolvers[e]))})}resolve(e,t={}){try{let n=this,r=_S(e);if(r===null)return Promise.resolve({...vS,didResolutionMetadata:{error:`invalidDid`}});let i=n.registry[r.method];return i?Promise.resolve(n.cache(r,()=>i(r.did,r,n,t))):Promise.resolve({...vS,didResolutionMetadata:{error:`unsupportedDidMethod`}})}catch(e){return Promise.reject(e)}}};
136
+ /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
137
+ function xS(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function SS(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(e=>typeof e==`string`):t.every(e=>Number.isSafeInteger(e)):!1}function CS(e){if(typeof e!=`function`)throw Error(`function expected`);return!0}function wS(e,t){if(typeof t!=`string`)throw Error(`${e}: string expected`);return!0}function TS(e){if(!Number.isSafeInteger(e))throw Error(`invalid integer: ${e}`)}function ES(e){if(!Array.isArray(e))throw Error(`array expected`)}function DS(e,t){if(!SS(!0,t))throw Error(`${e}: array of strings expected`)}function OS(e,t){if(!SS(!1,t))throw Error(`${e}: array of numbers expected`)}function kS(...e){let t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function AS(e){let t=typeof e==`string`?e.split(``):e,n=t.length;DS(`alphabet`,t);let r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(ES(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(ES(t),t.map(t=>{wS(`alphabet.decode`,t);let n=r.get(t);if(n===void 0)throw Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function jS(e=``){return wS(`join`,e),{encode:t=>(DS(`join.decode`,t),t.join(e)),decode:t=>(wS(`join.decode`,t),t.split(e))}}function MS(e,t=`=`){return TS(e),wS(`padding`,t),{encode(n){for(DS(`padding.encode`,n);n.length*e%8;)n.push(t);return n},decode(n){DS(`padding.decode`,n);let r=n.length;if(r*e%8)throw Error(`padding: invalid, string should have whole number of bytes`);for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw Error(`padding: invalid, string has too much padding`);return n.slice(0,r)}}}function NS(e){return CS(e),{encode:e=>e,decode:t=>e(t)}}const PS=(e,t)=>t===0?e:PS(t,e%t),FS=/* @__NO_SIDE_EFFECTS__ */ (e,t)=>e+(t-PS(e,t)),IS=/* @__PURE__ */ (()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function LS(e,t,n,r){if(ES(e),t<=0||t>32)throw Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw Error(`convertRadix2: wrong to=${n}`);if(/* @__PURE__ */ FS(t,n)>32)throw Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${/* @__PURE__ */ FS(t,n)}`);let i=0,a=0,o=IS[t],s=IS[n]-1,c=[];for(let r of e){if(TS(r),r>=o)throw Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,a+t>32)throw Error(`convertRadix2: carry overflow pos=${a} from=${t}`);for(a+=t;a>=n;a-=n)c.push((i>>a-n&s)>>>0);let e=IS[a];if(e===void 0)throw Error(`invalid carry`);i&=e-1}if(i=i<<n-a&s,!r&&a>=t)throw Error(`Excess padding`);if(!r&&i>0)throw Error(`Non-zero padding: ${i}`);return r&&a>0&&c.push(i>>>0),c}function RS(e,t=!1){if(TS(e),e<=0||e>32)throw Error(`radix2: bits should be in (0..32]`);if(/* @__PURE__ */ FS(8,e)>32||/* @__PURE__ */ FS(e,8)>32)throw Error(`radix2: carry overflow`);return{encode:n=>{if(!xS(n))throw Error(`radix2.encode input should be Uint8Array`);return LS(Array.from(n),8,e,!t)},decode:n=>(OS(`radix2.decode`,n),Uint8Array.from(LS(n,e,8,t)))}}function zS(e){return CS(e),function(...t){try{return e.apply(null,t)}catch{}}}kS(RS(4),AS(`0123456789ABCDEF`),jS(``)),kS(RS(5),AS(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),MS(5),jS(``)),kS(RS(5),AS(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),jS(``)),kS(RS(5),AS(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),MS(5),jS(``)),kS(RS(5),AS(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),jS(``)),kS(RS(5),AS(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`),jS(``),NS(e=>e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`)));const BS=typeof Uint8Array.from([]).toBase64==`function`&&typeof Uint8Array.fromBase64==`function`;BS||kS(RS(6),AS(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),MS(6),jS(``)),kS(RS(6),AS(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),jS(``)),BS||kS(RS(6),AS(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),MS(6),jS(``)),kS(RS(6),AS(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),jS(``));const VS=kS(AS(`qpzry9x8gf2tvdw0s3jn54khce6mua7l`),jS(``)),HS=[996825010,642813549,513874426,1027748829,705979059];function US(e){let t=e>>25,n=(e&33554431)<<5;for(let e=0;e<HS.length;e++)(t>>e&1)==1&&(n^=HS[e]);return n}function WS(e,t,n=1){let r=e.length,i=1;for(let t=0;t<r;t++){let n=e.charCodeAt(t);if(n<33||n>126)throw Error(`Invalid prefix (${e})`);i=US(i)^n>>5}i=US(i);for(let t=0;t<r;t++)i=US(i)^e.charCodeAt(t)&31;for(let e of t)i=US(i)^e;for(let e=0;e<6;e++)i=US(i);return i^=n,VS.encode(LS([i%IS[30]],30,5,!1))}function GS(e){let t=e===`bech32`?1:734539939,n=RS(5),r=n.decode,i=n.encode,a=zS(r);function o(e,n,r=90){wS(`bech32.encode prefix`,e),xS(n)&&(n=Array.from(n)),OS(`bech32.encode`,n);let i=e.length;if(i===0)throw TypeError(`Invalid prefix length ${i}`);let a=i+7+n.length;if(r!==!1&&a>r)throw TypeError(`Length ${a} exceeds limit ${r}`);let o=e.toLowerCase(),s=WS(o,n,t);return`${o}1${VS.encode(n)}${s}`}function s(e,n=90){wS(`bech32.decode input`,e);let r=e.length;if(r<8||n!==!1&&r>n)throw TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);let i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw Error(`String must be lowercase or uppercase`);let a=i.lastIndexOf(`1`);if(a===0||a===-1)throw Error(`Letter "1" must be present between prefix and data only`);let o=i.slice(0,a),s=i.slice(a+1);if(s.length<6)throw Error(`Data must be at least 6 characters long`);let c=VS.decode(s).slice(0,-6),l=WS(o,c,t);if(!s.endsWith(l))throw Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:c}}let c=zS(s);function l(e){let{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}}function u(e,t){return o(e,i(t))}return{encode:o,decode:s,encodeFromBytes:u,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:a,toWords:i}}const KS=GS(`bech32`);GS(`bech32m`),typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`||kS(RS(4),AS(`0123456789abcdef`),jS(``),NS(e=>{if(typeof e!=`string`||e.length%2!=0)throw TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const qS={toString:Rv,fromString:Lv,concat:$g};function JS(e){return qS.toString(e,`base64url`)}function YS(e){let t=e.replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``);return qS.fromString(t,`base64url`)}function XS(e){return qS.fromString(e,`base58btc`)}function ZS(e){return qS.toString(e,`base58btc`)}const QS={ES256:[`JsonWebKey2020`,`Multikey`,`EcdsaSecp256r1VerificationKey2019`],ES256K:[`EcdsaSecp256k1VerificationKey2019`,`EcdsaSecp256k1RecoveryMethod2020`,`Secp256k1VerificationKey2018`,`Secp256k1SignatureVerificationKey2018`,`EcdsaPublicKeySecp256k1`,`JsonWebKey2020`,`Multikey`],"ES256K-R":[`EcdsaSecp256k1VerificationKey2019`,`EcdsaSecp256k1RecoveryMethod2020`,`Secp256k1VerificationKey2018`,`Secp256k1SignatureVerificationKey2018`,`EcdsaPublicKeySecp256k1`,`ConditionalProof2022`,`JsonWebKey2020`,`Multikey`],Ed25519:[`ED25519SignatureVerification`,`Ed25519VerificationKey2018`,`Ed25519VerificationKey2020`,`JsonWebKey2020`,`Multikey`],EdDSA:[`ED25519SignatureVerification`,`Ed25519VerificationKey2018`,`Ed25519VerificationKey2020`,`JsonWebKey2020`,`Multikey`]},$S={Secp256k1SignatureVerificationKey2018:`Secp256k1`,Secp256k1VerificationKey2018:`Secp256k1`,EcdsaSecp256k1VerificationKey2019:`Secp256k1`,EcdsaPublicKeySecp256k1:`Secp256k1`,EcdsaSecp256k1RecoveryMethod2020:`Secp256k1`,EcdsaSecp256r1VerificationKey2019:`P-256`,Ed25519VerificationKey2018:`Ed25519`,Ed25519VerificationKey2020:`Ed25519`,ED25519SignatureVerification:`Ed25519`,X25519KeyAgreementKey2019:`X25519`,X25519KeyAgreementKey2020:`X25519`,ConditionalProof2022:void 0,JsonWebKey2020:void 0,Multikey:void 0},eC={"ed25519-pub":237,"x25519-pub":236,"secp256k1-pub":231,"bls12_381-g1-pub":234,"bls12_381-g2-pub":235,"p256-pub":4608},tC={"bls12_381-g1-pub":`Bls12381G1`,"bls12_381-g2-pub":`Bls12381G2`,"ed25519-pub":`Ed25519`,"p256-pub":`P-256`,"secp256k1-pub":`Secp256k1`,"x25519-pub":`X25519`};function nC(e){if(e.publicKeyBase58)return{keyBytes:XS(e.publicKeyBase58),keyType:$S[e.type]};if(e.publicKeyBase64)return{keyBytes:YS(e.publicKeyBase64),keyType:$S[e.type]};if(e.publicKeyHex)return{keyBytes:iC(e.publicKeyHex),keyType:$S[e.type]};if(e.publicKeyJwk&&e.publicKeyJwk.crv===`secp256k1`&&e.publicKeyJwk.x&&e.publicKeyJwk.y)return{keyBytes:gx.ProjectivePoint.fromAffine({x:cC(YS(e.publicKeyJwk.x)),y:cC(YS(e.publicKeyJwk.y))}).toRawBytes(!1),keyType:`Secp256k1`};if(e.publicKeyJwk&&e.publicKeyJwk.crv===`P-256`&&e.publicKeyJwk.x&&e.publicKeyJwk.y)return{keyBytes:Ex.ProjectivePoint.fromAffine({x:cC(YS(e.publicKeyJwk.x)),y:cC(YS(e.publicKeyJwk.y))}).toRawBytes(!1),keyType:`P-256`};if(e.publicKeyJwk&&e.publicKeyJwk.kty===`OKP`&&[`Ed25519`,`X25519`].includes(e.publicKeyJwk.crv??``)&&e.publicKeyJwk.x)return{keyBytes:YS(e.publicKeyJwk.x),keyType:e.publicKeyJwk.crv};if(e.publicKeyMultibase){let{keyBytes:t,keyType:n}=rC(e.publicKeyMultibase);return{keyBytes:t,keyType:n??$S[e.type]}}return{keyBytes:/* @__PURE__ */ new Uint8Array}}function rC(e){let t=(0,Ub.decode)(e);if([32,33,48,64,65,96].includes(t.length))return{keyBytes:t};try{let[e,n]=vv(t),r=Object.entries(eC).filter(([,t])=>t===e)?.[0][0]??``;return{keyBytes:t.slice(n),keyType:tC[r]}}catch{return{keyBytes:t}}}function iC(e,t){let n=e.startsWith(`0x`)?e.substring(2):e;if(n.length%2!=0&&(n=`0${n}`),t){let e=Math.max(n.length,t*2);n=n.padStart(e,`00`)}return qS.fromString(n.toLowerCase(),`base16`)}function aC(e){return JS(qS.fromString(e))}function oC(e){return qS.toString(YS(e))}function sC(e){return qS.toString(e,`base16`)}function cC(e){return BigInt(`0x`+qS.toString(e,`base16`))}function lC(e){return qS.fromString(e,`utf-8`)}function uC({r:e,s:t,recoveryParam:n},r){let i=new Uint8Array(r?65:64);if(i.set(qS.fromString(e,`base16`),0),i.set(qS.fromString(t,`base16`),32),r){if(n===void 0)throw Error(`Signer did not return a recoveryParam`);i[64]=n}return JS(i)}function dC(e){let t=YS(e);if(t.length<64||t.length>65)throw TypeError(`Wrong size for signature. Expected 64 or 65 bytes, but got ${t.length}`);return{r:sC(t.slice(0,32)),s:sC(t.slice(32,64)),recoveryParam:t.length===65?t[64]:void 0}}function fC(e){let t=typeof e==`string`?Lv(e):e;return Dx(t)}const pC=oS;function mC(e){let t=Lv(e.slice(2),`base16`);return`0x${Rv(pC(t).slice(-20),`base16`)}`}function hC(e){return typeof e==`object`&&`r`in e&&`s`in e}function gC(){return function(e,t){try{return Promise.resolve(t(e)).then(function(e){return hC(e)?uC(e):e})}catch(e){return Promise.reject(e)}}}function _C(e){return function(t,n){try{return Promise.resolve(n(t)).then(function(t){if(hC(t))return uC(t,e);if(e&&dC(t).recoveryParam===void 0)throw Error(`not_supported: ES256K-R not supported when signer doesn't provide a recovery param`);return t})}catch(e){return Promise.reject(e)}}}function vC(){return function(e,t){try{return Promise.resolve(t(e)).then(function(e){if(hC(e))throw Error(`invalid_config: expected a signer function that returns a string instead of signature object`);return e})}catch(e){return Promise.reject(e)}}}const yC={ES256:gC(),ES256K:_C(),"ES256K-R":_C(!0),Ed25519:vC(),EdDSA:vC()};function bC(e){let t=yC[e];if(!t)throw Error(`not_supported: Unsupported algorithm ${e}`);return t}function xC(e,t){let n=sC(XS(t).slice(0,1)),r=iC(e),i=n+sC(Hx(fC(r)));return ZS(iC(i+sC(fC(fC(iC(i)))).substring(0,8)))}function SC(e,t){let n=gx.ProjectivePoint.fromHex(e).toRawBytes(),r=Hx(fC(n)),i=KS.toWords(r);return KS.encode(t,i).replace(t,``)}function CC(e,t){if(t){let n=t.split(`:`);switch(n[0]){case`bip122`:n[n.length-1]=xC(e,n[n.length-1]);break;case`cosmos`:n[n.length-1]=SC(e,n[1]);break;case`eip155`:n[n.length-1]=mC(e);break;default:return!1}return n.join(`:`).toLowerCase()===t.toLowerCase()}return!1}function wC(e,t=!1){let n=YS(e);if(n.length!==(t?65:64))throw Error(`wrong signature length`);let r={r:sC(n.slice(0,32)),s:sC(n.slice(32,64))};return t&&(r.recoveryParam=n[64]),r}function TC(e,t=!1){let n=YS(e);if(n.length!==(t?65:64))throw Error(`wrong signature length`);return{compact:n.slice(0,64),recovery:n[64]}}function EC(e,t,n){let r=fC(e),i=Ex.Signature.fromCompact(TC(t).compact),a=n.filter(e=>!e.ethereumAddress&&!e.blockchainAccountId).find(e=>{try{let{keyBytes:t}=nC(e);return Ex.verify(i,r,t)}catch{return!1}});if(!a)throw Error(`invalid_signature: Signature invalid for JWT`);return a}function DC(e,t,n){let r=fC(e),i=gx.Signature.fromCompact(YS(t)).normalizeS(),a=n.filter(e=>!e.ethereumAddress&&!e.blockchainAccountId),o=n.filter(e=>e.ethereumAddress||e.blockchainAccountId),s=a.find(e=>{try{let{keyBytes:t}=nC(e);return gx.verify(i,r,t)}catch{return!1}});if(!s&&o.length>0&&(s=OC(e,t,o)),!s)throw Error(`invalid_signature: Signature invalid for JWT`);return s}function OC(e,t,n){let r=[];if(t.length>86)r.push(TC(t,!0));else{let e=TC(t,!1);r.push({...e,recovery:0}),r.push({...e,recovery:1})}let i=fC(e),a=e=>{let t=gx.Signature.fromCompact(e.compact).addRecoveryBit(e.recovery||0).recoverPublicKey(i),r=mC(t.toHex(!1)).toLowerCase(),a=t.toHex(!1),o=t.toHex(!0);return n.find(e=>{let{keyBytes:t}=nC(e),n=sC(t);return n===a||n===o||e.ethereumAddress?.toLowerCase()===r||e.blockchainAccountId?.split(`@eip155`)?.[0].toLowerCase()===r||CC(a,e.blockchainAccountId)})};for(let e of r){let t=a(e);if(t)return t}throw Error(`invalid_signature: Signature invalid for JWT`)}function kC(e,t,n){let r=lC(e),i=YS(t),a=n.find(e=>{let{keyBytes:t,keyType:n}=nC(e);return n===`Ed25519`&&xb.verify(i,r,t)});if(!a)throw Error(`invalid_signature: Signature invalid for JWT`);return a}const AC={ES256:EC,ES256K:DC,"ES256K-R":OC,Ed25519:kC,EdDSA:kC};function jC(e){let t=AC[e];if(!t)throw Error(`not_supported: Unsupported algorithm ${e}`);return t}jC.toSignatureObject=wC;const Y={INVALID_JWT:`invalid_jwt`,INVALID_AUDIENCE:`invalid_config`,INVALID_SIGNATURE:`invalid_signature`,NO_SUITABLE_KEYS:`no_suitable_keys`,NOT_SUPPORTED:`not_supported`,RESOLVER_ERROR:`resolver_error`};function MC(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}const NC=function(e,{header:t,payload:n,data:r,signature:i},a,o){try{if(!a.conditionDelegated)throw Error(`Expected conditionDelegated`);if(!o.resolver)throw Error(`Expected resolver`);let s,c=a.conditionDelegated;return Promise.resolve(XC(o.resolver,t.alg,c,o.proofPurpose)).then(function(l){function u(e){if(s)return a;throw Error(`${Y.INVALID_SIGNATURE}: condition for authenticator ${a.id} is not met.`)}let d=l.didResolutionResult;if(!d?.didDocument)throw Error(`${Y.RESOLVER_ERROR}: Could not resolve delegated DID ${c}.`);let f=l.authenticators.find(e=>e.id===c);if(!f)throw Error(`${Y.NO_SUITABLE_KEYS}: Could not find delegated authenticator ${c} in it's DID Document`);let p=function(){if(f.type===UC)return Promise.resolve(ZC(e,{...o,didAuthenticator:{didResolutionResult:d,authenticators:[f],issuer:f.id}})).then(function({verified:e}){e&&(s=f)});try{s=uw({header:t,payload:n,data:r,signature:i},f)}catch(e){if(!e.message.startsWith(`invalid_signature:`))throw e}}();return p&&p.then?p.then(u):u(p)})}catch(e){return Promise.reject(e)}},PC=typeof Symbol<`u`?Symbol.iterator||(Symbol.iterator=Symbol(`Symbol.iterator`)):`@@iterator`;function FC(e,t,n){if(!e.s){if(n instanceof IC){if(n.s)t&1&&(t=n.s),n=n.v;else{n.o=FC.bind(null,e,t);return}}if(n&&n.then){n.then(FC.bind(null,e,t),FC.bind(null,e,2));return}e.s=t,e.v=n;let r=e.o;r&&r(e)}}const IC=/*#__PURE__*/ function(){function e(){}return e.prototype.then=function(t,n){let r=new e,i=this.s;if(i){let e=i&1?t:n;if(e){try{FC(r,1,e(this.v))}catch(e){FC(r,2,e)}return r}return this}return this.o=function(e){try{let i=e.v;e.s&1?FC(r,1,t?t(i):i):n?FC(r,1,n(i)):FC(r,2,i)}catch(e){FC(r,2,e)}},r},e}();function LC(e){return e instanceof IC&&e.s&1}function RC(e,t,n){var r=-1,i,a;function o(s){try{for(;++r<e.length&&(!n||!n());)if(s=t(r),s&&s.then){if(LC(s))s=s.v;else{s.then(o,a||=FC.bind(null,i=new IC,2));return}}i?FC(i,1,s):i=s}catch(e){FC(i||=new IC,2,e)}}return o(),i}const zC=function(e,{header:t,payload:n,data:r,signature:i},a,o){try{let s;function c(e){if(s)return e;throw Error(`${Y.INVALID_SIGNATURE}: condition for authenticator ${a.id} is not met.`)}if(!a.conditionWeightedThreshold||!a.threshold)throw Error(`Expected conditionWeightedThreshold and threshold`);let l=[],u=a.threshold,d=0,f=BC(a.conditionWeightedThreshold,function(c){function f(e){if(s)return e;if(m&&!l.includes(m.id)&&(l.push(m.id),d+=c.weight,d>=u))return s=1,a}let p=c.condition,m,h=MC(function(){if(p.type===UC){if(!o.didAuthenticator)throw Error(`Expected didAuthenticator`);let t={...o,didAuthenticator:{didResolutionResult:o.didAuthenticator?.didResolutionResult,authenticators:[p],issuer:p.id}};return Promise.resolve(ZC(e,t)).then(function({verified:e}){e&&(m=p)})}return Promise.resolve(uw({header:t,payload:n,data:r,signature:i},p)).then(function(e){m=e})},function(e){if(!e.message.startsWith(Y.INVALID_SIGNATURE))throw e});return h&&h.then?h.then(f):f(h)},function(){return s});return Promise.resolve(f&&f.then?f.then(c):c(f))}catch(e){return Promise.reject(e)}};function BC(e,t,n){if(typeof e[PC]==`function`){var r=e[PC](),i,a,o;function c(e){try{for(;!(i=r.next()).done&&(!n||!n());)if(e=t(i.value),e&&e.then){if(LC(e))e=e.v;else{e.then(c,o||=FC.bind(null,a=new IC,2));return}}a?FC(a,1,e):a=e}catch(e){FC(a||=new IC,2,e)}}if(c(),r.return){var s=function(e){try{i.done||r.return()}catch{}return e};if(a&&a.then)return a.then(s,function(e){throw s(e)});s()}return a}if(!(`length`in e))throw TypeError(`Object is not iterable`);for(var c=[],l=0;l<e.length;l++)c.push(e[l]);return RC(c,function(e){return t(c[e])},n)}const VC=function(e,{header:t,payload:n,signature:r,data:i},a,o){try{if(a.conditionWeightedThreshold)return zC(e,{header:t,payload:n,data:i,signature:r},a,o);if(a.conditionDelegated)return NC(e,{header:t,payload:n,data:i,signature:r},a,o);throw Error(`${Y.INVALID_JWT}: conditional proof type did not find condition for authenticator ${a.id}.`)}catch(e){return Promise.reject(e)}},HC=function(e,{header:t,payload:n,signature:r,data:i},a,o){try{return a.type===UC?VC(e,{payload:n,header:t,signature:r,data:i},a,o):Promise.resolve(uw({header:t,payload:n,data:i,signature:r},[a]))}catch(e){return Promise.reject(e)}},UC=`ConditionalProof2022`;function WC(e,t,n){if(!e.s){if(n instanceof GC){if(n.s)t&1&&(t=n.s),n=n.v;else{n.o=WC.bind(null,e,t);return}}if(n&&n.then){n.then(WC.bind(null,e,t),WC.bind(null,e,2));return}e.s=t,e.v=n;let r=e.o;r&&r(e)}}const GC=/*#__PURE__*/ function(){function e(){}return e.prototype.then=function(t,n){let r=new e,i=this.s;if(i){let e=i&1?t:n;if(e){try{WC(r,1,e(this.v))}catch(e){WC(r,2,e)}return r}return this}return this.o=function(e){try{let i=e.v;e.s&1?WC(r,1,t?t(i):i):n?WC(r,1,n(i)):WC(r,2,i)}catch(e){WC(r,2,e)}},r},e}();function KC(e){return e instanceof GC&&e.s&1}function qC(e,t,n){var r=-1,i,a;function o(s){try{for(;++r<e.length&&(!n||!n());)if(s=t(r),s&&s.then){if(KC(s))s=s.v;else{s.then(o,a||=WC.bind(null,i=new GC,2));return}}i?WC(i,1,s):i=s}catch(e){WC(i||=new GC,2,e)}}return o(),i}function JC(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function YC(e,t,n){for(var r;;){var i=e();if(KC(i)&&(i=i.v),!i)return a;if(i.then){r=0;break}var a=n();if(a&&a.then){if(KC(a))a=a.s;else{r=1;break}}if(t){var o=t();if(o&&o.then&&!KC(o)){r=2;break}}}var s=new GC,c=WC.bind(null,s,2);return(r===0?i.then(u):r===1?a.then(l):o.then(d)).then(void 0,c),s;function l(r){a=r;do{if(t&&(o=t(),o&&o.then&&!KC(o))){o.then(d).then(void 0,c);return}if(i=e(),!i||KC(i)&&!i.v){WC(s,1,a);return}if(i.then){i.then(u).then(void 0,c);return}a=n(),KC(a)&&(a=a.v)}while(!a||!a.then);a.then(l).then(void 0,c)}function u(e){e?(a=n(),a&&a.then?a.then(l).then(void 0,c):l(a)):WC(s,1,a)}function d(){(i=e())?i.then?i.then(u).then(void 0,c):u(i):WC(s,1,a)}}const XC=function(e,t,n,r){try{let i=QS[t];if(!i||i.length===0)throw Error(`${Y.NOT_SUPPORTED}: No supported signature types for algorithm ${t}`);let a;return Promise.resolve(e.resolve(n,{accept:aw})).then(function(e){if(a=Object.getOwnPropertyNames(e).indexOf(`didDocument`)===-1?{didDocument:e,didDocumentMetadata:{},didResolutionMetadata:{contentType:aw}}:e,a.didResolutionMetadata?.error||a.didDocument==null){let{error:e,message:t}=a.didResolutionMetadata;throw Error(`${Y.RESOLVER_ERROR}: Unable to resolve DID document for ${n}: ${e}, ${t||``}`)}let o=(e,t)=>{let n=e.filter(({id:e})=>t===e);return n.length>0?n[0]:null},s=[...a?.didDocument?.verificationMethod||[],...a?.didDocument?.publicKey||[]];typeof r==`string`&&(r.startsWith(`assertion`)&&!Object.getOwnPropertyNames(a?.didDocument).includes(`assertionMethod`)&&(a.didDocument={...a.didDocument},a.didDocument.assertionMethod=[...s.map(e=>e.id)]),s=(a.didDocument[r]||[]).map(e=>typeof e==`string`?o(s,e):typeof e.publicKey==`string`?o(s,e.publicKey):e).filter(e=>e!=null));let c=s.filter(({type:e})=>i.find(t=>t===e));if(typeof r==`string`&&(!c||c.length===0))throw Error(`${Y.NO_SUITABLE_KEYS}: DID document for ${n} does not have public keys suitable for ${t} with ${r} purpose`);if(!c||c.length===0)throw Error(`${Y.NO_SUITABLE_KEYS}: DID document for ${n} does not have public keys for ${t}`);return{authenticators:c,issuer:n,didResolutionResult:a}})}catch(e){return Promise.reject(e)}},ZC=function(e,t={resolver:void 0,auth:void 0,audience:void 0,callbackUrl:void 0,skewTime:void 0,proofPurpose:void 0,policies:{},didAuthenticator:void 0}){try{function n(){function n(n){if(f){let n=typeof t.policies?.now==`number`?t.policies.now:Math.floor(Date.now()/1e3),i=t.skewTime!==void 0&&t.skewTime>=0?t.skewTime:sw,a=n+i;if(t.policies?.nbf!==!1&&r.nbf){if(r.nbf>a)throw Error(`${Y.INVALID_JWT}: JWT not valid before nbf: ${r.nbf}`)}else if(t.policies?.iat!==!1&&r.iat&&r.iat>a)throw Error(`${Y.INVALID_JWT}: JWT not valid yet (issued in the future) iat: ${r.iat}`);if(t.policies?.exp!==!1&&r.exp&&r.exp<=n-i)throw Error(`${Y.INVALID_JWT}: JWT has expired: exp: ${r.exp} < now: ${n}`);if(t.policies?.aud!==!1&&r.aud){if(!t.audience&&!t.callbackUrl)throw Error(`${Y.INVALID_AUDIENCE}: JWT audience is required but your app address has not been configured`);if((Array.isArray(r.aud)?r.aud:[r.aud]).find(e=>t.audience===e||t.callbackUrl===e)===void 0)throw Error(`${Y.INVALID_AUDIENCE}: JWT audience does not match your DID or callback url`)}return{verified:!0,payload:r,didResolutionResult:d,issuer:u,signer:f,jwt:e,policies:t.policies}}throw Error(`${Y.INVALID_SIGNATURE}: JWT not valid. issuer DID document does not contain a verificationMethod that matches the signature.`)}let{did:s}=_S(c),f=null,p=function(){if(s!==c){let n=l.find(e=>e.id===c);if(!n)throw Error(`${Y.INVALID_JWT}: No authenticator found for did URL ${c}`);return Promise.resolve(HC(e,{payload:r,header:i,signature:a,data:o},n,t)).then(function(e){f=e})}{let n=0;return YC(function(){return!f&&n<l.length},void 0,function(){function s(e){n++}let c=l[n],u=JC(function(){return Promise.resolve(HC(e,{payload:r,header:i,signature:a,data:o},c,t)).then(function(e){f=e})},function(e){if(!e.message.includes(Y.INVALID_SIGNATURE)||n===l.length-1)throw e});return u&&u.then?u.then(s):s(u)})}}();return p&&p.then?p.then(n):n(p)}if(!t.resolver)throw Error(`missing_resolver: No DID resolver has been configured`);let{payload:r,header:i,signature:a,data:o}=lw(e,!1),s=Object.prototype.hasOwnProperty.call(t,`auth`)?t.auth?`authentication`:void 0:t.proofPurpose,c;if(!r.iss&&!r.client_id)throw Error(`${Y.INVALID_JWT}: JWT iss or client_id are required`);if(t.didAuthenticator)c=t.didAuthenticator.issuer;else if(r.iss===tw||r.iss===nw){if(!r.sub)throw Error(`${Y.INVALID_JWT}: JWT sub is required`);c=r.sub_jwk===void 0?r.sub:(i.kid||``).split(`#`)[0]}else if(r.iss===rw){if(!r.did)throw Error(`${Y.INVALID_JWT}: JWT did is required`);c=r.did}else if(!r.iss&&r.scope===`openid`&&r.redirect_uri){if(!r.client_id)throw Error(`${Y.INVALID_JWT}: JWT client_id is required`);c=r.client_id}else c=r.iss;if(!c)throw Error(`${Y.INVALID_JWT}: No DID has been found in the JWT`);let l,u,d,f=function(){if(t.didAuthenticator)({didResolutionResult:d,authenticators:l,issuer:u}=t.didAuthenticator);else return Promise.resolve(XC(t.resolver,i.alg,c,s)).then(function(e){({didResolutionResult:d,authenticators:l,issuer:u}=e),t.didAuthenticator={didResolutionResult:d,authenticators:l,issuer:u}})}();return Promise.resolve(f&&f.then?f.then(n):n(f))}catch(e){return Promise.reject(e)}},QC=function(e,{expiresIn:t,canonicalize:n},r){try{if(r.length===0)throw Error(`invalid_argument: must provide one or more issuers`);let i=e,a=``,o=qC(r,function(e){let o=r[e],s={typ:`JWT`,alg:o.alg};return e!==0&&(s.cty=`JWT`),Promise.resolve($C(i,{...o,canonicalize:n,expiresIn:t},s)).then(function(e){a=e,i={jwt:a}})});return Promise.resolve(o&&o.then?o.then(function(){return a}):a)}catch(e){return Promise.reject(e)}},$C=function(e,{issuer:t,signer:n,alg:r,expiresIn:i,canonicalize:a},o={}){try{if(!n)throw Error(`missing_signer: No Signer functionality has been configured`);if(!t)throw Error(`missing_issuer: No issuing DID has been configured`);o.typ||=`JWT`,o.alg||=r;let s={iat:Math.floor(Date.now()/1e3),exp:void 0};if(i){if(typeof i==`number`)s.exp=(e.nbf||s.iat)+Math.floor(i);else throw Error(`invalid_argument: JWT expiresIn is not a number`)}let c={...s,...e,iss:t};return ew(c,n,o,{canonicalize:a})}catch(e){return Promise.reject(e)}},ew=function(e,t,n={},r={}){try{n.alg||=iw;let i=typeof e==`string`?e:ow(e,r.canonicalize),a=[ow(n,r.canonicalize),i].join(`.`),o=bC(n.alg);return Promise.resolve(o(a,t)).then(function(e){return[a,e].join(`.`)})}catch(e){return Promise.reject(e)}},tw=`https://self-issued.me/v2`,nw=`https://self-issued.me/v2/openid-vc`,rw=`https://self-issued.me`,iw=`ES256K`,aw=`application/did+json`;function ow(e,t=!1){return aC(t?(0,lS.default)(e):JSON.stringify(e))}const sw=300;function cw(e){let t=e.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);if(t)return{header:JSON.parse(oC(t[1])),payload:t[2],signature:t[3],data:`${t[1]}.${t[2]}`};throw Error(`invalid_argument: Incorrect format JWS`)}function lw(e,t=!0){if(!e)throw Error(`invalid_argument: no JWT passed into decodeJWT`);try{let n=cw(e),r=Object.assign(n,{payload:JSON.parse(oC(n.payload))}),i=r.payload.iss;if(r.header.cty===`JWT`&&t){let e=lw(r.payload.jwt);if(e.payload.iss!==i)throw Error(`${Y.INVALID_JWT}: multiple issuers`);return e}return r}catch(e){throw Error(`invalid_argument: ${Y.INVALID_JWT}: ${e}`)}}function uw({header:e,payload:t,data:n,signature:r},i){Array.isArray(i)||(i=[i]);let a=t.iss,o=!0;do{if(a!==t.iss)throw Error(`${Y.INVALID_JWT}: multiple issuers`);try{return jC(e.alg)(n,r,i)}catch(e){if(!e.message.startsWith(Y.INVALID_SIGNATURE))throw e}e.cty===`JWT`?{payload:t,header:e,signature:r,data:n}=lw(t.jwt,!1):o=!1}while(o);throw Error(`${Y.INVALID_SIGNATURE}: no matching public key found`)}typeof Symbol<`u`&&(Symbol.iterator||(Symbol.iterator=Symbol(`Symbol.iterator`)));const dw=`ES256K`,fw=/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,pw=`https://www.w3.org/2018/credentials/v1`,mw=`VerifiableCredential`,hw=[`evidence`,`termsOfUse`,`refreshService`,`credentialSchema`,`credentialStatus`];function gw(e){return Array.isArray(e)?e:[e]}function _w(e){return Array.isArray(e)?e.map(e=>_w(e)):e instanceof Date?new Date(e.getTime()):e&&typeof e==`object`?Object.getOwnPropertyNames(e).reduce((t,n)=>(Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n)),t[n]=_w(e[n]),t),Object.create(Object.getPrototypeOf(e))):e}function vw(e){return e!=null}function yw(e){if(typeof e!=`object`||!e)return e;let t={...e};return Object.keys(t).forEach(e=>t[e]===void 0&&delete t[e]),t}function bw(e){return typeof e==`object`&&e.sub&&e.iss&&e.claim&&e.iat}function xw(e){let{iat:t,nbf:n,claim:r,vc:i,...a}=e,o={...a,nbf:n||t,vc:{"@context":[pw],type:[mw],credentialSubject:r}};return i&&(e.issVc=i),o}function Sw(e,t=!0){let n=_w(e);bw(e)&&(n=xw(e)),n.credentialSubject={...e.credentialSubject,...e.vc?.credentialSubject},e.sub&&!e.credentialSubject?.id&&n.credentialSubject&&(n.credentialSubject.id=e.sub,t&&delete n.sub),t&&delete n.vc?.credentialSubject,(e.issuer===void 0||typeof e.issuer==`object`)&&(n.issuer=yw({id:e.iss,...e.issuer}),t&&!e.issuer?.id&&delete n.iss),!e.id&&e.jti&&(n.id=n.id||n.jti,t&&delete n.jti);let r=[...gw(n.type),...gw(n.vc?.type)].filter(vw);n.type=[...new Set(r)],t&&delete n.vc?.type;for(let r of hw)e.vc&&e.vc[r]&&(n[r]||(n[r]=e.vc[r]),t&&delete n.vc[r]);let i=[...gw(e.context),...gw(e[`@context`]),...gw(e.vc?.[`@context`])].filter(vw);return n[`@context`]=[...new Set(i)],t&&(delete n.context,delete n.vc?.[`@context`]),!e.issuanceDate&&(e.iat||e.nbf)&&(n.issuanceDate=(/* @__PURE__ */ new Date((e.nbf||e.iat)*1e3)).toISOString(),t&&(e.nbf?delete n.nbf:delete n.iat)),!e.expirationDate&&e.exp&&(n.expirationDate=(/* @__PURE__ */ new Date(e.exp*1e3)).toISOString(),t&&delete n.exp),t&&n.vc&&Object.keys(n.vc).length===0&&delete n.vc,n}function Cw(e,t=!0){let n;try{n=lw(e)}catch{throw TypeError(`unknown credential format`)}return{...Sw(n.payload,t),proof:{type:`JwtProof2020`,jwt:e}}}function ww(e,t=!0){if(typeof e==`string`){if(fw.test(e))return Cw(e,t);{let n;try{n=JSON.parse(e)}catch{throw TypeError(`unknown credential format`)}return ww(n,t)}}return e.proof?.jwt?_w({...Cw(e.proof.jwt,t),proof:e.proof}):{proof:{},...Sw(e,t)}}function Tw(e,t=!0){if(Array.isArray(e.credentialSubject))throw Error(`credentialSubject of type array not supported`);let n=_w({vc:{...e.vc},...e});n.vc=n.vc;let r={...e.credentialSubject,...e.vc?.credentialSubject};e.sub||(n.sub=e.credentialSubject?.id,t&&delete r.id);let i=[...gw(e.context),...gw(e[`@context`]),...gw(e.vc?.[`@context`])].filter(vw);n.vc[`@context`]=[...new Set(i)],t&&(delete n.context,delete n[`@context`]);let a=[...gw(e.type),...gw(e.vc?.type)].filter(vw);if(n.vc.type=[...new Set(a)],t&&delete n.type,e.id&&Object.getOwnPropertyNames(e).indexOf(`jti`)===-1&&(n.jti=e.id,t&&delete n.id),e.issuanceDate&&Object.getOwnPropertyNames(e).indexOf(`nbf`)===-1){let r=Date.parse(e.issuanceDate);isNaN(r)||(n.nbf=Math.floor(r/1e3),t&&delete n.issuanceDate)}if(e.expirationDate&&Object.getOwnPropertyNames(e).indexOf(`exp`)===-1){let r=Date.parse(e.expirationDate);isNaN(r)||(n.exp=Math.floor(r/1e3),t&&delete n.expirationDate)}e.issuer&&Object.getOwnPropertyNames(e).indexOf(`iss`)===-1&&(typeof e.issuer==`object`?(n.iss=e.issuer?.id,t&&(delete n.issuer.id,Object.keys(n.issuer).length===0&&delete n.issuer)):typeof e.issuer==`string`&&(n.iss=e.iss||``+e.issuer,t&&delete n.issuer)),n.vc.credentialSubject=r,t&&delete n.credentialSubject;for(let r of hw)e[r]&&(n.vc[r]||(n.vc[r]=e[r]),t&&delete n[r]);return n}const Ew={SCHEMA_ERROR:`schema_error`,FORMAT_ERROR:`format_error`,AUTH_ERROR:`auth_error`};({...Ew,...Y});function Dw(e){return e&&!isNaN(e)&&Object.prototype.toString.call(e)===`[object Date]`}function Ow(e){if(typeof e==`number`){if(!(Number.isInteger(e)&&e<1e11))throw TypeError(`${Ew.SCHEMA_ERROR}: "${e}" is not a unix timestamp in seconds`)}else if(typeof e==`string`)Ow(Math.floor(new Date(e).valueOf()/1e3));else if(!Dw(e))throw TypeError(`${Ew.SCHEMA_ERROR}: "${e}" is not a valid time`)}function kw(e){let t=gw(e);if(t.length<1||t.indexOf(pw)===-1)throw TypeError(`${Ew.SCHEMA_ERROR}: @context is missing default context "${pw}"`)}function Aw(e){let t=gw(e);if(t.length<1||t.indexOf(mw)===-1)throw TypeError(`${Ew.SCHEMA_ERROR}: type is missing default "${mw}"`)}function jw(e){if(Object.keys(e).length===0)throw TypeError(`${Ew.SCHEMA_ERROR}: credentialSubject must not be empty`)}const Mw=function(e,t,n={}){try{let r=n?.policies?.issuanceDate!==!1&&void 0,i=n?.policies?.expirationDate!==!1&&void 0;return n={...n,policies:{...n?.policies,nbf:r,exp:i,iat:r}},Promise.resolve(ZC(e,{resolver:t,...n})).then(function(e){return e.verifiableCredential=ww(e.jwt,n?.removeOriginalFields),n?.policies?.format!==!1&&Fw(e.verifiableCredential),e})}catch(e){return Promise.reject(e)}},Nw=function(e,t,n={}){try{let r={iat:void 0,...Tw(e,n.removeOriginalFields)};if(Pw(r),Array.isArray(t)){let e=t[0].did,i=[];for(let a of t){if(a.did!==e)throw Error(`All issuers must be the same did to comply with the Verifiable Conditions spec`);i.push({issuer:a.did||r.iss||``,signer:a.signer,alg:a.alg||n.header?.alg||dw})}return Promise.resolve(QC(r,{...n},i))}return Promise.resolve($C(r,{...n,issuer:t.did||r.iss||``,signer:t.signer},{...n.header,alg:t.alg||n.header?.alg||dw}))}catch(e){return Promise.reject(e)}};function Pw(e){kw(e.vc[`@context`]),Aw(e.vc.type),jw(e.vc.credentialSubject),e.nbf&&Ow(e.nbf),e.exp&&Ow(e.exp)}function Fw(e){kw(e[`@context`]),Aw(e.type),jw(e.credentialSubject),e.issuanceDate&&Ow(e.issuanceDate),e.expirationDate&&Ow(e.expirationDate)}var Iw=/* @__PURE__ */ s(((e,t)=>{t.exports=a;var n=128,r=-128,i=2**31;function a(e,t,o){if(2**53-1&&e>2**53-1)throw a.bytes=0,RangeError(`Could not encode varint`);t||=[],o||=0;for(var s=o;e>=i;)t[o++]=e&255|n,e/=128;for(;e&r;)t[o++]=e&255|n,e>>>=7;return t[o]=e|0,a.bytes=o-s+1,t}})),Lw=/* @__PURE__ */ s(((e,t)=>{t.exports=i;var n=128,r=127;function i(e,t){var a=0,t=t||0,o=0,s=t,c,l=e.length;do{if(s>=l||o>49)throw i.bytes=0,RangeError(`Could not decode varint`);c=e[s++],a+=o<28?(c&r)<<o:(c&r)*2**o,o+=7}while(c>=n);return i.bytes=s-t,a}})),Rw=/* @__PURE__ */ s(((e,t)=>{var n=2**14,r=2**21,i=2**28,a=2**35,o=2**42,s=2**49,c=2**56,l=2**63;t.exports=function(e){return e<128?1:e<n?2:e<r?3:e<i?4:e<a?5:e<o?6:e<s?7:e<c?8:e<l?9:10}})),zw=/* @__PURE__ */ u((/* @__PURE__ */ s(((e,t)=>{t.exports={encode:Iw(),decode:Lw(),encodingLength:Rw()}})))(),1);function Bw(e){if(e instanceof Uint8Array&&e.constructor.name===`Uint8Array`)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw Error(`Unknown type, must be binary type`)}function Vw(e){return new TextEncoder().encode(e)}function Hw(e){return new TextDecoder().decode(e)}function Uw(e,t){if(e.length>=255)throw TypeError(`Alphabet too long`);for(var n=/* @__PURE__ */ new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<e.length;i++){var a=e.charAt(i),o=a.charCodeAt(0);if(n[o]!==255)throw TypeError(a+` is ambiguous`);n[o]=i}var s=e.length,c=e.charAt(0),l=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function d(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;for(var n=0,r=0,i=0,a=t.length;i!==a&&t[i]===0;)i++,n++;for(var o=(a-i)*u+1>>>0,l=new Uint8Array(o);i!==a;){for(var d=t[i],f=0,p=o-1;(d!==0||f<r)&&p!==-1;p--,f++)d+=256*l[p]>>>0,l[p]=d%s>>>0,d=d/s>>>0;if(d!==0)throw Error(`Non-zero carry`);r=f,i++}for(var m=o-r;m!==o&&l[m]===0;)m++;for(var h=c.repeat(n);m<o;++m)h+=e.charAt(l[m]);return h}function f(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return/* @__PURE__ */ new Uint8Array;var t=0;if(e[t]!==` `){for(var r=0,i=0;e[t]===c;)r++,t++;for(var a=(e.length-t)*l+1>>>0,o=new Uint8Array(a);e[t];){var u=n[e.charCodeAt(t)];if(u===255)return;for(var d=0,f=a-1;(u!==0||d<i)&&f!==-1;f--,d++)u+=s*o[f]>>>0,o[f]=u%256>>>0,u=u/256>>>0;if(u!==0)throw Error(`Non-zero carry`);i=d,t++}if(e[t]!==` `){for(var p=a-i;p!==a&&o[p]===0;)p++;for(var m=new Uint8Array(r+(a-p)),h=r;p!==a;)m[h++]=o[p++];return m}}}function p(e){var n=f(e);if(n)return n;throw Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:p}}var Ww=Uw,Gw=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error(`Unknown type, must be binary type`)}},Kw=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let r=t.codePointAt(0);
138
+ /* c8 ignore next 3 */
139
+ if(r===void 0)throw Error(`Invalid prefix character`);this.prefixCodePoint=r,this.baseDecode=n}decode(e){if(typeof e==`string`){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}throw Error(`Can only multibase decode strings`)}or(e){return Jw(this,e)}},qw=class{decoders;constructor(e){this.decoders=e}or(e){return Jw(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Jw(e,t){return new qw({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Yw=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,r){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=r,this.encoder=new Gw(e,t,n),this.decoder=new Kw(e,t,r)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Xw({name:e,prefix:t,encode:n,decode:r}){return new Yw(e,t,n,r)}function Zw({name:e,prefix:t,alphabet:n}){let{encode:r,decode:i}=Ww(n,e);return Xw({prefix:t,name:e,encode:r,decode:e=>Bw(i(e))})}function Qw(e,t,n,r){let i=e.length;for(;e[i-1]===`=`;)--i;let a=new Uint8Array(i*n/8|0),o=0,s=0,c=0;for(let l=0;l<i;++l){let i=t[e[l]];if(i===void 0)throw SyntaxError(`Non-${r} character`);s=s<<n|i,o+=n,o>=8&&(o-=8,a[c++]=255&s>>o)}if(o>=n||255&s<<8-o)throw SyntaxError(`Unexpected end of data`);return a}function $w(e,t,n){let r=t[t.length-1]===`=`,i=(1<<n)-1,a=``,o=0,s=0;for(let r=0;r<e.length;++r)for(s=s<<8|e[r],o+=8;o>n;)o-=n,a+=t[i&s>>o];if(o!==0&&(a+=t[i&s<<n-o]),r)for(;a.length*n&7;)a+=`=`;return a}function eT(e){let t={};for(let n=0;n<e.length;++n)t[e[n]]=n;return t}function tT({name:e,prefix:t,bitsPerChar:n,alphabet:r}){let i=eT(r);return Xw({prefix:t,name:e,encode(e){return $w(e,r,n)},decode(t){return Qw(t,i,n,e)}})}var nT=/* @__PURE__ */ c({base58btc:()=>rT,base58flickr:()=>iT});const rT=Zw({name:`base58btc`,prefix:`z`,alphabet:`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`}),iT=Zw({name:`base58flickr`,prefix:`Z`,alphabet:`123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ`});function aT(e=0){return new Uint8Array(e)}function oT(e){return e}function sT(e,t){t??=e.reduce((e,t)=>e+t.length,0);let n=aT(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return oT(n)}var cT=/* @__PURE__ */ c({base10:()=>lT});const lT=Zw({prefix:`9`,name:`base10`,alphabet:`0123456789`});var uT=/* @__PURE__ */ c({base16:()=>dT,base16upper:()=>fT});const dT=tT({prefix:`f`,name:`base16`,alphabet:`0123456789abcdef`,bitsPerChar:4}),fT=tT({prefix:`F`,name:`base16upper`,alphabet:`0123456789ABCDEF`,bitsPerChar:4});var pT=/* @__PURE__ */ c({base2:()=>mT});const mT=tT({prefix:`0`,name:`base2`,alphabet:`01`,bitsPerChar:1});var hT=/* @__PURE__ */ c({base256emoji:()=>xT});const gT=Array.from(`🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂`),_T=gT.reduce((e,t,n)=>(e[n]=t,e),[]),vT=gT.reduce((e,t,n)=>{let r=t.codePointAt(0);if(r==null)throw Error(`Invalid character: ${t}`);return e[r]=n,e},[]);function yT(e){return e.reduce((e,t)=>(e+=_T[t],e),``)}function bT(e){let t=[];for(let n of e){let e=n.codePointAt(0);if(e==null)throw Error(`Invalid character: ${n}`);let r=vT[e];if(r==null)throw Error(`Non-base256emoji character: ${n}`);t.push(r)}return new Uint8Array(t)}const xT=Xw({prefix:`🚀`,name:`base256emoji`,encode:yT,decode:bT});var ST=/* @__PURE__ */ c({base32:()=>CT,base32hex:()=>DT,base32hexpad:()=>kT,base32hexpadupper:()=>AT,base32hexupper:()=>OT,base32pad:()=>TT,base32padupper:()=>ET,base32upper:()=>wT,base32z:()=>jT});const CT=tT({prefix:`b`,name:`base32`,alphabet:`abcdefghijklmnopqrstuvwxyz234567`,bitsPerChar:5}),wT=tT({prefix:`B`,name:`base32upper`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,bitsPerChar:5}),TT=tT({prefix:`c`,name:`base32pad`,alphabet:`abcdefghijklmnopqrstuvwxyz234567=`,bitsPerChar:5}),ET=tT({prefix:`C`,name:`base32padupper`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=`,bitsPerChar:5}),DT=tT({prefix:`v`,name:`base32hex`,alphabet:`0123456789abcdefghijklmnopqrstuv`,bitsPerChar:5}),OT=tT({prefix:`V`,name:`base32hexupper`,alphabet:`0123456789ABCDEFGHIJKLMNOPQRSTUV`,bitsPerChar:5}),kT=tT({prefix:`t`,name:`base32hexpad`,alphabet:`0123456789abcdefghijklmnopqrstuv=`,bitsPerChar:5}),AT=tT({prefix:`T`,name:`base32hexpadupper`,alphabet:`0123456789ABCDEFGHIJKLMNOPQRSTUV=`,bitsPerChar:5}),jT=tT({prefix:`h`,name:`base32z`,alphabet:`ybndrfg8ejkmcpqxot1uwisza345h769`,bitsPerChar:5});var MT=/* @__PURE__ */ c({base36:()=>NT,base36upper:()=>PT});const NT=Zw({prefix:`k`,name:`base36`,alphabet:`0123456789abcdefghijklmnopqrstuvwxyz`}),PT=Zw({prefix:`K`,name:`base36upper`,alphabet:`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`});var FT=/* @__PURE__ */ c({base64:()=>IT,base64pad:()=>LT,base64url:()=>RT,base64urlpad:()=>zT});const IT=tT({prefix:`m`,name:`base64`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,bitsPerChar:6}),LT=tT({prefix:`M`,name:`base64pad`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=`,bitsPerChar:6}),RT=tT({prefix:`u`,name:`base64url`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,bitsPerChar:6}),zT=tT({prefix:`U`,name:`base64urlpad`,alphabet:`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=`,bitsPerChar:6});var BT=/* @__PURE__ */ c({base8:()=>VT});const VT=tT({prefix:`7`,name:`base8`,alphabet:`01234567`,bitsPerChar:3});var HT=/* @__PURE__ */ c({identity:()=>UT});const UT=Xw({prefix:`\0`,name:`identity`,encode:e=>Hw(e),decode:e=>Vw(e)});new TextEncoder,new TextDecoder;var WT=JT,GT=128,KT=-128,qT=2**31;function JT(e,t,n){t||=[],n||=0;for(var r=n;e>=qT;)t[n++]=e&255|GT,e/=128;for(;e&KT;)t[n++]=e&255|GT,e>>>=7;return t[n]=e|0,JT.bytes=n-r+1,t}var YT=QT,XT=128,ZT=127;function QT(e,t){var n=0,t=t||0,r=0,i=t,a,o=e.length;do{if(i>=o)throw QT.bytes=0,RangeError(`Could not decode varint`);a=e[i++],n+=r<28?(a&ZT)<<r:(a&ZT)*2**r,r+=7}while(a>=XT);return QT.bytes=i-t,n}var $T=128,eE=2**14,tE=2**21,nE=2**28,rE=2**35,iE=2**42,aE=2**49,oE=2**56,sE=2**63,cE={encode:WT,decode:YT,encodingLength:function(e){return e<$T?1:e<eE?2:e<tE?3:e<nE?4:e<rE?5:e<iE?6:e<aE?7:e<oE?8:e<sE?9:10}};function lE(e,t,n=0){return cE.encode(e,t,n),t}function uE(e){return cE.encodingLength(e)}function dE(e,t){let n=t.byteLength,r=uE(e),i=r+uE(n),a=new Uint8Array(i+n);return lE(e,a,0),lE(n,a,r),a.set(t,i),new fE(e,n,t,a)}var fE=class{code;size;digest;bytes;constructor(e,t,n,r){this.code=e,this.size=t,this.digest=n,this.bytes=r}},pE=/* @__PURE__ */ c({identity:()=>gE});const mE=Bw;function hE(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return dE(0,mE(e))}const gE={code:0,name:`identity`,encode:mE,digest:hE};function _E({name:e,code:t,encode:n,minDigestLength:r,maxDigestLength:i}){return new vE(e,t,n,r,i)}var vE=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,r,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=r??20,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?yE(n,this.code,t?.truncate):n.then(e=>yE(e,this.code,t?.truncate))}throw Error(`Unknown type, must be binary type`)}};function yE(e,t,n){if(n!=null&&n!==e.byteLength){if(n>e.byteLength)throw Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,n)}return dE(t,e)}var bE=/* @__PURE__ */ c({sha256:()=>SE,sha512:()=>CE});function xE(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}const SE=_E({name:`sha2-256`,code:18,encode:xE(`SHA-256`)}),CE=_E({name:`sha2-512`,code:19,encode:xE(`SHA-512`)}),wE={...HT,...pT,...BT,...cT,...uT,...ST,...MT,...nT,...FT,...hT};({...bE,...pE});function TE(e,t,n,r){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:n},decoder:{decode:r}}}const EE=TE(`utf8`,`u`,e=>`u`+new TextDecoder(`utf8`).decode(e),e=>new TextEncoder().encode(e.substring(1))),DE=TE(`ascii`,`a`,e=>{let t=`a`;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t},e=>{e=e.substring(1);let t=aT(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}),OE={utf8:EE,"utf-8":EE,hex:wE.base16,latin1:DE,ascii:DE,binary:DE,...wE};function kE(e,t=`utf8`){let n=OE[t];if(n==null)throw Error(`Unsupported encoding "${t}"`);return n.decoder.decode(`${n.prefix}${e}`)}function AE(e,t=`utf8`){let n=OE[t];if(n==null)throw Error(`Unsupported encoding "${t}"`);return n.encoder.encode(e).substring(1)}var jE=/* @__PURE__ */ c({keyToDidDoc:()=>ME});function ME(e,t){let n=`did:key:${t}`,r=`${n}#${t}`;return{id:n,verificationMethod:[{id:r,type:`Secp256k1VerificationKey2018`,controller:n,publicKeyBase58:AE(e,`base58btc`)}],authentication:[r],assertionMethod:[r],capabilityDelegation:[r],capabilityInvocation:[r]}}var NE=/* @__PURE__ */ c({keyToDidDoc:()=>FE});function PE(e){let t=new Uint8Array(e.length+2);return t[0]=236,t[1]=1,t.set(e,2),`z${AE(t,`base58btc`)}`}function FE(e,t){let n=`did:key:${t}`,r=`${n}#${t}`,i=Nb(e),a=`${n}#${PE(i)}`;return{id:n,verificationMethod:[{id:r,type:`Ed25519VerificationKey2018`,controller:n,publicKeyBase58:AE(e,`base58btc`)}],authentication:[r],assertionMethod:[r],capabilityDelegation:[r],capabilityInvocation:[r],keyAgreement:[{id:a,type:`X25519KeyAgreementKey2019`,controller:n,publicKeyBase58:AE(i,`base58btc`)}]}}const IE=Yv;var LE=/* @__PURE__ */ c({keyToDidDoc:()=>RE});function RE(e,t){let n=`did:key:${t}`,r=`${n}#${t}`,i=Ex.ProjectivePoint.fromHex(zE(e));return{id:n,verificationMethod:[{id:r,type:`JsonWebKey2020`,controller:n,publicKeyJwk:{kty:`EC`,crv:`P-256`,x:AE(IE(i.x),`base64url`),y:AE(IE(i.y),`base64url`)}}],authentication:[r],assertionMethod:[r],capabilityDelegation:[r],capabilityInvocation:[r]}}function zE(e){return e.length===64?sT([new Uint8Array([4]),e]):e}
140
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
141
+ const BE=wx;var VE=/* @__PURE__ */ c({keyToDidDoc:()=>HE});function HE(e,t){let n=`did:key:${t}`,r=`${n}#${t}`,i=BE.ProjectivePoint.fromHex(UE(e));return{id:n,verificationMethod:[{id:r,type:`JsonWebKey2020`,controller:n,publicKeyJwk:{kty:`EC`,crv:`P-384`,x:AE(IE(i.x),`base64url`),y:AE(IE(i.y),`base64url`)}}],authentication:[r],assertionMethod:[r],capabilityDelegation:[r],capabilityInvocation:[r]}}function UE(e){return e.length===96?sT([new Uint8Array([4]),e]):e}
142
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
143
+ const WE=Tx;var GE=/* @__PURE__ */ c({keyToDidDoc:()=>KE});function KE(e,t){let n=`did:key:${t}`,r=`${n}#${t}`,i=WE.ProjectivePoint.fromHex(e);return{id:n,verificationMethod:[{id:r,type:`JsonWebKey2020`,controller:n,publicKeyJwk:{kty:`EC`,crv:`P-521`,x:AE(IE(i.x),`base64url`),y:AE(IE(i.y),`base64url`)}}],authentication:[r],assertionMethod:[r],capabilityDelegation:[r],capabilityInvocation:[r]}}const qE=`application/did+json`,JE={231:jE,237:NE,4608:LE,4609:VE,4610:GE};function YE(){return{key:async(e,t,n,r)=>{let i=r.accept||qE,a={didResolutionMetadata:{contentType:i},didDocument:null,didDocumentMetadata:{}};try{let e=rT.decode(t.id),n=zw.default.decode(e),r=e.slice(zw.default.decode.bytes),o=await JE[n].keyToDidDoc(r,t.id);i===`application/did+ld+json`?(o[`@context`]=`https://w3id.org/did/v1`,a.didDocument=o):i===qE?a.didDocument=o:(delete a.didResolutionMetadata.contentType,a.didResolutionMetadata.error=`representationNotSupported`)}catch(e){a.didResolutionMetadata.error=`invalidDid`,a.didResolutionMetadata.message=e.toString()}return a}}}function XE(e){let t=e.split(`:`);if(!e.startsWith(`did:pkh:`)||t.length!==5)throw Error(`Invalid pkh did`);let[,,n,r,i]=t;if(!i.startsWith(`0x`))throw Error(`Invalid address: ${i}`);let a=Number(r);if(isNaN(a))throw Error(`Invalid chain id: ${r}`);return{chainId:a,networkId:n,address:i}}async function ZE(e,t){try{let n=parseInt(String(Date.now()/1e3)),r=await Mw(e,eD(),{...t?.audience!==void 0&&{audience:t.audience},policies:{now:parseInt(String(Date.now()/1e3)),expirationDate:!0,issuanceDate:!0}});return r.payload.exp&&r.payload.exp<n?!1:(QE(r),r)}catch(e){return console.error(e),!1}}function QE(e){let t=Object.keys(e.verifiableCredential.credentialSubject);if(![`address`,`chainId`,`networkId`].every(e=>t.includes(e)))throw Error(`Invalid Auth Credential Subject:`+JSON.stringify(e.verifiableCredential.credentialSubject,null,2))}async function $E(e,t,n,r,i){let a={sub:r.did,vc:{"@context":[`https://www.w3.org/2018/credentials/v1`],type:[`VerifiableCredential`],credentialSubject:{chainId:e,networkId:t,address:n}},aud:i?.aud};return await Nw(a,r,{expiresIn:i?.expiresIn})}const eD=()=>{let e=YE();if(!e)throw Error(`Failed to get key resolver`);return new bS(e)};var tD=class extends Error{constructor(){super(`Invalid signature`)}},nD=class{crypto;appName;user;app;constructor(e,t,n){this.crypto=e,this.appName=t,this.user=n,this.app={key:this.crypto.did,name:this.appName}}get publicKey(){return this.crypto.publicKey}async sign(e){return this.crypto.sign(e)}async verify(e,t){if(!await this.crypto.verify(e,t))throw new tD}async signAction(e,t,n){let r=e.context?.prevOpHash??``;return this._signAction(e,t,r,n)}async signActionWithResultingState(e,t,n,r){let i=`${e.context?.prevOpHash??``}:${n}`;return this._signAction(e,t,i,r)}async signActionLegacy(e,t){if(t?.aborted)throw Error(`Signing aborted`);let n=[((/* @__PURE__ */ new Date()).getTime()/1e3).toFixed(0),this.crypto.did,await this.hashAction(e),e.context?.prevOpHash??``],r=await this.crypto.sign(this.buildSignatureMessage(n));if(t?.aborted)throw Error(`Signing aborted`);return[...n,`0x${this.arrayBufferToHex(r)}`]}async _signAction(e,t,n,r){if(r?.aborted)throw Error(`Signing aborted`);let i=await Ht({action:e,target:t,signer:zt(this),sign:e=>this.crypto.sign(e),previousStateHash:n});if(r?.aborted)throw Error(`Signing aborted`);return i}async hashAction(e){let t=[e.scope,e.type,JSON.stringify(e.input)].join(``),n=new TextEncoder().encode(t),r=await crypto.subtle.digest(`SHA-256`,n);return this.arrayBufferToBase64(r)}buildSignatureMessage(e){let t=e.join(``),n=`Signed Operation:
144
+ `+t.length.toString();return new TextEncoder().encode(n+t)}arrayBufferToHex(e){let t=e instanceof Uint8Array?e:new Uint8Array(e);return Array.from(t).map(e=>e.toString(16).padStart(2,`0`)).join(``)}arrayBufferToBase64(e){let t=new Uint8Array(e),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)}};function rD(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}var iD=o((()=>{}));function aD(e){return rD(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var oD=o((()=>{iD()})),sD,cD=o((()=>{sD=`2.52.0`}));function lD(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?lD(e.cause,t):t?null:e}var uD,dD,fD=o((()=>{cD(),uD={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${sD}`},dD=class e extends Error{constructor(t,n={}){let r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=uD.getDocsUrl?.({...n,docsPath:i}),o=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...uD.version?[`Version: ${uD.version}`]:[]].join(`
145
+ `);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=sD}walk(e){return lD(this,e)}}})),pD,mD,hD,gD,_D,vD,yD=o((()=>{oD(),fD(),pD=class extends dD{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join(`
146
+ `),{name:`AbiEncodingArrayLengthMismatchError`})}},mD=class extends dD{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${aD(t)}) does not match expected size (bytes${e}).`,{name:`AbiEncodingBytesSizeMismatchError`})}},hD=class extends dD{constructor({expectedLength:e,givenLength:t}){super([`ABI encoding params/values length mismatch.`,`Expected length (params): ${e}`,`Given length (values): ${t}`].join(`
147
+ `),{name:`AbiEncodingLengthMismatchError`})}},gD=class extends dD{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:`BytesSizeMismatchError`})}},_D=class extends dD{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,`Please provide a valid ABI type.`].join(`
148
+ `),{docsPath:t,name:`InvalidAbiEncodingType`})}},vD=class extends dD{constructor(e){super([`Value "${e}" is not a valid array.`].join(`
149
+ `),{name:`InvalidArrayError`})}}})),bD,xD,SD=o((()=>{fD(),bD=class extends dD{constructor({offset:e,position:t,size:n}){super(`Slice ${t===`start`?`starting`:`ending`} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:`SliceOffsetOutOfBoundsError`})}},xD=class extends dD{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}}}));function CD(e,{dir:t,size:n=32}={}){return typeof e==`string`?wD(e,{dir:t,size:n}):TD(e,{dir:t,size:n})}function wD(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new xD({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function TD(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new xD({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var ED=o((()=>{SD()})),DD,OD,kD=o((()=>{fD(),DD=class extends dD{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},OD=class extends dD{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function AD(e,{size:t}){if(aD(e)>t)throw new OD({givenSize:aD(e),maxSize:t})}function jD(e,t={}){let{signed:n}=t;t.size&&AD(e,{size:t.size});let r=BigInt(e);if(!n)return r;let i=(e.length-2)/2;return r<=(1n<<BigInt(i)*8n-1n)-1n?r:r-BigInt(`0x${`f`.padStart(i*2,`f`)}`)-1n}function MD(e,t={}){let n=jD(e,t),r=Number(n);if(!Number.isSafeInteger(r))throw new DD({max:`${2**53-1}`,min:`${-(2**53-1)}`,signed:t.signed,size:t.size,value:`${n}n`});return r}var ND=o((()=>{kD(),oD()}));function PD(e,t={}){return typeof e==`number`||typeof e==`bigint`?LD(e,t):typeof e==`string`?RD(e,t):typeof e==`boolean`?FD(e,t):ID(e,t)}function FD(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(AD(n,{size:t.size}),CD(n,{size:t.size})):n}function ID(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=zD[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(AD(r,{size:t.size}),CD(r,{dir:`right`,size:t.size})):r}function LD(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new DD({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?CD(s,{size:r}):s}function RD(e,t={}){return ID(BD.encode(e),t)}var zD,BD,VD=o((()=>{kD(),ED(),ND(),zD=/*#__PURE__*/ Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),BD=/*#__PURE__*/ new TextEncoder}));function HD(e,t={}){return typeof e==`number`||typeof e==`bigint`?KD(e,t):typeof e==`boolean`?UD(e,t):rD(e)?GD(e,t):qD(e,t)}function UD(e,t={}){let n=/* @__PURE__ */ new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(AD(n,{size:t.size}),CD(n,{size:t.size})):n}function WD(e){if(e>=YD.zero&&e<=YD.nine)return e-YD.zero;if(e>=YD.A&&e<=YD.F)return e-(YD.A-10);if(e>=YD.a&&e<=YD.f)return e-(YD.a-10)}function GD(e,t={}){let n=e;t.size&&(AD(n,{size:t.size}),n=CD(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=WD(r.charCodeAt(t++)),i=WD(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new dD(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function KD(e,t){return GD(LD(e,t))}function qD(e,t={}){let n=JD.encode(e);return typeof t.size==`number`?(AD(n,{size:t.size}),CD(n,{dir:`right`,size:t.size})):n}var JD,YD,XD=o((()=>{fD(),iD(),ED(),ND(),VD(),JD=/*#__PURE__*/ new TextEncoder,YD={zero:48,nine:57,A:65,F:70,a:97,f:102}}));function ZD(e,t){let n=t||`hex`,r=oS(rD(e,{strict:!1})?HD(e):e);return n===`bytes`?r:PD(r)}var QD=o((()=>{sS(),iD(),XD(),VD()})),$D,eO=o((()=>{fD(),$D=class extends dD{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:[`- Address must be a hex value of 20 bytes (40 hex characters).`,`- Address must match its checksum counterpart.`],name:`InvalidAddressError`})}}})),tO,nO=o((()=>{tO=class extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}}}));function rO(e,t){if(iO.has(`${e}.${t}`))return iO.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=ZD(qD(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return iO.set(`${e}.${t}`,a),a}var iO,aO=o((()=>{XD(),QD(),nO(),iO=/*#__PURE__*/ new tO(8192)}));function oO(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(cO.has(r))return cO.get(r);let i=sO.test(e)?e.toLowerCase()===e||!n||rO(e)===e:!1;return cO.set(r,i),i}var sO,cO,lO=o((()=>{nO(),aO(),sO=/^0x[a-fA-F0-9]{40}$/,cO=/*#__PURE__*/ new tO(8192)}));function uO(e){return typeof e[0]==`string`?fO(e):dO(e)}function dO(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function fO(e){return`0x${e.reduce((e,t)=>e+t.replace(`0x`,``),``)}`}var pO=o((()=>{}));function mO(e,t,n,{strict:r}={}){return rD(e,{strict:!1})?vO(e,t,n,{strict:r}):_O(e,t,n,{strict:r})}function hO(e,t){if(typeof t==`number`&&t>0&&t>aD(e)-1)throw new bD({offset:t,position:`start`,size:aD(e)})}function gO(e,t,n){if(typeof t==`number`&&typeof n==`number`&&aD(e)!==n-t)throw new bD({offset:n,position:`end`,size:aD(e)})}function _O(e,t,n,{strict:r}={}){hO(e,t);let i=e.slice(t,n);return r&&gO(i,t,n),i}function vO(e,t,n,{strict:r}={}){hO(e,t);let i=`0x${e.replace(`0x`,``).slice((t??0)*2,(n??e.length)*2)}`;return r&&gO(i,t,n),i}var yO=o((()=>{SD(),iD(),oD()})),bO,xO,SO=o((()=>{bO=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,xO=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/}));function CO(e,t){if(e.length!==t.length)throw new hD({expectedLength:e.length,givenLength:t.length});let n=EO(wO({params:e,values:t}));return n.length===0?`0x`:n}function wO({params:e,values:t}){let n=[];for(let r=0;r<e.length;r++)n.push(TO({param:e[r],value:t[r]}));return n}function TO({param:e,value:t}){let n=PO(e.type);if(n){let[r,i]=n;return OO(t,{length:r,param:{...e,type:i}})}if(e.type===`tuple`)return NO(t,{param:e});if(e.type===`address`)return DO(t);if(e.type===`bool`)return AO(t);if(e.type.startsWith(`uint`)||e.type.startsWith(`int`)){let n=e.type.startsWith(`int`),[,,r=`256`]=xO.exec(e.type)??[];return jO(t,{signed:n,size:Number(r)})}if(e.type.startsWith(`bytes`))return kO(t,{param:e});if(e.type===`string`)return MO(t);throw new _D(e.type,{docsPath:`/docs/contract/encodeAbiParameters`})}function EO(e){let t=0;for(let n=0;n<e.length;n++){let{dynamic:r,encoded:i}=e[n];t+=r?32:aD(i)}let n=[],r=[],i=0;for(let a=0;a<e.length;a++){let{dynamic:o,encoded:s}=e[a];o?(n.push(LD(t+i,{size:32})),r.push(s),i+=aD(s)):n.push(s)}return uO([...n,...r])}function DO(e){if(!oO(e))throw new $D({address:e});return{dynamic:!1,encoded:wD(e.toLowerCase())}}function OO(e,{length:t,param:n}){let r=t===null;if(!Array.isArray(e))throw new vD(e);if(!r&&e.length!==t)throw new pD({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let i=!1,a=[];for(let t=0;t<e.length;t++){let r=TO({param:n,value:e[t]});r.dynamic&&(i=!0),a.push(r)}if(r||i){let e=EO(a);if(r){let t=LD(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?uO([t,e]):t}}if(i)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:uO(a.map(({encoded:e})=>e))}}function kO(e,{param:t}){let[,n]=t.type.split(`bytes`),r=aD(e);if(!n){let t=e;return r%32!=0&&(t=wD(t,{dir:`right`,size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:uO([wD(LD(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new mD({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:wD(e,{dir:`right`})}}function AO(e){if(typeof e!=`boolean`)throw new dD(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:wD(FD(e))}}function jO(e,{signed:t,size:n=256}){if(typeof n==`number`){let r=2n**(BigInt(n)-(t?1n:0n))-1n,i=t?-r-1n:0n;if(e>r||e<i)throw new DD({max:r.toString(),min:i.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:LD(e,{size:32,signed:t})}}function MO(e){let t=RD(e),n=Math.ceil(aD(t)/32),r=[];for(let e=0;e<n;e++)r.push(wD(mO(t,e*32,(e+1)*32),{dir:`right`}));return{dynamic:!0,encoded:uO([wD(LD(aD(t),{size:32})),...r])}}function NO(e,{param:t}){let n=!1,r=[];for(let i=0;i<t.components.length;i++){let a=t.components[i],o=TO({param:a,value:e[Array.isArray(e)?i:a.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?EO(r):uO(r.map(({encoded:e})=>e))}}function PO(e){let t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}var FO=o((()=>{yD(),eO(),fD(),kD(),lO(),pO(),ED(),oD(),yO(),VD(),SO()})),IO,LO=o((()=>{IO=(e,t,n)=>JSON.stringify(e,(e,n)=>{let r=typeof n==`bigint`?n.toString():n;return typeof t==`function`?t(e,r):r},n)}));aO(),QD();function RO(e){return rO(`0x${ZD(`0x${e.substring(4)}`).substring(26)}`)}
150
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
151
+ function zO(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function BO(e){if(!zO(e))throw Error(`Uint8Array expected`)}function VO(e,t){if(typeof t!=`boolean`)throw Error(e+` boolean expected, got `+t)}function HO(e){let t=e.toString(16);return t.length&1?`0`+t:t}function UO(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?ok:BigInt(`0x`+e)}function WO(e){if(BO(e),ck)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=lk[e[n]];return t}function GO(e){if(e>=uk._0&&e<=uk._9)return e-uk._0;if(e>=uk.A&&e<=uk.F)return e-(uk.A-10);if(e>=uk.a&&e<=uk.f)return e-(uk.a-10)}function KO(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(ck)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=GO(e.charCodeAt(i)),a=GO(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function qO(e){return UO(WO(e))}function JO(e){return BO(e),UO(WO(Uint8Array.from(e).reverse()))}function YO(e,t){return KO(e.toString(16).padStart(t*2,`0`))}function XO(e,t){return YO(e,t).reverse()}function ZO(e,t,n){let r;if(typeof t==`string`)try{r=KO(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(zO(t))r=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let i=r.length;if(typeof n==`number`&&i!==n)throw Error(e+` of length `+n+` expected, got `+i);return r}function QO(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];BO(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function $O(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function ek(e,t,n){return dk(e)&&dk(t)&&dk(n)&&t<=e&&e<n}function tk(e,t,n,r){if(!ek(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function nk(e){let t=0;for(;e>ok;e>>=sk,t+=1);return t}function rk(e,t,n){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof n!=`function`)throw Error(`hmacFn must be a function`);let r=pk(e),i=pk(e),a=0,o=()=>{r.fill(1),i.fill(0),a=0},s=(...e)=>n(i,r,...e),c=(e=pk(0))=>{i=s(mk([0]),e),r=s(),e.length!==0&&(i=s(mk([1]),e),r=s())},l=()=>{if(a++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,n=[];for(;e<t;){r=s();let t=r.slice();n.push(t),e+=r.length}return QO(...n)};return(e,t)=>{o(),c(e);let n;for(;!(n=t(l()));)c();return o(),n}}function ik(e,t,n={}){let r=(t,n,r)=>{let i=hk[n];if(typeof i!=`function`)throw Error(`invalid validator function`);let a=e[t];if(!(r&&a===void 0)&&!i(a,e))throw Error(`param `+String(t)+` is invalid. Expected `+n+`, got `+a)};for(let[e,n]of Object.entries(t))r(e,n,!1);for(let[e,t]of Object.entries(n))r(e,t,!0);return e}function ak(e){let t=/* @__PURE__ */ new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}var ok,sk,ck,lk,uk,dk,fk,pk,mk,hk,gk=o((()=>{ok=/* @__PURE__ */ BigInt(0),sk=/* @__PURE__ */ BigInt(1),ck=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,lk=/* @__PURE__ */ Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),uk={_0:48,_9:57,A:65,F:70,a:97,f:102},dk=e=>typeof e==`bigint`&&ok<=e,fk=e=>(sk<<BigInt(e))-sk,pk=e=>new Uint8Array(e),mk=e=>Uint8Array.from(e),hk={bigint:e=>typeof e==`bigint`,function:e=>typeof e==`function`,boolean:e=>typeof e==`boolean`,string:e=>typeof e==`string`,stringOrUint8Array:e=>typeof e==`string`||zO(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e==`function`&&Number.isSafeInteger(e.outputLen)}}));
152
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
153
+ function X(e,t){let n=e%t;return n>=Mk?n:t+n}function _k(e,t,n){let r=e;for(;t-->Mk;)r*=r,r%=n;return r}function vk(e,t){if(e===Mk)throw Error(`invert: expected non-zero number`);if(t<=Mk)throw Error(`invert: expected positive modulus, got `+t);let n=X(e,t),r=t,i=Mk,a=Nk,o=Nk,s=Mk;for(;n!==Mk;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==Nk)throw Error(`invert: does not exist`);return X(i,t)}function yk(e,t){let n=(e.ORDER+Nk)/Ik,r=e.pow(t,n);if(!e.eql(e.sqr(r),t))throw Error(`Cannot find square root`);return r}function bk(e,t){let n=(e.ORDER-Lk)/Rk,r=e.mul(t,Pk),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,Pk),i),s=e.mul(a,e.sub(o,e.ONE));if(!e.eql(e.sqr(s),t))throw Error(`Cannot find square root`);return s}function xk(e){if(e<BigInt(3))throw Error(`sqrt is not defined for small field`);let t=e-Nk,n=0;for(;t%Pk===Mk;)t/=Pk,n++;let r=Pk,i=Ok(e);for(;Ek(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return yk;let a=i.pow(r,t),o=(t+Nk)/Pk;return function(e,r){if(e.is0(r))return r;if(Ek(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=Nk<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function Sk(e){return e%Ik===Fk?yk:e%Rk===Lk?bk:xk(e)}function Ck(e){return ik(e,zk.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`isSafeInteger`,BITS:`isSafeInteger`}))}function wk(e,t,n){if(n<Mk)throw Error(`invalid exponent, negatives unsupported`);if(n===Mk)return e.ONE;if(n===Nk)return t;let r=e.ONE,i=t;for(;n>Mk;)n&Nk&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Nk;return r}function Tk(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function Ek(e,t){let n=(e.ORDER-Nk)/Pk,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function Dk(e,t){t!==void 0&&xe(t);let n=t===void 0?e.toString(2).length:t;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Ok(e,t,n=!1,r={}){if(e<=Mk)throw Error(`invalid field: expected ORDER > 0, got `+e);let{nBitLength:i,nByteLength:a}=Dk(e,t);if(a>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let o,s=Object.freeze({ORDER:e,isLE:n,BITS:i,BYTES:a,MASK:fk(i),ZERO:Mk,ONE:Nk,create:t=>X(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return Mk<=t&&t<e},is0:e=>e===Mk,isOdd:e=>(e&Nk)===Nk,neg:t=>X(-t,e),eql:(e,t)=>e===t,sqr:t=>X(t*t,e),add:(t,n)=>X(t+n,e),sub:(t,n)=>X(t-n,e),mul:(t,n)=>X(t*n,e),pow:(e,t)=>wk(s,e,t),div:(t,n)=>X(t*vk(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>vk(t,e),sqrt:r.sqrt||(t=>(o||=Sk(e),o(s,t))),toBytes:e=>n?XO(e,a):YO(e,a),fromBytes:e=>{if(e.length!==a)throw Error(`Field.fromBytes: expected `+a+` bytes, got `+e.length);return n?JO(e):qO(e)},invertBatch:e=>Tk(s,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(s)}function kk(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function Ak(e){let t=kk(e);return t+Math.ceil(t/2)}function jk(e,t,n=!1){let r=e.length,i=kk(t),a=Ak(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=X(n?JO(e):qO(e),t-Nk)+Nk;return n?XO(o,i):YO(o,i)}var Mk,Nk,Pk,Fk,Ik,Lk,Rk,zk,Bk=o((()=>{qe(),gk(),Mk=BigInt(0),Nk=BigInt(1),Pk=/* @__PURE__ */ BigInt(2),Fk=/* @__PURE__ */ BigInt(3),Ik=/* @__PURE__ */ BigInt(4),Lk=/* @__PURE__ */ BigInt(5),Rk=/* @__PURE__ */ BigInt(8),zk=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`]}));
154
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
155
+ function Vk(e,t){let n=t.negate();return e?n:t}function Hk(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Uk(e,t){Hk(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:fk(e),maxNumber:i,shiftBy:BigInt(e)}}function Wk(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=Qk);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function Gk(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function Kk(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}function qk(e){return eA.get(e)||1}function Jk(e,t){return{constTimeNegate:Vk,hasPrecomputes(e){return qk(e)!==1},unsafeLadder(t,n,r=e.ZERO){let i=t;for(;n>Zk;)n&Qk&&(r=r.add(i)),i=i.double(),n>>=Qk;return r},precomputeWindow(e,n){let{windows:r,windowSize:i}=Uk(n,t),a=[],o=e,s=o;for(let e=0;e<r;e++){s=o,a.push(s);for(let e=1;e<i;e++)s=s.add(o),a.push(s);o=s.double()}return a},wNAF(n,r,i){let a=e.ZERO,o=e.BASE,s=Uk(n,t);for(let e=0;e<s.windows;e++){let{nextN:t,offset:n,isZero:c,isNeg:l,isNegF:u,offsetF:d}=Wk(i,e,s);i=t,c?o=o.add(Vk(u,r[d])):a=a.add(Vk(l,r[n]))}return{p:a,f:o}},wNAFUnsafe(n,r,i,a=e.ZERO){let o=Uk(n,t);for(let e=0;e<o.windows&&i!==Zk;e++){let{nextN:t,offset:n,isZero:s,isNeg:c}=Wk(i,e,o);if(i=t,!s){let e=r[n];a=a.add(c?e.negate():e)}}return a},getPrecomputes(e,t,n){let r=$k.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&$k.set(t,n(r))),r},wNAFCached(e,t,n){let r=qk(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)},wNAFCachedUnsafe(e,t,n,r){let i=qk(e);return i===1?this.unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)},setWindowSize(e,n){Hk(n,t),eA.set(e,n),$k.delete(e)}}}function Yk(e,t,n,r){Gk(n,e),Kk(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=nk(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=fk(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Xk(e){return Ck(e.Fp),ik(e,{n:`bigint`,h:`bigint`,Gx:`field`,Gy:`field`},{nBitLength:`isSafeInteger`,nByteLength:`isSafeInteger`}),Object.freeze({...Dk(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Zk,Qk,$k,eA,tA=o((()=>{Bk(),gk(),Zk=BigInt(0),Qk=BigInt(1),$k=/* @__PURE__ */ new WeakMap,eA=/* @__PURE__ */ new WeakMap}));
156
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
157
+ function nA(e){e.lowS!==void 0&&VO(`lowS`,e.lowS),e.prehash!==void 0&&VO(`prehash`,e.prehash)}function rA(e){let t=Xk(e);ik(t,{a:`field`,b:`field`},{allowInfinityPoint:`boolean`,allowedPrivateKeyLengths:`array`,clearCofactor:`function`,fromBytes:`function`,isTorsionFree:`function`,toBytes:`function`,wrapPrivateKey:`boolean`});let{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw Error(`invalid endo: CURVE.a must be 0`);if(typeof n!=`object`||typeof n.beta!=`bigint`||typeof n.splitScalar!=`function`)throw Error(`invalid endo: expected "beta": bigint and "splitScalar": function`)}return Object.freeze({...t})}function iA(e,t){return WO(YO(e,t))}function aA(e){let t=rA(e),{Fp:n}=t,r=Ok(t.n,t.nBitLength),i=t.toBytes||((e,t,r)=>{let i=t.toAffine();return QO(Uint8Array.from([4]),n.toBytes(i.x),n.toBytes(i.y))}),a=t.fromBytes||(e=>{let t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function o(e){let{a:r,b:i}=t,a=n.sqr(e),o=n.mul(a,e);return n.add(n.add(o,n.mul(e,r)),i)}function s(e,t){let r=n.sqr(t),i=o(e);return n.eql(r,i)}if(!s(t.Gx,t.Gy))throw Error(`bad curve params: generator point`);let c=n.mul(n.pow(t.a,mA),hA),l=n.mul(n.sqr(t.b),BigInt(27));if(n.is0(n.add(c,l)))throw Error(`bad curve params: a or b`);function u(e){return ek(e,Z,t.n)}function d(e){let{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:i,n:a}=t;if(n&&typeof e!=`bigint`){if(zO(e)&&(e=WO(e)),typeof e!=`string`||!n.includes(e.length))throw Error(`invalid private key`);e=e.padStart(r*2,`0`)}let o;try{o=typeof e==`bigint`?e:qO(ZO(`private key`,e,r))}catch{throw Error(`invalid private key, expected hex or `+r+` bytes, got `+typeof e)}return i&&(o=X(o,a)),tk(`private key`,o,Z,a),o}function f(e){if(!(e instanceof h))throw Error(`ProjectivePoint expected`)}let p=ak((e,t)=>{let{px:r,py:i,pz:a}=e;if(n.eql(a,n.ONE))return{x:r,y:i};let o=e.is0();t??=o?n.ONE:n.inv(a);let s=n.mul(r,t),c=n.mul(i,t),l=n.mul(a,t);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(l,n.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),m=ak(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.py))return;throw Error(`bad point: ZERO`)}let{x:r,y:i}=e.toAffine();if(!n.isValid(r)||!n.isValid(i))throw Error(`bad point: x or y not FE`);if(!s(r,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});class h{constructor(e,t,r){if(e==null||!n.isValid(e))throw Error(`x required`);if(t==null||!n.isValid(t)||n.is0(t))throw Error(`y required`);if(r==null||!n.isValid(r))throw Error(`z required`);this.px=e,this.py=t,this.pz=r,Object.freeze(this)}static fromAffine(e){let{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw Error(`invalid affine point`);if(e instanceof h)throw Error(`projective point not allowed`);let i=e=>n.eql(e,n.ZERO);return i(t)&&i(r)?h.ZERO:new h(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){let t=Tk(n,e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(h.fromAffine)}static fromHex(e){let t=h.fromAffine(a(ZO(`pointHex`,e)));return t.assertValidity(),t}static fromPrivateKey(e){return h.BASE.multiply(d(e))}static msm(e,t){return Yk(h,r,e,t)}_setWindowSize(e){v.setWindowSize(this,e)}assertValidity(){m(this)}hasEvenY(){let{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw Error(`Field doesn't support isOdd`)}equals(e){f(e);let{px:t,py:r,pz:i}=this,{px:a,py:o,pz:s}=e,c=n.eql(n.mul(t,s),n.mul(a,i)),l=n.eql(n.mul(r,s),n.mul(o,i));return c&&l}negate(){return new h(this.px,n.neg(this.py),this.pz)}double(){let{a:e,b:r}=t,i=n.mul(r,mA),{px:a,py:o,pz:s}=this,c=n.ZERO,l=n.ZERO,u=n.ZERO,d=n.mul(a,a),f=n.mul(o,o),p=n.mul(s,s),m=n.mul(a,o);return m=n.add(m,m),u=n.mul(a,s),u=n.add(u,u),c=n.mul(e,u),l=n.mul(i,p),l=n.add(c,l),c=n.sub(f,l),l=n.add(f,l),l=n.mul(c,l),c=n.mul(m,c),u=n.mul(i,u),p=n.mul(e,p),m=n.sub(d,p),m=n.mul(e,m),m=n.add(m,u),u=n.add(d,d),d=n.add(u,d),d=n.add(d,p),d=n.mul(d,m),l=n.add(l,d),p=n.mul(o,s),p=n.add(p,p),d=n.mul(p,m),c=n.sub(c,d),u=n.mul(p,f),u=n.add(u,u),u=n.add(u,u),new h(c,l,u)}add(e){f(e);let{px:r,py:i,pz:a}=this,{px:o,py:s,pz:c}=e,l=n.ZERO,u=n.ZERO,d=n.ZERO,p=t.a,m=n.mul(t.b,mA),g=n.mul(r,o),_=n.mul(i,s),v=n.mul(a,c),y=n.add(r,i),b=n.add(o,s);y=n.mul(y,b),b=n.add(g,_),y=n.sub(y,b),b=n.add(r,a);let x=n.add(o,c);return b=n.mul(b,x),x=n.add(g,v),b=n.sub(b,x),x=n.add(i,a),l=n.add(s,c),x=n.mul(x,l),l=n.add(_,v),x=n.sub(x,l),d=n.mul(p,b),l=n.mul(m,v),d=n.add(l,d),l=n.sub(_,d),d=n.add(_,d),u=n.mul(l,d),_=n.add(g,g),_=n.add(_,g),v=n.mul(p,v),b=n.mul(m,b),_=n.add(_,v),v=n.sub(g,v),v=n.mul(p,v),b=n.add(b,v),g=n.mul(_,b),u=n.add(u,g),g=n.mul(x,b),l=n.mul(y,l),l=n.sub(l,g),g=n.mul(y,_),d=n.mul(x,d),d=n.add(d,g),new h(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(h.ZERO)}wNAF(e){return v.wNAFCached(this,e,h.normalizeZ)}multiplyUnsafe(e){let{endo:r,n:i}=t;tk(`scalar`,e,fA,i);let a=h.ZERO;if(e===fA)return a;if(this.is0()||e===Z)return this;if(!r||v.hasPrecomputes(this))return v.wNAFCachedUnsafe(this,e,h.normalizeZ);let{k1neg:o,k1:s,k2neg:c,k2:l}=r.splitScalar(e),u=a,d=a,f=this;for(;s>fA||l>fA;)s&Z&&(u=u.add(f)),l&Z&&(d=d.add(f)),f=f.double(),s>>=Z,l>>=Z;return o&&(u=u.negate()),c&&(d=d.negate()),d=new h(n.mul(d.px,r.beta),d.py,d.pz),u.add(d)}multiply(e){let{endo:r,n:i}=t;tk(`scalar`,e,Z,i);let a,o;if(r){let{k1neg:t,k1:i,k2neg:s,k2:c}=r.splitScalar(e),{p:l,f:u}=this.wNAF(i),{p:d,f}=this.wNAF(c);l=v.constTimeNegate(t,l),d=v.constTimeNegate(s,d),d=new h(n.mul(d.px,r.beta),d.py,d.pz),a=l.add(d),o=u.add(f)}else{let{p:t,f:n}=this.wNAF(e);a=t,o=n}return h.normalizeZ([a,o])[0]}multiplyAndAddUnsafe(e,t,n){let r=h.BASE,i=(e,t)=>t===fA||t===Z||!e.equals(r)?e.multiplyUnsafe(t):e.multiply(t),a=i(this,t).add(i(e,n));return a.is0()?void 0:a}toAffine(e){return p(this,e)}isTorsionFree(){let{h:e,isTorsionFree:n}=t;if(e===Z)return!0;if(n)return n(h,this);throw Error(`isTorsionFree() has not been declared for the elliptic curve`)}clearCofactor(){let{h:e,clearCofactor:n}=t;return e===Z?this:n?n(h,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return VO(`isCompressed`,e),this.assertValidity(),i(h,this,e)}toHex(e=!0){return VO(`isCompressed`,e),WO(this.toRawBytes(e))}}h.BASE=new h(t.Gx,t.Gy,n.ONE),h.ZERO=new h(n.ZERO,n.ONE,n.ZERO);let{endo:g,nBitLength:_}=t,v=Jk(h,g?Math.ceil(_/2):_);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:d,weierstrassEquation:o,isWithinCurveOrder:u}}function oA(e){let t=Xk(e);return ik(t,{hash:`hash`,hmac:`function`,randomBytes:`function`},{bits2int:`function`,bits2int_modN:`function`,lowS:`boolean`}),Object.freeze({lowS:!0,...t})}function sA(e){let t=oA(e),{Fp:n,n:r,nByteLength:i,nBitLength:a}=t,o=n.BYTES+1,s=2*n.BYTES+1;function c(e){return X(e,r)}function l(e){return vk(e,r)}let{ProjectivePoint:u,normPrivateKeyToScalar:d,weierstrassEquation:f,isWithinCurveOrder:p}=aA({...t,toBytes(e,t,r){let i=t.toAffine(),a=n.toBytes(i.x),o=QO;return VO(`isCompressed`,r),r?o(Uint8Array.from([t.hasEvenY()?2:3]),a):o(Uint8Array.from([4]),a,n.toBytes(i.y))},fromBytes(e){let t=e.length,r=e[0],i=e.subarray(1);if(t===o&&(r===2||r===3)){let e=qO(i);if(!ek(e,Z,n.ORDER))throw Error(`Point is not on curve`);let t=f(e),a;try{a=n.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`Point is not on curve`+t)}let o=(a&Z)===Z;return(r&1)==1!==o&&(a=n.neg(a)),{x:e,y:a}}if(t===s&&r===4)return{x:n.fromBytes(i.subarray(0,n.BYTES)),y:n.fromBytes(i.subarray(n.BYTES,2*n.BYTES))};{let e=o,n=s;throw Error(`invalid Point, expected length of `+e+`, or uncompressed `+n+`, got `+t)}}});function m(e){return e>r>>Z}function h(e){return m(e)?c(-e):e}let g=(e,t,n)=>qO(e.slice(t,n));class _{constructor(e,t,n){tk(`r`,e,Z,r),tk(`s`,t,Z,r),this.r=e,this.s=t,n!=null&&(this.recovery=n),Object.freeze(this)}static fromCompact(e){let t=i;return e=ZO(`compactSignature`,e,t*2),new _(g(e,0,t),g(e,t,2*t))}static fromDER(e){let{r:t,s:n}=dA.toSig(ZO(`DER`,e));return new _(t,n)}assertValidity(){}addRecoveryBit(e){return new _(this.r,this.s,e)}recoverPublicKey(e){let{r,s:i,recovery:a}=this,o=C(ZO(`msgHash`,e));if(a==null||![0,1,2,3].includes(a))throw Error(`recovery id invalid`);let s=a===2||a===3?r+t.n:r;if(s>=n.ORDER)throw Error(`recovery id 2 or 3 invalid`);let d=a&1?`03`:`02`,f=u.fromHex(d+iA(s,n.BYTES)),p=l(s),m=c(-o*p),h=c(i*p),g=u.BASE.multiplyAndAddUnsafe(f,m,h);if(!g)throw Error(`point at infinify`);return g.assertValidity(),g}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new _(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return KO(this.toDERHex())}toDERHex(){return dA.hexFromSig(this)}toCompactRawBytes(){return KO(this.toCompactHex())}toCompactHex(){let e=i;return iA(this.r,e)+iA(this.s,e)}}let v={isValidPrivateKey(e){try{return d(e),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{let e=Ak(t.n);return jk(t.randomBytes(e),t.n)},precompute(e=8,t=u.BASE){return t._setWindowSize(e),t.multiply(BigInt(3)),t}};function y(e,t=!0){return u.fromPrivateKey(e).toRawBytes(t)}function b(e){if(typeof e==`bigint`)return!1;if(e instanceof u)return!0;let r=ZO(`key`,e).length,a=n.BYTES,o=a+1,s=2*a+1;if(!(t.allowedPrivateKeyLengths||i===o))return r===o||r===s}function x(e,t,n=!0){if(b(e)===!0)throw Error(`first arg must be private key`);if(b(t)===!1)throw Error(`second arg must be public key`);return u.fromHex(t).multiply(d(e)).toRawBytes(n)}let S=t.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=qO(e),n=e.length*8-a;return n>0?t>>BigInt(n):t},C=t.bits2int_modN||function(e){return c(S(e))},w=fk(a);function T(e){return tk(`num < 2^`+a,e,fA,w),YO(e,i)}function ee(e,r,i=te){if([`recovered`,`canonical`].some(e=>e in i))throw Error(`sign() legacy options not supported`);let{hash:a,randomBytes:o}=t,{lowS:s,prehash:f,extraEntropy:g}=i;s??=!0,e=ZO(`msgHash`,e),nA(i),f&&(e=ZO(`prehashed msgHash`,a(e)));let v=C(e),y=d(r),b=[T(y),T(v)];if(g!=null&&g!==!1){let e=g===!0?o(n.BYTES):g;b.push(ZO(`extraEntropy`,e))}let x=QO(...b),w=v;function ee(e){let t=S(e);if(!p(t))return;let n=l(t),r=u.BASE.multiply(t).toAffine(),i=c(r.x);if(i===fA)return;let a=c(n*c(w+i*y));if(a===fA)return;let o=(r.x===i?0:2)|Number(r.y&Z),d=a;return s&&m(a)&&(d=h(a),o^=1),new _(i,d,o)}return{seed:x,k2sig:ee}}let te={lowS:t.lowS,prehash:!1},ne={lowS:t.lowS,prehash:!1};function re(e,n,r=te){let{seed:i,k2sig:a}=ee(e,n,r),o=t;return rk(o.hash.outputLen,o.nByteLength,o.hmac)(i,a)}u.BASE._setWindowSize(8);function ie(e,n,r,i=ne){let a=e;n=ZO(`msgHash`,n),r=ZO(`publicKey`,r);let{lowS:o,prehash:s,format:d}=i;if(nA(i),`strict`in i)throw Error(`options.strict was renamed to lowS`);if(d!==void 0&&d!==`compact`&&d!==`der`)throw Error(`format must be compact or der`);let f=typeof a==`string`||zO(a),p=!f&&!d&&typeof a==`object`&&!!a&&typeof a.r==`bigint`&&typeof a.s==`bigint`;if(!f&&!p)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);let m,h;try{if(p&&(m=new _(a.r,a.s)),f){try{d!==`compact`&&(m=_.fromDER(a))}catch(e){if(!(e instanceof dA.Err))throw e}!m&&d!==`der`&&(m=_.fromCompact(a))}h=u.fromHex(r)}catch{return!1}if(!m||o&&m.hasHighS())return!1;s&&(n=t.hash(n));let{r:g,s:v}=m,y=C(n),b=l(v),x=c(y*b),S=c(g*b),w=u.BASE.multiplyAndAddUnsafe(h,x,S)?.toAffine();return w?c(w.x)===g:!1}return{CURVE:t,getPublicKey:y,getSharedSecret:x,sign:re,verify:ie,ProjectivePoint:u,Signature:_,utils:v}}function cA(e,t){let n=e.ORDER,r=fA;for(let e=n-Z;e%pA===fA;e/=pA)r+=Z;let i=r,a=pA<<i-Z-Z,o=a*pA,s=(n-Z)/o,c=(s-Z)/pA,l=o-Z,u=a,d=e.pow(t,s),f=e.pow(t,(s+Z)/pA),p=(t,n)=>{let r=d,a=e.pow(n,l),o=e.sqr(a);o=e.mul(o,n);let s=e.mul(t,o);s=e.pow(s,c),s=e.mul(s,a),a=e.mul(s,n),o=e.mul(s,t);let p=e.mul(o,a);s=e.pow(p,u);let m=e.eql(s,e.ONE);a=e.mul(o,f),s=e.mul(p,r),o=e.cmov(a,o,m),p=e.cmov(s,p,m);for(let t=i;t>Z;t--){let n=t-pA;n=pA<<n-Z;let i=e.pow(p,n),s=e.eql(i,e.ONE);a=e.mul(o,r),r=e.mul(r,r),i=e.mul(p,r),o=e.cmov(a,o,s),p=e.cmov(i,p,s)}return{isValid:m,value:o}};if(e.ORDER%hA===mA){let n=(e.ORDER-mA)/hA,r=e.sqrt(e.neg(t));p=(t,i)=>{let a=e.sqr(i),o=e.mul(t,i);a=e.mul(a,o);let s=e.pow(a,n);s=e.mul(s,o);let c=e.mul(s,r),l=e.mul(e.sqr(s),i),u=e.eql(l,t);return{isValid:u,value:e.cmov(c,s,u)}}}return p}function lA(e,t){if(Ck(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw Error(`mapToCurveSimpleSWU: invalid opts`);let n=cA(e,t.Z);if(!e.isOdd)throw Error(`Fp.isOdd is not implemented!`);return r=>{let i,a,o,s,c,l,u,d;i=e.sqr(r),i=e.mul(i,t.Z),a=e.sqr(i),a=e.add(a,i),o=e.add(a,e.ONE),o=e.mul(o,t.B),s=e.cmov(t.Z,e.neg(a),!e.eql(a,e.ZERO)),s=e.mul(s,t.A),a=e.sqr(o),l=e.sqr(s),c=e.mul(l,t.A),a=e.add(a,c),a=e.mul(a,o),l=e.mul(l,s),c=e.mul(l,t.B),a=e.add(a,c),u=e.mul(i,o);let{isValid:f,value:p}=n(a,l);d=e.mul(i,r),d=e.mul(d,p),u=e.cmov(u,o,f),d=e.cmov(d,p,f);let m=e.isOdd(r)===e.isOdd(d);d=e.cmov(e.neg(d),d,m);let h=Tk(e,[s],!0)[0];return u=e.mul(u,h),{x:u,y:d}}}var uA,dA,fA,Z,pA,mA,hA,gA=o((()=>{tA(),Bk(),gk(),uA=class extends Error{constructor(e=``){super(e)}},dA={Err:uA,_tlv:{encode:(e,t)=>{let{Err:n}=dA;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=HO(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?HO(i.length/2|128):``;return HO(e)+a+i+t},decode(e,t){let{Err:n}=dA,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=dA;if(e<fA)throw new t(`integer: negative integers are not allowed`);let n=HO(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=dA;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return qO(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=dA,i=ZO(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=dA,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},fA=BigInt(0),Z=BigInt(1),pA=BigInt(2),mA=BigInt(3),hA=BigInt(4)}));
158
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
159
+ function _A(e){return{hash:e,hmac:(t,...n)=>Vb(e,t,Re(...n)),randomBytes:Be}}function vA(e,t){let n=t=>sA({...e,..._A(t)});return{...n(t),create:n}}var yA=o((()=>{Hb(),qe(),gA()}));function bA(e,t){if(SA(e),SA(t),e<0||e>=1<<8*t)throw Error(`invalid I2OSP input: `+e);let n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function xA(e,t){let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r];return n}function SA(e){if(!Number.isSafeInteger(e))throw Error(`number expected`)}function CA(e,t,n,r){BO(e),BO(t),SA(n),t.length>255&&(t=r(QO($O(`H2C-OVERSIZE-DST-`),t)));let{outputLen:i,blockLen:a}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw Error(`expand_message_xmd: invalid lenInBytes`);let s=QO(t,bA(t.length,1)),c=bA(0,a),l=bA(n,2),u=Array(o),d=r(QO(c,e,l,bA(0,1),s));u[0]=r(QO(d,bA(1,1),s));for(let e=1;e<=o;e++){let t=[xA(d,u[e-1]),bA(e+1,1),s];u[e]=r(QO(...t))}return QO(...u).slice(0,n)}function wA(e,t,n,r,i){if(BO(e),BO(t),SA(n),t.length>255){let e=Math.ceil(2*r/8);t=i.create({dkLen:e}).update($O(`H2C-OVERSIZE-DST-`)).update(t).digest()}if(n>65535||t.length>255)throw Error(`expand_message_xof: invalid lenInBytes`);return i.create({dkLen:n}).update(e).update(bA(n,2)).update(t).update(bA(t.length,1)).digest()}function TA(e,t,n){ik(n,{DST:`stringOrUint8Array`,p:`bigint`,m:`isSafeInteger`,k:`isSafeInteger`,hash:`hash`});let{p:r,k:i,m:a,hash:o,expand:s,DST:c}=n;BO(e),SA(t);let l=typeof c==`string`?$O(c):c,u=r.toString(2).length,d=Math.ceil((u+i)/8),f=t*a*d,p;if(s===`xmd`)p=CA(e,l,f,o);else if(s===`xof`)p=wA(e,l,f,i,o);else if(s===`_internal_pass`)p=e;else throw Error(`expand must be "xmd" or "xof"`);let m=Array(t);for(let e=0;e<t;e++){let t=Array(a);for(let n=0;n<a;n++){let i=d*(n+e*a),o=p.subarray(i,i+d);t[n]=X(OA(o),r)}m[e]=t}return m}function EA(e,t){let n=t.map(e=>Array.from(e).reverse());return(t,r)=>{let[i,a,o,s]=n.map(n=>n.reduce((n,r)=>e.add(e.mul(n,t),r))),[c,l]=Tk(e,[a,s],!0);return t=e.mul(i,c),r=e.mul(r,e.mul(o,l)),{x:t,y:r}}}function DA(e,t,n){if(typeof t!=`function`)throw Error(`mapToCurve() must be defined`);function r(n){return e.fromAffine(t(n))}function i(t){let n=t.clearCofactor();return n.equals(e.ZERO)?e.ZERO:(n.assertValidity(),n)}return{defaults:n,hashToCurve(e,t){let a=TA(e,2,{...n,DST:n.DST,...t}),o=r(a[0]),s=r(a[1]);return i(o.add(s))},encodeToCurve(e,t){return i(r(TA(e,1,{...n,DST:n.encodeDST,...t})[0]))},mapToCurve(e){if(!Array.isArray(e))throw Error(`expected array of bigints`);for(let t of e)if(typeof t!=`bigint`)throw Error(`expected array of bigints`);return i(r(e))}}}var OA,kA=o((()=>{Bk(),gk(),OA=qO})),AA=/* @__PURE__ */ c({encodeToCurve:()=>oj,hashToCurve:()=>aj,schnorr:()=>tj,secp256k1:()=>KA,secp256k1_hasher:()=>ij});
160
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
161
+ function jA(e){let t=zA,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),s=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=_k(_k(_k(u,n,t)*u%t,n,t)*u%t,UA,t)*l%t,f=_k(d,i,t)*d%t,p=_k(f,a,t)*f%t,m=_k(p,s,t)*p%t,h=_k(_k(_k(_k(_k(_k(m,c,t)*m%t,s,t)*p%t,n,t)*u%t,o,t)*f%t,r,t)*l%t,UA,t);if(!GA.eql(GA.sqr(h),e))throw Error(`Cannot find square root`);return h}function MA(e,...t){let n=qA[e];if(n===void 0){let t=Mt(Uint8Array.from(e,e=>e.charCodeAt(0)));n=QO(t,t),qA[e]=n}return Mt(QO(n,...t))}function NA(e){let t=KA.utils.normPrivateKeyToScalar(e),n=QA.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:ZA(-t),bytes:JA(n)}}function PA(e){tk(`x`,e,HA,zA);let t=XA(e*e),n=jA(XA(t*e+BigInt(7)));n%UA!==VA&&(n=XA(-n));let r=new QA(e,n,HA);return r.assertValidity(),r}function FA(...e){return ZA(ej(MA(`BIP0340/challenge`,...e)))}function IA(e){return NA(e).bytes}function LA(e,t,n=Be(32)){let r=ZO(`message`,e),{bytes:i,scalar:a}=NA(t),o=ZO(`auxRand`,n,32),s=MA(`BIP0340/nonce`,YA(a^ej(MA(`BIP0340/aux`,o))),i,r),c=ZA(ej(s));if(c===VA)throw Error(`sign failed: k is zero`);let{bytes:l,scalar:u}=NA(c),d=FA(l,i,r),f=/* @__PURE__ */ new Uint8Array(64);if(f.set(l,0),f.set(YA(ZA(u+d*a)),32),!RA(f,r,i))throw Error(`sign: Invalid signature produced`);return f}function RA(e,t,n){let r=ZO(`signature`,e,64),i=ZO(`message`,t),a=ZO(`publicKey`,n,32);try{let e=PA(ej(a)),t=ej(r.subarray(0,32));if(!ek(t,HA,zA))return!1;let n=ej(r.subarray(32,64));if(!ek(n,HA,BA))return!1;let o=FA(YA(t),JA(e),i),s=$A(e,n,ZA(-o));return!(!s||!s.hasEvenY()||s.toAffine().x!==t)}catch{return!1}}var zA,BA,VA,HA,UA,WA,GA,KA,qA,JA,YA,XA,ZA,QA,$A,ej,tj,nj,rj,ij,aj,oj,sj=o((()=>{Ft(),qe(),yA(),kA(),Bk(),gk(),gA(),zA=BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f`),BA=BigInt(`0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141`),VA=BigInt(0),HA=BigInt(1),UA=BigInt(2),WA=(e,t)=>(e+t/UA)/t,GA=Ok(zA,void 0,void 0,{sqrt:jA}),KA=vA({a:VA,b:BigInt(7),Fp:GA,n:BA,Gx:BigInt(`55066263022277343669578718895168534326250603453777594175500187360389116729240`),Gy:BigInt(`32670510020758816978083085130507043184471273380659243275938904335757337482424`),h:BigInt(1),lowS:!0,endo:{beta:BigInt(`0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee`),splitScalar:e=>{let t=BA,n=BigInt(`0x3086d221a7d46bcde86c90e49284eb15`),r=-HA*BigInt(`0xe4437ed6010e88286f547fa90abfe4c3`),i=BigInt(`0x114ca50f7a8e2f3f657c1108d9d44cfd8`),a=n,o=BigInt(`0x100000000000000000000000000000000`),s=WA(a*e,t),c=WA(-r*e,t),l=X(e-s*n-c*i,t),u=X(-s*r-c*a,t),d=l>o,f=u>o;if(d&&(l=t-l),f&&(u=t-u),l>o||u>o)throw Error(`splitScalar: Endomorphism failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}}},Mt),qA={},JA=e=>e.toRawBytes(!0).slice(1),YA=e=>YO(e,32),XA=e=>X(e,zA),ZA=e=>X(e,BA),QA=KA.ProjectivePoint,$A=(e,t,n)=>QA.BASE.multiplyAndAddUnsafe(e,t,n),ej=qO,tj={getPublicKey:IA,sign:LA,verify:RA,utils:{randomPrivateKey:KA.utils.randomPrivateKey,lift_x:PA,pointToBytes:JA,numberToBytesBE:YO,bytesToNumberBE:qO,taggedHash:MA,mod:X}},nj=/* @__PURE__ */ EA(GA,[[`0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7`,`0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581`,`0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262`,`0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c`],[`0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b`,`0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14`,`0x0000000000000000000000000000000000000000000000000000000000000001`],[`0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c`,`0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3`,`0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931`,`0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84`],[`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b`,`0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573`,`0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f`,`0x0000000000000000000000000000000000000000000000000000000000000001`]].map(e=>e.map(e=>BigInt(e)))),rj=/* @__PURE__ */ lA(GA,{A:BigInt(`0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533`),B:BigInt(`1771`),Z:GA.create(BigInt(`-11`))}),ij=/* @__PURE__ */ DA(KA.ProjectivePoint,e=>{let{x:t,y:n}=rj(GA.create(e[0]));return nj(t,n)},{DST:`secp256k1_XMD:SHA-256_SSWU_RO_`,encodeDST:`secp256k1_XMD:SHA-256_SSWU_NU_`,p:GA.ORDER,m:1,k:128,expand:`xmd`,hash:Mt}),aj=ij.hashToCurve,oj=ij.encodeToCurve}));iD(),oD(),ND(),VD();async function cj({hash:e,signature:t}){let n=rD(e)?e:PD(e),{secp256k1:r}=await Promise.resolve().then(()=>(sj(),AA));return`0x${(()=>{if(typeof t==`object`&&`r`in t&&`s`in t){let{r:e,s:n,v:i,yParity:a}=t,o=lj(Number(a??i));return new r.Signature(jD(e),jD(n)).addRecoveryBit(o)}let e=rD(t)?t:PD(t);if(aD(e)!==65)throw Error(`invalid signature length`);let n=lj(MD(`0x${e.slice(130)}`));return r.Signature.fromCompact(e.substring(2,130)).addRecoveryBit(n)})().recoverPublicKey(n.substring(2)).toHex(!1)}`}function lj(e){if(e===0||e===1)return e;if(e===27)return 0;if(e===28)return 1;throw Error(`Invalid yParityOrV value`)}async function uj({hash:e,signature:t}){return RO(await cj({hash:e,signature:t}))}LO(),fD();var dj=class extends dD{constructor({domain:e}){super(`Invalid domain "${IO(e)}".`,{metaMessages:[`Must be a valid EIP-712 domain.`]})}},fj=class extends dD{constructor({primaryType:e,types:t}){super(`Invalid primary type \`${e}\` must be one of \`${JSON.stringify(Object.keys(t))}\`.`,{docsPath:`/api/glossary/Errors#typeddatainvalidprimarytypeerror`,metaMessages:["Check that the primary type is a key in `types`."]})}},pj=class extends dD{constructor({type:e}){super(`Struct type "${e}" is invalid.`,{metaMessages:[`Struct type must not be a Solidity type.`],name:`InvalidStructTypeError`})}};yD(),eO(),lO(),oD(),VD(),SO();function mj(e){let{domain:t,message:n,primaryType:r,types:i}=e,a=(e,t)=>{for(let n of e){let{name:e,type:r}=n,o=t[e],s=r.match(xO);if(s&&(typeof o==`number`||typeof o==`bigint`)){let[e,t,n]=s;LD(o,{signed:t===`int`,size:Number.parseInt(n,10)/8})}if(r===`address`&&typeof o==`string`&&!oO(o))throw new $D({address:o});let c=r.match(bO);if(c){let[e,t]=c;if(t&&aD(o)!==Number.parseInt(t,10))throw new gD({expectedSize:Number.parseInt(t,10),givenSize:aD(o)})}let l=i[r];l&&(gj(r),a(l,o))}};if(i.EIP712Domain&&t){if(typeof t!=`object`)throw new dj({domain:t});a(i.EIP712Domain,t)}if(r!==`EIP712Domain`){if(i[r])a(i[r],n);else throw new fj({primaryType:r,types:i})}}function hj({domain:e}){return[typeof e?.name==`string`&&{name:`name`,type:`string`},e?.version&&{name:`version`,type:`string`},(typeof e?.chainId==`number`||typeof e?.chainId==`bigint`)&&{name:`chainId`,type:`uint256`},e?.verifyingContract&&{name:`verifyingContract`,type:`address`},e?.salt&&{name:`salt`,type:`bytes32`}].filter(Boolean)}function gj(e){if(e===`address`||e===`bool`||e===`string`||e.startsWith(`bytes`)||e.startsWith(`uint`)||e.startsWith(`int`))throw new pj({type:e})}FO(),pO(),VD(),QD();function _j(e){let{domain:t={},message:n,primaryType:r}=e,i={EIP712Domain:hj({domain:t}),...e.types};mj({domain:t,message:n,primaryType:r,types:i});let a=[`0x1901`];return t&&a.push(vj({domain:t,types:i})),r!==`EIP712Domain`&&a.push(yj({data:n,primaryType:r,types:i})),ZD(uO(a))}function vj({domain:e,types:t}){return yj({data:e,primaryType:`EIP712Domain`,types:t})}function yj({data:e,primaryType:t,types:n}){return ZD(bj({data:e,primaryType:t,types:n}))}function bj({data:e,primaryType:t,types:n}){let r=[{type:`bytes32`}],i=[xj({primaryType:t,types:n})];for(let a of n[t]){let[t,o]=wj({types:n,name:a.name,type:a.type,value:e[a.name]});r.push(t),i.push(o)}return CO(r,i)}function xj({primaryType:e,types:t}){return ZD(PD(Sj({primaryType:e,types:t})))}function Sj({primaryType:e,types:t}){let n=``,r=Cj({primaryType:e,types:t});r.delete(e);let i=[e,...Array.from(r).sort()];for(let e of i)n+=`${e}(${t[e].map(({name:e,type:t})=>`${t} ${e}`).join(`,`)})`;return n}function Cj({primaryType:e,types:t},n=/* @__PURE__ */ new Set){let r=e.match(/^\w*/u)?.[0];if(n.has(r)||t[r]===void 0)return n;n.add(r);for(let e of t[r])Cj({primaryType:e.type,types:t},n);return n}function wj({types:e,name:t,type:n,value:r}){if(e[n]!==void 0)return[{type:`bytes32`},ZD(bj({data:r,primaryType:n,types:e}))];if(n===`bytes`)return[{type:`bytes32`},ZD(r)];if(n===`string`)return[{type:`bytes32`},ZD(PD(r))];if(n.lastIndexOf(`]`)===n.length-1){let i=n.slice(0,n.lastIndexOf(`[`)),a=r.map(n=>wj({name:t,type:i,types:e,value:n}));return[{type:`bytes32`},ZD(CO(a.map(([e])=>e),a.map(([,e])=>e)))]}return[{type:n},r]}async function Tj(e){let{domain:t,message:n,primaryType:r,signature:i,types:a}=e;return uj({hash:_j({domain:t,message:n,primaryType:r,types:a}),signature:i})}async function Ej(e){let{switchboardUrl:t,baseUrl:n,timeoutMs:r}=e;if(t)return t;if(!n)return;let i=new AbortController,a=setTimeout(()=>i.abort(),r??3e3);try{let e=new URL(`/api/switchboard`,n),t=await fetch(e,{method:`GET`,signal:i.signal});return t.ok&&(await t.json()).endpoint||void 0}catch{return}finally{clearTimeout(a)}}var Dj=class e extends Error{constructor(){super(`signIn requires a switchboard endpoint. Set switchboardUrl or a discoverable baseUrl.`),this.name=`MissingSwitchboardError`}static is(t){return t instanceof e||t instanceof Error&&t.name===`MissingSwitchboardError`}};function Oj(e){return`renown-${e.toLowerCase()}`}const kj=`
162
+ query RenownCredentials($input: RenownCredentialsInput!) {
163
+ renownCredentials(input: $input) {
164
+ documentId
165
+ credentialId
166
+ context
167
+ type
168
+ issuerId
169
+ issuerEthereumAddress
170
+ issuanceDate
171
+ expirationDate
172
+ credentialSubjectId
173
+ credentialSubjectApp
174
+ credentialStatusId
175
+ credentialStatusType
176
+ credentialSchemaId
177
+ credentialSchemaType
178
+ proofVerificationMethod
179
+ proofEthereumAddress
180
+ proofCreated
181
+ proofPurpose
182
+ proofType
183
+ proofValue
184
+ proofEip712Domain
185
+ proofEip712PrimaryType
186
+ revoked
187
+ }
188
+ }
189
+ `;function Aj(e){return e instanceof Error&&/Cannot query field "execute" on type "Mutation"/.test(e.message)}function jj(e){return`token`in e?{token:e.token,signed:{}}:{signed:{signature:e.signature,timestamp:e.timestamp}}}function Mj(e){return`\\\\?"${e}\\\\?"`}function Nj(e,t,...n){let r=e instanceof Error?e.message:String(e);return RegExp(`Cannot query field ${Mj(t)}`).test(r)?!0:!r.includes(`got invalid value`)&&n.some(e=>RegExp(`Unknown type ${Mj(e)}`).test(r))}function Pj(e){let t=JSON.parse(e.proofEip712Domain);return{"@context":e.context,type:e.type,id:e.credentialId,issuer:{id:e.issuerId,ethereumAddress:e.issuerEthereumAddress},credentialSubject:{id:e.credentialSubjectId??``,app:e.credentialSubjectApp},credentialSchema:{id:e.credentialSchemaId,type:e.credentialSchemaType},...e.credentialStatusId?{credentialStatus:{id:e.credentialStatusId,type:e.credentialStatusType??``}}:{},issuanceDate:e.issuanceDate,expirationDate:e.expirationDate??``,proof:{type:e.proofType,created:e.proofCreated,verificationMethod:e.proofVerificationMethod,proofPurpose:e.proofPurpose,proofValue:e.proofValue,ethereumAddress:e.proofEthereumAddress,eip712:{domain:t,types:f,primaryType:`VerifiableCredential`}}}}function Fj(e){return e.split(`:`)[3]}function Ij(e){return e.split(`:`)[4]}function Lj(e,t,n,r){return!e.revoked&&Rj(e,t,n,r)}function Rj(e,t,n,r){let i=t.toLowerCase();return e.credentialSubjectId===r&&Fj(e.issuerId)===String(n)&&Ij(e.issuerId)?.toLowerCase()===i&&e.issuerEthereumAddress.toLowerCase()===i}var zj=class{#e;#t;#n=!1;constructor(e){typeof e==`string`?(this.#e=e,this.#t=(t,n,r)=>this.#r(e,t,n,r?.token)):this.#t=e}get endpoint(){return this.#e}async#r(e,t,n,r){let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`,...r?{Authorization:`Bearer ${r}`}:{}},body:JSON.stringify({query:t,variables:n})}),a=await i.json().catch(()=>void 0);if(a?.errors?.length)throw Error(a.errors.map(e=>e.message).join(`; `));if(!i.ok||!a)throw Error(`Switchboard request failed: ${i.status}`);return a.data}async#i(e,t,n){let r=await(n?this.#t(e,t,{token:n}):this.#t(e,t));if(!r)throw Error(`Switchboard returned no data`);return r}async getCredential(e){let{address:t,chainId:n,appDid:r}=e,{renownCredentials:i}=await this.#i(kj,{input:{driveId:Oj(t),ethAddress:t.toLowerCase(),did:r,includeRevoked:!1}}),a=Date.now(),o=i.filter(e=>Lj(e,t,n,r)).filter(e=>{if(!e.expirationDate)return!0;let t=Date.parse(e.expirationDate);return!Number.isNaN(t)&&t>a}).sort((e,t)=>Date.parse(t.issuanceDate)-Date.parse(e.issuanceDate)).at(0);return o?Pj(o):void 0}async getIssuedCredentials(e){let{address:t,chainId:n,appDid:r}=e,{renownCredentials:i}=await this.#i(kj,{input:{driveId:Oj(t),ethAddress:t.toLowerCase(),did:r,includeRevoked:!0}}),a=[];for(let e of i)if(Rj(e,t,n,r))try{a.push(Pj(e))}catch{}return a}async getProfileByAddress(e){let{renownUsers:t}=await this.#i(`
190
+ query RenownUsers($input: RenownUsersInput!) {
191
+ renownUsers(input: $input) {
192
+ documentId
193
+ username
194
+ ethAddress
195
+ userImage
196
+ createdAt
197
+ updatedAt
198
+ }
199
+ }
200
+ `,{input:{driveId:Oj(e),ethAddresses:[e.toLowerCase()]}}),n=t.at(0);if(n)return{documentId:n.documentId,username:n.username,ethAddress:n.ethAddress,userImage:n.userImage,createdAt:n.createdAt,updatedAt:n.updatedAt}}async createEmptyDocument(e,t,n){let{createEmptyDocument:r}=await this.#i(`
201
+ mutation CreateEmptyDocument(
202
+ $documentType: String!
203
+ $parentIdentifier: String
204
+ ) {
205
+ createEmptyDocument(
206
+ documentType: $documentType
207
+ parentIdentifier: $parentIdentifier
208
+ ) {
209
+ id
210
+ }
211
+ }
212
+ `,{documentType:e,parentIdentifier:t},n);return r.id}async mutateDocument(e,t,n){let r={documentIdentifier:e,actions:t};if(!this.#n)try{let{mutateDocument:e}=await this.#i(`
213
+ mutation MutateDocument(
214
+ $documentIdentifier: String!
215
+ $actions: [ActionInput!]!
216
+ ) {
217
+ mutateDocument: execute(
218
+ documentIdentifier: $documentIdentifier
219
+ actions: $actions
220
+ ) {
221
+ id
222
+ }
223
+ }
224
+ `,r,n);return e.id}catch(e){if(!Aj(e))throw e;this.#n=!0}let{mutateDocument:i}=await this.#i(`
225
+ mutation MutateDocument(
226
+ $documentIdentifier: String!
227
+ $actions: [JSONObject!]!
228
+ ) {
229
+ mutateDocument(documentIdentifier: $documentIdentifier, actions: $actions) {
230
+ id
231
+ }
232
+ }
233
+ `,r,n);return i.id}async issueCredential(e,t){let n={id:e.id,context:e[`@context`],type:e.type,issuer:{id:e.issuer.id,ethereumAddress:e.issuer.ethereumAddress},credentialSubject:{id:e.credentialSubject.id,app:e.credentialSubject.app},credentialSchema:{id:e.credentialSchema.id,type:e.credentialSchema.type},issuanceDate:e.issuanceDate,expirationDate:e.expirationDate||void 0,proof:{type:e.proof.type,created:e.proof.created,verificationMethod:e.proof.verificationMethod,proofPurpose:e.proof.proofPurpose,proofValue:e.proof.proofValue,ethereumAddress:e.proof.ethereumAddress,eip712:{domain:{version:e.proof.eip712.domain.version,chainId:e.proof.eip712.domain.chainId},primaryType:e.proof.eip712.primaryType}}};try{let{renown_issueCredential:e}=await this.#i(`
234
+ mutation RenownIssueCredential(
235
+ $input: RenownCredential_InitInput!
236
+ $username: String
237
+ $userImage: String
238
+ $userDocId: PHID
239
+ ) {
240
+ renown_issueCredential(
241
+ input: $input
242
+ username: $username
243
+ userImage: $userImage
244
+ userDocId: $userDocId
245
+ )
246
+ }
247
+ `,{input:n});return e}catch(e){if(!Nj(e,`renown_issueCredential`,`RenownCredential_InitInput`))throw e;let r=await this.createEmptyDocument(`powerhouse/renown-credential`,t);return await this.mutateDocument(r,[H(`INIT`,n)]),r}}async upsertUserProfile(e,t,n){let{token:r,signed:i}=jj(n);try{let{renown_upsertProfile:n}=await this.#i(`
248
+ mutation RenownUpsertProfile(
249
+ $address: String!
250
+ $username: String
251
+ $userImage: String
252
+ $signature: String
253
+ $timestamp: String
254
+ ) {
255
+ renown_upsertProfile(
256
+ address: $address
257
+ username: $username
258
+ userImage: $userImage
259
+ signature: $signature
260
+ timestamp: $timestamp
261
+ )
262
+ }
263
+ `,{address:e,username:t.username,userImage:t.userImage,...i},r);return n}catch(n){if(!Nj(n,`renown_upsertProfile`))throw n;return this.#a(e,t,r)}}async#a(e,t,n){let r=[];t.username!=null&&r.push(H(`SET_USERNAME`,{username:t.username})),t.userImage!=null&&r.push(H(`SET_USER_IMAGE`,{userImage:t.userImage}));let i=await this.getProfileByAddress(e);if(i)return r.length&&await this.mutateDocument(i.documentId,r,n),i.documentId;let a=await this.createEmptyDocument(`powerhouse/renown-user`,void 0,n);return await this.mutateDocument(a,[H(`SET_ETH_ADDRESS`,{ethAddress:e}),...r],n),a}async revokeCredential(e,t){let{token:n,signed:r}=jj(t);try{await this.#i(`
264
+ mutation RenownRevokeCredential(
265
+ $credentialId: String!
266
+ $signature: String
267
+ $timestamp: String
268
+ ) {
269
+ renown_revokeCredential(
270
+ credentialId: $credentialId
271
+ signature: $signature
272
+ timestamp: $timestamp
273
+ )
274
+ }
275
+ `,{credentialId:e,...r},n)}catch(t){if(!Nj(t,`renown_revokeCredential`))throw t;await this.#o(e,n)}}async#o(e,t){let{renownCredentials:n}=await this.#i(kj,{input:{includeRevoked:!1}},t),r=n.filter(t=>t.credentialId===e).map(e=>e.documentId);if(!r.length)throw Error(`Credential not found: ${e}`);let i=(/* @__PURE__ */ new Date()).toISOString();for(let e of r)await this.mutateDocument(e,[H(`REVOKE`,{revokedAt:i,reason:null})],t)}profileFetcher=e=>this.getProfileByAddress(e.address).catch(()=>void 0)};async function Bj(e){let{signTypedData:t,address:n,chainId:r,app:i,appId:a,expiresInDays:o=7}=e,s=`did:pkh:${d}:${r}:${n.toLowerCase()}`,c=`urn:uuid:${globalThis.crypto.randomUUID()}`,l=/* @__PURE__ */ new Date,u=new Date(l.getTime()+o*24*60*60*1e3),p={"@context":[`https://www.w3.org/2018/credentials/v1`],type:[`VerifiableCredential`,`RenownCredential`],id:c,issuer:{id:s,ethereumAddress:n},credentialSubject:{id:a,app:i},credentialSchema:{id:`https://renown.id/schemas/renown-credential/v1`,type:`JsonSchemaValidator2018`},issuanceDate:l.toISOString(),expirationDate:u.toISOString()},m={version:`1`,chainId:r},{EIP712Domain:h,...g}=f,_=await t({domain:m,types:g,primaryType:`VerifiableCredential`,message:p});return{...p,proof:{type:`EthereumEip712Signature2021`,created:p.issuanceDate,verificationMethod:s,proofPurpose:`assertionMethod`,proofValue:_,ethereumAddress:n,eip712:{domain:m,types:f,primaryType:`VerifiableCredential`}}}}async function Vj(e){let{proof:t,...n}=e,{EIP712Domain:r,...i}=f;return Tj({domain:t.eip712.domain,types:i,primaryType:`VerifiableCredential`,message:n,signature:t.proofValue})}async function Hj(e){try{return(await Vj(e)).toLowerCase()===e.issuer.ethereumAddress.toLowerCase()}catch{return!1}}(/* @__PURE__ */ s(((e,t)=>{t.exports=function(e,t){t||={},typeof t==`function`&&(t={cmp:t});var n=typeof t.cycles==`boolean`&&t.cycles,r=t.cmp&&(function(e){return function(t){return function(n,r){return e({key:n,value:t[n]},{key:r,value:t[r]})}}})(t.cmp),i=[];return(function e(t){if(t&&t.toJSON&&typeof t.toJSON==`function`&&(t=t.toJSON()),t!==void 0){if(typeof t==`number`)return isFinite(t)?``+t:`null`;if(typeof t!=`object`)return JSON.stringify(t);var a,o;if(Array.isArray(t)){for(o=`[`,a=0;a<t.length;a++)a&&(o+=`,`),o+=e(t[a])||`null`;return o+`]`}if(t===null)return`null`;if(i.indexOf(t)!==-1){if(n)return JSON.stringify(`__cycle__`);throw TypeError(`Converting circular structure to JSON`)}var s=i.push(t)-1,c=Object.keys(t).sort(r&&r(t));for(o=``,a=0;a<c.length;a++){var l=c[a],u=e(t[l]);u&&(o&&(o+=`,`),o+=JSON.stringify(l)+`:`+u)}return i.splice(s,1),`{`+o+`}`}})(e)}})))();function Uj(e,t){let n=new Uint8Array(e.length+1);return n[0]=2+(t[t.length-1]&1),n.set(e,1),n}async function Wj({publicKey:e}){let t=await globalThis.crypto.subtle.exportKey(`raw`,e);return Uj(new Uint8Array(t.slice(1,33)),new Uint8Array(t.slice(33,65)))}function Gj(e){return`did:key:z${AE(sT([new Uint8Array(zw.default.encode(4608)),e]),`base58btc`)}`}const Kj={name:`ECDSA`,namedCurve:`P-256`},qj={name:`ECDSA`,namedCurve:`P-256`,hash:`SHA-256`};async function Jj(e){return Gj(await Wj(e))}async function Yj(e,t){return{publicKey:await t.exportKey(`jwk`,e.publicKey),privateKey:await t.exportKey(`jwk`,e.privateKey)}}async function Xj(e,t,n=Kj){return{publicKey:await t.importKey(`jwk`,e.publicKey,n,!0,[`verify`]),privateKey:await t.importKey(`jwk`,e.privateKey,n,!0,[`sign`])}}async function Zj(e,t=Kj){return e.generateKey(t,!0,[`sign`,`verify`])}var Qj=class e{#e;#t;#n;did;chainId;static algorithm=Kj;static signAlgorithm=qj;constructor(e,t,n,r,i=1){this.#n=e,this.#e=t,this.#t=n,this.did=r,this.chainId=i}get publicKey(){return this.#t.publicKey}async getBearerToken(e,t){return await $E(this.chainId,d,e||this.did,this.issuer,t)}async removeDid(){await this.#n.removeKeyPair()}#r(e){return kE(e,`utf-8`)}async sign(t){let n=typeof t==`string`?this.#r(t):t,r=await this.#e.sign(e.signAlgorithm,this.#t.privateKey,n.buffer);return new Uint8Array(r)}async verify(e,t){return this.#e.verify({name:`ECDSA`,hash:`SHA-256`},this.#t.publicKey,t.buffer,e.buffer)}get issuer(){return{did:this.did,signer:async e=>AE(await this.sign(typeof e==`string`?new TextEncoder().encode(e):e),`base64url`),alg:`ES256`}}},$j=class{keyPairStorage;subtleCrypto;chainId;withKeyPairStorage(e){return this.keyPairStorage=e,this}withSubtleCrypto(e){return this.subtleCrypto=e,this}withChainId(e){return this.chainId=e,this}async build(){if(!this.keyPairStorage)throw Error(`KeyPairStorage is required. Use withKeyPairStorage() to set it.`);let e=this.subtleCrypto??globalThis.crypto.subtle,t=await this.#e(e,this.keyPairStorage),n=await Jj(t);return new Qj(this.keyPairStorage,e,t,n,this.chainId)}async#e(e,t){let n=await t.loadKeyPair();if(n)return Xj(n,e);let r=await Zj(e),i=await Yj(r,e);return await t.saveKeyPair(i),r}};const eM=`keyPairs`,tM=`keyPair`;var nM=class e{#e;constructor(e){this.#e=e}static async create(t=`renownKeyDB`){let n=await e.#t(t);return new e(n)}static#t(e){return new Promise((t,n)=>{let r=indexedDB.open(e);r.onupgradeneeded=e=>{let t=e.target.result;t.objectStoreNames.contains(eM)||t.createObjectStore(eM)},r.onsuccess=()=>{let i=r.result;if(i.objectStoreNames.contains(eM))t(i);else{let r=i.version;i.close();let a=indexedDB.open(e,r+1);a.onupgradeneeded=e=>{let t=e.target.result;t.objectStoreNames.contains(eM)||t.createObjectStore(eM)},a.onsuccess=()=>t(a.result),a.onerror=()=>n(a.error)}},r.onerror=()=>n(r.error)})}#n(e=`readwrite`){return this.#e.transaction(eM,e).objectStore(eM)}async saveKeyPair(e){let t=this.#n().put(e,tM);return new Promise((e,n)=>{t.onsuccess=()=>e(),t.onerror=()=>n(/* @__PURE__ */ Error(`Failed to save key pair`))})}async loadKeyPair(){let e=this.#n(`readonly`).get(tM);return new Promise((t,n)=>{e.onsuccess=()=>{let n=e.result;t(n)},e.onerror=()=>n(/* @__PURE__ */ Error(`Failed to load key pair`))})}async removeKeyPair(){let e=this.#n().delete(tM);return new Promise((t,n)=>{e.onsuccess=()=>t(),e.onerror=()=>n(/* @__PURE__ */ Error(`Failed to remove key pair`))})}},rM=class{},iM=class extends rM{data=/* @__PURE__ */ new Map;get(e){return this.data.get(e)}set(e,t){t===void 0?this.data.delete(e):this.data.set(e,t)}delete(e){this.data.delete(e)}},aM=class extends iM{};function oM(e){if(e)return{address:e.address,networkId:e.networkId,chainId:e.chainId}}var sM=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=`initial`;constructor(e,t,n,r,i=`https://www.renown.id`,a,o,s=1){this.#t=e,this.#n=t,this.#e=i,this.#i=n,this.#r=r,this.#o=a,this.#s=o,this.#c=s;let c=this.user;this.#a=new nD(n,this.#r,oM(c)),c&&(this.#l=`authorized`),this.on(`user`,e=>{this.#a.user=oM(e)})}get baseUrl(){return this.#e}get chainId(){return this.#c}get user(){return this.#t.get(`user`)}get status(){return this.#l}get signer(){return this.#a}get crypto(){return this.#i}get did(){return this.#i.did}get profileFetcher(){return this.#o}#u(e){this.#l=e,this.#n.emit(`status`,e)}#d(e){e?this.#t.set(`user`,e):this.#t.delete(`user`),this.#n.emit(`user`,e)}async login(e){this.#u(`checking`);try{let t=XE(e),n=await this.#m(t.address,t.chainId,this.#i.did);if(!n)throw this.#d(void 0),Error(`Credential not found`);return await this.#p(e,t,n)}catch(e){throw this.#d(void 0),this.#u(`not-authorized`),e}}async signIn(e){if(!this.#s)throw new Dj;let{address:t,chainId:n,signTypedData:r,username:i,userImage:a,expiresInDays:o}=e;if(n!==this.#c)throw Error(`Renown signIn: wallet is on chain ${n}, but this app issues credentials on chain ${this.#c}. Switch networks and retry — signing here would create a separate identity for the same address.`);this.#u(`checking`);try{let e=await Bj({signTypedData:r,address:t,chainId:n,app:this.#r,appId:this.did,expiresInDays:o});await this.#s.issueCredential(e);let s=`did:pkh:${d}:${n}:${t.toLowerCase()}`,c=await this.#p(s,XE(s),e);return(i!==void 0||a!==void 0)&&this.#f(t,{username:i,userImage:a}).catch(()=>void 0),c}catch(e){throw this.#d(void 0),this.#u(`not-authorized`),e}}async adoptCredential(e,t={}){this.#u(`checking`);try{let n=e.issuer.id,r=await this.#p(n,XE(n),e);if(!t.local)return r;let i={...r,local:!0};return this.#d(i),i}catch(e){throw this.#d(void 0),this.#u(`not-authorized`),e}}async#f(e,t){if(!this.#s)return;let n=await this.#i.getBearerToken(e);for(let r=1;r<=5;r++)try{await this.#s.upsertUserProfile(e,t,{token:n});return}catch(e){if(r===5)throw e;await new Promise(e=>setTimeout(e,600))}}async#p(e,t,n){if(n.issuer.id!==e||n.credentialSubject.id!==this.did)throw Error(`Invalid credential`);let r=n.proof.eip712?.domain?n:{...n,proof:{...n.proof,eip712:{domain:{version:`1`,chainId:t.chainId},types:f,primaryType:`VerifiableCredential`}}};if(n.issuer.ethereumAddress.toLowerCase()!==t.address.toLowerCase()||r.proof.eip712.domain.chainId!==t.chainId||!await Hj(r))throw Error(`Invalid credential signature`);let i={...t,address:n.issuer.ethereumAddress,did:e,credential:r};return this.#d(i),this.#u(`authorized`),this.#o&&this.#o(i,this.#e).then(e=>{e&&this.user?.address===i.address&&this.user.chainId===i.chainId&&this.#d({...this.user,profile:e,ens:{name:e.username??void 0,avatarUrl:e.userImage??void 0}})}).catch(console.error),i}logout(){return this.#d(void 0),this.#u(`initial`),Promise.resolve()}async revalidate(){let e=this.user;if(!e)return!1;if(e.local)return!0;try{return await this.#m(e.address,e.chainId,this.#i.did)?(await this.refreshProfile(),!0):(await this.logout(),!1)}catch{return!0}}async refreshProfile(){let e=this.user;if(!e||e.local||!this.#o)return!1;try{let t=await this.#o(e,this.#e);if(!t)return!1;let n=this.user;return!n||n.address!==e.address||n.chainId!==e.chainId||n.profile!==void 0&&n.profile.documentId===t.documentId&&n.profile.username===t.username&&n.profile.userImage===t.userImage?!1:(this.#d({...n,profile:t,ens:{name:t.username??void 0,avatarUrl:t.userImage??void 0}}),!0)}catch{return!1}}on(e,t){return this.#n.on(e,t)}async#m(e,t,n){if(this.#s)return this.#s.getCredential({address:e,chainId:t,appDid:n});if(!this.#e)throw Error(`RENOWN_URL is not set`);let r=new URL(`/api/auth/credential?address=${encodeURIComponent(e)}&chainId=${encodeURIComponent(t)}&connectId=${encodeURIComponent(n)}&appId=${encodeURIComponent(n)}`,this.#e),i=await fetch(r,{method:`GET`});if(i.ok)return(await i.json()).credential;throw Error(`Failed to get credential: ${i.status}`)}async verifyBearerToken(e){return ZE(e)}async getBearerToken(e){if(!this.user)throw Error(`User not found`);return this.#i.getBearerToken(this.user.address,e)}};function cM(e){return e.reason instanceof Error?e.reason:e.reason?Error(String(e.reason)):new DOMException(`Aborted`,`AbortError`)}function lM(e,t){return new Promise((n,r)=>{if(t?.aborted){r(cM(t));return}let i=()=>{clearTimeout(a),r(cM(t))},a=setTimeout(()=>{t?.removeEventListener(`abort`,i),n()},e);t?.addEventListener(`abort`,i,{once:!0})})}async function uM(e,t,n,r,i){let a=Date.now(),o=new URL(`/api/console/session/${t}`,e).toString();for(;Date.now()-a<n;){i?.throwIfAborted();try{let e=await fetch(o,{signal:i});if(e.ok){let t=await e.json();if(t.status===`ready`)return t}}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)throw e}r?.(),await lM(500,i)}return null}async function dM(e,t){let n=t.timeoutMs??3e5,r=crypto.randomUUID(),i=new URL(`/console`,t.renownUrl);i.searchParams.set(`session`,r),i.searchParams.set(`connect`,e.did),i.searchParams.set(`app`,e.did);let a=i.toString();t.onLoginUrl?.(a,r);try{await t.open(a)}catch{t.onOpenFailed?.(a)}let o=await uM(t.renownUrl,r,n,t.onPollTick,t.signal);if(!o)throw Error(`Authentication timed out.`);return e.login(o.did)}var fM=class{#e=/* @__PURE__ */ new Map;on(e,t){return this.#e.has(e)||this.#e.set(e,/* @__PURE__ */ new Set),this.#e.get(e).add(t),()=>{this.#e.get(e)?.delete(t)}}emit(e,t){this.#e.get(e)?.forEach(e=>e(t))}};const pM=async(e,t)=>{try{let n=await fetch(`${t.replace(/\/+$/,``)}/api/profile`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({ethAddress:e.address})});return n.ok?(await n.json()).profile??void 0:void 0}catch{return}};var mM=class e{#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e){this.#e=e}withStorage(e){return this.#t=e,this}withEventEmitter(e){return this.#n=e,this}withCrypto(e){return this.#r=e,this}withKeyPairStorage(e){return this.#i=e,this}withBaseUrl(e){return this.#a=e,this}withSwitchboardUrl(e){return this.#o=e,this}withChainId(e){return this.#c=e,this}withProfileFetcher(e){return this.#s=e,this}async build(){if(!this.#r&&!this.#i)throw Error(`Either crypto or keyPairStorage is required. Use withCrypto() or withKeyPairStorage() to set one.`);let e=this.#c??1,t=this.#r??await new $j().withKeyPairStorage(this.#i).withChainId(e).build();t.chainId!==void 0&&t.chainId!==e&&console.warn(`Renown: the supplied crypto signs bearer tokens for chain ${t.chainId}, but credentials are issued on chain ${e}.`);let n=this.#t??new aM,r=this.#n??new fM,i=this.#a??`https://www.renown.id`,a=await Ej({switchboardUrl:this.#o,baseUrl:i}),o=a?new zj(a):void 0,s=this.#s??(o?o.profileFetcher:pM);return new sM(n,r,t,this.#e,i,s,o,e)}static from(t){let n=new e(t.appName);return t.storage&&n.withStorage(t.storage),t.eventEmitter&&n.withEventEmitter(t.eventEmitter),t.crypto&&n.withCrypto(t.crypto),t.keyPairStorage&&n.withKeyPairStorage(t.keyPairStorage),t.baseUrl&&n.withBaseUrl(t.baseUrl),t.switchboardUrl&&n.withSwitchboardUrl(t.switchboardUrl),t.profileFetcher&&n.withProfileFetcher(t.profileFetcher),t.chainId!==void 0&&n.withChainId(t.chainId),n}},hM=class extends CustomEvent{constructor(e,t){super(e,{detail:t})}},gM=class{#e=new EventTarget;on(e,t){let n=e=>{e instanceof hM&&t(e.detail)};return this.#e.addEventListener(e.toString(),n),()=>{this.#e.removeEventListener(e.toString(),n)}}emit(e,t){let n=new hM(e.toString(),t);this.#e.dispatchEvent(n)}},_M=class extends rM{namespace;constructor(e,t){super(),this.namespace=`${t}:${e}`}#e(e){return`${this.namespace}:${e.toString()}`}get(e){let t=localStorage.getItem(this.#e(e));if(t)return JSON.parse(t)}set(e,t){return t?localStorage.setItem(this.#e(e),JSON.stringify(t)):localStorage.removeItem(this.#e(e))}delete(e){return localStorage.removeItem(this.#e(e))}},vM=class extends _M{},yM=class extends gM{},bM=class extends mM{#e;#t;#n;constructor(e,t={}){super(e),this.#e=t.basename,this.#t=t.keyDbName,this.#n=t.revalidate??`always`,this.withStorage(new vM(`renown`,this.#e)),this.withEventEmitter(new yM),t.baseUrl&&this.withBaseUrl(t.baseUrl),t.switchboardUrl&&this.withSwitchboardUrl(t.switchboardUrl),t.chainId!==void 0&&this.withChainId(t.chainId)}withBasename(e){return this.#e=e,this.withStorage(new vM(`renown`,this.#e)),this}withKeyDbName(e){return this.#t=e,this}async build(){let e=await nM.create(this.#t);this.withKeyPairStorage(e);let t=await super.build();return t.user&&(this.#n===`always`?t.revalidate():t.refreshProfile()),t}};const xM=`connect`,SM=document.getElementById(`sign-in`);let Q,CM=null,wM;const TM=(e,t)=>window.__TAURI_INTERNALS__.invoke(e,t),EM=e=>e instanceof Error?e.message:String(e),$=e=>e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e]);function DM(e){let t=CM?`<p class="notice" role="alert">${$(CM)}</p>`:``;CM=null,SM.innerHTML=t+e,SM.querySelector(`[autofocus]`)?.focus()}function OM(e,t){document.getElementById(e)?.addEventListener(`click`,()=>{Promise.resolve(t()).catch(kM)})}function kM(e){CM=EM(e),jM()}function AM(){return wM??=new bM(xM,{basename:`/`,baseUrl:Q.renownUrl,switchboardUrl:Q.renownSwitchboardUrl??void 0,chainId:Q.chainId,revalidate:`never`}).build(),wM}async function jM(){if(Q=await TM(`desktop_state`),document.title=Q.appName,Q.rootMissing)return IM();if(Q.settingsError)return LM();let e=Q.identities.map(MM).join(``);DM(`
276
+ <h1>${Q.identities.length?`Who's using ${$(Q.appName)}?`:`Welcome to ${$(Q.appName)}`}</h1>
277
+ ${e?`<ul class="identities">${e}</ul>`:``}
278
+ <button class="primary" id="renown" autofocus>Sign in with Renown</button>
279
+ <button id="local">${Q.hasLocalKey?`Use your local key`:`Use a local key`}</button>
280
+ ${NM()}
281
+ `);for(let e of Q.identities)OM(`as-${e.id}`,()=>e.kind===`local`?GM():zM(e));OM(`renown`,RM),OM(`local`,()=>Q.hasLocalKey?GM():WM()),PM()}function MM(e){let t=`${e.address.slice(0,6)}…${e.address.slice(-4)}`,n=e.name??(e.kind===`local`?`Local key`:t),r=e.image?`<img src="${$(e.image)}" alt="" />`:`<span class="initial">${$(n.replace(/^0x/,``).charAt(0).toUpperCase())}</span>`;return`<li><button id="as-${$(e.id)}" class="identity">${r}
282
+ <span><b>${$(n)}</b><small>${$(t)}</small></span></button></li>`}function NM(){let e=Q.syncedFolder?`<p class="notice">This folder syncs with ${$(Q.syncedFolder)}. A live database can be damaged there, so a folder that doesn't sync is safer.</p>`:``,t=Q.rootLocked?``:`<button class="link" id="change-folder">Change</button>`;return`
283
+ <p class="folder"><small>Your documents are in</small><br />${$(Q.root)} ${t}</p>
284
+ ${e}
285
+ <details>
286
+ <summary>Advanced</summary>
287
+ <label>Renown instance
288
+ <input id="renown-url" spellcheck="false" value="${$(Q.renownUrl)}" />
289
+ </label>
290
+ <button id="save-renown-url">Save</button>
291
+ </details>`}function PM(){OM(`change-folder`,FM),OM(`save-renown-url`,async()=>{let e=document.getElementById(`renown-url`);await TM(`save_renown_url`,{url:e.value.trim()}),wM=void 0,await jM()})}async function FM(){await TM(`pick_root`),wM=void 0,await jM()}function IM(){DM(`
292
+ <h1>We can't find your ${$(Q.appName)} folder</h1>
293
+ <p>${$(Q.root)} isn't there. If it's on a drive that isn't plugged in, plug it in and try again.</p>
294
+ <button class="primary" id="retry" autofocus>Try again</button>
295
+ <button id="change-folder">Choose another folder</button>
296
+ `),OM(`retry`,jM),OM(`change-folder`,FM)}function LM(){DM(`
297
+ <h1>settings.json can't be read</h1>
298
+ <p>${$(Q.settingsError??``)}</p>
299
+ <p>Fix the file, then try again. It's in ${$(Q.root)}.</p>
300
+ <button class="primary" id="retry" autofocus>Try again</button>
301
+ `),OM(`retry`,jM)}async function RM(){let e=await AM(),t=new AbortController;DM(`
302
+ <h1>Finish signing in in your browser</h1>
303
+ <p>Your browser has opened Renown. Come back here when you've approved ${$(Q.appName)}.</p>
304
+ <button id="cancel">Cancel</button>
305
+ `),OM(`cancel`,()=>t.abort());try{let n=await dM(e,{renownUrl:e.baseUrl,open:e=>window.phDesktop.openExternal(e),signal:t.signal});await VM(e,n.address),await qM(n.address.toLowerCase())}catch(e){if(!t.signal.aborted)throw e;await jM()}}async function zM(e){let t=await AM();if(t.user?.address.toLowerCase()===e.address)return qM(e.id);let n=await TM(`saved_credential`,{address:e.address,appDid:t.did});if(!n)return RM();await t.adoptCredential(n),await qM(e.id)}const BM={"image/png":`png`,"image/jpeg":`jpg`,"image/webp":`webp`};async function VM(e,t){await Promise.race([e.refreshProfile().catch(()=>!1),new Promise(e=>setTimeout(e,5e3))]);let n=e.user?.profile,r=null;try{if(n?.userImage){let e=await fetch(n.userImage),t=BM[e.headers.get(`content-type`)??``];e.ok&&t&&(r={ext:t,bytes:[...new Uint8Array(await e.arrayBuffer())]})}}catch{}await TM(`save_profile`,{address:t.toLowerCase(),name:n?.username??null,image:r})}function HM(){return`
306
+ <label>Password <input id="password" type="password" autocomplete="new-password" autofocus /></label>
307
+ <label>Repeat it <input id="repeat" type="password" autocomplete="new-password" /></label>
308
+ <p><small>The password protects the key, not your documents, which aren't encrypted on disk. It can't be recovered, but you can replace the key and keep your documents.</small></p>`}function UM(){let e=e=>document.getElementById(e).value,t=e(`password`);return t.length<8?CM=`Use at least 8 characters.`:t!==e(`repeat`)&&(CM=`Those passwords don't match.`),CM?null:t}function WM(e=!1){DM(`
309
+ <h1>${e?`Replace your local key`:`Create a local key`}</h1>
310
+ ${e?`<p>This makes a new key. Your documents stay, and the old key stops working.</p>`:`<p>A key kept on this computer. It needs no account and no internet.</p>`}
311
+ ${HM()}
312
+ <button class="primary" id="create">${e?`Replace the key`:`Create the key`}</button>
313
+ <button id="back">Back</button>
314
+ `),OM(`back`,jM),OM(`create`,async()=>{let t=UM();if(t===null)return WM(e);JM(`Making your key…`),await TM(`local_create`,{password:t,replace:e}),await KM(t)})}function GM(){DM(`
315
+ <h1>Unlock your local key</h1>
316
+ <label>Password <input id="password" type="password" autocomplete="current-password" autofocus /></label>
317
+ <button class="primary" id="unlock">Unlock</button>
318
+ <button id="back">Back</button>
319
+ <button class="link" id="replace">Forgot the password? Replace the key</button>
320
+ `);let e=document.getElementById(`password`);e.addEventListener(`keydown`,e=>{e.key===`Enter`&&document.getElementById(`unlock`)?.click()}),OM(`back`,jM),OM(`replace`,()=>WM(!0)),OM(`unlock`,()=>KM(e.value))}async function KM(e){let t=await AM();JM(`Unlocking…`);try{let{credential:n}=await TM(`local_unlock`,{password:e,appDid:t.did,appName:xM});await t.adoptCredential(n,{local:!0})}catch(e){return CM=EM(e),GM()}await qM(`local`)}async function qM(e){if(!Q.oldData)return YM(e);DM(`
321
+ <h1>Are these documents yours?</h1>
322
+ <p>This folder has documents from before ${$(Q.appName)} had sign-in. They can move to this identity, or stay where they are.</p>
323
+ <button class="primary" id="adopt" autofocus>Move them to this identity</button>
324
+ <button id="leave">Leave them</button>
325
+ `),OM(`adopt`,async()=>{await TM(`adopt_old_data`,{identity:e}),await YM(e)}),OM(`leave`,()=>YM(e))}function JM(e){DM(`<p class="busy"><span class="dot"></span>${$(e)}</p>`)}async function YM(e){JM(`Starting ${Q.appName}…`),await TM(`start_stack`,{identity:e})}window.phDesktopStartFailed=e=>{CM=e,jM()},jM().catch(kM);