@vbyte/btc-dev 1.1.1 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vbyte/btc-dev",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Batteries-included toolset for plebian bitcoin development",
5
5
  "type": "module",
6
6
  "keywords": [
package/dist/script.js CHANGED
@@ -11,5 +11,5 @@ function Ye(e){void 0!==e.lowS&&se("lowS",e.lowS),void 0!==e.prehash&&se("prehas
11
11
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
12
12
  const dt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ft=BigInt(0),lt=BigInt(1),ht=BigInt(2),pt=(e,t)=>(e+t/ht)/t;function mt(e){const t=dt.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,d=c*c*e%t,f=Ae(d,n,t)*d%t,l=Ae(f,n,t)*d%t,h=Ae(l,ht,t)*c%t,p=Ae(h,i,t)*h%t,m=Ae(p,s,t)*p%t,g=Ae(m,a,t)*m%t,y=Ae(g,u,t)*g%t,_=Ae(y,a,t)*m%t,v=Ae(_,n,t)*d%t,w=Ae(v,o,t)*p%t,b=Ae(w,r,t)*c%t,x=Ae(b,ht,t);if(!gt.eql(gt.sqr(x),e))throw new Error("Cannot find square root");return x}const gt=Be(dt.p,void 0,void 0,{sqrt:mt}),yt=function(e,t){const n=t=>ct({...e,hash:t});return{...n(t),create:n}}({...dt,Fp:gt,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=dt.n,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-lt*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=pt(s*e,t),u=pt(-r*e,t);let c=Se(e-a*n-u*i,t),d=Se(-a*r-u*s,t);const f=c>o,l=d>o;if(f&&(c=t-c),l&&(d=t-d),c>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:c,k2neg:l,k2:d}}}},ee),_t={};function vt(e,...t){let n=_t[e];if(void 0===n){const t=ee(Uint8Array.from(e,e=>e.charCodeAt(0)));n=H(t,t),_t[e]=n}return ee(H(n,...t))}const wt=e=>e.toBytes(!0).slice(1),bt=e=>de(e,32),xt=e=>Se(e,dt.p),Et=e=>Se(e,dt.n),kt=(()=>yt.Point)(),Ot=e=>e%ht===ft;function St(e){let t=yt.utils.normPrivateKeyToScalar(e),n=kt.fromPrivateKey(t);return{scalar:Ot(n.y)?t:Et(-t),bytes:wt(n)}}function At(e){me("x",e,lt,dt.p);const t=xt(e*e);let n=mt(xt(t*e+BigInt(7)));Ot(n)||(n=xt(-n));const r=kt.fromAffine({x:e,y:n});return r.assertValidity(),r}const Pt=ue;function It(...e){return Et(Pt(vt("BIP0340/challenge",...e)))}function Tt(e){return St(e).bytes}function Nt(e,t,n=M(32)){const r=le("message",e),{bytes:i,scalar:s}=St(t),o=le("auxRand",n,32),a=bt(s^Pt(vt("BIP0340/aux",o))),u=vt("BIP0340/nonce",a,i,r),c=Et(Pt(u));if(c===ft)throw new Error("sign failed: k is zero");const{bytes:d,scalar:f}=St(c),l=It(d,i,r),h=new Uint8Array(64);if(h.set(d,0),h.set(bt(Et(f+l*s)),32),!Ct(h,r,i))throw new Error("sign: Invalid signature produced");return h}function Ct(e,t,n){const r=le("signature",e,64),i=le("message",t),s=le("publicKey",n,32);try{const e=At(Pt(s)),t=Pt(r.subarray(0,32));if(!pe(t,lt,dt.p))return!1;const n=Pt(r.subarray(32,64));if(!pe(n,lt,dt.n))return!1;const o=It(bt(t),wt(e),i),a=kt.BASE.multiplyUnsafe(n).add(e.multiplyUnsafe(Et(-o))),{x:u,y:c}=a.toAffine();return!(a.is0()||!Ot(c)||u!==t)}catch(e){return!1}}const $t=(()=>({getPublicKey:Tt,sign:Nt,verify:Ct,utils:{randomPrivateKey:yt.utils.randomPrivateKey,lift_x:At,pointToBytes:wt,numberToBytesBE:de,bytesToNumberBE:ue,taggedHash:vt,mod:Se}}))();BigInt(0),BigInt(2);Be(yt.CURVE.n,32,!0);const Rt=yt.Point.BASE;function Bt(e,t,n,r=!1){const i=jt(t).big,s=function(e){try{const t=Ut(e,"ecdsa");return yt.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),o=Rt.multiply(i);let a=s.add(o);r&&!a.hasEvenY()&&(a=a.negate());return Ut(a.toHex(!0),n)}function Ut(e,t){try{const n=jt(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 jt(e){try{return g.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const Zt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),zt=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Ft=(()=>zt.map(e=>(9*e+5)%16))(),Lt=(()=>{const e=[[zt],[Ft]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Zt[e]));return e})(),Dt=(()=>Lt[0])(),Ht=(()=>Lt[1])(),qt=[[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)),Vt=Dt.map((e,t)=>e.map(e=>qt[t][e])),Mt=Ht.map((e,t)=>e.map(e=>qt[t][e])),Kt=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Wt=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Gt(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 Yt=new Uint32Array(16);class Qt extends G{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)Yt[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,s=i,o=0|this.h2,a=o,u=0|this.h3,c=u,d=0|this.h4,f=d;for(let e=0;e<5;e++){const t=4-e,l=Kt[e],h=Wt[e],p=Dt[e],m=Ht[e],g=Vt[e],y=Mt[e];for(let t=0;t<16;t++){const r=T(n+Gt(e,i,o,u)+Yt[p[t]]+l,g[t])+d|0;n=d,d=u,u=0|T(o,10),o=i,i=r}for(let e=0;e<16;e++){const n=T(r+Gt(t,s,a,c)+Yt[m[e]]+h,y[e])+f|0;r=f,f=c,c=0|T(a,10),a=s,s=n}}this.set(this.h1+o+c|0,this.h2+u+f|0,this.h3+d+r|0,this.h4+n+s|0,this.h0+i+a|0)}roundClean(){A(Yt)}destroy(){this.destroyed=!0,A(this.buffer),this.set(0,0,0,0,0)}}const Xt=V(()=>new Qt);function Jt(...e){const t=g.join(e),n=Xt(ee(t));return new g(n)}function en(...e){const t=g.join(e),n=ee(t);return new g(n)}function tn(...e){const t=g.join(e),n=ee(ee(t));return new g(n)}function nn(e,...t){const n=function(e){const t=en(g.str(e));return g.join([t,t])}(e),r=t.map(e=>new g(e));return en(g.join([n,...r]))}var rn,sn;!function(e){e.assertEqual=e=>{},e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const n of e)t[n]=n;return t},e.getValidEnumValues=t=>{const n=e.objectKeys(t).filter(e=>"number"!=typeof t[t[e]]),r={};for(const e of n)r[e]=t[e];return e.objectValues(r)},e.objectValues=t=>e.objectKeys(t).map(function(e){return t[e]}),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t},e.find=(e,t)=>{for(const n of e)if(t(n))return n},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(rn||(rn={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(sn||(sn={}));const on=rn.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),an=e=>{switch(typeof e){case"undefined":return on.undefined;case"string":return on.string;case"number":return Number.isNaN(e)?on.nan:on.number;case"boolean":return on.boolean;case"function":return on.function;case"bigint":return on.bigint;case"symbol":return on.symbol;case"object":return Array.isArray(e)?on.array:null===e?on.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?on.promise:"undefined"!=typeof Map&&e instanceof Map?on.map:"undefined"!=typeof Set&&e instanceof Set?on.set:"undefined"!=typeof Date&&e instanceof Date?on.date:on.object;default:return on.unknown}},un=rn.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class cn extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},n={_errors:[]},r=e=>{for(const i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(r);else if("invalid_return_type"===i.code)r(i.returnTypeError);else if("invalid_arguments"===i.code)r(i.argumentsError);else if(0===i.path.length)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){const n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(this),n}static assert(e){if(!(e instanceof cn))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,rn.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},n=[];for(const r of this.issues)if(r.path.length>0){const n=r.path[0];t[n]=t[n]||[],t[n].push(e(r))}else n.push(e(r));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}cn.create=e=>new cn(e);const dn=(e,t)=>{let n;switch(e.code){case un.invalid_type:n=e.received===on.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case un.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,rn.jsonStringifyReplacer)}`;break;case un.unrecognized_keys:n=`Unrecognized key(s) in object: ${rn.joinValues(e.keys,", ")}`;break;case un.invalid_union:n="Invalid input";break;case un.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${rn.joinValues(e.options)}`;break;case un.invalid_enum_value:n=`Invalid enum value. Expected ${rn.joinValues(e.options)}, received '${e.received}'`;break;case un.invalid_arguments:n="Invalid function arguments";break;case un.invalid_return_type:n="Invalid function return type";break;case un.invalid_date:n="Invalid date";break;case un.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:rn.assertNever(e.validation):n="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case un.too_small:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case un.too_big:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case un.custom:n="Invalid input";break;case un.invalid_intersection_types:n="Intersection results could not be merged";break;case un.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case un.not_finite:n="Number must be finite";break;default:n=t.defaultError,rn.assertNever(e)}return{message:n}};let fn=dn;function ln(e,t){const n=fn,r=(e=>{const{data:t,path:n,errorMaps:r,issueData:i}=e,s=[...n,...i.path||[]],o={...i,path:s};if(void 0!==i.message)return{...i,path:s,message:i.message};let a="";const u=r.filter(e=>!!e).slice().reverse();for(const e of u)a=e(o,{data:t,defaultError:a}).message;return{...i,path:s,message:a}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===dn?void 0:dn].filter(e=>!!e)});e.common.issues.push(r)}class hn{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const r of t){if("aborted"===r.status)return pn;"dirty"===r.status&&e.dirty(),n.push(r.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const e of t){const t=await e.key,r=await e.value;n.push({key:t,value:r})}return hn.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const r of t){const{key:t,value:i}=r;if("aborted"===t.status)return pn;if("aborted"===i.status)return pn;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"===t.value||void 0===i.value&&!r.alwaysSet||(n[t.value]=i.value)}return{status:e.value,value:n}}}const pn=Object.freeze({status:"aborted"}),mn=e=>({status:"dirty",value:e}),gn=e=>({status:"valid",value:e}),yn=e=>"aborted"===e.status,_n=e=>"dirty"===e.status,vn=e=>"valid"===e.status,wn=e=>"undefined"!=typeof Promise&&e instanceof Promise;var bn;!function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:e?.message}(bn||(bn={}));class xn{constructor(e,t,n,r){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=r}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const En=(e,t)=>{if(vn(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new cn(e.common.issues);return this._error=t,this._error}}};function kn(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:i}=e;if(t&&(n||r))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:i};return{errorMap:(t,i)=>{const{message:s}=e;return"invalid_enum_value"===t.code?{message:s??i.defaultError}:void 0===i.data?{message:s??r??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:s??n??i.defaultError}},description:i}}class On{get description(){return this._def.description}_getType(e){return an(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:an(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new hn,ctx:{common:e.parent.common,data:e.data,parsedType:an(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(wn(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){const n={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)},r=this._parseSync({data:e,path:n.path,parent:n});return En(n,r)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return vn(n)?{value:n.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>vn(e)?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)},r=this._parse({data:e,path:n.path,parent:n}),i=await(wn(r)?r:Promise.resolve(r));return En(n,i)}refine(e,t){const n=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement((t,r)=>{const i=e(t),s=()=>r.addIssue({code:un.custom,...n(t)});return"undefined"!=typeof Promise&&i instanceof Promise?i.then(e=>!!e||(s(),!1)):!!i||(s(),!1)})}refinement(e,t){return this._refinement((n,r)=>!!e(n)||(r.addIssue("function"==typeof t?t(n,r):t),!1))}_refinement(e){return new kr({schema:this,typeName:Rr.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Or.create(this,this._def)}nullable(){return Sr.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ur.create(this)}promise(){return Er.create(this,this._def)}or(e){return fr.create([this,e],this._def)}and(e){return hr.create(this,e,this._def)}transform(e){return new kr({...kn(this._def),schema:this,typeName:Rr.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Ar({...kn(this._def),innerType:this,defaultValue:t,typeName:Rr.ZodDefault})}brand(){return new Tr({typeName:Rr.ZodBranded,type:this,...kn(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Pr({...kn(this._def),innerType:this,catchValue:t,typeName:Rr.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return Nr.create(this,e)}readonly(){return Cr.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Sn=/^c[^\s-]{8,}$/i,An=/^[0-9a-z]+$/,Pn=/^[0-9A-HJKMNP-TV-Z]{26}$/i,In=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Tn=/^[a-z0-9_-]{21}$/i,Nn=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Cn=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,$n=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let Rn;const Bn=/^(?:(?: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])$/,Un=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,jn=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Zn=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,zn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Fn=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Ln="((\\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])))",Dn=new RegExp(`^${Ln}$`);function Hn(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function qn(e){return new RegExp(`^${Hn(e)}$`)}function Vn(e){let t=`${Ln}T${Hn(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function Mn(e,t){return!("v4"!==t&&t||!Bn.test(e))||!("v6"!==t&&t||!jn.test(e))}function Kn(e,t){if(!Nn.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),i=JSON.parse(atob(r));return"object"==typeof i&&null!==i&&((!("typ"in i)||"JWT"===i?.typ)&&(!!i.alg&&(!t||i.alg===t)))}catch{return!1}}function Wn(e,t){return!("v4"!==t&&t||!Un.test(e))||!("v6"!==t&&t||!Zn.test(e))}class Gn extends On{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==on.string){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.string,received:t.parsedType}),pn}const t=new hn;let n;for(const r of this._def.checks)if("min"===r.kind)e.data.length<r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("max"===r.kind)e.data.length>r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("length"===r.kind){const i=e.data.length>r.value,s=e.data.length<r.value;(i||s)&&(n=this._getOrReturnCtx(e,n),i?ln(n,{code:un.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}):s&&ln(n,{code:un.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}),t.dirty())}else if("email"===r.kind)$n.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"email",code:un.invalid_string,message:r.message}),t.dirty());else if("emoji"===r.kind)Rn||(Rn=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Rn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"emoji",code:un.invalid_string,message:r.message}),t.dirty());else if("uuid"===r.kind)In.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"uuid",code:un.invalid_string,message:r.message}),t.dirty());else if("nanoid"===r.kind)Tn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"nanoid",code:un.invalid_string,message:r.message}),t.dirty());else if("cuid"===r.kind)Sn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"cuid",code:un.invalid_string,message:r.message}),t.dirty());else if("cuid2"===r.kind)An.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"cuid2",code:un.invalid_string,message:r.message}),t.dirty());else if("ulid"===r.kind)Pn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"ulid",code:un.invalid_string,message:r.message}),t.dirty());else if("url"===r.kind)try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),ln(n,{validation:"url",code:un.invalid_string,message:r.message}),t.dirty()}else if("regex"===r.kind){r.regex.lastIndex=0;r.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"regex",code:un.invalid_string,message:r.message}),t.dirty())}else if("trim"===r.kind)e.data=e.data.trim();else if("includes"===r.kind)e.data.includes(r.value,r.position)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:{includes:r.value,position:r.position},message:r.message}),t.dirty());else if("toLowerCase"===r.kind)e.data=e.data.toLowerCase();else if("toUpperCase"===r.kind)e.data=e.data.toUpperCase();else if("startsWith"===r.kind)e.data.startsWith(r.value)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:{startsWith:r.value},message:r.message}),t.dirty());else if("endsWith"===r.kind)e.data.endsWith(r.value)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:{endsWith:r.value},message:r.message}),t.dirty());else if("datetime"===r.kind){Vn(r).test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:"datetime",message:r.message}),t.dirty())}else if("date"===r.kind){Dn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:"date",message:r.message}),t.dirty())}else if("time"===r.kind){qn(r).test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:"time",message:r.message}),t.dirty())}else"duration"===r.kind?Cn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"duration",code:un.invalid_string,message:r.message}),t.dirty()):"ip"===r.kind?Mn(e.data,r.version)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"ip",code:un.invalid_string,message:r.message}),t.dirty()):"jwt"===r.kind?Kn(e.data,r.alg)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"jwt",code:un.invalid_string,message:r.message}),t.dirty()):"cidr"===r.kind?Wn(e.data,r.version)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"cidr",code:un.invalid_string,message:r.message}),t.dirty()):"base64"===r.kind?zn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"base64",code:un.invalid_string,message:r.message}),t.dirty()):"base64url"===r.kind?Fn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"base64url",code:un.invalid_string,message:r.message}),t.dirty()):rn.assertNever(r);return{status:t.value,value:e.data}}_regex(e,t,n){return this.refinement(t=>e.test(t),{validation:t,code:un.invalid_string,...bn.errToObj(n)})}_addCheck(e){return new Gn({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...bn.errToObj(e)})}url(e){return this._addCheck({kind:"url",...bn.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...bn.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...bn.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...bn.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...bn.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...bn.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...bn.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...bn.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...bn.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...bn.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...bn.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...bn.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...bn.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...bn.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...bn.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...bn.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...bn.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...bn.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...bn.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...bn.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...bn.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...bn.errToObj(t)})}nonempty(e){return this.min(1,bn.errToObj(e))}trim(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function Yn(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,i=n>r?n:r;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}Gn.create=e=>new Gn({checks:[],typeName:Rr.ZodString,coerce:e?.coerce??!1,...kn(e)});class Qn extends On{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){this._def.coerce&&(e.data=Number(e.data));if(this._getType(e)!==on.number){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.number,received:t.parsedType}),pn}let t;const n=new hn;for(const r of this._def.checks)if("int"===r.kind)rn.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),ln(t,{code:un.invalid_type,expected:"integer",received:"float",message:r.message}),n.dirty());else if("min"===r.kind){(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_small,minimum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),n.dirty())}else if("max"===r.kind){(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_big,maximum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),n.dirty())}else"multipleOf"===r.kind?0!==Yn(e.data,r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.not_multiple_of,multipleOf:r.value,message:r.message}),n.dirty()):"finite"===r.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),ln(t,{code:un.not_finite,message:r.message}),n.dirty()):rn.assertNever(r);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,bn.toString(t))}gt(e,t){return this.setLimit("min",e,!1,bn.toString(t))}lte(e,t){return this.setLimit("max",e,!0,bn.toString(t))}lt(e,t){return this.setLimit("max",e,!1,bn.toString(t))}setLimit(e,t,n,r){return new Qn({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:bn.toString(r)}]})}_addCheck(e){return new Qn({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:bn.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:bn.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:bn.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:bn.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:bn.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:bn.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:bn.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:bn.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:bn.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&rn.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if("finite"===n.kind||"int"===n.kind||"multipleOf"===n.kind)return!0;"min"===n.kind?(null===t||n.value>t)&&(t=n.value):"max"===n.kind&&(null===e||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Qn.create=e=>new Qn({checks:[],typeName:Rr.ZodNumber,coerce:e?.coerce||!1,...kn(e)});class Xn extends On{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==on.bigint)return this._getInvalidInput(e);let t;const n=new hn;for(const r of this._def.checks)if("min"===r.kind){(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_small,type:"bigint",minimum:r.value,inclusive:r.inclusive,message:r.message}),n.dirty())}else if("max"===r.kind){(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_big,type:"bigint",maximum:r.value,inclusive:r.inclusive,message:r.message}),n.dirty())}else"multipleOf"===r.kind?e.data%r.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.not_multiple_of,multipleOf:r.value,message:r.message}),n.dirty()):rn.assertNever(r);return{status:n.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.bigint,received:t.parsedType}),pn}gte(e,t){return this.setLimit("min",e,!0,bn.toString(t))}gt(e,t){return this.setLimit("min",e,!1,bn.toString(t))}lte(e,t){return this.setLimit("max",e,!0,bn.toString(t))}lt(e,t){return this.setLimit("max",e,!1,bn.toString(t))}setLimit(e,t,n,r){return new Xn({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:bn.toString(r)}]})}_addCheck(e){return new Xn({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:bn.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:bn.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:bn.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:bn.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:bn.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}Xn.create=e=>new Xn({checks:[],typeName:Rr.ZodBigInt,coerce:e?.coerce??!1,...kn(e)});class Jn extends On{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==on.boolean){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.boolean,received:t.parsedType}),pn}return gn(e.data)}}Jn.create=e=>new Jn({typeName:Rr.ZodBoolean,coerce:e?.coerce||!1,...kn(e)});class er extends On{_parse(e){this._def.coerce&&(e.data=new Date(e.data));if(this._getType(e)!==on.date){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.date,received:t.parsedType}),pn}if(Number.isNaN(e.data.getTime())){return ln(this._getOrReturnCtx(e),{code:un.invalid_date}),pn}const t=new hn;let n;for(const r of this._def.checks)"min"===r.kind?e.data.getTime()<r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_small,message:r.message,inclusive:!0,exact:!1,minimum:r.value,type:"date"}),t.dirty()):"max"===r.kind?e.data.getTime()>r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_big,message:r.message,inclusive:!0,exact:!1,maximum:r.value,type:"date"}),t.dirty()):rn.assertNever(r);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new er({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:bn.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:bn.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}er.create=e=>new er({checks:[],coerce:e?.coerce||!1,typeName:Rr.ZodDate,...kn(e)});class tr extends On{_parse(e){if(this._getType(e)!==on.symbol){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.symbol,received:t.parsedType}),pn}return gn(e.data)}}tr.create=e=>new tr({typeName:Rr.ZodSymbol,...kn(e)});class nr extends On{_parse(e){if(this._getType(e)!==on.undefined){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.undefined,received:t.parsedType}),pn}return gn(e.data)}}nr.create=e=>new nr({typeName:Rr.ZodUndefined,...kn(e)});class rr extends On{_parse(e){if(this._getType(e)!==on.null){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.null,received:t.parsedType}),pn}return gn(e.data)}}rr.create=e=>new rr({typeName:Rr.ZodNull,...kn(e)});class ir extends On{constructor(){super(...arguments),this._any=!0}_parse(e){return gn(e.data)}}ir.create=e=>new ir({typeName:Rr.ZodAny,...kn(e)});class sr extends On{constructor(){super(...arguments),this._unknown=!0}_parse(e){return gn(e.data)}}sr.create=e=>new sr({typeName:Rr.ZodUnknown,...kn(e)});class or extends On{_parse(e){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.never,received:t.parsedType}),pn}}or.create=e=>new or({typeName:Rr.ZodNever,...kn(e)});class ar extends On{_parse(e){if(this._getType(e)!==on.undefined){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.void,received:t.parsedType}),pn}return gn(e.data)}}ar.create=e=>new ar({typeName:Rr.ZodVoid,...kn(e)});class ur extends On{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),r=this._def;if(t.parsedType!==on.array)return ln(t,{code:un.invalid_type,expected:on.array,received:t.parsedType}),pn;if(null!==r.exactLength){const e=t.data.length>r.exactLength.value,i=t.data.length<r.exactLength.value;(e||i)&&(ln(t,{code:e?un.too_big:un.too_small,minimum:i?r.exactLength.value:void 0,maximum:e?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),n.dirty())}if(null!==r.minLength&&t.data.length<r.minLength.value&&(ln(t,{code:un.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),n.dirty()),null!==r.maxLength&&t.data.length>r.maxLength.value&&(ln(t,{code:un.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((e,n)=>r.type._parseAsync(new xn(t,e,t.path,n)))).then(e=>hn.mergeArray(n,e));const i=[...t.data].map((e,n)=>r.type._parseSync(new xn(t,e,t.path,n)));return hn.mergeArray(n,i)}get element(){return this._def.type}min(e,t){return new ur({...this._def,minLength:{value:e,message:bn.toString(t)}})}max(e,t){return new ur({...this._def,maxLength:{value:e,message:bn.toString(t)}})}length(e,t){return new ur({...this._def,exactLength:{value:e,message:bn.toString(t)}})}nonempty(e){return this.min(1,e)}}function cr(e){if(e instanceof dr){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Or.create(cr(r))}return new dr({...e._def,shape:()=>t})}return e instanceof ur?new ur({...e._def,type:cr(e.element)}):e instanceof Or?Or.create(cr(e.unwrap())):e instanceof Sr?Sr.create(cr(e.unwrap())):e instanceof pr?pr.create(e.items.map(e=>cr(e))):e}ur.create=(e,t)=>new ur({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Rr.ZodArray,...kn(t)});class dr extends On{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),t=rn.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==on.object){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.object,received:t.parsedType}),pn}const{status:t,ctx:n}=this._processInputParams(e),{shape:r,keys:i}=this._getCached(),s=[];if(!(this._def.catchall instanceof or&&"strip"===this._def.unknownKeys))for(const e in n.data)i.includes(e)||s.push(e);const o=[];for(const e of i){const t=r[e],i=n.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new xn(n,i,n.path,e)),alwaysSet:e in n.data})}if(this._def.catchall instanceof or){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of s)o.push({key:{status:"valid",value:e},value:{status:"valid",value:n.data[e]}});else if("strict"===e)s.length>0&&(ln(n,{code:un.unrecognized_keys,keys:s}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of s){const r=n.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new xn(n,r,n.path,t)),alwaysSet:t in n.data})}}return n.common.async?Promise.resolve().then(async()=>{const e=[];for(const t of o){const n=await t.key,r=await t.value;e.push({key:n,value:r,alwaysSet:t.alwaysSet})}return e}).then(e=>hn.mergeObjectSync(t,e)):hn.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return new dr({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,n)=>{const r=this._def.errorMap?.(t,n).message??n.defaultError;return"unrecognized_keys"===t.code?{message:bn.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new dr({...this._def,unknownKeys:"strip"})}passthrough(){return new dr({...this._def,unknownKeys:"passthrough"})}extend(e){return new dr({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new dr({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:Rr.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new dr({...this._def,catchall:e})}pick(e){const t={};for(const n of rn.objectKeys(e))e[n]&&this.shape[n]&&(t[n]=this.shape[n]);return new dr({...this._def,shape:()=>t})}omit(e){const t={};for(const n of rn.objectKeys(this.shape))e[n]||(t[n]=this.shape[n]);return new dr({...this._def,shape:()=>t})}deepPartial(){return cr(this)}partial(e){const t={};for(const n of rn.objectKeys(this.shape)){const r=this.shape[n];e&&!e[n]?t[n]=r:t[n]=r.optional()}return new dr({...this._def,shape:()=>t})}required(e){const t={};for(const n of rn.objectKeys(this.shape))if(e&&!e[n])t[n]=this.shape[n];else{let e=this.shape[n];for(;e instanceof Or;)e=e._def.innerType;t[n]=e}return new dr({...this._def,shape:()=>t})}keyof(){return wr(rn.objectKeys(this.shape))}}dr.create=(e,t)=>new dr({shape:()=>e,unknownKeys:"strip",catchall:or.create(),typeName:Rr.ZodObject,...kn(t)}),dr.strictCreate=(e,t)=>new dr({shape:()=>e,unknownKeys:"strict",catchall:or.create(),typeName:Rr.ZodObject,...kn(t)}),dr.lazycreate=(e,t)=>new dr({shape:e,unknownKeys:"strip",catchall:or.create(),typeName:Rr.ZodObject,...kn(t)});class fr extends On{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;if(t.common.async)return Promise.all(n.map(async e=>{const n={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:n}),ctx:n}})).then(function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const n of e)if("dirty"===n.result.status)return t.common.issues.push(...n.ctx.common.issues),n.result;const n=e.map(e=>new cn(e.ctx.common.issues));return ln(t,{code:un.invalid_union,unionErrors:n}),pn});{let e;const r=[];for(const i of n){const n={...t,common:{...t.common,issues:[]},parent:null},s=i._parseSync({data:t.data,path:t.path,parent:n});if("valid"===s.status)return s;"dirty"!==s.status||e||(e={result:s,ctx:n}),n.common.issues.length&&r.push(n.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const i=r.map(e=>new cn(e));return ln(t,{code:un.invalid_union,unionErrors:i}),pn}}get options(){return this._def.options}}function lr(e,t){const n=an(e),r=an(t);if(e===t)return{valid:!0,data:e};if(n===on.object&&r===on.object){const n=rn.objectKeys(t),r=rn.objectKeys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=lr(e[n],t[n]);if(!r.valid)return{valid:!1};i[n]=r.data}return{valid:!0,data:i}}if(n===on.array&&r===on.array){if(e.length!==t.length)return{valid:!1};const n=[];for(let r=0;r<e.length;r++){const i=lr(e[r],t[r]);if(!i.valid)return{valid:!1};n.push(i.data)}return{valid:!0,data:n}}return n===on.date&&r===on.date&&+e===+t?{valid:!0,data:e}:{valid:!1}}fr.create=(e,t)=>new fr({options:e,typeName:Rr.ZodUnion,...kn(t)});class hr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=(e,r)=>{if(yn(e)||yn(r))return pn;const i=lr(e.value,r.value);return i.valid?((_n(e)||_n(r))&&t.dirty(),{status:t.value,value:i.data}):(ln(n,{code:un.invalid_intersection_types}),pn)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([e,t])=>r(e,t)):r(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}hr.create=(e,t,n)=>new hr({left:e,right:t,typeName:Rr.ZodIntersection,...kn(n)});class pr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.array)return ln(n,{code:un.invalid_type,expected:on.array,received:n.parsedType}),pn;if(n.data.length<this._def.items.length)return ln(n,{code:un.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),pn;!this._def.rest&&n.data.length>this._def.items.length&&(ln(n,{code:un.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const r=[...n.data].map((e,t)=>{const r=this._def.items[t]||this._def.rest;return r?r._parse(new xn(n,e,n.path,t)):null}).filter(e=>!!e);return n.common.async?Promise.all(r).then(e=>hn.mergeArray(t,e)):hn.mergeArray(t,r)}get items(){return this._def.items}rest(e){return new pr({...this._def,rest:e})}}pr.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new pr({items:e,typeName:Rr.ZodTuple,rest:null,...kn(t)})};class mr extends On{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.object)return ln(n,{code:un.invalid_type,expected:on.object,received:n.parsedType}),pn;const r=[],i=this._def.keyType,s=this._def.valueType;for(const e in n.data)r.push({key:i._parse(new xn(n,e,n.path,e)),value:s._parse(new xn(n,n.data[e],n.path,e)),alwaysSet:e in n.data});return n.common.async?hn.mergeObjectAsync(t,r):hn.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,n){return new mr(t instanceof On?{keyType:e,valueType:t,typeName:Rr.ZodRecord,...kn(n)}:{keyType:Gn.create(),valueType:e,typeName:Rr.ZodRecord,...kn(t)})}}class gr extends On{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.map)return ln(n,{code:un.invalid_type,expected:on.map,received:n.parsedType}),pn;const r=this._def.keyType,i=this._def.valueType,s=[...n.data.entries()].map(([e,t],s)=>({key:r._parse(new xn(n,e,n.path,[s,"key"])),value:i._parse(new xn(n,t,n.path,[s,"value"]))}));if(n.common.async){const e=new Map;return Promise.resolve().then(async()=>{for(const n of s){const r=await n.key,i=await n.value;if("aborted"===r.status||"aborted"===i.status)return pn;"dirty"!==r.status&&"dirty"!==i.status||t.dirty(),e.set(r.value,i.value)}return{status:t.value,value:e}})}{const e=new Map;for(const n of s){const r=n.key,i=n.value;if("aborted"===r.status||"aborted"===i.status)return pn;"dirty"!==r.status&&"dirty"!==i.status||t.dirty(),e.set(r.value,i.value)}return{status:t.value,value:e}}}}gr.create=(e,t,n)=>new gr({valueType:t,keyType:e,typeName:Rr.ZodMap,...kn(n)});class yr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.set)return ln(n,{code:un.invalid_type,expected:on.set,received:n.parsedType}),pn;const r=this._def;null!==r.minSize&&n.data.size<r.minSize.value&&(ln(n,{code:un.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),null!==r.maxSize&&n.data.size>r.maxSize.value&&(ln(n,{code:un.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function s(e){const n=new Set;for(const r of e){if("aborted"===r.status)return pn;"dirty"===r.status&&t.dirty(),n.add(r.value)}return{status:t.value,value:n}}const o=[...n.data.values()].map((e,t)=>i._parse(new xn(n,e,n.path,t)));return n.common.async?Promise.all(o).then(e=>s(e)):s(o)}min(e,t){return new yr({...this._def,minSize:{value:e,message:bn.toString(t)}})}max(e,t){return new yr({...this._def,maxSize:{value:e,message:bn.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}yr.create=(e,t)=>new yr({valueType:e,minSize:null,maxSize:null,typeName:Rr.ZodSet,...kn(t)});class _r extends On{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}_r.create=(e,t)=>new _r({getter:e,typeName:Rr.ZodLazy,...kn(t)});class vr extends On{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return ln(t,{received:t.data,code:un.invalid_literal,expected:this._def.value}),pn}return{status:"valid",value:e.data}}get value(){return this._def.value}}function wr(e,t){return new br({values:e,typeName:Rr.ZodEnum,...kn(t)})}vr.create=(e,t)=>new vr({value:e,typeName:Rr.ZodLiteral,...kn(t)});class br extends On{_parse(e){if("string"!=typeof e.data){const t=this._getOrReturnCtx(e),n=this._def.values;return ln(t,{expected:rn.joinValues(n),received:t.parsedType,code:un.invalid_type}),pn}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return ln(t,{received:t.data,code:un.invalid_enum_value,options:n}),pn}return gn(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return br.create(e,{...this._def,...t})}exclude(e,t=this._def){return br.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}br.create=wr;class xr extends On{_parse(e){const t=rn.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==on.string&&n.parsedType!==on.number){const e=rn.objectValues(t);return ln(n,{expected:rn.joinValues(e),received:n.parsedType,code:un.invalid_type}),pn}if(this._cache||(this._cache=new Set(rn.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const e=rn.objectValues(t);return ln(n,{received:n.data,code:un.invalid_enum_value,options:e}),pn}return gn(e.data)}get enum(){return this._def.values}}xr.create=(e,t)=>new xr({values:e,typeName:Rr.ZodNativeEnum,...kn(t)});class Er extends On{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==on.promise&&!1===t.common.async)return ln(t,{code:un.invalid_type,expected:on.promise,received:t.parsedType}),pn;const n=t.parsedType===on.promise?t.data:Promise.resolve(t.data);return gn(n.then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Er.create=(e,t)=>new Er({type:e,typeName:Rr.ZodPromise,...kn(t)});class kr extends On{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Rr.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=this._def.effect||null,i={addIssue:e=>{ln(n,e),e.fatal?t.abort():t.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===r.type){const e=r.transform(n.data,i);if(n.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return pn;const r=await this._def.schema._parseAsync({data:e,path:n.path,parent:n});return"aborted"===r.status?pn:"dirty"===r.status||"dirty"===t.value?mn(r.value):r});{if("aborted"===t.value)return pn;const r=this._def.schema._parseSync({data:e,path:n.path,parent:n});return"aborted"===r.status?pn:"dirty"===r.status||"dirty"===t.value?mn(r.value):r}}if("refinement"===r.type){const e=e=>{const t=r.refinement(e,i);if(n.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===n.common.async){const r=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===r.status?pn:("dirty"===r.status&&t.dirty(),e(r.value),{status:t.value,value:r.value})}return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(n=>"aborted"===n.status?pn:("dirty"===n.status&&t.dirty(),e(n.value).then(()=>({status:t.value,value:n.value}))))}if("transform"===r.type){if(!1===n.common.async){const e=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!vn(e))return pn;const s=r.transform(e.value,i);if(s instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:s}}return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(e=>vn(e)?Promise.resolve(r.transform(e.value,i)).then(e=>({status:t.value,value:e})):pn)}rn.assertNever(r)}}kr.create=(e,t,n)=>new kr({schema:e,typeName:Rr.ZodEffects,effect:t,...kn(n)}),kr.createWithPreprocess=(e,t,n)=>new kr({schema:t,effect:{type:"preprocess",transform:e},typeName:Rr.ZodEffects,...kn(n)});class Or extends On{_parse(e){return this._getType(e)===on.undefined?gn(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Or.create=(e,t)=>new Or({innerType:e,typeName:Rr.ZodOptional,...kn(t)});class Sr extends On{_parse(e){return this._getType(e)===on.null?gn(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Sr.create=(e,t)=>new Sr({innerType:e,typeName:Rr.ZodNullable,...kn(t)});class Ar extends On{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===on.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ar.create=(e,t)=>new Ar({innerType:e,typeName:Rr.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...kn(t)});class Pr extends On{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},r=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return wn(r)?r.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new cn(n.common.issues)},input:n.data})})):{status:"valid",value:"valid"===r.status?r.value:this._def.catchValue({get error(){return new cn(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}Pr.create=(e,t)=>new Pr({innerType:e,typeName:Rr.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...kn(t)});class Ir extends On{_parse(e){if(this._getType(e)!==on.nan){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.nan,received:t.parsedType}),pn}return{status:"valid",value:e.data}}}Ir.create=e=>new Ir({typeName:Rr.ZodNaN,...kn(e)});class Tr extends On{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class Nr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return"aborted"===e.status?pn:"dirty"===e.status?(t.dirty(),mn(e.value)):this._def.out._parseAsync({data:e.value,path:n.path,parent:n})})()}{const e=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===e.status?pn:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:n.path,parent:n})}}static create(e,t){return new Nr({in:e,out:t,typeName:Rr.ZodPipeline})}}class Cr extends On{_parse(e){const t=this._def.innerType._parse(e),n=e=>(vn(e)&&(e.value=Object.freeze(e.value)),e);return wn(t)?t.then(e=>n(e)):n(t)}unwrap(){return this._def.innerType}}function $r(e,t){const n="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof n?{message:n}:n}var Rr;Cr.create=(e,t)=>new Cr({innerType:e,typeName:Rr.ZodReadonly,...kn(t)}),function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(Rr||(Rr={}));const Br=Gn.create,Ur=Qn.create,jr=Xn.create,Zr=Jn.create,zr=er.create,Fr=rr.create,Lr=ir.create,Dr=ur.create,Hr=dr.create,qr=fr.create,Vr=mr.create,Mr=_r.create;jr(),Zr(),zr();const Kr=Ur().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),Wr=((e,t={message:`Input not instance of ${e.name}`})=>function(e,t={},n){return e?ir.create().superRefine((r,i)=>{const s=e(r);if(s instanceof Promise)return s.then(e=>{if(!e){const e=$r(t,r),s=e.fatal??n??!0;i.addIssue({code:"custom",...e,fatal:s})}});if(!s){const e=$r(t,r),s=e.fatal??n??!0;i.addIssue({code:"custom",...e,fatal:s})}}):ir.create()}(t=>t instanceof e,t))(Uint8Array);Br(),Kr.min(5e8),Lr(),Kr.min(0).max(255),Kr.min(0).max(65535);const Gr=Kr.min(0).max(4294967295);Ur().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const Yr=Br().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),Qr=qr([Br(),Ur(),Zr(),Fr()]),Xr=Mr(()=>qr([Qr,Dr(Xr),Vr(Xr)]));Wr.refine(e=>20===e.length);const Jr=Wr.refine(e=>32===e.length),ei=Wr.refine(e=>33===e.length),ti=Wr.refine(e=>64===e.length);Yr.refine(e=>40===e.length);const ni=Yr.refine(e=>64===e.length),ri=Yr.refine(e=>66===e.length),ii=Yr.refine(e=>128===e.length);qr([Yr,Wr]);const si=qr([ni,Jr]);
13
13
  /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
14
- function oi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ai(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function ui(e){if("function"!=typeof e)throw new Error("function expected");return!0}function ci(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function di(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function fi(e){if(!Array.isArray(e))throw new Error("array expected")}function li(e,t){if(!ai(!0,t))throw new Error(`${e}: array of strings expected`)}function hi(e,t){if(!ai(!1,t))throw new Error(`${e}: array of numbers expected`)}function pi(...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 mi(e){const t="string"==typeof e?e.split(""):e,n=t.length;li("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(fi(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=>(fi(t),t.map(t=>{ci("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function gi(e=""){return ci("join",e),{encode:t=>(li("join.decode",t),t.join(e)),decode:t=>(ci("join.decode",t),t.split(e))}}function yi(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(fi(e),!e.length)return[];let r=0;const i=[],s=Array.from(e,e=>{if(di(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),o=s.length;for(;;){let e=0,a=!0;for(let i=r;i<o;i++){const o=s[i],u=t*e,c=u+o;if(!Number.isSafeInteger(c)||u/t!==e||c-o!==u)throw new Error("convertRadix: carry overflow");const d=c/n;e=c%n;const f=Math.floor(d);if(s[i]=f,!Number.isSafeInteger(f)||f*n+e!==c)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=i)}if(i.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}qr([ri,ei]),qr([ii,ti]),Br().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),Br().regex(/^[a-zA-Z0-9+/]+={0,2}$/),Br().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),Br().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const _i=(e,t)=>0===t?e:_i(t,e%t),vi=(e,t)=>e+(t-_i(e,t)),wi=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function bi(e,t,n,r){if(fi(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(vi(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${vi(t,n)}`);let i=0,s=0;const o=wi[t],a=wi[n]-1,u=[];for(const r of e){if(di(r),r>=o)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)u.push((i>>s-n&a)>>>0);const e=wi[s];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-s&a,!r&&s>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&u.push(i>>>0),u}function xi(e,t=!1){if(di(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(vi(8,e)>32||vi(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!oi(n))throw new Error("radix2.encode input should be Uint8Array");return bi(Array.from(n),8,e,!t)},decode:n=>(hi("radix2.decode",n),Uint8Array.from(bi(n,e,8,t)))}}function Ei(e){return ui(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const ki=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!oi(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(ci("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)}:pi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return di(e),ci("padding",t),{encode(n){for(li("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){li("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),gi("")),Oi=pi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),gi("")),Si=(Ai="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",pi(function(e){return di(e),{encode:t=>{if(!oi(t))throw new Error("radix.encode input should be Uint8Array");return yi(Array.from(t),256,e)},decode:t=>(hi("radix.decode",t),Uint8Array.from(yi(t,e,256)))}}(58),mi(Ai),gi("")));var Ai;const Pi=e=>{return pi((n=t=>e(e(t)),di(t=4),ui(n),{encode(e){if(!oi(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(!oi(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),s=n(r).slice(0,t);for(let e=0;e<t;e++)if(s[e]!==i[e])throw new Error("Invalid checksum");return r}}),Si);var t,n},Ii=pi(mi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),gi("")),Ti=[996825010,642813549,513874426,1027748829,705979059];function Ni(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Ti.length;e++)1==(t>>e&1)&&(n^=Ti[e]);return n}function Ci(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=Ni(i)^n>>5}i=Ni(i);for(let t=0;t<r;t++)i=Ni(i)^31&e.charCodeAt(t);for(let e of t)i=Ni(i)^e;for(let e=0;e<6;e++)i=Ni(i);return i^=n,Ii.encode(bi([i%wi[30]],30,5,!1))}function $i(e){const t="bech32"===e?1:734539939,n=xi(5),r=n.decode,i=n.encode,s=Ei(r);function o(e,n,r=90){ci("bech32.encode prefix",e),oi(n)&&(n=Array.from(n)),hi("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const s=i+7+n.length;if(!1!==r&&s>r)throw new TypeError(`Length ${s} exceeds limit ${r}`);const o=e.toLowerCase(),a=Ci(o,n,t);return`${o}1${Ii.encode(n)}${a}`}function a(e,n=90){ci("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 s=i.lastIndexOf("1");if(0===s||-1===s)throw new Error('Letter "1" must be present between prefix and data only');const o=i.slice(0,s),a=i.slice(s+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const u=Ii.decode(a).slice(0,-6),c=Ci(o,u,t);if(!a.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:o,words:u}}return{encode:o,decode:a,encodeFromBytes:function(e,t){return o(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Ei(a),fromWords:r,fromWordsUnsafe:s,toWords:i}}const Ri=$i("bech32"),Bi=$i("bech32m");var Ui,ji,Zi,zi,Fi;function Li(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Di(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),Pi(ee).encode(e)),e.decode=e=>(b.is_base58(e),Pi(ee).decode(e))}(Ui||(Ui={})),function(e){e.encode=e=>(b.is_u8a(e),ki.encode(e)),e.decode=e=>(b.is_base64(e),ki.decode(e))}(ji||(ji={})),function(e){e.encode=e=>(b.is_u8a(e),Oi.encode(e)),e.decode=e=>(b.is_b64url(e),Oi.decode(e))}(Zi||(Zi={})),function(e){e.to_words=Ri.toWords,e.to_bytes=Ri.fromWords,e.encode=(e,t,n=!1)=>(Li(e),Di(t),Ri.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Ri.decode(e,t))}(zi||(zi={})),function(e){e.to_words=Bi.toWords,e.to_bytes=Bi.fromWords,e.encode=(e,t,n=!1)=>(Li(e),Di(t),Bi.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Bi.decode(e,t))}(Fi||(Fi={}));const Hi={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}$/},qi=0,Vi=1;function Mi(e){const t=function(e){for(const[t,n]of Object.entries(Hi))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=Ui.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}=zi.decode(e),[r,...i]=n;b.ok(r===qi,"bech32 version mismatch");return{data:zi.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Fi.decode(e),[r,...i]=n;b.ok(r===Vi,"bech32m version mismatch");return{data:Fi.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function Ki(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 Ui.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=zi.to_words(t);return zi.encode(e.prefix,[qi,...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=Fi.to_words(t);return Fi.encode(e.prefix,[Vi,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const Wi=[["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","p2w-pkh","main",20,"bech32",0],["tb","p2w-pkh","testnet",20,"bech32",0],["bcrt","p2w-pkh","regtest",20,"bech32",0],["bc","p2w-sh","main",32,"bech32",0],["tb","p2w-sh","testnet",32,"bech32",0],["bcrt","p2w-sh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function Gi(e,t){for(const[n,r,i,s,o,a]of Wi)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:s,format:o,version:a};return null}function Yi(e){const t=function(e){const t=Mi(e);for(const[n,r,i,s,o,a]of Wi){if(o!==t.format)continue;if(s!==t.data.length)continue;if(a!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const u=g.uint(t.data).hex;return{data:t.data,hex:u,type:r,prefix:n,network:i,size:s,format:o,version:a}}throw new Error("address configuration is invalid")}(e),n=function(e,t){switch(t){case"p2pkh":return function(e){return{script_hex:"76a914"+e+"88ac",script_asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{script_hex:"a914"+e+"87",script_asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2w-pkh":return function(e){return{script_hex:"0014"+e,script_asm:["OP_0",e]}}(e);case"p2w-sh":return function(e){return{script_hex:"0020"+e,script_asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{script_hex:"5120"+e,script_asm:["OP_1",e]}}(e);default:throw new Error("unrecognized script type: "+t)}}(t.hex,t.type);return{...t,...n}}const Qi="p2pkh";var Xi;function Ji(e,t="main"){return es(Jt(g.bytes(e)),t)}function es(e,t="main"){const n=g.bytes(e),r=Gi(t,Qi);return b.exists(r,`unrecognized address config: ${Qi} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"base58",version:r.version})}function ts(e){const t=Yi(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${Qi}`),t}!function(e){e.create=Ji,e.encode=es,e.decode=ts}(Xi||(Xi={}));const ns="p2sh";var rs;function is(e,t="main"){return ss(Jt(g.bytes(e)),t)}function ss(e,t="main"){const n=g.bytes(e),r=Gi(t,ns);return b.exists(r,`unrecognized address config: ${ns} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"base58",version:r.version})}function os(e){const t=Yi(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${ns}`),t}!function(e){e.create=is,e.encode=ss,e.decode=os}(rs||(rs={}));const as="p2w-pkh";var us;function cs(e,t="main"){const n=g.bytes(e);b.size(n,33,`invalid payload size: ${n.length} !== 33`);return ds(Jt(n),t)}function ds(e,t="main"){const n=g.bytes(e),r=Gi(t,as);return b.exists(r,`unrecognized address config: ${as} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32",prefix:r.prefix})}function fs(e){const t=Yi(e);return b.ok("p2w-pkh"===t.type,`address type mismatch: ${t.type} !== ${as}`),t}!function(e){e.create=cs,e.encode=ds,e.decode=fs}(us||(us={}));const ls="p2w-sh";var hs;function ps(e,t="main"){return ms(en(g.bytes(e)),t)}function ms(e,t="main"){const n=g.bytes(e),r=Gi(t,ls);return b.exists(r,`unrecognized address config: ${ls} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32",prefix:r.prefix})}function gs(e){const t=Yi(e);return b.ok("p2w-sh"===t.type,`address type mismatch: ${t.type} !== ${ls}`),t}!function(e){e.create=ps,e.encode=ms,e.decode=gs}(hs||(hs={}));const ys="p2tr";var _s,vs;function ws(e,t="main"){const n=g.bytes(e),r=Gi(t,ys);return b.exists(r,`unrecognized address config: ${ys} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32m",prefix:r.prefix})}function bs(e){const t=Yi(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${ys}`),t}!function(e){e.encode=ws,e.decode=bs}(_s||(_s={})),function(e){e.P2PKH=Xi,e.P2SH=rs,e.P2WPKH=us,e.P2WSH=hs,e.P2TR=_s,e.parse=Yi}(vs||(vs={}));var xs=Object.freeze({__proto__:null,get AddressTool(){return vs},get P2PKH(){return Xi},get P2SH(){return rs},get P2TR(){return _s},get P2WPKH(){return us},get P2WSH(){return hs},parse_address:Yi});const Es=5e8;var ks,Os;function Ss(e){switch(e.type){case"timelock":return b.ok(e.stamp>=Es,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<Es,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function As(e){return isNaN(e)||e<=0?null:e<Es?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function Ps(e,t=0){return`${e}i${t}`}function Is(e){Ns(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function Ts(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function Ns(e){if(!Ts(e))throw new Error(`invalid inscription id: ${e}`)}function Cs(e,t){return`${e}:${t}`}function $s(e){Bs(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function Rs(e){return null!==e.match(/^\d+:\d+$/)}function Bs(e){if(!Rs(e))throw new Error(`invalid rune id: ${e}`)}function Us(e,t){return`${e}:${t}`}function js(e){zs(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function Zs(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function zs(e){if(!Zs(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=Ss,e.decode=As}(ks||(ks={})),function(e){e.outpoint={encode:Us,decode:js,verify:Zs,assert:zs},e.record_id={encode:Ps,decode:Is,verify:Ts,assert:Ns},e.rune_id={encode:Cs,decode:$s,verify:Rs,assert:Bs}}(Os||(Os={}));const Fs={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 Ls(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Fs))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ds(e){for(const[t,n]of Object.entries(Fs))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Hs(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 qs(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 Vs=520;function Ms(e,t=!1){if(0===e.length)return g.num(0,1);const n=[];for(const t of e)n.push(Ks(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")):r}function Ks(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ds(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>Vs){let e;e=Ws(t),e=e.map(e=>Gs(e)),t=g.join(e)}else t=Gs(t);return t}function Ws(e){const t=[],n=new y(e);for(;n.size>Vs;)t.push(n.read(Vs));return t.push(n.read(n.size)),t}function Gs(e){const t=Ys(e.length);return g.join([t,e])}function Ys(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<=Vs:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function Qs(e){const t=new y(e),n=[],r=t.size;let i,s,o,a=0;for(;a<r;)switch(i=t.read(1).num,s=Hs(i),a++,s){case"varint":n.push(t.read(i).hex),a+=i;break;case"pushdata1":o=t.read(1).reverse().num,n.push(t.read(o).hex),a+=o+1;break;case"pushdata2":o=t.read(2).reverse().num,n.push(t.read(o).hex),a+=o+2;break;case"pushdata4":o=t.read(4).reverse().num,n.push(t.read(o).hex),a+=o+4;break;case"opcode":if(!qs(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Ls(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Xs(e){try{return Qs(e).length>0}catch{return!1}}const Js=BigInt(0),eo=BigInt(1),to=BigInt(26);var no;function ro(e){const t=function(e){const t=Qs(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(oo)}function io(e){return g.join(e.map(so))}function so(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=uo(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=uo(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=fo(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=fo(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=Js;for(const e of t)e>="A"&&e<="Z"&&(n=n*to+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=eo,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 y(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"),Ms(t)}function oo(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=ho(e[n+1]),n+=1;break;case"OP_2":t.pointer=lo(e[n+1]),n+=1;break;case"OP_3":t.parent=co(e[n+1]),n+=1;break;case"OP_11":t.delegate=co(e[n+1]),n+=1;break;case"OP_13":t.rune=mo(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=ao(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=lo(e[n+1]),n+=1;break;case"OP_0":return t.content=po(e.slice(n+1)),t}return t}function ao(e){return g.bytes(e).hex}function uo(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 co(e){const t=g.bytes(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function fo(e){return g.num(e).reverse().hex}function lo(e){return g.bytes(e).reverse().num}function ho(e){return g.bytes(e).str}function po(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function mo(e){let t=g.bytes(e).reverse().big;t+=eo;let n="";for(;t>Js;){const e=t%to;if(e===Js)n="Z"+n,t=t/to-eo;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=to}}return n}!function(e){e.encode=io,e.decode=ro}(no||(no={}));const go=4194304,yo=65535,_o=65535;var vo;function wo(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>_o)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&yo)>>>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>_o)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(go|t&yo)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function bo(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&yo;if(t&go){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>_o)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=wo,e.decode=bo}(vo||(vo={}));var xo,Eo=Object.freeze({__proto__:null,get InscriptionUtil(){return no},get LocktimeField(){return ks},get RefPointer(){return Os},get SequenceField(){return vo},decode_inscription:ro,decode_locktime:As,decode_sequence:bo,encode_inscription:io,encode_locktime:Ss,encode_sequence:wo});function ko(e){return g.bytes(e).prefix_varint("le").hex}function Oo(e){return[...("string"==typeof e?e:g.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])}!function(e){e.prefix_size=ko,e.decode=Qs,e.encode=Ms,e.is_valid=Xs,e.get_pubkeys=Oo,e.OPCODES=Fs}(xo||(xo={}));var So=Object.freeze({__proto__:null,OPCODE_MAP:Fs,get ScriptUtil(){return xo},decode_script:Qs,encode_script:Ms,encode_script_word:Ks,get_asm_code:Ds,get_op_code:Ls,get_op_type:Hs,get_size_varint:Ys,is_valid_op:qs,is_valid_script:Xs,parse_script_pubkeys:Oo,prefix_script_size:ko,prefix_word_size:Gs,split_script_word:Ws});function Ao(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function Po(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 Io(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return en(g.hex(t).prefix_varint("be"))}}const To={TXID:"00".repeat(32),VOUT:4294967295},No={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},Co=[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],$o={p2pkh:/^76a914[0-9a-f]{40}88ac$/i,p2sh:/^a914[0-9a-f]{40}87$/i,p2wpkh:/^0014[0-9a-f]{40}$/i,p2wsh:/^0020[0-9a-f]{64}$/i,p2tr:/^5120[0-9a-f]{64}$/i,opreturn:/^6a[0-9a-f]{2,}$/i},Ro=[1,2,3,129,130,131],Bo=[0,...Ro];var Uo=Object.freeze({__proto__:null,COINBASE:To,DEFAULT:No,LOCK_SCRIPT_REGEX:$o,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:Ro,SIGHASH_TAPROOT:Bo,TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:Co,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});const jo=qr([Dr(si),si]),Zo=Hr({pubkey:si,leaves:jo.array().optional(),target:si.optional(),version:Gr.optional()});var zo=Object.freeze({__proto__:null,config:Zo,taptree:jo});const Fo=jr().min(0n).max(2100000000000000n),Lo=Hr({value:Fo,script_pk:Yr}),Do=Hr({coinbase:Yr.nullable(),txid:ni,vout:Gr,prevout:Lo.nullable(),script_sig:Yr.nullable(),sequence:Gr,witness:Dr(Yr)}),Ho=Hr({version:Gr,vin:Dr(Do),vout:Dr(Lo),locktime:Gr}),qo=Lo.extend({value:qr([Gr,Fo])}),Vo=Do.extend({coinbase:Yr.nullable().optional(),prevout:qo.nullable().optional(),script_sig:Yr.nullable().optional(),sequence:qr([Yr,Gr]).optional(),witness:Dr(Yr).optional()}),Mo=Hr({version:Gr.optional(),vin:Dr(Vo),vout:Dr(qo),locktime:Gr.optional()});var Ko=Object.freeze({__proto__:null,tx_data:Ho,tx_input:Do,tx_output:Lo,tx_template:Mo,vin_template:Vo,vout_template:qo}),Wo=Object.freeze({__proto__:null,taproot:zo,tx:Ko});function Go(e){Mo.parse(e)}function Yo(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Qo(e){Ho.parse(e)}function Xo(e){Vo.parse(e)}function Jo(e){qo.parse(e)}function ea(e,t=!0){Qo(e);const{version:n,vin:r,vout:i,locktime:s}=e,o=[ta(n)];if(t&&o.push(g.hex("0001")),o.push(sa(r)),o.push(ua(i)),t)for(const e of r)o.push(da(e.witness));return o.push(fa(s)),g.join(o)}function ta(e){return g.num(e,4).reverse()}function na(e){return g.hex(e,32).reverse()}function ra(e){return g.num(e,4).reverse()}function ia(e){return g.num(e,4).reverse()}function sa(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(oa(n));return g.join(t)}function oa(e){return null!==e.coinbase?g.join([na(To.TXID),ra(To.VOUT),la(e.coinbase),ia(e.sequence)]):g.join([na(e.txid),ra(e.vout),la(e.script_sig),ia(e.sequence)])}function aa(e){return g.big(e,8).reverse()}function ua(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(ca(n));return g.join(t)}function ca(e){const{value:t,script_pk:n}=e;return g.join([aa(t),la(n)])}function da(e){const t=[g.varint(e.length)];for(const n of e)t.push(la(n));return g.join(t)}function fa(e){return g.num(e,4).reverse()}function la(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function ha(e){for(const[t,n]of Object.entries($o))if(n.test(e))return t;return"unknown"}function pa(e){switch(e.slice(0,4)){case"0014":return 0;case"5120":return 1;default:return null}}function ma(e){if(!w.exists(e))return No.SEQUENCE;if(w.is_hex(e))return g.hex(e,4).reverse().num;if(w.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function ga(e){if(w.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function ya(e){return{script_pk:e.script_pk,value:ga(e.value)}}function _a(e){Xo(e),b.exists(e.coinbase,"coinbase is required");const t=To.TXID,n=To.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:ma(e.sequence),witness:i,txid:t,vout:n}}function va(e){Xo(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:ma(e.sequence),witness:i}}function wa(e){Xo(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:ya(e.prevout),script_sig:r,sequence:ma(e.sequence),witness:i}}function ba(e){return e.coinbase?_a(e):e.prevout?wa(e):va(e)}function xa(e){Jo(e);return{script_pk:e.script_pk,value:ga(e.value)}}function Ea(e){Go(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??No.LOCKTIME,i=e.version??No.VERSION;return{locktime:r,vin:t.map(e=>ba(e)),vout:n.map(e=>xa(e)),version:i}}function ka(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new y(e),r=function(e){return e.read(4).reverse().to_num()}(n),i=!!t&&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),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Oa(e);t.push(n)}return t}(n),o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(Sa(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${v(e)}`)}return t}(n);if(i)for(const e of s)e.witness=Aa(n);const a=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:s,vout:o,locktime:a}}function Oa(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=Pa(e),i=e.read(4).reverse().num,s=[];return t===To.TXID&&n===To.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:s}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:s}}function Sa(e){const t=e.read(8).reverse().big,n=Pa(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function Aa(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Pa(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function Pa(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function Ia(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=ka(e):(Go(e),n=Ea(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=xa(n)}}return n}var Ta=Object.freeze({__proto__:null,assert_has_prevouts:Yo,assert_tx_data:Qo,assert_tx_input:function(e){Do.parse(e)},assert_tx_output:function(e){Lo.parse(e)},assert_tx_spend_data:function(e){Qo(e),Yo(e.vin)},assert_tx_template:Go,assert_vin_template:Xo,assert_vout_template:Jo,create_coinbase_input:_a,create_spend_input:wa,create_tx:Ea,create_tx_input:ba,create_tx_output:xa,create_virtual_input:va,decode_tx:ka,encode_script_data:la,encode_tx:ea,encode_tx_inputs:sa,encode_tx_locktime:fa,encode_tx_outputs:ua,encode_tx_version:ta,encode_tx_vout:ca,encode_txin_sequence:ia,encode_txin_txid:na,encode_txin_vout:ra,encode_vin:oa,encode_vin_witness:da,encode_vout_value:aa,get_prevouts:function(e){Go(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+da(t).length,0)},get_tx_value:function(e){const t=e.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),n=e.vout.reduce((e,t)=>e+t.value,0n);return{fees:t>n?t-n:0n,vin:t,vout:n}},get_txhash:function(e){return Go(e),tn(ea(e,!0)).reverse().hex},get_txid:function(e){return Go(e),tn(ea(e,!1)).reverse().hex},get_txin_size:function(e){return oa(e).length},get_txout_size:function(e){return ca(e).length},get_txsize:function(e){const t=Ia(e),n=ea(t,!1).length,r=ea(t,!0).length,i=3*n+r,s=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+s,weight:i}},get_vin_size:function(e){return sa(e).length},get_vout_info:function(e){return{type:ha(e.script_pk),version:pa(e.script_pk)}},get_vout_size:function(e){return ua(e).length},get_vout_type:ha,get_vout_version:pa,get_vsize:function(e){const t=g.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},is_return_script:function(e){return e.startsWith("6a")},normalize_prevout:ya,normalize_sequence:ma,normalize_value:ga,parse_tx:Ia,read_payload:Pa,serialize_tx:function(e){const t=Ia(e),n=t.version,r=t.locktime,i=[],s=[];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)s.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:s}}});function Na(e,t={}){const{sigflag:n=1,txindex:r}=t,i=Ia(e),s=!(128&~n),o=n%128;if(!Ro.includes(o))throw new Error("Invalid hash type: "+String(n));const{version:a,vin:u,vout:c,locktime:d}=i,f=Po(i,t),{txid:l,vout:h,prevout:p,sequence:m}=f,{value:y}=p??{};if(void 0===y)throw new Error("Prevout value is empty!");let{pubkey:_,script:v}=t;if(void 0===v&&void 0!==_){const e=Jt(_).hex;v=`76a914${String(e)}88ac`}if(void 0===v)throw new Error("No pubkey / script has been set!");if(Qs(v).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const w=[ta(a),Ca(u,s),$a(u,o,s),na(l),ra(h),ko(v),aa(y),ia(m),Ra(c,o,r),fa(d),g.num(n,4).reverse()];return tn(g.join(w))}function Ca(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(na(t)),n.push(ra(r));return tn(g.join(n))}function $a(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(ia(t));return tn(g.join(r))}function Ra(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(aa(t)),r.push(ko(n));return tn(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(aa(t)),r.push(ko(i)),tn(g.join(r))}return g.num(0,32)}function Ba(e,t=192){return Ua(ko(e),t)}function Ua(e,t=192){return nn("TapLeaf",Za(t),e)}function ja(e,t){return t<e&&([e,t]=[t,e]),nn("TapBranch",e,t)}function Za(e=192){return 254&e}function za(e,t=new Uint8Array){return b.size(e,32),nn("TapTweak",e,t)}function Fa(e,t={}){return nn("TapSighash",La(e,t))}function La(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:s=0,key_version:o=0,separator_pos:a=4294967295}=t,u=Ia(e),{version:c,vin:d,vout:f,locktime:l}=u,h=Po(u,t),{txid:p,vout:m,sequence:y,witness:_=[]}=h;if(!Bo.includes(i))throw new Error("Invalid hash type: "+String(i));if(s<0||s>127)throw new Error("Extention flag out of range: "+String(s));let{extension:v}=t;void 0!==n&&(v=Ba(n).hex);const w=!(128&~i),x=Io(_),E=2*(s+(void 0!==v?1:0))+(void 0!==x?1:0),k=[g.num(0,1),g.num(i,1),ta(c),fa(l)];if(!w){const e=d.map(e=>Ao(e));k.push(Da(d),qa(e),Va(e),Ha(d))}if(((3&i)<2||(3&i)>3)&&k.push(Ma(f)),k.push(g.num(E,1)),w){const{value:e,script_pk:t}=Ao(h);k.push(na(p),ra(m),aa(e),la(t),ia(y))}else b.ok("number"==typeof r),k.push(g.num(r,4).reverse());return void 0!==x&&k.push(x),3&~i||(b.ok("number"==typeof r),k.push(Ka(f[r]))),void 0!==v&&k.push(g.bytes(v),g.num(o),g.num(a,4,"le")),g.join(k)}function Da(e){const t=[];for(const{txid:n,vout:r}of e)t.push(na(n)),t.push(ra(r));return en(g.join(t))}function Ha(e){return en(...e.map(e=>ia(e.sequence)))}function qa(e){return en(...e.map(e=>aa(e.value)))}function Va(e){return en(...e.map(e=>la(e.script_pk)))}function Ma(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(aa(n)),t.push(la(r));return en(...t)}function Ka(e){return en(aa(e.value),la(e.script_pk))}var Wa=Object.freeze({__proto__:null,bip143_hash_outputs:Ra,bip143_hash_prevouts:Ca,bip143_hash_sequence:$a,bip341_hash_amounts:qa,bip341_hash_outpoints:Da,bip341_hash_output:Ka,bip341_hash_outputs:Ma,bip341_hash_scripts:Va,bip341_hash_sequence:Ha,get_annex_data:Io,get_prevout:Ao,get_taproot_tx_preimage:La,hash_segwit_tx:Na,hash_taproot_tx:Fa,parse_txinput:Po});function Ga(e){return 0!==e?g.num(e,1).hex:""}var Ya=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=jt(t),r=yt.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,Na(Ia(t),n)).hex+Ga(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=jt(t);return jt($t.sign(n,e))}(e,Fa(Ia(t),n)).hex+Ga(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Qa(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 s=e[i];if(Array.isArray(s)){let[e,i,o]=Qa(s,t);t=i,r.push(e);for(const e of o)n.push(e)}else{const e=g.bytes(s).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 s=ja(r[e],r[e+1]).hex;i.push(s),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=s):t===r[e+1]&&(n.push(r[e]),t=s))}return Qa(i,t,n)}function Xa(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&&Co.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const s=function(e,t){let n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2tr-ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=64&&33===r.length?"p2w-pkh":1===e.length&&void 0!==n&&64===n.length?"p2tr-pk":e.length>1&&void 0!==i&&Xs(i)?"p2w-sh":"unknown"}(t,i),o=function(e){return e.startsWith("p2tr")?1:e.startsWith("p2w")?0:null}(s),a=function(e,t){let n;switch(t){case"p2tr-ts":n=e.at(-1);case"p2w-sh":n=e.at(-1)}return void 0!==n?new g(n).hex:null}(t,s);null!==a&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:a,stack:n,type:s,version:o}}function Ja(e){const t=new y(e),n=t.read(1).num,r=t.read(32).hex,[i,s]=eu(n),o=[];for(;t.size>=32;)o.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:o,parity:s,version:i}}function eu(e){return e%2==0?[e-0,2]:[e-1,3]}function tu(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 nu=192;var ru=Object.freeze({__proto__:null,create_taproot:function(e){Zo.parse(e);const{pubkey:t,version:n=nu}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let s,o=[];if(r.length>0){const[e,t,n]=Qa(r,i);o=n,s=e}else s=i;const a=za(t,s),u=Bt(t,a,"ecdsa"),c=tu(u),d=Ut(u,"bip340"),f=[g.num(n+c),g.bytes(t)];o.length>0&&o.forEach(e=>f.push(e));const l=g.join(f);return{int_key:g.bytes(t).hex,path:o,parity:c,taproot:s??null,cblock:l.hex,tapkey:d.hex,taptweak:a.hex}},encode_leaf_version:Za,encode_tapbranch:ja,encode_tapleaf:Ua,encode_tapscript:Ba,encode_taptweak:za,get_merkle_root:function(e){return Qa(e)[0]},merkleize:Qa,parse_cblock:Ja,parse_cblock_parity:eu,parse_pubkey_parity:tu,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Xa(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=Ja(t);let s=Ba(r,i.version).hex;for(const e of i.path)s=ja(s,e).hex;const o=za(i.int_key,s),a=Bt(i.int_key,o,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:a.hex,tweak:o.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:s}=Ja(n),o=g.join([r,e]);let a=g.bytes(t).hex;for(const e of i)a=ja(a,e).hex;const u=Bt(s,za(s,a),"ecdsa");return o.hex===u.hex}});var iu=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:Xa});return e.ADDRESS=xs,e.CONST=Uo,e.META=Eo,e.SCHEMA=Wo,e.SCRIPT=So,e.SIGHASH=Wa,e.SIGNER=Ya,e.TAPROOT=ru,e.TX=Ta,e.WITNESS=iu,e}({});
14
+ function oi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ai(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function ui(e){if("function"!=typeof e)throw new Error("function expected");return!0}function ci(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function di(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function fi(e){if(!Array.isArray(e))throw new Error("array expected")}function li(e,t){if(!ai(!0,t))throw new Error(`${e}: array of strings expected`)}function hi(e,t){if(!ai(!1,t))throw new Error(`${e}: array of numbers expected`)}function pi(...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 mi(e){const t="string"==typeof e?e.split(""):e,n=t.length;li("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(fi(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=>(fi(t),t.map(t=>{ci("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function gi(e=""){return ci("join",e),{encode:t=>(li("join.decode",t),t.join(e)),decode:t=>(ci("join.decode",t),t.split(e))}}function yi(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(fi(e),!e.length)return[];let r=0;const i=[],s=Array.from(e,e=>{if(di(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),o=s.length;for(;;){let e=0,a=!0;for(let i=r;i<o;i++){const o=s[i],u=t*e,c=u+o;if(!Number.isSafeInteger(c)||u/t!==e||c-o!==u)throw new Error("convertRadix: carry overflow");const d=c/n;e=c%n;const f=Math.floor(d);if(s[i]=f,!Number.isSafeInteger(f)||f*n+e!==c)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=i)}if(i.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}qr([ri,ei]),qr([ii,ti]),Br().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),Br().regex(/^[a-zA-Z0-9+/]+={0,2}$/),Br().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),Br().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const _i=(e,t)=>0===t?e:_i(t,e%t),vi=(e,t)=>e+(t-_i(e,t)),wi=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function bi(e,t,n,r){if(fi(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(vi(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${vi(t,n)}`);let i=0,s=0;const o=wi[t],a=wi[n]-1,u=[];for(const r of e){if(di(r),r>=o)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)u.push((i>>s-n&a)>>>0);const e=wi[s];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-s&a,!r&&s>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&u.push(i>>>0),u}function xi(e,t=!1){if(di(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(vi(8,e)>32||vi(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!oi(n))throw new Error("radix2.encode input should be Uint8Array");return bi(Array.from(n),8,e,!t)},decode:n=>(hi("radix2.decode",n),Uint8Array.from(bi(n,e,8,t)))}}function Ei(e){return ui(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const ki=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!oi(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(ci("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)}:pi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return di(e),ci("padding",t),{encode(n){for(li("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){li("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),gi("")),Oi=pi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),gi("")),Si=(Ai="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",pi(function(e){return di(e),{encode:t=>{if(!oi(t))throw new Error("radix.encode input should be Uint8Array");return yi(Array.from(t),256,e)},decode:t=>(hi("radix.decode",t),Uint8Array.from(yi(t,e,256)))}}(58),mi(Ai),gi("")));var Ai;const Pi=e=>{return pi((n=t=>e(e(t)),di(t=4),ui(n),{encode(e){if(!oi(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(!oi(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),s=n(r).slice(0,t);for(let e=0;e<t;e++)if(s[e]!==i[e])throw new Error("Invalid checksum");return r}}),Si);var t,n},Ii=pi(mi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),gi("")),Ti=[996825010,642813549,513874426,1027748829,705979059];function Ni(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Ti.length;e++)1==(t>>e&1)&&(n^=Ti[e]);return n}function Ci(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=Ni(i)^n>>5}i=Ni(i);for(let t=0;t<r;t++)i=Ni(i)^31&e.charCodeAt(t);for(let e of t)i=Ni(i)^e;for(let e=0;e<6;e++)i=Ni(i);return i^=n,Ii.encode(bi([i%wi[30]],30,5,!1))}function $i(e){const t="bech32"===e?1:734539939,n=xi(5),r=n.decode,i=n.encode,s=Ei(r);function o(e,n,r=90){ci("bech32.encode prefix",e),oi(n)&&(n=Array.from(n)),hi("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const s=i+7+n.length;if(!1!==r&&s>r)throw new TypeError(`Length ${s} exceeds limit ${r}`);const o=e.toLowerCase(),a=Ci(o,n,t);return`${o}1${Ii.encode(n)}${a}`}function a(e,n=90){ci("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 s=i.lastIndexOf("1");if(0===s||-1===s)throw new Error('Letter "1" must be present between prefix and data only');const o=i.slice(0,s),a=i.slice(s+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const u=Ii.decode(a).slice(0,-6),c=Ci(o,u,t);if(!a.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:o,words:u}}return{encode:o,decode:a,encodeFromBytes:function(e,t){return o(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Ei(a),fromWords:r,fromWordsUnsafe:s,toWords:i}}const Ri=$i("bech32"),Bi=$i("bech32m");var Ui,ji,Zi,zi,Fi;function Li(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Di(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),Pi(ee).encode(e)),e.decode=e=>(b.is_base58(e),Pi(ee).decode(e))}(Ui||(Ui={})),function(e){e.encode=e=>(b.is_u8a(e),ki.encode(e)),e.decode=e=>(b.is_base64(e),ki.decode(e))}(ji||(ji={})),function(e){e.encode=e=>(b.is_u8a(e),Oi.encode(e)),e.decode=e=>(b.is_b64url(e),Oi.decode(e))}(Zi||(Zi={})),function(e){e.to_words=Ri.toWords,e.to_bytes=Ri.fromWords,e.encode=(e,t,n=!1)=>(Li(e),Di(t),Ri.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Ri.decode(e,t))}(zi||(zi={})),function(e){e.to_words=Bi.toWords,e.to_bytes=Bi.fromWords,e.encode=(e,t,n=!1)=>(Li(e),Di(t),Bi.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Bi.decode(e,t))}(Fi||(Fi={}));const Hi={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}$/},qi=0,Vi=1;function Mi(e){const t=function(e){for(const[t,n]of Object.entries(Hi))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=Ui.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}=zi.decode(e),[r,...i]=n;b.ok(r===qi,"bech32 version mismatch");return{data:zi.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Fi.decode(e),[r,...i]=n;b.ok(r===Vi,"bech32m version mismatch");return{data:Fi.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function Ki(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 Ui.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=zi.to_words(t);return zi.encode(e.prefix,[qi,...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=Fi.to_words(t);return Fi.encode(e.prefix,[Vi,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const Wi=[["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","p2w-pkh","main",20,"bech32",0],["tb","p2w-pkh","testnet",20,"bech32",0],["bcrt","p2w-pkh","regtest",20,"bech32",0],["bc","p2w-sh","main",32,"bech32",0],["tb","p2w-sh","testnet",32,"bech32",0],["bcrt","p2w-sh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function Gi(e,t){for(const[n,r,i,s,o,a]of Wi)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:s,format:o,version:a};return null}function Yi(e){const t=function(e){const t=Mi(e);for(const[n,r,i,s,o,a]of Wi){if(o!==t.format)continue;if(s!==t.data.length)continue;if(a!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const u=g.uint(t.data).hex;return{data:t.data,hex:u,type:r,prefix:n,network:i,size:s,format:o,version:a}}throw new Error("address configuration is invalid")}(e),n=function(e,t){switch(t){case"p2pkh":return function(e){return{script_hex:"76a914"+e+"88ac",script_asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{script_hex:"a914"+e+"87",script_asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2w-pkh":return function(e){return{script_hex:"0014"+e,script_asm:["OP_0",e]}}(e);case"p2w-sh":return function(e){return{script_hex:"0020"+e,script_asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{script_hex:"5120"+e,script_asm:["OP_1",e]}}(e);default:throw new Error("unrecognized script type: "+t)}}(t.hex,t.type);return{...t,...n}}const Qi="p2pkh";var Xi;function Ji(e,t="main"){return es(Jt(g.bytes(e)),t)}function es(e,t="main"){const n=g.bytes(e),r=Gi(t,Qi);return b.exists(r,`unrecognized address config: ${Qi} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"base58",version:r.version})}function ts(e){const t=Yi(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${Qi}`),t}!function(e){e.create=Ji,e.encode=es,e.decode=ts}(Xi||(Xi={}));const ns="p2sh";var rs;function is(e,t="main"){return ss(Jt(g.bytes(e)),t)}function ss(e,t="main"){const n=g.bytes(e),r=Gi(t,ns);return b.exists(r,`unrecognized address config: ${ns} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"base58",version:r.version})}function os(e){const t=Yi(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${ns}`),t}!function(e){e.create=is,e.encode=ss,e.decode=os}(rs||(rs={}));const as="p2w-pkh";var us;function cs(e,t="main"){const n=g.bytes(e);b.size(n,33,`invalid payload size: ${n.length} !== 33`);return ds(Jt(n),t)}function ds(e,t="main"){const n=g.bytes(e),r=Gi(t,as);return b.exists(r,`unrecognized address config: ${as} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32",prefix:r.prefix})}function fs(e){const t=Yi(e);return b.ok("p2w-pkh"===t.type,`address type mismatch: ${t.type} !== ${as}`),t}!function(e){e.create=cs,e.encode=ds,e.decode=fs}(us||(us={}));const ls="p2w-sh";var hs;function ps(e,t="main"){return ms(en(g.bytes(e)),t)}function ms(e,t="main"){const n=g.bytes(e),r=Gi(t,ls);return b.exists(r,`unrecognized address config: ${ls} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32",prefix:r.prefix})}function gs(e){const t=Yi(e);return b.ok("p2w-sh"===t.type,`address type mismatch: ${t.type} !== ${ls}`),t}!function(e){e.create=ps,e.encode=ms,e.decode=gs}(hs||(hs={}));const ys="p2tr";var _s,vs;function ws(e,t="main"){const n=g.bytes(e),r=Gi(t,ys);return b.exists(r,`unrecognized address config: ${ys} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32m",prefix:r.prefix})}function bs(e){const t=Yi(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${ys}`),t}!function(e){e.encode=ws,e.decode=bs}(_s||(_s={})),function(e){e.P2PKH=Xi,e.P2SH=rs,e.P2WPKH=us,e.P2WSH=hs,e.P2TR=_s,e.parse=Yi}(vs||(vs={}));var xs=Object.freeze({__proto__:null,get AddressTool(){return vs},get P2PKH(){return Xi},get P2SH(){return rs},get P2TR(){return _s},get P2WPKH(){return us},get P2WSH(){return hs},parse_address:Yi});const Es=5e8;var ks,Os;function Ss(e){switch(e.type){case"timelock":return b.ok(e.stamp>=Es,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<Es,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function As(e){return isNaN(e)||e<=0?null:e<Es?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function Ps(e,t=0){return`${e}i${t}`}function Is(e){Ns(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function Ts(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function Ns(e){if(!Ts(e))throw new Error(`invalid inscription id: ${e}`)}function Cs(e,t){return`${e}:${t}`}function $s(e){Bs(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function Rs(e){return null!==e.match(/^\d+:\d+$/)}function Bs(e){if(!Rs(e))throw new Error(`invalid rune id: ${e}`)}function Us(e,t){return`${e}:${t}`}function js(e){zs(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function Zs(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function zs(e){if(!Zs(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=Ss,e.decode=As}(ks||(ks={})),function(e){e.outpoint={encode:Us,decode:js,verify:Zs,assert:zs},e.record_id={encode:Ps,decode:Is,verify:Ts,assert:Ns},e.rune_id={encode:Cs,decode:$s,verify:Rs,assert:Bs}}(Os||(Os={}));const Fs={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 Ls(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Fs))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ds(e){for(const[t,n]of Object.entries(Fs))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Hs(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 qs(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 Vs=520;function Ms(e,t=!1){if(0===e.length)return g.num(0,1);const n=[];for(const t of e)n.push(Ks(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")):r}function Ks(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ds(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>Vs){let e;e=Ws(t),e=e.map(e=>Gs(e)),t=g.join(e)}else t=Gs(t);return t}function Ws(e){const t=[],n=new y(e);for(;n.size>Vs;)t.push(n.read(Vs));return t.push(n.read(n.size)),t}function Gs(e){const t=Ys(e.length);return g.join([t,e])}function Ys(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<=Vs:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function Qs(e){const t=new y(e),n=[],r=t.size;let i,s,o,a=0;for(;a<r;)switch(i=t.read(1).num,s=Hs(i),a++,s){case"varint":n.push(t.read(i).hex),a+=i;break;case"pushdata1":o=t.read(1).reverse().num,n.push(t.read(o).hex),a+=o+1;break;case"pushdata2":o=t.read(2).reverse().num,n.push(t.read(o).hex),a+=o+2;break;case"pushdata4":o=t.read(4).reverse().num,n.push(t.read(o).hex),a+=o+4;break;case"opcode":if(!qs(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Ls(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Xs(e){try{return Qs(e).length>0}catch{return!1}}const Js=BigInt(0),eo=BigInt(1),to=BigInt(26);var no;function ro(e){const t=function(e){const t=Qs(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(oo)}function io(e){return g.join(e.map(so))}function so(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=uo(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=uo(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=fo(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=fo(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=Js;for(const e of t)e>="A"&&e<="Z"&&(n=n*to+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=eo,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 y(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"),Ms(t)}function oo(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=ho(e[n+1]),n+=1;break;case"OP_2":t.pointer=lo(e[n+1]),n+=1;break;case"OP_3":t.parent=co(e[n+1]),n+=1;break;case"OP_11":t.delegate=co(e[n+1]),n+=1;break;case"OP_13":t.rune=mo(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=ao(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=lo(e[n+1]),n+=1;break;case"OP_0":return t.content=po(e.slice(n+1)),t}return t}function ao(e){return g.bytes(e).hex}function uo(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 co(e){const t=g.bytes(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function fo(e){return g.num(e).reverse().hex}function lo(e){return g.bytes(e).reverse().num}function ho(e){return g.bytes(e).str}function po(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function mo(e){let t=g.bytes(e).reverse().big;t+=eo;let n="";for(;t>Js;){const e=t%to;if(e===Js)n="Z"+n,t=t/to-eo;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=to}}return n}!function(e){e.encode=io,e.decode=ro}(no||(no={}));const go=4194304,yo=65535,_o=65535;var vo;function wo(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>_o)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&yo)>>>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>_o)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(go|t&yo)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function bo(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&yo;if(t&go){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>_o)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=wo,e.decode=bo}(vo||(vo={}));var xo,Eo=Object.freeze({__proto__:null,get InscriptionUtil(){return no},get LocktimeField(){return ks},get RefPointer(){return Os},get SequenceField(){return vo},decode_inscription:ro,decode_locktime:As,decode_sequence:bo,encode_inscription:io,encode_locktime:Ss,encode_sequence:wo});function ko(e){return g.bytes(e).prefix_varint("le").hex}function Oo(e){return[...("string"==typeof e?e:g.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])}!function(e){e.prefix_size=ko,e.decode=Qs,e.encode=Ms,e.is_valid=Xs,e.get_pubkeys=Oo,e.OPCODES=Fs}(xo||(xo={}));var So=Object.freeze({__proto__:null,OPCODE_MAP:Fs,get ScriptUtil(){return xo},decode_script:Qs,encode_script:Ms,encode_script_word:Ks,get_asm_code:Ds,get_op_code:Ls,get_op_type:Hs,get_size_varint:Ys,is_valid_op:qs,is_valid_script:Xs,parse_script_pubkeys:Oo,prefix_script_size:ko,prefix_word_size:Gs,split_script_word:Ws});function Ao(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function Po(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 Io(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return en(g.hex(t).prefix_varint("be"))}}const To={TXID:"00".repeat(32),VOUT:4294967295},No={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},Co=[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],$o={p2pkh:/^76a914[0-9a-f]{40}88ac$/i,p2sh:/^a914[0-9a-f]{40}87$/i,p2wpkh:/^0014[0-9a-f]{40}$/i,p2wsh:/^0020[0-9a-f]{64}$/i,p2tr:/^5120[0-9a-f]{64}$/i,opreturn:/^6a[0-9a-f]{2,}$/i},Ro=[1,2,3,129,130,131],Bo=[0,...Ro];var Uo=Object.freeze({__proto__:null,COINBASE:To,DEFAULT:No,LOCK_SCRIPT_REGEX:$o,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:Ro,SIGHASH_TAPROOT:Bo,TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:Co,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});const jo=qr([Dr(si),si]),Zo=Hr({pubkey:si,leaves:jo.array().optional(),target:si.optional(),version:Gr.optional()});var zo=Object.freeze({__proto__:null,config:Zo,taptree:jo});const Fo=jr().min(0n).max(2100000000000000n),Lo=Hr({value:Fo,script_pk:Yr}),Do=Hr({coinbase:Yr.nullable(),txid:ni,vout:Gr,prevout:Lo.nullable(),script_sig:Yr.nullable(),sequence:Gr,witness:Dr(Yr)}),Ho=Hr({version:Gr,vin:Dr(Do),vout:Dr(Lo),locktime:Gr}),qo=Lo.extend({value:qr([Gr,Fo])}),Vo=Do.extend({coinbase:Yr.nullable().optional(),prevout:qo.nullable().optional(),script_sig:Yr.nullable().optional(),sequence:qr([Yr,Gr]).optional(),witness:Dr(Yr).optional()}),Mo=Hr({version:Gr.optional(),vin:Dr(Vo),vout:Dr(qo),locktime:Gr.optional()});var Ko=Object.freeze({__proto__:null,tx_data:Ho,tx_input:Do,tx_output:Lo,tx_template:Mo,vin_template:Vo,vout_template:qo}),Wo=Object.freeze({__proto__:null,taproot:zo,tx:Ko});function Go(e){Mo.parse(e)}function Yo(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Qo(e){Ho.parse(e)}function Xo(e){Vo.parse(e)}function Jo(e){qo.parse(e)}function ea(e,t=!0){Qo(e);const{version:n,vin:r,vout:i,locktime:s}=e,o=[ta(n)];if(t&&o.push(g.hex("0001")),o.push(sa(r)),o.push(ua(i)),t)for(const e of r)o.push(da(e.witness));return o.push(fa(s)),g.join(o)}function ta(e){return g.num(e,4).reverse()}function na(e){return g.hex(e,32).reverse()}function ra(e){return g.num(e,4).reverse()}function ia(e){return g.num(e,4).reverse()}function sa(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(oa(n));return g.join(t)}function oa(e){return null!==e.coinbase?g.join([na(To.TXID),ra(To.VOUT),la(e.coinbase),ia(e.sequence)]):g.join([na(e.txid),ra(e.vout),la(e.script_sig),ia(e.sequence)])}function aa(e){return g.big(e,8).reverse()}function ua(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(ca(n));return g.join(t)}function ca(e){const{value:t,script_pk:n}=e;return g.join([aa(t),la(n)])}function da(e){const t=[g.varint(e.length)];for(const n of e)t.push(la(n));return g.join(t)}function fa(e){return g.num(e,4).reverse()}function la(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function ha(e){const t=g.bytes(e).hex;for(const[e,n]of Object.entries($o))if(n.test(t))return e;return null}function pa(e){switch(g.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function ma(e){if(!w.exists(e))return No.SEQUENCE;if(w.is_hex(e))return g.hex(e,4).reverse().num;if(w.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function ga(e){if(w.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function ya(e){return{script_pk:e.script_pk,value:ga(e.value)}}function _a(e){Xo(e),b.exists(e.coinbase,"coinbase is required");const t=To.TXID,n=To.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:ma(e.sequence),witness:i,txid:t,vout:n}}function va(e){Xo(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:ma(e.sequence),witness:i}}function wa(e){Xo(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:ya(e.prevout),script_sig:r,sequence:ma(e.sequence),witness:i}}function ba(e){return e.coinbase?_a(e):e.prevout?wa(e):va(e)}function xa(e){Jo(e);return{script_pk:e.script_pk,value:ga(e.value)}}function Ea(e){Go(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??No.LOCKTIME,i=e.version??No.VERSION;return{locktime:r,vin:t.map(e=>ba(e)),vout:n.map(e=>xa(e)),version:i}}function ka(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new y(e),r=function(e){return e.read(4).reverse().to_num()}(n),i=!!t&&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),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Oa(e);t.push(n)}return t}(n),o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(Sa(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${v(e)}`)}return t}(n);if(i)for(const e of s)e.witness=Aa(n);const a=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:s,vout:o,locktime:a}}function Oa(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=Pa(e),i=e.read(4).reverse().num,s=[];return t===To.TXID&&n===To.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:s}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:s}}function Sa(e){const t=e.read(8).reverse().big,n=Pa(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function Aa(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Pa(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function Pa(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function Ia(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=ka(e):(Go(e),n=Ea(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=xa(n)}}return n}var Ta=Object.freeze({__proto__:null,assert_has_prevouts:Yo,assert_tx_data:Qo,assert_tx_input:function(e){Do.parse(e)},assert_tx_output:function(e){Lo.parse(e)},assert_tx_spend_data:function(e){Qo(e),Yo(e.vin)},assert_tx_template:Go,assert_vin_template:Xo,assert_vout_template:Jo,create_coinbase_input:_a,create_spend_input:wa,create_tx:Ea,create_tx_input:ba,create_tx_output:xa,create_virtual_input:va,decode_tx:ka,encode_script_data:la,encode_tx:ea,encode_tx_inputs:sa,encode_tx_locktime:fa,encode_tx_outputs:ua,encode_tx_version:ta,encode_tx_vout:ca,encode_txin_sequence:ia,encode_txin_txid:na,encode_txin_vout:ra,encode_vin:oa,encode_vin_witness:da,encode_vout_value:aa,get_prevouts:function(e){Go(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+da(t).length,0)},get_tx_value:function(e){const t=e.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),n=e.vout.reduce((e,t)=>e+t.value,0n);return{fees:t>n?t-n:0n,vin:t,vout:n}},get_txhash:function(e){return Go(e),tn(ea(e,!0)).reverse().hex},get_txid:function(e){return Go(e),tn(ea(e,!1)).reverse().hex},get_txin_size:function(e){return oa(e).length},get_txout_size:function(e){return ca(e).length},get_txsize:function(e){const t=Ia(e),n=ea(t,!1).length,r=ea(t,!0).length,i=3*n+r,s=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+s,weight:i}},get_vin_size:function(e){return sa(e).length},get_vout_script_info:function(e){return{type:ha(e),version:pa(e)}},get_vout_script_type:ha,get_vout_script_version:pa,get_vout_size:function(e){return ua(e).length},get_vsize:function(e){const t=g.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},is_return_script:function(e){return 106===g.bytes(e).at(0)},normalize_prevout:ya,normalize_sequence:ma,normalize_value:ga,parse_tx:Ia,read_payload:Pa,serialize_tx:function(e){const t=Ia(e),n=t.version,r=t.locktime,i=[],s=[];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)s.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:s}}});function Na(e,t={}){const{sigflag:n=1,txindex:r}=t,i=Ia(e),s=!(128&~n),o=n%128;if(!Ro.includes(o))throw new Error("Invalid hash type: "+String(n));const{version:a,vin:u,vout:c,locktime:d}=i,f=Po(i,t),{txid:l,vout:h,prevout:p,sequence:m}=f,{value:y}=p??{};if(void 0===y)throw new Error("Prevout value is empty!");let{pubkey:_,script:v}=t;if(void 0===v&&void 0!==_){const e=Jt(_).hex;v=`76a914${String(e)}88ac`}if(void 0===v)throw new Error("No pubkey / script has been set!");if(Qs(v).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const w=[ta(a),Ca(u,s),$a(u,o,s),na(l),ra(h),ko(v),aa(y),ia(m),Ra(c,o,r),fa(d),g.num(n,4).reverse()];return tn(g.join(w))}function Ca(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(na(t)),n.push(ra(r));return tn(g.join(n))}function $a(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(ia(t));return tn(g.join(r))}function Ra(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(aa(t)),r.push(ko(n));return tn(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(aa(t)),r.push(ko(i)),tn(g.join(r))}return g.num(0,32)}function Ba(e,t=192){return Ua(ko(e),t)}function Ua(e,t=192){return nn("TapLeaf",Za(t),e)}function ja(e,t){return t<e&&([e,t]=[t,e]),nn("TapBranch",e,t)}function Za(e=192){return 254&e}function za(e,t=new Uint8Array){return b.size(e,32),nn("TapTweak",e,t)}function Fa(e,t={}){return nn("TapSighash",La(e,t))}function La(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:s=0,key_version:o=0,separator_pos:a=4294967295}=t,u=Ia(e),{version:c,vin:d,vout:f,locktime:l}=u,h=Po(u,t),{txid:p,vout:m,sequence:y,witness:_=[]}=h;if(!Bo.includes(i))throw new Error("Invalid hash type: "+String(i));if(s<0||s>127)throw new Error("Extention flag out of range: "+String(s));let{extension:v}=t;void 0!==n&&(v=Ba(n).hex);const w=!(128&~i),x=Io(_),E=2*(s+(void 0!==v?1:0))+(void 0!==x?1:0),k=[g.num(0,1),g.num(i,1),ta(c),fa(l)];if(!w){const e=d.map(e=>Ao(e));k.push(Da(d),qa(e),Va(e),Ha(d))}if(((3&i)<2||(3&i)>3)&&k.push(Ma(f)),k.push(g.num(E,1)),w){const{value:e,script_pk:t}=Ao(h);k.push(na(p),ra(m),aa(e),la(t),ia(y))}else b.ok("number"==typeof r),k.push(g.num(r,4).reverse());return void 0!==x&&k.push(x),3&~i||(b.ok("number"==typeof r),k.push(Ka(f[r]))),void 0!==v&&k.push(g.bytes(v),g.num(o),g.num(a,4,"le")),g.join(k)}function Da(e){const t=[];for(const{txid:n,vout:r}of e)t.push(na(n)),t.push(ra(r));return en(g.join(t))}function Ha(e){return en(...e.map(e=>ia(e.sequence)))}function qa(e){return en(...e.map(e=>aa(e.value)))}function Va(e){return en(...e.map(e=>la(e.script_pk)))}function Ma(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(aa(n)),t.push(la(r));return en(...t)}function Ka(e){return en(aa(e.value),la(e.script_pk))}var Wa=Object.freeze({__proto__:null,bip143_hash_outputs:Ra,bip143_hash_prevouts:Ca,bip143_hash_sequence:$a,bip341_hash_amounts:qa,bip341_hash_outpoints:Da,bip341_hash_output:Ka,bip341_hash_outputs:Ma,bip341_hash_scripts:Va,bip341_hash_sequence:Ha,get_annex_data:Io,get_prevout:Ao,get_taproot_tx_preimage:La,hash_segwit_tx:Na,hash_taproot_tx:Fa,parse_txinput:Po});function Ga(e){return 0!==e?g.num(e,1).hex:""}var Ya=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=jt(t),r=yt.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,Na(Ia(t),n)).hex+Ga(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=jt(t);return jt($t.sign(n,e))}(e,Fa(Ia(t),n)).hex+Ga(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Qa(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 s=e[i];if(Array.isArray(s)){let[e,i,o]=Qa(s,t);t=i,r.push(e);for(const e of o)n.push(e)}else{const e=g.bytes(s).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 s=ja(r[e],r[e+1]).hex;i.push(s),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=s):t===r[e+1]&&(n.push(r[e]),t=s))}return Qa(i,t,n)}function Xa(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&&Co.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const s=function(e,t){let n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2tr-ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=64&&33===r.length?"p2w-pkh":1===e.length&&void 0!==n&&64===n.length?"p2tr-pk":e.length>1&&void 0!==i&&Xs(i)?"p2w-sh":"unknown"}(t,i),o=function(e){return e.startsWith("p2tr")?1:e.startsWith("p2w")?0:null}(s),a=function(e,t){let n;switch(t){case"p2tr-ts":n=e.at(-1);case"p2w-sh":n=e.at(-1)}return void 0!==n?new g(n).hex:null}(t,s);null!==a&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:a,stack:n,type:s,version:o}}function Ja(e){const t=new y(e),n=t.read(1).num,r=t.read(32).hex,[i,s]=eu(n),o=[];for(;t.size>=32;)o.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:o,parity:s,version:i}}function eu(e){return e%2==0?[e-0,2]:[e-1,3]}function tu(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 nu=192;var ru=Object.freeze({__proto__:null,create_taproot:function(e){Zo.parse(e);const{pubkey:t,version:n=nu}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let s,o=[];if(r.length>0){const[e,t,n]=Qa(r,i);o=n,s=e}else s=i;const a=za(t,s),u=Bt(t,a,"ecdsa"),c=tu(u),d=Ut(u,"bip340"),f=[g.num(n+c),g.bytes(t)];o.length>0&&o.forEach(e=>f.push(e));const l=g.join(f);return{int_key:g.bytes(t).hex,path:o,parity:c,taproot:s??null,cblock:l.hex,tapkey:d.hex,taptweak:a.hex}},encode_leaf_version:Za,encode_tapbranch:ja,encode_tapleaf:Ua,encode_tapscript:Ba,encode_taptweak:za,get_merkle_root:function(e){return Qa(e)[0]},merkleize:Qa,parse_cblock:Ja,parse_cblock_parity:eu,parse_pubkey_parity:tu,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Xa(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=Ja(t);let s=Ba(r,i.version).hex;for(const e of i.path)s=ja(s,e).hex;const o=za(i.int_key,s),a=Bt(i.int_key,o,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:a.hex,tweak:o.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:s}=Ja(n),o=g.join([r,e]);let a=g.bytes(t).hex;for(const e of i)a=ja(a,e).hex;const u=Bt(s,za(s,a),"ecdsa");return o.hex===u.hex}});var iu=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:Xa});return e.ADDRESS=xs,e.CONST=Uo,e.META=Eo,e.SCHEMA=Wo,e.SCRIPT=So,e.SIGHASH=Wa,e.SIGNER=Ya,e.TAPROOT=ru,e.TX=Ta,e.WITNESS=iu,e}({});
15
15
  //# sourceMappingURL=script.js.map