@solarpunkltd/swarm-id 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,15 +9,15 @@ const Ei=BigInt(0),_i=BigInt(1);function xi(e,t){const n=t.negate();return e?n:t
9
9
  const Ui=(e,t)=>(e+(e>=0?t:-t)/Zi)/t;function Pi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Fi(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return Uo(n.lowS,"lowS"),Uo(n.prehash,"prehash"),void 0!==n.format&&Pi(n.format),n}class Ci extends Error{constructor(e=""){super(e)}}const Li={Err:Ci,_tlv:{encode:(e,t)=>{const{Err:n}=Li;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,o=Fo(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?Fo(o.length/2|128):"";return Fo(e)+i+o+t},decode(e,t){const{Err:n}=Li;let 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");const o=t[r++];let i=0;if(!!(128&o)){const e=127&o;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");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(r+=e,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=Li;if(e<Mi)throw new t("integer: negative integers are not allowed");let n=Fo(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=Li;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return Lo(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Li,o=jo("signature",e),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,i),{v:u,l:l}=r.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=Li,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Mi=BigInt(0),Di=BigInt(1),Zi=BigInt(2),ji=BigInt(3),qi=BigInt(4);function Gi(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let o=jo("private key",t);try{r=e.fromBytes(o)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Hi(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>Ei))throw new Error(`CURVE.${e} must be positive bigint`)}const o=Ri(t.p,n.Fp,r),i=Ri(t.n,n.Fn,r),s=["Gx","Gy","a","b"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}("weierstrass",e,t),{Fp:r,Fn:o}=n;let i=n.CURVE;const{h:s,n:a}=i;Ko(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=t;if(c&&(!r.is0(i.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Ki(r,o);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=t.toBytes||function(e,t,n){const{x:o,y:i}=t.toAffine(),s=r.toBytes(o);if(Uo(n,"isCompressed"),n){l();return bo(Vi(!r.isOdd(i)),s)}return bo(Uint8Array.of(4),s,r.toBytes(i))},d=t.fromBytes||function(e){Po(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===n&&4===i){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!p(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=h(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}l();return!(1&~i)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function h(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,i.a)),i.b)}function p(e,t){const n=r.sqr(t),o=h(e);return r.eql(n,o)}if(!p(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const m=r.mul(r.pow(i.a,ji),qi),g=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(m,g)))throw new Error("bad curve params: a or b");function y(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof x))throw new Error("ProjectivePoint expected")}function b(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,o],[i,s]]=t,a=Ui(s*e,n),c=Ui(-o*e,n);let u=e-a*r-c*i,l=-a*o-c*s;const f=u<Mi,d=l<Mi;f&&(u=-u),d&&(l=-l);const h=Vo(Math.ceil(Ho(n)/2))+Di;if(u<Mi||u>=h||l<Mi||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:d,k2:l}}(e,c.basises,o.ORDER)}const v=Wo((e,t)=>{const{X:n,Y:o,Z:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const a=r.mul(n,t),c=r.mul(o,t),u=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),E=Wo(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!p(n,o))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function _(e,t,n,o,i){return n=new x(r.mul(n.X,e),n.Y,n.Z),t=xi(o,t),n=xi(i,n),t.add(n)}class x{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 i}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof x)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?x.ZERO:new x(t,n,r.ONE)}static fromBytes(e){const t=x.fromAffine(d(Po(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return x.fromBytes(jo("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return A.createCache(this,e),t||this.multiply(ji),this}assertValidity(){E(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){w(e);const{X:t,Y:n,Z:o}=this,{X:i,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(i,o)),u=r.eql(r.mul(n,a),r.mul(s,o));return c&&u}negate(){return new x(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,n=r.mul(t,ji),{X:o,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,l=r.ZERO,f=r.mul(o,o),d=r.mul(s,s),h=r.mul(a,a),p=r.mul(o,s);return p=r.add(p,p),l=r.mul(o,a),l=r.add(l,l),c=r.mul(e,l),u=r.mul(n,h),u=r.add(c,u),c=r.sub(d,u),u=r.add(d,u),u=r.mul(c,u),c=r.mul(p,c),l=r.mul(n,l),h=r.mul(e,h),p=r.sub(f,h),p=r.mul(e,p),p=r.add(p,l),l=r.add(f,f),f=r.add(l,f),f=r.add(f,h),f=r.mul(f,p),u=r.add(u,f),h=r.mul(s,a),h=r.add(h,h),f=r.mul(h,p),c=r.sub(c,f),l=r.mul(h,d),l=r.add(l,l),l=r.add(l,l),new x(c,u,l)}add(e){w(e);const{X:t,Y:n,Z:o}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,l=r.ZERO,f=r.ZERO;const d=i.a,h=r.mul(i.b,ji);let p=r.mul(t,s),m=r.mul(n,a),g=r.mul(o,c),y=r.add(t,n),b=r.add(s,a);y=r.mul(y,b),b=r.add(p,m),y=r.sub(y,b),b=r.add(t,o);let v=r.add(s,c);return b=r.mul(b,v),v=r.add(p,g),b=r.sub(b,v),v=r.add(n,o),u=r.add(a,c),v=r.mul(v,u),u=r.add(m,g),v=r.sub(v,u),f=r.mul(d,b),u=r.mul(h,g),f=r.add(u,f),u=r.sub(m,f),f=r.add(m,f),l=r.mul(u,f),m=r.add(p,p),m=r.add(m,p),g=r.mul(d,g),b=r.mul(h,b),m=r.add(m,g),g=r.sub(p,g),g=r.mul(d,g),b=r.add(b,g),p=r.mul(m,b),l=r.add(l,p),p=r.mul(v,b),u=r.mul(y,u),u=r.sub(u,p),p=r.mul(y,m),f=r.mul(v,f),f=r.add(f,p),new x(u,l,f)}subtract(e){return this.add(e.negate())}is0(){return this.equals(x.ZERO)}multiply(e){const{endo:n}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,i;const s=e=>A.cached(this,e,e=>ki(x,e));if(n){const{k1neg:t,k1:o,k2neg:a,k2:c}=b(e),{p:u,f:l}=s(o),{p:f,f:d}=s(c);i=l.add(d),r=_(n.beta,u,f,t,a)}else{const{p:t,f:n}=s(e);r=t,i=n}return ki(x,[r,i])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===Mi||r.is0())return x.ZERO;if(e===Di)return r;if(A.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:o,k2neg:i,k2:s}=b(e),{p1:a,p2:c}=function(e,t,n,r){let o=t,i=e.ZERO,s=e.ZERO;for(;n>Ei||r>Ei;)n&_i&&(i=i.add(o)),r&_i&&(s=s.add(o)),o=o.double(),n>>=_i,r>>=_i;return{p1:i,p2:s}}(x,r,o,s);return _(n.beta,a,c,t,i)}return A.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===Di||(e?e(x,this):A.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===Di?this:e?e(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return Uo(e,"isCompressed"),this.assertValidity(),f(x,this,e)}toHex(e=!0){return co(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 ki(x,e)}static msm(e,t){return Ni(x,o,e,t)}static fromPrivateKey(e){return x.BASE.multiply(Gi(o,e))}}x.BASE=new x(i.Gx,i.Gy,r.ONE),x.ZERO=new x(r.ZERO,r.ONE,r.ZERO),x.Fp=r,x.Fn=o;const k=o.BITS,A=new Ti(x,t.endo?Math.ceil(k/2):k);return x.BASE.precompute(8),x}function Vi(e){return Uint8Array.of(e?2:3)}function Ki(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Wi(e,t={}){const{Fn:n}=e,r=t.randomBytes||_o,o=Object.assign(Ki(e.Fp,n),{seed:vi(n.ORDER)});function i(e){try{return!!Gi(n,e)}catch(e){return!1}}function s(e=r(o.seed)){return function(e,t,n=!1){const r=e.length,o=bi(t),i=vi(t);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const s=si(n?Mo(e):Lo(e),t-Xo)+Xo;return n?Zo(s,o):Do(s,o)}(Po(e,o.seed,"seed"),n.ORDER)}function a(t,r=!0){return e.BASE.multiply(Gi(n,t)).toBytes(r)}function c(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:r,publicKey:i,publicKeyUncompressed:s}=o;if(n.allowedLengths||r===i)return;const a=jo("key",t).length;return a===i||a===s}const u={isValidSecretKey:i,isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:i}=o;try{const o=t.length;return(!0!==n||o===r)&&((!1!==n||o===i)&&!!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:s,isValidPrivateKey:i,randomPrivateKey:s,normPrivateKeyToScalar:e=>Gi(n,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};return Object.freeze({getPublicKey:a,getSharedSecret:function(t,r,o=!0){if(!0===c(t))throw new Error("first arg must be private key");if(!1===c(r))throw new Error("second arg must be public key");const i=Gi(n,t);return e.fromHex(r).multiply(i).toBytes(o)},keygen:function(e){const t=s(e);return{secretKey:t,publicKey:a(t)}},Point:e,utils:u,lengths:o})}function Ji(e,t,n={}){to(t),Ko(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||_o,o=n.hmac||((e,...n)=>To(t,e,bo(...n))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=Wi(e,n),p={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},m="compact";function g(e){return e>a>>Di}function y(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class w{constructor(e,t,n){this.r=y("r",e),this.s=y("s",t),null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=m){let n;if(function(e,t){Pi(t);const n=h.signature;Po(e,"compact"===t?n:"recovered"===t?n+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:n}=Li.toSig(Po(e));return new w(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=s.BYTES,o=e.subarray(0,r),i=e.subarray(r,2*r);return new w(s.fromBytes(o),s.fromBytes(i),n)}static fromHex(e,t){return this.fromBytes(yo(e),t)}addRecoveryBit(e){return new w(this.r,this.s,e)}recoverPublicKey(t){const n=i.ORDER,{r:r,s:o,recovery:c}=this;if(null==c||![0,1,2,3].includes(c))throw new Error("recovery id invalid");if(a*Zi<n&&c>1)throw new Error("recovery id is ambiguous for h>1 curve");const u=2===c||3===c?r+a:r;if(!i.isValid(u))throw new Error("recovery id 2 or 3 invalid");const l=i.toBytes(u),f=e.fromBytes(bo(Vi(!(1&c)),l)),d=s.inv(u),h=v(jo("msgHash",t)),p=s.create(-h*d),m=s.create(o*d),g=e.BASE.multiplyUnsafe(p).add(f.multiplyUnsafe(m));if(g.is0())throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return g(this.s)}toBytes(e=m){if(Pi(e),"der"===e)return yo(Li.hexFromSig(this));const t=s.toBytes(this.r),n=s.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return bo(Uint8Array.of(this.recovery),t,n)}return bo(t,n)}toHex(e){return co(this.toBytes(e))}assertValidity(){}static fromCompact(e){return w.fromBytes(jo("sig",e),"compact")}static fromDER(e){return w.fromBytes(jo("sig",e),"der")}normalizeS(){return this.hasHighS()?new w(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return co(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return co(this.toBytes("compact"))}}const b=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=Lo(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},v=n.bits2int_modN||function(e){return s.create(b(e))},E=Vo(c);function _(e){return Go("num < 2^"+c,e,Mi,E),s.toBytes(e)}function x(e,n){return Po(e,void 0,"message"),n?Po(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:e,sign:function(n,i,a={}){n=jo("message",n);const{seed:c,k2sig:u}=function(t,n,o){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{lowS:i,prehash:a,extraEntropy:c}=Fi(o,p);t=x(t,a);const u=v(t),l=Gi(s,n),f=[_(l),_(u)];if(null!=c&&!1!==c){const e=!0===c?r(h.secretKey):c;f.push(jo("extraEntropy",e))}const d=bo(...f),m=u;return{seed:d,k2sig:function(t){const n=b(t);if(!s.isValidNot0(n))return;const r=s.inv(n),o=e.BASE.multiply(n).toAffine(),a=s.create(o.x);if(a===Mi)return;const c=s.create(r*s.create(m+a*l));if(c===Mi)return;let u=(o.x===a?0:2)|Number(o.y&Di),f=c;return i&&g(c)&&(f=s.neg(c),u^=1),new w(a,f,u)}}}(n,i,a),l=function(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),o=e=>Uint8Array.of(e);let i=r(e),s=r(e),a=0;const c=()=>{i.fill(1),s.fill(0),a=0},u=(...e)=>n(s,i,...e),l=(e=r(0))=>{s=u(o(0),e),i=u(),0!==e.length&&(s=u(o(1),e),i=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){i=u();const t=i.slice();n.push(t),e+=i.length}return bo(...n)};return(e,t)=>{let n;for(c(),l(e);!(n=t(f()));)l();return c(),n}}(t.outputLen,s.BYTES,o);return l(c,u)},verify:function(t,n,r,o={}){const{lowS:i,prehash:a,format:c}=Fi(o,p);if(r=jo("publicKey",r),n=x(jo("message",n),a),"strict"in o)throw new Error("options.strict was renamed to lowS");const u=void 0===c?function(e){let t;const n="string"==typeof e||Yr(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!n&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new w(e.r,e.s);else if(n){try{t=w.fromBytes(jo("sig",e),"der")}catch(e){if(!(e instanceof Li.Err))throw e}if(!t)try{t=w.fromBytes(jo("sig",e),"compact")}catch(e){return!1}}return t||!1}(t):w.fromBytes(jo("sig",t),c);if(!1===u)return!1;try{const t=e.fromBytes(r);if(i&&u.hasHighS())return!1;const{r:o,s:a}=u,c=v(n),l=s.inv(a),f=s.create(c*l),d=s.create(o*l),h=e.BASE.multiplyUnsafe(f).add(t.multiplyUnsafe(d));if(h.is0())return!1;return s.create(h.x)===o}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=Fi(n,p);return t=x(t,r),w.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:w,hash:t})}function Xi(e){const{CURVE:t,curveOpts:n}=function(e){const 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;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:wi(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}}}(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 Yi(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:o}=Xi(e);return function(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,yi(n.Fn.ORDER,n.Fn.BITS))})}(e,Ji(Hi(t,n),r,o))}
10
10
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
11
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
12
- const Qi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},es={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},ts=BigInt(2);const ns=wi(Qi.p,{sqrt:function(e){const t=Qi.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=ai(l,n,t)*l%t,d=ai(f,n,t)*l%t,h=ai(d,ts,t)*u%t,p=ai(h,o,t)*h%t,m=ai(p,i,t)*p%t,g=ai(m,a,t)*m%t,y=ai(g,c,t)*g%t,w=ai(y,a,t)*m%t,b=ai(w,n,t)*l%t,v=ai(b,s,t)*p%t,E=ai(v,r,t)*u%t,_=ai(E,ts,t);if(!ns.eql(ns.sqr(_),e))throw new Error("Cannot find square root");return _}}),rs=function(e,t){const n=t=>Yi({...e,hash:t});return{...n(t),create:n}}({...Qi,Fp:ns,lowS:!0,endo:es},So);function os(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.subarray(r,r+t));return n}function is(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 ss(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e.subarray(0,r);return e.subarray(0,n)}function as(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function cs(e,t){const n=new Uint8Array(32);let r=e;for(let e=31;e>=0;e--)n[e]=Number(0xffn&r),r>>=8n;return n}function us(e,t){let n=0n;for(let t=0;t<32;t++)n=n<<8n|BigInt(e[t]);return n}function ls(e){const t=e.startsWith("0x")||e.startsWith("0X")?e.slice(2):e,n=new Uint8Array(t.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(t.slice(2*e,2*e+2),16);return n}var fs="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ds(e,t){const n=t.length;let r=0,o=0,i="";for(const s of e)for(o=o<<8|s,r+=8;r>=Math.log2(n);)r-=Math.log2(n),i+=t.charAt(o>>r&n-1);return r>0&&(i+=t.charAt(o<<Math.log2(n)-r&n-1)),i.length%4!=0&&(i+="=".repeat(4-i.length%4)),i}function hs(e){return function(e,t){const n=t.length;let r=0,o=0;const i=[];for(let s=0;s<e.length;s++){const a=e.charAt(s);if("="===a)break;const c=t.indexOf(a);if(-1===c)throw new Error(`Invalid character: ${a}`);o=o<<Math.log2(n)|c,r+=Math.log2(n),r>=8&&(r-=8,i.push(o>>r&255))}return new Uint8Array(i)}(e,fs)}function ps(e){return ds(e,fs)}function ms(e){return new Uint8Array([e])}function gs(e){return e[0]}function ys(e,t){return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(0,"LE"===t)}function ws(e,t){const n=new ArrayBuffer(4);return new DataView(n).setUint32(0,e,"LE"===t),new Uint8Array(n)}function bs(e,t){const n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,e,"LE"===t),new Uint8Array(n)}function vs(e,t){return new DataView(e.buffer,e.byteOffset,e.byteLength).getBigUint64(0,"LE"===t)}var Es=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function _s(e){return t=function(e,t){for(const n of t){for(let t=0;t<34;t+=2)e[t]=e[t]^n[t+1],e[t+1]=e[t+1]^n[t];xs(e)}return e}(new Array(50).fill(0),function(e,t){if(!e.length){const e=new Uint8Array(136);return e[0]=t,e[135]=128,[ks(e)]}const n=os(e,136),r=n[n.length-1];if(r.length<136){const e=new Uint8Array(136);e.set(r),e[r.length]=t,e[135]=128|e[135],n[n.length-1]=e}if(136===r.length){const e=new Uint8Array(136);e[0]=t,e[135]=128,n.push(e)}return n.map(ks)}(e,1)),new Uint8Array([t[1],t[1]>>-24,t[1]>>-16,t[1]>>-8,t[0],t[0]>>8,t[0]>>16,t[0]>>24,t[3],t[3]>>-24,t[3]>>-16,t[3]>>-8,t[2],t[2]>>8,t[2]>>16,t[2]>>24,t[5],t[5]>>-24,t[5]>>-16,t[5]>>-8,t[4],t[4]>>8,t[4]>>16,t[4]>>24,t[7],t[7]>>-24,t[7]>>-16,t[7]>>-8,t[6],t[6]>>8,t[6]>>16,t[6]>>24]);var t}function xs(e){for(let t=0;t<24;t++){const n=e[0]^e[10]^e[20]^e[30]^e[40],r=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],i=e[3]^e[13]^e[23]^e[33]^e[43],s=e[4]^e[14]^e[24]^e[34]^e[44],a=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],u=e[7]^e[17]^e[27]^e[37]^e[47],l=e[8]^e[18]^e[28]^e[38]^e[48],f=e[9]^e[19]^e[29]^e[39]^e[49],d=l^(o<<1|i>>>31),h=f^(i<<1|o>>>31),p=n^(s<<1|a>>>31),m=r^(a<<1|s>>>31),g=o^(c<<1|u>>>31),y=i^(u<<1|c>>>31),w=s^(l<<1|f>>>31),b=a^(f<<1|l>>>31),v=c^(n<<1|r>>>31),E=u^(r<<1|n>>>31);e[0]^=d,e[1]^=h,e[2]^=p,e[3]^=m,e[4]^=g,e[5]^=y,e[6]^=w,e[7]^=b,e[8]^=v,e[9]^=E,e[10]^=d,e[11]^=h,e[12]^=p,e[13]^=m,e[14]^=g,e[15]^=y,e[16]^=w,e[17]^=b,e[18]^=v,e[19]^=E,e[20]^=d,e[21]^=h,e[22]^=p,e[23]^=m,e[24]^=g,e[25]^=y,e[26]^=w,e[27]^=b,e[28]^=v,e[29]^=E,e[30]^=d,e[31]^=h,e[32]^=p,e[33]^=m,e[34]^=g,e[35]^=y,e[36]^=w,e[37]^=b,e[38]^=v,e[39]^=E,e[40]^=d,e[41]^=h,e[42]^=p,e[43]^=m,e[44]^=g,e[45]^=y,e[46]^=w,e[47]^=b,e[48]^=v,e[49]^=E;const _=e[0],x=e[1],k=e[2]<<1|e[3]>>>31,A=e[3]<<1|e[2]>>>31,I=e[5]<<30|e[4]>>>2,$=e[4]<<30|e[5]>>>2,B=e[6]<<28|e[7]>>>4,z=e[7]<<28|e[6]>>>4,S=e[8]<<27|e[9]>>>5,O=e[9]<<27|e[8]>>>5,T=e[11]<<4|e[10]>>>28,N=e[10]<<4|e[11]>>>28,R=e[13]<<12|e[12]>>>20,U=e[12]<<12|e[13]>>>20,P=e[14]<<6|e[15]>>>26,F=e[15]<<6|e[14]>>>26,C=e[17]<<23|e[16]>>>9,L=e[16]<<23|e[17]>>>9,M=e[18]<<20|e[19]>>>12,D=e[19]<<20|e[18]>>>12,Z=e[20]<<3|e[21]>>>29,j=e[21]<<3|e[20]>>>29,q=e[22]<<10|e[23]>>>22,G=e[23]<<10|e[22]>>>22,H=e[25]<<11|e[24]>>>21,V=e[24]<<11|e[25]>>>21,K=e[26]<<25|e[27]>>>7,W=e[27]<<25|e[26]>>>7,J=e[29]<<7|e[28]>>>25,X=e[28]<<7|e[29]>>>25,Y=e[31]<<9|e[30]>>>23,Q=e[30]<<9|e[31]>>>23,ee=e[33]<<13|e[32]>>>19,te=e[32]<<13|e[33]>>>19,ne=e[34]<<15|e[35]>>>17,re=e[35]<<15|e[34]>>>17,oe=e[36]<<21|e[37]>>>11,ie=e[37]<<21|e[36]>>>11,se=e[38]<<8|e[39]>>>24,ae=e[39]<<8|e[38]>>>24,ce=e[40]<<18|e[41]>>>14,ue=e[41]<<18|e[40]>>>14,le=e[42]<<2|e[43]>>>30,fe=e[43]<<2|e[42]>>>30,de=e[45]<<29|e[44]>>>3,he=e[44]<<29|e[45]>>>3,pe=e[47]<<24|e[46]>>>8,me=e[46]<<24|e[47]>>>8,ge=e[48]<<14|e[49]>>>18,ye=e[49]<<14|e[48]>>>18;e[0]=_^~R&H,e[1]=x^~U&V,e[2]=R^~H&oe,e[3]=U^~V&ie,e[4]=H^~oe&ge,e[5]=V^~ie&ye,e[6]=oe^~ge&_,e[7]=ie^~ye&x,e[8]=ge^~_&R,e[9]=ye^~x&U,e[10]=B^~M&Z,e[11]=z^~D&j,e[12]=M^~Z&ee,e[13]=D^~j&te,e[14]=Z^~ee&de,e[15]=j^~te&he,e[16]=ee^~de&B,e[17]=te^~he&z,e[18]=de^~B&M,e[19]=he^~z&D,e[20]=k^~P&K,e[21]=A^~F&W,e[22]=P^~K&se,e[23]=F^~W&ae,e[24]=K^~se&ce,e[25]=W^~ae&ue,e[26]=se^~ce&k,e[27]=ae^~ue&A,e[28]=ce^~k&P,e[29]=ue^~A&F,e[30]=S^~T&q,e[31]=O^~N&G,e[32]=T^~q&ne,e[33]=N^~G&re,e[34]=q^~ne&pe,e[35]=G^~re&me,e[36]=ne^~pe&S,e[37]=re^~me&O,e[38]=pe^~S&T,e[39]=me^~O&N,e[40]=I^~C&J,e[41]=$^~L&X,e[42]=C^~J&Y,e[43]=L^~X&Q,e[44]=J^~Y&le,e[45]=X^~Q&fe,e[46]=Y^~le&I,e[47]=Q^~fe&$,e[48]=le^~I&C,e[49]=fe^~$&L,e[0]^=Es[2*t],e[1]^=Es[2*t+1]}}function ks(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24);return t}var As=new TextDecoder,Is=new TextEncoder,$s=/^(0x)?[0-9a-fA-F]*$/i;var Bs=class e{bytes;length;constructor(t,n){if(!t)throw new Error(`Bytes#constructor: constructor parameter is falsy: ${t}`);if(t instanceof e)this.bytes=t.bytes;else if("string"==typeof t){if(!$s.test(t)||t.replace(/^0x/i,"").length%2!=0)throw new Error(`Bytes#constructor: invalid hex string: ${t}`);this.bytes=ls(t)}else if(t instanceof ArrayBuffer)this.bytes=new Uint8Array(t);else if(t instanceof Uint8Array)this.bytes=t;else{const e=t;if("object"!=typeof(r=e)||null===r||"function"!=typeof r.toHex)throw new Error("Bytes#constructor: unsupported type: "+typeof t);this.bytes=ls(e.toHex())}var r;if(this.length=this.bytes.length,void 0!==n)if(Array.isArray(n)){if(!n.includes(this.length))throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${n.join(" or ")}`)}else if(this.length!==n)throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${n}`)}static keccak256(t){return new e(_s(new e(t).toUint8Array()))}static concat(...t){const n=t.map(t=>t instanceof e?t.toUint8Array():t),r=n.reduce((e,t)=>e+t.length,0),o=new Uint8Array(r);let i=0;for(const e of n)o.set(e,i),i+=e.length;return o}static fromUtf8(t){return new e(Is.encode(t))}static fromSlice(t,n,r){return new e(void 0===r?t.slice(n):t.slice(n,n+r))}offset(e){return new Uint8Array(this.bytes.slice(e))}toUint8Array(){return new Uint8Array(this.bytes)}toHex(){return as(this.bytes)}toBase64(){return function(e){return ds(e,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}(this.bytes)}toBase32(){return ps(this.bytes)}toString(){return this.toHex()}toUtf8(){return As.decode(this.bytes)}toJSON(){return JSON.parse(this.toUtf8())}equals(t){return this.toHex()===new e(t).toHex()}represent(){return this.toHex()}},zs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}},Ss=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function Os(e){if(e<=0n||e>=Ss)throw new Error("Invalid private key");const t=rs.Point.BASE.multiply(e);return[t.x,t.y]}function Ts(e){const t=new Uint8Array(20),n=_s(Bs.concat(cs(e[0]),cs(e[1])));return t.set(n.subarray(12)),t}var Ns=class extends Bs{static LENGTH=20;constructor(e){super(e,20)}toChecksum(){return function(e){const t=as(e),n=as(_s(Uint8Array.from(t,e=>e.charCodeAt(0))));let r="0x";for(let e=0;e<t.length;e++)r+=parseInt(n.charAt(e),16)>7?t.charAt(e).toUpperCase():t.charAt(e);return r}(this.bytes)}},Rs=new Uint8Array(8).fill(255,0,8),Us=class e extends Bs{static LENGTH=8;static MINUS_ONE=new e(Rs);constructor(e){super(e,8)}static fromBigInt(t){return new e(bs(t,"BE"))}toBigInt(){return vs(this.bytes,"BE")}next(){return as(this.bytes)===as(Rs)?e.fromBigInt(0n):e.fromBigInt(this.toBigInt()+1n)}},Ps=new TextEncoder,Fs=class e extends Bs{static LENGTH=32;constructor(e){super(e,32)}static fromString(t){return new e(_s(Ps.encode(t)))}},Cs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}};function Ls(e,t){const n=rs.sign(_s(e),t,{prehash:!1}),r=0===n.recovery?27n:28n;return[n.r,n.s,r]}function Ms(e,t,n,r){const o=27n===r?0:1,i=new rs.Signature(t,n,o).recoverPublicKey(_s(e));return[i.x,i.y]}var Ds=class extends Bs{static LENGTH=64;constructor(e){const t=new Bs(e);if(33===t.length){const[e,n]=function(e){if(33!==e.length||2!==e[0]&&3!==e[0])throw new Error("Invalid compressed public key");const t=rs.Point.fromBytes(e);return[t.x,t.y]}(t.toUint8Array());super(Bs.concat(cs(e),cs(n)),64)}else super(e,64)}address(){const e=us(this.bytes.slice(0,32)),t=us(this.bytes.slice(32,64));return new Ns(Ts([e,t]))}toCompressedUint8Array(){const e=us(this.bytes.slice(0,32)),t=us(this.bytes.slice(32,64));return n=[e,t],rs.Point.fromAffine({x:n[0],y:n[1]}).toBytes(!0);var n}toCompressedHex(){return as(this.toCompressedUint8Array())}},Zs=new TextEncoder,js=Zs.encode("Ethereum Signed Message:\n32");function qs(e){const t=e instanceof Uint8Array?e:Zs.encode(e);return Bs.concat(js,_s(t))}var Gs=class e extends Bs{static LENGTH=65;constructor(e){super(e,65)}static fromSlice(t,n){return new e(t.slice(n,n+e.LENGTH))}recoverPublicKey(e){const t=us(this.bytes.slice(0,32)),n=us(this.bytes.slice(32,64)),r=BigInt(this.bytes[64]),[o,i]=Ms(qs(e),t,n,r);return new Ds(Bs.concat(cs(o),cs(i)))}isValid(e,t){return this.recoverPublicKey(e).address().equals(t)}},Hs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}publicKey(){const[e,t]=Os(this.toBigInt());return new Ds(Bs.concat(cs(e),cs(t)))}sign(e){const[t,n,r]=Ls(qs(e),this.toBigInt());return new Gs(Bs.concat(cs(t),cs(n),new Uint8Array([Number(r)])))}toBigInt(){return us(this.bytes)}};var Vs=class e extends Bs{static LENGTH=32;constructor(e){"string"==typeof e&&e.startsWith("bah5")?super(function(e){const t=hs(e.toUpperCase().slice(1)),n=t[1];if(250!==n&&251!==n)throw new Error("Unknown codec");return t.slice(-32)}(e),32):super(e,[32,64])}toCid(e){return`b${ps(Bs.concat(new Uint8Array([1]),new Uint8Array(["feed"===e?251:250]),new Uint8Array([1]),new Uint8Array([27]),new Uint8Array([32]))).replace(/=+$/,"")}${this.toBase32().replace(/=+$/,"")}`.toLowerCase()}static isValid(t){try{return new e(t),!0}catch{return!1}}},Ks=class e extends Bs{static LENGTH=8;constructor(e){super(e,8)}static fromBigInt(t){return new e(bs(t,"LE"))}toBigInt(){return vs(this.bytes,"LE")}static fromSlice(t,n){return new e(t.slice(n,n+e.LENGTH))}},Ws=new TextEncoder,Js=class e extends Bs{static LENGTH=32;constructor(e){super(e,32)}static fromString(t){return new e(_s(Ws.encode(t)))}},Xs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}},Ys=class{cursor=0;buffer;constructor(e){this.buffer=e}read(e){const t=this.buffer.subarray(this.cursor,this.cursor+e);return this.cursor+=e,t}max(){return this.buffer.length-this.cursor}},Qs=class{cursor=0;buffer;constructor(e){this.buffer=e}write(e){const t=Math.min(this.max(),e.max());return this.buffer.set(e.read(t),this.cursor),this.cursor+=t,t}max(){return this.buffer.length-this.cursor}};function ea(e,t,n){const r=new Uint8Array(n.length),o=new Uint8Array(36);o.set(e);for(let e=0,i=0;i<n.length;e++,i+=32){const s=t+e>>>0;o[32]=255&s,o[33]=s>>>8&255,o[34]=s>>>16&255,o[35]=s>>>24&255;const a=_s(_s(o)),c=Math.min(i+32,n.length);for(let e=i;e<c;e++)r[e]=n[e]^a[e-i]}return r}var ta=4096;function na(e){const t=e.subarray(0,8),n=function(e){if(e.length>ta)throw new Error(`payload size ${e.length} exceeds maximum chunk payload size 4096`);const t=new Uint8Array(ta);t.set(e);let n=os(t,32);for(;n.length>1;){const e=[];for(let t=0;t<n.length;t+=2)e.push(_s(Bs.concat(n[t],n[t+1])));n=e}return n[0]}(e.subarray(8));return new Vs(_s(Bs.concat(t,n)))}ls("dc5b20847f43d67928f49cd4f85d696b5a7617b5");var ra=Fs.LENGTH,oa=Fs.LENGTH+65,ia=oa+Ks.LENGTH,sa=(new TextEncoder).encode("Ethereum Signed Message:\n32");function aa(e,t){const n=_s(Bs.concat(e,t));return Bs.concat(sa,n)}function ca(e,t){const n=new Fs(e),r=new Ns(t);return new Vs(_s(Bs.concat(n.toUint8Array(),r.toUint8Array())))}function ua(e,t,n){const r=new Fs(t),o=function(e,t,n){const[r,o,i]=Ls(aa(e,t),n);return Bs.concat(cs(r),cs(o),new Uint8Array([Number(i)]))}(r.toUint8Array(),e.address.toUint8Array(),n),i=new Ns(Ts(Os(n))),s=ca(r,i);return{data:Bs.concat(r.toUint8Array(),o,e.data),identifier:r,signature:new Gs(o),span:e.span,payload:e.payload,address:s,owner:i}}function la(e,t){const n=e instanceof Bs?e.toUint8Array():e,r=new Vs(t),o=new Fs(Bs.fromSlice(n,0,Fs.LENGTH)),i=n.slice(ra,ra+65),s=na(n.slice(oa)),a=new Ns(function(e,t,n){const r=us(n.subarray(0,32)),o=us(n.subarray(32,64)),i=BigInt(n[64]);return Ts(Ms(aa(e,t),r,o,i))}(o.toUint8Array(),s.toUint8Array(),i)),c=ca(o,a);if(!c.equals(r))throw new Error("SOC data does not match given address");const u=Ks.fromSlice(n,oa),l=Bs.fromSlice(n,ia);return{data:n,identifier:o,signature:new Gs(i),span:u,payload:l,address:c,owner:a}}function fa(e,t){if("string"==typeof e&&(e=Bs.fromUtf8(e)),e.length<1||e.length>4096)throw new RangeError(`payload size ${e.length} exceeds limits [1, 4096]`);const n=t?"bigint"==typeof t?Ks.fromBigInt(t):t:Ks.fromBigInt(BigInt(e.length)),r=new Bs(e),o=Bs.concat(n.toUint8Array(),r.toUint8Array()),i={data:o,span:n,payload:r,address:na(o),toSingleOwnerChunk:(e,t)=>ua(i,e,new Hs(t).toBigInt())};return i}function da(e){const t=new Bs(e);return fa(t.toUint8Array().slice(Ks.LENGTH),Ks.fromSlice(t.toUint8Array(),0))}var ha=class{span;writer;constructor(e=0n){this.span=e,this.writer=new Qs(new Uint8Array(4096))}build(){return Bs.concat(bs(this.span,"LE"),this.writer.buffer)}hash(){return na(this.build())}encryptedHash(e){e||(e=new Uint8Array(32),crypto.getRandomValues(e));const t=function(e,t){return ea(e,128,t)}(e,bs(this.span,"LE")),n=function(e,t){return ea(e,0,t)}(e,this.writer.buffer);return{address:na(Bs.concat(t,n)),key:e}}},pa=class e{static NOOP=async e=>[];refSize;encrypted;maxShards;chunks;counters=[1];pending=[[]];onBatch;onIntermediateChunk;hasParity=[!1];pendingEntries=[];constructor(e,t,n=!1,r){this.encrypted=n,this.refSize=n?64:32,this.maxShards=t??4096/this.refSize,this.chunks=[new ha],this.onBatch=e,this.onIntermediateChunk=r}static async root(t){const n=new e(e.NOOP);return await n.append(t),n.finalize()}static async encryptedRoot(t){const n=new e(e.NOOP,void 0,!0);await n.append(t);return(await n.finalize()).encryptedHash()}async append(e,t=0,n=0n){const r=new Ys(e);for(;r.max()>0;){(0===this.chunks[t].writer.max()||n&&this.chunks[t].writer.max()<e.length)&&await this.elevate(t);const o=this.chunks[t].writer.write(r);n?this.chunks[t].span+=n:this.chunks[0].span+=BigInt(o)}}async elevate(e){this.counters[e]=(this.counters[e]+1)%(4096/this.refSize),this.pending[e]||(this.pending[e]=[]),await this.sealParities(e);const t=this.chunks[e].span;if(e>=1&&this.onIntermediateChunk&&(this.onIntermediateChunk(this.chunks[e],this.hasParity[e]??!1),this.hasParity[e]=!1),this.encrypted){const{address:n,key:r}=this.chunks[e].encryptedHash(),o=new Uint8Array(64);o.set(n.toUint8Array()),o.set(r,32),this.pending[e].push({entry:{chunk:this.chunks[e],key:r},ref:o,span:t})}else this.pending[e].push({entry:{chunk:this.chunks[e]},ref:this.chunks[e].hash().toUint8Array(),span:t});this.chunks[e]=new ha,this.pending[e].length>=this.maxShards&&await this.flushBatch(e)}async sealParities(e){const t=this.pendingEntries[e];if(!t?.length)return;this.pendingEntries[e]=[];const n=await this.onBatch(t);if(n.length>0){this.hasParity[e]=!0;for(const{chunk:t}of n)this.chunks[e].writer.write(new Ys(t.hash().toUint8Array()))}}async flushBatch(e){this.chunks[e+1]||(this.chunks.push(new ha),this.counters.push(1),this.pending.push([]),this.hasParity.push(!1));const t=this.pending[e];this.pending[e]=[];for(const{ref:n,span:r}of t)await this.append(n,e+1,r);this.pendingEntries[e+1]||(this.pendingEntries[e+1]=[]),this.pendingEntries[e+1].push(...t.map(e=>e.entry)),t.length>=this.maxShards&&await this.sealParities(e+1)}async finalize(e=0){return this.pending[e]?.length&&await this.flushBatch(e),this.chunks[e+1]?1===this.counters[e]?(await this.elevate(e+1),await this.flushBatch(e+1),this.chunks[e+1]=this.chunks[e],this.finalize(e+1)):(await this.elevate(e),await this.flushBatch(e),this.finalize(e+1)):(await this.sealParities(e),e>=1&&this.onIntermediateChunk&&this.onIntermediateChunk(this.chunks[e],this.hasParity[e]??!1),this.chunks[e])}};function ma(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r%t.length];return n}var ga=new TextEncoder,ya=new TextDecoder,wa=new Uint8Array([47]),ba=ls("5768b3b6a7db56d21d1abff40d41cebfc83448fed8d7e9b06ec0d3b073f28f7b");function va(e,t){const n=Math.floor(t/8),r=t%8;e[n]=e[n]|1<<r}function Ea(e,t){const n=t%8;return 1==(e[Math.floor(t/8)]>>n&1)}var _a=class e{obfuscationKey=new Uint8Array(32);selfAddress=null;targetAddress=new Uint8Array(32);metadata=null;path=new Uint8Array(0);forks=new Map;parent=null;type=null;encrypt=!1;constructor(e){e?.encrypt&&(this.encrypt=!0),e?.targetAddress?this.targetAddress=e.targetAddress:this.encrypt&&(this.targetAddress=new Uint8Array(64)),e?.selfAddress&&(this.selfAddress=e.selfAddress),e?.metadata&&(this.metadata=e.metadata),e?.obfuscationKey&&(this.obfuscationKey=e.obfuscationKey),e?.path&&(this.path=e.path),e?.parent&&(this.parent=e.parent),this.type=e?.type??null}get fullPath(){return Bs.concat(this.parent?.fullPath??new Uint8Array(0),this.path)}get fullPathString(){return ya.decode(this.fullPath)}async marshal(){for(const e of this.forks.values())e.node.selfAddress||(e.node.selfAddress=(await e.node.calculateSelfAddress()).toUint8Array());this.encrypt&&is(this.obfuscationKey,new Uint8Array(32))&&(this.obfuscationKey=new Uint8Array(32),crypto.getRandomValues(this.obfuscationKey));const e=!is(this.targetAddress,new Uint8Array(this.targetAddress.length));let t=0;if(e)t=this.targetAddress.length;else for(const e of this.forks.values())if(e.node.selfAddress&&e.node.selfAddress.length>0){t=e.node.selfAddress.length;break}const n=new Uint8Array(32);n.set(ba,0),n.set(ms(t),31);const r=e?this.targetAddress:new Uint8Array(t),o=new Uint8Array(32);for(const e of this.forks.keys())va(o,e);const i=[];for(let e=0;e<256;e++)Ea(o,e)&&i.push(this.forks.get(e).marshal());const s=ma(Bs.concat(n,r,o,...i),this.obfuscationKey);return Bs.concat(this.obfuscationKey,s)}static unmarshalFromData(t,n){if(t.length<64)throw new Error("MantarayNode#unmarshalFromData data too short");const r=t.subarray(0,32),o=ma(t.subarray(32),r),i=new Ys(o);if(!is(i.read(31),ba.slice(0,31)))throw new Error("MantarayNode#unmarshalFromData invalid version hash");const s=gs(i.read(1)),a=i.read(s),c=new e({selfAddress:n,targetAddress:a,obfuscationKey:r}),u=i.read(32),l=0===s?32:s;for(let e=0;e<256;e++)if(Ea(u,e)){const t=Aa.unmarshal(i,l);c.forks.set(e,t),t.node.parent=c}return c}addFork(t,n,r){this.selfAddress=null,this.type=null,t=t instanceof Uint8Array?t:ga.encode(t);let o=this;for(;t.length;){const i=t.slice(0,30),s=0===(t=t.slice(30)).length,[a,c]=o.findClosest(i),u=i.slice(c.length);if(c.length&&(o=a),!u.length)continue;const l=new Aa(u,new e({targetAddress:s?new Vs(n).toUint8Array():void 0,metadata:s?r:void 0,path:u,encrypt:this.encrypt})),f=a.forks.get(u[0]);if(f){const e=Aa.split(l,f);o.forks.set(u[0],e),e.node.parent=o}else o.forks.set(u[0],l),l.node.parent=o;o.selfAddress=null,o.type=null,o=l.node}}removeFork(e){if(this.selfAddress=null,this.type=null,0===(e=e instanceof Uint8Array?e:ga.encode(e)).length)throw new Error("MantarayNode#removeFork path cannot be empty");const t=this.find(e);if(!t)throw new Error("MantarayNode#removeFork fork not found");const[n,r]=this.findClosest(e.slice(0,e.length-1));n.forks.delete(e.slice(r.length)[0]);for(const e of t.forks.values())n.addFork(Bs.concat(t.path,e.prefix),e.node.targetAddress,e.node.metadata)}async calculateSelfAddress(){if(this.selfAddress)return new Vs(this.selfAddress);if(this.encrypt)throw new Error("MantarayNode#calculateSelfAddress is not supported for encrypted nodes - use saveRecursively");return(await pa.root(await this.marshal())).hash()}async saveRecursively(e){for(const t of this.forks.values())await t.node.saveRecursively(e);const t=new pa(async t=>{for(const{chunk:n,key:r}of t)await e(n,r);return[]},void 0,this.encrypt);await t.append(await this.marshal());const n=await t.finalize();if(this.encrypt){const{address:t,key:r}=n.encryptedHash();return await e(n,r),this.selfAddress=Bs.concat(t.toUint8Array(),r),{reference:this.selfAddress,rootChunk:n,encryptionKey:r}}return await e(n),this.selfAddress=n.hash().toUint8Array(),{reference:this.selfAddress,rootChunk:n}}find(e){const t=e instanceof Uint8Array?e:ga.encode(e),[n,r]=this.findClosest(t);return r.length===t.length?n:null}findClosest(e,t=new Uint8Array){if(0===(e=e instanceof Uint8Array?e:ga.encode(e)).length)return[this,t];const n=this.forks.get(e[0]);return n&&ss(n.prefix,e).length===n.prefix.length?n.node.findClosest(e.slice(n.prefix.length),Bs.concat(t,n.prefix)):[this,t]}collect(e=[]){for(const t of this.forks.values())is(t.node.targetAddress,new Uint8Array(t.node.targetAddress.length))||e.push(t.node),t.node.collect(e);return e}collectAndMap(){const e={};for(const t of this.collect())e[t.fullPathString]=new Vs(t.targetAddress).toHex();return e}determineType(){let e=0;const t=new Uint8Array(this.targetAddress.length);return is(this.targetAddress,t)&&0!==this.forks.size||(e|=2),this.forks.size>0&&(e|=4),function(e,t,n=0){for(let r=n;r<e.length;r++)for(let n=0;n<t.length&&e[r+n]===t[n];n++)if(n===t.length-1)return r;return-1}(this.path,wa)>0&&(e|=8),this.metadata&&(e|=16),e}},xa=new TextEncoder,ka=new TextDecoder;var Aa=class e{prefix;node;constructor(e,t){this.prefix=e,this.node=t}static split(t,n){const r=ss(t.prefix,n.prefix);if(r.length===t.prefix.length){const e=n.prefix.slice(r.length);return n.node.path=n.prefix.slice(r.length),n.prefix=n.prefix.slice(r.length),n.node.parent=t.node,t.node.forks.set(e[0],n),t}if(r.length===n.prefix.length){const e=t.prefix.slice(r.length);return t.node.path=t.prefix.slice(r.length),t.prefix=t.prefix.slice(r.length),t.node.parent=n.node,n.node.forks.set(e[0],t),n}const o=new _a({path:r,encrypt:t.node.encrypt}),i=new e(t.prefix.slice(r.length),t.node),s=new e(n.prefix.slice(r.length),n.node);return t.node.path=t.prefix.slice(r.length),n.node.path=n.prefix.slice(r.length),t.prefix=t.prefix.slice(r.length),n.prefix=n.prefix.slice(r.length),o.forks.set(i.prefix[0],i),o.forks.set(s.prefix[0],s),i.node.parent=o,s.node.parent=o,new e(r,o)}marshal(){if(!this.node.selfAddress)throw new Error("Fork#marshal node.selfAddress is not set");const e=[];if(e.push(new Uint8Array([this.node.type??this.node.determineType()])),e.push(ms(this.prefix.length)),e.push(this.prefix),this.prefix.length<30&&e.push(new Uint8Array(30-this.prefix.length)),e.push(this.node.selfAddress),this.node.metadata){const t=function(e,t,n){const r=e.length%t;if(0===r)return e;const o=new Uint8Array(e.length+t-r).fill(n);return o.set(e,0),o}(Bs.concat(new Uint8Array([0,0]),xa.encode(JSON.stringify(this.node.metadata))),32,10);t.set(function(e,t){const n=new ArrayBuffer(2);return new DataView(n).setUint16(0,e,"LE"===t),new Uint8Array(n)}(t.length-2,"BE"),0),e.push(t)}return Bs.concat(...e)}static unmarshal(t,n){const r=gs(t.read(1)),o=gs(t.read(1)),i=t.read(o);o<30&&t.read(30-o);const s=t.read(n);let a;if(function(e,t){return(e&t)===t}(r,16)){const e=ys(t.read(2),"BE");if(e>t.max())throw new Error("Fork#unmarshal not enough bytes for metadata");a=JSON.parse(ka.decode(t.read(e)))}return new e(i,new _a({selfAddress:s,metadata:a,path:i,type:r}))}};function Ia(e,t,n){return e/Math.pow(2,t-n)}function $a(e){return 4096*2**e}function Ba(e){const t=e.match(/^([\d.]+)\s*(B|kB|MB|GB|TB|PB)$/);if(!t)throw new Error(`Invalid size format: ${e}`);return Math.ceil(parseFloat(t[1])*{B:1,kB:1e3,MB:1e6,GB:1e3**3,TB:1e3**4,PB:1e3**5}[t[2]])}var za,Sa=[[17,"0.00004089 GB"],[18,"0.00609 GB"],[19,"0.10249 GB"],[20,"0.62891 GB"],[21,"2.38 GB"],[22,"7.07 GB"],[23,"18.24 GB"],[24,"43.04 GB"],[25,"96.5 GB"],[26,"208.52 GB"],[27,"435.98 GB"],[28,"908.81 GB"],[29,"1870 GB"],[30,"3810 GB"],[31,"7730 GB"],[32,"15610 GB"],[33,"31430 GB"],[34,"63150 GB"]],Oa=[[[17,"44.70 kB"],[18,"6.66 MB"],[19,"112.06 MB"],[20,"687.62 MB"],[21,"2.60 GB"],[22,"7.73 GB"],[23,"19.94 GB"],[24,"47.06 GB"],[25,"105.51 GB"],[26,"227.98 GB"],[27,"476.68 GB"],[28,"993.65 GB"],[29,"2.04 TB"],[30,"4.17 TB"],[31,"8.45 TB"],[32,"17.07 TB"],[33,"34.36 TB"],[34,"69.04 TB"],[35,"138.54 TB"],[36,"277.72 TB"],[37,"556.35 TB"],[38,"1.11 PB"],[39,"2.23 PB"],[40,"4.46 PB"],[41,"8.93 PB"]],[[17,"41.56 kB"],[18,"6.19 MB"],[19,"104.18 MB"],[20,"639.27 MB"],[21,"2.41 GB"],[22,"7.18 GB"],[23,"18.54 GB"],[24,"43.75 GB"],[25,"98.09 GB"],[26,"211.95 GB"],[27,"443.16 GB"],[28,"923.78 GB"],[29,"1.90 TB"],[30,"3.88 TB"],[31,"7.86 TB"],[32,"15.87 TB"],[33,"31.94 TB"],[34,"64.19 TB"],[35,"128.80 TB"],[36,"258.19 TB"],[37,"517.23 TB"],[38,"1.04 PB"],[39,"2.07 PB"],[40,"4.15 PB"],[41,"8.30 PB"]],[[17,"37.37 kB"],[18,"5.57 MB"],[19,"93.68 MB"],[20,"574.81 MB"],[21,"2.17 GB"],[22,"6.46 GB"],[23,"16.67 GB"],[24,"39.34 GB"],[25,"88.20 GB"],[26,"190.58 GB"],[27,"398.47 GB"],[28,"830.63 GB"],[29,"1.71 TB"],[30,"3.49 TB"],[31,"7.07 TB"],[32,"14.27 TB"],[33,"28.72 TB"],[34,"57.71 TB"],[35,"115.81 TB"],[36,"232.16 TB"],[37,"465.07 TB"],[38,"931.23 TB"],[39,"1.86 PB"],[40,"3.73 PB"],[41,"7.46 PB"]],[[17,"33.88 kB"],[18,"5.05 MB"],[19,"84.92 MB"],[20,"521.09 MB"],[21,"1.97 GB"],[22,"5.86 GB"],[23,"15.11 GB"],[24,"35.66 GB"],[25,"79.96 GB"],[26,"172.77 GB"],[27,"361.23 GB"],[28,"753.00 GB"],[29,"1.55 TB"],[30,"3.16 TB"],[31,"6.41 TB"],[32,"12.93 TB"],[33,"26.04 TB"],[34,"52.32 TB"],[35,"104.99 TB"],[36,"210.46 TB"],[37,"421.61 TB"],[38,"844.20 TB"],[39,"1.69 PB"],[40,"3.38 PB"],[41,"6.77 PB"]],[[17,"13.27 kB"],[18,"1.98 MB"],[19,"33.27 MB"],[20,"204.14 MB"],[21,"771.13 MB"],[22,"2.29 GB"],[23,"5.92 GB"],[24,"13.97 GB"],[25,"31.32 GB"],[26,"67.68 GB"],[27,"141.51 GB"],[28,"294.99 GB"],[29,"606.90 GB"],[30,"1.24 TB"],[31,"2.51 TB"],[32,"5.07 TB"],[33,"10.20 TB"],[34,"20.50 TB"],[35,"41.13 TB"],[36,"82.45 TB"],[37,"165.17 TB"],[38,"330.72 TB"],[39,"661.97 TB"],[40,"1.32 PB"],[41,"2.65 PB"]]],Ta=[[[17,"44.35 kB"],[18,"6.61 MB"],[19,"111.18 MB"],[20,"682.21 MB"],[21,"2.58 GB"],[22,"7.67 GB"],[23,"19.78 GB"],[24,"46.69 GB"],[25,"104.68 GB"],[26,"226.19 GB"],[27,"472.93 GB"],[28,"985.83 GB"],[29,"2.03 TB"],[30,"4.14 TB"],[31,"8.39 TB"],[32,"16.93 TB"],[33,"34.09 TB"],[34,"68.50 TB"],[35,"137.45 TB"],[36,"275.53 TB"],[37,"551.97 TB"],[38,"1.11 PB"],[39,"2.21 PB"],[40,"4.43 PB"],[41,"8.86 PB"]],[[17,"40.89 kB"],[18,"6.09 MB"],[19,"102.49 MB"],[20,"628.91 MB"],[21,"2.38 GB"],[22,"7.07 GB"],[23,"18.24 GB"],[24,"43.04 GB"],[25,"96.50 GB"],[26,"208.52 GB"],[27,"435.98 GB"],[28,"908.81 GB"],[29,"1.87 TB"],[30,"3.81 TB"],[31,"7.73 TB"],[32,"15.61 TB"],[33,"31.43 TB"],[34,"63.15 TB"],[35,"126.71 TB"],[36,"254.01 TB"],[37,"508.85 TB"],[38,"1.02 PB"],[39,"2.04 PB"],[40,"4.08 PB"],[41,"8.17 PB"]],[[17,"36.73 kB"],[18,"5.47 MB"],[19,"92.07 MB"],[20,"564.95 MB"],[21,"2.13 GB"],[22,"6.35 GB"],[23,"16.38 GB"],[24,"38.66 GB"],[25,"86.69 GB"],[26,"187.31 GB"],[27,"391.64 GB"],[28,"816.39 GB"],[29,"1.68 TB"],[30,"3.43 TB"],[31,"6.94 TB"],[32,"14.02 TB"],[33,"28.23 TB"],[34,"56.72 TB"],[35,"113.82 TB"],[36,"228.18 TB"],[37,"457.10 TB"],[38,"915.26 TB"],[39,"1.83 PB"],[40,"3.67 PB"],[41,"7.34 PB"]],[[17,"33.26 kB"],[18,"4.96 MB"],[19,"83.38 MB"],[20,"511.65 MB"],[21,"1.93 GB"],[22,"5.75 GB"],[23,"14.84 GB"],[24,"35.02 GB"],[25,"78.51 GB"],[26,"169.64 GB"],[27,"354.69 GB"],[28,"739.37 GB"],[29,"1.52 TB"],[30,"3.10 TB"],[31,"6.29 TB"],[32,"12.70 TB"],[33,"25.57 TB"],[34,"51.37 TB"],[35,"103.08 TB"],[36,"206.65 TB"],[37,"413.98 TB"],[38,"828.91 TB"],[39,"1.66 PB"],[40,"3.32 PB"],[41,"6.64 PB"]],[[17,"13.17 kB"],[18,"1.96 MB"],[19,"33.01 MB"],[20,"202.53 MB"],[21,"765.05 MB"],[22,"2.28 GB"],[23,"5.87 GB"],[24,"13.86 GB"],[25,"31.08 GB"],[26,"67.15 GB"],[27,"140.40 GB"],[28,"292.67 GB"],[29,"602.12 GB"],[30,"1.23 TB"],[31,"2.49 TB"],[32,"5.03 TB"],[33,"10.12 TB"],[34,"20.34 TB"],[35,"40.80 TB"],[36,"81.80 TB"],[37,"163.87 TB"],[38,"328.11 TB"],[39,"656.76 TB"],[40,"1.31 PB"],[41,"2.63 PB"]]];function Na(e,t,n){if(e<17)return 0;if(void 0!==t&&void 0!==n){const r=(t?Ta:Oa)[n],o=r?.find(([t])=>t===e);if(o)return Ba(o[1])}else{const t=Sa.find(([t])=>t===e);if(t)return Ba(t[1])}return Math.ceil(.9*$a(e))}function Ra(e,t,n){if(void 0!==t&&void 0!==n){const r=(t?Ta:Oa)[n],o=r?.find(([,t])=>e<=Ba(t));if(o)return o[0]}else for(const[t,n]of Sa)if(e<=Ba(n))return t;return 35}function Ua(e){return function(e,t,n,r){if(65!==e.length)throw new Error("invalid signature length");if(32!==t.length)throw new Error("invalid batch ID length");if(8!==n.length)throw new Error("invalid timestamp length");if(8!==r.length)throw new Error("invalid index length");return new Bs(Bs.concat(t,r,n,e))}(e.signature.toUint8Array(),e.batchId.toUint8Array(),e.timestamp,e.index)}function Pa(e,t,n,r,o=Date.now()){const i=new Hs(e),s=new zs(t),a=ys(n,"BE"),c=Bs.concat(ws(a,"BE"),ws(r,"BE")),u=bs(1000000n*BigInt(o),"BE"),l=i.sign(Bs.concat(n,s.toUint8Array(),c,u));return{batchId:s,index:c,issuer:i.publicKey().address(),signature:l,timestamp:u}}function Fa(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:s,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const o=s.prototype,i=Object.keys(o);for(let e=0;e<i.length;e++){const t=i[e];t in n||(n[t]=o[t].bind(n))}}const o=n?.Parent??Object;class i extends o{}function s(e){var t;const o=n?.Parent?new i:this;r(o,e),(t=o._zod).deferred??(t.deferred=[]);for(const e of o._zod.deferred)e();return o}return Object.defineProperty(i,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class Ca extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class La extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}(za=globalThis).__zod_globalConfig??(za.__zod_globalConfig={});const Ma=globalThis.__zod_globalConfig;function Da(e){return Ma}function Za(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function ja(e,t){return"bigint"==typeof t?t.toString():t}function qa(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Ga(e){return null==e}function Ha(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const Va=Symbol("evaluating");function Ka(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Va)return void 0===r&&(r=Va,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Wa(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Ja(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Xa(e){return JSON.stringify(e)}const Ya="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Qa(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const ec=qa(()=>{if(Ma.jitless)return!1;if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function tc(e){if(!1===Qa(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==Qa(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function nc(e){return tc(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const rc=new Set(["string","number","symbol"]);function oc(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ic(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function sc(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const ac={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function cc(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function uc(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!1===e.issues[n]?.continue)return!0;return!1}function lc(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function fc(e){return"string"==typeof e?e:e?.message}function dc(e,t,n){const r=e.message?e.message:fc(e.inst?._zod.def?.error?.(e))??fc(t?.error?.(e))??fc(n.customError?.(e))??fc(n.localeError?.(e))??"Invalid input",{inst:o,continue:i,input:s,...a}=e;return a.path??(a.path=[]),a.message=r,t?.reportInput&&(a.input=s),a}function hc(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function pc(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const mc=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ja,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},gc=Fa("$ZodError",mc),yc=Fa("$ZodError",mc,{Parent:Error});const wc=e=>(t,n,r,o)=>{const i=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new Ca;if(s.issues.length){const t=new(o?.Err??e)(s.issues.map(e=>dc(e,i,Da())));throw Ya(t,o?.callee),t}return s.value},bc=wc(yc),vc=e=>async(t,n,r,o)=>{const i=r?{...r,async:!0}:{async:!0};let s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(o?.Err??e)(s.issues.map(e=>dc(e,i,Da())));throw Ya(t,o?.callee),t}return s.value},Ec=vc(yc),_c=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new Ca;return i.issues.length?{success:!1,error:new(e??gc)(i.issues.map(e=>dc(e,o,Da())))}:{success:!0,data:i.value}},xc=_c(yc),kc=e=>async(t,n,r)=>{const o=r?{...r,async:!0}:{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(e=>dc(e,o,Da())))}:{success:!0,data:i.value}},Ac=kc(yc),Ic=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return wc(e)(t,n,o)},$c=e=>(t,n,r)=>wc(e)(t,n,r),Bc=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return vc(e)(t,n,o)},zc=e=>async(t,n,r)=>vc(e)(t,n,r),Sc=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return _c(e)(t,n,o)},Oc=e=>(t,n,r)=>_c(e)(t,n,r),Tc=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return kc(e)(t,n,o)},Nc=e=>async(t,n,r)=>kc(e)(t,n,r),Rc=/^[cC][0-9a-z]{6,}$/,Uc=/^[0-9a-z]+$/,Pc=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Fc=/^[0-9a-vA-V]{20}$/,Cc=/^[A-Za-z0-9]{27}$/,Lc=/^[a-zA-Z0-9_-]{21}$/,Mc=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Dc=/^([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})$/,Zc=e=>e?new 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)$/,jc=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const qc=/^(?:(?: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])$/,Gc=/^(([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}|:))$/,Hc=/^((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])$/,Vc=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Kc=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Wc=/^[A-Za-z0-9_-]*$/,Jc=/^https?$/,Xc=/^\+[1-9]\d{6,14}$/,Yc="(?:(?:\\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])))",Qc=new RegExp(`^${Yc}$`);function eu(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const tu=/^-?\d+n?$/,nu=/^-?\d+$/,ru=/^-?\d+(?:\.\d+)?$/,ou=/^(?:true|false)$/i,iu=/^[^A-Z]*$/,su=/^[^a-z]*$/,au=Fa("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),cu={number:"number",bigint:"bigint",object:"date"},uu=Fa("$ZodCheckLessThan",(e,t)=>{au.init(e,t);const n=cu[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),lu=Fa("$ZodCheckGreaterThan",(e,t)=>{au.init(e,t);const n=cu[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),fu=Fa("$ZodCheckMultipleOf",(e,t)=>{au.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=e/t,r=Math.round(n),o=Number.EPSILON*Math.max(Math.abs(n),1);return Math.abs(n-r)<o?0:n-r}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),du=Fa("$ZodCheckNumberFormat",(e,t)=>{au.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,i]=ac[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=o,r.maximum=i,n&&(r.pattern=nu)}),e._zod.check=s=>{const a=s.value;if(n){if(!Number.isInteger(a))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});if(!Number.isSafeInteger(a))return void(a>0?s.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):s.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}))}a<o&&s.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),a>i&&s.issues.push({origin:"number",input:a,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),hu=Fa("$ZodCheckMaxLength",(e,t)=>{var n;au.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Ga(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const o=hc(r);n.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),pu=Fa("$ZodCheckMinLength",(e,t)=>{var n;au.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Ga(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const o=hc(r);n.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),mu=Fa("$ZodCheckLengthEquals",(e,t)=>{var n;au.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Ga(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,o=r.length;if(o===t.length)return;const i=hc(r),s=o>t.length;n.issues.push({origin:i,...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})}}),gu=Fa("$ZodCheckStringFormat",(e,t)=>{var n,r;au.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),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=()=>{})}),yu=Fa("$ZodCheckRegex",(e,t)=>{gu.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})}}),wu=Fa("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=iu),gu.init(e,t)}),bu=Fa("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=su),gu.init(e,t)}),vu=Fa("$ZodCheckIncludes",(e,t)=>{au.init(e,t);const n=oc(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),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})}}),Eu=Fa("$ZodCheckStartsWith",(e,t)=>{au.init(e,t);const n=new RegExp(`^${oc(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(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})}}),_u=Fa("$ZodCheckEndsWith",(e,t)=>{au.init(e,t);const n=new RegExp(`.*${oc(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(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})}}),xu=Fa("$ZodCheckOverwrite",(e,t)=>{au.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class ku{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Au={major:4,minor:4,patch:3},Iu=Fa("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Au;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,o=cc(e);for(const i of t){if(i._zod.def.when){if(uc(e))continue;if(!i._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,s=i._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new Ca;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(o||(o=cc(e,t)))});else{if(e.issues.length===t)continue;o||(o=cc(e,t))}}return r?r.then(()=>e):e},n=(n,o,i)=>{if(cc(n))return n.aborted=!0,n;const s=t(o,r,i);if(s instanceof Promise){if(!1===i.async)throw new Ca;return s.then(t=>e._zod.parse(t,i))}return e._zod.parse(s,i)};e._zod.run=(o,i)=>{if(i.skipChecks)return e._zod.parse(o,i);if("backward"===i.direction){const t=e._zod.parse({value:o.value,issues:[]},{...i,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,o,i)):n(t,o,i)}const s=e._zod.parse(o,i);if(s instanceof Promise){if(!1===i.async)throw new Ca;return s.then(e=>t(e,r,i))}return t(s,r,i)}}Ka(e,"~standard",()=>({validate:t=>{try{const n=xc(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return Ac(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}))}),$u=Fa("$ZodString",(e,t)=>{var n;Iu.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Bu=Fa("$ZodStringFormat",(e,t)=>{gu.init(e,t),$u.init(e,t)}),zu=Fa("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Dc),Bu.init(e,t)}),Su=Fa("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Zc(e))}else t.pattern??(t.pattern=Zc());Bu.init(e,t)}),Ou=Fa("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=jc),Bu.init(e,t)}),Tu=Fa("$ZodURL",(e,t)=>{Bu.init(e,t),e._zod.check=n=>{try{const r=n.value.trim();if(!t.normalize&&t.protocol?.source===Jc.source&&!/^https?:\/\//i.test(r))return void n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});const o=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.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&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(t.normalize?n.value=o.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Nu=Fa("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Bu.init(e,t)}),Ru=Fa("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Lc),Bu.init(e,t)}),Uu=Fa("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Rc),Bu.init(e,t)}),Pu=Fa("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Uc),Bu.init(e,t)}),Fu=Fa("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Pc),Bu.init(e,t)}),Cu=Fa("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Fc),Bu.init(e,t)}),Lu=Fa("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Cc),Bu.init(e,t)}),Mu=Fa("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=eu({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Yc}T(?:${r})$`)}(t)),Bu.init(e,t)}),Du=Fa("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Qc),Bu.init(e,t)}),Zu=Fa("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${eu(t)}$`)),Bu.init(e,t)}),ju=Fa("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Mc),Bu.init(e,t)}),qu=Fa("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=qc),Bu.init(e,t),e._zod.bag.format="ipv4"}),Gu=Fa("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Gc),Bu.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Hu=Fa("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Hc),Bu.init(e,t)}),Vu=Fa("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Vc),Bu.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Ku(e){if(""===e)return!0;if(/\s/.test(e))return!1;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Wu=Fa("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Kc),Bu.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Ku(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const Ju=Fa("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Wc),Bu.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!Wc.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return Ku(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Xu=Fa("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Xc),Bu.init(e,t)});const Yu=Fa("$ZodJWT",(e,t)=>{Bu.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&"JWT"!==o?.typ||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Qu=Fa("$ZodNumber",(e,t)=>{Iu.init(e,t),e._zod.pattern=e._zod.bag.pattern??ru,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const o=n.value;if("number"==typeof o&&!Number.isNaN(o)&&Number.isFinite(o))return n;const i="number"==typeof o?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),n}}),el=Fa("$ZodNumberFormat",(e,t)=>{du.init(e,t),Qu.init(e,t)}),tl=Fa("$ZodBoolean",(e,t)=>{Iu.init(e,t),e._zod.pattern=ou,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const o=n.value;return"boolean"==typeof o||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),nl=Fa("$ZodBigInt",(e,t)=>{Iu.init(e,t),e._zod.pattern=tu,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}}),rl=Fa("$ZodAny",(e,t)=>{Iu.init(e,t),e._zod.parse=e=>e}),ol=Fa("$ZodUnknown",(e,t)=>{Iu.init(e,t),e._zod.parse=e=>e}),il=Fa("$ZodNever",(e,t)=>{Iu.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function sl(e,t,n){e.issues.length&&t.issues.push(...lc(n,e.issues)),t.value[n]=e.value}const al=Fa("$ZodArray",(e,t)=>{Iu.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let e=0;e<o.length;e++){const s=o[e],a=t.element._zod.run({value:s,issues:[]},r);a instanceof Promise?i.push(a.then(t=>sl(t,n,e))):sl(a,n,e)}return i.length?Promise.all(i).then(()=>n):n}});function cl(e,t,n,r,o,i){const s=n in r;if(e.issues.length){if(o&&i&&!s)return;t.issues.push(...lc(n,e.issues))}s||o?void 0===e.value?s&&(t.value[n]=void 0):t.value[n]=e.value:e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]})}function ul(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function ll(e,t,n,r,o,i){const s=[],a=o.keySet,c=o.catchall._zod,u=c.def.type,l="optional"===c.optin,f="optional"===c.optout;for(const o in t){if("__proto__"===o)continue;if(a.has(o))continue;if("never"===u){s.push(o);continue}const i=c.run({value:t[o],issues:[]},r);i instanceof Promise?e.push(i.then(e=>cl(e,n,o,t,l,f))):cl(i,n,o,t,l,f)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const fl=Fa("$ZodObject",(e,t)=>{Iu.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=qa(()=>ul(t));Ka(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});const o=Qa,i=t.catchall;let s;e._zod.parse=(t,n)=>{s??(s=r.value);const a=t.value;if(!o(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=s.shape;for(const e of s.keys){const r=u[e],o="optional"===r._zod.optin,i="optional"===r._zod.optout,s=r._zod.run({value:a[e],issues:[]},n);s instanceof Promise?c.push(s.then(n=>cl(n,t,e,a,o,i))):cl(s,t,e,a,o,i)}return i?ll(c,a,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),dl=Fa("$ZodObjectJIT",(e,t)=>{fl.init(e,t);const n=e._zod.parse,r=qa(()=>ul(t));let o;const i=Qa,s=!Ma.jitless,a=s&&ec.value,c=t.catchall;let u;e._zod.parse=(l,f)=>{u??(u=r.value);const d=l.value;return i(d)?s&&a&&!1===f?.async&&!0!==f.jitless?(o||(o=(e=>{const t=new ku(["shape","payload","ctx"]),n=r.value,o=e=>{const t=Xa(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const i=Object.create(null);let s=0;for(const e of n.keys)i[e]="key_"+s++;t.write("const newResult = {};");for(const r of n.keys){const n=i[r],s=Xa(r),a=e[r],c="optional"===a?._zod?.optin,u="optional"===a?._zod?.optout;t.write(`const ${n} = ${o(r)};`),c&&u?t.write(`\n if (${n}.issues.length) {\n if (${s} in input) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `):c?t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `):t.write(`\n const ${n}_present = ${s} in input;\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n if (!${n}_present && !${n}.issues.length) {\n payload.issues.push({\n code: "invalid_type",\n expected: "nonoptional",\n input: undefined,\n path: [${s}]\n });\n }\n\n if (${n}_present) {\n if (${n}.value === undefined) {\n newResult[${s}] = undefined;\n } else {\n newResult[${s}] = ${n}.value;\n }\n }\n\n `)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,n)=>a(e,t,n)})(t.shape)),l=o(l,f),c?ll([],d,l,f,u,e):l):n(l,f):(l.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),l)}});function hl(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const o=e.filter(e=>!cc(e));return 1===o.length?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>dc(e,r,Da())))}),t)}const pl=Fa("$ZodUnion",(e,t)=>{Iu.init(e,t),Ka(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),Ka(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),Ka(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Ka(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>Ha(e.source)).join("|")})$`)}});const n=1===t.options.length?t.options[0]._zod.run:null;e._zod.parse=(r,o)=>{if(n)return n(r,o);let i=!1;const s=[];for(const e of t.options){const t=e._zod.run({value:r.value,issues:[]},o);if(t instanceof Promise)s.push(t),i=!0;else{if(0===t.issues.length)return t;s.push(t)}}return i?Promise.all(s).then(t=>hl(t,r,e,o)):hl(s,r,e,o)}}),ml=Fa("$ZodIntersection",(e,t)=>{Iu.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,o=t.left._zod.run({value:r,issues:[]},n),i=t.right._zod.run({value:r,issues:[]},n);return o instanceof Promise||i instanceof Promise?Promise.all([o,i]).then(([t,n])=>yl(e,t,n)):yl(e,o,i)}});function gl(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(tc(e)&&tc(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),o={...e,...t};for(const n of r){const r=gl(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};o[n]=r.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=gl(e[r],t[r]);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function yl(e,t,n){const r=new Map;let o;for(const n of t.issues)if("unrecognized_keys"===n.code){o??(o=n);for(const e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(const t of n.issues)if("unrecognized_keys"===t.code)for(const e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);const i=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(i.length&&o&&e.issues.push({...o,keys:i}),cc(e))return e;const s=gl(t.value,n.value);if(!s.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(s.mergeErrorPath)}`);return e.value=s.data,e}const wl=Fa("$ZodTuple",(e,t)=>{Iu.init(e,t);const n=t.items;e._zod.parse=(r,o)=>{const i=r.value;if(!Array.isArray(i))return r.issues.push({input:i,inst:e,expected:"tuple",code:"invalid_type"}),r;r.value=[];const s=[],a=bl(n,"optin"),c=bl(n,"optout");if(!t.rest){if(i.length<a)return r.issues.push({code:"too_small",minimum:a,inclusive:!0,input:i,inst:e,origin:"array"}),r;i.length>n.length&&r.issues.push({code:"too_big",maximum:n.length,inclusive:!0,input:i,inst:e,origin:"array"})}const u=new Array(n.length);for(let e=0;e<n.length;e++){const t=n[e]._zod.run({value:i[e],issues:[]},o);t instanceof Promise?s.push(t.then(t=>{u[e]=t})):u[e]=t}if(t.rest){let e=n.length-1;const a=i.slice(n.length);for(const n of a){e++;const i=t.rest._zod.run({value:n,issues:[]},o);i instanceof Promise?s.push(i.then(t=>vl(t,r,e))):vl(i,r,e)}}return s.length?Promise.all(s).then(()=>El(u,r,n,i,c)):El(u,r,n,i,c)}});function bl(e,t){for(let n=e.length-1;n>=0;n--)if("optional"!==e[n]._zod[t])return n+1;return 0}function vl(e,t,n){e.issues.length&&t.issues.push(...lc(n,e.issues)),t.value[n]=e.value}function El(e,t,n,r,o){for(let i=0;i<n.length;i++){const n=e[i],s=i<r.length;if(n.issues.length){if(!s&&i>=o){t.value.length=i;break}t.issues.push(...lc(i,n.issues))}t.value[i]=n.value}for(let e=t.value.length-1;e>=r.length&&("optional"===n[e]._zod.optout&&void 0===t.value[e]);e--)t.value.length=e;return t}const _l=Fa("$ZodRecord",(e,t)=>{Iu.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!tc(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const i=[],s=t.keyType._zod.values;if(s){n.value={};const a=new Set;for(const c of s)if("string"==typeof c||"number"==typeof c||"symbol"==typeof c){a.add("number"==typeof c?c.toString():c);const s=t.keyType._zod.run({value:c,issues:[]},r);if(s instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(s.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:s.issues.map(e=>dc(e,r,Da())),input:c,path:[c],inst:e});continue}const u=s.value,l=t.valueType._zod.run({value:o[c],issues:[]},r);l instanceof Promise?i.push(l.then(e=>{e.issues.length&&n.issues.push(...lc(c,e.issues)),n.value[u]=e.value})):(l.issues.length&&n.issues.push(...lc(c,l.issues)),n.value[u]=l.value)}let c;for(const e in o)a.has(e)||(c=c??[],c.push(e));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:c})}else{n.value={};for(const s of Reflect.ownKeys(o)){if("__proto__"===s)continue;if(!Object.prototype.propertyIsEnumerable.call(o,s))continue;let a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if("string"==typeof s&&ru.test(s)&&a.issues.length){const e=t.keyType._zod.run({value:Number(s),issues:[]},r);if(e instanceof Promise)throw new Error("Async schemas not supported in object keys currently");0===e.issues.length&&(a=e)}if(a.issues.length){"loose"===t.mode?n.value[s]=o[s]:n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(e=>dc(e,r,Da())),input:s,path:[s],inst:e});continue}const c=t.valueType._zod.run({value:o[s],issues:[]},r);c instanceof Promise?i.push(c.then(e=>{e.issues.length&&n.issues.push(...lc(s,e.issues)),n.value[a.value]=e.value})):(c.issues.length&&n.issues.push(...lc(s,c.issues)),n.value[a.value]=c.value)}}return i.length?Promise.all(i).then(()=>n):n}}),xl=Fa("$ZodEnum",(e,t)=>{Iu.init(e,t);const n=Za(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>rc.has(typeof e)).map(e=>"string"==typeof e?oc(e):e.toString()).join("|")})$`),e._zod.parse=(t,o)=>{const i=t.value;return r.has(i)||t.issues.push({code:"invalid_value",values:n,input:i,inst:e}),t}}),kl=Fa("$ZodLiteral",(e,t)=>{if(Iu.init(e,t),0===t.values.length)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(e=>"string"==typeof e?oc(e):e?oc(e.toString()):String(e)).join("|")})$`),e._zod.parse=(r,o)=>{const i=r.value;return n.has(i)||r.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),r}}),Al=Fa("$ZodTransform",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new La(e.constructor.name);const o=t.transform(n.value,n);if(r.async){return(o instanceof Promise?o:Promise.resolve(o)).then(e=>(n.value=e,n.fallback=!0,n))}if(o instanceof Promise)throw new Ca;return n.value=o,n.fallback=!0,n}});function Il(e,t){return void 0===t&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const $l=Fa("$ZodOptional",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Ka(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Ka(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ha(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=e.value,o=t.innerType._zod.run(e,n);return o instanceof Promise?o.then(e=>Il(e,r)):Il(o,r)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),Bl=Fa("$ZodExactOptional",(e,t)=>{$l.init(e,t),Ka(e._zod,"values",()=>t.innerType._zod.values),Ka(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),zl=Fa("$ZodNullable",(e,t)=>{Iu.init(e,t),Ka(e._zod,"optin",()=>t.innerType._zod.optin),Ka(e._zod,"optout",()=>t.innerType._zod.optout),Ka(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ha(e.source)}|null)$`):void 0}),Ka(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),Sl=Fa("$ZodDefault",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",Ka(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Ol(e,t)):Ol(r,t)}});function Ol(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Tl=Fa("$ZodPrefault",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",Ka(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Nl=Fa("$ZodNonOptional",(e,t)=>{Iu.init(e,t),Ka(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(t=>Rl(t,e)):Rl(o,e)}});function Rl(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Ul=Fa("$ZodCatch",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",Ka(e._zod,"optout",()=>t.innerType._zod.optout),Ka(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>dc(e,n,Da()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>dc(e,n,Da()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),Pl=Fa("$ZodPipe",(e,t)=>{Iu.init(e,t),Ka(e._zod,"values",()=>t.in._zod.values),Ka(e._zod,"optin",()=>t.in._zod.optin),Ka(e._zod,"optout",()=>t.out._zod.optout),Ka(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Fl(e,t.in,n)):Fl(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Fl(e,t.out,n)):Fl(r,t.out,n)}});function Fl(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const Cl=Fa("$ZodReadonly",(e,t)=>{Iu.init(e,t),Ka(e._zod,"propValues",()=>t.innerType._zod.propValues),Ka(e._zod,"values",()=>t.innerType._zod.values),Ka(e._zod,"optin",()=>t.innerType?._zod?.optin),Ka(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ll):Ll(r)}});function Ll(e){return e.value=Object.freeze(e.value),e}const Ml=Fa("$ZodFunction",(e,t)=>(Iu.init(e,t),e._def=t,e._zod.def=t,e.implement=t=>{if("function"!=typeof t)throw new Error("implement() must be called with a function");return function(...n){const r=e._def.input?bc(e._def.input,n):n,o=Reflect.apply(t,this,r);return e._def.output?bc(e._def.output,o):o}},e.implementAsync=t=>{if("function"!=typeof t)throw new Error("implementAsync() must be called with a function");return async function(...n){const r=e._def.input?await Ec(e._def.input,n):n,o=await Reflect.apply(t,this,r);return e._def.output?await Ec(e._def.output,o):o}},e._zod.parse=(t,n)=>{if("function"!=typeof t.value)return t.issues.push({code:"invalid_type",expected:"function",input:t.value,inst:e}),t;const r=e._def.output&&"promise"===e._def.output._zod.def.type;return t.value=r?e.implementAsync(t.value):e.implement(t.value),t},e.input=(...t)=>{const n=e.constructor;return Array.isArray(t[0])?new n({type:"function",input:new wl({type:"tuple",items:t[0],rest:t[1]}),output:e._def.output}):new n({type:"function",input:t[0],output:e._def.output})},e.output=t=>new(0,e.constructor)({type:"function",input:e._def.input,output:t}),e)),Dl=Fa("$ZodCustom",(e,t)=>{au.init(e,t),Iu.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(t=>Zl(t,n,r,e));Zl(o,n,r,e)}});function Zl(e,t,n,r){if(!e){const 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(pc(e))}}var jl;class ql{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){const n=t[0];return this._map.set(e,n),n&&"object"==typeof n&&"id"in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const 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)}}(jl=globalThis).__zod_globalRegistry??(jl.__zod_globalRegistry=new ql);const Gl=globalThis.__zod_globalRegistry;function Hl(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...sc(t)})}function Vl(e,t){return new uu({check:"less_than",...sc(t),value:e,inclusive:!1})}function Kl(e,t){return new uu({check:"less_than",...sc(t),value:e,inclusive:!0})}function Wl(e,t){return new lu({check:"greater_than",...sc(t),value:e,inclusive:!1})}function Jl(e,t){return new lu({check:"greater_than",...sc(t),value:e,inclusive:!0})}function Xl(e,t){return new fu({check:"multiple_of",...sc(t),value:e})}function Yl(e,t){return new hu({check:"max_length",...sc(t),maximum:e})}function Ql(e,t){return new pu({check:"min_length",...sc(t),minimum:e})}function ef(e,t){return new mu({check:"length_equals",...sc(t),length:e})}function tf(e){return new xu({check:"overwrite",tx:e})}function nf(e,t){const n=function(e,t){const n=new au({check:"custom",...sc(t)});return n._zod.check=e,n}(t=>(t.addIssue=e=>{if("string"==typeof e)t.issues.push(pc(e,t.value,n._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=t.value),r.inst??(r.inst=n),r.continue??(r.continue=!n._zod.def.abort),t.issues.push(pc(r))}},e(t.value,t)),t);return n}function rf(e){let t=e?.target??"draft-2020-12";return"draft-4"===t&&(t="draft-04"),"draft-7"===t&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??Gl,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function of(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,i=t.seen.get(e);if(i){i.count++;return n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema}const s={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,s);const a=e._zod.toJSONSchema?.();if(a)s.schema=a;else{const r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,r);else{const n=s.schema,i=t.processors[o.type];if(!i)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);i(e,t,n,r)}const i=e._zod.parent;i&&(s.ref||(s.ref=i),of(i,t,r),t.seen.get(i).isParent=!0)}const c=t.metadataRegistry.get(e);c&&Object.assign(s.schema,c),"input"===t.io&&cf(e)&&(delete s.schema.examples,delete s.schema.default),"input"===t.io&&"_prefault"in s.schema&&((r=s.schema).default??(r.default=s.schema._prefault)),delete s.schema._prefault;return t.seen.get(e).schema}function sf(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const t of e.seen.entries()){const n=e.metadataRegistry.get(t[0])?.id;if(n){const e=r.get(n);if(e&&e!==t[0])throw new 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])}}const o=t=>{if(t[1].schema.$ref)return;const r=t[1],{ref:o,defId:i}=(t=>{const r="draft-2020-12"===e.target?"$defs":"definitions";if(e.external){const n=e.external.registry.get(t[0])?.id,o=e.external.uri??(e=>e);if(n)return{ref:o(n)};const i=t[1].defId??t[1].schema.id??"schema"+e.counter++;return t[1].defId=i,{defId:i,ref:`${o("__shared")}#/${r}/${i}`}}if(t[1]===n)return{ref:"#"};const o=`#/${r}/`,i=t[1].schema.id??"__schema"+e.counter++;return{defId:i,ref:o+i}})(t);r.def={...r.schema},i&&(r.defId=i);const s=r.schema;for(const e in s)delete s[e];s.$ref=o};if("throw"===e.cycles)for(const t of e.seen.entries()){const e=t[1];if(e.cycle)throw new Error(`Cycle detected: #/${e.cycle?.join("/")}/<root>\n\nSet the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const n of e.seen.entries()){const r=n[1];if(t===n[0]){o(n);continue}if(e.external){const r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){o(n);continue}}const i=e.metadataRegistry.get(n[0])?.id;i?o(n):(r.cycle||r.count>1&&"ref"===e.reused)&&o(n)}}function af(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=t=>{const n=e.seen.get(t);if(null===n.ref)return;const o=n.def??n.schema,i={...o},s=n.ref;if(n.ref=null,s){r(s);const n=e.seen.get(s),a=n.schema;!a.$ref||"draft-07"!==e.target&&"draft-04"!==e.target&&"openapi-3.0"!==e.target?Object.assign(o,a):(o.allOf=o.allOf??[],o.allOf.push(a)),Object.assign(o,i);if(t._zod.parent===s)for(const e in o)"$ref"!==e&&"allOf"!==e&&(e in i||delete o[e]);if(a.$ref&&n.def)for(const e in o)"$ref"!==e&&"allOf"!==e&&e in n.def&&JSON.stringify(o[e])===JSON.stringify(n.def[e])&&delete o[e]}const a=t._zod.parent;if(a&&a!==s){r(a);const t=e.seen.get(a);if(t?.schema.$ref&&(o.$ref=t.schema.$ref,t.def))for(const e in o)"$ref"!==e&&"allOf"!==e&&e in t.def&&JSON.stringify(o[e])===JSON.stringify(t.def[e])&&delete o[e]}e.override({zodSchema:t,jsonSchema:o,path:n.path??[]})};for(const t of[...e.seen.entries()].reverse())r(t[0]);const o={};if("draft-2020-12"===e.target?o.$schema="https://json-schema.org/draft/2020-12/schema":"draft-07"===e.target?o.$schema="http://json-schema.org/draft-07/schema#":"draft-04"===e.target?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const n=e.external.registry.get(t)?.id;if(!n)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(n)}Object.assign(o,n.def??n.schema);const i=e.metadataRegistry.get(t)?.id;void 0!==i&&o.id===i&&delete o.id;const s=e.external?.defs??{};for(const t of e.seen.entries()){const e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,s[e.defId]=e.def)}e.external||Object.keys(s).length>0&&("draft-2020-12"===e.target?o.$defs=s:o.definitions=s);try{const n=JSON.parse(JSON.stringify(o));return Object.defineProperty(n,"~standard",{value:{...t["~standard"],jsonSchema:{input:uf(t,"input",e.processors),output:uf(t,"output",e.processors)}},enumerable:!1,writable:!1}),n}catch(e){throw new Error("Error converting schema to JSON.")}}function cf(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if("transform"===r.type)return!0;if("array"===r.type)return cf(r.element,n);if("set"===r.type)return cf(r.valueType,n);if("lazy"===r.type)return cf(r.getter(),n);if("promise"===r.type||"optional"===r.type||"nonoptional"===r.type||"nullable"===r.type||"readonly"===r.type||"default"===r.type||"prefault"===r.type)return cf(r.innerType,n);if("intersection"===r.type)return cf(r.left,n)||cf(r.right,n);if("record"===r.type||"map"===r.type)return cf(r.keyType,n)||cf(r.valueType,n);if("pipe"===r.type)return!!e._zod.traits.has("$ZodCodec")||(cf(r.in,n)||cf(r.out,n));if("object"===r.type){for(const e in r.shape)if(cf(r.shape[e],n))return!0;return!1}if("union"===r.type){for(const e of r.options)if(cf(e,n))return!0;return!1}if("tuple"===r.type){for(const e of r.items)if(cf(e,n))return!0;return!(!r.rest||!cf(r.rest,n))}return!1}const uf=(e,t,n={})=>r=>{const{libraryOptions:o,target:i}=r??{},s=rf({...o??{},target:i,io:t,processors:n});return of(e,s),sf(s,e),af(s,e)},lf={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},ff=(e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r);t.seen.get(e).ref=o.innerType},df=Fa("ZodISODateTime",(e,t)=>{Mu.init(e,t),Mf.init(e,t)});function hf(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...sc(t)})}(df,e)}const pf=Fa("ZodISODate",(e,t)=>{Du.init(e,t),Mf.init(e,t)});function mf(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...sc(t)})}(pf,e)}const gf=Fa("ZodISOTime",(e,t)=>{Zu.init(e,t),Mf.init(e,t)});function yf(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...sc(t)})}(gf,e)}const wf=Fa("ZodISODuration",(e,t)=>{ju.init(e,t),Mf.init(e,t)});function bf(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...sc(t)})}(wf,e)}const vf=(e,t)=>{gc.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=(e,o=[])=>{for(const i of e.issues)if("invalid_union"===i.code&&i.errors.length)i.errors.map(e=>r({issues:e},[...o,...i.path]));else if("invalid_key"===i.code)r({issues:i.issues},[...o,...i.path]);else if("invalid_element"===i.code)r({issues:i.issues},[...o,...i.path]);else{const e=[...o,...i.path];if(0===e.length)n._errors.push(t(i));else{let r=n,o=0;for(;o<e.length;){const n=e[o];o===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(i))):r[n]=r[n]||{_errors:[]},r=r[n],o++}}}};return r(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ja,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ja,2)}},isEmpty:{get:()=>0===e.issues.length}})},Ef=Fa("ZodError",vf,{Parent:Error}),_f=wc(Ef),xf=vc(Ef),kf=_c(Ef),Af=kc(Ef),If=Ic(Ef),$f=$c(Ef),Bf=Bc(Ef),zf=zc(Ef),Sf=Sc(Ef),Of=Oc(Ef),Tf=Tc(Ef),Nf=Nc(Ef),Rf=new WeakMap;function Uf(e,t,n){const r=Object.getPrototypeOf(e);let o=Rf.get(r);if(o||(o=new Set,Rf.set(r,o)),!o.has(t)){o.add(t);for(const e in n){const t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){const n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}const Pf=Fa("ZodType",(e,t)=>(Iu.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:uf(e,"input"),output:uf(e,"output")}}),e.toJSONSchema=((e,t={})=>n=>{const r=rf({...n,processors:t});return of(e,r),sf(r,e),af(r,e)})(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>_f(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>kf(e,t,n),e.parseAsync=async(t,n)=>xf(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Af(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>If(e,t,n),e.decode=(t,n)=>$f(e,t,n),e.encodeAsync=async(t,n)=>Bf(e,t,n),e.decodeAsync=async(t,n)=>zf(e,t,n),e.safeEncode=(t,n)=>Sf(e,t,n),e.safeDecode=(t,n)=>Of(e,t,n),e.safeEncodeAsync=async(t,n)=>Tf(e,t,n),e.safeDecodeAsync=async(t,n)=>Nf(e,t,n),Uf(e,"ZodType",{check(...e){const t=this.def;return this.clone(Ja(t,{checks:[...t.checks??[],...e.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ic(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...sc(n)})}(Vd,e,t)}(e,t))},superRefine(e,t){return this.check(function(e,t){return nf(e,t)}(e,t))},overwrite(e){return this.check(tf(e))},optional(){return Ud(this)},exactOptional(){return new Pd({type:"optional",innerType:this})},nullable(){return Cd(this)},nullish(){return Ud(Cd(this))},nonoptional(e){return function(e,t){return new Dd({type:"nonoptional",innerType:e,...sc(t)})}(this,e)},array(){return Ed(this)},or(e){return new kd({type:"union",options:[this,e],...sc(t)});var t},and(e){return new Ad({type:"intersection",left:this,right:e})},transform(e){return qd(this,new Nd({type:"transform",transform:e}))},default(e){return t=e,new Ld({type:"default",innerType:this,get defaultValue(){return"function"==typeof t?t():nc(t)}});var t},prefault(e){return t=e,new Md({type:"prefault",innerType:this,get defaultValue(){return"function"==typeof t?t():nc(t)}});var t},catch(e){return new Zd({type:"catch",innerType:this,catchValue:"function"==typeof(t=e)?t:()=>t});var t},pipe(e){return qd(this,e)},readonly(){return new Gd({type:"readonly",innerType:this})},describe(e){const t=this.clone();return Gl.add(t,{description:e}),t},meta(...e){if(0===e.length)return Gl.get(this);const t=this.clone();return Gl.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get:()=>Gl.get(e)?.description,configurable:!0}),e)),Ff=Fa("_ZodString",(e,t)=>{$u.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n;r.type="string";const{minimum:o,maximum:i,format:s,patterns:a,contentEncoding:c}=e._zod.bag;if("number"==typeof o&&(r.minLength=o),"number"==typeof i&&(r.maxLength=i),s&&(r.format=lf[s]??s,""===r.format&&delete r.format,"time"===s&&delete r.format),c&&(r.contentEncoding=c),a&&a.size>0){const e=[...a];1===e.length?r.pattern=e[0].source:e.length>1&&(r.allOf=[...e.map(e=>({..."draft-07"===t.target||"draft-04"===t.target||"openapi-3.0"===t.target?{type:"string"}:{},pattern:e.source}))])}})(e,t,n);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Uf(e,"_ZodString",{regex(...e){return this.check(function(e,t){return new yu({check:"string_format",format:"regex",...sc(t),pattern:e})}(...e))},includes(...e){return this.check(function(e,t){return new vu({check:"string_format",format:"includes",...sc(t),includes:e})}(...e))},startsWith(...e){return this.check(function(e,t){return new Eu({check:"string_format",format:"starts_with",...sc(t),prefix:e})}(...e))},endsWith(...e){return this.check(function(e,t){return new _u({check:"string_format",format:"ends_with",...sc(t),suffix:e})}(...e))},min(...e){return this.check(Ql(...e))},max(...e){return this.check(Yl(...e))},length(...e){return this.check(ef(...e))},nonempty(...e){return this.check(Ql(1,...e))},lowercase(e){return this.check(function(e){return new wu({check:"string_format",format:"lowercase",...sc(e)})}(e))},uppercase(e){return this.check(function(e){return new bu({check:"string_format",format:"uppercase",...sc(e)})}(e))},trim(){return this.check(tf(e=>e.trim()))},normalize(...e){return this.check(function(e){return tf(t=>t.normalize(e))}(...e))},toLowerCase(){return this.check(tf(e=>e.toLowerCase()))},toUpperCase(){return this.check(tf(e=>e.toUpperCase()))},slugify(){return this.check(tf(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e)))}})}),Cf=Fa("ZodString",(e,t)=>{$u.init(e,t),Ff.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...sc(t)})}(Df,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...sc(t)})}(qf,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...sc(t)})}(id,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...sc(t)})}(Gf,t)),e.guid=t=>e.check(Hl(Zf,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...sc(t)})}(jf,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...sc(t)})}(jf,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...sc(t)})}(jf,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...sc(t)})}(jf,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...sc(t)})}(Hf,t)),e.guid=t=>e.check(Hl(Zf,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...sc(t)})}(Vf,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...sc(t)})}(Kf,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...sc(t)})}(Wf,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...sc(t)})}(nd,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...sc(t)})}(rd,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...sc(t)})}(Jf,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...sc(t)})}(Xf,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...sc(t)})}(Yf,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...sc(t)})}(Qf,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...sc(t)})}(ed,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...sc(t)})}(td,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...sc(t)})}(od,t)),e.datetime=t=>e.check(hf(t)),e.date=t=>e.check(mf(t)),e.time=t=>e.check(yf(t)),e.duration=t=>e.check(bf(t))});function Lf(e){return function(e,t){return new e({type:"string",...sc(t)})}(Cf,e)}const Mf=Fa("ZodStringFormat",(e,t)=>{Bu.init(e,t),Ff.init(e,t)}),Df=Fa("ZodEmail",(e,t)=>{Ou.init(e,t),Mf.init(e,t)}),Zf=Fa("ZodGUID",(e,t)=>{zu.init(e,t),Mf.init(e,t)}),jf=Fa("ZodUUID",(e,t)=>{Su.init(e,t),Mf.init(e,t)}),qf=Fa("ZodURL",(e,t)=>{Tu.init(e,t),Mf.init(e,t)}),Gf=Fa("ZodEmoji",(e,t)=>{Nu.init(e,t),Mf.init(e,t)}),Hf=Fa("ZodNanoID",(e,t)=>{Ru.init(e,t),Mf.init(e,t)}),Vf=Fa("ZodCUID",(e,t)=>{Uu.init(e,t),Mf.init(e,t)}),Kf=Fa("ZodCUID2",(e,t)=>{Pu.init(e,t),Mf.init(e,t)}),Wf=Fa("ZodULID",(e,t)=>{Fu.init(e,t),Mf.init(e,t)}),Jf=Fa("ZodXID",(e,t)=>{Cu.init(e,t),Mf.init(e,t)}),Xf=Fa("ZodKSUID",(e,t)=>{Lu.init(e,t),Mf.init(e,t)}),Yf=Fa("ZodIPv4",(e,t)=>{qu.init(e,t),Mf.init(e,t)}),Qf=Fa("ZodIPv6",(e,t)=>{Gu.init(e,t),Mf.init(e,t)}),ed=Fa("ZodCIDRv4",(e,t)=>{Hu.init(e,t),Mf.init(e,t)}),td=Fa("ZodCIDRv6",(e,t)=>{Vu.init(e,t),Mf.init(e,t)}),nd=Fa("ZodBase64",(e,t)=>{Wu.init(e,t),Mf.init(e,t)}),rd=Fa("ZodBase64URL",(e,t)=>{Ju.init(e,t),Mf.init(e,t)}),od=Fa("ZodE164",(e,t)=>{Xu.init(e,t),Mf.init(e,t)}),id=Fa("ZodJWT",(e,t)=>{Yu.init(e,t),Mf.init(e,t)}),sd=Fa("ZodNumber",(e,t)=>{Qu.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n,{minimum:o,maximum:i,format:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u}=e._zod.bag;"string"==typeof s&&s.includes("int")?r.type="integer":r.type="number";const l="number"==typeof u&&u>=(o??Number.NEGATIVE_INFINITY),f="number"==typeof c&&c<=(i??Number.POSITIVE_INFINITY),d="draft-04"===t.target||"openapi-3.0"===t.target;l?d?(r.minimum=u,r.exclusiveMinimum=!0):r.exclusiveMinimum=u:"number"==typeof o&&(r.minimum=o),f?d?(r.maximum=c,r.exclusiveMaximum=!0):r.exclusiveMaximum=c:"number"==typeof i&&(r.maximum=i),"number"==typeof a&&(r.multipleOf=a)})(e,t,n),Uf(e,"ZodNumber",{gt(e,t){return this.check(Wl(e,t))},gte(e,t){return this.check(Jl(e,t))},min(e,t){return this.check(Jl(e,t))},lt(e,t){return this.check(Vl(e,t))},lte(e,t){return this.check(Kl(e,t))},max(e,t){return this.check(Kl(e,t))},int(e){return this.check(ud(e))},safe(e){return this.check(ud(e))},positive(e){return this.check(Wl(0,e))},nonnegative(e){return this.check(Jl(0,e))},negative(e){return this.check(Vl(0,e))},nonpositive(e){return this.check(Kl(0,e))},multipleOf(e,t){return this.check(Xl(e,t))},step(e,t){return this.check(Xl(e,t))},finite(){return this}});const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function ad(e){return function(e,t){return new e({type:"number",checks:[],...sc(t)})}(sd,e)}const cd=Fa("ZodNumberFormat",(e,t)=>{el.init(e,t),sd.init(e,t)});function ud(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...sc(t)})}(cd,e)}const ld=Fa("ZodBoolean",(e,t)=>{tl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.type="boolean"})(0,0,t)});function fd(e){return function(e,t){return new e({type:"boolean",...sc(t)})}(ld,e)}const dd=Fa("ZodBigInt",(e,t)=>{nl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("BigInt cannot be represented in JSON Schema")})(0,e),e.gte=(t,n)=>e.check(Jl(t,n)),e.min=(t,n)=>e.check(Jl(t,n)),e.gt=(t,n)=>e.check(Wl(t,n)),e.gte=(t,n)=>e.check(Jl(t,n)),e.min=(t,n)=>e.check(Jl(t,n)),e.lt=(t,n)=>e.check(Vl(t,n)),e.lte=(t,n)=>e.check(Kl(t,n)),e.max=(t,n)=>e.check(Kl(t,n)),e.positive=t=>e.check(Wl(BigInt(0),t)),e.negative=t=>e.check(Vl(BigInt(0),t)),e.nonpositive=t=>e.check(Kl(BigInt(0),t)),e.nonnegative=t=>e.check(Jl(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Xl(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});function hd(e){return function(e,t){return new e({type:"bigint",...sc(t)})}(dd,e)}const pd=Fa("ZodAny",(e,t)=>{rl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function md(){return new pd({type:"any"})}const gd=Fa("ZodUnknown",(e,t)=>{ol.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function yd(){return new gd({type:"unknown"})}const wd=Fa("ZodNever",(e,t)=>{il.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.not={}})(0,0,t)});function bd(e){return function(e,t){return new e({type:"never",...sc(t)})}(wd,e)}const vd=Fa("ZodArray",(e,t)=>{al.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def,{minimum:s,maximum:a}=e._zod.bag;"number"==typeof s&&(o.minItems=s),"number"==typeof a&&(o.maxItems=a),o.type="array",o.items=of(i.element,t,{...r,path:[...r.path,"items"]})})(e,t,n,r),e.element=t.element,Uf(e,"ZodArray",{min(e,t){return this.check(Ql(e,t))},nonempty(e){return this.check(Ql(1,e))},max(e,t){return this.check(Yl(e,t))},length(e,t){return this.check(ef(e,t))},unwrap(){return this.element}})});function Ed(e,t){return function(e,t,n){return new e({type:"array",element:t,...sc(n)})}(vd,e,t)}const _d=Fa("ZodObject",(e,t)=>{dl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object",o.properties={};const s=i.shape;for(const e in s)o.properties[e]=of(s[e],t,{...r,path:[...r.path,"properties",e]});const a=new Set(Object.keys(s)),c=new Set([...a].filter(e=>{const n=i.shape[e]._zod;return"input"===t.io?void 0===n.optin:void 0===n.optout}));c.size>0&&(o.required=Array.from(c)),"never"===i.catchall?._zod.def.type?o.additionalProperties=!1:i.catchall?i.catchall&&(o.additionalProperties=of(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):"output"===t.io&&(o.additionalProperties=!1)})(e,t,n,r),Ka(e,"shape",()=>t.shape),Uf(e,"ZodObject",{keyof(){return Od(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:yd()})},loose(){return this.clone({...this._zod.def,catchall:yd()})},strict(){return this.clone({...this._zod.def,catchall:bd()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return function(e,t){if(!tc(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const n=e._zod.def.shape;for(const e in t)if(void 0!==Object.getOwnPropertyDescriptor(n,e))throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Ja(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Wa(this,"shape",n),n}});return ic(e,r)}(this,e)},safeExtend(e){return function(e,t){if(!tc(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Ja(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Wa(this,"shape",n),n}});return ic(e,n)}(this,e)},merge(e){return function(e,t){if(e._zod.def.checks?.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");const n=Ja(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return Wa(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return ic(e,n)}(this,e)},pick(e){return function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return ic(e,Ja(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return Wa(this,"shape",e),e},checks:[]}))}(this,e)},omit(e){return function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const o=Ja(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return Wa(this,"shape",r),r},checks:[]});return ic(e,o)}(this,e)},partial(...e){return function(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Ja(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)o[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return Wa(this,"shape",o),o},checks:[]});return ic(t,o)}(Rd,this,e[0])},required(...e){return function(e,t,n){const r=Ja(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in o))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)o[t]=new e({type:"nonoptional",innerType:r[t]});return Wa(this,"shape",o),o}});return ic(t,r)}(Dd,this,e[0])}})});function xd(e,t){const n={type:"object",shape:e??{},...sc(t)};return new _d(n)}const kd=Fa("ZodUnion",(e,t)=>{pl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=!1===o.inclusive,s=o.options.map((e,n)=>of(e,t,{...r,path:[...r.path,i?"oneOf":"anyOf",n]}));i?n.oneOf=s:n.anyOf=s})(e,t,n,r),e.options=t.options});const Ad=Fa("ZodIntersection",(e,t)=>{ml.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=of(o.left,t,{...r,path:[...r.path,"allOf",0]}),s=of(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=e=>"allOf"in e&&1===Object.keys(e).length,c=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];n.allOf=c})(e,t,n,r)});const Id=Fa("ZodTuple",(e,t)=>{wl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="array";const s="draft-2020-12"===t.target?"prefixItems":"items",a="draft-2020-12"===t.target||"openapi-3.0"===t.target?"items":"additionalItems",c=i.items.map((e,n)=>of(e,t,{...r,path:[...r.path,s,n]})),u=i.rest?of(i.rest,t,{...r,path:[...r.path,a,..."openapi-3.0"===t.target?[i.items.length]:[]]}):null;"draft-2020-12"===t.target?(o.prefixItems=c,u&&(o.items=u)):"openapi-3.0"===t.target?(o.items={anyOf:c},u&&o.items.anyOf.push(u),o.minItems=c.length,u||(o.maxItems=c.length)):(o.items=c,u&&(o.additionalItems=u));const{minimum:l,maximum:f}=e._zod.bag;"number"==typeof l&&(o.minItems=l),"number"==typeof f&&(o.maxItems=f)})(e,t,n,r),e.rest=t=>e.clone({...e._zod.def,rest:t})});function $d(e,t,n){const r=t instanceof Iu;return new Id({type:"tuple",items:e,rest:r?t:null,...sc(r?n:t)})}const Bd=Fa("ZodRecord",(e,t)=>{_l.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object";const s=i.keyType,a=s._zod.bag,c=a?.patterns;if("loose"===i.mode&&c&&c.size>0){const e=of(i.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});o.patternProperties={};for(const t of c)o.patternProperties[t.source]=e}else"draft-07"!==t.target&&"draft-2020-12"!==t.target||(o.propertyNames=of(i.keyType,t,{...r,path:[...r.path,"propertyNames"]})),o.additionalProperties=of(i.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const u=s._zod.values;if(u){const e=[...u].filter(e=>"string"==typeof e||"number"==typeof e);e.length>0&&(o.required=e)}})(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function zd(e,t,n){return t&&t._zod?new Bd({type:"record",keyType:e,valueType:t,...sc(n)}):new Bd({type:"record",keyType:Lf(),valueType:e,...sc(t)})}const Sd=Fa("ZodEnum",(e,t)=>{xl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=Za(e._zod.def.entries);r.every(e=>"number"==typeof e)&&(n.type="number"),r.every(e=>"string"==typeof e)&&(n.type="string"),n.enum=r})(e,0,n),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const o={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);o[r]=t.entries[r]}return new Sd({...t,checks:[],...sc(r),entries:o})},e.exclude=(e,r)=>{const o={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete o[t]}return new Sd({...t,checks:[],...sc(r),entries:o})}});function Od(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Sd({type:"enum",entries:n,...sc(t)})}const Td=Fa("ZodLiteral",(e,t)=>{kl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=e._zod.def,o=[];for(const e of r.values)if(void 0===e){if("throw"===t.unrepresentable)throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if("bigint"==typeof e){if("throw"===t.unrepresentable)throw new Error("BigInt literals cannot be represented in JSON Schema");o.push(Number(e))}else o.push(e);if(0===o.length);else if(1===o.length){const e=o[0];n.type=null===e?"null":typeof e,"draft-04"===t.target||"openapi-3.0"===t.target?n.enum=[e]:n.const=e}else o.every(e=>"number"==typeof e)&&(n.type="number"),o.every(e=>"string"==typeof e)&&(n.type="string"),o.every(e=>"boolean"==typeof e)&&(n.type="boolean"),o.every(e=>null===e)&&(n.type="null"),n.enum=o})(e,t,n),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});const Nd=Fa("ZodTransform",(e,t)=>{Al.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Transforms cannot be represented in JSON Schema")})(0,e),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new La(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(pc(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push(pc(t))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=o,n.fallback=!0,n)}});const Rd=Fa("ZodOptional",(e,t)=>{$l.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ff(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});function Ud(e){return new Rd({type:"optional",innerType:e})}const Pd=Fa("ZodExactOptional",(e,t)=>{Bl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ff(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const Fd=Fa("ZodNullable",(e,t)=>{zl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=of(o.innerType,t,r),s=t.seen.get(e);"openapi-3.0"===t.target?(s.ref=o.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cd(e){return new Fd({type:"nullable",innerType:e})}const Ld=Fa("ZodDefault",(e,t)=>{Sl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const Md=Fa("ZodPrefault",(e,t)=>{Tl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType,"input"===t.io&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const Dd=Fa("ZodNonOptional",(e,t)=>{Nl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType})(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const Zd=Fa("ZodCatch",(e,t)=>{Ul.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;let i;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType;try{i=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=i})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const jd=Fa("ZodPipe",(e,t)=>{Pl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=o.in._zod.traits.has("$ZodTransform"),s="input"===t.io?i?o.out:o.in:o.out;of(s,t,r),t.seen.get(e).ref=s})(e,t,0,r),e.in=t.in,e.out=t.out});function qd(e,t){return new jd({type:"pipe",in:e,out:t})}const Gd=Fa("ZodReadonly",(e,t)=>{Cl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.readOnly=!0})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const Hd=Fa("ZodFunction",(e,t)=>{Ml.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Function types cannot be represented in JSON Schema")})(0,e)});const Vd=Fa("ZodCustom",(e,t)=>{Dl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Custom types cannot be represented in JSON Schema")})(0,e)});function Kd(e){return function(e,t){return new e({type:"number",coerce:!0,checks:[],...sc(t)})}(sd,e)}const Wd=xd({issuer:Lf().transform(e=>ls(e)),index:Lf().transform(e=>ls(e)),timestamp:Lf().transform(e=>ls(e)),signature:Lf().transform(e=>ls(e))});var Jd,Xd,Yd,Qd,eh,th={exports:{}};function nh(){if(Xd)return Jd;Xd=1;var e=1e3,t=60*e,n=60*t,r=24*n,o=7*r,i=365.25*r;function s(e,t,n,r){var o=t>=1.5*n;return Math.round(e/n)+" "+r+(o?"s":"")}return Jd=function(a,c){c=c||{};var u=typeof a;if("string"===u&&a.length>0)return function(s){if((s=String(s)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*o;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===u&&isFinite(a))return c.long?function(o){var i=Math.abs(o);if(i>=r)return s(o,i,r,"day");if(i>=n)return s(o,i,n,"hour");if(i>=t)return s(o,i,t,"minute");if(i>=e)return s(o,i,e,"second");return o+" ms"}(a):function(o){var i=Math.abs(o);if(i>=r)return Math.round(o/r)+"d";if(i>=n)return Math.round(o/n)+"h";if(i>=t)return Math.round(o/t)+"m";if(i>=e)return Math.round(o/e)+"s";return o+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var rh=(eh||(eh=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))}),t.splice(o,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=(Qd||(Qd=1,Yd=function(e){function t(e){let r,o,i,s=null;function a(...e){if(!a.enabled)return;const n=a,o=Number(new Date),i=o-(r||o);n.diff=i,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,o)=>{if("%%"===r)return"%";s++;const i=t.formatters[o];if("function"==typeof i){const t=e[s];r=i.call(n,t),e.splice(s,1),s--}return r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(o!==t.namespaces&&(o=t.namespaces,i=t.enabled(e)),i),set:e=>{s=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e,t){let n=0,r=0,o=-1,i=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(o=r,i=n,r++):(n++,r++);else{if(-1===o)return!1;r=o+1,i++,n=i}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=nh(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}),Yd)(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(th,th.exports)),th.exports);const oh=Vr(rh)("bee-js:http"),ih={headers:{accept:"application/json, text/plain, */*"}};async function sh(e,t){const n=t.data,r=Jr.Objects.deepMerge3(ih,{...t,data:void 0},e);if(r.data=n,e.signal&&(r.signal=e.signal),function(e){if(void 0===e.data)return;const t=e.data;if(null!==t&&"object"==typeof t&&t.constructor===Object||Array.isArray(t))e.body=JSON.stringify(t),e.headers={"content-type":"application/json",...e.headers};else{e.body=t,e.duplex="half";const n=t instanceof Blob&&t.type?t.type:"application/octet-stream";e.headers={"content-type":n,...e.headers}}}(r),r.params)for(const e of Object.keys(r.params))void 0===r.params[e]&&delete r.params[e];const o=function(e){let t=Jr.Strings.joinUrl([e.baseURL??"",e.url??""]);if(e.params){const n=new URLSearchParams(Object.entries(e.params).filter(([,e])=>void 0!==e).map(([e,t])=>[e,String(t)])).toString();n&&(t+=`?${n}`)}return t}(r),i=(r.method||"GET").toUpperCase();r.method=i,e.onRequest?.({method:i,url:Jr.Strings.joinUrl([r.baseURL??"",r.url??""]),headers:{...r.headers},params:r.params});let s=0;for(;s<1e5;)try{oh(`${i} ${o}`,{headers:r.headers,params:r.params});const e=await fetch(o,r);return e.ok||await ah(i,o,e,r.responseType),uh(e,r.responseType)}catch(t){if(t instanceof ph)throw t;const n=t;if("TimeoutError"!==n.name||!e.endlesslyRetry)throw ch(n,i,o);s++,await Jr.System.sleepMillis(s<300?200:1e3)}throw Error("Max number of failed attempts reached")}async function ah(e,t,n,r){const o=await uh(n,r).catch(()=>({data:void 0})),i="string"==typeof o.data?o.data:JSON.stringify(o.data),s=i&&"undefined"!==i?`${n.statusText}: ${i}`:n.statusText;throw new ph(e,t,s,o.data,n.status,n.statusText)}function ch(e,t,n){if("AbortError"===e.name)return new ph(t,n,"Request aborted",void 0,void 0,"ERR_CANCELED");const r=e.cause,o=r?.message?`${e.message}: ${r.message}`:e.message;return new ph(t,n,o)}async function uh(e,t="json"){let n;switch(t){case"arraybuffer":n=await e.arrayBuffer();break;case"text":n=await e.text();break;case"blob":n=await e.blob();break;case"stream":n=e.body;break;default:{const t=await e.text();n=t?JSON.parse(t):null}}return{data:n,status:e.status,statusText:e.statusText,headers:Object.fromEntries(e.headers.entries()),raw:e}}const lh=xd({durationSeconds:ad()}),fh=xd({reference:Lf().transform(e=>new Vs(e))});class dh extends Error{constructor(e){super(e)}}class hh extends dh{constructor(e,t){super(e),this.value=t}}class ph extends dh{constructor(e,t,n,r,o,i){super(n),this.method=e,this.url=t,this.responseBody=r,this.status=o,this.statusText=i,this.response={status:o,data:r,statusText:i}}}class mh{constructor(e){this.seconds=Math.ceil(e),e<0&&(this.seconds=0)}static fromMilliseconds(e){return new mh(e/1e3)}static fromSeconds(e){return new mh(e)}static fromHours(e){return new mh(60*e*60)}static fromDays(e){return new mh(24*e*60*60)}static fromWeeks(e){return new mh(7*e*24*60*60)}static fromYears(e){return new mh(365*e*24*60*60)}static fromEndDate(e,t){return new mh((e.getTime()-(t??new Date).getTime())/1e3)}static parseFromString(e){return mh.fromSeconds(Jr.Dates.make(e)/1e3)}toSeconds(){return this.seconds}toHours(){return this.seconds/60/60}toDays(){return this.seconds/24/60/60}toWeeks(){return this.seconds/7/24/60/60}toYears(){return this.seconds/365/24/60/60}toEndDate(e){return new Date((e??new Date).getTime()+1e3*this.seconds)}represent(){return Jr.Dates.secondsToHumanTime(this.seconds)}isZero(){return 0===this.seconds}}mh.ZERO=new mh(0);class gh{constructor(e){this.state=e}static fromDecimalString(e){return new gh(Jr.FixedPointNumber.fromDecimalString(e,gh.DIGITS))}static fromPLUR(e){return new gh(new Jr.FixedPointNumber(e,gh.DIGITS))}static fromFloat(e){return new gh(Jr.FixedPointNumber.fromFloat(e,gh.DIGITS))}toPLURString(){return this.state.toString()}toPLURBigInt(){return this.state.value}toDecimalString(){return this.state.toDecimalString()}toFloat(){return this.state.toFloat()}toSignificantDigits(e){return this.toDecimalString().slice(0,this.toDecimalString().indexOf(".")+e+1)}plus(e){return new gh(this.state.add(e instanceof gh?e.state:new Jr.FixedPointNumber(e,gh.DIGITS)))}minus(e){return new gh(this.state.subtract(e instanceof gh?e.state:new Jr.FixedPointNumber(e,gh.DIGITS)))}divide(e){return new gh(this.state.divmod(e)[0])}gt(e){return 1===this.state.compare(e.state)}gte(e){return-1!==this.state.compare(e.state)}lt(e){return-1===this.state.compare(e.state)}lte(e){return 1!==this.state.compare(e.state)}eq(e){return 0===this.state.compare(e.state)}exchangeToDAI(e){return yh.fromWei(this.state.exchange("*",new Jr.FixedPointNumber(e.toWeiBigInt(),yh.DIGITS),yh.DIGITS).value)}}gh.DIGITS=16;class yh{constructor(e){this.state=e}static fromDecimalString(e){return new yh(Jr.FixedPointNumber.fromDecimalString(e,yh.DIGITS))}static fromWei(e){return new yh(new Jr.FixedPointNumber(e,yh.DIGITS))}static fromFloat(e){return new yh(Jr.FixedPointNumber.fromFloat(e,yh.DIGITS))}toWeiString(){return this.state.toString()}toWeiBigInt(){return this.state.value}toDecimalString(){return this.state.toDecimalString()}toSignificantDigits(e){return this.toDecimalString().slice(0,this.toDecimalString().indexOf(".")+e+1)}toFloat(){return this.state.toFloat()}plus(e){return new yh(this.state.add(e instanceof yh?e.state:new Jr.FixedPointNumber(e,yh.DIGITS)))}minus(e){return new yh(this.state.subtract(e instanceof yh?e.state:new Jr.FixedPointNumber(e,yh.DIGITS)))}divide(e){return new yh(this.state.divmod(e)[0])}gt(e){return 1===this.state.compare(e.state)}gte(e){return-1!==this.state.compare(e.state)}lt(e){return-1===this.state.compare(e.state)}lte(e){return 1!==this.state.compare(e.state)}eq(e){return 0===this.state.compare(e.state)}exchangeToBZZ(e){return gh.fromPLUR(this.state.exchange("/",new Jr.FixedPointNumber(e.toWeiBigInt(),yh.DIGITS),gh.DIGITS).value)}}function wh(e){if("function"==typeof File&&e instanceof File)return!0;const t=e;return"object"==typeof t&&"string"==typeof t.name&&("function"==typeof t.stream||"function"==typeof t.arrayBuffer)}async function bh(e){return e.arrayBuffer?e.arrayBuffer():new Promise(t=>{const n=new FileReader;n.onload=()=>t(n.result),n.readAsArrayBuffer(e)})}var vh;function Eh(e){switch(e){case"full":return vh.FULL;case"light":return vh.LIGHT;case"ultra-light":return vh.ULTRA_LIGHT;case"dev":return vh.DEV;default:throw new Error(`Unknown Bee mode: ${e}`)}}yh.DIGITS=18,function(e){e.FULL="full",e.LIGHT="light",e.ULTRA_LIGHT="ultra-light",e.DEV="dev"}(vh||(vh={}));const _h=4096,xh=17,kh=255;var Ah,Ih;!function(e){e[e.OFF=0]="OFF",e[e.MEDIUM=1]="MEDIUM",e[e.STRONG=2]="STRONG",e[e.INSANE=3]="INSANE",e[e.PARANOID=4]="PARANOID"}(Ah||(Ah={})),function(e){e[e.NONE=0]="NONE",e[e.DATA=1]="DATA",e[e.PROX=2]="PROX",e[e.RACE=3]="RACE"}(Ih||(Ih={})),Ah.OFF,Ah.MEDIUM,Ah.STRONG,Ah.INSANE,Ah.PARANOID,Ah.OFF,Ah.MEDIUM,Ah.STRONG,Ah.INSANE,Ah.PARANOID,Lf().regex(/^(?:0x)?[0-9a-fA-F]*$/i,"expected hex string").refine(e=>e.replace(/^0x/i,"").length%2==0,"expected even-length hex string");const $h=md().refine(e=>{return new Hd({type:"function",input:Array.isArray(t?.input)?$d(t?.input):Ed(yd()),output:yd()}).safeParse(e).success;var t},"expected a function"),Bh=md().transform(e=>(hd().safeParse(e).success&&(e=String(e)),Lf().regex(/^-?\d+$/,"expected integer string").parse(e))),zh=md().transform(e=>(hd().safeParse(e).success&&(e=String(e)),Lf().regex(/^\d+$/,"expected non-negative integer string").parse(e))),Sh=xd({baseURL:Lf().optional(),timeout:ad().int().min(0).optional(),headers:zd(Lf(),Lf()).optional(),onRequest:$h.optional(),httpAgent:yd().optional(),httpsAgent:yd().optional(),endlesslyRetry:fd().optional(),signal:md().optional()}),Oh=xd({redundancyStrategy:ad().int().optional(),fallback:fd().optional(),timeoutMs:ad().int().min(0).optional(),actPublisher:Ud(md().transform(e=>new Ds(e))),actHistoryAddress:Ud(md().transform(e=>new Vs(e))),actTimestamp:Kd().optional()}),Th=xd({act:fd().optional(),actHistoryAddress:Ud(md().transform(e=>new Vs(e))),deferred:fd().optional(),encrypt:fd().optional(),pin:fd().optional(),tag:ad().int().min(0).optional()}),Nh=Th.extend({redundancyLevel:ad().int().min(0).optional()}),Rh=Th.extend({size:ad().int().min(0).optional(),contentType:Lf().optional(),redundancyLevel:ad().int().min(0).optional()}),Uh=Th.extend({errorDocument:Lf().optional(),indexDocument:Lf().optional(),redundancyLevel:ad().int().min(0).optional()}),Ph=xd({uid:ad().int()}),Fh=Kd().min(0),Ch=xd({onMessage:$h,onError:$h,onClose:$h}),Lh=xd({onMessage:$h,onError:$h,onClose:$h}),Mh=xd({gasPrice:Bh.optional(),immutableFlag:fd().optional(),label:Lf().optional(),waitForUsable:fd().optional(),waitForUsableTimeout:ad().int().min(0).optional()}),Dh=xd({gasLimit:zh.optional(),gasPrice:zh.optional()}),Zh=xd({limit:ad().int().min(1).max(1e3).optional(),offset:ad().int().min(0).optional()});function jh(e,t){if("bigint"==typeof e&&(e=e.toString()),"string"!=typeof e||!/^-?\d+$/.test(e))throw new TypeError(`${t?.name??"value"} is not a valid integer string, got: ${e}`);if(void 0!==t?.min&&BigInt(e)<t.min)throw new RangeError(`${t?.name??"value"} must be >= ${t.min}, got: ${e}`);if(void 0!==t?.max&&BigInt(e)>t.max)throw new RangeError(`${t?.name??"value"} must be <= ${t.max}, got: ${e}`);return e}function qh(e){if("string"!=typeof e&&!(e instanceof Uint8Array)&&!(e instanceof Blob))throw new TypeError("Data must be either string, Uint8Array, Blob or Readable!")}function Gh(e){if("string"!=typeof e&&!(e instanceof Uint8Array)&&!wh(e))throw new TypeError("Data must be either string, Readable, Uint8Array or File!")}function Hh(e){if(null==e)throw new TypeError(`Expected number | Tag | string from tagUid, got: ${e}`);if(t=e,Ph.safeParse(t).success)return e.uid;if("number"==typeof e||"string"==typeof e)return Fh.parse(e);var t;throw new TypeError(`Expected number | Tag | string from tagUid, got: ${e}`)}function Vh(e){return Number.isInteger(e)?e<1?1:e>3155695200?3155695200:e:1}const Kh=xd({peer:Lf(),balance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"balance"})))}),Wh=xd({balances:Ed(Kh)}),Jh=Kh,Xh=xd({beneficiary:Lf().transform(e=>new Ns(e)),chequebook:Lf().transform(e=>new Ns(e)),payout:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"payout"})))}),Yh=xd({recipient:Lf(),lastPayout:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"lastPayout"}))),bounced:fd()}),Qh=xd({chequebookAddress:Lf().transform(e=>new Ns(e))}),ep=xd({availableBalance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"availableBalance"}))),totalBalance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"totalBalance"})))}),tp=xd({peer:Lf(),uncashedAmount:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"uncashedAmount"}))),transactionHash:Lf().nullish().transform(e=>e??null),lastCashedCheque:Xh.nullish().transform(e=>e??null),result:Yh.nullish().transform(e=>e??null)}),np=xd({peer:Lf(),lastreceived:Xh.nullish().transform(e=>e??null),lastsent:Xh.nullish().transform(e=>e??null)}),rp=xd({lastcheques:Ed(xd({peer:Lf(),lastreceived:Xh.nullish().transform(e=>e??null),lastsent:Xh.nullish().transform(e=>e??null)}))}),op=xd({transactionHash:Lf().transform(e=>new Xs(e))}),ip=xd({address:Lf(),fullNode:fd()}),sp=xd({population:ad(),connected:ad(),connectedPeers:Ed(xd({address:Lf()})).nullish().transform(e=>e??[]),disconnectedPeers:Ed(xd({address:Lf()})).nullish().transform(e=>e??[])}),ap=zd(Lf(),sp),cp=xd({overlay:Lf().transform(e=>new Cs(e)),underlay:Ed(Lf()),ethereum:Lf().transform(e=>new Ns(e)),publicKey:Lf().transform(e=>new Ds(e)),pssPublicKey:Lf().transform(e=>new Ds(e))}),up=xd({peers:Ed(ip)}),lp=xd({peers:Ed(ip)}),fp=xd({baseAddr:Lf(),population:ad(),connected:ad(),timestamp:Lf(),nnLowWatermark:ad(),depth:ad(),reachability:Lf(),networkAvailability:Lf(),bins:ap}),dp=xd({overlay:Lf(),proximity:ad(),beeMode:Lf().transform(Eh),reserveSize:ad(),reserveSizeWithinRadius:ad(),pullsyncRate:ad(),storageRadius:ad(),connectedPeers:ad(),neighborhoodSize:ad(),batchCommitment:ad(),isReachable:fd(),lastSyncedBlock:ad(),committedDepth:ad(),isWarmingUp:fd()}),hp=xd({apiVersion:Lf(),version:Lf(),status:(pp="ok",new Td({type:"literal",values:Array.isArray(pp)?pp:[pp],...sc(mp)}))});var pp,mp;const gp=xd({apiVersion:Lf(),version:Lf(),status:Od(["ready","notReady"])}),yp=xd({beeMode:Lf().transform(Eh),chequebookEnabled:fd(),swapEnabled:fd()}),wp=xd({gateway:fd()}),bp=xd({isRetrievable:fd()}),vp=Ed(Lf().transform(e=>new Ds(e))),Ep=xd({ref:Lf().transform(e=>new Vs(e)),historyref:Lf().transform(e=>new Vs(e))});var _p=null;"undefined"!=typeof WebSocket?_p=WebSocket:"undefined"!=typeof MozWebSocket?_p=MozWebSocket:"undefined"!=typeof global?_p=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?_p=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(_p=self.WebSocket||self.MozWebSocket);var xp=_p;const kp=xd({references:Ed(Lf()).nullable()}),Ap=xd({peer:Lf(),sent:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"sent"}))),received:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"received"})))}),Ip=Ap,$p=xd({totalSent:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"totalSent"}))),totalReceived:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"totalReceived"}))),settlements:Ed(Ap)}),Bp=xd({stakedAmount:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"stakedAmount"})))}),zp=xd({withdrawableAmount:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"withdrawableAmount"})))}),Sp=xd({txHash:Lf().transform(e=>new Xs(e))}),Op=xd({minimumGasFunds:Lf().transform(e=>yh.fromWei(jh(e,{name:"minimumGasFunds"}))),hasSufficientFunds:fd(),isFrozen:fd(),isFullySynced:fd(),phase:Lf(),round:ad(),lastWonRound:ad(),lastPlayedRound:ad(),lastFrozenRound:ad(),lastSelectedRound:ad(),lastSampleDurationSeconds:ad(),block:ad(),reward:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"reward"}))),fees:Lf().transform(e=>yh.fromWei(jh(e,{name:"fees"}))),isHealthy:fd()}),Tp=xd({batchID:Lf(),utilization:ad(),utilizationRatio:ad().optional(),usable:fd(),label:Lf(),depth:ad(),amount:Lf(),bucketDepth:ad(),blockNumber:ad(),immutableFlag:fd(),batchTTL:ad()}),Np=xd({batchID:Lf().transform(e=>new zs(e)),batchTTL:ad(),bucketDepth:ad(),depth:ad(),immutable:fd(),owner:Lf().transform(e=>new Ns(e)),start:ad(),value:Lf().transform(e=>jh(e,{name:"value"}))}),Rp=xd({batches:Ed(Np)}),Up=xd({stamps:Ed(Tp)}),Pp=Tp,Fp=xd({depth:ad(),bucketDepth:ad(),bucketUpperBound:ad(),buckets:Ed(xd({bucketID:ad(),collisions:ad()}))}),Cp=xd({batchID:Lf().transform(e=>new zs(e))});var Lp,Mp,Dp,Zp;function jp(){if(Mp)return Lp;Mp=1;const e="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...e)=>console.error("SEMVER",...e):()=>{};return Lp=e}function qp(){if(Zp)return Dp;Zp=1;const e=Number.MAX_SAFE_INTEGER||9007199254740991;return Dp={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:e,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:"2.0.0",FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}}var Gp,Hp,Vp,Kp,Wp,Jp,Xp,Yp,Qp,em={exports:{}};function tm(){return Gp||(Gp=1,function(e,t){const{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:o}=qp(),i=jp(),s=(t=e.exports={}).re=[],a=t.safeRe=[],c=t.src=[],u=t.safeSrc=[],l=t.t={};let f=0;const d="[a-zA-Z0-9-]",h=[["\\s",1],["\\d",o],[d,r]],p=(e,t,n)=>{const r=(e=>{for(const[t,n]of h)e=e.split(`${t}*`).join(`${t}{0,${n}}`).split(`${t}+`).join(`${t}{1,${n}}`);return e})(t),o=f++;i(e,o,t),l[e]=o,c[o]=t,u[o]=r,s[o]=new RegExp(t,n?"g":void 0),a[o]=new RegExp(r,n?"g":void 0)};p("NUMERICIDENTIFIER","0|[1-9]\\d*"),p("NUMERICIDENTIFIERLOOSE","\\d+"),p("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${d}*`),p("MAINVERSION",`(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})`),p("MAINVERSIONLOOSE",`(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASEIDENTIFIER",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIER]})`),p("PRERELEASEIDENTIFIERLOOSE",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASE",`(?:-(${c[l.PRERELEASEIDENTIFIER]}(?:\\.${c[l.PRERELEASEIDENTIFIER]})*))`),p("PRERELEASELOOSE",`(?:-?(${c[l.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[l.PRERELEASEIDENTIFIERLOOSE]})*))`),p("BUILDIDENTIFIER",`${d}+`),p("BUILD",`(?:\\+(${c[l.BUILDIDENTIFIER]}(?:\\.${c[l.BUILDIDENTIFIER]})*))`),p("FULLPLAIN",`v?${c[l.MAINVERSION]}${c[l.PRERELEASE]}?${c[l.BUILD]}?`),p("FULL",`^${c[l.FULLPLAIN]}$`),p("LOOSEPLAIN",`[v=\\s]*${c[l.MAINVERSIONLOOSE]}${c[l.PRERELEASELOOSE]}?${c[l.BUILD]}?`),p("LOOSE",`^${c[l.LOOSEPLAIN]}$`),p("GTLT","((?:<|>)?=?)"),p("XRANGEIDENTIFIERLOOSE",`${c[l.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),p("XRANGEIDENTIFIER",`${c[l.NUMERICIDENTIFIER]}|x|X|\\*`),p("XRANGEPLAIN",`[v=\\s]*(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:${c[l.PRERELEASE]})?${c[l.BUILD]}?)?)?`),p("XRANGEPLAINLOOSE",`[v=\\s]*(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:${c[l.PRERELEASELOOSE]})?${c[l.BUILD]}?)?)?`),p("XRANGE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAIN]}$`),p("XRANGELOOSE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAINLOOSE]}$`),p("COERCEPLAIN",`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),p("COERCE",`${c[l.COERCEPLAIN]}(?:$|[^\\d])`),p("COERCEFULL",c[l.COERCEPLAIN]+`(?:${c[l.PRERELEASE]})?`+`(?:${c[l.BUILD]})?(?:$|[^\\d])`),p("COERCERTL",c[l.COERCE],!0),p("COERCERTLFULL",c[l.COERCEFULL],!0),p("LONETILDE","(?:~>?)"),p("TILDETRIM",`(\\s*)${c[l.LONETILDE]}\\s+`,!0),t.tildeTrimReplace="$1~",p("TILDE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAIN]}$`),p("TILDELOOSE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAINLOOSE]}$`),p("LONECARET","(?:\\^)"),p("CARETTRIM",`(\\s*)${c[l.LONECARET]}\\s+`,!0),t.caretTrimReplace="$1^",p("CARET",`^${c[l.LONECARET]}${c[l.XRANGEPLAIN]}$`),p("CARETLOOSE",`^${c[l.LONECARET]}${c[l.XRANGEPLAINLOOSE]}$`),p("COMPARATORLOOSE",`^${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]})$|^$`),p("COMPARATOR",`^${c[l.GTLT]}\\s*(${c[l.FULLPLAIN]})$|^$`),p("COMPARATORTRIM",`(\\s*)${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]}|${c[l.XRANGEPLAIN]})`,!0),t.comparatorTrimReplace="$1$2$3",p("HYPHENRANGE",`^\\s*(${c[l.XRANGEPLAIN]})\\s+-\\s+(${c[l.XRANGEPLAIN]})\\s*$`),p("HYPHENRANGELOOSE",`^\\s*(${c[l.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[l.XRANGEPLAINLOOSE]})\\s*$`),p("STAR","(<|>)?=?\\s*\\*"),p("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),p("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")}(em,em.exports)),em.exports}function nm(){if(Xp)return Jp;Xp=1;const e=jp(),{MAX_LENGTH:t,MAX_SAFE_INTEGER:n}=qp(),{safeRe:r,t:o}=tm(),i=function(){if(Vp)return Hp;Vp=1;const e=Object.freeze({loose:!0}),t=Object.freeze({});return Hp=n=>n?"object"!=typeof n?e:n:t}(),{compareIdentifiers:s}=function(){if(Wp)return Kp;Wp=1;const e=/^[0-9]+$/,t=(t,n)=>{if("number"==typeof t&&"number"==typeof n)return t===n?0:t<n?-1:1;const r=e.test(t),o=e.test(n);return r&&o&&(t=+t,n=+n),t===n?0:r&&!o?-1:o&&!r?1:t<n?-1:1};return Kp={compareIdentifiers:t,rcompareIdentifiers:(e,n)=>t(n,e)}}();class a{constructor(s,c){if(c=i(c),s instanceof a){if(s.loose===!!c.loose&&s.includePrerelease===!!c.includePrerelease)return s;s=s.version}else if("string"!=typeof s)throw new TypeError(`Invalid version. Must be a string. Got type "${typeof s}".`);if(s.length>t)throw new TypeError(`version is longer than ${t} characters`);e("SemVer",s,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;const u=s.trim().match(c.loose?r[o.LOOSE]:r[o.FULL]);if(!u)throw new TypeError(`Invalid Version: ${s}`);if(this.raw=s,this.major=+u[1],this.minor=+u[2],this.patch=+u[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");u[4]?this.prerelease=u[4].split(".").map(e=>{if(/^[0-9]+$/.test(e)){const t=+e;if(t>=0&&t<n)return t}return e}):this.prerelease=[],this.build=u[5]?u[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(t){if(e("SemVer.compare",this.version,this.options,t),!(t instanceof a)){if("string"==typeof t&&t===this.version)return 0;t=new a(t,this.options)}return t.version===this.version?0:this.compareMain(t)||this.comparePre(t)}compareMain(e){return e instanceof a||(e=new a(e,this.options)),this.major<e.major?-1:this.major>e.major?1:this.minor<e.minor?-1:this.minor>e.minor?1:this.patch<e.patch?-1:this.patch>e.patch?1:0}comparePre(t){if(t instanceof a||(t=new a(t,this.options)),this.prerelease.length&&!t.prerelease.length)return-1;if(!this.prerelease.length&&t.prerelease.length)return 1;if(!this.prerelease.length&&!t.prerelease.length)return 0;let n=0;do{const r=this.prerelease[n],o=t.prerelease[n];if(e("prerelease compare",n,r,o),void 0===r&&void 0===o)return 0;if(void 0===o)return 1;if(void 0===r)return-1;if(r!==o)return s(r,o)}while(++n)}compareBuild(t){t instanceof a||(t=new a(t,this.options));let n=0;do{const r=this.build[n],o=t.build[n];if(e("build compare",n,r,o),void 0===r&&void 0===o)return 0;if(void 0===o)return 1;if(void 0===r)return-1;if(r!==o)return s(r,o)}while(++n)}inc(e,t,n){if(e.startsWith("pre")){if(!t&&!1===n)throw new Error("invalid increment argument: identifier is empty");if(t){const e=`-${t}`.match(this.options.loose?r[o.PRERELEASELOOSE]:r[o.PRERELEASE]);if(!e||e[1]!==t)throw new Error(`invalid identifier: ${t}`)}}switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",t,n);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",t,n);break;case"prepatch":this.prerelease.length=0,this.inc("patch",t,n),this.inc("pre",t,n);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",t,n),this.inc("pre",t,n);break;case"release":if(0===this.prerelease.length)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":{const e=Number(n)?1:0;if(0===this.prerelease.length)this.prerelease=[e];else{let r=this.prerelease.length;for(;--r>=0;)"number"==typeof this.prerelease[r]&&(this.prerelease[r]++,r=-2);if(-1===r){if(t===this.prerelease.join(".")&&!1===n)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(e)}}if(t){let r=[t,e];if(!1===n&&(r=[t]),((e,t)=>{const n=t.split(".");if(n.length>e.length)return!1;for(let t=0;t<n.length;t++)if(0!==s(e[t],n[t]))return!1;return!0})(this.prerelease,t)){const e=this.prerelease[t.split(".").length];isNaN(e)&&(this.prerelease=r)}else this.prerelease=r}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return Jp=a}var rm=Vr(function(){if(Qp)return Yp;Qp=1;const e=nm();return Yp=(t,n)=>new e(t,n).major}());const om="2.8.1-7cf53193";om.split("-")[0];const im="8.1.0",sm=xd({commitment:ad(),radius:ad(),storageRadius:ad(),reserveCapacityDoubling:ad()}),am=xd({block:ad(),chainTip:ad(),totalAmount:Lf().transform(e=>jh(e,{name:"totalAmount"})),currentPrice:Lf().transform(Number).transform(e=>{return t=e,Number.isInteger(t)?t<24e3?24e3:t:24e3;var t}),minimumValidityBlocks:ad().optional()}),cm=xd({bzzBalance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"bzzBalance"}))),nativeTokenBalance:Lf().transform(e=>yh.fromWei(jh(e,{name:"nativeTokenBalance"}))),chainID:ad(),chequebookContractAddress:Lf(),walletAddress:Lf()}),um=xd({transactionHash:Lf().transform(e=>new Xs(e))}),lm=xd({address:Lf().nullish().transform(e=>e??""),seen:ad(),sent:ad(),split:ad(),startedAt:Lf(),stored:ad(),synced:ad(),uid:ad()}),fm=xd({tags:Ed(lm)}),dm=xd({transactionHash:Lf().transform(e=>new Xs(e)),to:Lf(),nonce:ad(),gasPrice:Lf().transform(e=>jh(e,{name:"gasPrice"})),gasLimit:ad(),data:Lf(),created:Lf(),description:Lf(),value:Lf().transform(e=>jh(e,{name:"value"}))}),hm=xd({pendingTransactions:Ed(dm)}),pm=dm,mm=xd({transactionHash:Lf().transform(e=>new Xs(e))});new zs("0000000000000000000000000000000000000000000000000000000000000000"),new Js("0000000000000000000000000000000000000000000000000000000000000000");const gm=new Uint8Array(32);function ym(e){return e.endsWith("/")?e.slice(0,-1):e}function wm(e){try{const{protocol:t}=new URL(e);return"http:"===t||"https:"===t}catch{return!1}}function bm(e){if(!wm(e)||/[\s?#]/.test(e))return!1;const{username:t,password:n}=new URL(e);return""===t&&""===n}function vm(e,t,n,r){const o=new URLSearchParams;return o.set("origin",t),n&&(o.set("appName",n.name),n.description&&o.set("appDescription",n.description),n.icon&&o.set("appIcon",n.icon)),r?.challenge&&o.set("challenge",r.challenge),`${e}/connect#${o.toString()}`}const Em="https://api.gateway.ethswarm.org/",_m="https://xdai.fairdatasociety.org/",xm=e=>Fn().regex(new RegExp(`^[0-9a-fA-F]{${e}}$`),{message:`Must be a ${e}-character hex string`}),km=Fn().regex(/^[0-9a-fA-F]{64}$|^[0-9a-fA-F]{128}$/,{message:"Reference must be 64 hex chars (32 bytes) or 128 hex chars (64 bytes for encrypted)"}),Am=xm(64),Im=xm(40),$m=xm(64),Bm=xm(66),zm=xm(64),Sm=xm(64),Om=xm(130),Tm=xm(64),Nm=xm(226),Rm=Hr(e=>"bigint"==typeof e?e.toString():e,Er([ir(),Fn()])),Um=Hr(e=>"bigint"==typeof e?e.toString():e,Er([ir(),Fn()])),Pm=Im.transform(e=>new Ns(e)),Fm=Am.transform(e=>new zs(e)),Cm=$m.transform(e=>new Hs(e)),Lm=Fn().regex(/^\d+$/,{message:"Must be a decimal integer string"}).transform(e=>BigInt(e)),Mm=wr({deviceId:Fn(),createdAt:ir(),lastSignedInAt:ir(),name:Fn().optional(),nameUpdatedAt:ir().optional(),removedAt:ir().optional()}),Dm=wr({message:Fn().max(512),signature:Fn().regex(/^0x[0-9a-fA-F]{130}$/)}),Zm="none",jm=wr({appUrl:Fn(),appName:Fn(),lastConnectedAt:ir(),appIcon:Fn().optional(),appDescription:Fn().optional(),connectedUntil:ir().optional(),appSecret:Fn().optional(),postageStampBatchID:Er([Sr(Zm),Fm]).optional(),postageStampBatchIDAt:ir().optional(),stampPending:Sr(!0).optional(),revokedAt:ir().optional(),disconnectedAt:ir().optional(),chatBinding:Dm.optional()}),qm=wr({batchID:Fm,signerKey:Cm,name:Fn().optional(),nameUpdatedAt:ir().optional(),utilization:ir(),usable:ur(),depth:ir(),amount:Lm,bucketDepth:ir(),blockNumber:ir(),immutableFlag:ur(),exists:ur(),batchTTL:ir().optional(),createdAt:ir(),updatedAt:ir().optional(),deletedAt:ir().optional()}),Gm=xr("type",[wr({type:Sr("passkey"),credentialId:Fn()}),wr({type:Sr("eth-wallet"),encryptionSalt:Fn()}),wr({type:Sr("password"),kdfSalt:Fn(),kdfIterations:ir()})]),Hm=wr({access:Gm,encryptedSeed:Fn().regex(/^([0-9a-f]{2})+$/)}),Vm=wr({id:Pm,name:Fn(),createdAt:ir(),derivationKey:Fn().length(64),publicKey:Bm,defaultPostageStampBatchID:Fm.optional(),devices:gr(Mm).default([]),connectedApps:gr(jm).default([]),postageStamps:gr(qm).default([]),settings:wr({appSessionDuration:ir().optional()}).optional(),accountNameAt:ir().optional(),defaultStampAt:ir().optional(),settingsAt:ir().optional(),lastModified:ir().optional(),partitionCount:ir().int().min(1).optional()}),Km=Vm.extend({...Hm.shape,signedOutAt:function(e){return function(e,t){return new e({type:"undefined",...x(t)})}(lr,e)}().optional()}),Wm=Er([Km,wr({id:Pm,name:Fn(),createdAt:ir(),...Hm.shape,encryptedState:Fn().optional(),storageWarning:ur().optional(),soonestDriveExpiry:ir().optional(),signedOutAt:ir()})]),Jm=wr({accountName:Fn(),defaultPostageStampBatchID:Fn().length(64).optional(),publicKey:Bm,settings:wr({appSessionDuration:ir().optional()}).optional(),accountNameAt:ir().optional(),defaultStampAt:ir().optional(),settingsAt:ir().optional(),createdAt:ir(),lastModified:ir(),devices:gr(Mm).default([]),partitionCount:ir().int().min(1).default(1)}),Xm=wr({version:Sr(1),timestamp:ir(),accountId:Fn().length(40),metadata:Jm,connectedApps:gr(jm),postageStamps:gr(qm)});function Ym(e){return void 0!==e.signedOutAt}const Qm=wr({timestampMs:ir().int().nonnegative(),tiebreaker:Fn().regex(/^[0-9a-f]{16}$/)}),eg=wr({holderDeviceId:Fn(),generation:Qm,acquiredAt:ir().int().nonnegative(),leasedUntil:ir().int().nonnegative()}),tg=wr({deviceId:Fn(),generation:Qm,leasedUntil:ir().int().nonnegative().optional()}),ng=wr({beeNodeUrl:Fn().refine(wm,"Must be an http(s) URL"),gnosisRpcUrl:Fn().refine(wm,"Must be an http(s) URL")}),rg=Fn().refine(bm,"Must be an http(s) URL, optionally with a path, and no credentials, query or fragment"),og=wr({index:ir().int().min(0).max(65535),value:ir().int().min(0)}),ig=wr({type:Sr("utilization-updated"),batchId:Fn().length(64),partition:ir().int().min(0),partitionCount:ir().int().min(1),buckets:gr(og)}),sg="swarm-id-accounts",ag="swarm-id-network-settings",cg="swarm-storage-challenge",ug="swarm-id-site-allow-list";function lg(e,t){return`swarm-id-lease-v2:${e.toLowerCase()}:${t.toLowerCase()}`}function fg(e,t){return`swarm-id-app-stamp-usage:${e}:${t.toLowerCase()}`}function dg(e,t){return`swarm-id-soc-restamp-slots:${e}:${t.toLowerCase()}`}function hg(e){return`swarm-id-partition-session:${e}`}const pg=wr({pin:ur().optional(),encrypt:ur().optional(),encryptManifest:ur().optional(),tag:ir().optional(),deferred:ur().optional()}),mg=pg.optional(),gg=Br(["app","identity"]),yg=pg.extend({beeCompatible:ur().optional(),publisher:gg.optional()}).optional(),wg=wr({timeout:ir().optional(),headers:Ir(Fn(),Fn()).optional(),endlesslyRetry:ur().optional()}).optional(),bg=wr({redundancyStrategy:Er([Sr(0),Sr(1),Sr(2),Sr(3)]).optional(),fallback:ur().optional(),timeoutMs:ir().optional(),actPublisher:Er([Gr(Uint8Array),Fn()]).optional(),actHistoryAddress:Er([Gr(Uint8Array),Fn()]).optional(),actTimestamp:Er([ir(),Fn()]).optional()}).optional(),vg=pg.extend({indexDocument:Fn().optional(),errorDocument:Fn().optional()}).optional(),Eg=wr({path:Fn().min(1),data:Gr(Uint8Array),contentType:Fn().optional()}),_g=wr({path:Fn(),reference:km,contentType:Fn().optional()}),xg=wr({reference:km,tagUid:ir().optional()});xg.extend({encryptionKey:Fn().optional(),owner:Im}),xg.extend({encryptionKey:Fn().optional(),owner:Im}),wr({name:Fn(),data:Gr(Uint8Array)});const kg=wr({batchID:Am,utilization:ir(),usable:ur(),label:Fn(),depth:ir(),amount:Fn(),bucketDepth:ir(),blockNumber:ir(),immutableFlag:ur(),exists:ur(),batchTTL:ir().optional()});wr({authenticated:ur(),origin:Fn().optional(),beeApiUrl:Fn().url().optional()});const Ag=Br(["user-stamp","subsidised","unavailable"]),Ig=Br(["no-stamp","stamper-failed","stamp-expired","stamp-not-usable","subsidised","app-stamp-count","app-stamp-rate","app-bucket-share","app-slice-full","session-unconfirmed"]),$g=wr({source:Br(["generated"]),url:Fn()}),Bg=wr({id:Fn(),name:Fn(),address:Im,publicKey:Bm.optional(),sharingPublicKey:Bm.optional(),postageSignerAddress:Im.optional(),avatar:$g});wr({canUpload:ur(),storagePartitioned:ur().optional(),uploadMode:Ag.optional(),uploadUnavailableReason:Ig.optional(),partition:ir().int().min(0).optional(),identity:Bg.optional(),appKey:wr({address:Im,publicKey:Bm}).optional(),chatBinding:Dm.optional(),beeApiUrl:Fn().optional(),postageBatchId:Am.optional()});const zg=wr({name:Fn().min(1).max(100),description:Fn().max(500).optional(),icon:Fn().optional().refine(e=>{if(!e)return!0;if(!e.startsWith("data:image/"))return!1;if(!e.match(/^data:image\/(svg\+xml|png);/))return!1;const t=e.match(/base64,(.+)$/);if(t){if(3*t[1].length/4>4096)return!1}return!0},{message:"Icon must be a data URL with SVG or PNG mime type, max 4KB"})}),Sg=wr({connectText:Fn().optional(),disconnectText:Fn().optional(),loadingText:Fn().optional(),backgroundColor:Fn().optional(),color:Fn().optional(),borderRadius:Fn().optional(),fontFamily:Fn().optional(),fontSize:Fn().optional(),fontWeight:Er([Fn(),ir()]).optional()}).optional(),Og=wr({type:Sr("parentIdentify"),requestId:Fn(),beeApiUrl:rg.optional(),popupMode:Br(["popup","window"]).optional(),metadata:zg,buttonConfig:Sg,subsidisedGatewayUrl:Fn().url().optional()}),Tg=wr({type:Sr("checkAuth"),requestId:Fn()}),Ng=wr({type:Sr("disconnect"),requestId:Fn()}),Rg=wr({type:Sr("uploadData"),requestId:Fn(),data:Gr(Uint8Array),options:mg,requestOptions:wg,enableProgress:ur().optional(),useWebSocket:ur().optional(),useWorkers:ur().optional(),workerCount:ir().int().min(1).max(32).optional(),concurrency:ir().int().min(1).max(256).optional()}),Ug=wr({type:Sr("downloadData"),requestId:Fn(),reference:km,options:bg,requestOptions:wg}),Pg=wr({type:Sr("deriveAppSecret"),requestId:Fn(),label:Fn()}),Fg=wr({type:Sr("setBeeApiUrl"),requestId:Fn(),beeApiUrl:rg}),Cg=wr({type:Sr("getChatKey"),requestId:Fn()}),Lg=Er([Sr("app"),br({privateKey:$m})]),Mg=xr("kind",[br({kind:Sr("content"),data:Gr(Uint8Array)}),br({kind:Sr("soc"),identifier:Sm,data:Gr(Uint8Array),signer:Lg})]),Dg=br({type:Sr("stampChunk"),requestId:Fn(),chunk:Mg}),Zg=wr({type:Sr("uploadFile"),requestId:Fn(),data:Gr(Uint8Array),name:Fn().optional(),options:mg,requestOptions:wg,enableProgress:ur().optional(),useWebSocket:ur().optional(),useWorkers:ur().optional(),workerCount:ir().int().min(1).max(32).optional(),concurrency:ir().int().min(1).max(256).optional()}),jg=wr({type:Sr("downloadFile"),requestId:Fn(),reference:km,path:Fn().optional(),options:bg,requestOptions:wg}),qg=wr({type:Sr("uploadFiles"),requestId:Fn(),files:gr(Eg),options:vg,requestOptions:wg,enableProgress:ur().optional(),useWorkers:ur().optional(),workerCount:ir().int().min(1).max(32).optional()}),Gg=wr({type:Sr("listFiles"),requestId:Fn(),reference:km,requestOptions:wg}),Hg=wr({type:Sr("uploadChunk"),requestId:Fn(),data:Gr(Uint8Array),options:mg,requestOptions:wg}),Vg=wr({type:Sr("downloadChunk"),requestId:Fn(),reference:km,options:bg,requestOptions:wg}),Kg=wr({type:Sr("isConnected"),requestId:Fn()}),Wg=wr({type:Sr("getNodeInfo"),requestId:Fn()}),Jg=wr({type:Sr("gsocMine"),requestId:Fn(),targetOverlay:Fn(),identifier:Fn(),proximity:ir().optional()}),Xg=wr({type:Sr("gsocSend"),requestId:Fn(),signer:Fn(),identifier:Fn(),data:Gr(Uint8Array),options:mg,requestOptions:wg}),Yg=wr({type:Sr("socUpload"),requestId:Fn(),identifier:Sm,data:Gr(Uint8Array),signer:$m.optional(),options:mg,requestOptions:wg}),Qg=wr({type:Sr("socRawUpload"),requestId:Fn(),identifier:Sm,data:Gr(Uint8Array),signer:$m.optional(),options:mg,requestOptions:wg}),ey=wr({type:Sr("socDownload"),requestId:Fn(),owner:Im.optional(),identifier:Sm,encryptionKey:zm,requestOptions:wg}),ty=wr({type:Sr("socRawDownload"),requestId:Fn(),owner:Im.optional(),identifier:Sm,encryptionKey:zm.optional(),requestOptions:wg}),ny=wr({type:Sr("socGetOwner"),requestId:Fn()}),ry=wr({type:Sr("epochFeedDownloadReference"),requestId:Fn(),topic:Sm,owner:Im.optional(),at:Rm,after:Rm.optional(),encryptionKey:zm.optional(),requestOptions:wg}),oy=wr({lastEpoch:wr({start:Fn(),level:ir()}).optional(),lastTimestamp:Fn().optional()}).optional(),iy=xr("type",[Og,Tg,Ng,Rg,Ug,Pg,Cg,Fg,Dg,Zg,jg,qg,Gg,Hg,Vg,Kg,Wg,Jg,Xg,Yg,Qg,ey,ty,ny,ry,wr({type:Sr("epochFeedUploadReference"),requestId:Fn(),topic:Sm,signer:$m.optional(),at:Rm,reference:km,encryptionKey:zm.optional(),hints:oy,requestOptions:wg}),wr({type:Sr("feedGetOwner"),requestId:Fn()}),wr({type:Sr("seqFeedGetOwner"),requestId:Fn()}),wr({type:Sr("seqFeedDownloadPayload"),requestId:Fn(),topic:Sm,owner:Im.optional(),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm,requestOptions:wg}),wr({type:Sr("seqFeedDownloadRawPayload"),requestId:Fn(),topic:Sm,owner:Im.optional(),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm.optional(),requestOptions:wg}),wr({type:Sr("seqFeedDownloadReference"),requestId:Fn(),topic:Sm,owner:Im.optional(),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm,requestOptions:wg}),wr({type:Sr("seqFeedUploadPayload"),requestId:Fn(),topic:Sm,signer:$m.optional(),data:Gr(Uint8Array),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),options:mg,requestOptions:wg}),wr({type:Sr("seqFeedUploadRawPayload"),requestId:Fn(),topic:Sm,signer:$m.optional(),data:Gr(Uint8Array),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm.optional(),options:mg,requestOptions:wg}),wr({type:Sr("seqFeedUploadReference"),requestId:Fn(),topic:Sm,signer:$m.optional(),reference:km,index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),options:mg,requestOptions:wg}),wr({type:Sr("createFeedManifest"),requestId:Fn(),topic:Sm,owner:Im.optional(),feedType:Br(["Sequence","Epoch"]).optional(),uploadOptions:mg,requestOptions:wg}),wr({type:Sr("actUploadData"),requestId:Fn(),data:Gr(Uint8Array),grantees:gr(Fn()),options:yg,requestOptions:wg,enableProgress:ur().optional()}),wr({type:Sr("actDownloadData"),requestId:Fn(),encryptedReference:km,historyReference:km,publisherPubKey:Fn(),timestamp:ir().optional(),requestOptions:wg}),wr({type:Sr("actAddGrantees"),requestId:Fn(),historyReference:km,grantees:gr(Fn()),requestOptions:wg}),wr({type:Sr("actRevokeGrantees"),requestId:Fn(),historyReference:km,encryptedReference:km,revokeGrantees:gr(Fn()),requestOptions:wg}),wr({type:Sr("actGetGrantees"),requestId:Fn(),historyReference:km,requestOptions:wg}),wr({type:Sr("getPostageBatch"),requestId:Fn()}),wr({type:Sr("connect"),requestId:Fn(),popupMode:Br(["popup","window"]).optional()})]),sy=wr({type:Sr("proxyReady"),authenticated:ur(),parentOrigin:Fn(),storageShared:ur().optional()}),ay=wr({type:Sr("initError"),error:Fn()}),cy=wr({type:Sr("authStatusResponse"),requestId:Fn(),authenticated:ur(),origin:Fn().optional(),beeApiUrl:Fn().url().optional()}),uy=wr({type:Sr("disconnectResponse"),requestId:Fn(),success:ur()}),ly=wr({type:Sr("authSuccess"),origin:Fn()}),fy=wr({type:Sr("uploadDataResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),dy=wr({type:Sr("downloadDataResponse"),requestId:Fn(),data:Gr(Uint8Array)}),hy=wr({type:Sr("deriveAppSecretResponse"),requestId:Fn(),secret:Gr(Uint8Array)}),py=wr({type:Sr("getChatKeyResponse"),requestId:Fn(),chatKey:Gr(Uint8Array)}),my=wr({type:Sr("setBeeApiUrlResponse"),requestId:Fn(),beeApiUrl:Fn()}),gy=wr({type:Sr("stampChunkResponse"),requestId:Fn(),address:Tm,stamp:Nm,owner:Im.optional(),signature:Om.optional()}),yy=wr({type:Sr("uploadFileResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),wy=wr({type:Sr("downloadFileResponse"),requestId:Fn(),name:Fn(),data:Gr(Uint8Array)}),by=wr({type:Sr("uploadFilesResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),vy=wr({type:Sr("listFilesResponse"),requestId:Fn(),entries:gr(_g)}),Ey=wr({type:Sr("uploadChunkResponse"),requestId:Fn(),reference:km}),_y=wr({type:Sr("downloadChunkResponse"),requestId:Fn(),data:Gr(Uint8Array)}),xy=wr({type:Sr("uploadProgress"),requestId:Fn(),total:ir(),processed:ir()}),ky=Br(["not-authenticated","upload-unavailable","partition-contended","lease-lost","bee-rejected","network","timeout","invalid-request","invalid-state","init-failed","popup-blocked","internal"]),Ay=xr("type",[sy,ay,cy,uy,ly,fy,dy,hy,py,my,gy,yy,wy,by,vy,Ey,_y,xy,wr({error:Fn(),code:ky.catch("internal"),reason:Ig.optional().catch(void 0),status:ir().int().optional(),beeMessage:Fn().optional(),url:Fn().optional()}).extend({type:Sr("error"),requestId:Fn()}),wr({type:Sr("connectionInfoChanged"),canUpload:ur(),storagePartitioned:ur().optional(),uploadMode:Ag.optional(),uploadUnavailableReason:Ig.optional().catch(void 0),identity:Bg.optional(),appKey:wr({address:Im,publicKey:Bm}).optional(),partition:ir().int().min(0).optional(),chatBinding:Dm.optional(),beeApiUrl:Fn().optional(),postageBatchId:Am.optional()}),wr({type:Sr("connectResponse"),requestId:Fn(),success:ur()}),wr({type:Sr("isConnectedResponse"),requestId:Fn(),connected:ur()}),wr({type:Sr("getNodeInfoResponse"),requestId:Fn(),beeMode:Fn(),chequebookEnabled:ur(),swapEnabled:ur()}),wr({type:Sr("gsocMineResponse"),requestId:Fn(),signer:Fn()}),wr({type:Sr("gsocSendResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),wr({type:Sr("socUploadResponse"),requestId:Fn(),reference:km,tagUid:ir().optional(),encryptionKey:Fn().optional(),owner:Im}),wr({type:Sr("socRawUploadResponse"),requestId:Fn(),reference:km,tagUid:ir().optional(),encryptionKey:Fn().optional(),owner:Im}),wr({type:Sr("socDownloadResponse"),requestId:Fn(),data:Gr(Uint8Array),identifier:Sm,signature:Om,span:ir(),payload:Gr(Uint8Array),address:km,owner:Im}),wr({type:Sr("socRawDownloadResponse"),requestId:Fn(),data:Gr(Uint8Array),identifier:Sm,signature:Om,span:ir(),payload:Gr(Uint8Array),address:km,owner:Im}),wr({type:Sr("socGetOwnerResponse"),requestId:Fn(),owner:Im}),wr({type:Sr("epochFeedDownloadReferenceResponse"),requestId:Fn(),reference:km.optional()}),wr({type:Sr("epochFeedUploadReferenceResponse"),requestId:Fn(),socAddress:km,encryptionKey:zm.optional(),epoch:wr({start:Fn(),level:ir()}),timestamp:Fn()}),wr({type:Sr("feedGetOwnerResponse"),requestId:Fn(),owner:Im}),wr({type:Sr("seqFeedGetOwnerResponse"),requestId:Fn(),owner:Im}),wr({type:Sr("seqFeedDownloadPayloadResponse"),requestId:Fn(),payload:Gr(Uint8Array),timestamp:ir().optional(),feedIndex:Fn(),feedIndexNext:Fn()}),wr({type:Sr("seqFeedDownloadRawPayloadResponse"),requestId:Fn(),payload:Gr(Uint8Array),timestamp:ir().optional(),feedIndex:Fn(),feedIndexNext:Fn()}),wr({type:Sr("seqFeedDownloadReferenceResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),feedIndexNext:Fn()}),wr({type:Sr("seqFeedUploadPayloadResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),owner:Im,encryptionKey:Fn().optional(),tagUid:ir().optional()}),wr({type:Sr("seqFeedUploadRawPayloadResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),owner:Im,encryptionKey:Fn().optional(),tagUid:ir().optional()}),wr({type:Sr("seqFeedUploadReferenceResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),owner:Im,encryptionKey:Fn().optional(),tagUid:ir().optional()}),wr({type:Sr("createFeedManifestResponse"),requestId:Fn(),reference:km}),wr({type:Sr("actUploadDataResponse"),requestId:Fn(),encryptedReference:km,historyReference:km,granteeListReference:km,publisherPubKey:Fn(),actReference:km,tagUid:ir().optional()}),wr({type:Sr("actDownloadDataResponse"),requestId:Fn(),data:Gr(Uint8Array)}),wr({type:Sr("actAddGranteesResponse"),requestId:Fn(),historyReference:km,granteeListReference:km,actReference:km}),wr({type:Sr("actRevokeGranteesResponse"),requestId:Fn(),encryptedReference:km,historyReference:km,granteeListReference:km,actReference:km}),wr({type:Sr("actGetGranteesResponse"),requestId:Fn(),grantees:gr(Fn())}),wr({type:Sr("getPostageBatchResponse"),requestId:Fn(),postageBatch:kg.optional()})]),Iy=wr({secret:Fn(),networkSettings:ng.optional(),account:Vm,chatBinding:Dm.optional(),stampPending:Sr(!0).optional()}),$y=wr({version:Sr(1),parentOrigin:Fn(),connectedUntil:ir(),data:Fn()}),By=xr("type",[wr({type:Sr("setSecret"),appOrigin:Fn(),challenge:Fn(),data:Iy})]),zy="#FCFCFC",Sy="#131416",Oy=[["#FFE0CC","#DD7200","#401F00"],["#99CCFF","#0082FB","#003366"],["#99E6B3","#00C853","#004D1F"],["#E1BEE7","#9C27B0","#4A148C"]],Ty=[];for(const e of Oy)Ty.push([e[1],zy]),Ty.push([e[1],Sy]),Ty.push([zy,e[1]]),Ty.push([Sy,e[1]]);for(const e of Oy)Ty.push([e[0],e[1]]),Ty.push([e[2],e[1]]),Ty.push([e[1],e[0]]),Ty.push([e[1],e[2]]),Ty.push([e[0],e[2]]),Ty.push([e[2],e[0]]);for(let e=0;e<Oy.length;e++){const t=Oy[(e+1)%Oy.length];Ty.push([Oy[e][0],t[2]]),Ty.push([t[2],Oy[e][0]])}const Ny=[[0,1],[1,0],[0,-1],[-1,0]];function Ry(e,t=40){const n=function(e){let t=0;for(let n=0;n<e.length;n++)t=e.charCodeAt(n)+(t<<6)+(t<<16)-t;return t}(e.length<6?e.padEnd(6," "):e),[r,o]=Ty[Math.abs(n)%Ty.length],i=.25*t,s=(t-2*i)/2,a=Array.from({length:2},()=>Array(2).fill(!1)),c=Math.floor(1),u=[[c,c]];a[c][c]=!0;let l="";for(let e=u.pop();void 0!==e;e=u.pop()){const[t,r]=e,o=15&Math.abs(n>>3*t+5*r),c=[];for(const[e,n]of Ny){const o=t+e,i=r+n;o>=0&&o<2&&i>=0&&i<2&&!a[o][i]&&c.push([o,i])}for(;c.length>0;){const e=Math.abs(o+c.length)%c.length,[t,n]=c.splice(e,1)[0];u.push([t,n]),a[t][n]=!0}const f=o%4*90,d=i+t*s,h=i+r*s;l+=o%5==0?`M${d},${h} h${s} v${s} h-${s}z `:0===f?`M${d},${h} h${s} v${s}z `:90===f?`M${d+s},${h} v${s} h-${s}z `:180===f?`M${d+s},${h+s} h-${s} v-${s}z `:`M${d},${h+s} v-${s} h${s}z `}return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 ${t} ${t}"><rect width="${t}" height="${t}" fill="${r}"/><path d="${l}" fill="${o}"/></svg>`}function Uy(e,t=40){const n=Ry(e,t);return{source:"generated",url:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}}function Py(e){const t=e.replace(/^0x/i,"");if(t.length%2!=0||!/^[0-9a-fA-F]*$/.test(t))throw new Error("Invalid hex string.");const n=new Uint8Array(t.length/2);for(let e=0;e<t.length;e+=2)n[e/2]=parseInt(t.substring(e,e+2),16);return n}function Fy(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function Cy(e){const t=e.replace(/^0x/i,"").toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error(`Invalid hex address: expected 40 hex characters (with optional 0x prefix), got "${e}"`);return t}class Ly extends Error{constructor(e){super(e),this.name="TimeoutError"}}function My(e,t,n){let r;const o=new Promise((e,o)=>{r=setTimeout(()=>o(new Ly(n)),t)});return Promise.race([e,o]).finally(()=>clearTimeout(r))}function Dy(e){return new Promise(t=>setTimeout(t,e))}function Zy(e,t,n){let r,o=!1,i=()=>{};const s=new Promise((e,s)=>{i=()=>{o||(clearTimeout(r),r=setTimeout(()=>s(new Ly(n)),t))},i()}),a=(async()=>e(i))();return Promise.race([a,s]).finally(()=>{o=!0,clearTimeout(r)})}const jy=0,qy=4096,Gy=8,Hy=32,Vy=8;class Ky{constructor(e,t,n){this.encryptionKey=e,this.keyLen=e.length,this.padding=t,this.initCtr=n,this.index=0}key(){return this.encryptionKey}encrypt(e){const t=e.length;let n=t;if(this.padding>0){if(t>this.padding)throw new Error(`data length ${t} longer than padding ${this.padding}`);n=this.padding}const r=new Uint8Array(n);return this.transform(e,r),r}decrypt(e){const t=e.length;if(this.padding>0&&t!==this.padding)throw new Error(`data length ${t} different than padding ${this.padding}`);const n=new Uint8Array(t);return this.transform(e,n),n}reset(){this.index=0}transform(e,t){const n=e.length;for(let r=0;r<n;r+=this.keyLen){const o=Math.min(this.keyLen,n-r);this.transcrypt(this.index,e.subarray(r,r+o),t.subarray(r,r+o)),this.index++}Wy(t.subarray(n))}transcrypt(e,t,n){const r=new Uint8Array(4);new DataView(r.buffer).setUint32(0,e+this.initCtr,!0);const o=new Uint8Array(this.encryptionKey.length+4);o.set(this.encryptionKey),o.set(r,this.encryptionKey.length);const i=Jr.Binary.keccak256(o),s=Jr.Binary.keccak256(i),a=t.length;for(let e=0;e<a;e++)n[e]=t[e]^s[e];Wy(n.subarray(a))}}function Wy(e){0!==e.length&&crypto.getRandomValues(e)}function Jy(e=32){const t=new Uint8Array(e);return Wy(t),t}function Xy(e){return new Ky(e,0,Math.floor(128))}function Yy(e){return new Ky(e,4096,0)}class Qy{encryptChunk(e,t){const n=t||Jy(32);return{key:n,encryptedSpan:Xy(n).encrypt(e.subarray(0,8)),encryptedData:Yy(n).encrypt(e.subarray(8))}}}function ew(){return new Qy}function tw(e,t){const n=Xy(e).decrypt(t.subarray(0,8)),r=Yy(e).decrypt(t.subarray(8)),o=new Uint8Array(8+r.length);return o.set(n),o.set(r,8),o}const nw=4096;function rw(e){const t=e.slice(0,Ks.LENGTH),n=function(e){if(e.length>nw)throw new Error(`payload size ${e.length} exceeds maximum chunk payload size 4096`);const t=new Uint8Array(nw);t.set(e);let n=Jr.Binary.partition(t,32);for(;n.length>1;){const e=[];for(let t=0;t<n.length;t+=2){const r=n[t],o=n[t+1],i=Jr.Binary.concatBytes(r,o),s=Jr.Binary.keccak256(i);e.push(s)}n=e}return n[0]}(e.slice(Ks.LENGTH)),r=Jr.Binary.keccak256(Jr.Binary.concatBytes(t,n));return new Vs(r)}const ow=new TextEncoder;function iw(e,t){if(e instanceof Uint8Array||(e=ow.encode(e)),e.length<0||e.length>qy)throw new RangeError(`payload size ${e.length} exceeds limits [0, 4096]`);let n;n=t instanceof Ks?t:"bigint"==typeof t?Ks.fromBigInt(t):Ks.fromBigInt(BigInt(e.length));const r=Jr.Binary.concatBytes(n.toUint8Array(),e),o=rw(r);return{data:r,span:n,payload:new Bs(e),address:o}}const sw=new TextEncoder;function aw(e,t){if(e instanceof Uint8Array||(e=sw.encode(e)),e.length<0||e.length>qy)throw new RangeError(`payload size ${e.length} exceeds limits [0, 4096]`);const n=Ks.fromBigInt(BigInt(e.length)),r=Jr.Binary.concatBytes(n.toUint8Array(),e),o=ew(),{key:i,encryptedSpan:s,encryptedData:a}=o.encryptChunk(r,t),c=Jr.Binary.concatBytes(s,a),u=rw(c),l=new Vs(Jr.Binary.concatBytes(u.toUint8Array(),i));return{data:c,encryptionKey:i,span:n,payload:new Bs(c.slice(Ks.LENGTH)),address:u,reference:l}}function cw(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return Number(t.getBigUint64(0,!0))}function uw(e,t){return new Vs(Jr.Binary.keccak256(Jr.Binary.concatBytes(e.toUint8Array(),t.toUint8Array())))}function lw(e,t,n,r){const o=new Fs(e.slice(0,32)),i=Gs.fromSlice(e,32),s=e.slice(97),a=rw(s),c=Jr.Binary.concatBytes(o.toUint8Array(),a.toUint8Array()),u=i.recoverPublicKey(c).address();if(!u.equals(n))throw new Error("SOC owner mismatch");const l=uw(o,u);if(!Jr.Binary.equals(t.toUint8Array(),l.toUint8Array()))throw new Error("SOC data does not match given address");let f,d,h;if(r){const e=tw(r,s);f=e.slice(0,8);const t=cw(f);d=e.slice(8,8+t),h=Jr.Binary.concatBytes(o.toUint8Array(),i.toUint8Array(),f,d)}else{f=e.slice(97,105);const t=cw(f);if(t>4096)throw new Error("SOC payload length is invalid; this chunk likely requires decryption");d=e.slice(105,105+t),h=e}const p=cw(f);return{data:h,identifier:o.toHex(),signature:i.toHex(),span:p,payload:d,address:t.toHex(),owner:u.toHex()}}function fw(e,t,n){const r=[],o=n?64:Hy,i=Math.floor(e.length/o),s=Math.ceil(t/qy),a=Math.min(i,s);for(let t=0;t<a;t++){const i=t*o;if(i+o>e.length)break;const s=e.slice(i,i+Hy);if(s.every(e=>0===e))break;if(n){const t=e.slice(i+Hy,i+64);r.push({address:s,encryptionKey:t})}else r.push({address:s})}return r}async function dw(e,t,n){const r=Jr.Binary.uint8ArrayToHex(t.address);let o,i;try{o=await e.chunk.download(r,void 0,n)}catch(n){throw console.error(`[DownloadData] chunk fetch failed addr=${r} encrypted=${void 0!==t.encryptionKey} bee.url=${e.url}:`,n),n}i=t.encryptionKey?tw(t.encryptionKey,o):o;return{span:cw(i.slice(0,8)),payload:i.slice(8)}}async function hw(e,t,n,r,o,i){const{span:s,payload:a}=await dw(e,t,i);if(o(),s<=qy)return a.slice(0,s);const c=fw(a,s,n);if(0===c.length)throw new Error("No valid references found in intermediate chunk");const u=new Array(c.length);for(let t=0;t<c.length;t+=r){const s=c.slice(t,Math.min(t+r,c.length)),a=await Promise.all(s.map(t=>hw(e,t,n,r,o,i)));for(let e=0;e<a.length;e++)u[t+e]=a[e]}const l=u.reduce((e,t)=>e+t.length,0),f=new Uint8Array(l);let d=0;for(const e of u)f.set(e,d),d+=e.length;return f}async function pw(e,t,n,r,o){const i=function(e){const t=Py(e);if(t.length===Hy)return{address:t};if(64===t.length)return{address:t.slice(0,Hy),encryptionKey:t.slice(Hy)};throw new Error(`Invalid reference length: ${t.length}, expected 32 or 64`)}(t),s=void 0!==i.encryptionKey;console.log(`[DownloadData] start addr=${Jr.Binary.uint8ArrayToHex(i.address)} encrypted=${s} bee.url=${e.url}`);const{span:a,payload:c}=await dw(e,i,o);if(a<=qy)return c.slice(0,a);const u=()=>{},l=fw(c,a,s);if(0===l.length)throw new Error("No valid references found in root chunk");const f=new Array(l.length);for(let t=0;t<l.length;t+=64){const n=l.slice(t,Math.min(t+64,l.length)),r=await Promise.all(n.map(t=>hw(e,t,s,64,u,o)));for(let e=0;e<r.length;e++)f[t+e]=r[e]}const d=f.reduce((e,t)=>e+t.length,0),h=new Uint8Array(d);let p=0;for(const e of f)h.set(e,p),p+=e.length;return h}async function mw(e,t,n,r){const o=new Ns(t),i=uw(new Fs(n),o);return lw(await e.chunk.download(i.toHex(),void 0,r),i,o)}async function gw(e,t,n,r,o){const i=new Ns(t),s=uw(new Fs(n),i),a="string"==typeof r?Py(r):r;return lw(await e.chunk.download(s.toHex(),void 0,o),s,i,a)}async function yw(e,t){const n=await async function e(n,r){for(const t of n.forks.values())await e(t.node,!1);const o=await n.marshal(),i=await t(o,r);return n.selfAddress=Py(i.reference),i}(e,!0);return{rootReference:n.reference,tagUid:n.tagUid}}async function ww(e,t,n){const r=!0===n?.encrypt;const o=await async function e(n,o){for(const t of n.forks.values())await e(t.node,!1);const i=await n.marshal();if(r){const e=aw(i),r=await t(e.data,o),s=new Uint8Array(64);return s.set(e.address.toUint8Array(),0),s.set(e.encryptionKey,32),n.selfAddress=s,r}{const e=iw(i),r=await t(e.data,o);return n.selfAddress=e.address.toUint8Array(),r}}(e,!0);return{rootReference:Fy(e.selfAddress),tagUid:o.tagUid}}const bw=["invalid version hash","data too short"];async function vw(e,t,n){const r=function(e,t){try{return _a.unmarshalFromData(e,Py(t))}catch(e){if(e instanceof Error&&bw.some(t=>e.message.endsWith(t)))throw new Error("No manifest at this reference; a reference from uploadData needs downloadData.",{cause:e});throw e}}(await pw(e,t,0,0,n),t);return await async function t(r){for(const o of r.forks.values()){if(!o.node.selfAddress)throw new Error("Fork node selfAddress is not set");const i=Fy(o.node.selfAddress),s=await pw(e,i,0,0,n),a=_a.unmarshalFromData(s,o.node.selfAddress);o.node.targetAddress=a.targetAddress,o.node.forks=a.forks,o.node.obfuscationKey=a.obfuscationKey,o.node.path=o.prefix,o.node.parent=r;for(const e of o.node.forks.values())e.node.parent=o.node;await t(o.node)}}(r),r}const Ew=5,_w=86400n/BigInt(5),xw=86400,kw=30n*BigInt(xw);async function Aw(){const e=await fetch("https://api.swarmscan.io/v1/postage-stamps/stats");if(!e.ok)throw new Error(`Failed to fetch Swarmscan stats: ${e.status}`);return(await e.json()).pricePerGBPerMonth}function Iw(e,t){if(!Number.isFinite(t)||t<=0)return 0;const n=BigInt(e);if(n<=0n)return 0;const r=function(e){const t=e.toFixed(16),n=t.startsWith("-"),r=n?t.slice(1):t,[o,i=""]=r.split("."),s=i.padEnd(16,"0").slice(0,16),a=BigInt(o+s);return n?-a:a}(t)/262144n;return r<=0n?0:Number(n*kw/r)}function $w(e){if(void 0===e||e<=0)return"N/A";return`${Math.floor(e/xw)}d ${Math.floor(e%xw/3600)}h`}function Bw(e,t){return e<=0n||!Number.isInteger(t)||t<=0?0n:e*_w*BigInt(t)}async function zw(e,t){try{const n=e.replace(/\/$/,""),r=await fetch(`${n}/stamps/${t}`);if(!r.ok)return;const o=await r.json();if("object"!=typeof o||null===o)return;const{batchTTL:i,usable:s,exists:a}=o;return{batchTTL:"number"==typeof i?i<0?0:i:void 0,usable:"boolean"==typeof s?s:void 0,exists:"boolean"==typeof a?a:void 0}}catch{return}}async function Sw(e,t){const n=await zw(e,t);return n?.batchTTL}const Ow=1e4;function Tw(e){try{return new URL(e).origin}catch{return"The RPC endpoint"}}function Nw(e){return"object"==typeof e&&null!==e}function Rw(e,t,n){if(e.error)throw new Error(`${n} refused ${t}: ${e.error.message??"unknown error"}`);if(!("result"in e))throw new Error(`${n} returned a malformed envelope for ${t}.`);return e.result??void 0}function Uw(e,t,n){if(void 0===e)throw new Error(`${n} returned no result for ${t}.`);return e}async function Pw(e,t,n,r){const o=r.label??Tw(e),i=new AbortController,s=setTimeout(()=>i.abort(),r.timeoutMs),a=e=>i.signal.aborted?new Ly(`${o} did not answer ${n} within ${r.timeoutMs}ms.`):new Error(e);try{let r;try{r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:i.signal})}catch(e){throw a(`${o} could not be reached for ${n}: ${c=e,c instanceof Error?c.message:String(c)}`)}!function(e,t,n){if(!e.ok)throw new Error(`${n} answered ${e.status} to ${t}.`)}(r,n,o);try{return await r.json()}catch{throw a(`${o} answered ${n} with a body that is not JSON.`)}}finally{clearTimeout(s)}var c}async function Fw(e,t,n,r){const o=r.label??Tw(e);return Uw(Rw(await Pw(e,{jsonrpc:"2.0",id:1,method:t,params:n},t,r),t,o),t,o)}async function Cw(e,t,n){if(0===t.length)return[];const r=n.label??Tw(e),o=`a batch of ${t.length} calls`,i=t.map((e,t)=>({jsonrpc:"2.0",id:t,method:e.method,params:e.params})),s=()=>new Error(`${r} returned a malformed response to ${o}.`),a=await Pw(e,i,o,n);if(!Array.isArray(a))throw Nw(a)&&a.error&&Rw(a,o,r),s();if(a.length!==t.length)throw s();const c=new Array(t.length),u=new Set;for(const e of a){if(!Nw(e))throw s();const{id:n}=e;if("number"!=typeof n||n<0||n>=t.length)throw new Error(`${r} returned a response with an unknown id.`);if(u.has(n))throw new Error(`${r} returned two responses for id ${n}.`);u.add(n);const o=t[n].method;c[n]=Uw(Rw(e,o,r),o,r)}return c}function Lw(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Mw(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Dw(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Zw(e,t){Mw(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const jw="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,qw=e=>e instanceof Uint8Array,Gw=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Hw=(e,t)=>e<<32-t|e>>>t;
13
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function Vw(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!qw(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class Kw{clone(){return this._cloneInto()}}function Ww(e){const t=t=>e().update(Vw(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Jw(e=32){if(jw&&"function"==typeof jw.getRandomValues)return jw.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class Xw extends Kw{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Gw(this.buffer)}update(e){Dw(this);const{view:t,buffer:n,blockLen:r}=this,o=(e=Vw(e)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=Gw(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Dw(this),Zw(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=Gw(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.length=r,e.pos=s,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(n),e}}const Yw=(e,t,n)=>e&t^~e&n,Qw=(e,t,n)=>e&t^e&n^t&n,eb=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),tb=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nb=new Uint32Array(64);class rb extends Xw{constructor(){super(64,32,8,!1),this.A=0|tb[0],this.B=0|tb[1],this.C=0|tb[2],this.D=0|tb[3],this.E=0|tb[4],this.F=0|tb[5],this.G=0|tb[6],this.H=0|tb[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)nb[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=nb[e-15],n=nb[e-2],r=Hw(t,7)^Hw(t,18)^t>>>3,o=Hw(n,17)^Hw(n,19)^n>>>10;nb[e]=o+nb[e-7]+r+nb[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(Hw(s,6)^Hw(s,11)^Hw(s,25))+Yw(s,a,c)+eb[e]+nb[e]|0,l=(Hw(n,2)^Hw(n,13)^Hw(n,22))+Qw(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){nb.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const ob=Ww(()=>new rb),ib=BigInt(0),sb=BigInt(1),ab=BigInt(2),cb=e=>e instanceof Uint8Array,ub=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));
14
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function lb(e){if(!cb(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=ub[e[n]];return t}function fb(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function db(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function hb(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,o=e.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[t]=i}return n}function pb(e){return db(lb(e))}function mb(e){if(!cb(e))throw new Error("Uint8Array expected");return db(lb(Uint8Array.from(e).reverse()))}function gb(e,t){return hb(e.toString(16).padStart(2*t,"0"))}function yb(e,t){return gb(e,t).reverse()}function wb(e,t,n){let r;if("string"==typeof t)try{r=hb(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!cb(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(`${e} expected ${n} bytes, got ${o}`);return r}function bb(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!cb(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const vb=e=>(ab<<BigInt(e-1))-sb,Eb=e=>new Uint8Array(e),_b=e=>Uint8Array.from(e);function xb(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=Eb(e),o=Eb(e),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},a=(...e)=>n(o,r,...e),c=(e=Eb())=>{o=a(_b([0]),e),r=a(),0!==e.length&&(o=a(_b([1]),e),r=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return bb(...n)};return(e,t)=>{let n;for(s(),c(e);!(n=t(u()));)c();return s(),n}}const kb={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function Ab(e,t,n={}){const r=(t,n,r)=>{const o=kb[n];if("function"!=typeof o)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||o(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}var Ib=Object.freeze({__proto__:null,bitGet:function(e,t){return e>>BigInt(t)&sb},bitLen:function(e){let t;for(t=0;e>ib;e>>=sb,t+=1);return t},bitMask:vb,bitSet:(e,t,n)=>e|(n?sb:ib)<<BigInt(t),bytesToHex:lb,bytesToNumberBE:pb,bytesToNumberLE:mb,concatBytes:bb,createHmacDrbg:xb,ensureBytes:wb,equalBytes:function(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},hexToBytes:hb,hexToNumber:db,numberToBytesBE:gb,numberToBytesLE:yb,numberToHexUnpadded:fb,numberToVarBytesBE:function(e){return hb(fb(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:Ab});
15
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const $b=BigInt(0),Bb=BigInt(1),zb=BigInt(2),Sb=BigInt(3),Ob=BigInt(4),Tb=BigInt(5),Nb=BigInt(8);function Rb(e,t){const n=e%t;return n>=$b?n:t+n}function Ub(e,t,n){if(n<=$b||t<$b)throw new Error("Expected power/modulo > 0");if(n===Bb)return $b;let r=Bb;for(;t>$b;)t&Bb&&(r=r*e%n),e=e*e%n,t>>=Bb;return r}function Pb(e,t,n){let r=e;for(;t-- >$b;)r*=r,r%=n;return r}function Fb(e,t){if(e===$b||t<=$b)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Rb(e,t),r=t,o=$b,i=Bb;for(;n!==$b;){const e=r%n,t=o-i*(r/n);r=n,n=e,o=i,i=t}if(r!==Bb)throw new Error("invert: does not exist");return Rb(o,t)}function Cb(e){if(e%Ob===Sb){const t=(e+Bb)/Ob;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Nb===Tb){const t=(e-Tb)/Nb;return function(e,n){const r=e.mul(n,zb),o=e.pow(r,t),i=e.mul(n,o),s=e.mul(e.mul(i,zb),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-Bb)/zb;let n,r,o;for(n=e-Bb,r=0;n%zb===$b;n/=zb,r++);for(o=zb;o<e&&Ub(o,t,e)!==e-Bb;o++);if(1===r){const t=(e+Bb)/Ob;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+Bb)/zb;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,o),n),u=e.pow(s,i),l=e.pow(s,n);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(l);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,Bb<<BigInt(a-t-1));c=e.sqr(n),u=e.mul(u,n),l=e.mul(l,c),a=t}return u}}(e)}BigInt(9),BigInt(16);const Lb=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mb(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Db(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Zb(e){const t=Db(e);return t+Math.ceil(t/2)}
12
+ const Qi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},es={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},ts=BigInt(2);const ns=wi(Qi.p,{sqrt:function(e){const t=Qi.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=ai(l,n,t)*l%t,d=ai(f,n,t)*l%t,h=ai(d,ts,t)*u%t,p=ai(h,o,t)*h%t,m=ai(p,i,t)*p%t,g=ai(m,a,t)*m%t,y=ai(g,c,t)*g%t,w=ai(y,a,t)*m%t,b=ai(w,n,t)*l%t,v=ai(b,s,t)*p%t,E=ai(v,r,t)*u%t,_=ai(E,ts,t);if(!ns.eql(ns.sqr(_),e))throw new Error("Cannot find square root");return _}}),rs=function(e,t){const n=t=>Yi({...e,hash:t});return{...n(t),create:n}}({...Qi,Fp:ns,lowS:!0,endo:es},So);function os(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.subarray(r,r+t));return n}function is(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 ss(e,t){const n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!==t[r])return e.subarray(0,r);return e.subarray(0,n)}function as(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function cs(e,t){const n=new Uint8Array(32);let r=e;for(let e=31;e>=0;e--)n[e]=Number(0xffn&r),r>>=8n;return n}function us(e,t){let n=0n;for(let t=0;t<32;t++)n=n<<8n|BigInt(e[t]);return n}function ls(e){const t=e.startsWith("0x")||e.startsWith("0X")?e.slice(2):e,n=new Uint8Array(t.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(t.slice(2*e,2*e+2),16);return n}var fs="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";function ds(e,t){const n=t.length;let r=0,o=0,i="";for(const s of e)for(o=o<<8|s,r+=8;r>=Math.log2(n);)r-=Math.log2(n),i+=t.charAt(o>>r&n-1);return r>0&&(i+=t.charAt(o<<Math.log2(n)-r&n-1)),i.length%4!=0&&(i+="=".repeat(4-i.length%4)),i}function hs(e){return function(e,t){const n=t.length;let r=0,o=0;const i=[];for(let s=0;s<e.length;s++){const a=e.charAt(s);if("="===a)break;const c=t.indexOf(a);if(-1===c)throw new Error(`Invalid character: ${a}`);o=o<<Math.log2(n)|c,r+=Math.log2(n),r>=8&&(r-=8,i.push(o>>r&255))}return new Uint8Array(i)}(e,fs)}function ps(e){return ds(e,fs)}function ms(e){return new Uint8Array([e])}function gs(e){return e[0]}function ys(e,t){return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(0,"LE"===t)}function ws(e,t){const n=new ArrayBuffer(4);return new DataView(n).setUint32(0,e,"LE"===t),new Uint8Array(n)}function bs(e,t){const n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,e,"LE"===t),new Uint8Array(n)}function vs(e,t){return new DataView(e.buffer,e.byteOffset,e.byteLength).getBigUint64(0,"LE"===t)}var Es=[0,1,0,32898,2147483648,32906,2147483648,2147516416,0,32907,0,2147483649,2147483648,2147516545,2147483648,32777,0,138,0,136,0,2147516425,0,2147483658,0,2147516555,2147483648,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,0,32778,2147483648,2147483658,2147483648,2147516545,2147483648,32896,0,2147483649,2147483648,2147516424];function _s(e){return t=function(e,t){for(const n of t){for(let t=0;t<34;t+=2)e[t]=e[t]^n[t+1],e[t+1]=e[t+1]^n[t];xs(e)}return e}(new Array(50).fill(0),function(e,t){if(!e.length){const e=new Uint8Array(136);return e[0]=t,e[135]=128,[ks(e)]}const n=os(e,136),r=n[n.length-1];if(r.length<136){const e=new Uint8Array(136);e.set(r),e[r.length]=t,e[135]=128|e[135],n[n.length-1]=e}if(136===r.length){const e=new Uint8Array(136);e[0]=t,e[135]=128,n.push(e)}return n.map(ks)}(e,1)),new Uint8Array([t[1],t[1]>>-24,t[1]>>-16,t[1]>>-8,t[0],t[0]>>8,t[0]>>16,t[0]>>24,t[3],t[3]>>-24,t[3]>>-16,t[3]>>-8,t[2],t[2]>>8,t[2]>>16,t[2]>>24,t[5],t[5]>>-24,t[5]>>-16,t[5]>>-8,t[4],t[4]>>8,t[4]>>16,t[4]>>24,t[7],t[7]>>-24,t[7]>>-16,t[7]>>-8,t[6],t[6]>>8,t[6]>>16,t[6]>>24]);var t}function xs(e){for(let t=0;t<24;t++){const n=e[0]^e[10]^e[20]^e[30]^e[40],r=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],i=e[3]^e[13]^e[23]^e[33]^e[43],s=e[4]^e[14]^e[24]^e[34]^e[44],a=e[5]^e[15]^e[25]^e[35]^e[45],c=e[6]^e[16]^e[26]^e[36]^e[46],u=e[7]^e[17]^e[27]^e[37]^e[47],l=e[8]^e[18]^e[28]^e[38]^e[48],f=e[9]^e[19]^e[29]^e[39]^e[49],d=l^(o<<1|i>>>31),h=f^(i<<1|o>>>31),p=n^(s<<1|a>>>31),m=r^(a<<1|s>>>31),g=o^(c<<1|u>>>31),y=i^(u<<1|c>>>31),w=s^(l<<1|f>>>31),b=a^(f<<1|l>>>31),v=c^(n<<1|r>>>31),E=u^(r<<1|n>>>31);e[0]^=d,e[1]^=h,e[2]^=p,e[3]^=m,e[4]^=g,e[5]^=y,e[6]^=w,e[7]^=b,e[8]^=v,e[9]^=E,e[10]^=d,e[11]^=h,e[12]^=p,e[13]^=m,e[14]^=g,e[15]^=y,e[16]^=w,e[17]^=b,e[18]^=v,e[19]^=E,e[20]^=d,e[21]^=h,e[22]^=p,e[23]^=m,e[24]^=g,e[25]^=y,e[26]^=w,e[27]^=b,e[28]^=v,e[29]^=E,e[30]^=d,e[31]^=h,e[32]^=p,e[33]^=m,e[34]^=g,e[35]^=y,e[36]^=w,e[37]^=b,e[38]^=v,e[39]^=E,e[40]^=d,e[41]^=h,e[42]^=p,e[43]^=m,e[44]^=g,e[45]^=y,e[46]^=w,e[47]^=b,e[48]^=v,e[49]^=E;const _=e[0],x=e[1],k=e[2]<<1|e[3]>>>31,A=e[3]<<1|e[2]>>>31,I=e[5]<<30|e[4]>>>2,$=e[4]<<30|e[5]>>>2,B=e[6]<<28|e[7]>>>4,z=e[7]<<28|e[6]>>>4,S=e[8]<<27|e[9]>>>5,O=e[9]<<27|e[8]>>>5,T=e[11]<<4|e[10]>>>28,N=e[10]<<4|e[11]>>>28,R=e[13]<<12|e[12]>>>20,U=e[12]<<12|e[13]>>>20,P=e[14]<<6|e[15]>>>26,F=e[15]<<6|e[14]>>>26,C=e[17]<<23|e[16]>>>9,L=e[16]<<23|e[17]>>>9,M=e[18]<<20|e[19]>>>12,D=e[19]<<20|e[18]>>>12,Z=e[20]<<3|e[21]>>>29,j=e[21]<<3|e[20]>>>29,q=e[22]<<10|e[23]>>>22,G=e[23]<<10|e[22]>>>22,H=e[25]<<11|e[24]>>>21,V=e[24]<<11|e[25]>>>21,K=e[26]<<25|e[27]>>>7,W=e[27]<<25|e[26]>>>7,J=e[29]<<7|e[28]>>>25,X=e[28]<<7|e[29]>>>25,Y=e[31]<<9|e[30]>>>23,Q=e[30]<<9|e[31]>>>23,ee=e[33]<<13|e[32]>>>19,te=e[32]<<13|e[33]>>>19,ne=e[34]<<15|e[35]>>>17,re=e[35]<<15|e[34]>>>17,oe=e[36]<<21|e[37]>>>11,ie=e[37]<<21|e[36]>>>11,se=e[38]<<8|e[39]>>>24,ae=e[39]<<8|e[38]>>>24,ce=e[40]<<18|e[41]>>>14,ue=e[41]<<18|e[40]>>>14,le=e[42]<<2|e[43]>>>30,fe=e[43]<<2|e[42]>>>30,de=e[45]<<29|e[44]>>>3,he=e[44]<<29|e[45]>>>3,pe=e[47]<<24|e[46]>>>8,me=e[46]<<24|e[47]>>>8,ge=e[48]<<14|e[49]>>>18,ye=e[49]<<14|e[48]>>>18;e[0]=_^~R&H,e[1]=x^~U&V,e[2]=R^~H&oe,e[3]=U^~V&ie,e[4]=H^~oe&ge,e[5]=V^~ie&ye,e[6]=oe^~ge&_,e[7]=ie^~ye&x,e[8]=ge^~_&R,e[9]=ye^~x&U,e[10]=B^~M&Z,e[11]=z^~D&j,e[12]=M^~Z&ee,e[13]=D^~j&te,e[14]=Z^~ee&de,e[15]=j^~te&he,e[16]=ee^~de&B,e[17]=te^~he&z,e[18]=de^~B&M,e[19]=he^~z&D,e[20]=k^~P&K,e[21]=A^~F&W,e[22]=P^~K&se,e[23]=F^~W&ae,e[24]=K^~se&ce,e[25]=W^~ae&ue,e[26]=se^~ce&k,e[27]=ae^~ue&A,e[28]=ce^~k&P,e[29]=ue^~A&F,e[30]=S^~T&q,e[31]=O^~N&G,e[32]=T^~q&ne,e[33]=N^~G&re,e[34]=q^~ne&pe,e[35]=G^~re&me,e[36]=ne^~pe&S,e[37]=re^~me&O,e[38]=pe^~S&T,e[39]=me^~O&N,e[40]=I^~C&J,e[41]=$^~L&X,e[42]=C^~J&Y,e[43]=L^~X&Q,e[44]=J^~Y&le,e[45]=X^~Q&fe,e[46]=Y^~le&I,e[47]=Q^~fe&$,e[48]=le^~I&C,e[49]=fe^~$&L,e[0]^=Es[2*t],e[1]^=Es[2*t+1]}}function ks(e){const t=[];for(let n=0;n<e.length;n+=4)t.push(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24);return t}var As=new TextDecoder,Is=new TextEncoder,$s=/^(0x)?[0-9a-fA-F]*$/i;var Bs=class e{bytes;length;constructor(t,n){if(!t)throw new Error(`Bytes#constructor: constructor parameter is falsy: ${t}`);if(t instanceof e)this.bytes=t.bytes;else if("string"==typeof t){if(!$s.test(t)||t.replace(/^0x/i,"").length%2!=0)throw new Error(`Bytes#constructor: invalid hex string: ${t}`);this.bytes=ls(t)}else if(t instanceof ArrayBuffer)this.bytes=new Uint8Array(t);else if(t instanceof Uint8Array)this.bytes=t;else{const e=t;if("object"!=typeof(r=e)||null===r||"function"!=typeof r.toHex)throw new Error("Bytes#constructor: unsupported type: "+typeof t);this.bytes=ls(e.toHex())}var r;if(this.length=this.bytes.length,void 0!==n)if(Array.isArray(n)){if(!n.includes(this.length))throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${n.join(" or ")}`)}else if(this.length!==n)throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${n}`)}static keccak256(t){return new e(_s(new e(t).toUint8Array()))}static concat(...t){const n=t.map(t=>t instanceof e?t.toUint8Array():t),r=n.reduce((e,t)=>e+t.length,0),o=new Uint8Array(r);let i=0;for(const e of n)o.set(e,i),i+=e.length;return o}static fromUtf8(t){return new e(Is.encode(t))}static fromSlice(t,n,r){return new e(void 0===r?t.slice(n):t.slice(n,n+r))}offset(e){return new Uint8Array(this.bytes.slice(e))}toUint8Array(){return new Uint8Array(this.bytes)}toHex(){return as(this.bytes)}toBase64(){return function(e){return ds(e,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}(this.bytes)}toBase32(){return ps(this.bytes)}toString(){return this.toHex()}toUtf8(){return As.decode(this.bytes)}toJSON(){return JSON.parse(this.toUtf8())}equals(t){return this.toHex()===new e(t).toHex()}represent(){return this.toHex()}},zs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}},Ss=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function Os(e){if(e<=0n||e>=Ss)throw new Error("Invalid private key");const t=rs.Point.BASE.multiply(e);return[t.x,t.y]}function Ts(e){const t=new Uint8Array(20),n=_s(Bs.concat(cs(e[0]),cs(e[1])));return t.set(n.subarray(12)),t}var Ns=class extends Bs{static LENGTH=20;constructor(e){super(e,20)}toChecksum(){return function(e){const t=as(e),n=as(_s(Uint8Array.from(t,e=>e.charCodeAt(0))));let r="0x";for(let e=0;e<t.length;e++)r+=parseInt(n.charAt(e),16)>7?t.charAt(e).toUpperCase():t.charAt(e);return r}(this.bytes)}},Rs=new Uint8Array(8).fill(255,0,8),Us=class e extends Bs{static LENGTH=8;static MINUS_ONE=new e(Rs);constructor(e){super(e,8)}static fromBigInt(t){return new e(bs(t,"BE"))}toBigInt(){return vs(this.bytes,"BE")}next(){return as(this.bytes)===as(Rs)?e.fromBigInt(0n):e.fromBigInt(this.toBigInt()+1n)}},Ps=new TextEncoder,Fs=class e extends Bs{static LENGTH=32;constructor(e){super(e,32)}static fromString(t){return new e(_s(Ps.encode(t)))}},Cs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}};function Ls(e,t){const n=rs.sign(_s(e),t,{prehash:!1}),r=0===n.recovery?27n:28n;return[n.r,n.s,r]}function Ms(e,t,n,r){const o=27n===r?0:1,i=new rs.Signature(t,n,o).recoverPublicKey(_s(e));return[i.x,i.y]}var Ds=class extends Bs{static LENGTH=64;constructor(e){const t=new Bs(e);if(33===t.length){const[e,n]=function(e){if(33!==e.length||2!==e[0]&&3!==e[0])throw new Error("Invalid compressed public key");const t=rs.Point.fromBytes(e);return[t.x,t.y]}(t.toUint8Array());super(Bs.concat(cs(e),cs(n)),64)}else super(e,64)}address(){const e=us(this.bytes.slice(0,32)),t=us(this.bytes.slice(32,64));return new Ns(Ts([e,t]))}toCompressedUint8Array(){const e=us(this.bytes.slice(0,32)),t=us(this.bytes.slice(32,64));return n=[e,t],rs.Point.fromAffine({x:n[0],y:n[1]}).toBytes(!0);var n}toCompressedHex(){return as(this.toCompressedUint8Array())}},Zs=new TextEncoder,js=Zs.encode("Ethereum Signed Message:\n32");function qs(e){const t=e instanceof Uint8Array?e:Zs.encode(e);return Bs.concat(js,_s(t))}var Gs=class e extends Bs{static LENGTH=65;constructor(e){super(e,65)}static fromSlice(t,n){return new e(t.slice(n,n+e.LENGTH))}recoverPublicKey(e){const t=us(this.bytes.slice(0,32)),n=us(this.bytes.slice(32,64)),r=BigInt(this.bytes[64]),[o,i]=Ms(qs(e),t,n,r);return new Ds(Bs.concat(cs(o),cs(i)))}isValid(e,t){return this.recoverPublicKey(e).address().equals(t)}},Hs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}publicKey(){const[e,t]=Os(this.toBigInt());return new Ds(Bs.concat(cs(e),cs(t)))}sign(e){const[t,n,r]=Ls(qs(e),this.toBigInt());return new Gs(Bs.concat(cs(t),cs(n),new Uint8Array([Number(r)])))}toBigInt(){return us(this.bytes)}};var Vs=class e extends Bs{static LENGTH=32;constructor(e){"string"==typeof e&&e.startsWith("bah5")?super(function(e){const t=hs(e.toUpperCase().slice(1)),n=t[1];if(250!==n&&251!==n)throw new Error("Unknown codec");return t.slice(-32)}(e),32):super(e,[32,64])}toCid(e){return`b${ps(Bs.concat(new Uint8Array([1]),new Uint8Array(["feed"===e?251:250]),new Uint8Array([1]),new Uint8Array([27]),new Uint8Array([32]))).replace(/=+$/,"")}${this.toBase32().replace(/=+$/,"")}`.toLowerCase()}static isValid(t){try{return new e(t),!0}catch{return!1}}},Ks=class e extends Bs{static LENGTH=8;constructor(e){super(e,8)}static fromBigInt(t){return new e(bs(t,"LE"))}toBigInt(){return vs(this.bytes,"LE")}static fromSlice(t,n){return new e(t.slice(n,n+e.LENGTH))}},Ws=new TextEncoder,Js=class e extends Bs{static LENGTH=32;constructor(e){super(e,32)}static fromString(t){return new e(_s(Ws.encode(t)))}},Xs=class extends Bs{static LENGTH=32;constructor(e){super(e,32)}},Ys=class{cursor=0;buffer;constructor(e){this.buffer=e}read(e){const t=this.buffer.subarray(this.cursor,this.cursor+e);return this.cursor+=e,t}max(){return this.buffer.length-this.cursor}},Qs=class{cursor=0;buffer;constructor(e){this.buffer=e}write(e){const t=Math.min(this.max(),e.max());return this.buffer.set(e.read(t),this.cursor),this.cursor+=t,t}max(){return this.buffer.length-this.cursor}};function ea(e,t,n){const r=new Uint8Array(n.length),o=new Uint8Array(36);o.set(e);for(let e=0,i=0;i<n.length;e++,i+=32){const s=t+e>>>0;o[32]=255&s,o[33]=s>>>8&255,o[34]=s>>>16&255,o[35]=s>>>24&255;const a=_s(_s(o)),c=Math.min(i+32,n.length);for(let e=i;e<c;e++)r[e]=n[e]^a[e-i]}return r}var ta=4096;function na(e){const t=e.subarray(0,8),n=function(e){if(e.length>ta)throw new Error(`payload size ${e.length} exceeds maximum chunk payload size 4096`);const t=new Uint8Array(ta);t.set(e);let n=os(t,32);for(;n.length>1;){const e=[];for(let t=0;t<n.length;t+=2)e.push(_s(Bs.concat(n[t],n[t+1])));n=e}return n[0]}(e.subarray(8));return new Vs(_s(Bs.concat(t,n)))}ls("dc5b20847f43d67928f49cd4f85d696b5a7617b5");var ra=Fs.LENGTH,oa=Fs.LENGTH+65,ia=oa+Ks.LENGTH,sa=(new TextEncoder).encode("Ethereum Signed Message:\n32");function aa(e,t){const n=_s(Bs.concat(e,t));return Bs.concat(sa,n)}function ca(e,t){const n=new Fs(e),r=new Ns(t);return new Vs(_s(Bs.concat(n.toUint8Array(),r.toUint8Array())))}function ua(e,t,n){const r=new Fs(t),o=function(e,t,n){const[r,o,i]=Ls(aa(e,t),n);return Bs.concat(cs(r),cs(o),new Uint8Array([Number(i)]))}(r.toUint8Array(),e.address.toUint8Array(),n),i=new Ns(Ts(Os(n))),s=ca(r,i);return{data:Bs.concat(r.toUint8Array(),o,e.data),identifier:r,signature:new Gs(o),span:e.span,payload:e.payload,address:s,owner:i}}function la(e,t){const n=e instanceof Bs?e.toUint8Array():e,r=new Vs(t),o=new Fs(Bs.fromSlice(n,0,Fs.LENGTH)),i=n.slice(ra,ra+65),s=na(n.slice(oa)),a=new Ns(function(e,t,n){const r=us(n.subarray(0,32)),o=us(n.subarray(32,64)),i=BigInt(n[64]);return Ts(Ms(aa(e,t),r,o,i))}(o.toUint8Array(),s.toUint8Array(),i)),c=ca(o,a);if(!c.equals(r))throw new Error("SOC data does not match given address");const u=Ks.fromSlice(n,oa),l=Bs.fromSlice(n,ia);return{data:n,identifier:o,signature:new Gs(i),span:u,payload:l,address:c,owner:a}}function fa(e,t){if("string"==typeof e&&(e=Bs.fromUtf8(e)),e.length<1||e.length>4096)throw new RangeError(`payload size ${e.length} exceeds limits [1, 4096]`);const n=t?"bigint"==typeof t?Ks.fromBigInt(t):t:Ks.fromBigInt(BigInt(e.length)),r=new Bs(e),o=Bs.concat(n.toUint8Array(),r.toUint8Array()),i={data:o,span:n,payload:r,address:na(o),toSingleOwnerChunk:(e,t)=>ua(i,e,new Hs(t).toBigInt())};return i}function da(e){const t=new Bs(e);return fa(t.toUint8Array().slice(Ks.LENGTH),Ks.fromSlice(t.toUint8Array(),0))}var ha=class{span;writer;constructor(e=0n){this.span=e,this.writer=new Qs(new Uint8Array(4096))}build(){return Bs.concat(bs(this.span,"LE"),this.writer.buffer)}hash(){return na(this.build())}encryptedHash(e){e||(e=new Uint8Array(32),crypto.getRandomValues(e));const t=function(e,t){return ea(e,128,t)}(e,bs(this.span,"LE")),n=function(e,t){return ea(e,0,t)}(e,this.writer.buffer);return{address:na(Bs.concat(t,n)),key:e}}},pa=class e{static NOOP=async e=>[];refSize;encrypted;maxShards;chunks;counters=[1];pending=[[]];onBatch;onIntermediateChunk;hasParity=[!1];pendingEntries=[];constructor(e,t,n=!1,r){this.encrypted=n,this.refSize=n?64:32,this.maxShards=t??4096/this.refSize,this.chunks=[new ha],this.onBatch=e,this.onIntermediateChunk=r}static async root(t){const n=new e(e.NOOP);return await n.append(t),n.finalize()}static async encryptedRoot(t){const n=new e(e.NOOP,void 0,!0);await n.append(t);return(await n.finalize()).encryptedHash()}async append(e,t=0,n=0n){const r=new Ys(e);for(;r.max()>0;){(0===this.chunks[t].writer.max()||n&&this.chunks[t].writer.max()<e.length)&&await this.elevate(t);const o=this.chunks[t].writer.write(r);n?this.chunks[t].span+=n:this.chunks[0].span+=BigInt(o)}}async elevate(e){this.counters[e]=(this.counters[e]+1)%(4096/this.refSize),this.pending[e]||(this.pending[e]=[]),await this.sealParities(e);const t=this.chunks[e].span;if(e>=1&&this.onIntermediateChunk&&(this.onIntermediateChunk(this.chunks[e],this.hasParity[e]??!1),this.hasParity[e]=!1),this.encrypted){const{address:n,key:r}=this.chunks[e].encryptedHash(),o=new Uint8Array(64);o.set(n.toUint8Array()),o.set(r,32),this.pending[e].push({entry:{chunk:this.chunks[e],key:r},ref:o,span:t})}else this.pending[e].push({entry:{chunk:this.chunks[e]},ref:this.chunks[e].hash().toUint8Array(),span:t});this.chunks[e]=new ha,this.pending[e].length>=this.maxShards&&await this.flushBatch(e)}async sealParities(e){const t=this.pendingEntries[e];if(!t?.length)return;this.pendingEntries[e]=[];const n=await this.onBatch(t);if(n.length>0){this.hasParity[e]=!0;for(const{chunk:t}of n)this.chunks[e].writer.write(new Ys(t.hash().toUint8Array()))}}async flushBatch(e){this.chunks[e+1]||(this.chunks.push(new ha),this.counters.push(1),this.pending.push([]),this.hasParity.push(!1));const t=this.pending[e];this.pending[e]=[];for(const{ref:n,span:r}of t)await this.append(n,e+1,r);this.pendingEntries[e+1]||(this.pendingEntries[e+1]=[]),this.pendingEntries[e+1].push(...t.map(e=>e.entry)),t.length>=this.maxShards&&await this.sealParities(e+1)}async finalize(e=0){return this.pending[e]?.length&&await this.flushBatch(e),this.chunks[e+1]?1===this.counters[e]?(await this.elevate(e+1),await this.flushBatch(e+1),this.chunks[e+1]=this.chunks[e],this.finalize(e+1)):(await this.elevate(e),await this.flushBatch(e),this.finalize(e+1)):(await this.sealParities(e),e>=1&&this.onIntermediateChunk&&this.onIntermediateChunk(this.chunks[e],this.hasParity[e]??!1),this.chunks[e])}};function ma(e,t){const n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r%t.length];return n}var ga=new TextEncoder,ya=new TextDecoder,wa=new Uint8Array([47]),ba=ls("5768b3b6a7db56d21d1abff40d41cebfc83448fed8d7e9b06ec0d3b073f28f7b");function va(e,t){const n=Math.floor(t/8),r=t%8;e[n]=e[n]|1<<r}function Ea(e,t){const n=t%8;return 1==(e[Math.floor(t/8)]>>n&1)}var _a=class e{obfuscationKey=new Uint8Array(32);selfAddress=null;targetAddress=new Uint8Array(32);metadata=null;path=new Uint8Array(0);forks=new Map;parent=null;type=null;encrypt=!1;constructor(e){e?.encrypt&&(this.encrypt=!0),e?.targetAddress?this.targetAddress=e.targetAddress:this.encrypt&&(this.targetAddress=new Uint8Array(64)),e?.selfAddress&&(this.selfAddress=e.selfAddress),e?.metadata&&(this.metadata=e.metadata),e?.obfuscationKey&&(this.obfuscationKey=e.obfuscationKey),e?.path&&(this.path=e.path),e?.parent&&(this.parent=e.parent),this.type=e?.type??null}get fullPath(){return Bs.concat(this.parent?.fullPath??new Uint8Array(0),this.path)}get fullPathString(){return ya.decode(this.fullPath)}async marshal(){for(const e of this.forks.values())e.node.selfAddress||(e.node.selfAddress=(await e.node.calculateSelfAddress()).toUint8Array());this.encrypt&&is(this.obfuscationKey,new Uint8Array(32))&&(this.obfuscationKey=new Uint8Array(32),crypto.getRandomValues(this.obfuscationKey));const e=!is(this.targetAddress,new Uint8Array(this.targetAddress.length));let t=0;if(e)t=this.targetAddress.length;else for(const e of this.forks.values())if(e.node.selfAddress&&e.node.selfAddress.length>0){t=e.node.selfAddress.length;break}const n=new Uint8Array(32);n.set(ba,0),n.set(ms(t),31);const r=e?this.targetAddress:new Uint8Array(t),o=new Uint8Array(32);for(const e of this.forks.keys())va(o,e);const i=[];for(let e=0;e<256;e++)Ea(o,e)&&i.push(this.forks.get(e).marshal());const s=ma(Bs.concat(n,r,o,...i),this.obfuscationKey);return Bs.concat(this.obfuscationKey,s)}static unmarshalFromData(t,n){if(t.length<64)throw new Error("MantarayNode#unmarshalFromData data too short");const r=t.subarray(0,32),o=ma(t.subarray(32),r),i=new Ys(o);if(!is(i.read(31),ba.slice(0,31)))throw new Error("MantarayNode#unmarshalFromData invalid version hash");const s=gs(i.read(1)),a=i.read(s),c=new e({selfAddress:n,targetAddress:a,obfuscationKey:r}),u=i.read(32),l=0===s?32:s;for(let e=0;e<256;e++)if(Ea(u,e)){const t=Aa.unmarshal(i,l);c.forks.set(e,t),t.node.parent=c}return c}addFork(t,n,r){this.selfAddress=null,this.type=null,t=t instanceof Uint8Array?t:ga.encode(t);let o=this;for(;t.length;){const i=t.slice(0,30),s=0===(t=t.slice(30)).length,[a,c]=o.findClosest(i),u=i.slice(c.length);if(c.length&&(o=a),!u.length)continue;const l=new Aa(u,new e({targetAddress:s?new Vs(n).toUint8Array():void 0,metadata:s?r:void 0,path:u,encrypt:this.encrypt})),f=a.forks.get(u[0]);if(f){const e=Aa.split(l,f);o.forks.set(u[0],e),e.node.parent=o}else o.forks.set(u[0],l),l.node.parent=o;o.selfAddress=null,o.type=null,o=l.node}}removeFork(e){if(this.selfAddress=null,this.type=null,0===(e=e instanceof Uint8Array?e:ga.encode(e)).length)throw new Error("MantarayNode#removeFork path cannot be empty");const t=this.find(e);if(!t)throw new Error("MantarayNode#removeFork fork not found");const[n,r]=this.findClosest(e.slice(0,e.length-1));n.forks.delete(e.slice(r.length)[0]);for(const e of t.forks.values())n.addFork(Bs.concat(t.path,e.prefix),e.node.targetAddress,e.node.metadata)}async calculateSelfAddress(){if(this.selfAddress)return new Vs(this.selfAddress);if(this.encrypt)throw new Error("MantarayNode#calculateSelfAddress is not supported for encrypted nodes - use saveRecursively");return(await pa.root(await this.marshal())).hash()}async saveRecursively(e){for(const t of this.forks.values())await t.node.saveRecursively(e);const t=new pa(async t=>{for(const{chunk:n,key:r}of t)await e(n,r);return[]},void 0,this.encrypt);await t.append(await this.marshal());const n=await t.finalize();if(this.encrypt){const{address:t,key:r}=n.encryptedHash();return await e(n,r),this.selfAddress=Bs.concat(t.toUint8Array(),r),{reference:this.selfAddress,rootChunk:n,encryptionKey:r}}return await e(n),this.selfAddress=n.hash().toUint8Array(),{reference:this.selfAddress,rootChunk:n}}find(e){const t=e instanceof Uint8Array?e:ga.encode(e),[n,r]=this.findClosest(t);return r.length===t.length?n:null}findClosest(e,t=new Uint8Array){if(0===(e=e instanceof Uint8Array?e:ga.encode(e)).length)return[this,t];const n=this.forks.get(e[0]);return n&&ss(n.prefix,e).length===n.prefix.length?n.node.findClosest(e.slice(n.prefix.length),Bs.concat(t,n.prefix)):[this,t]}collect(e=[]){for(const t of this.forks.values())is(t.node.targetAddress,new Uint8Array(t.node.targetAddress.length))||e.push(t.node),t.node.collect(e);return e}collectAndMap(){const e={};for(const t of this.collect())e[t.fullPathString]=new Vs(t.targetAddress).toHex();return e}determineType(){let e=0;const t=new Uint8Array(this.targetAddress.length);return is(this.targetAddress,t)&&0!==this.forks.size||(e|=2),this.forks.size>0&&(e|=4),function(e,t,n=0){for(let r=n;r<e.length;r++)for(let n=0;n<t.length&&e[r+n]===t[n];n++)if(n===t.length-1)return r;return-1}(this.path,wa)>0&&(e|=8),this.metadata&&(e|=16),e}},xa=new TextEncoder,ka=new TextDecoder;var Aa=class e{prefix;node;constructor(e,t){this.prefix=e,this.node=t}static split(t,n){const r=ss(t.prefix,n.prefix);if(r.length===t.prefix.length){const e=n.prefix.slice(r.length);return n.node.path=n.prefix.slice(r.length),n.prefix=n.prefix.slice(r.length),n.node.parent=t.node,t.node.forks.set(e[0],n),t}if(r.length===n.prefix.length){const e=t.prefix.slice(r.length);return t.node.path=t.prefix.slice(r.length),t.prefix=t.prefix.slice(r.length),t.node.parent=n.node,n.node.forks.set(e[0],t),n}const o=new _a({path:r,encrypt:t.node.encrypt}),i=new e(t.prefix.slice(r.length),t.node),s=new e(n.prefix.slice(r.length),n.node);return t.node.path=t.prefix.slice(r.length),n.node.path=n.prefix.slice(r.length),t.prefix=t.prefix.slice(r.length),n.prefix=n.prefix.slice(r.length),o.forks.set(i.prefix[0],i),o.forks.set(s.prefix[0],s),i.node.parent=o,s.node.parent=o,new e(r,o)}marshal(){if(!this.node.selfAddress)throw new Error("Fork#marshal node.selfAddress is not set");const e=[];if(e.push(new Uint8Array([this.node.type??this.node.determineType()])),e.push(ms(this.prefix.length)),e.push(this.prefix),this.prefix.length<30&&e.push(new Uint8Array(30-this.prefix.length)),e.push(this.node.selfAddress),this.node.metadata){const t=function(e,t,n){const r=e.length%t;if(0===r)return e;const o=new Uint8Array(e.length+t-r).fill(n);return o.set(e,0),o}(Bs.concat(new Uint8Array([0,0]),xa.encode(JSON.stringify(this.node.metadata))),32,10);t.set(function(e,t){const n=new ArrayBuffer(2);return new DataView(n).setUint16(0,e,"LE"===t),new Uint8Array(n)}(t.length-2,"BE"),0),e.push(t)}return Bs.concat(...e)}static unmarshal(t,n){const r=gs(t.read(1)),o=gs(t.read(1)),i=t.read(o);o<30&&t.read(30-o);const s=t.read(n);let a;if(function(e,t){return(e&t)===t}(r,16)){const e=ys(t.read(2),"BE");if(e>t.max())throw new Error("Fork#unmarshal not enough bytes for metadata");a=JSON.parse(ka.decode(t.read(e)))}return new e(i,new _a({selfAddress:s,metadata:a,path:i,type:r}))}};function Ia(e,t,n){return e/Math.pow(2,t-n)}function $a(e){return 4096*2**e}function Ba(e){const t=e.match(/^([\d.]+)\s*(B|kB|MB|GB|TB|PB)$/);if(!t)throw new Error(`Invalid size format: ${e}`);return Math.ceil(parseFloat(t[1])*{B:1,kB:1e3,MB:1e6,GB:1e3**3,TB:1e3**4,PB:1e3**5}[t[2]])}var za,Sa=[[17,"0.00004089 GB"],[18,"0.00609 GB"],[19,"0.10249 GB"],[20,"0.62891 GB"],[21,"2.38 GB"],[22,"7.07 GB"],[23,"18.24 GB"],[24,"43.04 GB"],[25,"96.5 GB"],[26,"208.52 GB"],[27,"435.98 GB"],[28,"908.81 GB"],[29,"1870 GB"],[30,"3810 GB"],[31,"7730 GB"],[32,"15610 GB"],[33,"31430 GB"],[34,"63150 GB"]],Oa=[[[17,"44.70 kB"],[18,"6.66 MB"],[19,"112.06 MB"],[20,"687.62 MB"],[21,"2.60 GB"],[22,"7.73 GB"],[23,"19.94 GB"],[24,"47.06 GB"],[25,"105.51 GB"],[26,"227.98 GB"],[27,"476.68 GB"],[28,"993.65 GB"],[29,"2.04 TB"],[30,"4.17 TB"],[31,"8.45 TB"],[32,"17.07 TB"],[33,"34.36 TB"],[34,"69.04 TB"],[35,"138.54 TB"],[36,"277.72 TB"],[37,"556.35 TB"],[38,"1.11 PB"],[39,"2.23 PB"],[40,"4.46 PB"],[41,"8.93 PB"]],[[17,"41.56 kB"],[18,"6.19 MB"],[19,"104.18 MB"],[20,"639.27 MB"],[21,"2.41 GB"],[22,"7.18 GB"],[23,"18.54 GB"],[24,"43.75 GB"],[25,"98.09 GB"],[26,"211.95 GB"],[27,"443.16 GB"],[28,"923.78 GB"],[29,"1.90 TB"],[30,"3.88 TB"],[31,"7.86 TB"],[32,"15.87 TB"],[33,"31.94 TB"],[34,"64.19 TB"],[35,"128.80 TB"],[36,"258.19 TB"],[37,"517.23 TB"],[38,"1.04 PB"],[39,"2.07 PB"],[40,"4.15 PB"],[41,"8.30 PB"]],[[17,"37.37 kB"],[18,"5.57 MB"],[19,"93.68 MB"],[20,"574.81 MB"],[21,"2.17 GB"],[22,"6.46 GB"],[23,"16.67 GB"],[24,"39.34 GB"],[25,"88.20 GB"],[26,"190.58 GB"],[27,"398.47 GB"],[28,"830.63 GB"],[29,"1.71 TB"],[30,"3.49 TB"],[31,"7.07 TB"],[32,"14.27 TB"],[33,"28.72 TB"],[34,"57.71 TB"],[35,"115.81 TB"],[36,"232.16 TB"],[37,"465.07 TB"],[38,"931.23 TB"],[39,"1.86 PB"],[40,"3.73 PB"],[41,"7.46 PB"]],[[17,"33.88 kB"],[18,"5.05 MB"],[19,"84.92 MB"],[20,"521.09 MB"],[21,"1.97 GB"],[22,"5.86 GB"],[23,"15.11 GB"],[24,"35.66 GB"],[25,"79.96 GB"],[26,"172.77 GB"],[27,"361.23 GB"],[28,"753.00 GB"],[29,"1.55 TB"],[30,"3.16 TB"],[31,"6.41 TB"],[32,"12.93 TB"],[33,"26.04 TB"],[34,"52.32 TB"],[35,"104.99 TB"],[36,"210.46 TB"],[37,"421.61 TB"],[38,"844.20 TB"],[39,"1.69 PB"],[40,"3.38 PB"],[41,"6.77 PB"]],[[17,"13.27 kB"],[18,"1.98 MB"],[19,"33.27 MB"],[20,"204.14 MB"],[21,"771.13 MB"],[22,"2.29 GB"],[23,"5.92 GB"],[24,"13.97 GB"],[25,"31.32 GB"],[26,"67.68 GB"],[27,"141.51 GB"],[28,"294.99 GB"],[29,"606.90 GB"],[30,"1.24 TB"],[31,"2.51 TB"],[32,"5.07 TB"],[33,"10.20 TB"],[34,"20.50 TB"],[35,"41.13 TB"],[36,"82.45 TB"],[37,"165.17 TB"],[38,"330.72 TB"],[39,"661.97 TB"],[40,"1.32 PB"],[41,"2.65 PB"]]],Ta=[[[17,"44.35 kB"],[18,"6.61 MB"],[19,"111.18 MB"],[20,"682.21 MB"],[21,"2.58 GB"],[22,"7.67 GB"],[23,"19.78 GB"],[24,"46.69 GB"],[25,"104.68 GB"],[26,"226.19 GB"],[27,"472.93 GB"],[28,"985.83 GB"],[29,"2.03 TB"],[30,"4.14 TB"],[31,"8.39 TB"],[32,"16.93 TB"],[33,"34.09 TB"],[34,"68.50 TB"],[35,"137.45 TB"],[36,"275.53 TB"],[37,"551.97 TB"],[38,"1.11 PB"],[39,"2.21 PB"],[40,"4.43 PB"],[41,"8.86 PB"]],[[17,"40.89 kB"],[18,"6.09 MB"],[19,"102.49 MB"],[20,"628.91 MB"],[21,"2.38 GB"],[22,"7.07 GB"],[23,"18.24 GB"],[24,"43.04 GB"],[25,"96.50 GB"],[26,"208.52 GB"],[27,"435.98 GB"],[28,"908.81 GB"],[29,"1.87 TB"],[30,"3.81 TB"],[31,"7.73 TB"],[32,"15.61 TB"],[33,"31.43 TB"],[34,"63.15 TB"],[35,"126.71 TB"],[36,"254.01 TB"],[37,"508.85 TB"],[38,"1.02 PB"],[39,"2.04 PB"],[40,"4.08 PB"],[41,"8.17 PB"]],[[17,"36.73 kB"],[18,"5.47 MB"],[19,"92.07 MB"],[20,"564.95 MB"],[21,"2.13 GB"],[22,"6.35 GB"],[23,"16.38 GB"],[24,"38.66 GB"],[25,"86.69 GB"],[26,"187.31 GB"],[27,"391.64 GB"],[28,"816.39 GB"],[29,"1.68 TB"],[30,"3.43 TB"],[31,"6.94 TB"],[32,"14.02 TB"],[33,"28.23 TB"],[34,"56.72 TB"],[35,"113.82 TB"],[36,"228.18 TB"],[37,"457.10 TB"],[38,"915.26 TB"],[39,"1.83 PB"],[40,"3.67 PB"],[41,"7.34 PB"]],[[17,"33.26 kB"],[18,"4.96 MB"],[19,"83.38 MB"],[20,"511.65 MB"],[21,"1.93 GB"],[22,"5.75 GB"],[23,"14.84 GB"],[24,"35.02 GB"],[25,"78.51 GB"],[26,"169.64 GB"],[27,"354.69 GB"],[28,"739.37 GB"],[29,"1.52 TB"],[30,"3.10 TB"],[31,"6.29 TB"],[32,"12.70 TB"],[33,"25.57 TB"],[34,"51.37 TB"],[35,"103.08 TB"],[36,"206.65 TB"],[37,"413.98 TB"],[38,"828.91 TB"],[39,"1.66 PB"],[40,"3.32 PB"],[41,"6.64 PB"]],[[17,"13.17 kB"],[18,"1.96 MB"],[19,"33.01 MB"],[20,"202.53 MB"],[21,"765.05 MB"],[22,"2.28 GB"],[23,"5.87 GB"],[24,"13.86 GB"],[25,"31.08 GB"],[26,"67.15 GB"],[27,"140.40 GB"],[28,"292.67 GB"],[29,"602.12 GB"],[30,"1.23 TB"],[31,"2.49 TB"],[32,"5.03 TB"],[33,"10.12 TB"],[34,"20.34 TB"],[35,"40.80 TB"],[36,"81.80 TB"],[37,"163.87 TB"],[38,"328.11 TB"],[39,"656.76 TB"],[40,"1.31 PB"],[41,"2.63 PB"]]];function Na(e,t,n){if(e<17)return 0;if(void 0!==t&&void 0!==n){const r=(t?Ta:Oa)[n],o=r?.find(([t])=>t===e);if(o)return Ba(o[1])}else{const t=Sa.find(([t])=>t===e);if(t)return Ba(t[1])}return Math.ceil(.9*$a(e))}function Ra(e,t,n){if(void 0!==t&&void 0!==n){const r=(t?Ta:Oa)[n],o=r?.find(([,t])=>e<=Ba(t));if(o)return o[0]}else for(const[t,n]of Sa)if(e<=Ba(n))return t;return 35}function Ua(e){return function(e,t,n,r){if(65!==e.length)throw new Error("invalid signature length");if(32!==t.length)throw new Error("invalid batch ID length");if(8!==n.length)throw new Error("invalid timestamp length");if(8!==r.length)throw new Error("invalid index length");return new Bs(Bs.concat(t,r,n,e))}(e.signature.toUint8Array(),e.batchId.toUint8Array(),e.timestamp,e.index)}function Pa(e,t,n,r,o=Date.now()){const i=new Hs(e),s=new zs(t),a=ys(n,"BE"),c=Bs.concat(ws(a,"BE"),ws(r,"BE")),u=bs(1000000n*BigInt(o),"BE"),l=i.sign(Bs.concat(n,s.toUint8Array(),c,u));return{batchId:s,index:c,issuer:i.publicKey().address(),signature:l,timestamp:u}}function Fa(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:s,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const o=s.prototype,i=Object.keys(o);for(let e=0;e<i.length;e++){const t=i[e];t in n||(n[t]=o[t].bind(n))}}const o=n?.Parent??Object;class i extends o{}function s(e){var t;const o=n?.Parent?new i:this;r(o,e),(t=o._zod).deferred??(t.deferred=[]);for(const e of o._zod.deferred)e();return o}return Object.defineProperty(i,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class Ca extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class La extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}(za=globalThis).__zod_globalConfig??(za.__zod_globalConfig={});const Ma=globalThis.__zod_globalConfig;function Da(e){return Ma}function Za(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function ja(e,t){return"bigint"==typeof t?t.toString():t}function qa(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Ga(e){return null==e}function Ha(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const Va=Symbol("evaluating");function Ka(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Va)return void 0===r&&(r=Va,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Wa(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Ja(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Xa(e){return JSON.stringify(e)}const Ya="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Qa(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const ec=qa(()=>{if(Ma.jitless)return!1;if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function tc(e){if(!1===Qa(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==Qa(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function nc(e){return tc(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const rc=new Set(["string","number","symbol"]);function oc(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ic(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function sc(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const ac={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function cc(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function uc(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!1===e.issues[n]?.continue)return!0;return!1}function lc(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function fc(e){return"string"==typeof e?e:e?.message}function dc(e,t,n){const r=e.message?e.message:fc(e.inst?._zod.def?.error?.(e))??fc(t?.error?.(e))??fc(n.customError?.(e))??fc(n.localeError?.(e))??"Invalid input",{inst:o,continue:i,input:s,...a}=e;return a.path??(a.path=[]),a.message=r,t?.reportInput&&(a.input=s),a}function hc(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function pc(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const mc=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ja,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},gc=Fa("$ZodError",mc),yc=Fa("$ZodError",mc,{Parent:Error});const wc=e=>(t,n,r,o)=>{const i=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new Ca;if(s.issues.length){const t=new(o?.Err??e)(s.issues.map(e=>dc(e,i,Da())));throw Ya(t,o?.callee),t}return s.value},bc=wc(yc),vc=e=>async(t,n,r,o)=>{const i=r?{...r,async:!0}:{async:!0};let s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(o?.Err??e)(s.issues.map(e=>dc(e,i,Da())));throw Ya(t,o?.callee),t}return s.value},Ec=vc(yc),_c=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new Ca;return i.issues.length?{success:!1,error:new(e??gc)(i.issues.map(e=>dc(e,o,Da())))}:{success:!0,data:i.value}},xc=_c(yc),kc=e=>async(t,n,r)=>{const o=r?{...r,async:!0}:{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(e=>dc(e,o,Da())))}:{success:!0,data:i.value}},Ac=kc(yc),Ic=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return wc(e)(t,n,o)},$c=e=>(t,n,r)=>wc(e)(t,n,r),Bc=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return vc(e)(t,n,o)},zc=e=>async(t,n,r)=>vc(e)(t,n,r),Sc=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return _c(e)(t,n,o)},Oc=e=>(t,n,r)=>_c(e)(t,n,r),Tc=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return kc(e)(t,n,o)},Nc=e=>async(t,n,r)=>kc(e)(t,n,r),Rc=/^[cC][0-9a-z]{6,}$/,Uc=/^[0-9a-z]+$/,Pc=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Fc=/^[0-9a-vA-V]{20}$/,Cc=/^[A-Za-z0-9]{27}$/,Lc=/^[a-zA-Z0-9_-]{21}$/,Mc=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Dc=/^([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})$/,Zc=e=>e?new 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)$/,jc=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const qc=/^(?:(?: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])$/,Gc=/^(([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}|:))$/,Hc=/^((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])$/,Vc=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Kc=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Wc=/^[A-Za-z0-9_-]*$/,Jc=/^https?$/,Xc=/^\+[1-9]\d{6,14}$/,Yc="(?:(?:\\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])))",Qc=new RegExp(`^${Yc}$`);function eu(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const tu=/^-?\d+n?$/,nu=/^-?\d+$/,ru=/^-?\d+(?:\.\d+)?$/,ou=/^(?:true|false)$/i,iu=/^[^A-Z]*$/,su=/^[^a-z]*$/,au=Fa("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),cu={number:"number",bigint:"bigint",object:"date"},uu=Fa("$ZodCheckLessThan",(e,t)=>{au.init(e,t);const n=cu[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),lu=Fa("$ZodCheckGreaterThan",(e,t)=>{au.init(e,t);const n=cu[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),fu=Fa("$ZodCheckMultipleOf",(e,t)=>{au.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=e/t,r=Math.round(n),o=Number.EPSILON*Math.max(Math.abs(n),1);return Math.abs(n-r)<o?0:n-r}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),du=Fa("$ZodCheckNumberFormat",(e,t)=>{au.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,i]=ac[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=o,r.maximum=i,n&&(r.pattern=nu)}),e._zod.check=s=>{const a=s.value;if(n){if(!Number.isInteger(a))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});if(!Number.isSafeInteger(a))return void(a>0?s.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):s.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}))}a<o&&s.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),a>i&&s.issues.push({origin:"number",input:a,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),hu=Fa("$ZodCheckMaxLength",(e,t)=>{var n;au.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Ga(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const o=hc(r);n.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),pu=Fa("$ZodCheckMinLength",(e,t)=>{var n;au.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Ga(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const o=hc(r);n.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),mu=Fa("$ZodCheckLengthEquals",(e,t)=>{var n;au.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Ga(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,o=r.length;if(o===t.length)return;const i=hc(r),s=o>t.length;n.issues.push({origin:i,...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})}}),gu=Fa("$ZodCheckStringFormat",(e,t)=>{var n,r;au.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),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=()=>{})}),yu=Fa("$ZodCheckRegex",(e,t)=>{gu.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})}}),wu=Fa("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=iu),gu.init(e,t)}),bu=Fa("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=su),gu.init(e,t)}),vu=Fa("$ZodCheckIncludes",(e,t)=>{au.init(e,t);const n=oc(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),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})}}),Eu=Fa("$ZodCheckStartsWith",(e,t)=>{au.init(e,t);const n=new RegExp(`^${oc(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(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})}}),_u=Fa("$ZodCheckEndsWith",(e,t)=>{au.init(e,t);const n=new RegExp(`.*${oc(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(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})}}),xu=Fa("$ZodCheckOverwrite",(e,t)=>{au.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class ku{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Au={major:4,minor:4,patch:3},Iu=Fa("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Au;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,o=cc(e);for(const i of t){if(i._zod.def.when){if(uc(e))continue;if(!i._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,s=i._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new Ca;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(o||(o=cc(e,t)))});else{if(e.issues.length===t)continue;o||(o=cc(e,t))}}return r?r.then(()=>e):e},n=(n,o,i)=>{if(cc(n))return n.aborted=!0,n;const s=t(o,r,i);if(s instanceof Promise){if(!1===i.async)throw new Ca;return s.then(t=>e._zod.parse(t,i))}return e._zod.parse(s,i)};e._zod.run=(o,i)=>{if(i.skipChecks)return e._zod.parse(o,i);if("backward"===i.direction){const t=e._zod.parse({value:o.value,issues:[]},{...i,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,o,i)):n(t,o,i)}const s=e._zod.parse(o,i);if(s instanceof Promise){if(!1===i.async)throw new Ca;return s.then(e=>t(e,r,i))}return t(s,r,i)}}Ka(e,"~standard",()=>({validate:t=>{try{const n=xc(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return Ac(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}))}),$u=Fa("$ZodString",(e,t)=>{var n;Iu.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Bu=Fa("$ZodStringFormat",(e,t)=>{gu.init(e,t),$u.init(e,t)}),zu=Fa("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Dc),Bu.init(e,t)}),Su=Fa("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Zc(e))}else t.pattern??(t.pattern=Zc());Bu.init(e,t)}),Ou=Fa("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=jc),Bu.init(e,t)}),Tu=Fa("$ZodURL",(e,t)=>{Bu.init(e,t),e._zod.check=n=>{try{const r=n.value.trim();if(!t.normalize&&t.protocol?.source===Jc.source&&!/^https?:\/\//i.test(r))return void n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});const o=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.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&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(t.normalize?n.value=o.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Nu=Fa("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Bu.init(e,t)}),Ru=Fa("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Lc),Bu.init(e,t)}),Uu=Fa("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Rc),Bu.init(e,t)}),Pu=Fa("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Uc),Bu.init(e,t)}),Fu=Fa("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Pc),Bu.init(e,t)}),Cu=Fa("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Fc),Bu.init(e,t)}),Lu=Fa("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Cc),Bu.init(e,t)}),Mu=Fa("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=eu({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Yc}T(?:${r})$`)}(t)),Bu.init(e,t)}),Du=Fa("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Qc),Bu.init(e,t)}),Zu=Fa("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${eu(t)}$`)),Bu.init(e,t)}),ju=Fa("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Mc),Bu.init(e,t)}),qu=Fa("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=qc),Bu.init(e,t),e._zod.bag.format="ipv4"}),Gu=Fa("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Gc),Bu.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Hu=Fa("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Hc),Bu.init(e,t)}),Vu=Fa("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Vc),Bu.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Ku(e){if(""===e)return!0;if(/\s/.test(e))return!1;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Wu=Fa("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Kc),Bu.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Ku(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const Ju=Fa("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Wc),Bu.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!Wc.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return Ku(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Xu=Fa("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Xc),Bu.init(e,t)});const Yu=Fa("$ZodJWT",(e,t)=>{Bu.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&"JWT"!==o?.typ||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Qu=Fa("$ZodNumber",(e,t)=>{Iu.init(e,t),e._zod.pattern=e._zod.bag.pattern??ru,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const o=n.value;if("number"==typeof o&&!Number.isNaN(o)&&Number.isFinite(o))return n;const i="number"==typeof o?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),n}}),el=Fa("$ZodNumberFormat",(e,t)=>{du.init(e,t),Qu.init(e,t)}),tl=Fa("$ZodBoolean",(e,t)=>{Iu.init(e,t),e._zod.pattern=ou,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const o=n.value;return"boolean"==typeof o||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),nl=Fa("$ZodBigInt",(e,t)=>{Iu.init(e,t),e._zod.pattern=tu,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}}),rl=Fa("$ZodAny",(e,t)=>{Iu.init(e,t),e._zod.parse=e=>e}),ol=Fa("$ZodUnknown",(e,t)=>{Iu.init(e,t),e._zod.parse=e=>e}),il=Fa("$ZodNever",(e,t)=>{Iu.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function sl(e,t,n){e.issues.length&&t.issues.push(...lc(n,e.issues)),t.value[n]=e.value}const al=Fa("$ZodArray",(e,t)=>{Iu.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let e=0;e<o.length;e++){const s=o[e],a=t.element._zod.run({value:s,issues:[]},r);a instanceof Promise?i.push(a.then(t=>sl(t,n,e))):sl(a,n,e)}return i.length?Promise.all(i).then(()=>n):n}});function cl(e,t,n,r,o,i){const s=n in r;if(e.issues.length){if(o&&i&&!s)return;t.issues.push(...lc(n,e.issues))}s||o?void 0===e.value?s&&(t.value[n]=void 0):t.value[n]=e.value:e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]})}function ul(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function ll(e,t,n,r,o,i){const s=[],a=o.keySet,c=o.catchall._zod,u=c.def.type,l="optional"===c.optin,f="optional"===c.optout;for(const o in t){if("__proto__"===o)continue;if(a.has(o))continue;if("never"===u){s.push(o);continue}const i=c.run({value:t[o],issues:[]},r);i instanceof Promise?e.push(i.then(e=>cl(e,n,o,t,l,f))):cl(i,n,o,t,l,f)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const fl=Fa("$ZodObject",(e,t)=>{Iu.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=qa(()=>ul(t));Ka(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});const o=Qa,i=t.catchall;let s;e._zod.parse=(t,n)=>{s??(s=r.value);const a=t.value;if(!o(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=s.shape;for(const e of s.keys){const r=u[e],o="optional"===r._zod.optin,i="optional"===r._zod.optout,s=r._zod.run({value:a[e],issues:[]},n);s instanceof Promise?c.push(s.then(n=>cl(n,t,e,a,o,i))):cl(s,t,e,a,o,i)}return i?ll(c,a,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),dl=Fa("$ZodObjectJIT",(e,t)=>{fl.init(e,t);const n=e._zod.parse,r=qa(()=>ul(t));let o;const i=Qa,s=!Ma.jitless,a=s&&ec.value,c=t.catchall;let u;e._zod.parse=(l,f)=>{u??(u=r.value);const d=l.value;return i(d)?s&&a&&!1===f?.async&&!0!==f.jitless?(o||(o=(e=>{const t=new ku(["shape","payload","ctx"]),n=r.value,o=e=>{const t=Xa(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const i=Object.create(null);let s=0;for(const e of n.keys)i[e]="key_"+s++;t.write("const newResult = {};");for(const r of n.keys){const n=i[r],s=Xa(r),a=e[r],c="optional"===a?._zod?.optin,u="optional"===a?._zod?.optout;t.write(`const ${n} = ${o(r)};`),c&&u?t.write(`\n if (${n}.issues.length) {\n if (${s} in input) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `):c?t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `):t.write(`\n const ${n}_present = ${s} in input;\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n if (!${n}_present && !${n}.issues.length) {\n payload.issues.push({\n code: "invalid_type",\n expected: "nonoptional",\n input: undefined,\n path: [${s}]\n });\n }\n\n if (${n}_present) {\n if (${n}.value === undefined) {\n newResult[${s}] = undefined;\n } else {\n newResult[${s}] = ${n}.value;\n }\n }\n\n `)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,n)=>a(e,t,n)})(t.shape)),l=o(l,f),c?ll([],d,l,f,u,e):l):n(l,f):(l.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),l)}});function hl(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const o=e.filter(e=>!cc(e));return 1===o.length?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>dc(e,r,Da())))}),t)}const pl=Fa("$ZodUnion",(e,t)=>{Iu.init(e,t),Ka(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),Ka(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),Ka(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Ka(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>Ha(e.source)).join("|")})$`)}});const n=1===t.options.length?t.options[0]._zod.run:null;e._zod.parse=(r,o)=>{if(n)return n(r,o);let i=!1;const s=[];for(const e of t.options){const t=e._zod.run({value:r.value,issues:[]},o);if(t instanceof Promise)s.push(t),i=!0;else{if(0===t.issues.length)return t;s.push(t)}}return i?Promise.all(s).then(t=>hl(t,r,e,o)):hl(s,r,e,o)}}),ml=Fa("$ZodIntersection",(e,t)=>{Iu.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,o=t.left._zod.run({value:r,issues:[]},n),i=t.right._zod.run({value:r,issues:[]},n);return o instanceof Promise||i instanceof Promise?Promise.all([o,i]).then(([t,n])=>yl(e,t,n)):yl(e,o,i)}});function gl(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(tc(e)&&tc(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),o={...e,...t};for(const n of r){const r=gl(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};o[n]=r.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=gl(e[r],t[r]);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function yl(e,t,n){const r=new Map;let o;for(const n of t.issues)if("unrecognized_keys"===n.code){o??(o=n);for(const e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(const t of n.issues)if("unrecognized_keys"===t.code)for(const e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);const i=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(i.length&&o&&e.issues.push({...o,keys:i}),cc(e))return e;const s=gl(t.value,n.value);if(!s.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(s.mergeErrorPath)}`);return e.value=s.data,e}const wl=Fa("$ZodTuple",(e,t)=>{Iu.init(e,t);const n=t.items;e._zod.parse=(r,o)=>{const i=r.value;if(!Array.isArray(i))return r.issues.push({input:i,inst:e,expected:"tuple",code:"invalid_type"}),r;r.value=[];const s=[],a=bl(n,"optin"),c=bl(n,"optout");if(!t.rest){if(i.length<a)return r.issues.push({code:"too_small",minimum:a,inclusive:!0,input:i,inst:e,origin:"array"}),r;i.length>n.length&&r.issues.push({code:"too_big",maximum:n.length,inclusive:!0,input:i,inst:e,origin:"array"})}const u=new Array(n.length);for(let e=0;e<n.length;e++){const t=n[e]._zod.run({value:i[e],issues:[]},o);t instanceof Promise?s.push(t.then(t=>{u[e]=t})):u[e]=t}if(t.rest){let e=n.length-1;const a=i.slice(n.length);for(const n of a){e++;const i=t.rest._zod.run({value:n,issues:[]},o);i instanceof Promise?s.push(i.then(t=>vl(t,r,e))):vl(i,r,e)}}return s.length?Promise.all(s).then(()=>El(u,r,n,i,c)):El(u,r,n,i,c)}});function bl(e,t){for(let n=e.length-1;n>=0;n--)if("optional"!==e[n]._zod[t])return n+1;return 0}function vl(e,t,n){e.issues.length&&t.issues.push(...lc(n,e.issues)),t.value[n]=e.value}function El(e,t,n,r,o){for(let i=0;i<n.length;i++){const n=e[i],s=i<r.length;if(n.issues.length){if(!s&&i>=o){t.value.length=i;break}t.issues.push(...lc(i,n.issues))}t.value[i]=n.value}for(let e=t.value.length-1;e>=r.length&&("optional"===n[e]._zod.optout&&void 0===t.value[e]);e--)t.value.length=e;return t}const _l=Fa("$ZodRecord",(e,t)=>{Iu.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!tc(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const i=[],s=t.keyType._zod.values;if(s){n.value={};const a=new Set;for(const c of s)if("string"==typeof c||"number"==typeof c||"symbol"==typeof c){a.add("number"==typeof c?c.toString():c);const s=t.keyType._zod.run({value:c,issues:[]},r);if(s instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(s.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:s.issues.map(e=>dc(e,r,Da())),input:c,path:[c],inst:e});continue}const u=s.value,l=t.valueType._zod.run({value:o[c],issues:[]},r);l instanceof Promise?i.push(l.then(e=>{e.issues.length&&n.issues.push(...lc(c,e.issues)),n.value[u]=e.value})):(l.issues.length&&n.issues.push(...lc(c,l.issues)),n.value[u]=l.value)}let c;for(const e in o)a.has(e)||(c=c??[],c.push(e));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:c})}else{n.value={};for(const s of Reflect.ownKeys(o)){if("__proto__"===s)continue;if(!Object.prototype.propertyIsEnumerable.call(o,s))continue;let a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if("string"==typeof s&&ru.test(s)&&a.issues.length){const e=t.keyType._zod.run({value:Number(s),issues:[]},r);if(e instanceof Promise)throw new Error("Async schemas not supported in object keys currently");0===e.issues.length&&(a=e)}if(a.issues.length){"loose"===t.mode?n.value[s]=o[s]:n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(e=>dc(e,r,Da())),input:s,path:[s],inst:e});continue}const c=t.valueType._zod.run({value:o[s],issues:[]},r);c instanceof Promise?i.push(c.then(e=>{e.issues.length&&n.issues.push(...lc(s,e.issues)),n.value[a.value]=e.value})):(c.issues.length&&n.issues.push(...lc(s,c.issues)),n.value[a.value]=c.value)}}return i.length?Promise.all(i).then(()=>n):n}}),xl=Fa("$ZodEnum",(e,t)=>{Iu.init(e,t);const n=Za(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>rc.has(typeof e)).map(e=>"string"==typeof e?oc(e):e.toString()).join("|")})$`),e._zod.parse=(t,o)=>{const i=t.value;return r.has(i)||t.issues.push({code:"invalid_value",values:n,input:i,inst:e}),t}}),kl=Fa("$ZodLiteral",(e,t)=>{if(Iu.init(e,t),0===t.values.length)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(e=>"string"==typeof e?oc(e):e?oc(e.toString()):String(e)).join("|")})$`),e._zod.parse=(r,o)=>{const i=r.value;return n.has(i)||r.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),r}}),Al=Fa("$ZodTransform",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new La(e.constructor.name);const o=t.transform(n.value,n);if(r.async){return(o instanceof Promise?o:Promise.resolve(o)).then(e=>(n.value=e,n.fallback=!0,n))}if(o instanceof Promise)throw new Ca;return n.value=o,n.fallback=!0,n}});function Il(e,t){return void 0===t&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const $l=Fa("$ZodOptional",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Ka(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Ka(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ha(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=e.value,o=t.innerType._zod.run(e,n);return o instanceof Promise?o.then(e=>Il(e,r)):Il(o,r)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),Bl=Fa("$ZodExactOptional",(e,t)=>{$l.init(e,t),Ka(e._zod,"values",()=>t.innerType._zod.values),Ka(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),zl=Fa("$ZodNullable",(e,t)=>{Iu.init(e,t),Ka(e._zod,"optin",()=>t.innerType._zod.optin),Ka(e._zod,"optout",()=>t.innerType._zod.optout),Ka(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ha(e.source)}|null)$`):void 0}),Ka(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),Sl=Fa("$ZodDefault",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",Ka(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Ol(e,t)):Ol(r,t)}});function Ol(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Tl=Fa("$ZodPrefault",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",Ka(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Nl=Fa("$ZodNonOptional",(e,t)=>{Iu.init(e,t),Ka(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(t=>Rl(t,e)):Rl(o,e)}});function Rl(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Ul=Fa("$ZodCatch",(e,t)=>{Iu.init(e,t),e._zod.optin="optional",Ka(e._zod,"optout",()=>t.innerType._zod.optout),Ka(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>dc(e,n,Da()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>dc(e,n,Da()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),Pl=Fa("$ZodPipe",(e,t)=>{Iu.init(e,t),Ka(e._zod,"values",()=>t.in._zod.values),Ka(e._zod,"optin",()=>t.in._zod.optin),Ka(e._zod,"optout",()=>t.out._zod.optout),Ka(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Fl(e,t.in,n)):Fl(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Fl(e,t.out,n)):Fl(r,t.out,n)}});function Fl(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const Cl=Fa("$ZodReadonly",(e,t)=>{Iu.init(e,t),Ka(e._zod,"propValues",()=>t.innerType._zod.propValues),Ka(e._zod,"values",()=>t.innerType._zod.values),Ka(e._zod,"optin",()=>t.innerType?._zod?.optin),Ka(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ll):Ll(r)}});function Ll(e){return e.value=Object.freeze(e.value),e}const Ml=Fa("$ZodFunction",(e,t)=>(Iu.init(e,t),e._def=t,e._zod.def=t,e.implement=t=>{if("function"!=typeof t)throw new Error("implement() must be called with a function");return function(...n){const r=e._def.input?bc(e._def.input,n):n,o=Reflect.apply(t,this,r);return e._def.output?bc(e._def.output,o):o}},e.implementAsync=t=>{if("function"!=typeof t)throw new Error("implementAsync() must be called with a function");return async function(...n){const r=e._def.input?await Ec(e._def.input,n):n,o=await Reflect.apply(t,this,r);return e._def.output?await Ec(e._def.output,o):o}},e._zod.parse=(t,n)=>{if("function"!=typeof t.value)return t.issues.push({code:"invalid_type",expected:"function",input:t.value,inst:e}),t;const r=e._def.output&&"promise"===e._def.output._zod.def.type;return t.value=r?e.implementAsync(t.value):e.implement(t.value),t},e.input=(...t)=>{const n=e.constructor;return Array.isArray(t[0])?new n({type:"function",input:new wl({type:"tuple",items:t[0],rest:t[1]}),output:e._def.output}):new n({type:"function",input:t[0],output:e._def.output})},e.output=t=>new(0,e.constructor)({type:"function",input:e._def.input,output:t}),e)),Dl=Fa("$ZodCustom",(e,t)=>{au.init(e,t),Iu.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(t=>Zl(t,n,r,e));Zl(o,n,r,e)}});function Zl(e,t,n,r){if(!e){const 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(pc(e))}}var jl;class ql{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){const n=t[0];return this._map.set(e,n),n&&"object"==typeof n&&"id"in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const 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)}}(jl=globalThis).__zod_globalRegistry??(jl.__zod_globalRegistry=new ql);const Gl=globalThis.__zod_globalRegistry;function Hl(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...sc(t)})}function Vl(e,t){return new uu({check:"less_than",...sc(t),value:e,inclusive:!1})}function Kl(e,t){return new uu({check:"less_than",...sc(t),value:e,inclusive:!0})}function Wl(e,t){return new lu({check:"greater_than",...sc(t),value:e,inclusive:!1})}function Jl(e,t){return new lu({check:"greater_than",...sc(t),value:e,inclusive:!0})}function Xl(e,t){return new fu({check:"multiple_of",...sc(t),value:e})}function Yl(e,t){return new hu({check:"max_length",...sc(t),maximum:e})}function Ql(e,t){return new pu({check:"min_length",...sc(t),minimum:e})}function ef(e,t){return new mu({check:"length_equals",...sc(t),length:e})}function tf(e){return new xu({check:"overwrite",tx:e})}function nf(e,t){const n=function(e,t){const n=new au({check:"custom",...sc(t)});return n._zod.check=e,n}(t=>(t.addIssue=e=>{if("string"==typeof e)t.issues.push(pc(e,t.value,n._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=t.value),r.inst??(r.inst=n),r.continue??(r.continue=!n._zod.def.abort),t.issues.push(pc(r))}},e(t.value,t)),t);return n}function rf(e){let t=e?.target??"draft-2020-12";return"draft-4"===t&&(t="draft-04"),"draft-7"===t&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??Gl,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function of(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,i=t.seen.get(e);if(i){i.count++;return n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema}const s={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,s);const a=e._zod.toJSONSchema?.();if(a)s.schema=a;else{const r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,r);else{const n=s.schema,i=t.processors[o.type];if(!i)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);i(e,t,n,r)}const i=e._zod.parent;i&&(s.ref||(s.ref=i),of(i,t,r),t.seen.get(i).isParent=!0)}const c=t.metadataRegistry.get(e);c&&Object.assign(s.schema,c),"input"===t.io&&cf(e)&&(delete s.schema.examples,delete s.schema.default),"input"===t.io&&"_prefault"in s.schema&&((r=s.schema).default??(r.default=s.schema._prefault)),delete s.schema._prefault;return t.seen.get(e).schema}function sf(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const t of e.seen.entries()){const n=e.metadataRegistry.get(t[0])?.id;if(n){const e=r.get(n);if(e&&e!==t[0])throw new 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])}}const o=t=>{if(t[1].schema.$ref)return;const r=t[1],{ref:o,defId:i}=(t=>{const r="draft-2020-12"===e.target?"$defs":"definitions";if(e.external){const n=e.external.registry.get(t[0])?.id,o=e.external.uri??(e=>e);if(n)return{ref:o(n)};const i=t[1].defId??t[1].schema.id??"schema"+e.counter++;return t[1].defId=i,{defId:i,ref:`${o("__shared")}#/${r}/${i}`}}if(t[1]===n)return{ref:"#"};const o=`#/${r}/`,i=t[1].schema.id??"__schema"+e.counter++;return{defId:i,ref:o+i}})(t);r.def={...r.schema},i&&(r.defId=i);const s=r.schema;for(const e in s)delete s[e];s.$ref=o};if("throw"===e.cycles)for(const t of e.seen.entries()){const e=t[1];if(e.cycle)throw new Error(`Cycle detected: #/${e.cycle?.join("/")}/<root>\n\nSet the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const n of e.seen.entries()){const r=n[1];if(t===n[0]){o(n);continue}if(e.external){const r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){o(n);continue}}const i=e.metadataRegistry.get(n[0])?.id;i?o(n):(r.cycle||r.count>1&&"ref"===e.reused)&&o(n)}}function af(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=t=>{const n=e.seen.get(t);if(null===n.ref)return;const o=n.def??n.schema,i={...o},s=n.ref;if(n.ref=null,s){r(s);const n=e.seen.get(s),a=n.schema;!a.$ref||"draft-07"!==e.target&&"draft-04"!==e.target&&"openapi-3.0"!==e.target?Object.assign(o,a):(o.allOf=o.allOf??[],o.allOf.push(a)),Object.assign(o,i);if(t._zod.parent===s)for(const e in o)"$ref"!==e&&"allOf"!==e&&(e in i||delete o[e]);if(a.$ref&&n.def)for(const e in o)"$ref"!==e&&"allOf"!==e&&e in n.def&&JSON.stringify(o[e])===JSON.stringify(n.def[e])&&delete o[e]}const a=t._zod.parent;if(a&&a!==s){r(a);const t=e.seen.get(a);if(t?.schema.$ref&&(o.$ref=t.schema.$ref,t.def))for(const e in o)"$ref"!==e&&"allOf"!==e&&e in t.def&&JSON.stringify(o[e])===JSON.stringify(t.def[e])&&delete o[e]}e.override({zodSchema:t,jsonSchema:o,path:n.path??[]})};for(const t of[...e.seen.entries()].reverse())r(t[0]);const o={};if("draft-2020-12"===e.target?o.$schema="https://json-schema.org/draft/2020-12/schema":"draft-07"===e.target?o.$schema="http://json-schema.org/draft-07/schema#":"draft-04"===e.target?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const n=e.external.registry.get(t)?.id;if(!n)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(n)}Object.assign(o,n.def??n.schema);const i=e.metadataRegistry.get(t)?.id;void 0!==i&&o.id===i&&delete o.id;const s=e.external?.defs??{};for(const t of e.seen.entries()){const e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,s[e.defId]=e.def)}e.external||Object.keys(s).length>0&&("draft-2020-12"===e.target?o.$defs=s:o.definitions=s);try{const n=JSON.parse(JSON.stringify(o));return Object.defineProperty(n,"~standard",{value:{...t["~standard"],jsonSchema:{input:uf(t,"input",e.processors),output:uf(t,"output",e.processors)}},enumerable:!1,writable:!1}),n}catch(e){throw new Error("Error converting schema to JSON.")}}function cf(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if("transform"===r.type)return!0;if("array"===r.type)return cf(r.element,n);if("set"===r.type)return cf(r.valueType,n);if("lazy"===r.type)return cf(r.getter(),n);if("promise"===r.type||"optional"===r.type||"nonoptional"===r.type||"nullable"===r.type||"readonly"===r.type||"default"===r.type||"prefault"===r.type)return cf(r.innerType,n);if("intersection"===r.type)return cf(r.left,n)||cf(r.right,n);if("record"===r.type||"map"===r.type)return cf(r.keyType,n)||cf(r.valueType,n);if("pipe"===r.type)return!!e._zod.traits.has("$ZodCodec")||(cf(r.in,n)||cf(r.out,n));if("object"===r.type){for(const e in r.shape)if(cf(r.shape[e],n))return!0;return!1}if("union"===r.type){for(const e of r.options)if(cf(e,n))return!0;return!1}if("tuple"===r.type){for(const e of r.items)if(cf(e,n))return!0;return!(!r.rest||!cf(r.rest,n))}return!1}const uf=(e,t,n={})=>r=>{const{libraryOptions:o,target:i}=r??{},s=rf({...o??{},target:i,io:t,processors:n});return of(e,s),sf(s,e),af(s,e)},lf={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},ff=(e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r);t.seen.get(e).ref=o.innerType},df=Fa("ZodISODateTime",(e,t)=>{Mu.init(e,t),Mf.init(e,t)});function hf(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...sc(t)})}(df,e)}const pf=Fa("ZodISODate",(e,t)=>{Du.init(e,t),Mf.init(e,t)});function mf(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...sc(t)})}(pf,e)}const gf=Fa("ZodISOTime",(e,t)=>{Zu.init(e,t),Mf.init(e,t)});function yf(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...sc(t)})}(gf,e)}const wf=Fa("ZodISODuration",(e,t)=>{ju.init(e,t),Mf.init(e,t)});function bf(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...sc(t)})}(wf,e)}const vf=(e,t)=>{gc.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=(e,o=[])=>{for(const i of e.issues)if("invalid_union"===i.code&&i.errors.length)i.errors.map(e=>r({issues:e},[...o,...i.path]));else if("invalid_key"===i.code)r({issues:i.issues},[...o,...i.path]);else if("invalid_element"===i.code)r({issues:i.issues},[...o,...i.path]);else{const e=[...o,...i.path];if(0===e.length)n._errors.push(t(i));else{let r=n,o=0;for(;o<e.length;){const n=e[o];o===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(i))):r[n]=r[n]||{_errors:[]},r=r[n],o++}}}};return r(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ja,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ja,2)}},isEmpty:{get:()=>0===e.issues.length}})},Ef=Fa("ZodError",vf,{Parent:Error}),_f=wc(Ef),xf=vc(Ef),kf=_c(Ef),Af=kc(Ef),If=Ic(Ef),$f=$c(Ef),Bf=Bc(Ef),zf=zc(Ef),Sf=Sc(Ef),Of=Oc(Ef),Tf=Tc(Ef),Nf=Nc(Ef),Rf=new WeakMap;function Uf(e,t,n){const r=Object.getPrototypeOf(e);let o=Rf.get(r);if(o||(o=new Set,Rf.set(r,o)),!o.has(t)){o.add(t);for(const e in n){const t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){const n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}const Pf=Fa("ZodType",(e,t)=>(Iu.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:uf(e,"input"),output:uf(e,"output")}}),e.toJSONSchema=((e,t={})=>n=>{const r=rf({...n,processors:t});return of(e,r),sf(r,e),af(r,e)})(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>_f(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>kf(e,t,n),e.parseAsync=async(t,n)=>xf(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Af(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>If(e,t,n),e.decode=(t,n)=>$f(e,t,n),e.encodeAsync=async(t,n)=>Bf(e,t,n),e.decodeAsync=async(t,n)=>zf(e,t,n),e.safeEncode=(t,n)=>Sf(e,t,n),e.safeDecode=(t,n)=>Of(e,t,n),e.safeEncodeAsync=async(t,n)=>Tf(e,t,n),e.safeDecodeAsync=async(t,n)=>Nf(e,t,n),Uf(e,"ZodType",{check(...e){const t=this.def;return this.clone(Ja(t,{checks:[...t.checks??[],...e.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ic(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...sc(n)})}(Vd,e,t)}(e,t))},superRefine(e,t){return this.check(function(e,t){return nf(e,t)}(e,t))},overwrite(e){return this.check(tf(e))},optional(){return Ud(this)},exactOptional(){return new Pd({type:"optional",innerType:this})},nullable(){return Cd(this)},nullish(){return Ud(Cd(this))},nonoptional(e){return function(e,t){return new Dd({type:"nonoptional",innerType:e,...sc(t)})}(this,e)},array(){return Ed(this)},or(e){return new kd({type:"union",options:[this,e],...sc(t)});var t},and(e){return new Ad({type:"intersection",left:this,right:e})},transform(e){return qd(this,new Nd({type:"transform",transform:e}))},default(e){return t=e,new Ld({type:"default",innerType:this,get defaultValue(){return"function"==typeof t?t():nc(t)}});var t},prefault(e){return t=e,new Md({type:"prefault",innerType:this,get defaultValue(){return"function"==typeof t?t():nc(t)}});var t},catch(e){return new Zd({type:"catch",innerType:this,catchValue:"function"==typeof(t=e)?t:()=>t});var t},pipe(e){return qd(this,e)},readonly(){return new Gd({type:"readonly",innerType:this})},describe(e){const t=this.clone();return Gl.add(t,{description:e}),t},meta(...e){if(0===e.length)return Gl.get(this);const t=this.clone();return Gl.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get:()=>Gl.get(e)?.description,configurable:!0}),e)),Ff=Fa("_ZodString",(e,t)=>{$u.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n;r.type="string";const{minimum:o,maximum:i,format:s,patterns:a,contentEncoding:c}=e._zod.bag;if("number"==typeof o&&(r.minLength=o),"number"==typeof i&&(r.maxLength=i),s&&(r.format=lf[s]??s,""===r.format&&delete r.format,"time"===s&&delete r.format),c&&(r.contentEncoding=c),a&&a.size>0){const e=[...a];1===e.length?r.pattern=e[0].source:e.length>1&&(r.allOf=[...e.map(e=>({..."draft-07"===t.target||"draft-04"===t.target||"openapi-3.0"===t.target?{type:"string"}:{},pattern:e.source}))])}})(e,t,n);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Uf(e,"_ZodString",{regex(...e){return this.check(function(e,t){return new yu({check:"string_format",format:"regex",...sc(t),pattern:e})}(...e))},includes(...e){return this.check(function(e,t){return new vu({check:"string_format",format:"includes",...sc(t),includes:e})}(...e))},startsWith(...e){return this.check(function(e,t){return new Eu({check:"string_format",format:"starts_with",...sc(t),prefix:e})}(...e))},endsWith(...e){return this.check(function(e,t){return new _u({check:"string_format",format:"ends_with",...sc(t),suffix:e})}(...e))},min(...e){return this.check(Ql(...e))},max(...e){return this.check(Yl(...e))},length(...e){return this.check(ef(...e))},nonempty(...e){return this.check(Ql(1,...e))},lowercase(e){return this.check(function(e){return new wu({check:"string_format",format:"lowercase",...sc(e)})}(e))},uppercase(e){return this.check(function(e){return new bu({check:"string_format",format:"uppercase",...sc(e)})}(e))},trim(){return this.check(tf(e=>e.trim()))},normalize(...e){return this.check(function(e){return tf(t=>t.normalize(e))}(...e))},toLowerCase(){return this.check(tf(e=>e.toLowerCase()))},toUpperCase(){return this.check(tf(e=>e.toUpperCase()))},slugify(){return this.check(tf(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e)))}})}),Cf=Fa("ZodString",(e,t)=>{$u.init(e,t),Ff.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...sc(t)})}(Df,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...sc(t)})}(qf,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...sc(t)})}(id,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...sc(t)})}(Gf,t)),e.guid=t=>e.check(Hl(Zf,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...sc(t)})}(jf,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...sc(t)})}(jf,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...sc(t)})}(jf,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...sc(t)})}(jf,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...sc(t)})}(Hf,t)),e.guid=t=>e.check(Hl(Zf,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...sc(t)})}(Vf,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...sc(t)})}(Kf,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...sc(t)})}(Wf,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...sc(t)})}(nd,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...sc(t)})}(rd,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...sc(t)})}(Jf,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...sc(t)})}(Xf,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...sc(t)})}(Yf,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...sc(t)})}(Qf,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...sc(t)})}(ed,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...sc(t)})}(td,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...sc(t)})}(od,t)),e.datetime=t=>e.check(hf(t)),e.date=t=>e.check(mf(t)),e.time=t=>e.check(yf(t)),e.duration=t=>e.check(bf(t))});function Lf(e){return function(e,t){return new e({type:"string",...sc(t)})}(Cf,e)}const Mf=Fa("ZodStringFormat",(e,t)=>{Bu.init(e,t),Ff.init(e,t)}),Df=Fa("ZodEmail",(e,t)=>{Ou.init(e,t),Mf.init(e,t)}),Zf=Fa("ZodGUID",(e,t)=>{zu.init(e,t),Mf.init(e,t)}),jf=Fa("ZodUUID",(e,t)=>{Su.init(e,t),Mf.init(e,t)}),qf=Fa("ZodURL",(e,t)=>{Tu.init(e,t),Mf.init(e,t)}),Gf=Fa("ZodEmoji",(e,t)=>{Nu.init(e,t),Mf.init(e,t)}),Hf=Fa("ZodNanoID",(e,t)=>{Ru.init(e,t),Mf.init(e,t)}),Vf=Fa("ZodCUID",(e,t)=>{Uu.init(e,t),Mf.init(e,t)}),Kf=Fa("ZodCUID2",(e,t)=>{Pu.init(e,t),Mf.init(e,t)}),Wf=Fa("ZodULID",(e,t)=>{Fu.init(e,t),Mf.init(e,t)}),Jf=Fa("ZodXID",(e,t)=>{Cu.init(e,t),Mf.init(e,t)}),Xf=Fa("ZodKSUID",(e,t)=>{Lu.init(e,t),Mf.init(e,t)}),Yf=Fa("ZodIPv4",(e,t)=>{qu.init(e,t),Mf.init(e,t)}),Qf=Fa("ZodIPv6",(e,t)=>{Gu.init(e,t),Mf.init(e,t)}),ed=Fa("ZodCIDRv4",(e,t)=>{Hu.init(e,t),Mf.init(e,t)}),td=Fa("ZodCIDRv6",(e,t)=>{Vu.init(e,t),Mf.init(e,t)}),nd=Fa("ZodBase64",(e,t)=>{Wu.init(e,t),Mf.init(e,t)}),rd=Fa("ZodBase64URL",(e,t)=>{Ju.init(e,t),Mf.init(e,t)}),od=Fa("ZodE164",(e,t)=>{Xu.init(e,t),Mf.init(e,t)}),id=Fa("ZodJWT",(e,t)=>{Yu.init(e,t),Mf.init(e,t)}),sd=Fa("ZodNumber",(e,t)=>{Qu.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n,{minimum:o,maximum:i,format:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u}=e._zod.bag;"string"==typeof s&&s.includes("int")?r.type="integer":r.type="number";const l="number"==typeof u&&u>=(o??Number.NEGATIVE_INFINITY),f="number"==typeof c&&c<=(i??Number.POSITIVE_INFINITY),d="draft-04"===t.target||"openapi-3.0"===t.target;l?d?(r.minimum=u,r.exclusiveMinimum=!0):r.exclusiveMinimum=u:"number"==typeof o&&(r.minimum=o),f?d?(r.maximum=c,r.exclusiveMaximum=!0):r.exclusiveMaximum=c:"number"==typeof i&&(r.maximum=i),"number"==typeof a&&(r.multipleOf=a)})(e,t,n),Uf(e,"ZodNumber",{gt(e,t){return this.check(Wl(e,t))},gte(e,t){return this.check(Jl(e,t))},min(e,t){return this.check(Jl(e,t))},lt(e,t){return this.check(Vl(e,t))},lte(e,t){return this.check(Kl(e,t))},max(e,t){return this.check(Kl(e,t))},int(e){return this.check(ud(e))},safe(e){return this.check(ud(e))},positive(e){return this.check(Wl(0,e))},nonnegative(e){return this.check(Jl(0,e))},negative(e){return this.check(Vl(0,e))},nonpositive(e){return this.check(Kl(0,e))},multipleOf(e,t){return this.check(Xl(e,t))},step(e,t){return this.check(Xl(e,t))},finite(){return this}});const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function ad(e){return function(e,t){return new e({type:"number",checks:[],...sc(t)})}(sd,e)}const cd=Fa("ZodNumberFormat",(e,t)=>{el.init(e,t),sd.init(e,t)});function ud(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...sc(t)})}(cd,e)}const ld=Fa("ZodBoolean",(e,t)=>{tl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.type="boolean"})(0,0,t)});function fd(e){return function(e,t){return new e({type:"boolean",...sc(t)})}(ld,e)}const dd=Fa("ZodBigInt",(e,t)=>{nl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("BigInt cannot be represented in JSON Schema")})(0,e),e.gte=(t,n)=>e.check(Jl(t,n)),e.min=(t,n)=>e.check(Jl(t,n)),e.gt=(t,n)=>e.check(Wl(t,n)),e.gte=(t,n)=>e.check(Jl(t,n)),e.min=(t,n)=>e.check(Jl(t,n)),e.lt=(t,n)=>e.check(Vl(t,n)),e.lte=(t,n)=>e.check(Kl(t,n)),e.max=(t,n)=>e.check(Kl(t,n)),e.positive=t=>e.check(Wl(BigInt(0),t)),e.negative=t=>e.check(Vl(BigInt(0),t)),e.nonpositive=t=>e.check(Kl(BigInt(0),t)),e.nonnegative=t=>e.check(Jl(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Xl(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});function hd(e){return function(e,t){return new e({type:"bigint",...sc(t)})}(dd,e)}const pd=Fa("ZodAny",(e,t)=>{rl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function md(){return new pd({type:"any"})}const gd=Fa("ZodUnknown",(e,t)=>{ol.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function yd(){return new gd({type:"unknown"})}const wd=Fa("ZodNever",(e,t)=>{il.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.not={}})(0,0,t)});function bd(e){return function(e,t){return new e({type:"never",...sc(t)})}(wd,e)}const vd=Fa("ZodArray",(e,t)=>{al.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def,{minimum:s,maximum:a}=e._zod.bag;"number"==typeof s&&(o.minItems=s),"number"==typeof a&&(o.maxItems=a),o.type="array",o.items=of(i.element,t,{...r,path:[...r.path,"items"]})})(e,t,n,r),e.element=t.element,Uf(e,"ZodArray",{min(e,t){return this.check(Ql(e,t))},nonempty(e){return this.check(Ql(1,e))},max(e,t){return this.check(Yl(e,t))},length(e,t){return this.check(ef(e,t))},unwrap(){return this.element}})});function Ed(e,t){return function(e,t,n){return new e({type:"array",element:t,...sc(n)})}(vd,e,t)}const _d=Fa("ZodObject",(e,t)=>{dl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object",o.properties={};const s=i.shape;for(const e in s)o.properties[e]=of(s[e],t,{...r,path:[...r.path,"properties",e]});const a=new Set(Object.keys(s)),c=new Set([...a].filter(e=>{const n=i.shape[e]._zod;return"input"===t.io?void 0===n.optin:void 0===n.optout}));c.size>0&&(o.required=Array.from(c)),"never"===i.catchall?._zod.def.type?o.additionalProperties=!1:i.catchall?i.catchall&&(o.additionalProperties=of(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):"output"===t.io&&(o.additionalProperties=!1)})(e,t,n,r),Ka(e,"shape",()=>t.shape),Uf(e,"ZodObject",{keyof(){return Od(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:yd()})},loose(){return this.clone({...this._zod.def,catchall:yd()})},strict(){return this.clone({...this._zod.def,catchall:bd()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return function(e,t){if(!tc(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const n=e._zod.def.shape;for(const e in t)if(void 0!==Object.getOwnPropertyDescriptor(n,e))throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Ja(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Wa(this,"shape",n),n}});return ic(e,r)}(this,e)},safeExtend(e){return function(e,t){if(!tc(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Ja(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Wa(this,"shape",n),n}});return ic(e,n)}(this,e)},merge(e){return function(e,t){if(e._zod.def.checks?.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");const n=Ja(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return Wa(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return ic(e,n)}(this,e)},pick(e){return function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return ic(e,Ja(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return Wa(this,"shape",e),e},checks:[]}))}(this,e)},omit(e){return function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const o=Ja(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return Wa(this,"shape",r),r},checks:[]});return ic(e,o)}(this,e)},partial(...e){return function(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Ja(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)o[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return Wa(this,"shape",o),o},checks:[]});return ic(t,o)}(Rd,this,e[0])},required(...e){return function(e,t,n){const r=Ja(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in o))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)o[t]=new e({type:"nonoptional",innerType:r[t]});return Wa(this,"shape",o),o}});return ic(t,r)}(Dd,this,e[0])}})});function xd(e,t){const n={type:"object",shape:e??{},...sc(t)};return new _d(n)}const kd=Fa("ZodUnion",(e,t)=>{pl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=!1===o.inclusive,s=o.options.map((e,n)=>of(e,t,{...r,path:[...r.path,i?"oneOf":"anyOf",n]}));i?n.oneOf=s:n.anyOf=s})(e,t,n,r),e.options=t.options});const Ad=Fa("ZodIntersection",(e,t)=>{ml.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=of(o.left,t,{...r,path:[...r.path,"allOf",0]}),s=of(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=e=>"allOf"in e&&1===Object.keys(e).length,c=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];n.allOf=c})(e,t,n,r)});const Id=Fa("ZodTuple",(e,t)=>{wl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="array";const s="draft-2020-12"===t.target?"prefixItems":"items",a="draft-2020-12"===t.target||"openapi-3.0"===t.target?"items":"additionalItems",c=i.items.map((e,n)=>of(e,t,{...r,path:[...r.path,s,n]})),u=i.rest?of(i.rest,t,{...r,path:[...r.path,a,..."openapi-3.0"===t.target?[i.items.length]:[]]}):null;"draft-2020-12"===t.target?(o.prefixItems=c,u&&(o.items=u)):"openapi-3.0"===t.target?(o.items={anyOf:c},u&&o.items.anyOf.push(u),o.minItems=c.length,u||(o.maxItems=c.length)):(o.items=c,u&&(o.additionalItems=u));const{minimum:l,maximum:f}=e._zod.bag;"number"==typeof l&&(o.minItems=l),"number"==typeof f&&(o.maxItems=f)})(e,t,n,r),e.rest=t=>e.clone({...e._zod.def,rest:t})});function $d(e,t,n){const r=t instanceof Iu;return new Id({type:"tuple",items:e,rest:r?t:null,...sc(r?n:t)})}const Bd=Fa("ZodRecord",(e,t)=>{_l.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object";const s=i.keyType,a=s._zod.bag,c=a?.patterns;if("loose"===i.mode&&c&&c.size>0){const e=of(i.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});o.patternProperties={};for(const t of c)o.patternProperties[t.source]=e}else"draft-07"!==t.target&&"draft-2020-12"!==t.target||(o.propertyNames=of(i.keyType,t,{...r,path:[...r.path,"propertyNames"]})),o.additionalProperties=of(i.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const u=s._zod.values;if(u){const e=[...u].filter(e=>"string"==typeof e||"number"==typeof e);e.length>0&&(o.required=e)}})(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function zd(e,t,n){return t&&t._zod?new Bd({type:"record",keyType:e,valueType:t,...sc(n)}):new Bd({type:"record",keyType:Lf(),valueType:e,...sc(t)})}const Sd=Fa("ZodEnum",(e,t)=>{xl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=Za(e._zod.def.entries);r.every(e=>"number"==typeof e)&&(n.type="number"),r.every(e=>"string"==typeof e)&&(n.type="string"),n.enum=r})(e,0,n),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const o={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);o[r]=t.entries[r]}return new Sd({...t,checks:[],...sc(r),entries:o})},e.exclude=(e,r)=>{const o={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete o[t]}return new Sd({...t,checks:[],...sc(r),entries:o})}});function Od(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Sd({type:"enum",entries:n,...sc(t)})}const Td=Fa("ZodLiteral",(e,t)=>{kl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=e._zod.def,o=[];for(const e of r.values)if(void 0===e){if("throw"===t.unrepresentable)throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if("bigint"==typeof e){if("throw"===t.unrepresentable)throw new Error("BigInt literals cannot be represented in JSON Schema");o.push(Number(e))}else o.push(e);if(0===o.length);else if(1===o.length){const e=o[0];n.type=null===e?"null":typeof e,"draft-04"===t.target||"openapi-3.0"===t.target?n.enum=[e]:n.const=e}else o.every(e=>"number"==typeof e)&&(n.type="number"),o.every(e=>"string"==typeof e)&&(n.type="string"),o.every(e=>"boolean"==typeof e)&&(n.type="boolean"),o.every(e=>null===e)&&(n.type="null"),n.enum=o})(e,t,n),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});const Nd=Fa("ZodTransform",(e,t)=>{Al.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Transforms cannot be represented in JSON Schema")})(0,e),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new La(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(pc(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push(pc(t))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=o,n.fallback=!0,n)}});const Rd=Fa("ZodOptional",(e,t)=>{$l.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ff(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});function Ud(e){return new Rd({type:"optional",innerType:e})}const Pd=Fa("ZodExactOptional",(e,t)=>{Bl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ff(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const Fd=Fa("ZodNullable",(e,t)=>{zl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=of(o.innerType,t,r),s=t.seen.get(e);"openapi-3.0"===t.target?(s.ref=o.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cd(e){return new Fd({type:"nullable",innerType:e})}const Ld=Fa("ZodDefault",(e,t)=>{Sl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const Md=Fa("ZodPrefault",(e,t)=>{Tl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType,"input"===t.io&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const Dd=Fa("ZodNonOptional",(e,t)=>{Nl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType})(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const Zd=Fa("ZodCatch",(e,t)=>{Ul.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;let i;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType;try{i=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=i})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const jd=Fa("ZodPipe",(e,t)=>{Pl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=o.in._zod.traits.has("$ZodTransform"),s="input"===t.io?i?o.out:o.in:o.out;of(s,t,r),t.seen.get(e).ref=s})(e,t,0,r),e.in=t.in,e.out=t.out});function qd(e,t){return new jd({type:"pipe",in:e,out:t})}const Gd=Fa("ZodReadonly",(e,t)=>{Cl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;of(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.readOnly=!0})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const Hd=Fa("ZodFunction",(e,t)=>{Ml.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Function types cannot be represented in JSON Schema")})(0,e)});const Vd=Fa("ZodCustom",(e,t)=>{Dl.init(e,t),Pf.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Custom types cannot be represented in JSON Schema")})(0,e)});function Kd(e){return function(e,t){return new e({type:"number",coerce:!0,checks:[],...sc(t)})}(sd,e)}const Wd=xd({issuer:Lf().transform(e=>ls(e)),index:Lf().transform(e=>ls(e)),timestamp:Lf().transform(e=>ls(e)),signature:Lf().transform(e=>ls(e))});var Jd,Xd,Yd,Qd,eh,th={exports:{}};function nh(){if(Xd)return Jd;Xd=1;var e=1e3,t=60*e,n=60*t,r=24*n,o=7*r,i=365.25*r;function s(e,t,n,r){var o=t>=1.5*n;return Math.round(e/n)+" "+r+(o?"s":"")}return Jd=function(a,c){c=c||{};var u=typeof a;if("string"===u&&a.length>0)return function(s){if((s=String(s)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*i;case"weeks":case"week":case"w":return c*o;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===u&&isFinite(a))return c.long?function(o){var i=Math.abs(o);if(i>=r)return s(o,i,r,"day");if(i>=n)return s(o,i,n,"hour");if(i>=t)return s(o,i,t,"minute");if(i>=e)return s(o,i,e,"second");return o+" ms"}(a):function(o){var i=Math.abs(o);if(i>=r)return Math.round(o/r)+"d";if(i>=n)return Math.round(o/n)+"h";if(i>=t)return Math.round(o/t)+"m";if(i>=e)return Math.round(o/e)+"s";return o+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))}}var rh=(eh||(eh=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))}),t.splice(o,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=(Qd||(Qd=1,Yd=function(e){function t(e){let r,o,i,s=null;function a(...e){if(!a.enabled)return;const n=a,o=Number(new Date),i=o-(r||o);n.diff=i,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,o)=>{if("%%"===r)return"%";s++;const i=t.formatters[o];if("function"==typeof i){const t=e[s];r=i.call(n,t),e.splice(s,1),s--}return r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(o!==t.namespaces&&(o=t.namespaces,i=t.enabled(e)),i),set:e=>{s=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e,t){let n=0,r=0,o=-1,i=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(o=r,i=n,r++):(n++,r++);else{if(-1===o)return!1;r=o+1,i++,n=i}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(r(e,n))return!1;for(const n of t.names)if(r(e,n))return!0;return!1},t.humanize=nh(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}),Yd)(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(th,th.exports)),th.exports);const oh=Vr(rh)("bee-js:http"),ih={headers:{accept:"application/json, text/plain, */*"}};async function sh(e,t){const n=t.data,r=Jr.Objects.deepMerge3(ih,{...t,data:void 0},e);if(r.data=n,e.signal&&(r.signal=e.signal),function(e){if(void 0===e.data)return;const t=e.data;if(null!==t&&"object"==typeof t&&t.constructor===Object||Array.isArray(t))e.body=JSON.stringify(t),e.headers={"content-type":"application/json",...e.headers};else{e.body=t,e.duplex="half";const n=t instanceof Blob&&t.type?t.type:"application/octet-stream";e.headers={"content-type":n,...e.headers}}}(r),r.params)for(const e of Object.keys(r.params))void 0===r.params[e]&&delete r.params[e];const o=function(e){let t=Jr.Strings.joinUrl([e.baseURL??"",e.url??""]);if(e.params){const n=new URLSearchParams(Object.entries(e.params).filter(([,e])=>void 0!==e).map(([e,t])=>[e,String(t)])).toString();n&&(t+=`?${n}`)}return t}(r),i=(r.method||"GET").toUpperCase();r.method=i,e.onRequest?.({method:i,url:Jr.Strings.joinUrl([r.baseURL??"",r.url??""]),headers:{...r.headers},params:r.params});let s=0;for(;s<1e5;)try{oh(`${i} ${o}`,{headers:r.headers,params:r.params});const e=await fetch(o,r);return e.ok||await ah(i,o,e,r.responseType),uh(e,r.responseType)}catch(t){if(t instanceof ph)throw t;const n=t;if("TimeoutError"!==n.name||!e.endlesslyRetry)throw ch(n,i,o);s++,await Jr.System.sleepMillis(s<300?200:1e3)}throw Error("Max number of failed attempts reached")}async function ah(e,t,n,r){const o=await uh(n,r).catch(()=>({data:void 0})),i="string"==typeof o.data?o.data:JSON.stringify(o.data),s=i&&"undefined"!==i?`${n.statusText}: ${i}`:n.statusText;throw new ph(e,t,s,o.data,n.status,n.statusText)}function ch(e,t,n){if("AbortError"===e.name)return new ph(t,n,"Request aborted",void 0,void 0,"ERR_CANCELED");const r=e.cause,o=r?.message?`${e.message}: ${r.message}`:e.message;return new ph(t,n,o)}async function uh(e,t="json"){let n;switch(t){case"arraybuffer":n=await e.arrayBuffer();break;case"text":n=await e.text();break;case"blob":n=await e.blob();break;case"stream":n=e.body;break;default:{const t=await e.text();n=t?JSON.parse(t):null}}return{data:n,status:e.status,statusText:e.statusText,headers:Object.fromEntries(e.headers.entries()),raw:e}}const lh=xd({durationSeconds:ad()}),fh=xd({reference:Lf().transform(e=>new Vs(e))});class dh extends Error{constructor(e){super(e)}}class hh extends dh{constructor(e,t){super(e),this.value=t}}class ph extends dh{constructor(e,t,n,r,o,i){super(n),this.method=e,this.url=t,this.responseBody=r,this.status=o,this.statusText=i,this.response={status:o,data:r,statusText:i}}}class mh{constructor(e){this.seconds=Math.ceil(e),e<0&&(this.seconds=0)}static fromMilliseconds(e){return new mh(e/1e3)}static fromSeconds(e){return new mh(e)}static fromHours(e){return new mh(60*e*60)}static fromDays(e){return new mh(24*e*60*60)}static fromWeeks(e){return new mh(7*e*24*60*60)}static fromYears(e){return new mh(365*e*24*60*60)}static fromEndDate(e,t){return new mh((e.getTime()-(t??new Date).getTime())/1e3)}static parseFromString(e){return mh.fromSeconds(Jr.Dates.make(e)/1e3)}toSeconds(){return this.seconds}toHours(){return this.seconds/60/60}toDays(){return this.seconds/24/60/60}toWeeks(){return this.seconds/7/24/60/60}toYears(){return this.seconds/365/24/60/60}toEndDate(e){return new Date((e??new Date).getTime()+1e3*this.seconds)}represent(){return Jr.Dates.secondsToHumanTime(this.seconds)}isZero(){return 0===this.seconds}}mh.ZERO=new mh(0);class gh{constructor(e){this.state=e}static fromDecimalString(e){return new gh(Jr.FixedPointNumber.fromDecimalString(e,gh.DIGITS))}static fromPLUR(e){return new gh(new Jr.FixedPointNumber(e,gh.DIGITS))}static fromFloat(e){return new gh(Jr.FixedPointNumber.fromFloat(e,gh.DIGITS))}toPLURString(){return this.state.toString()}toPLURBigInt(){return this.state.value}toDecimalString(){return this.state.toDecimalString()}toFloat(){return this.state.toFloat()}toSignificantDigits(e){return this.toDecimalString().slice(0,this.toDecimalString().indexOf(".")+e+1)}plus(e){return new gh(this.state.add(e instanceof gh?e.state:new Jr.FixedPointNumber(e,gh.DIGITS)))}minus(e){return new gh(this.state.subtract(e instanceof gh?e.state:new Jr.FixedPointNumber(e,gh.DIGITS)))}divide(e){return new gh(this.state.divmod(e)[0])}gt(e){return 1===this.state.compare(e.state)}gte(e){return-1!==this.state.compare(e.state)}lt(e){return-1===this.state.compare(e.state)}lte(e){return 1!==this.state.compare(e.state)}eq(e){return 0===this.state.compare(e.state)}exchangeToDAI(e){return yh.fromWei(this.state.exchange("*",new Jr.FixedPointNumber(e.toWeiBigInt(),yh.DIGITS),yh.DIGITS).value)}}gh.DIGITS=16;class yh{constructor(e){this.state=e}static fromDecimalString(e){return new yh(Jr.FixedPointNumber.fromDecimalString(e,yh.DIGITS))}static fromWei(e){return new yh(new Jr.FixedPointNumber(e,yh.DIGITS))}static fromFloat(e){return new yh(Jr.FixedPointNumber.fromFloat(e,yh.DIGITS))}toWeiString(){return this.state.toString()}toWeiBigInt(){return this.state.value}toDecimalString(){return this.state.toDecimalString()}toSignificantDigits(e){return this.toDecimalString().slice(0,this.toDecimalString().indexOf(".")+e+1)}toFloat(){return this.state.toFloat()}plus(e){return new yh(this.state.add(e instanceof yh?e.state:new Jr.FixedPointNumber(e,yh.DIGITS)))}minus(e){return new yh(this.state.subtract(e instanceof yh?e.state:new Jr.FixedPointNumber(e,yh.DIGITS)))}divide(e){return new yh(this.state.divmod(e)[0])}gt(e){return 1===this.state.compare(e.state)}gte(e){return-1!==this.state.compare(e.state)}lt(e){return-1===this.state.compare(e.state)}lte(e){return 1!==this.state.compare(e.state)}eq(e){return 0===this.state.compare(e.state)}exchangeToBZZ(e){return gh.fromPLUR(this.state.exchange("/",new Jr.FixedPointNumber(e.toWeiBigInt(),yh.DIGITS),gh.DIGITS).value)}}function wh(e){if("function"==typeof File&&e instanceof File)return!0;const t=e;return"object"==typeof t&&"string"==typeof t.name&&("function"==typeof t.stream||"function"==typeof t.arrayBuffer)}async function bh(e){return e.arrayBuffer?e.arrayBuffer():new Promise(t=>{const n=new FileReader;n.onload=()=>t(n.result),n.readAsArrayBuffer(e)})}var vh;function Eh(e){switch(e){case"full":return vh.FULL;case"light":return vh.LIGHT;case"ultra-light":return vh.ULTRA_LIGHT;case"dev":return vh.DEV;default:throw new Error(`Unknown Bee mode: ${e}`)}}yh.DIGITS=18,function(e){e.FULL="full",e.LIGHT="light",e.ULTRA_LIGHT="ultra-light",e.DEV="dev"}(vh||(vh={}));const _h=4096,xh=17,kh=255;var Ah,Ih;!function(e){e[e.OFF=0]="OFF",e[e.MEDIUM=1]="MEDIUM",e[e.STRONG=2]="STRONG",e[e.INSANE=3]="INSANE",e[e.PARANOID=4]="PARANOID"}(Ah||(Ah={})),function(e){e[e.NONE=0]="NONE",e[e.DATA=1]="DATA",e[e.PROX=2]="PROX",e[e.RACE=3]="RACE"}(Ih||(Ih={})),Ah.OFF,Ah.MEDIUM,Ah.STRONG,Ah.INSANE,Ah.PARANOID,Ah.OFF,Ah.MEDIUM,Ah.STRONG,Ah.INSANE,Ah.PARANOID,Lf().regex(/^(?:0x)?[0-9a-fA-F]*$/i,"expected hex string").refine(e=>e.replace(/^0x/i,"").length%2==0,"expected even-length hex string");const $h=md().refine(e=>{return new Hd({type:"function",input:Array.isArray(t?.input)?$d(t?.input):Ed(yd()),output:yd()}).safeParse(e).success;var t},"expected a function"),Bh=md().transform(e=>(hd().safeParse(e).success&&(e=String(e)),Lf().regex(/^-?\d+$/,"expected integer string").parse(e))),zh=md().transform(e=>(hd().safeParse(e).success&&(e=String(e)),Lf().regex(/^\d+$/,"expected non-negative integer string").parse(e))),Sh=xd({baseURL:Lf().optional(),timeout:ad().int().min(0).optional(),headers:zd(Lf(),Lf()).optional(),onRequest:$h.optional(),httpAgent:yd().optional(),httpsAgent:yd().optional(),endlesslyRetry:fd().optional(),signal:md().optional()}),Oh=xd({redundancyStrategy:ad().int().optional(),fallback:fd().optional(),timeoutMs:ad().int().min(0).optional(),actPublisher:Ud(md().transform(e=>new Ds(e))),actHistoryAddress:Ud(md().transform(e=>new Vs(e))),actTimestamp:Kd().optional()}),Th=xd({act:fd().optional(),actHistoryAddress:Ud(md().transform(e=>new Vs(e))),deferred:fd().optional(),encrypt:fd().optional(),pin:fd().optional(),tag:ad().int().min(0).optional()}),Nh=Th.extend({redundancyLevel:ad().int().min(0).optional()}),Rh=Th.extend({size:ad().int().min(0).optional(),contentType:Lf().optional(),redundancyLevel:ad().int().min(0).optional()}),Uh=Th.extend({errorDocument:Lf().optional(),indexDocument:Lf().optional(),redundancyLevel:ad().int().min(0).optional()}),Ph=xd({uid:ad().int()}),Fh=Kd().min(0),Ch=xd({onMessage:$h,onError:$h,onClose:$h}),Lh=xd({onMessage:$h,onError:$h,onClose:$h}),Mh=xd({gasPrice:Bh.optional(),immutableFlag:fd().optional(),label:Lf().optional(),waitForUsable:fd().optional(),waitForUsableTimeout:ad().int().min(0).optional()}),Dh=xd({gasLimit:zh.optional(),gasPrice:zh.optional()}),Zh=xd({limit:ad().int().min(1).max(1e3).optional(),offset:ad().int().min(0).optional()});function jh(e,t){if("bigint"==typeof e&&(e=e.toString()),"string"!=typeof e||!/^-?\d+$/.test(e))throw new TypeError(`${t?.name??"value"} is not a valid integer string, got: ${e}`);if(void 0!==t?.min&&BigInt(e)<t.min)throw new RangeError(`${t?.name??"value"} must be >= ${t.min}, got: ${e}`);if(void 0!==t?.max&&BigInt(e)>t.max)throw new RangeError(`${t?.name??"value"} must be <= ${t.max}, got: ${e}`);return e}function qh(e){if("string"!=typeof e&&!(e instanceof Uint8Array)&&!(e instanceof Blob))throw new TypeError("Data must be either string, Uint8Array, Blob or Readable!")}function Gh(e){if("string"!=typeof e&&!(e instanceof Uint8Array)&&!wh(e))throw new TypeError("Data must be either string, Readable, Uint8Array or File!")}function Hh(e){if(null==e)throw new TypeError(`Expected number | Tag | string from tagUid, got: ${e}`);if(t=e,Ph.safeParse(t).success)return e.uid;if("number"==typeof e||"string"==typeof e)return Fh.parse(e);var t;throw new TypeError(`Expected number | Tag | string from tagUid, got: ${e}`)}function Vh(e){return Number.isInteger(e)?e<1?1:e>3155695200?3155695200:e:1}const Kh=xd({peer:Lf(),balance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"balance"})))}),Wh=xd({balances:Ed(Kh)}),Jh=Kh,Xh=xd({beneficiary:Lf().transform(e=>new Ns(e)),chequebook:Lf().transform(e=>new Ns(e)),payout:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"payout"})))}),Yh=xd({recipient:Lf(),lastPayout:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"lastPayout"}))),bounced:fd()}),Qh=xd({chequebookAddress:Lf().transform(e=>new Ns(e))}),ep=xd({availableBalance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"availableBalance"}))),totalBalance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"totalBalance"})))}),tp=xd({peer:Lf(),uncashedAmount:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"uncashedAmount"}))),transactionHash:Lf().nullish().transform(e=>e??null),lastCashedCheque:Xh.nullish().transform(e=>e??null),result:Yh.nullish().transform(e=>e??null)}),np=xd({peer:Lf(),lastreceived:Xh.nullish().transform(e=>e??null),lastsent:Xh.nullish().transform(e=>e??null)}),rp=xd({lastcheques:Ed(xd({peer:Lf(),lastreceived:Xh.nullish().transform(e=>e??null),lastsent:Xh.nullish().transform(e=>e??null)}))}),op=xd({transactionHash:Lf().transform(e=>new Xs(e))}),ip=xd({address:Lf(),fullNode:fd()}),sp=xd({population:ad(),connected:ad(),connectedPeers:Ed(xd({address:Lf()})).nullish().transform(e=>e??[]),disconnectedPeers:Ed(xd({address:Lf()})).nullish().transform(e=>e??[])}),ap=zd(Lf(),sp),cp=xd({overlay:Lf().transform(e=>new Cs(e)),underlay:Ed(Lf()),ethereum:Lf().transform(e=>new Ns(e)),publicKey:Lf().transform(e=>new Ds(e)),pssPublicKey:Lf().transform(e=>new Ds(e))}),up=xd({peers:Ed(ip)}),lp=xd({peers:Ed(ip)}),fp=xd({baseAddr:Lf(),population:ad(),connected:ad(),timestamp:Lf(),nnLowWatermark:ad(),depth:ad(),reachability:Lf(),networkAvailability:Lf(),bins:ap}),dp=xd({overlay:Lf(),proximity:ad(),beeMode:Lf().transform(Eh),reserveSize:ad(),reserveSizeWithinRadius:ad(),pullsyncRate:ad(),storageRadius:ad(),connectedPeers:ad(),neighborhoodSize:ad(),batchCommitment:ad(),isReachable:fd(),lastSyncedBlock:ad(),committedDepth:ad(),isWarmingUp:fd()}),hp=xd({apiVersion:Lf(),version:Lf(),status:(pp="ok",new Td({type:"literal",values:Array.isArray(pp)?pp:[pp],...sc(mp)}))});var pp,mp;const gp=xd({apiVersion:Lf(),version:Lf(),status:Od(["ready","notReady"])}),yp=xd({beeMode:Lf().transform(Eh),chequebookEnabled:fd(),swapEnabled:fd()}),wp=xd({gateway:fd()}),bp=xd({isRetrievable:fd()}),vp=Ed(Lf().transform(e=>new Ds(e))),Ep=xd({ref:Lf().transform(e=>new Vs(e)),historyref:Lf().transform(e=>new Vs(e))});var _p=null;"undefined"!=typeof WebSocket?_p=WebSocket:"undefined"!=typeof MozWebSocket?_p=MozWebSocket:"undefined"!=typeof global?_p=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window?_p=window.WebSocket||window.MozWebSocket:"undefined"!=typeof self&&(_p=self.WebSocket||self.MozWebSocket);var xp=_p;const kp=xd({references:Ed(Lf()).nullable()}),Ap=xd({peer:Lf(),sent:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"sent"}))),received:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"received"})))}),Ip=Ap,$p=xd({totalSent:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"totalSent"}))),totalReceived:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"totalReceived"}))),settlements:Ed(Ap)}),Bp=xd({stakedAmount:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"stakedAmount"})))}),zp=xd({withdrawableAmount:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"withdrawableAmount"})))}),Sp=xd({txHash:Lf().transform(e=>new Xs(e))}),Op=xd({minimumGasFunds:Lf().transform(e=>yh.fromWei(jh(e,{name:"minimumGasFunds"}))),hasSufficientFunds:fd(),isFrozen:fd(),isFullySynced:fd(),phase:Lf(),round:ad(),lastWonRound:ad(),lastPlayedRound:ad(),lastFrozenRound:ad(),lastSelectedRound:ad(),lastSampleDurationSeconds:ad(),block:ad(),reward:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"reward"}))),fees:Lf().transform(e=>yh.fromWei(jh(e,{name:"fees"}))),isHealthy:fd()}),Tp=xd({batchID:Lf(),utilization:ad(),utilizationRatio:ad().optional(),usable:fd(),label:Lf(),depth:ad(),amount:Lf(),bucketDepth:ad(),blockNumber:ad(),immutableFlag:fd(),batchTTL:ad()}),Np=xd({batchID:Lf().transform(e=>new zs(e)),batchTTL:ad(),bucketDepth:ad(),depth:ad(),immutable:fd(),owner:Lf().transform(e=>new Ns(e)),start:ad(),value:Lf().transform(e=>jh(e,{name:"value"}))}),Rp=xd({batches:Ed(Np)}),Up=xd({stamps:Ed(Tp)}),Pp=Tp,Fp=xd({depth:ad(),bucketDepth:ad(),bucketUpperBound:ad(),buckets:Ed(xd({bucketID:ad(),collisions:ad()}))}),Cp=xd({batchID:Lf().transform(e=>new zs(e))});var Lp,Mp,Dp,Zp;function jp(){if(Mp)return Lp;Mp=1;const e="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...e)=>console.error("SEMVER",...e):()=>{};return Lp=e}function qp(){if(Zp)return Dp;Zp=1;const e=Number.MAX_SAFE_INTEGER||9007199254740991;return Dp={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:e,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:"2.0.0",FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}}var Gp,Hp,Vp,Kp,Wp,Jp,Xp,Yp,Qp,em={exports:{}};function tm(){return Gp||(Gp=1,function(e,t){const{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:o}=qp(),i=jp(),s=(t=e.exports={}).re=[],a=t.safeRe=[],c=t.src=[],u=t.safeSrc=[],l=t.t={};let f=0;const d="[a-zA-Z0-9-]",h=[["\\s",1],["\\d",o],[d,r]],p=(e,t,n)=>{const r=(e=>{for(const[t,n]of h)e=e.split(`${t}*`).join(`${t}{0,${n}}`).split(`${t}+`).join(`${t}{1,${n}}`);return e})(t),o=f++;i(e,o,t),l[e]=o,c[o]=t,u[o]=r,s[o]=new RegExp(t,n?"g":void 0),a[o]=new RegExp(r,n?"g":void 0)};p("NUMERICIDENTIFIER","0|[1-9]\\d*"),p("NUMERICIDENTIFIERLOOSE","\\d+"),p("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${d}*`),p("MAINVERSION",`(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})\\.(${c[l.NUMERICIDENTIFIER]})`),p("MAINVERSIONLOOSE",`(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})\\.(${c[l.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASEIDENTIFIER",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIER]})`),p("PRERELEASEIDENTIFIERLOOSE",`(?:${c[l.NONNUMERICIDENTIFIER]}|${c[l.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASE",`(?:-(${c[l.PRERELEASEIDENTIFIER]}(?:\\.${c[l.PRERELEASEIDENTIFIER]})*))`),p("PRERELEASELOOSE",`(?:-?(${c[l.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[l.PRERELEASEIDENTIFIERLOOSE]})*))`),p("BUILDIDENTIFIER",`${d}+`),p("BUILD",`(?:\\+(${c[l.BUILDIDENTIFIER]}(?:\\.${c[l.BUILDIDENTIFIER]})*))`),p("FULLPLAIN",`v?${c[l.MAINVERSION]}${c[l.PRERELEASE]}?${c[l.BUILD]}?`),p("FULL",`^${c[l.FULLPLAIN]}$`),p("LOOSEPLAIN",`[v=\\s]*${c[l.MAINVERSIONLOOSE]}${c[l.PRERELEASELOOSE]}?${c[l.BUILD]}?`),p("LOOSE",`^${c[l.LOOSEPLAIN]}$`),p("GTLT","((?:<|>)?=?)"),p("XRANGEIDENTIFIERLOOSE",`${c[l.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),p("XRANGEIDENTIFIER",`${c[l.NUMERICIDENTIFIER]}|x|X|\\*`),p("XRANGEPLAIN",`[v=\\s]*(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:\\.(${c[l.XRANGEIDENTIFIER]})(?:${c[l.PRERELEASE]})?${c[l.BUILD]}?)?)?`),p("XRANGEPLAINLOOSE",`[v=\\s]*(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[l.XRANGEIDENTIFIERLOOSE]})(?:${c[l.PRERELEASELOOSE]})?${c[l.BUILD]}?)?)?`),p("XRANGE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAIN]}$`),p("XRANGELOOSE",`^${c[l.GTLT]}\\s*${c[l.XRANGEPLAINLOOSE]}$`),p("COERCEPLAIN",`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),p("COERCE",`${c[l.COERCEPLAIN]}(?:$|[^\\d])`),p("COERCEFULL",c[l.COERCEPLAIN]+`(?:${c[l.PRERELEASE]})?`+`(?:${c[l.BUILD]})?(?:$|[^\\d])`),p("COERCERTL",c[l.COERCE],!0),p("COERCERTLFULL",c[l.COERCEFULL],!0),p("LONETILDE","(?:~>?)"),p("TILDETRIM",`(\\s*)${c[l.LONETILDE]}\\s+`,!0),t.tildeTrimReplace="$1~",p("TILDE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAIN]}$`),p("TILDELOOSE",`^${c[l.LONETILDE]}${c[l.XRANGEPLAINLOOSE]}$`),p("LONECARET","(?:\\^)"),p("CARETTRIM",`(\\s*)${c[l.LONECARET]}\\s+`,!0),t.caretTrimReplace="$1^",p("CARET",`^${c[l.LONECARET]}${c[l.XRANGEPLAIN]}$`),p("CARETLOOSE",`^${c[l.LONECARET]}${c[l.XRANGEPLAINLOOSE]}$`),p("COMPARATORLOOSE",`^${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]})$|^$`),p("COMPARATOR",`^${c[l.GTLT]}\\s*(${c[l.FULLPLAIN]})$|^$`),p("COMPARATORTRIM",`(\\s*)${c[l.GTLT]}\\s*(${c[l.LOOSEPLAIN]}|${c[l.XRANGEPLAIN]})`,!0),t.comparatorTrimReplace="$1$2$3",p("HYPHENRANGE",`^\\s*(${c[l.XRANGEPLAIN]})\\s+-\\s+(${c[l.XRANGEPLAIN]})\\s*$`),p("HYPHENRANGELOOSE",`^\\s*(${c[l.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[l.XRANGEPLAINLOOSE]})\\s*$`),p("STAR","(<|>)?=?\\s*\\*"),p("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),p("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")}(em,em.exports)),em.exports}function nm(){if(Xp)return Jp;Xp=1;const e=jp(),{MAX_LENGTH:t,MAX_SAFE_INTEGER:n}=qp(),{safeRe:r,t:o}=tm(),i=function(){if(Vp)return Hp;Vp=1;const e=Object.freeze({loose:!0}),t=Object.freeze({});return Hp=n=>n?"object"!=typeof n?e:n:t}(),{compareIdentifiers:s}=function(){if(Wp)return Kp;Wp=1;const e=/^[0-9]+$/,t=(t,n)=>{if("number"==typeof t&&"number"==typeof n)return t===n?0:t<n?-1:1;const r=e.test(t),o=e.test(n);return r&&o&&(t=+t,n=+n),t===n?0:r&&!o?-1:o&&!r?1:t<n?-1:1};return Kp={compareIdentifiers:t,rcompareIdentifiers:(e,n)=>t(n,e)}}();class a{constructor(s,c){if(c=i(c),s instanceof a){if(s.loose===!!c.loose&&s.includePrerelease===!!c.includePrerelease)return s;s=s.version}else if("string"!=typeof s)throw new TypeError(`Invalid version. Must be a string. Got type "${typeof s}".`);if(s.length>t)throw new TypeError(`version is longer than ${t} characters`);e("SemVer",s,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;const u=s.trim().match(c.loose?r[o.LOOSE]:r[o.FULL]);if(!u)throw new TypeError(`Invalid Version: ${s}`);if(this.raw=s,this.major=+u[1],this.minor=+u[2],this.patch=+u[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");u[4]?this.prerelease=u[4].split(".").map(e=>{if(/^[0-9]+$/.test(e)){const t=+e;if(t>=0&&t<n)return t}return e}):this.prerelease=[],this.build=u[5]?u[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(t){if(e("SemVer.compare",this.version,this.options,t),!(t instanceof a)){if("string"==typeof t&&t===this.version)return 0;t=new a(t,this.options)}return t.version===this.version?0:this.compareMain(t)||this.comparePre(t)}compareMain(e){return e instanceof a||(e=new a(e,this.options)),this.major<e.major?-1:this.major>e.major?1:this.minor<e.minor?-1:this.minor>e.minor?1:this.patch<e.patch?-1:this.patch>e.patch?1:0}comparePre(t){if(t instanceof a||(t=new a(t,this.options)),this.prerelease.length&&!t.prerelease.length)return-1;if(!this.prerelease.length&&t.prerelease.length)return 1;if(!this.prerelease.length&&!t.prerelease.length)return 0;let n=0;do{const r=this.prerelease[n],o=t.prerelease[n];if(e("prerelease compare",n,r,o),void 0===r&&void 0===o)return 0;if(void 0===o)return 1;if(void 0===r)return-1;if(r!==o)return s(r,o)}while(++n)}compareBuild(t){t instanceof a||(t=new a(t,this.options));let n=0;do{const r=this.build[n],o=t.build[n];if(e("build compare",n,r,o),void 0===r&&void 0===o)return 0;if(void 0===o)return 1;if(void 0===r)return-1;if(r!==o)return s(r,o)}while(++n)}inc(e,t,n){if(e.startsWith("pre")){if(!t&&!1===n)throw new Error("invalid increment argument: identifier is empty");if(t){const e=`-${t}`.match(this.options.loose?r[o.PRERELEASELOOSE]:r[o.PRERELEASE]);if(!e||e[1]!==t)throw new Error(`invalid identifier: ${t}`)}}switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",t,n);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",t,n);break;case"prepatch":this.prerelease.length=0,this.inc("patch",t,n),this.inc("pre",t,n);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",t,n),this.inc("pre",t,n);break;case"release":if(0===this.prerelease.length)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":{const e=Number(n)?1:0;if(0===this.prerelease.length)this.prerelease=[e];else{let r=this.prerelease.length;for(;--r>=0;)"number"==typeof this.prerelease[r]&&(this.prerelease[r]++,r=-2);if(-1===r){if(t===this.prerelease.join(".")&&!1===n)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(e)}}if(t){let r=[t,e];if(!1===n&&(r=[t]),((e,t)=>{const n=t.split(".");if(n.length>e.length)return!1;for(let t=0;t<n.length;t++)if(0!==s(e[t],n[t]))return!1;return!0})(this.prerelease,t)){const e=this.prerelease[t.split(".").length];isNaN(e)&&(this.prerelease=r)}else this.prerelease=r}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return Jp=a}var rm=Vr(function(){if(Qp)return Yp;Qp=1;const e=nm();return Yp=(t,n)=>new e(t,n).major}());const om="2.8.1-7cf53193";om.split("-")[0];const im="8.1.0",sm=xd({commitment:ad(),radius:ad(),storageRadius:ad(),reserveCapacityDoubling:ad()}),am=xd({block:ad(),chainTip:ad(),totalAmount:Lf().transform(e=>jh(e,{name:"totalAmount"})),currentPrice:Lf().transform(Number).transform(e=>{return t=e,Number.isInteger(t)?t<24e3?24e3:t:24e3;var t}),minimumValidityBlocks:ad().optional()}),cm=xd({bzzBalance:Lf().transform(e=>gh.fromPLUR(jh(e,{name:"bzzBalance"}))),nativeTokenBalance:Lf().transform(e=>yh.fromWei(jh(e,{name:"nativeTokenBalance"}))),chainID:ad(),chequebookContractAddress:Lf(),walletAddress:Lf()}),um=xd({transactionHash:Lf().transform(e=>new Xs(e))}),lm=xd({address:Lf().nullish().transform(e=>e??""),seen:ad(),sent:ad(),split:ad(),startedAt:Lf(),stored:ad(),synced:ad(),uid:ad()}),fm=xd({tags:Ed(lm)}),dm=xd({transactionHash:Lf().transform(e=>new Xs(e)),to:Lf(),nonce:ad(),gasPrice:Lf().transform(e=>jh(e,{name:"gasPrice"})),gasLimit:ad(),data:Lf(),created:Lf(),description:Lf(),value:Lf().transform(e=>jh(e,{name:"value"}))}),hm=xd({pendingTransactions:Ed(dm)}),pm=dm,mm=xd({transactionHash:Lf().transform(e=>new Xs(e))});new zs("0000000000000000000000000000000000000000000000000000000000000000"),new Js("0000000000000000000000000000000000000000000000000000000000000000");const gm=new Uint8Array(32);function ym(e){return e.endsWith("/")?e.slice(0,-1):e}function wm(e){try{const{protocol:t}=new URL(e);return"http:"===t||"https:"===t}catch{return!1}}function bm(e){if(!wm(e)||/[\s?#]/.test(e))return!1;const{username:t,password:n}=new URL(e);return""===t&&""===n}function vm(e,t,n,r){const o=new URLSearchParams;return o.set("origin",t),n&&(o.set("appName",n.name),n.description&&o.set("appDescription",n.description),n.icon&&o.set("appIcon",n.icon)),r?.challenge&&o.set("challenge",r.challenge),`${e}/connect#${o.toString()}`}const Em="https://api.gateway.ethswarm.org/",_m="https://xdai.fairdatasociety.org/",xm=e=>Fn().regex(new RegExp(`^[0-9a-fA-F]{${e}}$`),{message:`Must be a ${e}-character hex string`}),km=Fn().regex(/^[0-9a-fA-F]{64}$|^[0-9a-fA-F]{128}$/,{message:"Reference must be 64 hex chars (32 bytes) or 128 hex chars (64 bytes for encrypted)"}),Am=xm(64),Im=xm(40),$m=xm(64),Bm=xm(66),zm=xm(64),Sm=xm(64),Om=xm(130),Tm=xm(64),Nm=xm(226),Rm=Hr(e=>"bigint"==typeof e?e.toString():e,Er([ir(),Fn()])),Um=Hr(e=>"bigint"==typeof e?e.toString():e,Er([ir(),Fn()])),Pm=Im.transform(e=>new Ns(e)),Fm=Am.transform(e=>new zs(e)),Cm=$m.transform(e=>new Hs(e)),Lm=Fn().regex(/^\d+$/,{message:"Must be a decimal integer string"}).transform(e=>BigInt(e)),Mm=wr({deviceId:Fn(),createdAt:ir(),lastSignedInAt:ir(),name:Fn().optional(),nameUpdatedAt:ir().optional(),removedAt:ir().optional()}),Dm=wr({message:Fn().max(512),signature:Fn().regex(/^0x[0-9a-fA-F]{130}$/)}),Zm="none",jm=wr({appUrl:Fn(),appName:Fn(),lastConnectedAt:ir(),appIcon:Fn().optional(),appDescription:Fn().optional(),connectedUntil:ir().optional(),appSecret:Fn().optional(),postageStampBatchID:Er([Sr(Zm),Fm]).optional(),postageStampBatchIDAt:ir().optional(),stampPending:Sr(!0).optional(),revokedAt:ir().optional(),disconnectedAt:ir().optional(),chatBinding:Dm.optional()}),qm=wr({batchID:Fm,signerKey:Cm,name:Fn().optional(),nameUpdatedAt:ir().optional(),utilization:ir(),usable:ur(),depth:ir(),amount:Lm,bucketDepth:ir(),blockNumber:ir(),immutableFlag:ur(),exists:ur(),batchTTL:ir().optional(),createdAt:ir(),updatedAt:ir().optional(),deletedAt:ir().optional()}),Gm=xr("type",[wr({type:Sr("passkey"),credentialId:Fn()}),wr({type:Sr("eth-wallet"),encryptionSalt:Fn()}),wr({type:Sr("password"),kdfSalt:Fn(),kdfIterations:ir()})]),Hm=wr({access:Gm,encryptedSeed:Fn().regex(/^([0-9a-f]{2})+$/)}),Vm=wr({id:Pm,name:Fn(),createdAt:ir(),derivationKey:Fn().length(64),publicKey:Bm,defaultPostageStampBatchID:Fm.optional(),devices:gr(Mm).default([]),connectedApps:gr(jm).default([]),postageStamps:gr(qm).default([]),settings:wr({appSessionDuration:ir().optional()}).optional(),accountNameAt:ir().optional(),defaultStampAt:ir().optional(),settingsAt:ir().optional(),lastModified:ir().optional(),partitionCount:ir().int().min(1).optional()}),Km=Vm.extend({...Hm.shape,signedOutAt:function(e){return function(e,t){return new e({type:"undefined",...x(t)})}(lr,e)}().optional()}),Wm=Er([Km,wr({id:Pm,name:Fn(),createdAt:ir(),...Hm.shape,encryptedState:Fn().optional(),storageWarning:ur().optional(),soonestDriveExpiry:ir().optional(),signedOutAt:ir()})]),Jm=wr({accountName:Fn(),defaultPostageStampBatchID:Fn().length(64).optional(),publicKey:Bm,settings:wr({appSessionDuration:ir().optional()}).optional(),accountNameAt:ir().optional(),defaultStampAt:ir().optional(),settingsAt:ir().optional(),createdAt:ir(),lastModified:ir(),devices:gr(Mm).default([]),partitionCount:ir().int().min(1).default(1)}),Xm=wr({version:Sr(1),timestamp:ir(),accountId:Fn().length(40),metadata:Jm,connectedApps:gr(jm),postageStamps:gr(qm)});function Ym(e){return void 0!==e.signedOutAt}const Qm=wr({timestampMs:ir().int().nonnegative(),tiebreaker:Fn().regex(/^[0-9a-f]{16}$/)}),eg=wr({holderDeviceId:Fn(),generation:Qm,acquiredAt:ir().int().nonnegative(),leasedUntil:ir().int().nonnegative()}),tg=wr({deviceId:Fn(),generation:Qm,leasedUntil:ir().int().nonnegative().optional()}),ng=wr({beeNodeUrl:Fn().refine(wm,"Must be an http(s) URL"),gnosisRpcUrl:Fn().refine(wm,"Must be an http(s) URL")}),rg=Fn().refine(bm,"Must be an http(s) URL, optionally with a path, and no credentials, query or fragment"),og=wr({index:ir().int().min(0).max(65535),value:ir().int().min(0)}),ig=wr({type:Sr("utilization-updated"),batchId:Fn().length(64),partition:ir().int().min(0),partitionCount:ir().int().min(1),buckets:gr(og)}),sg="swarm-id-accounts",ag="swarm-id-network-settings",cg="swarm-storage-challenge",ug="swarm-id-site-allow-list";function lg(e,t){return`swarm-id-lease-v2:${e.toLowerCase()}:${t.toLowerCase()}`}function fg(e,t){return`swarm-id-app-stamp-usage:${e}:${t.toLowerCase()}`}function dg(e,t){return`swarm-id-soc-restamp-slots:${e}:${t.toLowerCase()}`}function hg(e){return`swarm-id-partition-session:${e}`}const pg=wr({pin:ur().optional(),encrypt:ur().optional(),encryptManifest:ur().optional(),tag:ir().optional(),deferred:ur().optional()}),mg=pg.optional(),gg=Br(["app","identity"]),yg=pg.extend({beeCompatible:ur().optional(),publisher:gg.optional()}).optional(),wg=wr({timeout:ir().optional(),headers:Ir(Fn(),Fn()).optional(),endlesslyRetry:ur().optional()}).optional(),bg=wr({redundancyStrategy:Er([Sr(0),Sr(1),Sr(2),Sr(3)]).optional(),fallback:ur().optional(),timeoutMs:ir().optional(),actPublisher:Er([Gr(Uint8Array),Fn()]).optional(),actHistoryAddress:Er([Gr(Uint8Array),Fn()]).optional(),actTimestamp:Er([ir(),Fn()]).optional()}).optional(),vg=pg.extend({indexDocument:Fn().optional(),errorDocument:Fn().optional()}).optional(),Eg=wr({path:Fn().min(1),data:Gr(Uint8Array),contentType:Fn().optional()}),_g=wr({path:Fn(),reference:km,contentType:Fn().optional()}),xg=wr({reference:km,tagUid:ir().optional()});xg.extend({encryptionKey:Fn().optional(),owner:Im}),xg.extend({encryptionKey:Fn().optional(),owner:Im}),wr({name:Fn(),data:Gr(Uint8Array)});const kg=wr({batchID:Am,utilization:ir(),usable:ur(),label:Fn(),depth:ir(),amount:Fn(),bucketDepth:ir(),blockNumber:ir(),immutableFlag:ur(),exists:ur(),batchTTL:ir().optional()});wr({authenticated:ur(),origin:Fn().optional(),beeApiUrl:Fn().url().optional()});const Ag=Br(["user-stamp","subsidised","unavailable"]),Ig=Br(["no-stamp","stamper-failed","stamp-expired","stamp-not-usable","subsidised","app-stamp-count","app-stamp-rate","app-bucket-share","app-slice-full","session-unconfirmed"]),$g=wr({source:Br(["generated"]),url:Fn()}),Bg=wr({id:Fn(),name:Fn(),address:Im,publicKey:Bm.optional(),sharingPublicKey:Bm.optional(),postageSignerAddress:Im.optional(),avatar:$g});wr({canUpload:ur(),storagePartitioned:ur().optional(),uploadMode:Ag.optional(),uploadUnavailableReason:Ig.optional(),partition:ir().int().min(0).optional(),identity:Bg.optional(),appKey:wr({address:Im,publicKey:Bm}).optional(),chatBinding:Dm.optional(),beeApiUrl:Fn().optional(),postageBatchId:Am.optional()});const zg=wr({name:Fn().min(1).max(100),description:Fn().max(500).optional(),icon:Fn().optional().refine(e=>{if(!e)return!0;if(!e.startsWith("data:image/"))return!1;if(!e.match(/^data:image\/(svg\+xml|png);/))return!1;const t=e.match(/base64,(.+)$/);if(t){if(3*t[1].length/4>4096)return!1}return!0},{message:"Icon must be a data URL with SVG or PNG mime type, max 4KB"})}),Sg=Br(["sign-in","change-stamp"]),Og=["localhost","127.0.0.1","[::1]"];const Tg=wr({family:Fn().min(1),url:Fn().refine(function(e){let t;try{t=new URL(e)}catch{return!1}return!t.username&&!t.password&&("https:"===t.protocol||"http:"===t.protocol&&Og.includes(t.hostname))},{message:"A font file is served over https, or over http on localhost, with no user name or password in its URL"}),weight:Er([Fn(),ir()]).optional(),style:Br(["normal","italic","oblique"]).optional()}),Ng=wr({text:Fn().optional(),busyText:Fn().optional(),ariaLabel:Fn().optional(),disabled:ur().optional(),busy:ur().optional(),backgroundColor:Fn().optional(),color:Fn().optional(),borderRadius:Fn().optional(),borderColor:Fn().optional(),borderWidth:Fn().optional(),borderStyle:Br(["solid","dashed","dotted","double"]).optional(),fontFamily:Fn().optional(),fontSize:Fn().optional(),fontWeight:Er([Fn(),ir()]).optional(),fontFaces:gr(Tg).max(8).optional()}),Rg=Br(["open","closed","blocked"]),Ug=wr({type:Sr("buttonIdentify"),action:Sg,config:Ng.optional(),metadata:zg,popupMode:Br(["popup","window"]).optional()}),Pg=wr({type:Sr("buttonUpdate"),action:Sg,config:Ng.optional()});xr("type",[Ug,Pg]);const Fg=xr("type",[wr({type:Sr("buttonReady")}),wr({type:Sr("buttonInitError"),error:Fn()}),wr({type:Sr("buttonWindowChanged"),state:Rg})]),Cg=wr({type:Sr("connectWindowOpened"),challenge:Fn()}),Lg="buttonFrameLoaded",Mg=wr({type:Sr("parentIdentify"),requestId:Fn(),beeApiUrl:rg.optional(),metadata:zg,subsidisedGatewayUrl:Fn().url().optional()}),Dg=wr({type:Sr("checkAuth"),requestId:Fn()}),Zg=wr({type:Sr("disconnect"),requestId:Fn()}),jg=wr({type:Sr("uploadData"),requestId:Fn(),data:Gr(Uint8Array),options:mg,requestOptions:wg,enableProgress:ur().optional(),useWebSocket:ur().optional(),useWorkers:ur().optional(),workerCount:ir().int().min(1).max(32).optional(),concurrency:ir().int().min(1).max(256).optional()}),qg=wr({type:Sr("downloadData"),requestId:Fn(),reference:km,options:bg,requestOptions:wg}),Gg=wr({type:Sr("deriveAppSecret"),requestId:Fn(),label:Fn()}),Hg=wr({type:Sr("setBeeApiUrl"),requestId:Fn(),beeApiUrl:rg}),Vg=wr({type:Sr("getChatKey"),requestId:Fn()}),Kg=Er([Sr("app"),br({privateKey:$m})]),Wg=xr("kind",[br({kind:Sr("content"),data:Gr(Uint8Array)}),br({kind:Sr("soc"),identifier:Sm,data:Gr(Uint8Array),signer:Kg})]),Jg=br({type:Sr("stampChunk"),requestId:Fn(),chunk:Wg}),Xg=wr({type:Sr("uploadFile"),requestId:Fn(),data:Gr(Uint8Array),name:Fn().optional(),options:mg,requestOptions:wg,enableProgress:ur().optional(),useWebSocket:ur().optional(),useWorkers:ur().optional(),workerCount:ir().int().min(1).max(32).optional(),concurrency:ir().int().min(1).max(256).optional()}),Yg=wr({type:Sr("downloadFile"),requestId:Fn(),reference:km,path:Fn().optional(),options:bg,requestOptions:wg}),Qg=wr({type:Sr("uploadFiles"),requestId:Fn(),files:gr(Eg),options:vg,requestOptions:wg,enableProgress:ur().optional(),useWorkers:ur().optional(),workerCount:ir().int().min(1).max(32).optional()}),ey=wr({type:Sr("listFiles"),requestId:Fn(),reference:km,requestOptions:wg}),ty=wr({type:Sr("uploadChunk"),requestId:Fn(),data:Gr(Uint8Array),options:mg,requestOptions:wg}),ny=wr({type:Sr("downloadChunk"),requestId:Fn(),reference:km,options:bg,requestOptions:wg}),ry=wr({type:Sr("isConnected"),requestId:Fn()}),oy=wr({type:Sr("getNodeInfo"),requestId:Fn()}),iy=wr({type:Sr("gsocMine"),requestId:Fn(),targetOverlay:Fn(),identifier:Fn(),proximity:ir().optional()}),sy=wr({type:Sr("gsocSend"),requestId:Fn(),signer:Fn(),identifier:Fn(),data:Gr(Uint8Array),options:mg,requestOptions:wg}),ay=wr({type:Sr("socUpload"),requestId:Fn(),identifier:Sm,data:Gr(Uint8Array),signer:$m.optional(),options:mg,requestOptions:wg}),cy=wr({type:Sr("socRawUpload"),requestId:Fn(),identifier:Sm,data:Gr(Uint8Array),signer:$m.optional(),options:mg,requestOptions:wg}),uy=wr({type:Sr("socDownload"),requestId:Fn(),owner:Im.optional(),identifier:Sm,encryptionKey:zm,requestOptions:wg}),ly=wr({type:Sr("socRawDownload"),requestId:Fn(),owner:Im.optional(),identifier:Sm,encryptionKey:zm.optional(),requestOptions:wg}),fy=wr({type:Sr("socGetOwner"),requestId:Fn()}),dy=wr({type:Sr("epochFeedDownloadReference"),requestId:Fn(),topic:Sm,owner:Im.optional(),at:Rm,after:Rm.optional(),encryptionKey:zm.optional(),requestOptions:wg}),hy=wr({lastEpoch:wr({start:Fn(),level:ir()}).optional(),lastTimestamp:Fn().optional()}).optional(),py=xr("type",[Mg,Dg,Zg,jg,qg,Gg,Vg,Hg,Jg,Xg,Yg,Qg,ey,ty,ny,ry,oy,iy,sy,ay,cy,uy,ly,fy,dy,wr({type:Sr("epochFeedUploadReference"),requestId:Fn(),topic:Sm,signer:$m.optional(),at:Rm,reference:km,encryptionKey:zm.optional(),hints:hy,requestOptions:wg}),wr({type:Sr("feedGetOwner"),requestId:Fn()}),wr({type:Sr("seqFeedGetOwner"),requestId:Fn()}),wr({type:Sr("seqFeedDownloadPayload"),requestId:Fn(),topic:Sm,owner:Im.optional(),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm,requestOptions:wg}),wr({type:Sr("seqFeedDownloadRawPayload"),requestId:Fn(),topic:Sm,owner:Im.optional(),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm.optional(),requestOptions:wg}),wr({type:Sr("seqFeedDownloadReference"),requestId:Fn(),topic:Sm,owner:Im.optional(),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm,requestOptions:wg}),wr({type:Sr("seqFeedUploadPayload"),requestId:Fn(),topic:Sm,signer:$m.optional(),data:Gr(Uint8Array),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),options:mg,requestOptions:wg}),wr({type:Sr("seqFeedUploadRawPayload"),requestId:Fn(),topic:Sm,signer:$m.optional(),data:Gr(Uint8Array),index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),encryptionKey:zm.optional(),options:mg,requestOptions:wg}),wr({type:Sr("seqFeedUploadReference"),requestId:Fn(),topic:Sm,signer:$m.optional(),reference:km,index:Um.optional(),at:Rm.optional(),hasTimestamp:ur().optional(),lookupTimeoutMs:ir().optional(),options:mg,requestOptions:wg}),wr({type:Sr("createFeedManifest"),requestId:Fn(),topic:Sm,owner:Im.optional(),feedType:Br(["Sequence","Epoch"]).optional(),uploadOptions:mg,requestOptions:wg}),wr({type:Sr("actUploadData"),requestId:Fn(),data:Gr(Uint8Array),grantees:gr(Fn()),options:yg,requestOptions:wg,enableProgress:ur().optional()}),wr({type:Sr("actDownloadData"),requestId:Fn(),encryptedReference:km,historyReference:km,publisherPubKey:Fn(),timestamp:ir().optional(),requestOptions:wg}),wr({type:Sr("actAddGrantees"),requestId:Fn(),historyReference:km,grantees:gr(Fn()),requestOptions:wg}),wr({type:Sr("actRevokeGrantees"),requestId:Fn(),historyReference:km,encryptedReference:km,revokeGrantees:gr(Fn()),requestOptions:wg}),wr({type:Sr("actGetGrantees"),requestId:Fn(),historyReference:km,requestOptions:wg}),wr({type:Sr("getPostageBatch"),requestId:Fn()})]),my=wr({type:Sr("proxyReady"),authenticated:ur(),parentOrigin:Fn(),storageShared:ur().optional()}),gy=wr({type:Sr("initError"),error:Fn()}),yy=wr({type:Sr("authStatusResponse"),requestId:Fn(),authenticated:ur(),origin:Fn().optional(),beeApiUrl:Fn().url().optional()}),wy=wr({type:Sr("disconnectResponse"),requestId:Fn(),success:ur()}),by=wr({type:Sr("authSuccess"),origin:Fn()}),vy=wr({type:Sr("uploadDataResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),Ey=wr({type:Sr("downloadDataResponse"),requestId:Fn(),data:Gr(Uint8Array)}),_y=wr({type:Sr("deriveAppSecretResponse"),requestId:Fn(),secret:Gr(Uint8Array)}),xy=wr({type:Sr("getChatKeyResponse"),requestId:Fn(),chatKey:Gr(Uint8Array)}),ky=wr({type:Sr("setBeeApiUrlResponse"),requestId:Fn(),beeApiUrl:Fn()}),Ay=wr({type:Sr("stampChunkResponse"),requestId:Fn(),address:Tm,stamp:Nm,owner:Im.optional(),signature:Om.optional()}),Iy=wr({type:Sr("uploadFileResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),$y=wr({type:Sr("downloadFileResponse"),requestId:Fn(),name:Fn(),data:Gr(Uint8Array)}),By=wr({type:Sr("uploadFilesResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),zy=wr({type:Sr("listFilesResponse"),requestId:Fn(),entries:gr(_g)}),Sy=wr({type:Sr("uploadChunkResponse"),requestId:Fn(),reference:km}),Oy=wr({type:Sr("downloadChunkResponse"),requestId:Fn(),data:Gr(Uint8Array)}),Ty=wr({type:Sr("uploadProgress"),requestId:Fn(),total:ir(),processed:ir()}),Ny=Br(["not-authenticated","upload-unavailable","partition-contended","lease-lost","bee-rejected","network","timeout","invalid-request","invalid-state","init-failed","popup-blocked","button-required","internal"]),Ry=xr("type",[my,gy,yy,wy,by,vy,Ey,_y,xy,ky,Ay,Iy,$y,By,zy,Sy,Oy,Ty,wr({error:Fn(),code:Ny.catch("internal"),reason:Ig.optional().catch(void 0),status:ir().int().optional(),beeMessage:Fn().optional(),url:Fn().optional()}).extend({type:Sr("error"),requestId:Fn()}),wr({type:Sr("connectionInfoChanged"),canUpload:ur(),storagePartitioned:ur().optional(),uploadMode:Ag.optional(),uploadUnavailableReason:Ig.optional().catch(void 0),identity:Bg.optional(),appKey:wr({address:Im,publicKey:Bm}).optional(),partition:ir().int().min(0).optional(),chatBinding:Dm.optional(),beeApiUrl:Fn().optional(),postageBatchId:Am.optional()}),wr({type:Sr("isConnectedResponse"),requestId:Fn(),connected:ur()}),wr({type:Sr("getNodeInfoResponse"),requestId:Fn(),beeMode:Fn(),chequebookEnabled:ur(),swapEnabled:ur()}),wr({type:Sr("gsocMineResponse"),requestId:Fn(),signer:Fn()}),wr({type:Sr("gsocSendResponse"),requestId:Fn(),reference:km,tagUid:ir().optional()}),wr({type:Sr("socUploadResponse"),requestId:Fn(),reference:km,tagUid:ir().optional(),encryptionKey:Fn().optional(),owner:Im}),wr({type:Sr("socRawUploadResponse"),requestId:Fn(),reference:km,tagUid:ir().optional(),encryptionKey:Fn().optional(),owner:Im}),wr({type:Sr("socDownloadResponse"),requestId:Fn(),data:Gr(Uint8Array),identifier:Sm,signature:Om,span:ir(),payload:Gr(Uint8Array),address:km,owner:Im}),wr({type:Sr("socRawDownloadResponse"),requestId:Fn(),data:Gr(Uint8Array),identifier:Sm,signature:Om,span:ir(),payload:Gr(Uint8Array),address:km,owner:Im}),wr({type:Sr("socGetOwnerResponse"),requestId:Fn(),owner:Im}),wr({type:Sr("epochFeedDownloadReferenceResponse"),requestId:Fn(),reference:km.optional()}),wr({type:Sr("epochFeedUploadReferenceResponse"),requestId:Fn(),socAddress:km,encryptionKey:zm.optional(),epoch:wr({start:Fn(),level:ir()}),timestamp:Fn()}),wr({type:Sr("feedGetOwnerResponse"),requestId:Fn(),owner:Im}),wr({type:Sr("seqFeedGetOwnerResponse"),requestId:Fn(),owner:Im}),wr({type:Sr("seqFeedDownloadPayloadResponse"),requestId:Fn(),payload:Gr(Uint8Array),timestamp:ir().optional(),feedIndex:Fn(),feedIndexNext:Fn()}),wr({type:Sr("seqFeedDownloadRawPayloadResponse"),requestId:Fn(),payload:Gr(Uint8Array),timestamp:ir().optional(),feedIndex:Fn(),feedIndexNext:Fn()}),wr({type:Sr("seqFeedDownloadReferenceResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),feedIndexNext:Fn()}),wr({type:Sr("seqFeedUploadPayloadResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),owner:Im,encryptionKey:Fn().optional(),tagUid:ir().optional()}),wr({type:Sr("seqFeedUploadRawPayloadResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),owner:Im,encryptionKey:Fn().optional(),tagUid:ir().optional()}),wr({type:Sr("seqFeedUploadReferenceResponse"),requestId:Fn(),reference:km,feedIndex:Fn(),owner:Im,encryptionKey:Fn().optional(),tagUid:ir().optional()}),wr({type:Sr("createFeedManifestResponse"),requestId:Fn(),reference:km}),wr({type:Sr("actUploadDataResponse"),requestId:Fn(),encryptedReference:km,historyReference:km,granteeListReference:km,publisherPubKey:Fn(),actReference:km,tagUid:ir().optional()}),wr({type:Sr("actDownloadDataResponse"),requestId:Fn(),data:Gr(Uint8Array)}),wr({type:Sr("actAddGranteesResponse"),requestId:Fn(),historyReference:km,granteeListReference:km,actReference:km}),wr({type:Sr("actRevokeGranteesResponse"),requestId:Fn(),encryptedReference:km,historyReference:km,granteeListReference:km,actReference:km}),wr({type:Sr("actGetGranteesResponse"),requestId:Fn(),grantees:gr(Fn())}),wr({type:Sr("getPostageBatchResponse"),requestId:Fn(),postageBatch:kg.optional()})]),Uy=wr({secret:Fn(),networkSettings:ng.optional(),account:Vm,chatBinding:Dm.optional(),stampPending:Sr(!0).optional()}),Py=wr({version:Sr(1),parentOrigin:Fn(),connectedUntil:ir(),data:Fn()}),Fy=xr("type",[wr({type:Sr("setSecret"),appOrigin:Fn(),challenge:Fn(),data:Uy})]),Cy="#FCFCFC",Ly="#131416",My=[["#FFE0CC","#DD7200","#401F00"],["#99CCFF","#0082FB","#003366"],["#99E6B3","#00C853","#004D1F"],["#E1BEE7","#9C27B0","#4A148C"]],Dy=[];for(const e of My)Dy.push([e[1],Cy]),Dy.push([e[1],Ly]),Dy.push([Cy,e[1]]),Dy.push([Ly,e[1]]);for(const e of My)Dy.push([e[0],e[1]]),Dy.push([e[2],e[1]]),Dy.push([e[1],e[0]]),Dy.push([e[1],e[2]]),Dy.push([e[0],e[2]]),Dy.push([e[2],e[0]]);for(let e=0;e<My.length;e++){const t=My[(e+1)%My.length];Dy.push([My[e][0],t[2]]),Dy.push([t[2],My[e][0]])}const Zy=[[0,1],[1,0],[0,-1],[-1,0]];function jy(e,t=40){const n=function(e){let t=0;for(let n=0;n<e.length;n++)t=e.charCodeAt(n)+(t<<6)+(t<<16)-t;return t}(e.length<6?e.padEnd(6," "):e),[r,o]=Dy[Math.abs(n)%Dy.length],i=.25*t,s=(t-2*i)/2,a=Array.from({length:2},()=>Array(2).fill(!1)),c=Math.floor(1),u=[[c,c]];a[c][c]=!0;let l="";for(let e=u.pop();void 0!==e;e=u.pop()){const[t,r]=e,o=15&Math.abs(n>>3*t+5*r),c=[];for(const[e,n]of Zy){const o=t+e,i=r+n;o>=0&&o<2&&i>=0&&i<2&&!a[o][i]&&c.push([o,i])}for(;c.length>0;){const e=Math.abs(o+c.length)%c.length,[t,n]=c.splice(e,1)[0];u.push([t,n]),a[t][n]=!0}const f=o%4*90,d=i+t*s,h=i+r*s;l+=o%5==0?`M${d},${h} h${s} v${s} h-${s}z `:0===f?`M${d},${h} h${s} v${s}z `:90===f?`M${d+s},${h} v${s} h-${s}z `:180===f?`M${d+s},${h+s} h-${s} v-${s}z `:`M${d},${h+s} v-${s} h${s}z `}return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}" viewBox="0 0 ${t} ${t}"><rect width="${t}" height="${t}" fill="${r}"/><path d="${l}" fill="${o}"/></svg>`}function qy(e,t=40){const n=jy(e,t);return{source:"generated",url:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}}function Gy(e){const t=e.replace(/^0x/i,"");if(t.length%2!=0||!/^[0-9a-fA-F]*$/.test(t))throw new Error("Invalid hex string.");const n=new Uint8Array(t.length/2);for(let e=0;e<t.length;e+=2)n[e/2]=parseInt(t.substring(e,e+2),16);return n}function Hy(e){return Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join("")}function Vy(e){const t=e.replace(/^0x/i,"").toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error(`Invalid hex address: expected 40 hex characters (with optional 0x prefix), got "${e}"`);return t}class Ky extends Error{constructor(e){super(e),this.name="TimeoutError"}}function Wy(e,t,n){let r;const o=new Promise((e,o)=>{r=setTimeout(()=>o(new Ky(n)),t)});return Promise.race([e,o]).finally(()=>clearTimeout(r))}function Jy(e){return new Promise(t=>setTimeout(t,e))}function Xy(e,t,n){let r,o=!1,i=()=>{};const s=new Promise((e,s)=>{i=()=>{o||(clearTimeout(r),r=setTimeout(()=>s(new Ky(n)),t))},i()}),a=(async()=>e(i))();return Promise.race([a,s]).finally(()=>{o=!0,clearTimeout(r)})}const Yy=0,Qy=4096,ew=8,tw=32,nw=8;class rw{constructor(e,t,n){this.encryptionKey=e,this.keyLen=e.length,this.padding=t,this.initCtr=n,this.index=0}key(){return this.encryptionKey}encrypt(e){const t=e.length;let n=t;if(this.padding>0){if(t>this.padding)throw new Error(`data length ${t} longer than padding ${this.padding}`);n=this.padding}const r=new Uint8Array(n);return this.transform(e,r),r}decrypt(e){const t=e.length;if(this.padding>0&&t!==this.padding)throw new Error(`data length ${t} different than padding ${this.padding}`);const n=new Uint8Array(t);return this.transform(e,n),n}reset(){this.index=0}transform(e,t){const n=e.length;for(let r=0;r<n;r+=this.keyLen){const o=Math.min(this.keyLen,n-r);this.transcrypt(this.index,e.subarray(r,r+o),t.subarray(r,r+o)),this.index++}ow(t.subarray(n))}transcrypt(e,t,n){const r=new Uint8Array(4);new DataView(r.buffer).setUint32(0,e+this.initCtr,!0);const o=new Uint8Array(this.encryptionKey.length+4);o.set(this.encryptionKey),o.set(r,this.encryptionKey.length);const i=Jr.Binary.keccak256(o),s=Jr.Binary.keccak256(i),a=t.length;for(let e=0;e<a;e++)n[e]=t[e]^s[e];ow(n.subarray(a))}}function ow(e){0!==e.length&&crypto.getRandomValues(e)}function iw(e=32){const t=new Uint8Array(e);return ow(t),t}function sw(e){return new rw(e,0,Math.floor(128))}function aw(e){return new rw(e,4096,0)}class cw{encryptChunk(e,t){const n=t||iw(32);return{key:n,encryptedSpan:sw(n).encrypt(e.subarray(0,8)),encryptedData:aw(n).encrypt(e.subarray(8))}}}function uw(){return new cw}function lw(e,t){const n=sw(e).decrypt(t.subarray(0,8)),r=aw(e).decrypt(t.subarray(8)),o=new Uint8Array(8+r.length);return o.set(n),o.set(r,8),o}const fw=4096;function dw(e){const t=e.slice(0,Ks.LENGTH),n=function(e){if(e.length>fw)throw new Error(`payload size ${e.length} exceeds maximum chunk payload size 4096`);const t=new Uint8Array(fw);t.set(e);let n=Jr.Binary.partition(t,32);for(;n.length>1;){const e=[];for(let t=0;t<n.length;t+=2){const r=n[t],o=n[t+1],i=Jr.Binary.concatBytes(r,o),s=Jr.Binary.keccak256(i);e.push(s)}n=e}return n[0]}(e.slice(Ks.LENGTH)),r=Jr.Binary.keccak256(Jr.Binary.concatBytes(t,n));return new Vs(r)}const hw=new TextEncoder;function pw(e,t){if(e instanceof Uint8Array||(e=hw.encode(e)),e.length<0||e.length>Qy)throw new RangeError(`payload size ${e.length} exceeds limits [0, 4096]`);let n;n=t instanceof Ks?t:"bigint"==typeof t?Ks.fromBigInt(t):Ks.fromBigInt(BigInt(e.length));const r=Jr.Binary.concatBytes(n.toUint8Array(),e),o=dw(r);return{data:r,span:n,payload:new Bs(e),address:o}}const mw=new TextEncoder;function gw(e,t){if(e instanceof Uint8Array||(e=mw.encode(e)),e.length<0||e.length>Qy)throw new RangeError(`payload size ${e.length} exceeds limits [0, 4096]`);const n=Ks.fromBigInt(BigInt(e.length)),r=Jr.Binary.concatBytes(n.toUint8Array(),e),o=uw(),{key:i,encryptedSpan:s,encryptedData:a}=o.encryptChunk(r,t),c=Jr.Binary.concatBytes(s,a),u=dw(c),l=new Vs(Jr.Binary.concatBytes(u.toUint8Array(),i));return{data:c,encryptionKey:i,span:n,payload:new Bs(c.slice(Ks.LENGTH)),address:u,reference:l}}function yw(e){const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return Number(t.getBigUint64(0,!0))}function ww(e,t){return new Vs(Jr.Binary.keccak256(Jr.Binary.concatBytes(e.toUint8Array(),t.toUint8Array())))}function bw(e,t,n,r){const o=new Fs(e.slice(0,32)),i=Gs.fromSlice(e,32),s=e.slice(97),a=dw(s),c=Jr.Binary.concatBytes(o.toUint8Array(),a.toUint8Array()),u=i.recoverPublicKey(c).address();if(!u.equals(n))throw new Error("SOC owner mismatch");const l=ww(o,u);if(!Jr.Binary.equals(t.toUint8Array(),l.toUint8Array()))throw new Error("SOC data does not match given address");let f,d,h;if(r){const e=lw(r,s);f=e.slice(0,8);const t=yw(f);d=e.slice(8,8+t),h=Jr.Binary.concatBytes(o.toUint8Array(),i.toUint8Array(),f,d)}else{f=e.slice(97,105);const t=yw(f);if(t>4096)throw new Error("SOC payload length is invalid; this chunk likely requires decryption");d=e.slice(105,105+t),h=e}const p=yw(f);return{data:h,identifier:o.toHex(),signature:i.toHex(),span:p,payload:d,address:t.toHex(),owner:u.toHex()}}function vw(e,t,n){const r=[],o=n?64:tw,i=Math.floor(e.length/o),s=Math.ceil(t/Qy),a=Math.min(i,s);for(let t=0;t<a;t++){const i=t*o;if(i+o>e.length)break;const s=e.slice(i,i+tw);if(s.every(e=>0===e))break;if(n){const t=e.slice(i+tw,i+64);r.push({address:s,encryptionKey:t})}else r.push({address:s})}return r}async function Ew(e,t,n){const r=Jr.Binary.uint8ArrayToHex(t.address);let o,i;try{o=await e.chunk.download(r,void 0,n)}catch(n){throw console.error(`[DownloadData] chunk fetch failed addr=${r} encrypted=${void 0!==t.encryptionKey} bee.url=${e.url}:`,n),n}i=t.encryptionKey?lw(t.encryptionKey,o):o;return{span:yw(i.slice(0,8)),payload:i.slice(8)}}async function _w(e,t,n,r,o,i){const{span:s,payload:a}=await Ew(e,t,i);if(o(),s<=Qy)return a.slice(0,s);const c=vw(a,s,n);if(0===c.length)throw new Error("No valid references found in intermediate chunk");const u=new Array(c.length);for(let t=0;t<c.length;t+=r){const s=c.slice(t,Math.min(t+r,c.length)),a=await Promise.all(s.map(t=>_w(e,t,n,r,o,i)));for(let e=0;e<a.length;e++)u[t+e]=a[e]}const l=u.reduce((e,t)=>e+t.length,0),f=new Uint8Array(l);let d=0;for(const e of u)f.set(e,d),d+=e.length;return f}async function xw(e,t,n,r,o){const i=function(e){const t=Gy(e);if(t.length===tw)return{address:t};if(64===t.length)return{address:t.slice(0,tw),encryptionKey:t.slice(tw)};throw new Error(`Invalid reference length: ${t.length}, expected 32 or 64`)}(t),s=void 0!==i.encryptionKey;console.log(`[DownloadData] start addr=${Jr.Binary.uint8ArrayToHex(i.address)} encrypted=${s} bee.url=${e.url}`);const{span:a,payload:c}=await Ew(e,i,o);if(a<=Qy)return c.slice(0,a);const u=()=>{},l=vw(c,a,s);if(0===l.length)throw new Error("No valid references found in root chunk");const f=new Array(l.length);for(let t=0;t<l.length;t+=64){const n=l.slice(t,Math.min(t+64,l.length)),r=await Promise.all(n.map(t=>_w(e,t,s,64,u,o)));for(let e=0;e<r.length;e++)f[t+e]=r[e]}const d=f.reduce((e,t)=>e+t.length,0),h=new Uint8Array(d);let p=0;for(const e of f)h.set(e,p),p+=e.length;return h}async function kw(e,t,n,r){const o=new Ns(t),i=ww(new Fs(n),o);return bw(await e.chunk.download(i.toHex(),void 0,r),i,o)}async function Aw(e,t,n,r,o){const i=new Ns(t),s=ww(new Fs(n),i),a="string"==typeof r?Gy(r):r;return bw(await e.chunk.download(s.toHex(),void 0,o),s,i,a)}async function Iw(e,t){const n=await async function e(n,r){for(const t of n.forks.values())await e(t.node,!1);const o=await n.marshal(),i=await t(o,r);return n.selfAddress=Gy(i.reference),i}(e,!0);return{rootReference:n.reference,tagUid:n.tagUid}}async function $w(e,t,n){const r=!0===n?.encrypt;const o=await async function e(n,o){for(const t of n.forks.values())await e(t.node,!1);const i=await n.marshal();if(r){const e=gw(i),r=await t(e.data,o),s=new Uint8Array(64);return s.set(e.address.toUint8Array(),0),s.set(e.encryptionKey,32),n.selfAddress=s,r}{const e=pw(i),r=await t(e.data,o);return n.selfAddress=e.address.toUint8Array(),r}}(e,!0);return{rootReference:Hy(e.selfAddress),tagUid:o.tagUid}}const Bw=["invalid version hash","data too short"];async function zw(e,t,n){const r=function(e,t){try{return _a.unmarshalFromData(e,Gy(t))}catch(e){if(e instanceof Error&&Bw.some(t=>e.message.endsWith(t)))throw new Error("No manifest at this reference; a reference from uploadData needs downloadData.",{cause:e});throw e}}(await xw(e,t,0,0,n),t);return await async function t(r){for(const o of r.forks.values()){if(!o.node.selfAddress)throw new Error("Fork node selfAddress is not set");const i=Hy(o.node.selfAddress),s=await xw(e,i,0,0,n),a=_a.unmarshalFromData(s,o.node.selfAddress);o.node.targetAddress=a.targetAddress,o.node.forks=a.forks,o.node.obfuscationKey=a.obfuscationKey,o.node.path=o.prefix,o.node.parent=r;for(const e of o.node.forks.values())e.node.parent=o.node;await t(o.node)}}(r),r}const Sw=5,Ow=86400n/BigInt(5),Tw=86400,Nw=30n*BigInt(Tw);async function Rw(){const e=await fetch("https://api.swarmscan.io/v1/postage-stamps/stats");if(!e.ok)throw new Error(`Failed to fetch Swarmscan stats: ${e.status}`);return(await e.json()).pricePerGBPerMonth}function Uw(e,t){if(!Number.isFinite(t)||t<=0)return 0;const n=BigInt(e);if(n<=0n)return 0;const r=function(e){const t=e.toFixed(16),n=t.startsWith("-"),r=n?t.slice(1):t,[o,i=""]=r.split("."),s=i.padEnd(16,"0").slice(0,16),a=BigInt(o+s);return n?-a:a}(t)/262144n;return r<=0n?0:Number(n*Nw/r)}function Pw(e){if(void 0===e||e<=0)return"N/A";return`${Math.floor(e/Tw)}d ${Math.floor(e%Tw/3600)}h`}function Fw(e,t){return e<=0n||!Number.isInteger(t)||t<=0?0n:e*Ow*BigInt(t)}async function Cw(e,t){try{const n=e.replace(/\/$/,""),r=await fetch(`${n}/stamps/${t}`);if(!r.ok)return;const o=await r.json();if("object"!=typeof o||null===o)return;const{batchTTL:i,usable:s,exists:a}=o;return{batchTTL:"number"==typeof i?i<0?0:i:void 0,usable:"boolean"==typeof s?s:void 0,exists:"boolean"==typeof a?a:void 0}}catch{return}}async function Lw(e,t){const n=await Cw(e,t);return n?.batchTTL}const Mw=1e4;function Dw(e){try{return new URL(e).origin}catch{return"The RPC endpoint"}}function Zw(e){return"object"==typeof e&&null!==e}function jw(e,t,n){if(e.error)throw new Error(`${n} refused ${t}: ${e.error.message??"unknown error"}`);if(!("result"in e))throw new Error(`${n} returned a malformed envelope for ${t}.`);return e.result??void 0}function qw(e,t,n){if(void 0===e)throw new Error(`${n} returned no result for ${t}.`);return e}async function Gw(e,t,n,r){const o=r.label??Dw(e),i=new AbortController,s=setTimeout(()=>i.abort(),r.timeoutMs),a=e=>i.signal.aborted?new Ky(`${o} did not answer ${n} within ${r.timeoutMs}ms.`):new Error(e);try{let r;try{r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:i.signal})}catch(e){throw a(`${o} could not be reached for ${n}: ${c=e,c instanceof Error?c.message:String(c)}`)}!function(e,t,n){if(!e.ok)throw new Error(`${n} answered ${e.status} to ${t}.`)}(r,n,o);try{return await r.json()}catch{throw a(`${o} answered ${n} with a body that is not JSON.`)}}finally{clearTimeout(s)}var c}async function Hw(e,t,n,r){const o=r.label??Dw(e);return qw(jw(await Gw(e,{jsonrpc:"2.0",id:1,method:t,params:n},t,r),t,o),t,o)}async function Vw(e,t,n){if(0===t.length)return[];const r=n.label??Dw(e),o=`a batch of ${t.length} calls`,i=t.map((e,t)=>({jsonrpc:"2.0",id:t,method:e.method,params:e.params})),s=()=>new Error(`${r} returned a malformed response to ${o}.`),a=await Gw(e,i,o,n);if(!Array.isArray(a))throw Zw(a)&&a.error&&jw(a,o,r),s();if(a.length!==t.length)throw s();const c=new Array(t.length),u=new Set;for(const e of a){if(!Zw(e))throw s();const{id:n}=e;if("number"!=typeof n||n<0||n>=t.length)throw new Error(`${r} returned a response with an unknown id.`);if(u.has(n))throw new Error(`${r} returned two responses for id ${n}.`);u.add(n);const o=t[n].method;c[n]=qw(jw(e,o,r),o,r)}return c}function Kw(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Ww(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Jw(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Xw(e,t){Ww(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Yw="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,Qw=e=>e instanceof Uint8Array,eb=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),tb=(e,t)=>e<<32-t|e>>>t;
13
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");function nb(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!Qw(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class rb{clone(){return this._cloneInto()}}function ob(e){const t=t=>e().update(nb(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function ib(e=32){if(Yw&&"function"==typeof Yw.getRandomValues)return Yw.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}class sb extends rb{constructor(e,t,n,r){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=eb(this.buffer)}update(e){Jw(this);const{view:t,buffer:n,blockLen:r}=this,o=(e=nb(e)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const t=eb(e);for(;r<=o-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Jw(this),Xw(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;t[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=eb(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:i,pos:s}=this;return e.length=r,e.pos=s,e.finished=o,e.destroyed=i,r%t&&e.buffer.set(n),e}}const ab=(e,t,n)=>e&t^~e&n,cb=(e,t,n)=>e&t^e&n^t&n,ub=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),lb=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),fb=new Uint32Array(64);class db extends sb{constructor(){super(64,32,8,!1),this.A=0|lb[0],this.B=0|lb[1],this.C=0|lb[2],this.D=0|lb[3],this.E=0|lb[4],this.F=0|lb[5],this.G=0|lb[6],this.H=0|lb[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:i,G:s,H:a}=this;return[e,t,n,r,o,i,s,a]}set(e,t,n,r,o,i,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)fb[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=fb[e-15],n=fb[e-2],r=tb(t,7)^tb(t,18)^t>>>3,o=tb(n,17)^tb(n,19)^n>>>10;fb[e]=o+fb[e-7]+r+fb[e-16]|0}let{A:n,B:r,C:o,D:i,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(tb(s,6)^tb(s,11)^tb(s,25))+ab(s,a,c)+ub[e]+fb[e]|0,l=(tb(n,2)^tb(n,13)^tb(n,22))+cb(n,r,o)|0;u=c,c=a,a=s,s=i+t|0,i=o,o=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,o,i,s,a,c,u)}roundClean(){fb.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const hb=ob(()=>new db),pb=BigInt(0),mb=BigInt(1),gb=BigInt(2),yb=e=>e instanceof Uint8Array,wb=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));
14
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function bb(e){if(!yb(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=wb[e[n]];return t}function vb(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function Eb(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return BigInt(""===e?"0":`0x${e}`)}function _b(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let t=0;t<n.length;t++){const r=2*t,o=e.slice(r,r+2),i=Number.parseInt(o,16);if(Number.isNaN(i)||i<0)throw new Error("Invalid byte sequence");n[t]=i}return n}function xb(e){return Eb(bb(e))}function kb(e){if(!yb(e))throw new Error("Uint8Array expected");return Eb(bb(Uint8Array.from(e).reverse()))}function Ab(e,t){return _b(e.toString(16).padStart(2*t,"0"))}function Ib(e,t){return Ab(e,t).reverse()}function $b(e,t,n){let r;if("string"==typeof t)try{r=_b(t)}catch(n){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${n}`)}else{if(!yb(t))throw new Error(`${e} must be hex string or Uint8Array`);r=Uint8Array.from(t)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(`${e} expected ${n} bytes, got ${o}`);return r}function Bb(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!yb(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}const zb=e=>(gb<<BigInt(e-1))-mb,Sb=e=>new Uint8Array(e),Ob=e=>Uint8Array.from(e);function Tb(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");let r=Sb(e),o=Sb(e),i=0;const s=()=>{r.fill(1),o.fill(0),i=0},a=(...e)=>n(o,r,...e),c=(e=Sb())=>{o=a(Ob([0]),e),r=a(),0!==e.length&&(o=a(Ob([1]),e),r=a())},u=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){r=a();const t=r.slice();n.push(t),e+=r.length}return Bb(...n)};return(e,t)=>{let n;for(s(),c(e);!(n=t(u()));)c();return s(),n}}const Nb={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function Rb(e,t,n={}){const r=(t,n,r)=>{const o=Nb[n];if("function"!=typeof o)throw new Error(`Invalid validator "${n}", expected function`);const i=e[t];if(!(r&&void 0===i||o(i,e)))throw new Error(`Invalid param ${String(t)}=${i} (${typeof i}), expected ${n}`)};for(const[e,n]of Object.entries(t))r(e,n,!1);for(const[e,t]of Object.entries(n))r(e,t,!0);return e}var Ub=Object.freeze({__proto__:null,bitGet:function(e,t){return e>>BigInt(t)&mb},bitLen:function(e){let t;for(t=0;e>pb;e>>=mb,t+=1);return t},bitMask:zb,bitSet:(e,t,n)=>e|(n?mb:pb)<<BigInt(t),bytesToHex:bb,bytesToNumberBE:xb,bytesToNumberLE:kb,concatBytes:Bb,createHmacDrbg:Tb,ensureBytes:$b,equalBytes:function(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},hexToBytes:_b,hexToNumber:Eb,numberToBytesBE:Ab,numberToBytesLE:Ib,numberToHexUnpadded:vb,numberToVarBytesBE:function(e){return _b(vb(e))},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))},validateObject:Rb});
15
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pb=BigInt(0),Fb=BigInt(1),Cb=BigInt(2),Lb=BigInt(3),Mb=BigInt(4),Db=BigInt(5),Zb=BigInt(8);function jb(e,t){const n=e%t;return n>=Pb?n:t+n}function qb(e,t,n){if(n<=Pb||t<Pb)throw new Error("Expected power/modulo > 0");if(n===Fb)return Pb;let r=Fb;for(;t>Pb;)t&Fb&&(r=r*e%n),e=e*e%n,t>>=Fb;return r}function Gb(e,t,n){let r=e;for(;t-- >Pb;)r*=r,r%=n;return r}function Hb(e,t){if(e===Pb||t<=Pb)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=jb(e,t),r=t,o=Pb,i=Fb;for(;n!==Pb;){const e=r%n,t=o-i*(r/n);r=n,n=e,o=i,i=t}if(r!==Fb)throw new Error("invert: does not exist");return jb(o,t)}function Vb(e){if(e%Mb===Lb){const t=(e+Fb)/Mb;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}if(e%Zb===Db){const t=(e-Db)/Zb;return function(e,n){const r=e.mul(n,Cb),o=e.pow(r,t),i=e.mul(n,o),s=e.mul(e.mul(i,Cb),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),n))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-Fb)/Cb;let n,r,o;for(n=e-Fb,r=0;n%Cb===Pb;n/=Cb,r++);for(o=Cb;o<e&&qb(o,t,e)!==e-Fb;o++);if(1===r){const t=(e+Fb)/Mb;return function(e,n){const r=e.pow(n,t);if(!e.eql(e.sqr(r),n))throw new Error("Cannot find square root");return r}}const i=(n+Fb)/Cb;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=r,c=e.pow(e.mul(e.ONE,o),n),u=e.pow(s,i),l=e.pow(s,n);for(;!e.eql(l,e.ONE);){if(e.eql(l,e.ZERO))return e.ZERO;let t=1;for(let n=e.sqr(l);t<a&&!e.eql(n,e.ONE);t++)n=e.sqr(n);const n=e.pow(c,Fb<<BigInt(a-t-1));c=e.sqr(n),u=e.mul(u,n),l=e.mul(l,c),a=t}return u}}(e)}BigInt(9),BigInt(16);const Kb=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wb(e,t){const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function Jb(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Xb(e){const t=Jb(e);return t+Math.ceil(t/2)}
16
16
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
17
- const jb=BigInt(0),qb=BigInt(1);function Gb(e){return function(e){Ab(e,Lb.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"}))}(e.Fp),Ab(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Mb(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}
18
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:Hb,hexToBytes:Vb}=Ib,Kb={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=Kb;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Hb(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Kb,n="string"==typeof e?Vb(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:o,l:i}=Kb._parseInt(n.subarray(2)),{d:s,l:a}=Kb._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s:s}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),o=t(n(e.r)),i=r.length/2,s=o.length/2,a=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${a}${r}`}},Wb=BigInt(0),Jb=BigInt(1);BigInt(2);const Xb=BigInt(3);function Yb(e){const t=function(e){const t=Gb(e);Ab(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=t;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const o=t.toAffine();return bb(Uint8Array.from([4]),n.toBytes(o.x),n.toBytes(o.y))}),o=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function i(e){const{a:r,b:o}=t,i=n.sqr(e),s=n.mul(i,e);return n.add(n.add(s,n.mul(e,r)),o)}if(!n.eql(n.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(e){return"bigint"==typeof e&&Wb<e&&e<t.n}function a(e){if(!s(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:o,n:i}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=lb(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let s;try{s="bigint"==typeof e?e:pb(wb("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return o&&(s=Rb(s,i)),a(s),s}const u=new Map;function l(e){if(!(e instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof f)throw new Error("projective point not allowed");const o=e=>n.eql(e,n.ZERO);return o(t)&&o(r)?f.ZERO:new f(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)}static fromHex(e){const t=f.fromAffine(o(wb("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return f.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const o=n.sqr(r),s=i(e);if(!n.eql(o,s))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){l(e);const{px:t,py:r,pz:o}=this,{px:i,py:s,pz:a}=e,c=n.eql(n.mul(t,a),n.mul(i,o)),u=n.eql(n.mul(r,a),n.mul(s,o));return c&&u}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,o=n.mul(r,Xb),{px:i,py:s,pz:a}=this;let c=n.ZERO,u=n.ZERO,l=n.ZERO,d=n.mul(i,i),h=n.mul(s,s),p=n.mul(a,a),m=n.mul(i,s);return m=n.add(m,m),l=n.mul(i,a),l=n.add(l,l),c=n.mul(e,l),u=n.mul(o,p),u=n.add(c,u),c=n.sub(h,u),u=n.add(h,u),u=n.mul(c,u),c=n.mul(m,c),l=n.mul(o,l),p=n.mul(e,p),m=n.sub(d,p),m=n.mul(e,m),m=n.add(m,l),l=n.add(d,d),d=n.add(l,d),d=n.add(d,p),d=n.mul(d,m),u=n.add(u,d),p=n.mul(s,a),p=n.add(p,p),d=n.mul(p,m),c=n.sub(c,d),l=n.mul(p,h),l=n.add(l,l),l=n.add(l,l),new f(c,u,l)}add(e){l(e);const{px:r,py:o,pz:i}=this,{px:s,py:a,pz:c}=e;let u=n.ZERO,d=n.ZERO,h=n.ZERO;const p=t.a,m=n.mul(t.b,Xb);let g=n.mul(r,s),y=n.mul(o,a),w=n.mul(i,c),b=n.add(r,o),v=n.add(s,a);b=n.mul(b,v),v=n.add(g,y),b=n.sub(b,v),v=n.add(r,i);let E=n.add(s,c);return v=n.mul(v,E),E=n.add(g,w),v=n.sub(v,E),E=n.add(o,i),u=n.add(a,c),E=n.mul(E,u),u=n.add(y,w),E=n.sub(E,u),h=n.mul(p,v),u=n.mul(m,w),h=n.add(u,h),u=n.sub(y,h),h=n.add(y,h),d=n.mul(u,h),y=n.add(g,g),y=n.add(y,g),w=n.mul(p,w),v=n.mul(m,v),y=n.add(y,w),w=n.sub(g,w),w=n.mul(p,w),v=n.add(v,w),g=n.mul(y,v),d=n.add(d,g),g=n.mul(E,v),u=n.mul(b,u),u=n.sub(u,g),g=n.mul(b,y),h=n.mul(E,h),h=n.add(h,g),new f(u,d,h)}subtract(e){return this.add(e.negate())}is0(){return this.equals(f.ZERO)}wNAF(e){return h.wNAFCached(this,u,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)})}multiplyUnsafe(e){const r=f.ZERO;if(e===Wb)return r;if(a(e),e===Jb)return this;const{endo:o}=t;if(!o)return h.unsafeLadder(this,e);let{k1neg:i,k1:s,k2neg:c,k2:u}=o.splitScalar(e),l=r,d=r,p=this;for(;s>Wb||u>Wb;)s&Jb&&(l=l.add(p)),u&Jb&&(d=d.add(p)),p=p.double(),s>>=Jb,u>>=Jb;return i&&(l=l.negate()),c&&(d=d.negate()),d=new f(n.mul(d.px,o.beta),d.py,d.pz),l.add(d)}multiply(e){a(e);let r,o,i=e;const{endo:s}=t;if(s){const{k1neg:e,k1:t,k2neg:a,k2:c}=s.splitScalar(i);let{p:u,f:l}=this.wNAF(t),{p:d,f:p}=this.wNAF(c);u=h.constTimeNegate(e,u),d=h.constTimeNegate(a,d),d=new f(n.mul(d.px,s.beta),d.py,d.pz),r=u.add(d),o=l.add(p)}else{const{p:e,f:t}=this.wNAF(i);r=e,o=t}return f.normalizeZ([r,o])[0]}multiplyAndAddUnsafe(e,t,n){const r=f.BASE,o=(e,t)=>t!==Wb&&t!==Jb&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),i=o(this,t).add(o(e,n));return i.is0()?void 0:i}toAffine(e){const{px:t,py:r,pz:o}=this,i=this.is0();null==e&&(e=i?n.ONE:n.inv(o));const s=n.mul(t,e),a=n.mul(r,e),c=n.mul(o,e);if(i)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===Jb)return!0;if(n)return n(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===Jb?this:n?n(f,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(f,this,e)}toHex(e=!0){return lb(this.toRawBytes(e))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,h=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,o=t;for(;n>jb;)n&qb&&(r=r.add(o)),o=o.double(),n>>=qb;return r},precomputeWindow(e,t){const{windows:n,windowSize:o}=r(t),i=[];let s=e,a=s;for(let e=0;e<n;e++){a=s,i.push(a);for(let e=1;e<o;e++)a=a.add(s),i.push(a);s=a.double()}return i},wNAF(t,o,i){const{windows:s,windowSize:a}=r(t);let c=e.ZERO,u=e.BASE;const l=BigInt(2**t-1),f=2**t,d=BigInt(t);for(let e=0;e<s;e++){const t=e*a;let r=Number(i&l);i>>=d,r>a&&(r-=f,i+=qb);const s=t,h=t+Math.abs(r)-1,p=e%2!=0,m=r<0;0===r?u=u.add(n(p,o[s])):c=c.add(n(m,o[h]))}return{p:c,f:u}},wNAFCached(e,t,n,r){const o=e._WINDOW_SIZE||1;let i=t.get(e);return i||(i=this.precomputeWindow(e,o),1!==o&&t.set(e,r(i))),this.wNAF(o,i,n)}}}(f,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function Qb(e){const t=function(e){const t=Gb(e);return Ab(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,o=n.BYTES+1,i=2*n.BYTES+1;function s(e){return Rb(e,r)}function a(e){return Fb(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Yb({...t,toBytes(e,t,r){const o=t.toAffine(),i=n.toBytes(o.x),s=bb;return r?s(Uint8Array.from([t.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,n.toBytes(o.y))},fromBytes(e){const t=e.length,r=e[0],s=e.subarray(1);if(t!==o||2!==r&&3!==r){if(t===i&&4===r){return{x:n.fromBytes(s.subarray(0,n.BYTES)),y:n.fromBytes(s.subarray(n.BYTES,2*n.BYTES))}}throw new Error(`Point of length ${t} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}{const e=pb(s);if(!(Wb<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=l(e);let o=n.sqrt(t);return!(1&~r)!==((o&Jb)===Jb)&&(o=n.neg(o)),{x:e,y:o}}var a}}),d=e=>lb(gb(e,t.nByteLength));function h(e){return e>r>>Jb}const p=(e,t,n)=>pb(e.slice(t,n));class m{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=wb("compactSignature",e,2*n),new m(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=Kb.toSig(wb("DER",e));return new m(t,n)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new m(this.r,this.s,e)}recoverPublicKey(e){const{r:r,s:o,recovery:i}=this,u=b(wb("msgHash",e));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const l=2===i||3===i?r+t.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=1&i?"03":"02",h=c.fromHex(f+d(l)),p=a(l),m=s(-u*p),g=s(o*p),y=c.BASE.multiplyAndAddUnsafe(h,m,g);if(!y)throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return hb(this.toDERHex())}toDERHex(){return Kb.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return hb(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const g={isValidPrivateKey(e){try{return u(e),!0}catch(e){return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const e=Zb(t.n);return function(e,t,n=!1){const r=e.length,o=Db(t),i=Zb(t);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=Rb(n?pb(e):mb(e),t-Bb)+Bb;return n?yb(s,o):gb(s,o)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function y(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===o||r===i:n?r===2*o||r===2*i:e instanceof c}const w=t.bits2int||function(e){const n=pb(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},b=t.bits2int_modN||function(e){return s(w(e))},v=vb(t.nBitLength);function E(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(Wb<=e&&e<v))throw new Error(`bigint expected < 2^${t.nBitLength}`);return gb(e,t.nByteLength)}function _(e,r,o=x){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:l}=t;let{lowS:d,prehash:p,extraEntropy:g}=o;null==d&&(d=!0),e=wb("msgHash",e),p&&(e=wb("prehashed msgHash",i(e)));const y=b(e),v=u(r),_=[E(v),E(y)];if(null!=g){const e=!0===g?l(n.BYTES):g;_.push(wb("extraEntropy",e))}const k=bb(..._),A=y;return{seed:k,k2sig:function(e){const t=w(e);if(!f(t))return;const n=a(t),r=c.BASE.multiply(t).toAffine(),o=s(r.x);if(o===Wb)return;const i=s(n*s(A+o*v));if(i===Wb)return;let u=(r.x===o?0:2)|Number(r.y&Jb),l=i;return d&&h(i)&&(l=function(e){return h(e)?s(-e):e}(i),u^=1),new m(o,l,u)}}}const x={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(y(e))throw new Error("first arg must be private key");if(!y(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(u(e)).toRawBytes(n)},sign:function(e,n,r=x){const{seed:o,k2sig:i}=_(e,n,r),s=t;return xb(s.hash.outputLen,s.nByteLength,s.hmac)(o,i)},verify:function(e,n,r,o=k){const i=e;if(n=wb("msgHash",n),r=wb("publicKey",r),"strict"in o)throw new Error("options.strict was renamed to lowS");const{lowS:u,prehash:l}=o;let f,d;try{if("string"==typeof i||i instanceof Uint8Array)try{f=m.fromDER(i)}catch(e){if(!(e instanceof Kb.Err))throw e;f=m.fromCompact(i)}else{if("object"!=typeof i||"bigint"!=typeof i.r||"bigint"!=typeof i.s)throw new Error("PARSE");{const{r:e,s:t}=i;f=new m(e,t)}}d=c.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(u&&f.hasHighS())return!1;l&&(n=t.hash(n));const{r:h,s:p}=f,g=b(n),y=a(p),w=s(g*y),v=s(h*y),E=c.BASE.multiplyAndAddUnsafe(d,w,v)?.toAffine();return!!E&&s(E.x)===h},ProjectivePoint:c,Signature:m,utils:g}}BigInt(4);class ev extends Kw{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Lw(e.outputLen),Lw(e.blockLen)}(e);const n=Vw(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return Dw(this),this.iHash.update(e),this}digestInto(e){Dw(this),Mw(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const tv=(e,t,n)=>new ev(e,t).update(n).digest();
17
+ const Yb=BigInt(0),Qb=BigInt(1);function ev(e){return function(e){Rb(e,Kb.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"}))}(e.Fp),Rb(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Wb(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}
18
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const{bytesToNumberBE:tv,hexToBytes:nv}=Ub,rv={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(e){const{Err:t}=rv;if(e.length<2||2!==e[0])throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(128&r[0])throw new t("Invalid signature integer: negative");if(0===r[0]&&!(128&r[1]))throw new t("Invalid signature integer: unnecessary leading zero");return{d:tv(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=rv,n="string"==typeof e?nv(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||48!=n[0])throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:o,l:i}=rv._parseInt(n.subarray(2)),{d:s,l:a}=rv._parseInt(i);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:o,s:s}},hexFromSig(e){const t=e=>8&Number.parseInt(e[0],16)?"00"+e:e,n=e=>{const t=e.toString(16);return 1&t.length?`0${t}`:t},r=t(n(e.s)),o=t(n(e.r)),i=r.length/2,s=o.length/2,a=n(i),c=n(s);return`30${n(s+i+4)}02${c}${o}02${a}${r}`}},ov=BigInt(0),iv=BigInt(1);BigInt(2);const sv=BigInt(3);function av(e){const t=function(e){const t=ev(e);Rb(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:o}=t;if(n){if(!r.eql(o,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof n||"bigint"!=typeof n.beta||"function"!=typeof n.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:n}=t,r=t.toBytes||((e,t,r)=>{const o=t.toAffine();return Bb(Uint8Array.from([4]),n.toBytes(o.x),n.toBytes(o.y))}),o=t.fromBytes||(e=>{const t=e.subarray(1);return{x:n.fromBytes(t.subarray(0,n.BYTES)),y:n.fromBytes(t.subarray(n.BYTES,2*n.BYTES))}});function i(e){const{a:r,b:o}=t,i=n.sqr(e),s=n.mul(i,e);return n.add(n.add(s,n.mul(e,r)),o)}if(!n.eql(n.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function s(e){return"bigint"==typeof e&&ov<e&&e<t.n}function a(e){if(!s(e))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(e){const{allowedPrivateKeyLengths:n,nByteLength:r,wrapPrivateKey:o,n:i}=t;if(n&&"bigint"!=typeof e){if(e instanceof Uint8Array&&(e=bb(e)),"string"!=typeof e||!n.includes(e.length))throw new Error("Invalid key");e=e.padStart(2*r,"0")}let s;try{s="bigint"==typeof e?e:xb($b("private key",e,r))}catch(t){throw new Error(`private key must be ${r} bytes, hex or bigint, not ${typeof e}`)}return o&&(s=jb(s,i)),a(s),s}const u=new Map;function l(e){if(!(e instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(e,t,r){if(this.px=e,this.py=t,this.pz=r,null==e||!n.isValid(e))throw new Error("x required");if(null==t||!n.isValid(t))throw new Error("y required");if(null==r||!n.isValid(r))throw new Error("z required")}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof f)throw new Error("projective point not allowed");const o=e=>n.eql(e,n.ZERO);return o(t)&&o(r)?f.ZERO:new f(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)}static fromHex(e){const t=f.fromAffine(o($b("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return f.BASE.multiply(c(e))}_setWindowSize(e){this._WINDOW_SIZE=e,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:e,y:r}=this.toAffine();if(!n.isValid(e)||!n.isValid(r))throw new Error("bad point: x or y not FE");const o=n.sqr(r),s=i(e);if(!n.eql(o,s))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:e}=this.toAffine();if(n.isOdd)return!n.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){l(e);const{px:t,py:r,pz:o}=this,{px:i,py:s,pz:a}=e,c=n.eql(n.mul(t,a),n.mul(i,o)),u=n.eql(n.mul(r,a),n.mul(s,o));return c&&u}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:e,b:r}=t,o=n.mul(r,sv),{px:i,py:s,pz:a}=this;let c=n.ZERO,u=n.ZERO,l=n.ZERO,d=n.mul(i,i),h=n.mul(s,s),p=n.mul(a,a),m=n.mul(i,s);return m=n.add(m,m),l=n.mul(i,a),l=n.add(l,l),c=n.mul(e,l),u=n.mul(o,p),u=n.add(c,u),c=n.sub(h,u),u=n.add(h,u),u=n.mul(c,u),c=n.mul(m,c),l=n.mul(o,l),p=n.mul(e,p),m=n.sub(d,p),m=n.mul(e,m),m=n.add(m,l),l=n.add(d,d),d=n.add(l,d),d=n.add(d,p),d=n.mul(d,m),u=n.add(u,d),p=n.mul(s,a),p=n.add(p,p),d=n.mul(p,m),c=n.sub(c,d),l=n.mul(p,h),l=n.add(l,l),l=n.add(l,l),new f(c,u,l)}add(e){l(e);const{px:r,py:o,pz:i}=this,{px:s,py:a,pz:c}=e;let u=n.ZERO,d=n.ZERO,h=n.ZERO;const p=t.a,m=n.mul(t.b,sv);let g=n.mul(r,s),y=n.mul(o,a),w=n.mul(i,c),b=n.add(r,o),v=n.add(s,a);b=n.mul(b,v),v=n.add(g,y),b=n.sub(b,v),v=n.add(r,i);let E=n.add(s,c);return v=n.mul(v,E),E=n.add(g,w),v=n.sub(v,E),E=n.add(o,i),u=n.add(a,c),E=n.mul(E,u),u=n.add(y,w),E=n.sub(E,u),h=n.mul(p,v),u=n.mul(m,w),h=n.add(u,h),u=n.sub(y,h),h=n.add(y,h),d=n.mul(u,h),y=n.add(g,g),y=n.add(y,g),w=n.mul(p,w),v=n.mul(m,v),y=n.add(y,w),w=n.sub(g,w),w=n.mul(p,w),v=n.add(v,w),g=n.mul(y,v),d=n.add(d,g),g=n.mul(E,v),u=n.mul(b,u),u=n.sub(u,g),g=n.mul(b,y),h=n.mul(E,h),h=n.add(h,g),new f(u,d,h)}subtract(e){return this.add(e.negate())}is0(){return this.equals(f.ZERO)}wNAF(e){return h.wNAFCached(this,u,e,e=>{const t=n.invertBatch(e.map(e=>e.pz));return e.map((e,n)=>e.toAffine(t[n])).map(f.fromAffine)})}multiplyUnsafe(e){const r=f.ZERO;if(e===ov)return r;if(a(e),e===iv)return this;const{endo:o}=t;if(!o)return h.unsafeLadder(this,e);let{k1neg:i,k1:s,k2neg:c,k2:u}=o.splitScalar(e),l=r,d=r,p=this;for(;s>ov||u>ov;)s&iv&&(l=l.add(p)),u&iv&&(d=d.add(p)),p=p.double(),s>>=iv,u>>=iv;return i&&(l=l.negate()),c&&(d=d.negate()),d=new f(n.mul(d.px,o.beta),d.py,d.pz),l.add(d)}multiply(e){a(e);let r,o,i=e;const{endo:s}=t;if(s){const{k1neg:e,k1:t,k2neg:a,k2:c}=s.splitScalar(i);let{p:u,f:l}=this.wNAF(t),{p:d,f:p}=this.wNAF(c);u=h.constTimeNegate(e,u),d=h.constTimeNegate(a,d),d=new f(n.mul(d.px,s.beta),d.py,d.pz),r=u.add(d),o=l.add(p)}else{const{p:e,f:t}=this.wNAF(i);r=e,o=t}return f.normalizeZ([r,o])[0]}multiplyAndAddUnsafe(e,t,n){const r=f.BASE,o=(e,t)=>t!==ov&&t!==iv&&e.equals(r)?e.multiply(t):e.multiplyUnsafe(t),i=o(this,t).add(o(e,n));return i.is0()?void 0:i}toAffine(e){const{px:t,py:r,pz:o}=this,i=this.is0();null==e&&(e=i?n.ONE:n.inv(o));const s=n.mul(t,e),a=n.mul(r,e),c=n.mul(o,e);if(i)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:e,isTorsionFree:n}=t;if(e===iv)return!0;if(n)return n(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:n}=t;return e===iv?this:n?n(f,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return this.assertValidity(),r(f,this,e)}toHex(e=!0){return bb(this.toRawBytes(e))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,h=function(e,t){const n=(e,t)=>{const n=t.negate();return e?n:t},r=e=>({windows:Math.ceil(t/e)+1,windowSize:2**(e-1)});return{constTimeNegate:n,unsafeLadder(t,n){let r=e.ZERO,o=t;for(;n>Yb;)n&Qb&&(r=r.add(o)),o=o.double(),n>>=Qb;return r},precomputeWindow(e,t){const{windows:n,windowSize:o}=r(t),i=[];let s=e,a=s;for(let e=0;e<n;e++){a=s,i.push(a);for(let e=1;e<o;e++)a=a.add(s),i.push(a);s=a.double()}return i},wNAF(t,o,i){const{windows:s,windowSize:a}=r(t);let c=e.ZERO,u=e.BASE;const l=BigInt(2**t-1),f=2**t,d=BigInt(t);for(let e=0;e<s;e++){const t=e*a;let r=Number(i&l);i>>=d,r>a&&(r-=f,i+=Qb);const s=t,h=t+Math.abs(r)-1,p=e%2!=0,m=r<0;0===r?u=u.add(n(p,o[s])):c=c.add(n(m,o[h]))}return{p:c,f:u}},wNAFCached(e,t,n,r){const o=e._WINDOW_SIZE||1;let i=t.get(e);return i||(i=this.precomputeWindow(e,o),1!==o&&t.set(e,r(i))),this.wNAF(o,i,n)}}}(f,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:i,isWithinCurveOrder:s}}function cv(e){const t=function(e){const t=ev(e);return Rb(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:n,n:r}=t,o=n.BYTES+1,i=2*n.BYTES+1;function s(e){return jb(e,r)}function a(e){return Hb(e,r)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=av({...t,toBytes(e,t,r){const o=t.toAffine(),i=n.toBytes(o.x),s=Bb;return r?s(Uint8Array.from([t.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,n.toBytes(o.y))},fromBytes(e){const t=e.length,r=e[0],s=e.subarray(1);if(t!==o||2!==r&&3!==r){if(t===i&&4===r){return{x:n.fromBytes(s.subarray(0,n.BYTES)),y:n.fromBytes(s.subarray(n.BYTES,2*n.BYTES))}}throw new Error(`Point of length ${t} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}{const e=xb(s);if(!(ov<(a=e)&&a<n.ORDER))throw new Error("Point is not on curve");const t=l(e);let o=n.sqrt(t);return!(1&~r)!==((o&iv)===iv)&&(o=n.neg(o)),{x:e,y:o}}var a}}),d=e=>bb(Ab(e,t.nByteLength));function h(e){return e>r>>iv}const p=(e,t,n)=>xb(e.slice(t,n));class m{constructor(e,t,n){this.r=e,this.s=t,this.recovery=n,this.assertValidity()}static fromCompact(e){const n=t.nByteLength;return e=$b("compactSignature",e,2*n),new m(p(e,0,n),p(e,n,2*n))}static fromDER(e){const{r:t,s:n}=rv.toSig($b("DER",e));return new m(t,n)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(e){return new m(this.r,this.s,e)}recoverPublicKey(e){const{r:r,s:o,recovery:i}=this,u=b($b("msgHash",e));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const l=2===i||3===i?r+t.n:r;if(l>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const f=1&i?"03":"02",h=c.fromHex(f+d(l)),p=a(l),m=s(-u*p),g=s(o*p),y=c.BASE.multiplyAndAddUnsafe(h,m,g);if(!y)throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return _b(this.toDERHex())}toDERHex(){return rv.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return _b(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const g={isValidPrivateKey(e){try{return u(e),!0}catch(e){return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const e=Xb(t.n);return function(e,t,n=!1){const r=e.length,o=Jb(t),i=Xb(t);if(r<16||r<i||r>1024)throw new Error(`expected ${i}-1024 bytes of input, got ${r}`);const s=jb(n?xb(e):kb(e),t-Fb)+Fb;return n?Ib(s,o):Ab(s,o)}(t.randomBytes(e),t.n)},precompute:(e=8,t=c.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function y(e){const t=e instanceof Uint8Array,n="string"==typeof e,r=(t||n)&&e.length;return t?r===o||r===i:n?r===2*o||r===2*i:e instanceof c}const w=t.bits2int||function(e){const n=xb(e),r=8*e.length-t.nBitLength;return r>0?n>>BigInt(r):n},b=t.bits2int_modN||function(e){return s(w(e))},v=zb(t.nBitLength);function E(e){if("bigint"!=typeof e)throw new Error("bigint expected");if(!(ov<=e&&e<v))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Ab(e,t.nByteLength)}function _(e,r,o=x){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:l}=t;let{lowS:d,prehash:p,extraEntropy:g}=o;null==d&&(d=!0),e=$b("msgHash",e),p&&(e=$b("prehashed msgHash",i(e)));const y=b(e),v=u(r),_=[E(v),E(y)];if(null!=g){const e=!0===g?l(n.BYTES):g;_.push($b("extraEntropy",e))}const k=Bb(..._),A=y;return{seed:k,k2sig:function(e){const t=w(e);if(!f(t))return;const n=a(t),r=c.BASE.multiply(t).toAffine(),o=s(r.x);if(o===ov)return;const i=s(n*s(A+o*v));if(i===ov)return;let u=(r.x===o?0:2)|Number(r.y&iv),l=i;return d&&h(i)&&(l=function(e){return h(e)?s(-e):e}(i),u^=1),new m(o,l,u)}}}const x={lowS:t.lowS,prehash:!1},k={lowS:t.lowS,prehash:!1};return c.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return c.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,n=!0){if(y(e))throw new Error("first arg must be private key");if(!y(t))throw new Error("second arg must be public key");return c.fromHex(t).multiply(u(e)).toRawBytes(n)},sign:function(e,n,r=x){const{seed:o,k2sig:i}=_(e,n,r),s=t;return Tb(s.hash.outputLen,s.nByteLength,s.hmac)(o,i)},verify:function(e,n,r,o=k){const i=e;if(n=$b("msgHash",n),r=$b("publicKey",r),"strict"in o)throw new Error("options.strict was renamed to lowS");const{lowS:u,prehash:l}=o;let f,d;try{if("string"==typeof i||i instanceof Uint8Array)try{f=m.fromDER(i)}catch(e){if(!(e instanceof rv.Err))throw e;f=m.fromCompact(i)}else{if("object"!=typeof i||"bigint"!=typeof i.r||"bigint"!=typeof i.s)throw new Error("PARSE");{const{r:e,s:t}=i;f=new m(e,t)}}d=c.fromHex(r)}catch(e){if("PARSE"===e.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(u&&f.hasHighS())return!1;l&&(n=t.hash(n));const{r:h,s:p}=f,g=b(n),y=a(p),w=s(g*y),v=s(h*y),E=c.BASE.multiplyAndAddUnsafe(d,w,v)?.toAffine();return!!E&&s(E.x)===h},ProjectivePoint:c,Signature:m,utils:g}}BigInt(4);class uv extends rb{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");Kw(e.outputLen),Kw(e.blockLen)}(e);const n=nb(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),o.fill(0)}update(e){return Jw(this),this.iHash.update(e),this}digestInto(e){Jw(this),Ww(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=r,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const lv=(e,t,n)=>new uv(e,t).update(n).digest();
19
19
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
20
- function nv(e){return{hash:e,hmac:(t,...n)=>tv(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!qw(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:Jw}}tv.create=(e,t)=>new ev(e,t);
20
+ function fv(e){return{hash:e,hmac:(t,...n)=>lv(e,t,function(...e){const t=new Uint8Array(e.reduce((e,t)=>e+t.length,0));let n=0;return e.forEach(e=>{if(!Qw(e))throw new Error("Uint8Array expected");t.set(e,n),n+=e.length}),t}(...n)),randomBytes:ib}}lv.create=(e,t)=>new uv(e,t);
21
21
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
22
- const rv=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ov=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),iv=BigInt(1),sv=BigInt(2),av=(e,t)=>(e+t/sv)/t;const cv=function(e,t,n=!1,r={}){if(e<=$b)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:o,nByteLength:i}=Mb(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=Cb(e),a=Object.freeze({ORDER:e,BITS:o,BYTES:i,MASK:vb(o),ZERO:$b,ONE:Bb,create:t=>Rb(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return $b<=t&&t<e},is0:e=>e===$b,isOdd:e=>(e&Bb)===Bb,neg:t=>Rb(-t,e),eql:(e,t)=>e===t,sqr:t=>Rb(t*t,e),add:(t,n)=>Rb(t+n,e),sub:(t,n)=>Rb(t-n,e),mul:(t,n)=>Rb(t*n,e),pow:(e,t)=>function(e,t,n){if(n<$b)throw new Error("Expected power > 0");if(n===$b)return e.ONE;if(n===Bb)return t;let r=e.ONE,o=t;for(;n>$b;)n&Bb&&(r=e.mul(r,o)),o=e.sqr(o),n>>=Bb;return r}(a,e,t),div:(t,n)=>Rb(t*Fb(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Fb(t,e),sqrt:r.sqrt||(e=>s(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),o=e.inv(r);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),o),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?yb(e,i):gb(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?mb(e):pb(e)}});return Object.freeze(a)}(rv,void 0,void 0,{sqrt:function(e){const t=rv,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=Pb(l,n,t)*l%t,d=Pb(f,n,t)*l%t,h=Pb(d,sv,t)*u%t,p=Pb(h,o,t)*h%t,m=Pb(p,i,t)*p%t,g=Pb(m,a,t)*m%t,y=Pb(g,c,t)*g%t,w=Pb(y,a,t)*m%t,b=Pb(w,n,t)*l%t,v=Pb(b,s,t)*p%t,E=Pb(v,r,t)*u%t,_=Pb(E,sv,t);if(!cv.eql(cv.sqr(_),e))throw new Error("Cannot find square root");return _}}),uv=function(e,t){const n=t=>Qb({...e,...nv(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:cv,n:ov,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=ov,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-iv*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=av(i*e,t),c=av(-r*e,t);let u=Rb(e-a*n-c*o,t),l=Rb(-a*r-c*i,t);const f=u>s,d=l>s;if(f&&(u=t-u),d&&(l=t-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:d,k2:l}}}},ob);BigInt(0),uv.ProjectivePoint;const lv=BigInt(2**32-1),fv=BigInt(32);function dv(e,t=!1){return t?{h:Number(e&lv),l:Number(e>>fv&lv)}:{h:0|Number(e>>fv&lv),l:0|Number(e&lv)}}function hv(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:i,l:s}=dv(e[o],t);[n[o],r[o]]=[i,s]}return[n,r]}const[pv,mv,gv]=[[],[],[]],yv=BigInt(0),wv=BigInt(1),bv=BigInt(2),vv=BigInt(7),Ev=BigInt(256),_v=BigInt(113);for(let e=0,t=wv,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],pv.push(2*(5*r+n)),mv.push((e+1)*(e+2)/2%64);let o=yv;for(let e=0;e<7;e++)t=(t<<wv^(t>>vv)*_v)%Ev,t&bv&&(o^=wv<<(wv<<BigInt(e))-wv);gv.push(o)}const[xv,kv]=hv(gv,!0),Av=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),Iv=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class $v extends Kw{constructor(e,t,n,r=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Lw(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}keccak(){!function(e,t=24){const n=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){const r=(t+8)%10,o=(t+2)%10,i=n[o],s=n[o+1],a=Av(i,s,1)^n[r],c=Iv(i,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=mv[n],i=Av(t,o,r),s=Iv(t,o,r),a=pv[n];t=e[a],o=e[a+1],e[a]=i,e[a+1]=s}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]^=xv[r],e[1]^=kv[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){Dw(this);const{blockLen:t,state:n}=this,r=(e=Vw(e)).length;for(let o=0;o<r;){const i=Math.min(t-this.pos,r-o);for(let t=0;t<i;t++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Dw(this,!1),Mw(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Lw(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Zw(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:i}=this;return e||(e=new $v(t,n,r,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const Bv=((e,t,n)=>Ww(()=>new $v(t,e,n)))(1,136,32),zv="swarm-encryption",Sv="postage-signer",Ov="backup-key",Tv="act-sharing";async function Nv(e,t){const n=await crypto.subtle.importKey("raw",Py(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),r=await crypto.subtle.sign("HMAC",n,(new TextEncoder).encode(t));return Fy(new Uint8Array(r))}function Rv(e,t){return Fy(tv(ob,Py(e),(new TextEncoder).encode(t)))}async function Uv(e,t){const n=await Nv(e,t);return crypto.subtle.importKey("raw",Py(n),"AES-GCM",!1,["encrypt","decrypt"])}async function Pv(e){return Nv(e,"derivation-key")}async function Fv(e){return Nv(e,zv)}async function Cv(e){return Nv(e,Sv)}function Lv(e){return Rv(e,Sv)}function Mv(e){const t=Py(Rv(e,Tv));return{secret:t,publicKey:new Hs(t).publicKey().toCompressedHex()}}function Dv(e){return function(e,t){for(let n=0;n<16;n++){const r=e(0===n?t:`${t}/${n}`);if(uv.utils.isValidPrivateKey(r))return r}throw new Error(`No valid secp256k1 private key under "${t}" in 16 attempts.`)}(t=>Py(Rv(e,t)),"swarm-id chat key v1")}const Zv="Swarm ID chat binding v1",jv="Site: ",qv="Chat address: ",Gv="Date: ",Hv=/^0x[0-9a-fA-F]{130}$/,Vv=/^0x[0-9a-f]{40}$/,Kv=/^(0x)?[0-9a-fA-F]{40}$/,Wv=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,Jv=/^[a-z0-9-]+(\.[a-z0-9-]+)*$/,Xv=new Set(["localhost","127.0.0.1","[::1]"]);function Yv(e,t={}){let n;try{n=new URL(e)}catch{return!1}const r="https:"===n.protocol,o=!0===t.allowLocalHttp&&"http:"===n.protocol&&Xv.has(n.hostname);return!(!r&&!o)&&(!(!o&&!Jv.test(n.hostname))&&(""!==n.host&&""===n.username&&""===n.password&&n.origin===e))}function Qv(e){return e.toLowerCase().replace(/^0x/,"")}function eE(e,t){if(!Yv(e,t))throw new Error(`Chat binding site is not a clean https origin: ${e}`)}function tE(e,t={}){if(eE(e.site,t),!Kv.test(e.chatAddress))throw new Error("Chat address is not 20 bytes of hex.");if(Number.isNaN(e.date.getTime()))throw new Error("Chat binding date is not a valid date.");return[Zv,`${jv}${e.site}`,`${qv}0x${Qv(e.chatAddress)}`,`${Gv}${e.date.toISOString()}`].join("\n")}function nE(e,t){if(!e.startsWith(t))throw new Error(`Chat binding line does not start with "${t}".`);return e.slice(t.length)}function rE(e,t={}){const n=e.split("\n");if(4!==n.length)throw new Error(`Chat binding has ${n.length} lines, not 4.`);const[r,o,i,s]=n;if(r!==Zv)throw new Error("Not a Swarm ID chat binding v1.");const a=nE(o,jv);eE(a,t);const c=nE(i,qv);if(!Vv.test(c))throw new Error("Chat address is not 0x and 40 lower-case hex characters.");const u=nE(s,Gv);if(!function(e){if(!Wv.test(e))return!1;const t=Date.parse(e);return!Number.isNaN(t)&&new Date(t).toISOString()===e}(u))throw new Error("Chat binding date is not ISO 8601 UTC.");return{site:a,chatAddress:c,date:u}}function oE(e){const t=(new TextEncoder).encode(e),n=(new TextEncoder).encode(`Ethereum Signed Message:\n${t.length}`),r=new Uint8Array(n.length+t.length);return r.set(n),r.set(t,n.length),Bv(r)}function iE(e){return new Hs(Dv(e)).publicKey().address().toHex()}function sE(e,t,n,r={}){eE(t,r);const o=tE({site:t,chatAddress:iE(Rv(e,t)),date:n},r),i=uv.sign(oE(o),Py(e)),s=(i.recovery+27).toString(16);return{message:o,signature:`0x${i.toCompactHex()}${s}`}}function aE(e,t={}){const n=rE(e.message,t);if(!Hv.test(e.signature))throw new Error("Chat binding signature is not 65 bytes of 0x hex.");const r=e.signature.slice(2,130),o=parseInt(e.signature.slice(130),16)-27;if(0!==o&&1!==o)throw new Error("Chat binding signature has a recovery byte other than 27 or 28.");let i;try{const t=uv.Signature.fromCompact(r);if(t.hasHighS())throw new Error("high s");const n=t.addRecoveryBit(o).recoverPublicKey(oE(e.message));s=n.toRawBytes(!1),i=`0x${Fy(Bv(s.slice(1)).slice(-20))}`}catch(e){throw new Error(`Chat binding signature does not recover a signer: ${String(e)}`)}var s;return{signer:i,...n}}function cE(e,t,n={}){if(!e)return;let r;try{r=aE(e,n)}catch{return}return r.site===t.site&&Qv(r.chatAddress)===Qv(t.chatAddress)&&Qv(r.signer)===Qv(t.signer)?e:void 0}function uE(e,t){return e.map(e=>{if(e.appUrl===t||void 0===e.chatBinding)return e;const{chatBinding:n,...r}=e;return r})}const lE={allowLocalHttp:!0};function fE(e){try{return Date.parse(rE(e.message,lE).date)}catch{return Number.NEGATIVE_INFINITY}}function dE(e,t,n){try{const r=aE(e,lE);return r.site===t&&Qv(r.signer)===Qv(n)}catch{return!1}}function hE(e,t,n,r){if(!e||!t)return e??t;const o=dE(e,n,r);return o!==dE(t,n,r)?o?e:t:fE(t)>fE(e)?t:e}export{la as $,zg as A,Ra as B,Zv as C,Em as D,Ns as E,gh as F,Vh as G,Na as H,Ay as I,Ia as J,zs as K,$a as L,_a as M,gm as N,Ua as O,iy as P,fd as Q,Vs as R,e as S,Js as T,Ds as U,xd as V,dh as W,fh as X,Hh as Y,Bs as Z,ua as _,Fs as a,gp as a$,ca as a0,fa as a1,Wh as a2,Jh as a3,Cs as a4,Qh as a5,ep as a6,op as a7,rp as a8,np as a9,Rh as aA,wh as aB,Ep as aC,vp as aD,Ch as aE,cs as aF,Lh as aG,xp as aH,kp as aI,Ip as aJ,$p as aK,Bp as aL,zp as aM,Sp as aN,Op as aO,Cp as aP,Pp as aQ,Fp as aR,Up as aS,Np as aT,Rp as aU,Mh as aV,xh as aW,kh as aX,ad as aY,dp as aZ,hp as a_,tp as aa,Dh as ab,Th as ac,Ks as ad,hh as ae,_h as af,Oh as ag,pa as ah,bh as ai,Uh as aj,wp as ak,cp as al,lp as am,up as an,fp as ao,bp as ap,Lf as aq,qh as ar,Nh as as,Us as at,_s as au,vs as av,da as aw,bs as ax,ph as ay,Gh as az,vm as b,Fv as b$,yp as b0,sm as b1,am as b2,om as b3,rm as b4,im as b5,lm as b6,fm as b7,Zh as b8,hm as b9,Ov as bA,ag as bB,ng as bC,sg as bD,Ym as bE,Wm as bF,Uv as bG,Rv as bH,zv as bI,Sv as bJ,Tv as bK,Gy as bL,jy as bM,qy as bN,Ir as bO,ww as bP,vw as bQ,Zm as bR,hE as bS,gw as bT,eg as bU,Dy as bV,tg as bW,Gr as bX,pw as bY,Mm as bZ,qm as b_,pm as ba,mm as bb,Xs as bc,cm as bd,um as be,yh as bf,Sh as bg,jm as bh,wr as bi,Xm as bj,Sr as bk,gr as bl,Fn as bm,ir as bn,xr as bo,ig as bp,dr as bq,vn as br,aw as bs,iw as bt,ym as bu,rw as bv,Vy as bw,ew as bx,Nv as by,Pa as bz,Hs as c,Ew as c0,Ow as c1,Sw as c2,uv as c3,Jy as c4,_m as c5,cg as c6,iE as c7,uE as c8,hg as c9,$y as ca,Iy as cb,lg as cc,Og as cd,By as ce,Mv as cf,Lv as cg,mw as ch,Dv as ci,fg as cj,dg as ck,zw as cl,Aw as cm,Iw as cn,Bv as co,ug as cp,Am as cq,$m as cr,Vm as cs,Pv as ct,Cv as cu,sE as cv,Cy as cw,Zy as cx,Bw as cy,wm as cz,Ly as d,Ry as e,$w as f,Uy as g,Py as h,bm as i,Fw as j,Cw as k,cE as l,tE as m,Yv as n,sh as o,rE as p,Wd as q,Gs as r,yw as s,lh as t,Fy as u,aE as v,My as w,Jr as x,jh as y,mh as z};
23
- //# sourceMappingURL=chat-binding-DgECjSWW.js.map
22
+ const dv=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),hv=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),pv=BigInt(1),mv=BigInt(2),gv=(e,t)=>(e+t/mv)/t;const yv=function(e,t,n=!1,r={}){if(e<=Pb)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:o,nByteLength:i}=Wb(e,t);if(i>2048)throw new Error("Field lengths over 2048 bytes are not supported");const s=Vb(e),a=Object.freeze({ORDER:e,BITS:o,BYTES:i,MASK:zb(o),ZERO:Pb,ONE:Fb,create:t=>jb(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("Invalid field element: expected bigint, got "+typeof t);return Pb<=t&&t<e},is0:e=>e===Pb,isOdd:e=>(e&Fb)===Fb,neg:t=>jb(-t,e),eql:(e,t)=>e===t,sqr:t=>jb(t*t,e),add:(t,n)=>jb(t+n,e),sub:(t,n)=>jb(t-n,e),mul:(t,n)=>jb(t*n,e),pow:(e,t)=>function(e,t,n){if(n<Pb)throw new Error("Expected power > 0");if(n===Pb)return e.ONE;if(n===Fb)return t;let r=e.ONE,o=t;for(;n>Pb;)n&Fb&&(r=e.mul(r,o)),o=e.sqr(o),n>>=Fb;return r}(a,e,t),div:(t,n)=>jb(t*Hb(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Hb(t,e),sqrt:r.sqrt||(e=>s(a,e)),invertBatch:e=>function(e,t){const n=new Array(t.length),r=t.reduce((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r)),e.ONE),o=e.inv(r);return t.reduceRight((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r)),o),n}(a,e),cmov:(e,t,n)=>n?t:e,toBytes:e=>n?Ib(e,i):Ab(e,i),fromBytes:e=>{if(e.length!==i)throw new Error(`Fp.fromBytes: expected ${i}, got ${e.length}`);return n?kb(e):xb(e)}});return Object.freeze(a)}(dv,void 0,void 0,{sqrt:function(e){const t=dv,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=Gb(l,n,t)*l%t,d=Gb(f,n,t)*l%t,h=Gb(d,mv,t)*u%t,p=Gb(h,o,t)*h%t,m=Gb(p,i,t)*p%t,g=Gb(m,a,t)*m%t,y=Gb(g,c,t)*g%t,w=Gb(y,a,t)*m%t,b=Gb(w,n,t)*l%t,v=Gb(b,s,t)*p%t,E=Gb(v,r,t)*u%t,_=Gb(E,mv,t);if(!yv.eql(yv.sqr(_),e))throw new Error("Cannot find square root");return _}}),wv=function(e,t){const n=t=>cv({...e,...fv(t)});return Object.freeze({...n(t),create:n})}({a:BigInt(0),b:BigInt(7),Fp:yv,n:hv,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=hv,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-pv*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=gv(i*e,t),c=gv(-r*e,t);let u=jb(e-a*n-c*o,t),l=jb(-a*r-c*i,t);const f=u>s,d=l>s;if(f&&(u=t-u),d&&(l=t-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:d,k2:l}}}},hb);BigInt(0),wv.ProjectivePoint;const bv=BigInt(2**32-1),vv=BigInt(32);function Ev(e,t=!1){return t?{h:Number(e&bv),l:Number(e>>vv&bv)}:{h:0|Number(e>>vv&bv),l:0|Number(e&bv)}}function _v(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:i,l:s}=Ev(e[o],t);[n[o],r[o]]=[i,s]}return[n,r]}const[xv,kv,Av]=[[],[],[]],Iv=BigInt(0),$v=BigInt(1),Bv=BigInt(2),zv=BigInt(7),Sv=BigInt(256),Ov=BigInt(113);for(let e=0,t=$v,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],xv.push(2*(5*r+n)),kv.push((e+1)*(e+2)/2%64);let o=Iv;for(let e=0;e<7;e++)t=(t<<$v^(t>>zv)*Ov)%Sv,t&Bv&&(o^=$v<<($v<<BigInt(e))-$v);Av.push(o)}const[Tv,Nv]=_v(Av,!0),Rv=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),Uv=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class Pv extends rb{constructor(e,t,n,r=!1,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=o,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Kw(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}keccak(){!function(e,t=24){const n=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){const r=(t+8)%10,o=(t+2)%10,i=n[o],s=n[o+1],a=Rv(i,s,1)^n[r],c=Uv(i,s,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=kv[n],i=Rv(t,o,r),s=Uv(t,o,r),a=xv[n];t=e[a],o=e[a+1],e[a]=i,e[a+1]=s}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]^=Tv[r],e[1]^=Nv[r]}n.fill(0)}(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){Jw(this);const{blockLen:t,state:n}=this,r=(e=nb(e)).length;for(let o=0;o<r;){const i=Math.min(t-this.pos,r-o);for(let t=0;t<i;t++)n[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){Jw(this,!1),Ww(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Kw(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Xw(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:i}=this;return e||(e=new Pv(t,n,r,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const Fv=((e,t,n)=>ob(()=>new Pv(t,e,n)))(1,136,32),Cv="swarm-encryption",Lv="postage-signer",Mv="backup-key",Dv="act-sharing";async function Zv(e,t){const n=await crypto.subtle.importKey("raw",Gy(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),r=await crypto.subtle.sign("HMAC",n,(new TextEncoder).encode(t));return Hy(new Uint8Array(r))}function jv(e,t){return Hy(lv(hb,Gy(e),(new TextEncoder).encode(t)))}async function qv(e,t){const n=await Zv(e,t);return crypto.subtle.importKey("raw",Gy(n),"AES-GCM",!1,["encrypt","decrypt"])}async function Gv(e){return Zv(e,"derivation-key")}async function Hv(e){return Zv(e,Cv)}async function Vv(e){return Zv(e,Lv)}function Kv(e){return jv(e,Lv)}function Wv(e){const t=Gy(jv(e,Dv));return{secret:t,publicKey:new Hs(t).publicKey().toCompressedHex()}}function Jv(e){return function(e,t){for(let n=0;n<16;n++){const r=e(0===n?t:`${t}/${n}`);if(wv.utils.isValidPrivateKey(r))return r}throw new Error(`No valid secp256k1 private key under "${t}" in 16 attempts.`)}(t=>Gy(jv(e,t)),"swarm-id chat key v1")}const Xv="Swarm ID chat binding v1",Yv="Site: ",Qv="Chat address: ",eE="Date: ",tE=/^0x[0-9a-fA-F]{130}$/,nE=/^0x[0-9a-f]{40}$/,rE=/^(0x)?[0-9a-fA-F]{40}$/,oE=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,iE=/^[a-z0-9-]+(\.[a-z0-9-]+)*$/,sE=new Set(["localhost","127.0.0.1","[::1]"]);function aE(e,t={}){let n;try{n=new URL(e)}catch{return!1}const r="https:"===n.protocol,o=!0===t.allowLocalHttp&&"http:"===n.protocol&&sE.has(n.hostname);return!(!r&&!o)&&(!(!o&&!iE.test(n.hostname))&&(""!==n.host&&""===n.username&&""===n.password&&n.origin===e))}function cE(e){return e.toLowerCase().replace(/^0x/,"")}function uE(e,t){if(!aE(e,t))throw new Error(`Chat binding site is not a clean https origin: ${e}`)}function lE(e,t={}){if(uE(e.site,t),!rE.test(e.chatAddress))throw new Error("Chat address is not 20 bytes of hex.");if(Number.isNaN(e.date.getTime()))throw new Error("Chat binding date is not a valid date.");return[Xv,`${Yv}${e.site}`,`${Qv}0x${cE(e.chatAddress)}`,`${eE}${e.date.toISOString()}`].join("\n")}function fE(e,t){if(!e.startsWith(t))throw new Error(`Chat binding line does not start with "${t}".`);return e.slice(t.length)}function dE(e,t={}){const n=e.split("\n");if(4!==n.length)throw new Error(`Chat binding has ${n.length} lines, not 4.`);const[r,o,i,s]=n;if(r!==Xv)throw new Error("Not a Swarm ID chat binding v1.");const a=fE(o,Yv);uE(a,t);const c=fE(i,Qv);if(!nE.test(c))throw new Error("Chat address is not 0x and 40 lower-case hex characters.");const u=fE(s,eE);if(!function(e){if(!oE.test(e))return!1;const t=Date.parse(e);return!Number.isNaN(t)&&new Date(t).toISOString()===e}(u))throw new Error("Chat binding date is not ISO 8601 UTC.");return{site:a,chatAddress:c,date:u}}function hE(e){const t=(new TextEncoder).encode(e),n=(new TextEncoder).encode(`Ethereum Signed Message:\n${t.length}`),r=new Uint8Array(n.length+t.length);return r.set(n),r.set(t,n.length),Fv(r)}function pE(e){return new Hs(Jv(e)).publicKey().address().toHex()}function mE(e,t,n,r={}){uE(t,r);const o=lE({site:t,chatAddress:pE(jv(e,t)),date:n},r),i=wv.sign(hE(o),Gy(e)),s=(i.recovery+27).toString(16);return{message:o,signature:`0x${i.toCompactHex()}${s}`}}function gE(e,t={}){const n=dE(e.message,t);if(!tE.test(e.signature))throw new Error("Chat binding signature is not 65 bytes of 0x hex.");const r=e.signature.slice(2,130),o=parseInt(e.signature.slice(130),16)-27;if(0!==o&&1!==o)throw new Error("Chat binding signature has a recovery byte other than 27 or 28.");let i;try{const t=wv.Signature.fromCompact(r);if(t.hasHighS())throw new Error("high s");const n=t.addRecoveryBit(o).recoverPublicKey(hE(e.message));s=n.toRawBytes(!1),i=`0x${Hy(Fv(s.slice(1)).slice(-20))}`}catch(e){throw new Error(`Chat binding signature does not recover a signer: ${String(e)}`)}var s;return{signer:i,...n}}function yE(e,t,n={}){if(!e)return;let r;try{r=gE(e,n)}catch{return}return r.site===t.site&&cE(r.chatAddress)===cE(t.chatAddress)&&cE(r.signer)===cE(t.signer)?e:void 0}function wE(e,t){return e.map(e=>{if(e.appUrl===t||void 0===e.chatBinding)return e;const{chatBinding:n,...r}=e;return r})}const bE={allowLocalHttp:!0};function vE(e){try{return Date.parse(dE(e.message,bE).date)}catch{return Number.NEGATIVE_INFINITY}}function EE(e,t,n){try{const r=gE(e,bE);return r.site===t&&cE(r.signer)===cE(n)}catch{return!1}}function _E(e,t,n,r){if(!e||!t)return e??t;const o=EE(e,n,r);return o!==EE(t,n,r)?o?e:t:vE(t)>vE(e)?t:e}export{fh as $,zg as A,Lg as B,Xv as C,Em as D,Ns as E,Jr as F,jh as G,mh as H,Ry as I,Ra as J,gh as K,Vh as L,_a as M,gm as N,Na as O,py as P,Ia as Q,Vs as R,e as S,Js as T,zs as U,$a as V,Ua as W,fd as X,Ds as Y,xd as Z,dh as _,Fs as a,kh as a$,Hh as a0,Bs as a1,ua as a2,la as a3,ca as a4,fa as a5,Wh as a6,Jh as a7,Cs as a8,Qh as a9,da as aA,bs as aB,ph as aC,Gh as aD,Rh as aE,wh as aF,Ep as aG,vp as aH,Ch as aI,cs as aJ,Lh as aK,xp as aL,kp as aM,Ip as aN,$p as aO,Bp as aP,zp as aQ,Sp as aR,Op as aS,Cp as aT,Pp as aU,Fp as aV,Up as aW,Np as aX,Rp as aY,Mh as aZ,xh as a_,ep as aa,op as ab,rp as ac,np as ad,tp as ae,Dh as af,Th as ag,Ks as ah,hh as ai,_h as aj,Oh as ak,pa as al,bh as am,Uh as an,wp as ao,cp as ap,lp as aq,up as ar,fp as as,bp as at,Lf as au,qh as av,Nh as aw,Us as ax,_s as ay,vs as az,vm as b,Gr as b$,ad as b0,dp as b1,hp as b2,gp as b3,yp as b4,sm as b5,am as b6,om as b7,rm as b8,im as b9,nw as bA,uw as bB,Zv as bC,Pa as bD,Mv as bE,ag as bF,ng as bG,sg as bH,Ym as bI,Wm as bJ,qv as bK,jv as bL,Cv as bM,Lv as bN,Dv as bO,ew as bP,Yy as bQ,Qy as bR,Ir as bS,$w as bT,zw as bU,Zm as bV,_E as bW,Aw as bX,eg as bY,Jy as bZ,tg as b_,lm as ba,fm as bb,Zh as bc,hm as bd,pm as be,mm as bf,Xs as bg,cm as bh,um as bi,yh as bj,Sh as bk,jm as bl,wr as bm,Xm as bn,Sr as bo,gr as bp,Fn as bq,ir as br,xr as bs,ig as bt,dr as bu,vn as bv,gw as bw,pw as bx,ym as by,dw as bz,Hs as c,xw as c0,Mm as c1,qm as c2,Hv as c3,Sw as c4,Mw as c5,Lw as c6,wv as c7,iw as c8,_m as c9,Gv as cA,Vv as cB,mE as cC,Vy as cD,Xy as cE,Fw as cF,wm as cG,cg as ca,pE as cb,wE as cc,hg as cd,Py as ce,Uy as cf,lg as cg,Mg as ch,Cg as ci,Fy as cj,Wv as ck,Kv as cl,kw as cm,Jv as cn,fg as co,dg as cp,Cw as cq,Rw as cr,Uw as cs,Ug as ct,Pg as cu,Fv as cv,ug as cw,Am as cx,$m as cy,Vm as cz,Fg as d,Ky as e,Sg as f,qy as g,Ng as h,bm as i,Gy as j,jy as k,Pw as l,Hw as m,Vw as n,yE as o,lE as p,aE as q,dE as r,Iw as s,sh as t,Hy as u,gE as v,Wy as w,Wd as x,Gs as y,lh as z};
23
+ //# sourceMappingURL=chat-binding-BirKsDU3.js.map