@vbyte/btc-dev 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/tx/util.js +0 -2
- package/dist/main.cjs +0 -2
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +0 -2
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/script.js +1 -1
- package/dist/script.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/tx/util.ts +0 -2
package/dist/package.json
CHANGED
package/dist/script.js
CHANGED
|
@@ -9,5 +9,5 @@ const ct=(e,t)=>(e+(e>=0?t:-t)/mt)/t;function at(e){if(!["compact","recovered","
|
|
|
9
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
10
10
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
11
|
const zt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ot={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Pt=BigInt(0),St=BigInt(1),At=BigInt(2);const It=Ve(zt.p,{sqrt:function(e){const t=zt.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),u=BigInt(44),c=BigInt(88),a=e*e*e%t,f=a*a*e%t,d=Be(f,n,t)*f%t,l=Be(d,n,t)*f%t,h=Be(l,At,t)*a%t,p=Be(h,i,t)*h%t,m=Be(p,o,t)*p%t,g=Be(m,u,t)*m%t,_=Be(g,c,t)*g%t,y=Be(_,u,t)*m%t,w=Be(y,n,t)*f%t,v=Be(w,s,t)*p%t,b=Be(v,r,t)*a%t,E=Be(b,At,t);if(!It.eql(It.sqr(E),e))throw new Error("Cannot find square root");return E}}),$t=function(e,t){const n=t=>kt({...e,hash:t});return{...n(t),create:n}}({...zt,Fp:It,lowS:!0,endo:Ot},ne),Tt={};function Bt(e,...t){let n=Tt[e];if(void 0===n){const t=ne(L(e));n=q(t,t),Tt[e]=n}return ne(q(n,...t))}const Nt=e=>e.toBytes(!0).slice(1),Ut=(()=>$t.Point)(),Zt=e=>e%At===Pt;function Rt(e){const{Fn:t,BASE:n}=Ut,r=yt(t,e),i=n.multiply(r);return{scalar:Zt(i.y)?r:t.neg(r),bytes:Nt(i)}}function Ct(e){const t=It;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const n=t.create(e*e),r=t.create(n*e+BigInt(7));let i=t.sqrt(r);Zt(i)||(i=t.neg(i));const o=Ut.fromAffine({x:e,y:i});return o.assertValidity(),o}const jt=de;function Ft(...e){return Ut.Fn.create(jt(Bt("BIP0340/challenge",...e)))}function Dt(e){return Rt(e).bytes}function Ht(e,t,n=W(32)){const{Fn:r}=Ut,i=me("message",e),{bytes:o,scalar:s}=Rt(t),u=me("auxRand",n,32),c=r.toBytes(s^jt(Bt("BIP0340/aux",u))),a=Bt("BIP0340/nonce",c,o,i),{bytes:f,scalar:d}=Rt(a),l=Ft(f,o,i),h=new Uint8Array(64);if(h.set(f,0),h.set(r.toBytes(r.create(d+l*s)),32),!Lt(h,i,o))throw new Error("sign: Invalid signature produced");return h}function Lt(e,t,n){const{Fn:r,BASE:i}=Ut,o=me("signature",e,64),s=me("message",t),u=me("publicKey",n,32);try{const e=Ct(jt(u)),t=jt(o.subarray(0,32));if(!_e(t,St,zt.p))return!1;const n=jt(o.subarray(32,64));if(!_e(n,St,zt.n))return!1;const c=Ft(r.toBytes(t),Nt(e),s),a=i.multiplyUnsafe(n).add(e.multiplyUnsafe(r.neg(c))),{x:f,y:d}=a.toAffine();return!(a.is0()||!Zt(d)||f!==t)}catch(e){return!1}}const Vt=(()=>{const e=(e=W(48))=>Me(e,zt.n);return{keygen:function(t){const n=e(t);return{secretKey:n,publicKey:Dt(n)}},getPublicKey:Dt,sign:Ht,verify:Lt,Point:Ut,utils:{randomSecretKey:e,randomPrivateKey:e,taggedHash:Bt,lift_x:Ct,pointToBytes:Nt,numberToBytesBE:he,bytesToNumberBE:de,mod:Te},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),qt=BigInt(0),Kt=BigInt(2);Ve($t.CURVE.n,32,!0);const Mt=$t.Point.BASE;function Wt(e,t,n,r=!1){const i=Yt(t).big,o=function(e){try{const t=Gt(e,"ecdsa");return $t.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),s=Mt.multiply(i);let u=o.add(s);r&&u.y%Kt!==qt&&(u=u.negate());return Gt(u.toHex(!0),n)}function Gt(e,t){try{const n=Yt(e);if(33===n.length&&"bip340"===t)return n.slice(1);if(32===n.length&&"ecdsa"===t){const e=g.num(2,1);return g.join([e,n])}return n}catch(t){throw new Error("invalid pubkey: "+String(e))}}function Yt(e){try{return g.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const Xt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Jt=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Qt=(()=>Jt.map(e=>(9*e+5)%16))(),en=(()=>{const e=[[Jt],[Qt]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Xt[e]));return e})(),tn=(()=>en[0])(),nn=(()=>en[1])(),rn=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),on=tn.map((e,t)=>e.map(e=>rn[t][e])),sn=nn.map((e,t)=>e.map(e=>rn[t][e])),un=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),cn=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function an(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const fn=new Uint32Array(16);class dn extends X{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(e,t){for(let n=0;n<16;n++,t+=4)fn[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,o=i,s=0|this.h2,u=s,c=0|this.h3,a=c,f=0|this.h4,d=f;for(let e=0;e<5;e++){const t=4-e,l=un[e],h=cn[e],p=tn[e],m=nn[e],g=on[e],_=sn[e];for(let t=0;t<16;t++){const r=$(n+an(e,i,s,c)+fn[p[t]]+l,g[t])+f|0;n=f,f=c,c=0|$(s,10),s=i,i=r}for(let e=0;e<16;e++){const n=$(r+an(t,o,u,a)+fn[m[e]]+h,_[e])+d|0;r=d,d=a,a=0|$(u,10),u=o,o=n}}this.set(this.h1+s+a|0,this.h2+c+d|0,this.h3+f+r|0,this.h4+n+o|0,this.h0+i+u|0)}roundClean(){S(fn)}destroy(){this.destroyed=!0,S(this.buffer),this.set(0,0,0,0,0)}}const ln=M(()=>new dn);function hn(...e){const t=g.join(e),n=ln(ne(t));return new g(n)}function pn(...e){const t=g.join(e),n=ne(t);return new g(n)}function mn(...e){const t=g.join(e),n=ne(ne(t));return new g(n)}function gn(e,...t){const n=function(e){const t=pn(g.str(e));return g.join([t,t])}(e),r=t.map(e=>new g(e));return pn(g.join([n,...r]))}
|
|
12
|
-
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _n(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function yn(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function wn(e){if("function"!=typeof e)throw new Error("function expected");return!0}function vn(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function bn(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function En(e){if(!Array.isArray(e))throw new Error("array expected")}function xn(e,t){if(!yn(!0,t))throw new Error(`${e}: array of strings expected`)}function kn(e,t){if(!yn(!1,t))throw new Error(`${e}: array of numbers expected`)}function zn(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function On(e){const t="string"==typeof e?e.split(""):e,n=t.length;xn("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(En(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(En(t),t.map(t=>{vn("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Pn(e=""){return vn("join",e),{encode:t=>(xn("join.decode",t),t.join(e)),decode:t=>(vn("join.decode",t),t.split(e))}}function Sn(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(En(e),!e.length)return[];let r=0;const i=[],o=Array.from(e,e=>{if(bn(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,u=!0;for(let i=r;i<s;i++){const s=o[i],c=t*e,a=c+s;if(!Number.isSafeInteger(a)||c/t!==e||a-s!==c)throw new Error("convertRadix: carry overflow");const f=a/n;e=a%n;const d=Math.floor(f);if(o[i]=d,!Number.isSafeInteger(d)||d*n+e!==a)throw new Error("convertRadix: carry overflow");u&&(d?u=!1:r=i)}if(i.push(e),u)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}const An=(e,t)=>0===t?e:An(t,e%t),In=(e,t)=>e+(t-An(e,t)),$n=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Tn(e,t,n,r){if(En(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(In(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${In(t,n)}`);let i=0,o=0;const s=$n[t],u=$n[n]-1,c=[];for(const r of e){if(bn(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((i>>o-n&u)>>>0);const e=$n[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-o&u,!r&&o>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&c.push(i>>>0),c}function Bn(e,t=!1){if(bn(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(In(8,e)>32||In(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!_n(n))throw new Error("radix2.encode input should be Uint8Array");return Tn(Array.from(n),8,e,!t)},decode:n=>(kn("radix2.decode",n),Uint8Array.from(Tn(n,e,8,t)))}}function Nn(e){return wn(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const Un=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!_n(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>(e=>{if(vn("base64",e),e.length>0&&!/^[A-Za-z0-9=+/]+$/.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:"base64",lastChunkHandling:"strict"})})(e)}:zn(Bn(6),On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return bn(e),vn("padding",t),{encode(n){for(xn("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){xn("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),Pn("")),Zn=zn(Bn(6),On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Pn("")),Rn=(Cn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",zn(function(e){return bn(e),{encode:t=>{if(!_n(t))throw new Error("radix.encode input should be Uint8Array");return Sn(Array.from(t),256,e)},decode:t=>(kn("radix.decode",t),Uint8Array.from(Sn(t,e,256)))}}(58),On(Cn),Pn("")));var Cn;const jn=e=>{return zn((n=t=>e(e(t)),bn(t=4),wn(n),{encode(e){if(!_n(e))throw new Error("checksum.encode: input should be Uint8Array");const r=n(e).slice(0,t),i=new Uint8Array(e.length+t);return i.set(e),i.set(r,e.length),i},decode(e){if(!_n(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),o=n(r).slice(0,t);for(let e=0;e<t;e++)if(o[e]!==i[e])throw new Error("Invalid checksum");return r}}),Rn);var t,n},Fn=zn(On("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Pn("")),Dn=[996825010,642813549,513874426,1027748829,705979059];function Hn(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Dn.length;e++)1==(t>>e&1)&&(n^=Dn[e]);return n}function Ln(e,t,n=1){const r=e.length;let i=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);i=Hn(i)^n>>5}i=Hn(i);for(let t=0;t<r;t++)i=Hn(i)^31&e.charCodeAt(t);for(let e of t)i=Hn(i)^e;for(let e=0;e<6;e++)i=Hn(i);return i^=n,Fn.encode(Tn([i%$n[30]],30,5,!1))}function Vn(e){const t="bech32"===e?1:734539939,n=Bn(5),r=n.decode,i=n.encode,o=Nn(r);function s(e,n,r=90){vn("bech32.encode prefix",e),_n(n)&&(n=Array.from(n)),kn("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const o=i+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);const s=e.toLowerCase(),u=Ln(s,n,t);return`${s}1${Fn.encode(n)}${u}`}function u(e,n=90){vn("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=i.lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=i.slice(0,o),u=i.slice(o+1);if(u.length<6)throw new Error("Data must be at least 6 characters long");const c=Fn.decode(u).slice(0,-6),a=Ln(s,c,t);if(!u.endsWith(a))throw new Error(`Invalid checksum in ${e}: expected "${a}"`);return{prefix:s,words:c}}return{encode:s,decode:u,encodeFromBytes:function(e,t){return s(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=u(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Nn(u),fromWords:r,fromWordsUnsafe:o,toWords:i}}const qn=Vn("bech32"),Kn=Vn("bech32m");var Mn,Wn,Gn,Yn,Xn;function Jn(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Qn(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new Error(`invalid words: ${String(e)}`)}!function(e){e.encode=e=>(b.is_u8a(e),jn(ne).encode(e)),e.decode=e=>(b.is_base58(e),jn(ne).decode(e))}(Mn||(Mn={})),function(e){e.encode=e=>(b.is_u8a(e),Un.encode(e)),e.decode=e=>(b.is_base64(e),Un.decode(e))}(Wn||(Wn={})),function(e){e.encode=e=>(b.is_u8a(e),Zn.encode(e)),e.decode=e=>(b.is_b64url(e),Zn.decode(e))}(Gn||(Gn={})),function(e){e.to_words=qn.toWords,e.to_bytes=qn.fromWords,e.encode=(e,t,n=!1)=>(Jn(e),Qn(t),qn.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),qn.decode(e,t))}(Yn||(Yn={})),function(e){e.to_words=Kn.toWords,e.to_bytes=Kn.fromWords,e.encode=(e,t,n=!1)=>(Jn(e),Qn(t),Kn.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Kn.decode(e,t))}(Xn||(Xn={}));const er={base58:/^[13mn2][a-km-zA-HJ-NP-Z1-9]{25,34}$/,bech32:/^(bc|tb|bcrt)1q[ac-hj-np-z02-9]{6,87}$/,bech32m:/^(bc|tb|bcrt)1p[ac-hj-np-z02-9]{6,87}$/},tr=0,nr=1;function rr(e){const t=function(e){for(const[t,n]of Object.entries(er))if(n.test(e))return t;return null}(e);if(null===t)throw new Error("unrecognized address format: "+t);if("base58"===t)return function(e){const t=Mn.decode(e),n=t.slice(1),r=t[0];return{data:n,format:"base58",version:r}}(e);if("bech32"===t)return function(e){const{prefix:t,words:n}=Yn.decode(e),[r,...i]=n;b.ok(r===tr,"bech32 version mismatch");return{data:Yn.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Xn.decode(e),[r,...i]=n;b.ok(r===nr,"bech32m version mismatch");return{data:Xn.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function ir(e){if("base58"===e.format)return function(e){b.ok("base58"===e.format,"encoding mismatch"),b.exists(e.version,"must specify a version");const t=g.join([e.version,e.data]);return Mn.encode(t)}(e);if("bech32"===e.format)return function(e){b.ok("bech32"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Yn.to_words(t);return Yn.encode(e.prefix,[tr,...n])}(e);if("bech32m"===e.format)return function(e){b.ok("bech32m"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Xn.to_words(t);return Xn.encode(e.prefix,[nr,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const or={TXID:"00".repeat(32),VOUT:4294967295},sr={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},ur=[192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,102,126,128,132,150,152,186,188,190],cr={P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",OPRETURN:"opreturn"},ar={[cr.P2PKH]:/^76a914[0-9a-f]{40}88ac$/i,[cr.P2SH]:/^a914[0-9a-f]{40}87$/i,[cr.P2WPKH]:/^0014[0-9a-f]{40}$/i,[cr.P2WSH]:/^0020[0-9a-f]{64}$/i,[cr.P2TR]:/^5120[0-9a-f]{64}$/i,[cr.OPRETURN]:/^6a[0-9a-f]{2,}$/i},fr=[1,2,3,129,130,131],dr=[0,...fr];var lr=Object.freeze({__proto__:null,COINBASE:or,DEFAULT:sr,LOCK_SCRIPT_REGEX:ar,LOCK_SCRIPT_TYPE:cr,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:fr,SIGHASH_TAPROOT:dr,SPEND_SCRIPT_TYPE:{P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",P2TS:"p2ts"},TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:ur,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});function hr(e){const t=g.bytes(e).hex;for(const[e,n]of Object.entries(ar))if(n.test(t))return e;return null}function pr(e){switch(g.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function mr(e){const t=g.bytes(e).hex;return ar.p2pkh.test(t)}function gr(e){const t=g.bytes(e).hex;return ar.p2sh.test(t)}function _r(e){const t=g.bytes(e).hex;return ar.p2wpkh.test(t)}function yr(e){const t=g.bytes(e).hex;return ar.p2wsh.test(t)}function wr(e){const t=g.bytes(e).hex;return ar.p2tr.test(t)}function vr(e,t){switch(t){case"p2pkh":return function(e){return{hex:"76a914"+e+"88ac",asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{hex:"a914"+e+"87",asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2wpkh":return function(e){return{hex:"0014"+e,asm:["OP_0",e]}}(e);case"p2wsh":return function(e){return{hex:"0020"+e,asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{hex:"5120"+e,asm:["OP_1",e]}}(e);default:throw new Error("unrecognized script type: "+t)}}const br=[["1","p2pkh","main",20,"base58",0],["3","p2sh","main",20,"base58",5],["m","p2pkh","testnet",20,"base58",111],["n","p2pkh","testnet",20,"base58",111],["2","p2sh","testnet",20,"base58",196],["m","p2pkh","regtest",20,"base58",111],["n","p2pkh","regtest",20,"base58",111],["2","p2sh","regtest",20,"base58",196],["bc","p2wpkh","main",20,"bech32",0],["tb","p2wpkh","testnet",20,"bech32",0],["bcrt","p2wpkh","regtest",20,"bech32",0],["bc","p2wsh","main",32,"bech32",0],["tb","p2wsh","testnet",32,"bech32",0],["bcrt","p2wsh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function Er(e,t){for(const[n,r,i,o,s,u]of br)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:o,format:s,version:u};return null}function xr(e){const t=rr(e);for(const[n,r,i,o,s,u]of br){if(s!==t.format)continue;if(o!==t.data.length)continue;if(u!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const c=g.uint(t.data).hex;return{data:c,script:vr(c,r),type:r,prefix:n,network:i,size:o,format:s,version:u}}throw new Error("address configuration is invalid")}const kr=cr.P2PKH;var zr;function Or(e,t="main"){return Ar(Pr(e),t)}function Pr(e){const t=g.bytes(e);b.size(t,33,"invalid pubkey size");return Sr(hn(t))}function Sr(e){return g.join(["76a914",e,"88ac"])}function Ar(e,t="main"){const n=$r(e),r=Er(t,kr);return b.exists(r,`unrecognized address config: ${kr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"base58",version:r.version})}function Ir(e){const t=xr(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${kr}`),t}function $r(e){const t=g.bytes(e);return b.ok(mr(e),"invalid p2pkh script"),t.slice(3,23)}!function(e){e.create_address=Or,e.create_script=Pr,e.encode_address=Ar,e.encode_script=Sr,e.decode_address=Ir,e.decode_script=$r}(zr||(zr={}));const Tr=cr.P2SH;var Br;function Nr(e,t="main"){return Rr(Zr(hn(g.bytes(e))),t)}function Ur(e){return Zr(hn(g.bytes(e)))}function Zr(e){return g.join(["a914",e,"87"])}function Rr(e,t="main"){const n=jr(e),r=Er(t,Tr);return b.exists(r,`unrecognized address config: ${Tr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"base58",version:r.version})}function Cr(e){const t=xr(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${Tr}`),t}function jr(e){b.ok(gr(e),"invalid p2sh script");return g.bytes(e).slice(2,22)}!function(e){e.create_address=Nr,e.create_script=Ur,e.encode_address=Rr,e.encode_script=Zr,e.decode_address=Cr,e.decode_script=jr}(Br||(Br={}));const Fr=cr.P2WPKH;var Dr;function Hr(e,t="main"){return qr(Lr(e),t)}function Lr(e){const t=g.bytes(e);b.size(t,33,"invalid pubkey size");return Vr(hn(t))}function Vr(e){return g.join(["0014",e])}function qr(e,t="main"){const n=Mr(e),r=Er(t,Fr);return b.exists(r,`unrecognized address config: ${Fr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"bech32",prefix:r.prefix})}function Kr(e){const t=xr(e);return b.ok("p2wpkh"===t.type,`address type mismatch: ${t.type} !== ${Fr}`),t}function Mr(e){b.ok(_r(e),"invalid p2wpkh script");return g.bytes(e).slice(2,22)}!function(e){e.create_address=Hr,e.create_script=Lr,e.encode_address=qr,e.encode_script=Vr,e.decode_address=Kr,e.decode_script=Mr}(Dr||(Dr={}));const Wr=cr.P2WSH;var Gr;function Yr(e,t="main"){return Qr(Xr(e),t)}function Xr(e){return Jr(pn(g.bytes(e)))}function Jr(e){return g.join(["0020",e])}function Qr(e,t="main"){const n=ti(e),r=Er(t,Wr);return b.exists(r,`unrecognized address config: ${Wr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"bech32",prefix:r.prefix})}function ei(e){const t=xr(e);return b.ok("p2wsh"===t.type,`address type mismatch: ${t.type} !== ${Wr}`),t}function ti(e){b.ok(yr(e),"invalid p2wsh script");return g.bytes(e).slice(2,34)}!function(e){e.create_address=Yr,e.create_script=Xr,e.encode_address=Qr,e.encode_script=Jr,e.decode_address=ei,e.decode_script=ti}(Gr||(Gr={}));const ni=cr.P2TR;var ri;function ii(e,t="main"){return ui(oi(e),t)}function oi(e){const t=g.bytes(e);return b.size(t,32,"invalid pubkey size"),si(t)}function si(e){return g.join(["5120",e])}function ui(e,t="main"){const n=ai(e),r=Er(t,ni);return b.exists(r,`unrecognized address config: ${ni} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"bech32m",prefix:r.prefix})}function ci(e){const t=xr(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${ni}`),t}function ai(e){b.ok(wr(e),"invalid p2tr script");return g.bytes(e).slice(2,34)}!function(e){e.create_address=ii,e.create_script=oi,e.encode_address=ui,e.encode_script=si,e.decode_address=ci,e.decode_script=ai}(ri||(ri={}));var fi=Object.freeze({__proto__:null,get P2PKH(){return zr},get P2SH(){return Br},get P2TR(){return ri},get P2WPKH(){return Dr},get P2WSH(){return Gr},get_address:function(e,t="main"){const n=g.bytes(e),r=hr(n);if(null===r)throw new Error("unknown locking script: "+n.hex);switch(r){case cr.P2PKH:return zr.encode_address(e,t);case cr.P2SH:return Br.encode_address(e,t);case cr.P2WPKH:return Dr.encode_address(e,t);case cr.P2WSH:return Gr.encode_address(e,t);case cr.P2TR:return ri.encode_address(e,t);default:throw new Error("unknown script type: "+r)}},parse_address:function(e){return xr(e)}});const di=5e8;var li,hi;function pi(e){switch(e.type){case"timelock":return b.ok(e.stamp>=di,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<di,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function mi(e){return isNaN(e)||e<=0?null:e<di?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function gi(e,t=0){return`${e}i${t}`}function _i(e){wi(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function yi(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function wi(e){if(!yi(e))throw new Error(`invalid inscription id: ${e}`)}function vi(e,t){return`${e}:${t}`}function bi(e){xi(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function Ei(e){return null!==e.match(/^\d+:\d+$/)}function xi(e){if(!Ei(e))throw new Error(`invalid rune id: ${e}`)}function ki(e,t){return`${e}:${t}`}function zi(e){Pi(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function Oi(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function Pi(e){if(!Oi(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=pi,e.decode=mi}(li||(li={})),function(e){e.outpoint={encode:ki,decode:zi,verify:Oi,assert:Pi},e.record_id={encode:gi,decode:_i,verify:yi,assert:wi},e.rune_id={encode:vi,decode:bi,verify:Ei,assert:xi}}(hi||(hi={}));const Si={OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_SUCCESS80:80,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_SUCCESS98:98,OP_IF:99,OP_NOTIF:100,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_SUCCESS126:126,OP_SUCCESS127:127,OP_SUCCESS128:128,OP_SUCCESS129:129,OP_SIZE:130,OP_SUCCESS131:131,OP_SUCCESS132:132,OP_SUCCESS133:133,OP_SUCCESS134:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_SUCCESS137:137,OP_SUCCESS138:138,OP_1ADD:139,OP_1SUB:140,OP_SUCCESS141:141,OP_SUCCESS142:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_SUCCESS149:149,OP_SUCCESS150:150,OP_SUCCESS151:151,OP_SUCCESS152:152,OP_SUCCESS153:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186};function Ai(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Si))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ii(e){for(const[t,n]of Object.entries(Si))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function $i(e){switch(!0){case 0===e:return"opcode";case e>=1&&e<=75:return"varint";case 76===e:return"pushdata1";case 77===e:return"pushdata2";case 78===e:return"pushdata4";case e<=254:return"opcode";default:throw new Error(`Invalid word range: ${e}`)}}function Ti(e){switch(!0){case"number"!=typeof e:return!1;case 0===e:return!0;case[].includes(e):return!1;case 75<e&&e<254:return!0;default:return!1}}const Bi=520;function Ni(e,t=!1){if(0===e.length)return g.num(0,1);const n=[];for(const t of e)n.push(Ui(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")):r}function Ui(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ii(e);return g.num(t,1)}t=g.is_hex(e)?g.hex(e):g.str(e)}else if("number"==typeof e)t=g.num(e);else{if(!(e instanceof Uint8Array))throw new Error("invalid word type:"+typeof e);t=new g(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>Bi){let e;e=Zi(t),e=e.map(e=>Ri(e)),t=g.join(e)}else t=Ri(t);return t}function Zi(e){const t=[],n=new _(e);for(;n.size>Bi;)t.push(n.read(Bi));return t.push(n.read(n.size)),t}function Ri(e){const t=Ci(e.length);return g.join([t,e])}function Ci(e){const t=g.num(76,1),n=g.num(77,1);switch(!0){case e<=75:return g.num(e);case e>75&&e<256:return g.join([t,g.num(e,1,"le")]);case e>=256&&e<=Bi:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function ji(e){const t=g.bytes(e);return{asm:Fi(t),hex:t.hex}}function Fi(e){const t=new _(e),n=[],r=t.size;let i,o,s,u=0;for(;u<r;)switch(i=t.read(1).num,o=$i(i),u++,o){case"varint":n.push(t.read(i).hex),u+=i;break;case"pushdata1":s=t.read(1).reverse().num,n.push(t.read(s).hex),u+=s+1;break;case"pushdata2":s=t.read(2).reverse().num,n.push(t.read(s).hex),u+=s+2;break;case"pushdata4":s=t.read(4).reverse().num,n.push(t.read(s).hex),u+=s+4;break;case"opcode":if(!Ti(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Ai(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Di(e){try{return Fi(e).length>0}catch{return!1}}const Hi=BigInt(0),Li=BigInt(1),Vi=BigInt(26);var qi;function Ki(e){const t=function(e){const t=Fi(e),n=t.findIndex(e=>"OP_0"===e);b.ok(-1!==n,"inscription envelope not found");const r=[];for(let e=n;e<t.length;e++){b.ok("OP_IF"===t[e+1],"OP_IF missing from envelope"),b.ok("6f7264"===t[e+2],"magic bytes missing from envelope");const n=t.findIndex(e=>"OP_ENDIF"===e);b.ok(-1!==n,"inscription envelope missing END_IF statement");const i=t.slice(e+3,n);r.push(i),e+=n}return r}(e);return t.map(Gi)}function Mi(e){return g.join(e.map(Wi))}function Wi(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=Xi(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=Xi(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=Qi(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=Qi(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=Hi;for(const e of t)e>="A"&&e<="Z"&&(n=n*Vi+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=Li,g.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return g.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=g.is_hex(e)?g.hex(e):g.str(e),n=new _(t),r=[];for(;n.size>0;)if(n.size>520){const e=n.read(520);r.push(e.hex)}else{const e=n.read(n.size);r.push(e.hex)}return r}(e.content);t.push("OP_0",...n)}return t.push("OP_ENDIF"),Ni(t)}function Gi(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=to(e[n+1]),n+=1;break;case"OP_2":t.pointer=eo(e[n+1]),n+=1;break;case"OP_3":t.parent=Ji(e[n+1]),n+=1;break;case"OP_11":t.delegate=Ji(e[n+1]),n+=1;break;case"OP_13":t.rune=ro(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=Yi(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=eo(e[n+1]),n+=1;break;case"OP_0":return t.content=no(e.slice(n+1)),t}return t}function Yi(e){return g.bytes(e).hex}function Xi(e){b.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=g.hex(t[0]),r=Number(t[1]),i=n.reverse().hex;return 0!==r?i+g.num(r).hex:i}function Ji(e){const t=g.bytes(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function Qi(e){return g.num(e).reverse().hex}function eo(e){return g.bytes(e).reverse().num}function to(e){return g.bytes(e).str}function no(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function ro(e){let t=g.bytes(e).reverse().big;t+=Li;let n="";for(;t>Hi;){const e=t%Vi;if(e===Hi)n="Z"+n,t=t/Vi-Li;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=Vi}}return n}!function(e){e.encode=Mi,e.decode=Ki}(qi||(qi={}));const io=4194304,oo=65535,so=65535;var uo;function co(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>so)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&oo)>>>0}if("stamp"===e.mode){const t=function(e){if(void 0===e||!Number.isInteger(e))throw new Error("timestamp must be a number");const t=Math.floor(e/512);if(!Number.isInteger(t)||t<0||t>so)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(io|t&oo)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function ao(e){const t=function(e){const t="string"==typeof e?parseInt(e,16):e;if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`invalid sequence value: ${t}`);return t}(e);if(2147483648&t)return null;const n=t&oo;if(t&io){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>so)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=co,e.decode=ao}(uo||(uo={}));var fo,lo=Object.freeze({__proto__:null,get InscriptionUtil(){return qi},get LocktimeField(){return li},get RefPointer(){return hi},get SequenceField(){return uo},decode_inscription:Ki,decode_locktime:mi,decode_sequence:ao,encode_inscription:Mi,encode_locktime:pi,encode_sequence:co});function ho(e){return g.bytes(e).prefix_varint("le").hex}!function(e){e.parse=ji,e.decode=Fi,e.encode=Ni,e.is_valid=Di}(fo||(fo={}));var po=Object.freeze({__proto__:null,OPCODE_MAP:Si,get ScriptUtil(){return fo},decode_script:Fi,encode_script:Ni,encode_script_word:Ui,get_asm_code:Ii,get_lock_script_info:function(e){return{type:hr(e),version:pr(e)}},get_lock_script_type:hr,get_lock_script_version:pr,get_op_code:Ai,get_op_type:$i,get_size_varint:Ci,is_opreturn_script:function(e){const t=g.bytes(e).hex;return ar.opreturn.test(t)},is_p2pkh_script:mr,is_p2sh_script:gr,is_p2tr_script:wr,is_p2wpkh_script:_r,is_p2wsh_script:yr,is_return_script:function(e){return 106===g.bytes(e).at(0)},is_valid_op:Ti,is_valid_script:Di,parse_script:ji,parse_script_pubkeys:function(e){return[...("string"==typeof e?e:g.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])},prefix_script_size:ho,prefix_word_size:Ri,split_script_word:Zi});function mo(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function go(e,t){let{txindex:n,txinput:r}=t??{};if(void 0!==n){if(n>=e.vin.length)throw new Error("Input index out of bounds: "+String(n));r=e.vin.at(n)}return b.ok(void 0!==r),r}function _o(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return pn(g.hex(t).prefix_varint("be"))}}function yo(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new _(e),r=function(e){return e.read(4).reverse().to_num()}(n);let i=function(e){const[t,n]=[...e.peek(2)];if(0===t){if(e.read(2),1===n)return!0;throw new Error(`Invalid witness flag: ${n}`)}return!1}(n);i=!!t&&i;const o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=wo(e);t.push(n)}return t}(n),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(vo(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${w(e)}`)}return t}(n);if(i)for(const e of o)e.witness=bo(n);const u=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:o,vout:s,locktime:u}}function wo(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=Eo(e),i=e.read(4).reverse().num,o=[];return t===or.TXID&&n===or.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:o}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:o}}function vo(e){const t=e.read(8).reverse().big,n=Eo(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function bo(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Eo(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function Eo(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function xo(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(const e in s.prototype)e in n||Object.defineProperty(n,e,{value:s.prototype[e].bind(n)});n._zod.constr=s,n._zod.def=r}const i=n?.Parent??Object;class o extends i{}function s(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"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 ko extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class zo extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Oo={};function Po(e){return Oo}function So(e,t){return"bigint"==typeof t?t.toString():t}function Ao(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Io(e){return null==e}function $o(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const To=Symbol("evaluating");function Bo(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==To)return void 0===r&&(r=To,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function No(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Uo(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Zo(e){return JSON.stringify(e)}const Ro="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Co(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const jo=Ao(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Fo(e){if(!1===Co(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!1!==Co(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function Do(e){return Fo(e)?{...e}:e}const Ho=new Set(["string","number","symbol"]);function Lo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Vo(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function qo(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 Ko={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 Mo(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 Wo(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Go(e){return"string"==typeof e?e:e?.message}function Yo(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=Go(e.inst?._zod.def?.error?.(e))??Go(t?.error?.(e))??Go(n.customError?.(e))??Go(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Xo(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Jo(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const Qo=(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,So,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},es=xo("$ZodError",Qo),ts=xo("$ZodError",Qo,{Parent:Error});const ns=e=>(t,n,r,i)=>{const o=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new ko;if(s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Yo(e,o,Po())));throw Ro(t,i?.callee),t}return s.value},rs=e=>async(t,n,r,i)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Yo(e,o,Po())));throw Ro(t,i?.callee),t}return s.value},is=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new ko;return o.issues.length?{success:!1,error:new(e??es)(o.issues.map(e=>Yo(e,i,Po())))}:{success:!0,data:o.value}},os=is(ts),ss=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(e=>Yo(e,i,Po())))}:{success:!0,data:o.value}},us=ss(ts),cs=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ns(e)(t,n,i)},as=e=>(t,n,r)=>ns(e)(t,n,r),fs=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return rs(e)(t,n,i)},ds=e=>async(t,n,r)=>rs(e)(t,n,r),ls=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return is(e)(t,n,i)},hs=e=>(t,n,r)=>is(e)(t,n,r),ps=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ss(e)(t,n,i)},ms=e=>async(t,n,r)=>ss(e)(t,n,r),gs=/^[cC][^\s-]{8,}$/,_s=/^[0-9a-z]+$/,ys=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ws=/^[0-9a-vA-V]{20}$/,vs=/^[A-Za-z0-9]{27}$/,bs=/^[a-zA-Z0-9_-]{21}$/,Es=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,xs=/^([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})$/,ks=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)$/,zs=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const Os=/^(?:(?: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])$/,Ps=/^(([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})$/,Ss=/^((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])$/,As=/^(([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])$/,Is=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,$s=/^[A-Za-z0-9_-]*$/,Ts=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,Bs=/^\+(?:[0-9]){6,14}[0-9]$/,Ns="(?:(?:\\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])))",Us=new RegExp(`^${Ns}$`);function Zs(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 Rs=/^\d+n?$/,Cs=/^\d+$/,js=/^-?\d+(?:\.\d+)?/i,Fs=/true|false/i,Ds=/null/i,Hs=/^[^A-Z]*$/,Ls=/^[^a-z]*$/,Vs=xo("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),qs={number:"number",bigint:"bigint",object:"date"},Ks=xo("$ZodCheckLessThan",(e,t)=>{Vs.init(e,t);const n=qs[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:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ms=xo("$ZodCheckGreaterThan",(e,t)=>{Vs.init(e,t);const n=qs[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:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ws=xo("$ZodCheckMultipleOf",(e,t)=>{Vs.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.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(0===i&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}const o=n>i?n:i;return Number.parseInt(e.toFixed(o).replace(".",""))%Number.parseInt(t.toFixed(o).replace(".",""))/10**o}(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})}}),Gs=xo("$ZodCheckNumberFormat",(e,t)=>{Vs.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=Ko[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=Cs)}),e._zod.check=s=>{const u=s.value;if(n){if(!Number.isInteger(u))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:u,inst:e});if(!Number.isSafeInteger(u))return void(u>0?s.issues.push({input:u,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):s.issues.push({input:u,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}))}u<i&&s.issues.push({origin:"number",input:u,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),u>o&&s.issues.push({origin:"number",input:u,code:"too_big",maximum:o,inst:e})}}),Ys=xo("$ZodCheckMaxLength",(e,t)=>{var n;Vs.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Io(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 i=Xo(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Xs=xo("$ZodCheckMinLength",(e,t)=>{var n;Vs.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Io(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 i=Xo(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Js=xo("$ZodCheckLengthEquals",(e,t)=>{var n;Vs.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Io(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,i=r.length;if(i===t.length)return;const o=Xo(r),s=i>t.length;n.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Qs=xo("$ZodCheckStringFormat",(e,t)=>{var n,r;Vs.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=()=>{})}),eu=xo("$ZodCheckRegex",(e,t)=>{Qs.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})}}),tu=xo("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Hs),Qs.init(e,t)}),nu=xo("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Ls),Qs.init(e,t)}),ru=xo("$ZodCheckIncludes",(e,t)=>{Vs.init(e,t);const n=Lo(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})}}),iu=xo("$ZodCheckStartsWith",(e,t)=>{Vs.init(e,t);const n=new RegExp(`^${Lo(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})}}),ou=xo("$ZodCheckEndsWith",(e,t)=>{Vs.init(e,t);const n=new RegExp(`.*${Lo(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})}}),su=xo("$ZodCheckOverwrite",(e,t)=>{Vs.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class uu{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 cu={major:4,minor:1,patch:5},au=xo("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=cu;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,i=Mo(e);for(const o of t){if(o._zod.def.when){if(!o._zod.def.when(e))continue}else if(i)continue;const t=e.issues.length,s=o._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new ko;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(i||(i=Mo(e,t)))});else{if(e.issues.length===t)continue;i||(i=Mo(e,t))}}return r?r.then(()=>e):e},n=(n,i,o)=>{if(Mo(n))return n.aborted=!0,n;const s=t(i,r,o);if(s instanceof Promise){if(!1===o.async)throw new ko;return s.then(t=>e._zod.parse(t,o))}return e._zod.parse(s,o)};e._zod.run=(i,o)=>{if(o.skipChecks)return e._zod.parse(i,o);if("backward"===o.direction){const t=e._zod.parse({value:i.value,issues:[]},{...o,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,o)):n(t,i,o)}const s=e._zod.parse(i,o);if(s instanceof Promise){if(!1===o.async)throw new ko;return s.then(e=>t(e,r,o))}return t(s,r,o)}}e["~standard"]={validate:t=>{try{const n=os(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return us(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}}),fu=xo("$ZodString",(e,t)=>{var n;au.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}}),du=xo("$ZodStringFormat",(e,t)=>{Qs.init(e,t),fu.init(e,t)}),lu=xo("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=xs),du.init(e,t)}),hu=xo("$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=ks(e))}else t.pattern??(t.pattern=ks());du.init(e,t)}),pu=xo("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=zs),du.init(e,t)}),mu=xo("$ZodURL",(e,t)=>{du.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:Ts.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.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=i.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),gu=xo("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),du.init(e,t)}),_u=xo("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=bs),du.init(e,t)}),yu=xo("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=gs),du.init(e,t)}),wu=xo("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=_s),du.init(e,t)}),vu=xo("$ZodULID",(e,t)=>{t.pattern??(t.pattern=ys),du.init(e,t)}),bu=xo("$ZodXID",(e,t)=>{t.pattern??(t.pattern=ws),du.init(e,t)}),Eu=xo("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=vs),du.init(e,t)}),xu=xo("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=Zs({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(`^${Ns}T(?:${r})$`)}(t)),du.init(e,t)}),ku=xo("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Us),du.init(e,t)}),zu=xo("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${Zs(t)}$`)),du.init(e,t)}),Ou=xo("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Es),du.init(e,t)}),Pu=xo("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Os),du.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.format="ipv4"})}),Su=xo("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Ps),du.init(e,t),e._zod.onattach.push(e=>{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})}}}),Au=xo("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Ss),du.init(e,t)}),Iu=xo("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=As),du.init(e,t),e._zod.check=n=>{const[r,i]=n.value.split("/");try{if(!i)throw new Error;const e=Number(i);if(`${e}`!==i)throw new Error;if(e<0||e>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function $u(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Tu=xo("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Is),du.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64"}),e._zod.check=n=>{$u(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const Bu=xo("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=$s),du.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64url"}),e._zod.check=n=>{(function(e){if(!$s.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return $u(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})}}),Nu=xo("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Bs),du.init(e,t)});const Uu=xo("$ZodJWT",(e,t)=>{du.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 i=JSON.parse(atob(r));return!("typ"in i&&"JWT"!==i?.typ||!i.alg||t&&(!("alg"in i)||i.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})}}),Zu=xo("$ZodNumber",(e,t)=>{au.init(e,t),e._zod.pattern=e._zod.bag.pattern??js,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const i=n.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}}),Ru=xo("$ZodNumber",(e,t)=>{Gs.init(e,t),Zu.init(e,t)}),Cu=xo("$ZodBoolean",(e,t)=>{au.init(e,t),e._zod.pattern=Fs,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const i=n.value;return"boolean"==typeof i||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),ju=xo("$ZodBigInt",(e,t)=>{au.init(e,t),e._zod.pattern=Rs,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}}),Fu=xo("$ZodNull",(e,t)=>{au.init(e,t),e._zod.pattern=Ds,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}}),Du=xo("$ZodAny",(e,t)=>{au.init(e,t),e._zod.parse=e=>e}),Hu=xo("$ZodUnknown",(e,t)=>{au.init(e,t),e._zod.parse=e=>e}),Lu=xo("$ZodNever",(e,t)=>{au.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)}),Vu=xo("$ZodDate",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=new Date(n.value)}catch(e){}const i=n.value,o=i instanceof Date;return o&&!Number.isNaN(i.getTime())||n.issues.push({expected:"date",code:"invalid_type",input:i,...o?{received:"Invalid Date"}:{},inst:e}),n}});function qu(e,t,n){e.issues.length&&t.issues.push(...Wo(n,e.issues)),t.value[n]=e.value}const Ku=xo("$ZodArray",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const o=[];for(let e=0;e<i.length;e++){const s=i[e],u=t.element._zod.run({value:s,issues:[]},r);u instanceof Promise?o.push(u.then(t=>qu(t,n,e))):qu(u,n,e)}return o.length?Promise.all(o).then(()=>n):n}});function Mu(e,t,n,r){e.issues.length&&t.issues.push(...Wo(n,e.issues)),void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Wu(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 Gu(e,t,n,r,i,o){const s=[],u=i.keySet,c=i.catchall._zod,a=c.def.type;for(const i of Object.keys(t)){if(u.has(i))continue;if("never"===a){s.push(i);continue}const o=c.run({value:t[i],issues:[]},r);o instanceof Promise?e.push(o.then(e=>Mu(e,n,i,t))):Mu(o,n,i,t)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}const Yu=xo("$ZodObject",(e,t)=>{au.init(e,t);const n=Ao(()=>Wu(t));Bo(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 r=Co,i=t.catchall;let o;e._zod.parse=(t,s)=>{o??(o=n.value);const u=t.value;if(!r(u))return t.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),t;t.value={};const c=[],a=o.shape;for(const e of o.keys){const n=a[e]._zod.run({value:u[e],issues:[]},s);n instanceof Promise?c.push(n.then(n=>Mu(n,t,e,u))):Mu(n,t,e,u)}return i?Gu(c,u,t,s,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Xu=xo("$ZodObjectJIT",(e,t)=>{Yu.init(e,t);const n=e._zod.parse,r=Ao(()=>Wu(t));let i;const o=Co,s=!Oo.jitless,u=s&&jo.value,c=t.catchall;let a;e._zod.parse=(f,d)=>{a??(a=r.value);const l=f.value;return o(l)?s&&u&&!1===d?.async&&!0!==d.jitless?(i||(i=(e=>{const t=new uu(["shape","payload","ctx"]),n=r.value,i=e=>{const t=Zo(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const o=Object.create(null);let s=0;for(const e of n.keys)o[e]="key_"+s++;t.write("const newResult = {}");for(const e of n.keys){const n=o[e],r=Zo(e);t.write(`const ${n} = ${i(e)};`),t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${r}, ...iss.path] : [${r}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${r} in input) {\n newResult[${r}] = undefined;\n }\n } else {\n newResult[${r}] = ${n}.value;\n }\n `)}t.write("payload.value = newResult;"),t.write("return payload;");const u=t.compile();return(t,n)=>u(e,t,n)})(t.shape)),f=i(f,d),c?Gu([],l,f,d,a,e):f):n(f,d):(f.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),f)}});function Ju(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const i=e.filter(e=>!Mo(e));return 1===i.length?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Yo(e,r,Po())))}),t)}const Qu=xo("$ZodUnion",(e,t)=>{au.init(e,t),Bo(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),Bo(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),Bo(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Bo(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=>$o(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(i,o)=>{if(n)return r(i,o);let s=!1;const u=[];for(const e of t.options){const t=e._zod.run({value:i.value,issues:[]},o);if(t instanceof Promise)u.push(t),s=!0;else{if(0===t.issues.length)return t;u.push(t)}}return s?Promise.all(u).then(t=>Ju(t,i,e,o)):Ju(u,i,e,o)}}),ec=xo("$ZodIntersection",(e,t)=>{au.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,i=t.left._zod.run({value:r,issues:[]},n),o=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([t,n])=>nc(e,t,n)):nc(e,i,o)}});function tc(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(Fo(e)&&Fo(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=tc(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=tc(e[r],t[r]);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function nc(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Mo(e))return e;const r=tc(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const rc=xo("$ZodRecord",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Fo(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const o=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){const s=t.valueType._zod.run({value:i[e],issues:[]},r);s instanceof Promise?o.push(s.then(t=>{t.issues.length&&n.issues.push(...Wo(e,t.issues)),n.value[e]=t.value})):(s.issues.length&&n.issues.push(...Wo(e,s.issues)),n.value[e]=s.value)}let u;for(const e in i)s.has(e)||(u=u??[],u.push(e));u&&u.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:u})}else{n.value={};for(const s of Reflect.ownKeys(i)){if("__proto__"===s)continue;const u=t.keyType._zod.run({value:s,issues:[]},r);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(u.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:u.issues.map(e=>Yo(e,r,Po())),input:s,path:[s],inst:e}),n.value[u.value]=u.value;continue}const c=t.valueType._zod.run({value:i[s],issues:[]},r);c instanceof Promise?o.push(c.then(e=>{e.issues.length&&n.issues.push(...Wo(s,e.issues)),n.value[u.value]=e.value})):(c.issues.length&&n.issues.push(...Wo(s,c.issues)),n.value[u.value]=c.value)}}return o.length?Promise.all(o).then(()=>n):n}}),ic=xo("$ZodEnum",(e,t)=>{au.init(e,t);const n=function(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)}(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>Ho.has(typeof e)).map(e=>"string"==typeof e?Lo(e):e.toString()).join("|")})$`),e._zod.parse=(t,i)=>{const o=t.value;return r.has(o)||t.issues.push({code:"invalid_value",values:n,input:o,inst:e}),t}}),oc=xo("$ZodTransform",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new zo(e.constructor.name);const i=t.transform(n.value,n);if(r.async){return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n))}if(i instanceof Promise)throw new ko;return n.value=i,n}});function sc(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const uc=xo("$ZodOptional",(e,t)=>{au.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Bo(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Bo(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${$o(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>sc(t,e.value)):sc(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),cc=xo("$ZodNullable",(e,t)=>{au.init(e,t),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(e._zod,"optout",()=>t.innerType._zod.optout),Bo(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${$o(e.source)}|null)$`):void 0}),Bo(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)}),ac=xo("$ZodDefault",(e,t)=>{au.init(e,t),e._zod.optin="optional",Bo(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=>fc(e,t)):fc(r,t)}});function fc(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const dc=xo("$ZodPrefault",(e,t)=>{au.init(e,t),e._zod.optin="optional",Bo(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))}),lc=xo("$ZodNonOptional",(e,t)=>{au.init(e,t),Bo(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 i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>hc(t,e)):hc(i,e)}});function hc(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 pc=xo("$ZodCatch",(e,t)=>{au.init(e,t),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(e._zod,"optout",()=>t.innerType._zod.optout),Bo(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=>Yo(e,n,Po()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Yo(e,n,Po()))},input:e.value}),e.issues=[]),e)}}),mc=xo("$ZodPipe",(e,t)=>{au.init(e,t),Bo(e._zod,"values",()=>t.in._zod.values),Bo(e._zod,"optin",()=>t.in._zod.optin),Bo(e._zod,"optout",()=>t.out._zod.optout),Bo(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=>gc(e,t.in,n)):gc(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>gc(e,t.out,n)):gc(r,t.out,n)}});function gc(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const _c=xo("$ZodReadonly",(e,t)=>{au.init(e,t),Bo(e._zod,"propValues",()=>t.innerType._zod.propValues),Bo(e._zod,"values",()=>t.innerType._zod.values),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(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(yc):yc(r)}});function yc(e){return e.value=Object.freeze(e.value),e}const wc=xo("$ZodLazy",(e,t)=>{au.init(e,t),Bo(e._zod,"innerType",()=>t.getter()),Bo(e._zod,"pattern",()=>e._zod.innerType._zod.pattern),Bo(e._zod,"propValues",()=>e._zod.innerType._zod.propValues),Bo(e._zod,"optin",()=>e._zod.innerType._zod.optin??void 0),Bo(e._zod,"optout",()=>e._zod.innerType._zod.optout??void 0),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),vc=xo("$ZodCustom",(e,t)=>{Vs.init(e,t),au.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>bc(t,n,r,e));bc(i,n,r,e)}});function bc(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(Jo(e))}}class Ec{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){const n=t[0];if(this._map.set(e,n),n&&"object"==typeof n&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,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)}}function xc(){return new Ec}const kc=xc();function zc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...qo(t)})}function Oc(e,t){return new Ks({check:"less_than",...qo(t),value:e,inclusive:!1})}function Pc(e,t){return new Ks({check:"less_than",...qo(t),value:e,inclusive:!0})}function Sc(e,t){return new Ms({check:"greater_than",...qo(t),value:e,inclusive:!1})}function Ac(e,t){return new Ms({check:"greater_than",...qo(t),value:e,inclusive:!0})}function Ic(e,t){return new Ws({check:"multiple_of",...qo(t),value:e})}function $c(e,t){return new Ys({check:"max_length",...qo(t),maximum:e})}function Tc(e,t){return new Xs({check:"min_length",...qo(t),minimum:e})}function Bc(e,t){return new Js({check:"length_equals",...qo(t),length:e})}function Nc(e){return new su({check:"overwrite",tx:e})}function Uc(e){const t=function(e,t){const n=new Vs({check:"custom",...qo(t)});return n._zod.check=e,n}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Jo(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Jo(r))}},e(n.value,n)));return t}const Zc=xo("ZodISODateTime",(e,t)=>{xu.init(e,t),ua.init(e,t)});function Rc(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...qo(t)})}(Zc,e)}const Cc=xo("ZodISODate",(e,t)=>{ku.init(e,t),ua.init(e,t)});function jc(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...qo(t)})}(Cc,e)}const Fc=xo("ZodISOTime",(e,t)=>{zu.init(e,t),ua.init(e,t)});function Dc(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...qo(t)})}(Fc,e)}const Hc=xo("ZodISODuration",(e,t)=>{Ou.init(e,t),ua.init(e,t)});function Lc(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...qo(t)})}(Hc,e)}const Vc=xo("ZodError",(e,t)=>{es.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t){const n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(const t of e.issues)if("invalid_union"===t.code&&t.errors.length)t.errors.map(e=>i({issues:e}));else if("invalid_key"===t.code)i({issues:t.issues});else if("invalid_element"===t.code)i({issues:t.issues});else if(0===t.path.length)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){const r=t.path[i];i===t.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,So,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,So,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),qc=ns(Vc),Kc=rs(Vc),Mc=is(Vc),Wc=ss(Vc),Gc=cs(Vc),Yc=as(Vc),Xc=fs(Vc),Jc=ds(Vc),Qc=ls(Vc),ea=hs(Vc),ta=ps(Vc),na=ms(Vc),ra=xo("ZodType",(e,t)=>(au.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),e.clone=(t,n)=>Vo(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>qc(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Mc(e,t,n),e.parseAsync=async(t,n)=>Kc(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Wc(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Gc(e,t,n),e.decode=(t,n)=>Yc(e,t,n),e.encodeAsync=async(t,n)=>Xc(e,t,n),e.decodeAsync=async(t,n)=>Jc(e,t,n),e.safeEncode=(t,n)=>Qc(e,t,n),e.safeDecode=(t,n)=>ea(e,t,n),e.safeEncodeAsync=async(t,n)=>ta(e,t,n),e.safeDecodeAsync=async(t,n)=>na(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...qo(n)})}(lf,e,t)}(t,n)),e.superRefine=t=>e.check(Uc(t)),e.overwrite=t=>e.check(Nc(t)),e.optional=()=>ef(e),e.nullable=()=>nf(e),e.nullish=()=>ef(nf(e)),e.nonoptional=t=>function(e,t){return new sf({type:"nonoptional",innerType:e,...qo(t)})}(e,t),e.array=()=>La(e),e.or=t=>Ma([e,t]),e.and=t=>new Wa({type:"intersection",left:e,right:t}),e.transform=t=>af(e,new Ja({type:"transform",transform:t})),e.default=t=>{return n=t,new rf({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():Do(n)}});var n},e.prefault=t=>{return n=t,new of({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():Do(n)}});var n},e.catch=t=>{return new uf({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>af(e,t),e.readonly=()=>new ff({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return kc.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>kc.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return kc.get(e);const n=e.clone();return kc.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),ia=xo("_ZodString",(e,t)=>{fu.init(e,t),ra.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new eu({check:"string_format",format:"regex",...qo(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new ru({check:"string_format",format:"includes",...qo(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new iu({check:"string_format",format:"starts_with",...qo(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new ou({check:"string_format",format:"ends_with",...qo(t),suffix:e})}(...t)),e.min=(...t)=>e.check(Tc(...t)),e.max=(...t)=>e.check($c(...t)),e.length=(...t)=>e.check(Bc(...t)),e.nonempty=(...t)=>e.check(Tc(1,...t)),e.lowercase=t=>e.check(function(e){return new tu({check:"string_format",format:"lowercase",...qo(e)})}(t)),e.uppercase=t=>e.check(function(e){return new nu({check:"string_format",format:"uppercase",...qo(e)})}(t)),e.trim=()=>e.check(Nc(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return Nc(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(Nc(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(Nc(e=>e.toUpperCase()))}),oa=xo("ZodString",(e,t)=>{fu.init(e,t),ia.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...qo(t)})}(ca,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...qo(t)})}(da,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...qo(t)})}(Oa,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...qo(t)})}(la,t)),e.guid=t=>e.check(zc(aa,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...qo(t)})}(fa,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...qo(t)})}(fa,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...qo(t)})}(fa,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...qo(t)})}(fa,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...qo(t)})}(ha,t)),e.guid=t=>e.check(zc(aa,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...qo(t)})}(pa,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...qo(t)})}(ma,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...qo(t)})}(ga,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...qo(t)})}(xa,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...qo(t)})}(ka,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...qo(t)})}(_a,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...qo(t)})}(ya,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...qo(t)})}(wa,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...qo(t)})}(va,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...qo(t)})}(ba,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...qo(t)})}(Ea,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...qo(t)})}(za,t)),e.datetime=t=>e.check(Rc(t)),e.date=t=>e.check(jc(t)),e.time=t=>e.check(Dc(t)),e.duration=t=>e.check(Lc(t))});function sa(e){return function(e,t){return new e({type:"string",...qo(t)})}(oa,e)}const ua=xo("ZodStringFormat",(e,t)=>{du.init(e,t),ia.init(e,t)}),ca=xo("ZodEmail",(e,t)=>{pu.init(e,t),ua.init(e,t)}),aa=xo("ZodGUID",(e,t)=>{lu.init(e,t),ua.init(e,t)}),fa=xo("ZodUUID",(e,t)=>{hu.init(e,t),ua.init(e,t)}),da=xo("ZodURL",(e,t)=>{mu.init(e,t),ua.init(e,t)}),la=xo("ZodEmoji",(e,t)=>{gu.init(e,t),ua.init(e,t)}),ha=xo("ZodNanoID",(e,t)=>{_u.init(e,t),ua.init(e,t)}),pa=xo("ZodCUID",(e,t)=>{yu.init(e,t),ua.init(e,t)}),ma=xo("ZodCUID2",(e,t)=>{wu.init(e,t),ua.init(e,t)}),ga=xo("ZodULID",(e,t)=>{vu.init(e,t),ua.init(e,t)}),_a=xo("ZodXID",(e,t)=>{bu.init(e,t),ua.init(e,t)}),ya=xo("ZodKSUID",(e,t)=>{Eu.init(e,t),ua.init(e,t)}),wa=xo("ZodIPv4",(e,t)=>{Pu.init(e,t),ua.init(e,t)}),va=xo("ZodIPv6",(e,t)=>{Su.init(e,t),ua.init(e,t)}),ba=xo("ZodCIDRv4",(e,t)=>{Au.init(e,t),ua.init(e,t)}),Ea=xo("ZodCIDRv6",(e,t)=>{Iu.init(e,t),ua.init(e,t)}),xa=xo("ZodBase64",(e,t)=>{Tu.init(e,t),ua.init(e,t)}),ka=xo("ZodBase64URL",(e,t)=>{Bu.init(e,t),ua.init(e,t)}),za=xo("ZodE164",(e,t)=>{Nu.init(e,t),ua.init(e,t)}),Oa=xo("ZodJWT",(e,t)=>{Uu.init(e,t),ua.init(e,t)}),Pa=xo("ZodNumber",(e,t)=>{Zu.init(e,t),ra.init(e,t),e.gt=(t,n)=>e.check(Sc(t,n)),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.lt=(t,n)=>e.check(Oc(t,n)),e.lte=(t,n)=>e.check(Pc(t,n)),e.max=(t,n)=>e.check(Pc(t,n)),e.int=t=>e.check(Ia(t)),e.safe=t=>e.check(Ia(t)),e.positive=t=>e.check(Sc(0,t)),e.nonnegative=t=>e.check(Ac(0,t)),e.negative=t=>e.check(Oc(0,t)),e.nonpositive=t=>e.check(Pc(0,t)),e.multipleOf=(t,n)=>e.check(Ic(t,n)),e.step=(t,n)=>e.check(Ic(t,n)),e.finite=()=>e;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 Sa(e){return function(e,t){return new e({type:"number",checks:[],...qo(t)})}(Pa,e)}const Aa=xo("ZodNumberFormat",(e,t)=>{Ru.init(e,t),Pa.init(e,t)});function Ia(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...qo(t)})}(Aa,e)}const $a=xo("ZodBoolean",(e,t)=>{Cu.init(e,t),ra.init(e,t)});function Ta(e){return function(e,t){return new e({type:"boolean",...qo(t)})}($a,e)}const Ba=xo("ZodBigInt",(e,t)=>{ju.init(e,t),ra.init(e,t),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.gt=(t,n)=>e.check(Sc(t,n)),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.lt=(t,n)=>e.check(Oc(t,n)),e.lte=(t,n)=>e.check(Pc(t,n)),e.max=(t,n)=>e.check(Pc(t,n)),e.positive=t=>e.check(Sc(BigInt(0),t)),e.negative=t=>e.check(Oc(BigInt(0),t)),e.nonpositive=t=>e.check(Pc(BigInt(0),t)),e.nonnegative=t=>e.check(Ac(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Ic(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});function Na(e){return function(e,t){return new e({type:"bigint",...qo(t)})}(Ba,e)}const Ua=xo("ZodNull",(e,t)=>{Fu.init(e,t),ra.init(e,t)});const Za=xo("ZodAny",(e,t)=>{Du.init(e,t),ra.init(e,t)});const Ra=xo("ZodUnknown",(e,t)=>{Hu.init(e,t),ra.init(e,t)});function Ca(){return new Ra({type:"unknown"})}const ja=xo("ZodNever",(e,t)=>{Lu.init(e,t),ra.init(e,t)});function Fa(e){return function(e,t){return new e({type:"never",...qo(t)})}(ja,e)}const Da=xo("ZodDate",(e,t)=>{Vu.init(e,t),ra.init(e,t),e.min=(t,n)=>e.check(Ac(t,n)),e.max=(t,n)=>e.check(Pc(t,n));const n=e._zod.bag;e.minDate=n.minimum?new Date(n.minimum):null,e.maxDate=n.maximum?new Date(n.maximum):null});const Ha=xo("ZodArray",(e,t)=>{Ku.init(e,t),ra.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Tc(t,n)),e.nonempty=t=>e.check(Tc(1,t)),e.max=(t,n)=>e.check($c(t,n)),e.length=(t,n)=>e.check(Bc(t,n)),e.unwrap=()=>e.element});function La(e,t){return function(e,t,n){return new e({type:"array",element:t,...qo(n)})}(Ha,e,t)}const Va=xo("ZodObject",(e,t)=>{Xu.init(e,t),ra.init(e,t),Bo(e,"shape",()=>t.shape),e.keyof=()=>function(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Xa({type:"enum",entries:n,...qo(t)})}(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ca()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ca()}),e.strict=()=>e.clone({...e._zod.def,catchall:Fa()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!Fo(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const r=Uo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return No(this,"shape",n),n},checks:[]});return Vo(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!Fo(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const n={...e._zod.def.shape,...t};return No(this,"shape",n),n},checks:e._zod.def.checks};return Vo(e,n)}(e,t),e.merge=t=>function(e,t){const n=Uo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return No(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return Vo(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def;return Vo(e,Uo(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 No(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(e,t){const n=e._zod.def,r=Uo(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 No(this,"shape",r),r},checks:[]});return Vo(e,r)}(e,t),e.partial=(...t)=>function(e,t,n){const r=Uo(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)i[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return No(this,"shape",i),i},checks:[]});return Vo(t,r)}(Qa,e,t[0]),e.required=(...t)=>function(e,t,n){const r=Uo(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in i))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)i[t]=new e({type:"nonoptional",innerType:r[t]});return No(this,"shape",i),i},checks:[]});return Vo(t,r)}(sf,e,t[0])});function qa(e,t){const n={type:"object",get shape(){var t;return No(this,"shape",e?(t=e,Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))):{}),this.shape},...qo(t)};return new Va(n)}const Ka=xo("ZodUnion",(e,t)=>{Qu.init(e,t),ra.init(e,t),e.options=t.options});function Ma(e,t){return new Ka({type:"union",options:e,...qo(t)})}const Wa=xo("ZodIntersection",(e,t)=>{ec.init(e,t),ra.init(e,t)});const Ga=xo("ZodRecord",(e,t)=>{rc.init(e,t),ra.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Ya(e,t,n){return new Ga({type:"record",keyType:e,valueType:t,...qo(n)})}const Xa=xo("ZodEnum",(e,t)=>{ic.init(e,t),ra.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const i={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);i[r]=t.entries[r]}return new Xa({...t,checks:[],...qo(r),entries:i})},e.exclude=(e,r)=>{const i={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete i[t]}return new Xa({...t,checks:[],...qo(r),entries:i})}});const Ja=xo("ZodTransform",(e,t)=>{oc.init(e,t),ra.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new zo(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(Jo(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(Jo(t))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});const Qa=xo("ZodOptional",(e,t)=>{uc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ef(e){return new Qa({type:"optional",innerType:e})}const tf=xo("ZodNullable",(e,t)=>{cc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});function nf(e){return new tf({type:"nullable",innerType:e})}const rf=xo("ZodDefault",(e,t)=>{ac.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const of=xo("ZodPrefault",(e,t)=>{dc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});const sf=xo("ZodNonOptional",(e,t)=>{lc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});const uf=xo("ZodCatch",(e,t)=>{pc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const cf=xo("ZodPipe",(e,t)=>{mc.init(e,t),ra.init(e,t),e.in=t.in,e.out=t.out});function af(e,t){return new cf({type:"pipe",in:e,out:t})}const ff=xo("ZodReadonly",(e,t)=>{_c.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});const df=xo("ZodLazy",(e,t)=>{wc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.getter()});const lf=xo("ZodCustom",(e,t)=>{vc.init(e,t),ra.init(e,t)});var hf;Na(),Ta(),function(e,t){new e({type:"date",...qo(t)})}(Da,hf);const pf=Sa().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),mf=function(e,t={error:`Input not instance of ${e.name}`}){const n=new lf({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...qo(t)});return n._zod.bag.Class=e,n}(Uint8Array),gf=sa();pf.min(5e8),new Za({type:"any"}),pf.min(0).max(255),pf.min(0).max(65535);const _f=pf.min(0).max(4294967295);Sa().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const yf=sa().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),wf=Ma([sa(),Sa(),Ta(),function(e){return function(e,t){return new e({type:"null",...qo(t)})}(Ua,e)}()]),vf=new df({type:"lazy",getter:()=>Ma([wf,La(vf),Ya(gf,vf)])});mf.refine(e=>20===e.length);const bf=mf.refine(e=>32===e.length),Ef=mf.refine(e=>33===e.length),xf=mf.refine(e=>64===e.length);yf.refine(e=>40===e.length);const kf=yf.refine(e=>64===e.length),zf=yf.refine(e=>66===e.length),Of=yf.refine(e=>128===e.length);Ma([yf,mf]);const Pf=Ma([kf,bf]);Ma([zf,Ef]),Ma([Of,xf]),sa().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),sa().regex(/^[a-zA-Z0-9+/]+={0,2}$/),sa().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),sa().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const Sf=Ma([La(Pf),Pf]),Af=qa({pubkey:Pf,leaves:Sf.array().optional(),target:Pf.optional(),version:_f.optional()});var If=Object.freeze({__proto__:null,config:Af,taptree:Sf});const $f=Na().min(0n).max(2100000000000000n),Tf=qa({value:$f,script_pk:yf}),Bf=qa({coinbase:yf.nullable(),txid:kf,vout:_f,prevout:Tf.nullable(),script_sig:yf.nullable(),sequence:_f,witness:La(yf)}),Nf=qa({version:_f,vin:La(Bf),vout:La(Tf),locktime:_f}),Uf=Tf.extend({value:Ma([_f,$f])}),Zf=Bf.extend({coinbase:yf.nullable().optional(),prevout:Uf.nullable().optional(),script_sig:yf.nullable().optional(),sequence:Ma([yf,_f]).optional(),witness:La(yf).optional()}),Rf=qa({version:_f.optional(),vin:La(Zf),vout:La(Uf),locktime:_f.optional()});var Cf=Object.freeze({__proto__:null,tx_data:Nf,tx_input:Bf,tx_output:Tf,tx_template:Rf,vin_template:Zf,vout_template:Uf}),jf=Object.freeze({__proto__:null,taproot:If,tx:Cf});function Ff(e){Rf.parse(e)}function Df(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Hf(e){Nf.parse(e)}function Lf(e){Zf.parse(e)}function Vf(e){Uf.parse(e)}function qf(e,t=!0){Hf(e);const{version:n,vin:r,vout:i,locktime:o}=e,s=[Kf(n)];if(t&&s.push(g.hex("0001")),s.push(Yf(r)),s.push(Qf(i)),t)for(const e of r)s.push(td(e.witness));return s.push(nd(o)),g.join(s)}function Kf(e){return g.num(e,4).reverse()}function Mf(e){return g.hex(e,32).reverse()}function Wf(e){return g.num(e,4).reverse()}function Gf(e){return g.num(e,4).reverse()}function Yf(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(Xf(n));return g.join(t)}function Xf(e){return null!==e.coinbase?g.join([Mf(or.TXID),Wf(or.VOUT),rd(e.coinbase),Gf(e.sequence)]):g.join([Mf(e.txid),Wf(e.vout),rd(e.script_sig),Gf(e.sequence)])}function Jf(e){return g.big(e,8).reverse()}function Qf(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(ed(n));return g.join(t)}function ed(e){const{value:t,script_pk:n}=e;return g.join([Jf(t),rd(n)])}function td(e){const t=[g.varint(e.length)];for(const n of e)t.push(rd(n));return g.join(t)}function nd(e){return g.num(e,4).reverse()}function rd(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function id(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=yo(e):(Ff(e),n=pd(e)),t){b.has_items(t,"prevouts must be a non-empty array");for(const[e,r]of n.vin.entries()){const n=t.at(e);b.exists(n,"prevout not found for input index: "+e),r.prevout=hd(n)}}return n}function od(e,t=!0){console.log("txdata:",e);const n=yo(e);return console.log("decoded:",n),qf(n,t)}function sd(e){if(!v.exists(e))return sr.SEQUENCE;if(v.is_hex(e))return g.hex(e,4).reverse().num;if(v.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function ud(e){if(v.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function cd(e){return{script_pk:e.script_pk,value:ud(e.value)}}function ad(e){Lf(e),b.exists(e.coinbase,"coinbase is required");const t=or.TXID,n=or.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:sd(e.sequence),witness:i,txid:t,vout:n}}function fd(e){Lf(e),b.is_empty(e.coinbase,"coinbase is not allowed"),b.is_empty(e.prevout,"prevout is not allowed");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:null,script_sig:r,sequence:sd(e.sequence),witness:i}}function dd(e){Lf(e),b.exists(e.prevout,"prevout is required");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:cd(e.prevout),script_sig:r,sequence:sd(e.sequence),witness:i}}function ld(e){return e.coinbase?ad(e):e.prevout?dd(e):fd(e)}function hd(e){Vf(e);return{script_pk:e.script_pk,value:ud(e.value)}}function pd(e){Ff(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??sr.LOCKTIME,i=e.version??sr.VERSION;return{locktime:r,vin:t.map(e=>ld(e)),vout:n.map(e=>hd(e)),version:i}}var md=Object.freeze({__proto__:null,assert_has_prevouts:Df,assert_tx_data:Hf,assert_tx_input:function(e){Bf.parse(e)},assert_tx_output:function(e){Tf.parse(e)},assert_tx_spend_data:function(e){Hf(e),Df(e.vin)},assert_tx_template:Ff,assert_vin_template:Lf,assert_vout_template:Vf,create_coinbase_input:ad,create_spend_input:dd,create_tx:pd,create_tx_input:ld,create_tx_output:hd,create_virtual_input:fd,decode_tx:yo,encode_script_data:rd,encode_tx:qf,encode_tx_inputs:Yf,encode_tx_locktime:nd,encode_tx_outputs:Qf,encode_tx_version:Kf,encode_tx_vout:ed,encode_txin_sequence:Gf,encode_txin_txid:Mf,encode_txin_vout:Wf,encode_vin:Xf,encode_vin_witness:td,encode_vout_value:Jf,get_prevouts:function(e){Ff(e);const t=e.vin.map(e=>e.prevout);return b.ok(t.every(e=>null!==e),"prevouts missing from tx"),t},get_segwit_size:function(e){return 2+e.filter(e=>e.witness.length>0).map(e=>e.witness).reduce((e,t)=>e+td(t).length,0)},get_tx_value:function(e){const t=id(e);Ff(t);const n=t.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),r=t.vout.reduce((e,t)=>e+t.value,0n);return{fees:n>r?n-r:0n,vin:n,vout:r}},get_txhash:function(e){return"object"==typeof e&&(Ff(e),e=qf(e,!0)),mn(e).reverse().hex},get_txid:function(e){let t;if(e instanceof Uint8Array)t=od(e,!1);else if("object"==typeof e)Ff(e),t=qf(e,!1);else{if("string"!=typeof e)throw new TypeError("invalid txdata type: "+typeof e);b.is_hex(e),t=od(e,!1)}return mn(t).reverse().hex},get_txin_size:function(e){return Xf(e).length},get_txout_size:function(e){return ed(e).length},get_txsize:function(e){const t=id(e),n=qf(t,!1).length,r=qf(t,!0).length,i=3*n+r,o=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+o,weight:i}},get_vin_size:function(e){return Yf(e).length},get_vout_size:function(e){return Qf(e).length},get_vsize:function(e){const t=g.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},normalize_prevout:cd,normalize_sequence:sd,normalize_value:ud,parse_tx:id,read_payload:Eo,serialize_tx:function(e){const t=id(e),n=t.version,r=t.locktime,i=[],o=[];for(const e of t.vin)null!==e.prevout&&i.push({script_pk:e.prevout.script_pk,value:Number(e.prevout.value)});for(const e of t.vout)o.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:o}},transcode_tx:od});function gd(e,t={}){const{sigflag:n=1,txindex:r}=t,i=id(e),o=!(128&~n),s=n%128;if(!fr.includes(s))throw new Error("Invalid hash type: "+String(n));const{version:u,vin:c,vout:a,locktime:f}=i,d=go(i,t),{txid:l,vout:h,prevout:p,sequence:m}=d,{value:_}=p??{};if(void 0===_)throw new Error("Prevout value is empty!");let{pubkey:y,script:w}=t;if(void 0===w&&void 0!==y){const e=hn(y).hex;w=`76a914${String(e)}88ac`}if(void 0===w)throw new Error("No pubkey / script has been set!");if(Fi(w).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const v=[Kf(u),_d(c,o),yd(c,s,o),Mf(l),Wf(h),ho(w),Jf(_),Gf(m),wd(a,s,r),nd(f),g.num(n,4).reverse()];return mn(g.join(v))}function _d(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(Mf(t)),n.push(Wf(r));return mn(g.join(n))}function yd(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(Gf(t));return mn(g.join(r))}function wd(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(Jf(t)),r.push(ho(n));return mn(g.join(r))}if(3===t&&(b.ok(void 0!==n),n<e.length)){const{value:t,script_pk:i}=e[n];return r.push(Jf(t)),r.push(ho(i)),mn(g.join(r))}return g.num(0,32)}function vd(e,t=192){return bd(ho(e),t)}function bd(e,t=192){return gn("TapLeaf",xd(t),e)}function Ed(e,t){return t<e&&([e,t]=[t,e]),gn("TapBranch",e,t)}function xd(e=192){return 254&e}function kd(e,t=new Uint8Array){return b.size(e,32),gn("TapTweak",e,t)}function zd(e,t={}){return gn("TapSighash",Od(e,t))}function Od(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:o=0,key_version:s=0,separator_pos:u=4294967295}=t,c=id(e),{version:a,vin:f,vout:d,locktime:l}=c,h=go(c,t),{txid:p,vout:m,sequence:_,witness:y=[]}=h;if(!dr.includes(i))throw new Error("Invalid hash type: "+String(i));if(o<0||o>127)throw new Error("Extention flag out of range: "+String(o));let{extension:w}=t;void 0!==n&&(w=vd(n).hex);const v=!(128&~i),E=_o(y),x=2*(o+(void 0!==w?1:0))+(void 0!==E?1:0),k=[g.num(0,1),g.num(i,1),Kf(a),nd(l)];if(!v){const e=f.map(e=>mo(e));k.push(Pd(f),Ad(e),Id(e),Sd(f))}if(((3&i)<2||(3&i)>3)&&k.push($d(d)),k.push(g.num(x,1)),v){const{value:e,script_pk:t}=mo(h);k.push(Mf(p),Wf(m),Jf(e),rd(t),Gf(_))}else b.ok("number"==typeof r),k.push(g.num(r,4).reverse());return void 0!==E&&k.push(E),3&~i||(b.ok("number"==typeof r),k.push(Td(d[r]))),void 0!==w&&k.push(g.bytes(w),g.num(s),g.num(u,4,"le")),g.join(k)}function Pd(e){const t=[];for(const{txid:n,vout:r}of e)t.push(Mf(n)),t.push(Wf(r));return pn(g.join(t))}function Sd(e){return pn(...e.map(e=>Gf(e.sequence)))}function Ad(e){return pn(...e.map(e=>Jf(e.value)))}function Id(e){return pn(...e.map(e=>rd(e.script_pk)))}function $d(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(Jf(n)),t.push(rd(r));return pn(...t)}function Td(e){return pn(Jf(e.value),rd(e.script_pk))}var Bd=Object.freeze({__proto__:null,bip143_hash_outputs:wd,bip143_hash_prevouts:_d,bip143_hash_sequence:yd,bip341_hash_amounts:Ad,bip341_hash_outpoints:Pd,bip341_hash_output:Td,bip341_hash_outputs:$d,bip341_hash_scripts:Id,bip341_hash_sequence:Sd,get_annex_data:_o,get_prevout:mo,get_taproot_tx_preimage:Od,hash_segwit_tx:gd,hash_taproot_tx:zd,parse_txinput:go});function Nd(e){return 0!==e?g.num(e,1).hex:""}var Ud=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=Yt(t),r=$t.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,gd(id(t),n)).hex+Nd(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=Yt(t);return Yt(Vt.sign(n,e))}(e,zd(id(t),n)).hex+Nd(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Zd(e,t,n=[]){const r=[],i=[];if(e.length<1)throw new Error("Tree is empty!");for(let i=0;i<e.length;i++){const o=e[i];if(Array.isArray(o)){let[e,i,s]=Zd(o,t);t=i,r.push(e);for(const e of s)n.push(e)}else{const e=g.bytes(o).hex;r.push(e)}}if(1===r.length)return[r[0],t,n];r.sort(),r.length%2!=0&&r.push(r[r.length-1]);for(let e=0;e<r.length-1;e+=2){const o=Ed(r[e],r[e+1]).hex;i.push(o),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=o):t===r[e+1]&&(n.push(r[e]),t=o))}return Zd(i,t,n)}function Rd(e){const t=e.map(e=>g.bytes(e)),n=e.map(e=>g.bytes(e).hex),r=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new g(t).hex:null}(t);null!==r&&t.pop();const i=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&t.length>32&&ur.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const o=function(e,t){let n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=64&&33===r.length?"p2wpkh":1===e.length&&void 0!==n&&64===n.length?"p2tr":e.length>1&&void 0!==i&&Di(i)?"p2wsh":null}(t,i),s=function(e){return null===e?null:e.startsWith("p2w")?0:e.startsWith("p2t")?1:null}(o),u=function(e,t){let n;switch(t){case"p2ts":n=e.at(-1);case"p2wsh":n=e.at(-1)}return void 0!==n?new g(n).hex:null}(t,o);null!==u&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:u,stack:n,type:o,version:s}}function Cd(e){const t=new _(e),n=t.read(1).num,r=t.read(32).hex,[i,o]=jd(n),s=[];for(;t.size>=32;)s.push(t.read(32).hex);if(0!==t.size)throw new Error("Non-empty buffer on control block: "+String(t));return{int_key:r,path:s,parity:o,version:i}}function jd(e){return e%2==0?[e-0,2]:[e-1,3]}function Fd(e){b.size(e,33,"invalid pubkey size");const[t]=g.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new Error("Invalid parity bit: "+String(t))}const Dd=192;var Hd=Object.freeze({__proto__:null,create_taproot:function(e){Af.parse(e);const{pubkey:t,version:n=Dd}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let o,s=[];if(r.length>0){const[e,t,n]=Zd(r,i);s=n,o=e}else o=i;const u=kd(t,o),c=Wt(t,u,"ecdsa"),a=Fd(c),f=Gt(c,"bip340"),d=[g.num(n+a),g.bytes(t)];s.length>0&&s.forEach(e=>d.push(e));const l=g.join(d);return{int_key:g.bytes(t).hex,path:s,parity:a,taproot:o??null,cblock:l.hex,tapkey:f.hex,taptweak:u.hex}},encode_leaf_version:xd,encode_tapbranch:Ed,encode_tapleaf:bd,encode_tapscript:vd,encode_taptweak:kd,get_merkle_root:function(e){return Zd(e)[0]},merkleize:Zd,parse_cblock:Cd,parse_cblock_parity:jd,parse_pubkey_parity:Fd,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Rd(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=Cd(t);let o=vd(r,i.version).hex;for(const e of i.path)o=Ed(o,e).hex;const s=kd(i.int_key,o),u=Wt(i.int_key,s,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:u.hex,tweak:s.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:o}=Cd(n),s=g.join([r,e]);let u=g.bytes(t).hex;for(const e of i)u=Ed(u,e).hex;const c=Wt(o,kd(o,u),"ecdsa");return s.hex===c.hex}});var Ld=Object.freeze({__proto__:null,assert_witness:function(e){b.ok(Array.isArray(e),"witness must be an array"),b.ok(e.every(e=>g.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>g.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:Rd});return e.ADDRESS=fi,e.CONST=lr,e.META=lo,e.SCHEMA=jf,e.SCRIPT=po,e.SIGHASH=Bd,e.SIGNER=Ud,e.TAPROOT=Hd,e.TX=md,e.WITNESS=Ld,e}({});
|
|
12
|
+
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _n(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function yn(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function wn(e){if("function"!=typeof e)throw new Error("function expected");return!0}function vn(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function bn(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function En(e){if(!Array.isArray(e))throw new Error("array expected")}function xn(e,t){if(!yn(!0,t))throw new Error(`${e}: array of strings expected`)}function kn(e,t){if(!yn(!1,t))throw new Error(`${e}: array of numbers expected`)}function zn(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function On(e){const t="string"==typeof e?e.split(""):e,n=t.length;xn("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(En(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(En(t),t.map(t=>{vn("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Pn(e=""){return vn("join",e),{encode:t=>(xn("join.decode",t),t.join(e)),decode:t=>(vn("join.decode",t),t.split(e))}}function Sn(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(En(e),!e.length)return[];let r=0;const i=[],o=Array.from(e,e=>{if(bn(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,u=!0;for(let i=r;i<s;i++){const s=o[i],c=t*e,a=c+s;if(!Number.isSafeInteger(a)||c/t!==e||a-s!==c)throw new Error("convertRadix: carry overflow");const f=a/n;e=a%n;const d=Math.floor(f);if(o[i]=d,!Number.isSafeInteger(d)||d*n+e!==a)throw new Error("convertRadix: carry overflow");u&&(d?u=!1:r=i)}if(i.push(e),u)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}const An=(e,t)=>0===t?e:An(t,e%t),In=(e,t)=>e+(t-An(e,t)),$n=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Tn(e,t,n,r){if(En(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(In(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${In(t,n)}`);let i=0,o=0;const s=$n[t],u=$n[n]-1,c=[];for(const r of e){if(bn(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((i>>o-n&u)>>>0);const e=$n[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-o&u,!r&&o>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&c.push(i>>>0),c}function Bn(e,t=!1){if(bn(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(In(8,e)>32||In(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!_n(n))throw new Error("radix2.encode input should be Uint8Array");return Tn(Array.from(n),8,e,!t)},decode:n=>(kn("radix2.decode",n),Uint8Array.from(Tn(n,e,8,t)))}}function Nn(e){return wn(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const Un=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!_n(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>(e=>{if(vn("base64",e),e.length>0&&!/^[A-Za-z0-9=+/]+$/.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:"base64",lastChunkHandling:"strict"})})(e)}:zn(Bn(6),On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return bn(e),vn("padding",t),{encode(n){for(xn("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){xn("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),Pn("")),Zn=zn(Bn(6),On("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Pn("")),Rn=(Cn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",zn(function(e){return bn(e),{encode:t=>{if(!_n(t))throw new Error("radix.encode input should be Uint8Array");return Sn(Array.from(t),256,e)},decode:t=>(kn("radix.decode",t),Uint8Array.from(Sn(t,e,256)))}}(58),On(Cn),Pn("")));var Cn;const jn=e=>{return zn((n=t=>e(e(t)),bn(t=4),wn(n),{encode(e){if(!_n(e))throw new Error("checksum.encode: input should be Uint8Array");const r=n(e).slice(0,t),i=new Uint8Array(e.length+t);return i.set(e),i.set(r,e.length),i},decode(e){if(!_n(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),o=n(r).slice(0,t);for(let e=0;e<t;e++)if(o[e]!==i[e])throw new Error("Invalid checksum");return r}}),Rn);var t,n},Fn=zn(On("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Pn("")),Dn=[996825010,642813549,513874426,1027748829,705979059];function Hn(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Dn.length;e++)1==(t>>e&1)&&(n^=Dn[e]);return n}function Ln(e,t,n=1){const r=e.length;let i=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);i=Hn(i)^n>>5}i=Hn(i);for(let t=0;t<r;t++)i=Hn(i)^31&e.charCodeAt(t);for(let e of t)i=Hn(i)^e;for(let e=0;e<6;e++)i=Hn(i);return i^=n,Fn.encode(Tn([i%$n[30]],30,5,!1))}function Vn(e){const t="bech32"===e?1:734539939,n=Bn(5),r=n.decode,i=n.encode,o=Nn(r);function s(e,n,r=90){vn("bech32.encode prefix",e),_n(n)&&(n=Array.from(n)),kn("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const o=i+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);const s=e.toLowerCase(),u=Ln(s,n,t);return`${s}1${Fn.encode(n)}${u}`}function u(e,n=90){vn("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=i.lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=i.slice(0,o),u=i.slice(o+1);if(u.length<6)throw new Error("Data must be at least 6 characters long");const c=Fn.decode(u).slice(0,-6),a=Ln(s,c,t);if(!u.endsWith(a))throw new Error(`Invalid checksum in ${e}: expected "${a}"`);return{prefix:s,words:c}}return{encode:s,decode:u,encodeFromBytes:function(e,t){return s(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=u(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Nn(u),fromWords:r,fromWordsUnsafe:o,toWords:i}}const qn=Vn("bech32"),Kn=Vn("bech32m");var Mn,Wn,Gn,Yn,Xn;function Jn(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Qn(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new Error(`invalid words: ${String(e)}`)}!function(e){e.encode=e=>(b.is_u8a(e),jn(ne).encode(e)),e.decode=e=>(b.is_base58(e),jn(ne).decode(e))}(Mn||(Mn={})),function(e){e.encode=e=>(b.is_u8a(e),Un.encode(e)),e.decode=e=>(b.is_base64(e),Un.decode(e))}(Wn||(Wn={})),function(e){e.encode=e=>(b.is_u8a(e),Zn.encode(e)),e.decode=e=>(b.is_b64url(e),Zn.decode(e))}(Gn||(Gn={})),function(e){e.to_words=qn.toWords,e.to_bytes=qn.fromWords,e.encode=(e,t,n=!1)=>(Jn(e),Qn(t),qn.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),qn.decode(e,t))}(Yn||(Yn={})),function(e){e.to_words=Kn.toWords,e.to_bytes=Kn.fromWords,e.encode=(e,t,n=!1)=>(Jn(e),Qn(t),Kn.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Kn.decode(e,t))}(Xn||(Xn={}));const er={base58:/^[13mn2][a-km-zA-HJ-NP-Z1-9]{25,34}$/,bech32:/^(bc|tb|bcrt)1q[ac-hj-np-z02-9]{6,87}$/,bech32m:/^(bc|tb|bcrt)1p[ac-hj-np-z02-9]{6,87}$/},tr=0,nr=1;function rr(e){const t=function(e){for(const[t,n]of Object.entries(er))if(n.test(e))return t;return null}(e);if(null===t)throw new Error("unrecognized address format: "+t);if("base58"===t)return function(e){const t=Mn.decode(e),n=t.slice(1),r=t[0];return{data:n,format:"base58",version:r}}(e);if("bech32"===t)return function(e){const{prefix:t,words:n}=Yn.decode(e),[r,...i]=n;b.ok(r===tr,"bech32 version mismatch");return{data:Yn.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Xn.decode(e),[r,...i]=n;b.ok(r===nr,"bech32m version mismatch");return{data:Xn.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function ir(e){if("base58"===e.format)return function(e){b.ok("base58"===e.format,"encoding mismatch"),b.exists(e.version,"must specify a version");const t=g.join([e.version,e.data]);return Mn.encode(t)}(e);if("bech32"===e.format)return function(e){b.ok("bech32"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Yn.to_words(t);return Yn.encode(e.prefix,[tr,...n])}(e);if("bech32m"===e.format)return function(e){b.ok("bech32m"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Xn.to_words(t);return Xn.encode(e.prefix,[nr,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const or={TXID:"00".repeat(32),VOUT:4294967295},sr={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},ur=[192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,102,126,128,132,150,152,186,188,190],cr={P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",OPRETURN:"opreturn"},ar={[cr.P2PKH]:/^76a914[0-9a-f]{40}88ac$/i,[cr.P2SH]:/^a914[0-9a-f]{40}87$/i,[cr.P2WPKH]:/^0014[0-9a-f]{40}$/i,[cr.P2WSH]:/^0020[0-9a-f]{64}$/i,[cr.P2TR]:/^5120[0-9a-f]{64}$/i,[cr.OPRETURN]:/^6a[0-9a-f]{2,}$/i},fr=[1,2,3,129,130,131],dr=[0,...fr];var lr=Object.freeze({__proto__:null,COINBASE:or,DEFAULT:sr,LOCK_SCRIPT_REGEX:ar,LOCK_SCRIPT_TYPE:cr,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:fr,SIGHASH_TAPROOT:dr,SPEND_SCRIPT_TYPE:{P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",P2TS:"p2ts"},TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:ur,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});function hr(e){const t=g.bytes(e).hex;for(const[e,n]of Object.entries(ar))if(n.test(t))return e;return null}function pr(e){switch(g.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function mr(e){const t=g.bytes(e).hex;return ar.p2pkh.test(t)}function gr(e){const t=g.bytes(e).hex;return ar.p2sh.test(t)}function _r(e){const t=g.bytes(e).hex;return ar.p2wpkh.test(t)}function yr(e){const t=g.bytes(e).hex;return ar.p2wsh.test(t)}function wr(e){const t=g.bytes(e).hex;return ar.p2tr.test(t)}function vr(e,t){switch(t){case"p2pkh":return function(e){return{hex:"76a914"+e+"88ac",asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{hex:"a914"+e+"87",asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2wpkh":return function(e){return{hex:"0014"+e,asm:["OP_0",e]}}(e);case"p2wsh":return function(e){return{hex:"0020"+e,asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{hex:"5120"+e,asm:["OP_1",e]}}(e);default:throw new Error("unrecognized script type: "+t)}}const br=[["1","p2pkh","main",20,"base58",0],["3","p2sh","main",20,"base58",5],["m","p2pkh","testnet",20,"base58",111],["n","p2pkh","testnet",20,"base58",111],["2","p2sh","testnet",20,"base58",196],["m","p2pkh","regtest",20,"base58",111],["n","p2pkh","regtest",20,"base58",111],["2","p2sh","regtest",20,"base58",196],["bc","p2wpkh","main",20,"bech32",0],["tb","p2wpkh","testnet",20,"bech32",0],["bcrt","p2wpkh","regtest",20,"bech32",0],["bc","p2wsh","main",32,"bech32",0],["tb","p2wsh","testnet",32,"bech32",0],["bcrt","p2wsh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function Er(e,t){for(const[n,r,i,o,s,u]of br)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:o,format:s,version:u};return null}function xr(e){const t=rr(e);for(const[n,r,i,o,s,u]of br){if(s!==t.format)continue;if(o!==t.data.length)continue;if(u!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const c=g.uint(t.data).hex;return{data:c,script:vr(c,r),type:r,prefix:n,network:i,size:o,format:s,version:u}}throw new Error("address configuration is invalid")}const kr=cr.P2PKH;var zr;function Or(e,t="main"){return Ar(Pr(e),t)}function Pr(e){const t=g.bytes(e);b.size(t,33,"invalid pubkey size");return Sr(hn(t))}function Sr(e){return g.join(["76a914",e,"88ac"])}function Ar(e,t="main"){const n=$r(e),r=Er(t,kr);return b.exists(r,`unrecognized address config: ${kr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"base58",version:r.version})}function Ir(e){const t=xr(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${kr}`),t}function $r(e){const t=g.bytes(e);return b.ok(mr(e),"invalid p2pkh script"),t.slice(3,23)}!function(e){e.create_address=Or,e.create_script=Pr,e.encode_address=Ar,e.encode_script=Sr,e.decode_address=Ir,e.decode_script=$r}(zr||(zr={}));const Tr=cr.P2SH;var Br;function Nr(e,t="main"){return Rr(Zr(hn(g.bytes(e))),t)}function Ur(e){return Zr(hn(g.bytes(e)))}function Zr(e){return g.join(["a914",e,"87"])}function Rr(e,t="main"){const n=jr(e),r=Er(t,Tr);return b.exists(r,`unrecognized address config: ${Tr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"base58",version:r.version})}function Cr(e){const t=xr(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${Tr}`),t}function jr(e){b.ok(gr(e),"invalid p2sh script");return g.bytes(e).slice(2,22)}!function(e){e.create_address=Nr,e.create_script=Ur,e.encode_address=Rr,e.encode_script=Zr,e.decode_address=Cr,e.decode_script=jr}(Br||(Br={}));const Fr=cr.P2WPKH;var Dr;function Hr(e,t="main"){return qr(Lr(e),t)}function Lr(e){const t=g.bytes(e);b.size(t,33,"invalid pubkey size");return Vr(hn(t))}function Vr(e){return g.join(["0014",e])}function qr(e,t="main"){const n=Mr(e),r=Er(t,Fr);return b.exists(r,`unrecognized address config: ${Fr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"bech32",prefix:r.prefix})}function Kr(e){const t=xr(e);return b.ok("p2wpkh"===t.type,`address type mismatch: ${t.type} !== ${Fr}`),t}function Mr(e){b.ok(_r(e),"invalid p2wpkh script");return g.bytes(e).slice(2,22)}!function(e){e.create_address=Hr,e.create_script=Lr,e.encode_address=qr,e.encode_script=Vr,e.decode_address=Kr,e.decode_script=Mr}(Dr||(Dr={}));const Wr=cr.P2WSH;var Gr;function Yr(e,t="main"){return Qr(Xr(e),t)}function Xr(e){return Jr(pn(g.bytes(e)))}function Jr(e){return g.join(["0020",e])}function Qr(e,t="main"){const n=ti(e),r=Er(t,Wr);return b.exists(r,`unrecognized address config: ${Wr} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"bech32",prefix:r.prefix})}function ei(e){const t=xr(e);return b.ok("p2wsh"===t.type,`address type mismatch: ${t.type} !== ${Wr}`),t}function ti(e){b.ok(yr(e),"invalid p2wsh script");return g.bytes(e).slice(2,34)}!function(e){e.create_address=Yr,e.create_script=Xr,e.encode_address=Qr,e.encode_script=Jr,e.decode_address=ei,e.decode_script=ti}(Gr||(Gr={}));const ni=cr.P2TR;var ri;function ii(e,t="main"){return ui(oi(e),t)}function oi(e){const t=g.bytes(e);return b.size(t,32,"invalid pubkey size"),si(t)}function si(e){return g.join(["5120",e])}function ui(e,t="main"){const n=ai(e),r=Er(t,ni);return b.exists(r,`unrecognized address config: ${ni} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ir({data:n,format:"bech32m",prefix:r.prefix})}function ci(e){const t=xr(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${ni}`),t}function ai(e){b.ok(wr(e),"invalid p2tr script");return g.bytes(e).slice(2,34)}!function(e){e.create_address=ii,e.create_script=oi,e.encode_address=ui,e.encode_script=si,e.decode_address=ci,e.decode_script=ai}(ri||(ri={}));var fi=Object.freeze({__proto__:null,get P2PKH(){return zr},get P2SH(){return Br},get P2TR(){return ri},get P2WPKH(){return Dr},get P2WSH(){return Gr},get_address:function(e,t="main"){const n=g.bytes(e),r=hr(n);if(null===r)throw new Error("unknown locking script: "+n.hex);switch(r){case cr.P2PKH:return zr.encode_address(e,t);case cr.P2SH:return Br.encode_address(e,t);case cr.P2WPKH:return Dr.encode_address(e,t);case cr.P2WSH:return Gr.encode_address(e,t);case cr.P2TR:return ri.encode_address(e,t);default:throw new Error("unknown script type: "+r)}},parse_address:function(e){return xr(e)}});const di=5e8;var li,hi;function pi(e){switch(e.type){case"timelock":return b.ok(e.stamp>=di,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<di,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function mi(e){return isNaN(e)||e<=0?null:e<di?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function gi(e,t=0){return`${e}i${t}`}function _i(e){wi(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function yi(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function wi(e){if(!yi(e))throw new Error(`invalid inscription id: ${e}`)}function vi(e,t){return`${e}:${t}`}function bi(e){xi(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function Ei(e){return null!==e.match(/^\d+:\d+$/)}function xi(e){if(!Ei(e))throw new Error(`invalid rune id: ${e}`)}function ki(e,t){return`${e}:${t}`}function zi(e){Pi(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function Oi(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function Pi(e){if(!Oi(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=pi,e.decode=mi}(li||(li={})),function(e){e.outpoint={encode:ki,decode:zi,verify:Oi,assert:Pi},e.record_id={encode:gi,decode:_i,verify:yi,assert:wi},e.rune_id={encode:vi,decode:bi,verify:Ei,assert:xi}}(hi||(hi={}));const Si={OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_SUCCESS80:80,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_SUCCESS98:98,OP_IF:99,OP_NOTIF:100,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_SUCCESS126:126,OP_SUCCESS127:127,OP_SUCCESS128:128,OP_SUCCESS129:129,OP_SIZE:130,OP_SUCCESS131:131,OP_SUCCESS132:132,OP_SUCCESS133:133,OP_SUCCESS134:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_SUCCESS137:137,OP_SUCCESS138:138,OP_1ADD:139,OP_1SUB:140,OP_SUCCESS141:141,OP_SUCCESS142:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_SUCCESS149:149,OP_SUCCESS150:150,OP_SUCCESS151:151,OP_SUCCESS152:152,OP_SUCCESS153:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186};function Ai(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Si))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ii(e){for(const[t,n]of Object.entries(Si))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function $i(e){switch(!0){case 0===e:return"opcode";case e>=1&&e<=75:return"varint";case 76===e:return"pushdata1";case 77===e:return"pushdata2";case 78===e:return"pushdata4";case e<=254:return"opcode";default:throw new Error(`Invalid word range: ${e}`)}}function Ti(e){switch(!0){case"number"!=typeof e:return!1;case 0===e:return!0;case[].includes(e):return!1;case 75<e&&e<254:return!0;default:return!1}}const Bi=520;function Ni(e,t=!1){if(0===e.length)return g.num(0,1);const n=[];for(const t of e)n.push(Ui(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")):r}function Ui(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ii(e);return g.num(t,1)}t=g.is_hex(e)?g.hex(e):g.str(e)}else if("number"==typeof e)t=g.num(e);else{if(!(e instanceof Uint8Array))throw new Error("invalid word type:"+typeof e);t=new g(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>Bi){let e;e=Zi(t),e=e.map(e=>Ri(e)),t=g.join(e)}else t=Ri(t);return t}function Zi(e){const t=[],n=new _(e);for(;n.size>Bi;)t.push(n.read(Bi));return t.push(n.read(n.size)),t}function Ri(e){const t=Ci(e.length);return g.join([t,e])}function Ci(e){const t=g.num(76,1),n=g.num(77,1);switch(!0){case e<=75:return g.num(e);case e>75&&e<256:return g.join([t,g.num(e,1,"le")]);case e>=256&&e<=Bi:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function ji(e){const t=g.bytes(e);return{asm:Fi(t),hex:t.hex}}function Fi(e){const t=new _(e),n=[],r=t.size;let i,o,s,u=0;for(;u<r;)switch(i=t.read(1).num,o=$i(i),u++,o){case"varint":n.push(t.read(i).hex),u+=i;break;case"pushdata1":s=t.read(1).reverse().num,n.push(t.read(s).hex),u+=s+1;break;case"pushdata2":s=t.read(2).reverse().num,n.push(t.read(s).hex),u+=s+2;break;case"pushdata4":s=t.read(4).reverse().num,n.push(t.read(s).hex),u+=s+4;break;case"opcode":if(!Ti(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Ai(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Di(e){try{return Fi(e).length>0}catch{return!1}}const Hi=BigInt(0),Li=BigInt(1),Vi=BigInt(26);var qi;function Ki(e){const t=function(e){const t=Fi(e),n=t.findIndex(e=>"OP_0"===e);b.ok(-1!==n,"inscription envelope not found");const r=[];for(let e=n;e<t.length;e++){b.ok("OP_IF"===t[e+1],"OP_IF missing from envelope"),b.ok("6f7264"===t[e+2],"magic bytes missing from envelope");const n=t.findIndex(e=>"OP_ENDIF"===e);b.ok(-1!==n,"inscription envelope missing END_IF statement");const i=t.slice(e+3,n);r.push(i),e+=n}return r}(e);return t.map(Gi)}function Mi(e){return g.join(e.map(Wi))}function Wi(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=Xi(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=Xi(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=Qi(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=Qi(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=Hi;for(const e of t)e>="A"&&e<="Z"&&(n=n*Vi+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=Li,g.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return g.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=g.is_hex(e)?g.hex(e):g.str(e),n=new _(t),r=[];for(;n.size>0;)if(n.size>520){const e=n.read(520);r.push(e.hex)}else{const e=n.read(n.size);r.push(e.hex)}return r}(e.content);t.push("OP_0",...n)}return t.push("OP_ENDIF"),Ni(t)}function Gi(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=to(e[n+1]),n+=1;break;case"OP_2":t.pointer=eo(e[n+1]),n+=1;break;case"OP_3":t.parent=Ji(e[n+1]),n+=1;break;case"OP_11":t.delegate=Ji(e[n+1]),n+=1;break;case"OP_13":t.rune=ro(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=Yi(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=eo(e[n+1]),n+=1;break;case"OP_0":return t.content=no(e.slice(n+1)),t}return t}function Yi(e){return g.bytes(e).hex}function Xi(e){b.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=g.hex(t[0]),r=Number(t[1]),i=n.reverse().hex;return 0!==r?i+g.num(r).hex:i}function Ji(e){const t=g.bytes(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function Qi(e){return g.num(e).reverse().hex}function eo(e){return g.bytes(e).reverse().num}function to(e){return g.bytes(e).str}function no(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function ro(e){let t=g.bytes(e).reverse().big;t+=Li;let n="";for(;t>Hi;){const e=t%Vi;if(e===Hi)n="Z"+n,t=t/Vi-Li;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=Vi}}return n}!function(e){e.encode=Mi,e.decode=Ki}(qi||(qi={}));const io=4194304,oo=65535,so=65535;var uo;function co(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>so)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&oo)>>>0}if("stamp"===e.mode){const t=function(e){if(void 0===e||!Number.isInteger(e))throw new Error("timestamp must be a number");const t=Math.floor(e/512);if(!Number.isInteger(t)||t<0||t>so)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(io|t&oo)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function ao(e){const t=function(e){const t="string"==typeof e?parseInt(e,16):e;if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`invalid sequence value: ${t}`);return t}(e);if(2147483648&t)return null;const n=t&oo;if(t&io){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>so)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=co,e.decode=ao}(uo||(uo={}));var fo,lo=Object.freeze({__proto__:null,get InscriptionUtil(){return qi},get LocktimeField(){return li},get RefPointer(){return hi},get SequenceField(){return uo},decode_inscription:Ki,decode_locktime:mi,decode_sequence:ao,encode_inscription:Mi,encode_locktime:pi,encode_sequence:co});function ho(e){return g.bytes(e).prefix_varint("le").hex}!function(e){e.parse=ji,e.decode=Fi,e.encode=Ni,e.is_valid=Di}(fo||(fo={}));var po=Object.freeze({__proto__:null,OPCODE_MAP:Si,get ScriptUtil(){return fo},decode_script:Fi,encode_script:Ni,encode_script_word:Ui,get_asm_code:Ii,get_lock_script_info:function(e){return{type:hr(e),version:pr(e)}},get_lock_script_type:hr,get_lock_script_version:pr,get_op_code:Ai,get_op_type:$i,get_size_varint:Ci,is_opreturn_script:function(e){const t=g.bytes(e).hex;return ar.opreturn.test(t)},is_p2pkh_script:mr,is_p2sh_script:gr,is_p2tr_script:wr,is_p2wpkh_script:_r,is_p2wsh_script:yr,is_return_script:function(e){return 106===g.bytes(e).at(0)},is_valid_op:Ti,is_valid_script:Di,parse_script:ji,parse_script_pubkeys:function(e){return[...("string"==typeof e?e:g.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])},prefix_script_size:ho,prefix_word_size:Ri,split_script_word:Zi});function mo(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function go(e,t){let{txindex:n,txinput:r}=t??{};if(void 0!==n){if(n>=e.vin.length)throw new Error("Input index out of bounds: "+String(n));r=e.vin.at(n)}return b.ok(void 0!==r),r}function _o(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return pn(g.hex(t).prefix_varint("be"))}}function yo(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new _(e),r=function(e){return e.read(4).reverse().to_num()}(n);let i=function(e){const[t,n]=[...e.peek(2)];if(0===t){if(e.read(2),1===n)return!0;throw new Error(`Invalid witness flag: ${n}`)}return!1}(n);i=!!t&&i;const o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=wo(e);t.push(n)}return t}(n),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(vo(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${w(e)}`)}return t}(n);if(i)for(const e of o)e.witness=bo(n);const u=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:o,vout:s,locktime:u}}function wo(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=Eo(e),i=e.read(4).reverse().num,o=[];return t===or.TXID&&n===or.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:o}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:o}}function vo(e){const t=e.read(8).reverse().big,n=Eo(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function bo(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Eo(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function Eo(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function xo(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(const e in s.prototype)e in n||Object.defineProperty(n,e,{value:s.prototype[e].bind(n)});n._zod.constr=s,n._zod.def=r}const i=n?.Parent??Object;class o extends i{}function s(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"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 ko extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class zo extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const Oo={};function Po(e){return Oo}function So(e,t){return"bigint"==typeof t?t.toString():t}function Ao(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Io(e){return null==e}function $o(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const To=Symbol("evaluating");function Bo(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==To)return void 0===r&&(r=To,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function No(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Uo(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Zo(e){return JSON.stringify(e)}const Ro="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Co(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const jo=Ao(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Fo(e){if(!1===Co(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!1!==Co(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function Do(e){return Fo(e)?{...e}:e}const Ho=new Set(["string","number","symbol"]);function Lo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Vo(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function qo(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 Ko={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 Mo(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 Wo(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Go(e){return"string"==typeof e?e:e?.message}function Yo(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=Go(e.inst?._zod.def?.error?.(e))??Go(t?.error?.(e))??Go(n.customError?.(e))??Go(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Xo(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Jo(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const Qo=(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,So,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},es=xo("$ZodError",Qo),ts=xo("$ZodError",Qo,{Parent:Error});const ns=e=>(t,n,r,i)=>{const o=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new ko;if(s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Yo(e,o,Po())));throw Ro(t,i?.callee),t}return s.value},rs=e=>async(t,n,r,i)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Yo(e,o,Po())));throw Ro(t,i?.callee),t}return s.value},is=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new ko;return o.issues.length?{success:!1,error:new(e??es)(o.issues.map(e=>Yo(e,i,Po())))}:{success:!0,data:o.value}},os=is(ts),ss=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(e=>Yo(e,i,Po())))}:{success:!0,data:o.value}},us=ss(ts),cs=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ns(e)(t,n,i)},as=e=>(t,n,r)=>ns(e)(t,n,r),fs=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return rs(e)(t,n,i)},ds=e=>async(t,n,r)=>rs(e)(t,n,r),ls=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return is(e)(t,n,i)},hs=e=>(t,n,r)=>is(e)(t,n,r),ps=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ss(e)(t,n,i)},ms=e=>async(t,n,r)=>ss(e)(t,n,r),gs=/^[cC][^\s-]{8,}$/,_s=/^[0-9a-z]+$/,ys=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ws=/^[0-9a-vA-V]{20}$/,vs=/^[A-Za-z0-9]{27}$/,bs=/^[a-zA-Z0-9_-]{21}$/,Es=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,xs=/^([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})$/,ks=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)$/,zs=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const Os=/^(?:(?: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])$/,Ps=/^(([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})$/,Ss=/^((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])$/,As=/^(([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])$/,Is=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,$s=/^[A-Za-z0-9_-]*$/,Ts=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,Bs=/^\+(?:[0-9]){6,14}[0-9]$/,Ns="(?:(?:\\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])))",Us=new RegExp(`^${Ns}$`);function Zs(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 Rs=/^\d+n?$/,Cs=/^\d+$/,js=/^-?\d+(?:\.\d+)?/i,Fs=/true|false/i,Ds=/null/i,Hs=/^[^A-Z]*$/,Ls=/^[^a-z]*$/,Vs=xo("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),qs={number:"number",bigint:"bigint",object:"date"},Ks=xo("$ZodCheckLessThan",(e,t)=>{Vs.init(e,t);const n=qs[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:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ms=xo("$ZodCheckGreaterThan",(e,t)=>{Vs.init(e,t);const n=qs[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:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ws=xo("$ZodCheckMultipleOf",(e,t)=>{Vs.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.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(0===i&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}const o=n>i?n:i;return Number.parseInt(e.toFixed(o).replace(".",""))%Number.parseInt(t.toFixed(o).replace(".",""))/10**o}(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})}}),Gs=xo("$ZodCheckNumberFormat",(e,t)=>{Vs.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=Ko[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=Cs)}),e._zod.check=s=>{const u=s.value;if(n){if(!Number.isInteger(u))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:u,inst:e});if(!Number.isSafeInteger(u))return void(u>0?s.issues.push({input:u,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):s.issues.push({input:u,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}))}u<i&&s.issues.push({origin:"number",input:u,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),u>o&&s.issues.push({origin:"number",input:u,code:"too_big",maximum:o,inst:e})}}),Ys=xo("$ZodCheckMaxLength",(e,t)=>{var n;Vs.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Io(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 i=Xo(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Xs=xo("$ZodCheckMinLength",(e,t)=>{var n;Vs.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Io(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 i=Xo(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Js=xo("$ZodCheckLengthEquals",(e,t)=>{var n;Vs.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!Io(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,i=r.length;if(i===t.length)return;const o=Xo(r),s=i>t.length;n.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Qs=xo("$ZodCheckStringFormat",(e,t)=>{var n,r;Vs.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=()=>{})}),eu=xo("$ZodCheckRegex",(e,t)=>{Qs.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})}}),tu=xo("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Hs),Qs.init(e,t)}),nu=xo("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Ls),Qs.init(e,t)}),ru=xo("$ZodCheckIncludes",(e,t)=>{Vs.init(e,t);const n=Lo(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})}}),iu=xo("$ZodCheckStartsWith",(e,t)=>{Vs.init(e,t);const n=new RegExp(`^${Lo(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})}}),ou=xo("$ZodCheckEndsWith",(e,t)=>{Vs.init(e,t);const n=new RegExp(`.*${Lo(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})}}),su=xo("$ZodCheckOverwrite",(e,t)=>{Vs.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class uu{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 cu={major:4,minor:1,patch:5},au=xo("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=cu;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,i=Mo(e);for(const o of t){if(o._zod.def.when){if(!o._zod.def.when(e))continue}else if(i)continue;const t=e.issues.length,s=o._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new ko;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(i||(i=Mo(e,t)))});else{if(e.issues.length===t)continue;i||(i=Mo(e,t))}}return r?r.then(()=>e):e},n=(n,i,o)=>{if(Mo(n))return n.aborted=!0,n;const s=t(i,r,o);if(s instanceof Promise){if(!1===o.async)throw new ko;return s.then(t=>e._zod.parse(t,o))}return e._zod.parse(s,o)};e._zod.run=(i,o)=>{if(o.skipChecks)return e._zod.parse(i,o);if("backward"===o.direction){const t=e._zod.parse({value:i.value,issues:[]},{...o,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,o)):n(t,i,o)}const s=e._zod.parse(i,o);if(s instanceof Promise){if(!1===o.async)throw new ko;return s.then(e=>t(e,r,o))}return t(s,r,o)}}e["~standard"]={validate:t=>{try{const n=os(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return us(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}}),fu=xo("$ZodString",(e,t)=>{var n;au.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}}),du=xo("$ZodStringFormat",(e,t)=>{Qs.init(e,t),fu.init(e,t)}),lu=xo("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=xs),du.init(e,t)}),hu=xo("$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=ks(e))}else t.pattern??(t.pattern=ks());du.init(e,t)}),pu=xo("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=zs),du.init(e,t)}),mu=xo("$ZodURL",(e,t)=>{du.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:Ts.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.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=i.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),gu=xo("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),du.init(e,t)}),_u=xo("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=bs),du.init(e,t)}),yu=xo("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=gs),du.init(e,t)}),wu=xo("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=_s),du.init(e,t)}),vu=xo("$ZodULID",(e,t)=>{t.pattern??(t.pattern=ys),du.init(e,t)}),bu=xo("$ZodXID",(e,t)=>{t.pattern??(t.pattern=ws),du.init(e,t)}),Eu=xo("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=vs),du.init(e,t)}),xu=xo("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=Zs({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(`^${Ns}T(?:${r})$`)}(t)),du.init(e,t)}),ku=xo("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Us),du.init(e,t)}),zu=xo("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${Zs(t)}$`)),du.init(e,t)}),Ou=xo("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Es),du.init(e,t)}),Pu=xo("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Os),du.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.format="ipv4"})}),Su=xo("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Ps),du.init(e,t),e._zod.onattach.push(e=>{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})}}}),Au=xo("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Ss),du.init(e,t)}),Iu=xo("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=As),du.init(e,t),e._zod.check=n=>{const[r,i]=n.value.split("/");try{if(!i)throw new Error;const e=Number(i);if(`${e}`!==i)throw new Error;if(e<0||e>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function $u(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Tu=xo("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Is),du.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64"}),e._zod.check=n=>{$u(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const Bu=xo("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=$s),du.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64url"}),e._zod.check=n=>{(function(e){if(!$s.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return $u(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})}}),Nu=xo("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Bs),du.init(e,t)});const Uu=xo("$ZodJWT",(e,t)=>{du.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 i=JSON.parse(atob(r));return!("typ"in i&&"JWT"!==i?.typ||!i.alg||t&&(!("alg"in i)||i.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})}}),Zu=xo("$ZodNumber",(e,t)=>{au.init(e,t),e._zod.pattern=e._zod.bag.pattern??js,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const i=n.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}}),Ru=xo("$ZodNumber",(e,t)=>{Gs.init(e,t),Zu.init(e,t)}),Cu=xo("$ZodBoolean",(e,t)=>{au.init(e,t),e._zod.pattern=Fs,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const i=n.value;return"boolean"==typeof i||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),ju=xo("$ZodBigInt",(e,t)=>{au.init(e,t),e._zod.pattern=Rs,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}}),Fu=xo("$ZodNull",(e,t)=>{au.init(e,t),e._zod.pattern=Ds,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}}),Du=xo("$ZodAny",(e,t)=>{au.init(e,t),e._zod.parse=e=>e}),Hu=xo("$ZodUnknown",(e,t)=>{au.init(e,t),e._zod.parse=e=>e}),Lu=xo("$ZodNever",(e,t)=>{au.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)}),Vu=xo("$ZodDate",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=new Date(n.value)}catch(e){}const i=n.value,o=i instanceof Date;return o&&!Number.isNaN(i.getTime())||n.issues.push({expected:"date",code:"invalid_type",input:i,...o?{received:"Invalid Date"}:{},inst:e}),n}});function qu(e,t,n){e.issues.length&&t.issues.push(...Wo(n,e.issues)),t.value[n]=e.value}const Ku=xo("$ZodArray",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const o=[];for(let e=0;e<i.length;e++){const s=i[e],u=t.element._zod.run({value:s,issues:[]},r);u instanceof Promise?o.push(u.then(t=>qu(t,n,e))):qu(u,n,e)}return o.length?Promise.all(o).then(()=>n):n}});function Mu(e,t,n,r){e.issues.length&&t.issues.push(...Wo(n,e.issues)),void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Wu(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 Gu(e,t,n,r,i,o){const s=[],u=i.keySet,c=i.catchall._zod,a=c.def.type;for(const i of Object.keys(t)){if(u.has(i))continue;if("never"===a){s.push(i);continue}const o=c.run({value:t[i],issues:[]},r);o instanceof Promise?e.push(o.then(e=>Mu(e,n,i,t))):Mu(o,n,i,t)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}const Yu=xo("$ZodObject",(e,t)=>{au.init(e,t);const n=Ao(()=>Wu(t));Bo(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 r=Co,i=t.catchall;let o;e._zod.parse=(t,s)=>{o??(o=n.value);const u=t.value;if(!r(u))return t.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),t;t.value={};const c=[],a=o.shape;for(const e of o.keys){const n=a[e]._zod.run({value:u[e],issues:[]},s);n instanceof Promise?c.push(n.then(n=>Mu(n,t,e,u))):Mu(n,t,e,u)}return i?Gu(c,u,t,s,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Xu=xo("$ZodObjectJIT",(e,t)=>{Yu.init(e,t);const n=e._zod.parse,r=Ao(()=>Wu(t));let i;const o=Co,s=!Oo.jitless,u=s&&jo.value,c=t.catchall;let a;e._zod.parse=(f,d)=>{a??(a=r.value);const l=f.value;return o(l)?s&&u&&!1===d?.async&&!0!==d.jitless?(i||(i=(e=>{const t=new uu(["shape","payload","ctx"]),n=r.value,i=e=>{const t=Zo(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const o=Object.create(null);let s=0;for(const e of n.keys)o[e]="key_"+s++;t.write("const newResult = {}");for(const e of n.keys){const n=o[e],r=Zo(e);t.write(`const ${n} = ${i(e)};`),t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${r}, ...iss.path] : [${r}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${r} in input) {\n newResult[${r}] = undefined;\n }\n } else {\n newResult[${r}] = ${n}.value;\n }\n `)}t.write("payload.value = newResult;"),t.write("return payload;");const u=t.compile();return(t,n)=>u(e,t,n)})(t.shape)),f=i(f,d),c?Gu([],l,f,d,a,e):f):n(f,d):(f.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),f)}});function Ju(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const i=e.filter(e=>!Mo(e));return 1===i.length?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Yo(e,r,Po())))}),t)}const Qu=xo("$ZodUnion",(e,t)=>{au.init(e,t),Bo(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),Bo(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),Bo(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Bo(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=>$o(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(i,o)=>{if(n)return r(i,o);let s=!1;const u=[];for(const e of t.options){const t=e._zod.run({value:i.value,issues:[]},o);if(t instanceof Promise)u.push(t),s=!0;else{if(0===t.issues.length)return t;u.push(t)}}return s?Promise.all(u).then(t=>Ju(t,i,e,o)):Ju(u,i,e,o)}}),ec=xo("$ZodIntersection",(e,t)=>{au.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,i=t.left._zod.run({value:r,issues:[]},n),o=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([t,n])=>nc(e,t,n)):nc(e,i,o)}});function tc(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(Fo(e)&&Fo(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=tc(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=tc(e[r],t[r]);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function nc(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Mo(e))return e;const r=tc(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const rc=xo("$ZodRecord",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Fo(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const o=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){const s=t.valueType._zod.run({value:i[e],issues:[]},r);s instanceof Promise?o.push(s.then(t=>{t.issues.length&&n.issues.push(...Wo(e,t.issues)),n.value[e]=t.value})):(s.issues.length&&n.issues.push(...Wo(e,s.issues)),n.value[e]=s.value)}let u;for(const e in i)s.has(e)||(u=u??[],u.push(e));u&&u.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:u})}else{n.value={};for(const s of Reflect.ownKeys(i)){if("__proto__"===s)continue;const u=t.keyType._zod.run({value:s,issues:[]},r);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(u.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:u.issues.map(e=>Yo(e,r,Po())),input:s,path:[s],inst:e}),n.value[u.value]=u.value;continue}const c=t.valueType._zod.run({value:i[s],issues:[]},r);c instanceof Promise?o.push(c.then(e=>{e.issues.length&&n.issues.push(...Wo(s,e.issues)),n.value[u.value]=e.value})):(c.issues.length&&n.issues.push(...Wo(s,c.issues)),n.value[u.value]=c.value)}}return o.length?Promise.all(o).then(()=>n):n}}),ic=xo("$ZodEnum",(e,t)=>{au.init(e,t);const n=function(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)}(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>Ho.has(typeof e)).map(e=>"string"==typeof e?Lo(e):e.toString()).join("|")})$`),e._zod.parse=(t,i)=>{const o=t.value;return r.has(o)||t.issues.push({code:"invalid_value",values:n,input:o,inst:e}),t}}),oc=xo("$ZodTransform",(e,t)=>{au.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new zo(e.constructor.name);const i=t.transform(n.value,n);if(r.async){return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n))}if(i instanceof Promise)throw new ko;return n.value=i,n}});function sc(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const uc=xo("$ZodOptional",(e,t)=>{au.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Bo(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Bo(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${$o(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>sc(t,e.value)):sc(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),cc=xo("$ZodNullable",(e,t)=>{au.init(e,t),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(e._zod,"optout",()=>t.innerType._zod.optout),Bo(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${$o(e.source)}|null)$`):void 0}),Bo(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)}),ac=xo("$ZodDefault",(e,t)=>{au.init(e,t),e._zod.optin="optional",Bo(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=>fc(e,t)):fc(r,t)}});function fc(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const dc=xo("$ZodPrefault",(e,t)=>{au.init(e,t),e._zod.optin="optional",Bo(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))}),lc=xo("$ZodNonOptional",(e,t)=>{au.init(e,t),Bo(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 i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>hc(t,e)):hc(i,e)}});function hc(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 pc=xo("$ZodCatch",(e,t)=>{au.init(e,t),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(e._zod,"optout",()=>t.innerType._zod.optout),Bo(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=>Yo(e,n,Po()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Yo(e,n,Po()))},input:e.value}),e.issues=[]),e)}}),mc=xo("$ZodPipe",(e,t)=>{au.init(e,t),Bo(e._zod,"values",()=>t.in._zod.values),Bo(e._zod,"optin",()=>t.in._zod.optin),Bo(e._zod,"optout",()=>t.out._zod.optout),Bo(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=>gc(e,t.in,n)):gc(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>gc(e,t.out,n)):gc(r,t.out,n)}});function gc(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const _c=xo("$ZodReadonly",(e,t)=>{au.init(e,t),Bo(e._zod,"propValues",()=>t.innerType._zod.propValues),Bo(e._zod,"values",()=>t.innerType._zod.values),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(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(yc):yc(r)}});function yc(e){return e.value=Object.freeze(e.value),e}const wc=xo("$ZodLazy",(e,t)=>{au.init(e,t),Bo(e._zod,"innerType",()=>t.getter()),Bo(e._zod,"pattern",()=>e._zod.innerType._zod.pattern),Bo(e._zod,"propValues",()=>e._zod.innerType._zod.propValues),Bo(e._zod,"optin",()=>e._zod.innerType._zod.optin??void 0),Bo(e._zod,"optout",()=>e._zod.innerType._zod.optout??void 0),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),vc=xo("$ZodCustom",(e,t)=>{Vs.init(e,t),au.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>bc(t,n,r,e));bc(i,n,r,e)}});function bc(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(Jo(e))}}class Ec{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){const n=t[0];if(this._map.set(e,n),n&&"object"==typeof n&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,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)}}function xc(){return new Ec}const kc=xc();function zc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...qo(t)})}function Oc(e,t){return new Ks({check:"less_than",...qo(t),value:e,inclusive:!1})}function Pc(e,t){return new Ks({check:"less_than",...qo(t),value:e,inclusive:!0})}function Sc(e,t){return new Ms({check:"greater_than",...qo(t),value:e,inclusive:!1})}function Ac(e,t){return new Ms({check:"greater_than",...qo(t),value:e,inclusive:!0})}function Ic(e,t){return new Ws({check:"multiple_of",...qo(t),value:e})}function $c(e,t){return new Ys({check:"max_length",...qo(t),maximum:e})}function Tc(e,t){return new Xs({check:"min_length",...qo(t),minimum:e})}function Bc(e,t){return new Js({check:"length_equals",...qo(t),length:e})}function Nc(e){return new su({check:"overwrite",tx:e})}function Uc(e){const t=function(e,t){const n=new Vs({check:"custom",...qo(t)});return n._zod.check=e,n}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Jo(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Jo(r))}},e(n.value,n)));return t}const Zc=xo("ZodISODateTime",(e,t)=>{xu.init(e,t),ua.init(e,t)});function Rc(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...qo(t)})}(Zc,e)}const Cc=xo("ZodISODate",(e,t)=>{ku.init(e,t),ua.init(e,t)});function jc(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...qo(t)})}(Cc,e)}const Fc=xo("ZodISOTime",(e,t)=>{zu.init(e,t),ua.init(e,t)});function Dc(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...qo(t)})}(Fc,e)}const Hc=xo("ZodISODuration",(e,t)=>{Ou.init(e,t),ua.init(e,t)});function Lc(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...qo(t)})}(Hc,e)}const Vc=xo("ZodError",(e,t)=>{es.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t){const n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(const t of e.issues)if("invalid_union"===t.code&&t.errors.length)t.errors.map(e=>i({issues:e}));else if("invalid_key"===t.code)i({issues:t.issues});else if("invalid_element"===t.code)i({issues:t.issues});else if(0===t.path.length)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){const r=t.path[i];i===t.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,So,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,So,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),qc=ns(Vc),Kc=rs(Vc),Mc=is(Vc),Wc=ss(Vc),Gc=cs(Vc),Yc=as(Vc),Xc=fs(Vc),Jc=ds(Vc),Qc=ls(Vc),ea=hs(Vc),ta=ps(Vc),na=ms(Vc),ra=xo("ZodType",(e,t)=>(au.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),e.clone=(t,n)=>Vo(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>qc(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Mc(e,t,n),e.parseAsync=async(t,n)=>Kc(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Wc(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Gc(e,t,n),e.decode=(t,n)=>Yc(e,t,n),e.encodeAsync=async(t,n)=>Xc(e,t,n),e.decodeAsync=async(t,n)=>Jc(e,t,n),e.safeEncode=(t,n)=>Qc(e,t,n),e.safeDecode=(t,n)=>ea(e,t,n),e.safeEncodeAsync=async(t,n)=>ta(e,t,n),e.safeDecodeAsync=async(t,n)=>na(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...qo(n)})}(lf,e,t)}(t,n)),e.superRefine=t=>e.check(Uc(t)),e.overwrite=t=>e.check(Nc(t)),e.optional=()=>ef(e),e.nullable=()=>nf(e),e.nullish=()=>ef(nf(e)),e.nonoptional=t=>function(e,t){return new sf({type:"nonoptional",innerType:e,...qo(t)})}(e,t),e.array=()=>La(e),e.or=t=>Ma([e,t]),e.and=t=>new Wa({type:"intersection",left:e,right:t}),e.transform=t=>af(e,new Ja({type:"transform",transform:t})),e.default=t=>{return n=t,new rf({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():Do(n)}});var n},e.prefault=t=>{return n=t,new of({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():Do(n)}});var n},e.catch=t=>{return new uf({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>af(e,t),e.readonly=()=>new ff({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return kc.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>kc.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return kc.get(e);const n=e.clone();return kc.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),ia=xo("_ZodString",(e,t)=>{fu.init(e,t),ra.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new eu({check:"string_format",format:"regex",...qo(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new ru({check:"string_format",format:"includes",...qo(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new iu({check:"string_format",format:"starts_with",...qo(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new ou({check:"string_format",format:"ends_with",...qo(t),suffix:e})}(...t)),e.min=(...t)=>e.check(Tc(...t)),e.max=(...t)=>e.check($c(...t)),e.length=(...t)=>e.check(Bc(...t)),e.nonempty=(...t)=>e.check(Tc(1,...t)),e.lowercase=t=>e.check(function(e){return new tu({check:"string_format",format:"lowercase",...qo(e)})}(t)),e.uppercase=t=>e.check(function(e){return new nu({check:"string_format",format:"uppercase",...qo(e)})}(t)),e.trim=()=>e.check(Nc(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return Nc(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(Nc(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(Nc(e=>e.toUpperCase()))}),oa=xo("ZodString",(e,t)=>{fu.init(e,t),ia.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...qo(t)})}(ca,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...qo(t)})}(da,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...qo(t)})}(Oa,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...qo(t)})}(la,t)),e.guid=t=>e.check(zc(aa,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...qo(t)})}(fa,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...qo(t)})}(fa,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...qo(t)})}(fa,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...qo(t)})}(fa,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...qo(t)})}(ha,t)),e.guid=t=>e.check(zc(aa,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...qo(t)})}(pa,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...qo(t)})}(ma,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...qo(t)})}(ga,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...qo(t)})}(xa,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...qo(t)})}(ka,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...qo(t)})}(_a,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...qo(t)})}(ya,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...qo(t)})}(wa,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...qo(t)})}(va,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...qo(t)})}(ba,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...qo(t)})}(Ea,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...qo(t)})}(za,t)),e.datetime=t=>e.check(Rc(t)),e.date=t=>e.check(jc(t)),e.time=t=>e.check(Dc(t)),e.duration=t=>e.check(Lc(t))});function sa(e){return function(e,t){return new e({type:"string",...qo(t)})}(oa,e)}const ua=xo("ZodStringFormat",(e,t)=>{du.init(e,t),ia.init(e,t)}),ca=xo("ZodEmail",(e,t)=>{pu.init(e,t),ua.init(e,t)}),aa=xo("ZodGUID",(e,t)=>{lu.init(e,t),ua.init(e,t)}),fa=xo("ZodUUID",(e,t)=>{hu.init(e,t),ua.init(e,t)}),da=xo("ZodURL",(e,t)=>{mu.init(e,t),ua.init(e,t)}),la=xo("ZodEmoji",(e,t)=>{gu.init(e,t),ua.init(e,t)}),ha=xo("ZodNanoID",(e,t)=>{_u.init(e,t),ua.init(e,t)}),pa=xo("ZodCUID",(e,t)=>{yu.init(e,t),ua.init(e,t)}),ma=xo("ZodCUID2",(e,t)=>{wu.init(e,t),ua.init(e,t)}),ga=xo("ZodULID",(e,t)=>{vu.init(e,t),ua.init(e,t)}),_a=xo("ZodXID",(e,t)=>{bu.init(e,t),ua.init(e,t)}),ya=xo("ZodKSUID",(e,t)=>{Eu.init(e,t),ua.init(e,t)}),wa=xo("ZodIPv4",(e,t)=>{Pu.init(e,t),ua.init(e,t)}),va=xo("ZodIPv6",(e,t)=>{Su.init(e,t),ua.init(e,t)}),ba=xo("ZodCIDRv4",(e,t)=>{Au.init(e,t),ua.init(e,t)}),Ea=xo("ZodCIDRv6",(e,t)=>{Iu.init(e,t),ua.init(e,t)}),xa=xo("ZodBase64",(e,t)=>{Tu.init(e,t),ua.init(e,t)}),ka=xo("ZodBase64URL",(e,t)=>{Bu.init(e,t),ua.init(e,t)}),za=xo("ZodE164",(e,t)=>{Nu.init(e,t),ua.init(e,t)}),Oa=xo("ZodJWT",(e,t)=>{Uu.init(e,t),ua.init(e,t)}),Pa=xo("ZodNumber",(e,t)=>{Zu.init(e,t),ra.init(e,t),e.gt=(t,n)=>e.check(Sc(t,n)),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.lt=(t,n)=>e.check(Oc(t,n)),e.lte=(t,n)=>e.check(Pc(t,n)),e.max=(t,n)=>e.check(Pc(t,n)),e.int=t=>e.check(Ia(t)),e.safe=t=>e.check(Ia(t)),e.positive=t=>e.check(Sc(0,t)),e.nonnegative=t=>e.check(Ac(0,t)),e.negative=t=>e.check(Oc(0,t)),e.nonpositive=t=>e.check(Pc(0,t)),e.multipleOf=(t,n)=>e.check(Ic(t,n)),e.step=(t,n)=>e.check(Ic(t,n)),e.finite=()=>e;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 Sa(e){return function(e,t){return new e({type:"number",checks:[],...qo(t)})}(Pa,e)}const Aa=xo("ZodNumberFormat",(e,t)=>{Ru.init(e,t),Pa.init(e,t)});function Ia(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...qo(t)})}(Aa,e)}const $a=xo("ZodBoolean",(e,t)=>{Cu.init(e,t),ra.init(e,t)});function Ta(e){return function(e,t){return new e({type:"boolean",...qo(t)})}($a,e)}const Ba=xo("ZodBigInt",(e,t)=>{ju.init(e,t),ra.init(e,t),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.gt=(t,n)=>e.check(Sc(t,n)),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.lt=(t,n)=>e.check(Oc(t,n)),e.lte=(t,n)=>e.check(Pc(t,n)),e.max=(t,n)=>e.check(Pc(t,n)),e.positive=t=>e.check(Sc(BigInt(0),t)),e.negative=t=>e.check(Oc(BigInt(0),t)),e.nonpositive=t=>e.check(Pc(BigInt(0),t)),e.nonnegative=t=>e.check(Ac(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Ic(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});function Na(e){return function(e,t){return new e({type:"bigint",...qo(t)})}(Ba,e)}const Ua=xo("ZodNull",(e,t)=>{Fu.init(e,t),ra.init(e,t)});const Za=xo("ZodAny",(e,t)=>{Du.init(e,t),ra.init(e,t)});const Ra=xo("ZodUnknown",(e,t)=>{Hu.init(e,t),ra.init(e,t)});function Ca(){return new Ra({type:"unknown"})}const ja=xo("ZodNever",(e,t)=>{Lu.init(e,t),ra.init(e,t)});function Fa(e){return function(e,t){return new e({type:"never",...qo(t)})}(ja,e)}const Da=xo("ZodDate",(e,t)=>{Vu.init(e,t),ra.init(e,t),e.min=(t,n)=>e.check(Ac(t,n)),e.max=(t,n)=>e.check(Pc(t,n));const n=e._zod.bag;e.minDate=n.minimum?new Date(n.minimum):null,e.maxDate=n.maximum?new Date(n.maximum):null});const Ha=xo("ZodArray",(e,t)=>{Ku.init(e,t),ra.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Tc(t,n)),e.nonempty=t=>e.check(Tc(1,t)),e.max=(t,n)=>e.check($c(t,n)),e.length=(t,n)=>e.check(Bc(t,n)),e.unwrap=()=>e.element});function La(e,t){return function(e,t,n){return new e({type:"array",element:t,...qo(n)})}(Ha,e,t)}const Va=xo("ZodObject",(e,t)=>{Xu.init(e,t),ra.init(e,t),Bo(e,"shape",()=>t.shape),e.keyof=()=>function(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Xa({type:"enum",entries:n,...qo(t)})}(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ca()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ca()}),e.strict=()=>e.clone({...e._zod.def,catchall:Fa()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!Fo(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const r=Uo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return No(this,"shape",n),n},checks:[]});return Vo(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!Fo(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n={...e._zod.def,get shape(){const n={...e._zod.def.shape,...t};return No(this,"shape",n),n},checks:e._zod.def.checks};return Vo(e,n)}(e,t),e.merge=t=>function(e,t){const n=Uo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return No(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return Vo(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def;return Vo(e,Uo(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 No(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(e,t){const n=e._zod.def,r=Uo(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 No(this,"shape",r),r},checks:[]});return Vo(e,r)}(e,t),e.partial=(...t)=>function(e,t,n){const r=Uo(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)i[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return No(this,"shape",i),i},checks:[]});return Vo(t,r)}(Qa,e,t[0]),e.required=(...t)=>function(e,t,n){const r=Uo(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in i))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)i[t]=new e({type:"nonoptional",innerType:r[t]});return No(this,"shape",i),i},checks:[]});return Vo(t,r)}(sf,e,t[0])});function qa(e,t){const n={type:"object",get shape(){var t;return No(this,"shape",e?(t=e,Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))):{}),this.shape},...qo(t)};return new Va(n)}const Ka=xo("ZodUnion",(e,t)=>{Qu.init(e,t),ra.init(e,t),e.options=t.options});function Ma(e,t){return new Ka({type:"union",options:e,...qo(t)})}const Wa=xo("ZodIntersection",(e,t)=>{ec.init(e,t),ra.init(e,t)});const Ga=xo("ZodRecord",(e,t)=>{rc.init(e,t),ra.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Ya(e,t,n){return new Ga({type:"record",keyType:e,valueType:t,...qo(n)})}const Xa=xo("ZodEnum",(e,t)=>{ic.init(e,t),ra.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const i={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);i[r]=t.entries[r]}return new Xa({...t,checks:[],...qo(r),entries:i})},e.exclude=(e,r)=>{const i={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete i[t]}return new Xa({...t,checks:[],...qo(r),entries:i})}});const Ja=xo("ZodTransform",(e,t)=>{oc.init(e,t),ra.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new zo(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(Jo(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(Jo(t))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});const Qa=xo("ZodOptional",(e,t)=>{uc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ef(e){return new Qa({type:"optional",innerType:e})}const tf=xo("ZodNullable",(e,t)=>{cc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});function nf(e){return new tf({type:"nullable",innerType:e})}const rf=xo("ZodDefault",(e,t)=>{ac.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const of=xo("ZodPrefault",(e,t)=>{dc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});const sf=xo("ZodNonOptional",(e,t)=>{lc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});const uf=xo("ZodCatch",(e,t)=>{pc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const cf=xo("ZodPipe",(e,t)=>{mc.init(e,t),ra.init(e,t),e.in=t.in,e.out=t.out});function af(e,t){return new cf({type:"pipe",in:e,out:t})}const ff=xo("ZodReadonly",(e,t)=>{_c.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.innerType});const df=xo("ZodLazy",(e,t)=>{wc.init(e,t),ra.init(e,t),e.unwrap=()=>e._zod.def.getter()});const lf=xo("ZodCustom",(e,t)=>{vc.init(e,t),ra.init(e,t)});var hf;Na(),Ta(),function(e,t){new e({type:"date",...qo(t)})}(Da,hf);const pf=Sa().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),mf=function(e,t={error:`Input not instance of ${e.name}`}){const n=new lf({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...qo(t)});return n._zod.bag.Class=e,n}(Uint8Array),gf=sa();pf.min(5e8),new Za({type:"any"}),pf.min(0).max(255),pf.min(0).max(65535);const _f=pf.min(0).max(4294967295);Sa().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const yf=sa().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),wf=Ma([sa(),Sa(),Ta(),function(e){return function(e,t){return new e({type:"null",...qo(t)})}(Ua,e)}()]),vf=new df({type:"lazy",getter:()=>Ma([wf,La(vf),Ya(gf,vf)])});mf.refine(e=>20===e.length);const bf=mf.refine(e=>32===e.length),Ef=mf.refine(e=>33===e.length),xf=mf.refine(e=>64===e.length);yf.refine(e=>40===e.length);const kf=yf.refine(e=>64===e.length),zf=yf.refine(e=>66===e.length),Of=yf.refine(e=>128===e.length);Ma([yf,mf]);const Pf=Ma([kf,bf]);Ma([zf,Ef]),Ma([Of,xf]),sa().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),sa().regex(/^[a-zA-Z0-9+/]+={0,2}$/),sa().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),sa().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const Sf=Ma([La(Pf),Pf]),Af=qa({pubkey:Pf,leaves:Sf.array().optional(),target:Pf.optional(),version:_f.optional()});var If=Object.freeze({__proto__:null,config:Af,taptree:Sf});const $f=Na().min(0n).max(2100000000000000n),Tf=qa({value:$f,script_pk:yf}),Bf=qa({coinbase:yf.nullable(),txid:kf,vout:_f,prevout:Tf.nullable(),script_sig:yf.nullable(),sequence:_f,witness:La(yf)}),Nf=qa({version:_f,vin:La(Bf),vout:La(Tf),locktime:_f}),Uf=Tf.extend({value:Ma([_f,$f])}),Zf=Bf.extend({coinbase:yf.nullable().optional(),prevout:Uf.nullable().optional(),script_sig:yf.nullable().optional(),sequence:Ma([yf,_f]).optional(),witness:La(yf).optional()}),Rf=qa({version:_f.optional(),vin:La(Zf),vout:La(Uf),locktime:_f.optional()});var Cf=Object.freeze({__proto__:null,tx_data:Nf,tx_input:Bf,tx_output:Tf,tx_template:Rf,vin_template:Zf,vout_template:Uf}),jf=Object.freeze({__proto__:null,taproot:If,tx:Cf});function Ff(e){Rf.parse(e)}function Df(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Hf(e){Nf.parse(e)}function Lf(e){Zf.parse(e)}function Vf(e){Uf.parse(e)}function qf(e,t=!0){Hf(e);const{version:n,vin:r,vout:i,locktime:o}=e,s=[Kf(n)];if(t&&s.push(g.hex("0001")),s.push(Yf(r)),s.push(Qf(i)),t)for(const e of r)s.push(td(e.witness));return s.push(nd(o)),g.join(s)}function Kf(e){return g.num(e,4).reverse()}function Mf(e){return g.hex(e,32).reverse()}function Wf(e){return g.num(e,4).reverse()}function Gf(e){return g.num(e,4).reverse()}function Yf(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(Xf(n));return g.join(t)}function Xf(e){return null!==e.coinbase?g.join([Mf(or.TXID),Wf(or.VOUT),rd(e.coinbase),Gf(e.sequence)]):g.join([Mf(e.txid),Wf(e.vout),rd(e.script_sig),Gf(e.sequence)])}function Jf(e){return g.big(e,8).reverse()}function Qf(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(ed(n));return g.join(t)}function ed(e){const{value:t,script_pk:n}=e;return g.join([Jf(t),rd(n)])}function td(e){const t=[g.varint(e.length)];for(const n of e)t.push(rd(n));return g.join(t)}function nd(e){return g.num(e,4).reverse()}function rd(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function id(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=yo(e):(Ff(e),n=pd(e)),t){b.has_items(t,"prevouts must be a non-empty array");for(const[e,r]of n.vin.entries()){const n=t.at(e);b.exists(n,"prevout not found for input index: "+e),r.prevout=hd(n)}}return n}function od(e,t=!0){return qf(yo(e),t)}function sd(e){if(!v.exists(e))return sr.SEQUENCE;if(v.is_hex(e))return g.hex(e,4).reverse().num;if(v.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function ud(e){if(v.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function cd(e){return{script_pk:e.script_pk,value:ud(e.value)}}function ad(e){Lf(e),b.exists(e.coinbase,"coinbase is required");const t=or.TXID,n=or.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:sd(e.sequence),witness:i,txid:t,vout:n}}function fd(e){Lf(e),b.is_empty(e.coinbase,"coinbase is not allowed"),b.is_empty(e.prevout,"prevout is not allowed");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:null,script_sig:r,sequence:sd(e.sequence),witness:i}}function dd(e){Lf(e),b.exists(e.prevout,"prevout is required");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:cd(e.prevout),script_sig:r,sequence:sd(e.sequence),witness:i}}function ld(e){return e.coinbase?ad(e):e.prevout?dd(e):fd(e)}function hd(e){Vf(e);return{script_pk:e.script_pk,value:ud(e.value)}}function pd(e){Ff(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??sr.LOCKTIME,i=e.version??sr.VERSION;return{locktime:r,vin:t.map(e=>ld(e)),vout:n.map(e=>hd(e)),version:i}}var md=Object.freeze({__proto__:null,assert_has_prevouts:Df,assert_tx_data:Hf,assert_tx_input:function(e){Bf.parse(e)},assert_tx_output:function(e){Tf.parse(e)},assert_tx_spend_data:function(e){Hf(e),Df(e.vin)},assert_tx_template:Ff,assert_vin_template:Lf,assert_vout_template:Vf,create_coinbase_input:ad,create_spend_input:dd,create_tx:pd,create_tx_input:ld,create_tx_output:hd,create_virtual_input:fd,decode_tx:yo,encode_script_data:rd,encode_tx:qf,encode_tx_inputs:Yf,encode_tx_locktime:nd,encode_tx_outputs:Qf,encode_tx_version:Kf,encode_tx_vout:ed,encode_txin_sequence:Gf,encode_txin_txid:Mf,encode_txin_vout:Wf,encode_vin:Xf,encode_vin_witness:td,encode_vout_value:Jf,get_prevouts:function(e){Ff(e);const t=e.vin.map(e=>e.prevout);return b.ok(t.every(e=>null!==e),"prevouts missing from tx"),t},get_segwit_size:function(e){return 2+e.filter(e=>e.witness.length>0).map(e=>e.witness).reduce((e,t)=>e+td(t).length,0)},get_tx_value:function(e){const t=id(e);Ff(t);const n=t.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),r=t.vout.reduce((e,t)=>e+t.value,0n);return{fees:n>r?n-r:0n,vin:n,vout:r}},get_txhash:function(e){return"object"==typeof e&&(Ff(e),e=qf(e,!0)),mn(e).reverse().hex},get_txid:function(e){let t;if(e instanceof Uint8Array)t=od(e,!1);else if("object"==typeof e)Ff(e),t=qf(e,!1);else{if("string"!=typeof e)throw new TypeError("invalid txdata type: "+typeof e);b.is_hex(e),t=od(e,!1)}return mn(t).reverse().hex},get_txin_size:function(e){return Xf(e).length},get_txout_size:function(e){return ed(e).length},get_txsize:function(e){const t=id(e),n=qf(t,!1).length,r=qf(t,!0).length,i=3*n+r,o=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+o,weight:i}},get_vin_size:function(e){return Yf(e).length},get_vout_size:function(e){return Qf(e).length},get_vsize:function(e){const t=g.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},normalize_prevout:cd,normalize_sequence:sd,normalize_value:ud,parse_tx:id,read_payload:Eo,serialize_tx:function(e){const t=id(e),n=t.version,r=t.locktime,i=[],o=[];for(const e of t.vin)null!==e.prevout&&i.push({script_pk:e.prevout.script_pk,value:Number(e.prevout.value)});for(const e of t.vout)o.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:o}},transcode_tx:od});function gd(e,t={}){const{sigflag:n=1,txindex:r}=t,i=id(e),o=!(128&~n),s=n%128;if(!fr.includes(s))throw new Error("Invalid hash type: "+String(n));const{version:u,vin:c,vout:a,locktime:f}=i,d=go(i,t),{txid:l,vout:h,prevout:p,sequence:m}=d,{value:_}=p??{};if(void 0===_)throw new Error("Prevout value is empty!");let{pubkey:y,script:w}=t;if(void 0===w&&void 0!==y){const e=hn(y).hex;w=`76a914${String(e)}88ac`}if(void 0===w)throw new Error("No pubkey / script has been set!");if(Fi(w).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const v=[Kf(u),_d(c,o),yd(c,s,o),Mf(l),Wf(h),ho(w),Jf(_),Gf(m),wd(a,s,r),nd(f),g.num(n,4).reverse()];return mn(g.join(v))}function _d(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(Mf(t)),n.push(Wf(r));return mn(g.join(n))}function yd(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(Gf(t));return mn(g.join(r))}function wd(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(Jf(t)),r.push(ho(n));return mn(g.join(r))}if(3===t&&(b.ok(void 0!==n),n<e.length)){const{value:t,script_pk:i}=e[n];return r.push(Jf(t)),r.push(ho(i)),mn(g.join(r))}return g.num(0,32)}function vd(e,t=192){return bd(ho(e),t)}function bd(e,t=192){return gn("TapLeaf",xd(t),e)}function Ed(e,t){return t<e&&([e,t]=[t,e]),gn("TapBranch",e,t)}function xd(e=192){return 254&e}function kd(e,t=new Uint8Array){return b.size(e,32),gn("TapTweak",e,t)}function zd(e,t={}){return gn("TapSighash",Od(e,t))}function Od(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:o=0,key_version:s=0,separator_pos:u=4294967295}=t,c=id(e),{version:a,vin:f,vout:d,locktime:l}=c,h=go(c,t),{txid:p,vout:m,sequence:_,witness:y=[]}=h;if(!dr.includes(i))throw new Error("Invalid hash type: "+String(i));if(o<0||o>127)throw new Error("Extention flag out of range: "+String(o));let{extension:w}=t;void 0!==n&&(w=vd(n).hex);const v=!(128&~i),E=_o(y),x=2*(o+(void 0!==w?1:0))+(void 0!==E?1:0),k=[g.num(0,1),g.num(i,1),Kf(a),nd(l)];if(!v){const e=f.map(e=>mo(e));k.push(Pd(f),Ad(e),Id(e),Sd(f))}if(((3&i)<2||(3&i)>3)&&k.push($d(d)),k.push(g.num(x,1)),v){const{value:e,script_pk:t}=mo(h);k.push(Mf(p),Wf(m),Jf(e),rd(t),Gf(_))}else b.ok("number"==typeof r),k.push(g.num(r,4).reverse());return void 0!==E&&k.push(E),3&~i||(b.ok("number"==typeof r),k.push(Td(d[r]))),void 0!==w&&k.push(g.bytes(w),g.num(s),g.num(u,4,"le")),g.join(k)}function Pd(e){const t=[];for(const{txid:n,vout:r}of e)t.push(Mf(n)),t.push(Wf(r));return pn(g.join(t))}function Sd(e){return pn(...e.map(e=>Gf(e.sequence)))}function Ad(e){return pn(...e.map(e=>Jf(e.value)))}function Id(e){return pn(...e.map(e=>rd(e.script_pk)))}function $d(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(Jf(n)),t.push(rd(r));return pn(...t)}function Td(e){return pn(Jf(e.value),rd(e.script_pk))}var Bd=Object.freeze({__proto__:null,bip143_hash_outputs:wd,bip143_hash_prevouts:_d,bip143_hash_sequence:yd,bip341_hash_amounts:Ad,bip341_hash_outpoints:Pd,bip341_hash_output:Td,bip341_hash_outputs:$d,bip341_hash_scripts:Id,bip341_hash_sequence:Sd,get_annex_data:_o,get_prevout:mo,get_taproot_tx_preimage:Od,hash_segwit_tx:gd,hash_taproot_tx:zd,parse_txinput:go});function Nd(e){return 0!==e?g.num(e,1).hex:""}var Ud=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=Yt(t),r=$t.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,gd(id(t),n)).hex+Nd(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=Yt(t);return Yt(Vt.sign(n,e))}(e,zd(id(t),n)).hex+Nd(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Zd(e,t,n=[]){const r=[],i=[];if(e.length<1)throw new Error("Tree is empty!");for(let i=0;i<e.length;i++){const o=e[i];if(Array.isArray(o)){let[e,i,s]=Zd(o,t);t=i,r.push(e);for(const e of s)n.push(e)}else{const e=g.bytes(o).hex;r.push(e)}}if(1===r.length)return[r[0],t,n];r.sort(),r.length%2!=0&&r.push(r[r.length-1]);for(let e=0;e<r.length-1;e+=2){const o=Ed(r[e],r[e+1]).hex;i.push(o),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=o):t===r[e+1]&&(n.push(r[e]),t=o))}return Zd(i,t,n)}function Rd(e){const t=e.map(e=>g.bytes(e)),n=e.map(e=>g.bytes(e).hex),r=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new g(t).hex:null}(t);null!==r&&t.pop();const i=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&t.length>32&&ur.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const o=function(e,t){let n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=64&&33===r.length?"p2wpkh":1===e.length&&void 0!==n&&64===n.length?"p2tr":e.length>1&&void 0!==i&&Di(i)?"p2wsh":null}(t,i),s=function(e){return null===e?null:e.startsWith("p2w")?0:e.startsWith("p2t")?1:null}(o),u=function(e,t){let n;switch(t){case"p2ts":n=e.at(-1);case"p2wsh":n=e.at(-1)}return void 0!==n?new g(n).hex:null}(t,o);null!==u&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:u,stack:n,type:o,version:s}}function Cd(e){const t=new _(e),n=t.read(1).num,r=t.read(32).hex,[i,o]=jd(n),s=[];for(;t.size>=32;)s.push(t.read(32).hex);if(0!==t.size)throw new Error("Non-empty buffer on control block: "+String(t));return{int_key:r,path:s,parity:o,version:i}}function jd(e){return e%2==0?[e-0,2]:[e-1,3]}function Fd(e){b.size(e,33,"invalid pubkey size");const[t]=g.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new Error("Invalid parity bit: "+String(t))}const Dd=192;var Hd=Object.freeze({__proto__:null,create_taproot:function(e){Af.parse(e);const{pubkey:t,version:n=Dd}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let o,s=[];if(r.length>0){const[e,t,n]=Zd(r,i);s=n,o=e}else o=i;const u=kd(t,o),c=Wt(t,u,"ecdsa"),a=Fd(c),f=Gt(c,"bip340"),d=[g.num(n+a),g.bytes(t)];s.length>0&&s.forEach(e=>d.push(e));const l=g.join(d);return{int_key:g.bytes(t).hex,path:s,parity:a,taproot:o??null,cblock:l.hex,tapkey:f.hex,taptweak:u.hex}},encode_leaf_version:xd,encode_tapbranch:Ed,encode_tapleaf:bd,encode_tapscript:vd,encode_taptweak:kd,get_merkle_root:function(e){return Zd(e)[0]},merkleize:Zd,parse_cblock:Cd,parse_cblock_parity:jd,parse_pubkey_parity:Fd,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Rd(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=Cd(t);let o=vd(r,i.version).hex;for(const e of i.path)o=Ed(o,e).hex;const s=kd(i.int_key,o),u=Wt(i.int_key,s,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:u.hex,tweak:s.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:o}=Cd(n),s=g.join([r,e]);let u=g.bytes(t).hex;for(const e of i)u=Ed(u,e).hex;const c=Wt(o,kd(o,u),"ecdsa");return s.hex===c.hex}});var Ld=Object.freeze({__proto__:null,assert_witness:function(e){b.ok(Array.isArray(e),"witness must be an array"),b.ok(e.every(e=>g.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>g.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:Rd});return e.ADDRESS=fi,e.CONST=lr,e.META=lo,e.SCHEMA=jf,e.SCRIPT=po,e.SIGHASH=Bd,e.SIGNER=Ud,e.TAPROOT=Hd,e.TX=md,e.WITNESS=Ld,e}({});
|
|
13
13
|
//# sourceMappingURL=script.js.map
|