@gardenfi/core 2.0.15 → 2.0.16

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/index.cjs CHANGED
@@ -6,7 +6,7 @@
6
6
  */(function(e){const t=ui,r=Os,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=a,e.SlowBuffer=U,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i,a.TYPED_ARRAY_SUPPORT=s(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function s(){try{const h=new Uint8Array(1),f={foo:function(){return 42}};return Object.setPrototypeOf(f,Uint8Array.prototype),Object.setPrototypeOf(h,f),h.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function o(h){if(h>i)throw new RangeError('The value "'+h+'" is invalid for option "size"');const f=new Uint8Array(h);return Object.setPrototypeOf(f,a.prototype),f}function a(h,f,u){if(typeof h=="number"){if(typeof f=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return b(h)}return c(h,f,u)}a.poolSize=8192;function c(h,f,u){if(typeof h=="string")return E(h,f);if(ArrayBuffer.isView(h))return I(h);if(h==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h);if(qe(h,ArrayBuffer)||h&&qe(h.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qe(h,SharedArrayBuffer)||h&&qe(h.buffer,SharedArrayBuffer)))return B(h,f,u);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const y=h.valueOf&&h.valueOf();if(y!=null&&y!==h)return a.from(y,f,u);const v=A(h);if(v)return v;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return a.from(h[Symbol.toPrimitive]("string"),f,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h)}a.from=function(h,f,u){return c(h,f,u)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function l(h){if(typeof h!="number")throw new TypeError('"size" argument must be of type number');if(h<0)throw new RangeError('The value "'+h+'" is invalid for option "size"')}function d(h,f,u){return l(h),h<=0?o(h):f!==void 0?typeof u=="string"?o(h).fill(f,u):o(h).fill(f):o(h)}a.alloc=function(h,f,u){return d(h,f,u)};function b(h){return l(h),o(h<0?0:k(h)|0)}a.allocUnsafe=function(h){return b(h)},a.allocUnsafeSlow=function(h){return b(h)};function E(h,f){if((typeof f!="string"||f==="")&&(f="utf8"),!a.isEncoding(f))throw new TypeError("Unknown encoding: "+f);const u=_(h,f)|0;let y=o(u);const v=y.write(h,f);return v!==u&&(y=y.slice(0,v)),y}function p(h){const f=h.length<0?0:k(h.length)|0,u=o(f);for(let y=0;y<f;y+=1)u[y]=h[y]&255;return u}function I(h){if(qe(h,Uint8Array)){const f=new Uint8Array(h);return B(f.buffer,f.byteOffset,f.byteLength)}return p(h)}function B(h,f,u){if(f<0||h.byteLength<f)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<f+(u||0))throw new RangeError('"length" is outside of buffer bounds');let y;return f===void 0&&u===void 0?y=new Uint8Array(h):u===void 0?y=new Uint8Array(h,f):y=new Uint8Array(h,f,u),Object.setPrototypeOf(y,a.prototype),y}function A(h){if(a.isBuffer(h)){const f=k(h.length)|0,u=o(f);return u.length===0||h.copy(u,0,0,f),u}if(h.length!==void 0)return typeof h.length!="number"||Jt(h.length)?o(0):p(h);if(h.type==="Buffer"&&Array.isArray(h.data))return p(h.data)}function k(h){if(h>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return h|0}function U(h){return+h!=h&&(h=0),a.alloc(+h)}a.isBuffer=function(f){return f!=null&&f._isBuffer===!0&&f!==a.prototype},a.compare=function(f,u){if(qe(f,Uint8Array)&&(f=a.from(f,f.offset,f.byteLength)),qe(u,Uint8Array)&&(u=a.from(u,u.offset,u.byteLength)),!a.isBuffer(f)||!a.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(f===u)return 0;let y=f.length,v=u.length;for(let O=0,L=Math.min(y,v);O<L;++O)if(f[O]!==u[O]){y=f[O],v=u[O];break}return y<v?-1:v<y?1:0},a.isEncoding=function(f){switch(String(f).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(f,u){if(!Array.isArray(f))throw new TypeError('"list" argument must be an Array of Buffers');if(f.length===0)return a.alloc(0);let y;if(u===void 0)for(u=0,y=0;y<f.length;++y)u+=f[y].length;const v=a.allocUnsafe(u);let O=0;for(y=0;y<f.length;++y){let L=f[y];if(qe(L,Uint8Array))O+L.length>v.length?(a.isBuffer(L)||(L=a.from(L)),L.copy(v,O)):Uint8Array.prototype.set.call(v,L,O);else if(a.isBuffer(L))L.copy(v,O);else throw new TypeError('"list" argument must be an Array of Buffers');O+=L.length}return v};function _(h,f){if(a.isBuffer(h))return h.length;if(ArrayBuffer.isView(h)||qe(h,ArrayBuffer))return h.byteLength;if(typeof h!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof h);const u=h.length,y=arguments.length>2&&arguments[2]===!0;if(!y&&u===0)return 0;let v=!1;for(;;)switch(f){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return te(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return Gr(h).length;default:if(v)return y?-1:te(h).length;f=(""+f).toLowerCase(),v=!0}}a.byteLength=_;function m(h,f,u){let y=!1;if((f===void 0||f<0)&&(f=0),f>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,f>>>=0,u<=f))return"";for(h||(h="utf8");;)switch(h){case"hex":return Ve(this,f,u);case"utf8":case"utf-8":return W(this,f,u);case"ascii":return ue(this,f,u);case"latin1":case"binary":return tt(this,f,u);case"base64":return M(this,f,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return st(this,f,u);default:if(y)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),y=!0}}a.prototype._isBuffer=!0;function S(h,f,u){const y=h[f];h[f]=h[u],h[u]=y}a.prototype.swap16=function(){const f=this.length;if(f%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<f;u+=2)S(this,u,u+1);return this},a.prototype.swap32=function(){const f=this.length;if(f%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<f;u+=4)S(this,u,u+3),S(this,u+1,u+2);return this},a.prototype.swap64=function(){const f=this.length;if(f%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<f;u+=8)S(this,u,u+7),S(this,u+1,u+6),S(this,u+2,u+5),S(this,u+3,u+4);return this},a.prototype.toString=function(){const f=this.length;return f===0?"":arguments.length===0?W(this,0,f):m.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(f){if(!a.isBuffer(f))throw new TypeError("Argument must be a Buffer");return this===f?!0:a.compare(this,f)===0},a.prototype.inspect=function(){let f="";const u=e.INSPECT_MAX_BYTES;return f=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(f+=" ... "),"<Buffer "+f+">"},n&&(a.prototype[n]=a.prototype.inspect),a.prototype.compare=function(f,u,y,v,O){if(qe(f,Uint8Array)&&(f=a.from(f,f.offset,f.byteLength)),!a.isBuffer(f))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof f);if(u===void 0&&(u=0),y===void 0&&(y=f?f.length:0),v===void 0&&(v=0),O===void 0&&(O=this.length),u<0||y>f.length||v<0||O>this.length)throw new RangeError("out of range index");if(v>=O&&u>=y)return 0;if(v>=O)return-1;if(u>=y)return 1;if(u>>>=0,y>>>=0,v>>>=0,O>>>=0,this===f)return 0;let L=O-v,Q=y-u;const ve=Math.min(L,Q),ge=this.slice(v,O),Ee=f.slice(u,y);for(let ie=0;ie<ve;++ie)if(ge[ie]!==Ee[ie]){L=ge[ie],Q=Ee[ie];break}return L<Q?-1:Q<L?1:0};function x(h,f,u,y,v){if(h.length===0)return-1;if(typeof u=="string"?(y=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,Jt(u)&&(u=v?0:h.length-1),u<0&&(u=h.length+u),u>=h.length){if(v)return-1;u=h.length-1}else if(u<0)if(v)u=0;else return-1;if(typeof f=="string"&&(f=a.from(f,y)),a.isBuffer(f))return f.length===0?-1:H(h,f,u,y,v);if(typeof f=="number")return f=f&255,typeof Uint8Array.prototype.indexOf=="function"?v?Uint8Array.prototype.indexOf.call(h,f,u):Uint8Array.prototype.lastIndexOf.call(h,f,u):H(h,[f],u,y,v);throw new TypeError("val must be string, number or Buffer")}function H(h,f,u,y,v){let O=1,L=h.length,Q=f.length;if(y!==void 0&&(y=String(y).toLowerCase(),y==="ucs2"||y==="ucs-2"||y==="utf16le"||y==="utf-16le")){if(h.length<2||f.length<2)return-1;O=2,L/=2,Q/=2,u/=2}function ve(Ee,ie){return O===1?Ee[ie]:Ee.readUInt16BE(ie*O)}let ge;if(v){let Ee=-1;for(ge=u;ge<L;ge++)if(ve(h,ge)===ve(f,Ee===-1?0:ge-Ee)){if(Ee===-1&&(Ee=ge),ge-Ee+1===Q)return Ee*O}else Ee!==-1&&(ge-=ge-Ee),Ee=-1}else for(u+Q>L&&(u=L-Q),ge=u;ge>=0;ge--){let Ee=!0;for(let ie=0;ie<Q;ie++)if(ve(h,ge+ie)!==ve(f,ie)){Ee=!1;break}if(Ee)return ge}return-1}a.prototype.includes=function(f,u,y){return this.indexOf(f,u,y)!==-1},a.prototype.indexOf=function(f,u,y){return x(this,f,u,y,!0)},a.prototype.lastIndexOf=function(f,u,y){return x(this,f,u,y,!1)};function $(h,f,u,y){u=Number(u)||0;const v=h.length-u;y?(y=Number(y),y>v&&(y=v)):y=v;const O=f.length;y>O/2&&(y=O/2);let L;for(L=0;L<y;++L){const Q=parseInt(f.substr(L*2,2),16);if(Jt(Q))return L;h[u+L]=Q}return L}function R(h,f,u,y){return gr(te(f,h.length-u),h,u,y)}function z(h,f,u,y){return gr(Rt(f),h,u,y)}function Z(h,f,u,y){return gr(Gr(f),h,u,y)}function C(h,f,u,y){return gr(wr(f,h.length-u),h,u,y)}a.prototype.write=function(f,u,y,v){if(u===void 0)v="utf8",y=this.length,u=0;else if(y===void 0&&typeof u=="string")v=u,y=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(y)?(y=y>>>0,v===void 0&&(v="utf8")):(v=y,y=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const O=this.length-u;if((y===void 0||y>O)&&(y=O),f.length>0&&(y<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");v||(v="utf8");let L=!1;for(;;)switch(v){case"hex":return $(this,f,u,y);case"utf8":case"utf-8":return R(this,f,u,y);case"ascii":case"latin1":case"binary":return z(this,f,u,y);case"base64":return Z(this,f,u,y);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,f,u,y);default:if(L)throw new TypeError("Unknown encoding: "+v);v=(""+v).toLowerCase(),L=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function M(h,f,u){return f===0&&u===h.length?t.fromByteArray(h):t.fromByteArray(h.slice(f,u))}function W(h,f,u){u=Math.min(h.length,u);const y=[];let v=f;for(;v<u;){const O=h[v];let L=null,Q=O>239?4:O>223?3:O>191?2:1;if(v+Q<=u){let ve,ge,Ee,ie;switch(Q){case 1:O<128&&(L=O);break;case 2:ve=h[v+1],(ve&192)===128&&(ie=(O&31)<<6|ve&63,ie>127&&(L=ie));break;case 3:ve=h[v+1],ge=h[v+2],(ve&192)===128&&(ge&192)===128&&(ie=(O&15)<<12|(ve&63)<<6|ge&63,ie>2047&&(ie<55296||ie>57343)&&(L=ie));break;case 4:ve=h[v+1],ge=h[v+2],Ee=h[v+3],(ve&192)===128&&(ge&192)===128&&(Ee&192)===128&&(ie=(O&15)<<18|(ve&63)<<12|(ge&63)<<6|Ee&63,ie>65535&&ie<1114112&&(L=ie))}}L===null?(L=65533,Q=1):L>65535&&(L-=65536,y.push(L>>>10&1023|55296),L=56320|L&1023),y.push(L),v+=Q}return fe(y)}const q=4096;function fe(h){const f=h.length;if(f<=q)return String.fromCharCode.apply(String,h);let u="",y=0;for(;y<f;)u+=String.fromCharCode.apply(String,h.slice(y,y+=q));return u}function ue(h,f,u){let y="";u=Math.min(h.length,u);for(let v=f;v<u;++v)y+=String.fromCharCode(h[v]&127);return y}function tt(h,f,u){let y="";u=Math.min(h.length,u);for(let v=f;v<u;++v)y+=String.fromCharCode(h[v]);return y}function Ve(h,f,u){const y=h.length;(!f||f<0)&&(f=0),(!u||u<0||u>y)&&(u=y);let v="";for(let O=f;O<u;++O)v+=Wr[h[O]];return v}function st(h,f,u){const y=h.slice(f,u);let v="";for(let O=0;O<y.length-1;O+=2)v+=String.fromCharCode(y[O]+y[O+1]*256);return v}a.prototype.slice=function(f,u){const y=this.length;f=~~f,u=u===void 0?y:~~u,f<0?(f+=y,f<0&&(f=0)):f>y&&(f=y),u<0?(u+=y,u<0&&(u=0)):u>y&&(u=y),u<f&&(u=f);const v=this.subarray(f,u);return Object.setPrototypeOf(v,a.prototype),v};function be(h,f,u){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+f>u)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(f,u,y){f=f>>>0,u=u>>>0,y||be(f,u,this.length);let v=this[f],O=1,L=0;for(;++L<u&&(O*=256);)v+=this[f+L]*O;return v},a.prototype.readUintBE=a.prototype.readUIntBE=function(f,u,y){f=f>>>0,u=u>>>0,y||be(f,u,this.length);let v=this[f+--u],O=1;for(;u>0&&(O*=256);)v+=this[f+--u]*O;return v},a.prototype.readUint8=a.prototype.readUInt8=function(f,u){return f=f>>>0,u||be(f,1,this.length),this[f]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(f,u){return f=f>>>0,u||be(f,2,this.length),this[f]|this[f+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(f,u){return f=f>>>0,u||be(f,2,this.length),this[f]<<8|this[f+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(f,u){return f=f>>>0,u||be(f,4,this.length),(this[f]|this[f+1]<<8|this[f+2]<<16)+this[f+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(f,u){return f=f>>>0,u||be(f,4,this.length),this[f]*16777216+(this[f+1]<<16|this[f+2]<<8|this[f+3])},a.prototype.readBigUInt64LE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],y=this[f+7];(u===void 0||y===void 0)&&D(f,this.length-8);const v=u+this[++f]*2**8+this[++f]*2**16+this[++f]*2**24,O=this[++f]+this[++f]*2**8+this[++f]*2**16+y*2**24;return BigInt(v)+(BigInt(O)<<BigInt(32))}),a.prototype.readBigUInt64BE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],y=this[f+7];(u===void 0||y===void 0)&&D(f,this.length-8);const v=u*2**24+this[++f]*2**16+this[++f]*2**8+this[++f],O=this[++f]*2**24+this[++f]*2**16+this[++f]*2**8+y;return(BigInt(v)<<BigInt(32))+BigInt(O)}),a.prototype.readIntLE=function(f,u,y){f=f>>>0,u=u>>>0,y||be(f,u,this.length);let v=this[f],O=1,L=0;for(;++L<u&&(O*=256);)v+=this[f+L]*O;return O*=128,v>=O&&(v-=Math.pow(2,8*u)),v},a.prototype.readIntBE=function(f,u,y){f=f>>>0,u=u>>>0,y||be(f,u,this.length);let v=u,O=1,L=this[f+--v];for(;v>0&&(O*=256);)L+=this[f+--v]*O;return O*=128,L>=O&&(L-=Math.pow(2,8*u)),L},a.prototype.readInt8=function(f,u){return f=f>>>0,u||be(f,1,this.length),this[f]&128?(255-this[f]+1)*-1:this[f]},a.prototype.readInt16LE=function(f,u){f=f>>>0,u||be(f,2,this.length);const y=this[f]|this[f+1]<<8;return y&32768?y|4294901760:y},a.prototype.readInt16BE=function(f,u){f=f>>>0,u||be(f,2,this.length);const y=this[f+1]|this[f]<<8;return y&32768?y|4294901760:y},a.prototype.readInt32LE=function(f,u){return f=f>>>0,u||be(f,4,this.length),this[f]|this[f+1]<<8|this[f+2]<<16|this[f+3]<<24},a.prototype.readInt32BE=function(f,u){return f=f>>>0,u||be(f,4,this.length),this[f]<<24|this[f+1]<<16|this[f+2]<<8|this[f+3]},a.prototype.readBigInt64LE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],y=this[f+7];(u===void 0||y===void 0)&&D(f,this.length-8);const v=this[f+4]+this[f+5]*2**8+this[f+6]*2**16+(y<<24);return(BigInt(v)<<BigInt(32))+BigInt(u+this[++f]*2**8+this[++f]*2**16+this[++f]*2**24)}),a.prototype.readBigInt64BE=Xe(function(f){f=f>>>0,N(f,"offset");const u=this[f],y=this[f+7];(u===void 0||y===void 0)&&D(f,this.length-8);const v=(u<<24)+this[++f]*2**16+this[++f]*2**8+this[++f];return(BigInt(v)<<BigInt(32))+BigInt(this[++f]*2**24+this[++f]*2**16+this[++f]*2**8+y)}),a.prototype.readFloatLE=function(f,u){return f=f>>>0,u||be(f,4,this.length),r.read(this,f,!0,23,4)},a.prototype.readFloatBE=function(f,u){return f=f>>>0,u||be(f,4,this.length),r.read(this,f,!1,23,4)},a.prototype.readDoubleLE=function(f,u){return f=f>>>0,u||be(f,8,this.length),r.read(this,f,!0,52,8)},a.prototype.readDoubleBE=function(f,u){return f=f>>>0,u||be(f,8,this.length),r.read(this,f,!1,52,8)};function xe(h,f,u,y,v,O){if(!a.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(f>v||f<O)throw new RangeError('"value" argument is out of bounds');if(u+y>h.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(f,u,y,v){if(f=+f,u=u>>>0,y=y>>>0,!v){const Q=Math.pow(2,8*y)-1;xe(this,f,u,y,Q,0)}let O=1,L=0;for(this[u]=f&255;++L<y&&(O*=256);)this[u+L]=f/O&255;return u+y},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(f,u,y,v){if(f=+f,u=u>>>0,y=y>>>0,!v){const Q=Math.pow(2,8*y)-1;xe(this,f,u,y,Q,0)}let O=y-1,L=1;for(this[u+O]=f&255;--O>=0&&(L*=256);)this[u+O]=f/L&255;return u+y},a.prototype.writeUint8=a.prototype.writeUInt8=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,1,255,0),this[u]=f&255,u+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,2,65535,0),this[u]=f&255,this[u+1]=f>>>8,u+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,2,65535,0),this[u]=f>>>8,this[u+1]=f&255,u+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,4,4294967295,0),this[u+3]=f>>>24,this[u+2]=f>>>16,this[u+1]=f>>>8,this[u]=f&255,u+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,4,4294967295,0),this[u]=f>>>24,this[u+1]=f>>>16,this[u+2]=f>>>8,this[u+3]=f&255,u+4};function ze(h,f,u,y,v){g(f,y,v,h,u,7);let O=Number(f&BigInt(4294967295));h[u++]=O,O=O>>8,h[u++]=O,O=O>>8,h[u++]=O,O=O>>8,h[u++]=O;let L=Number(f>>BigInt(32)&BigInt(4294967295));return h[u++]=L,L=L>>8,h[u++]=L,L=L>>8,h[u++]=L,L=L>>8,h[u++]=L,u}function kt(h,f,u,y,v){g(f,y,v,h,u,7);let O=Number(f&BigInt(4294967295));h[u+7]=O,O=O>>8,h[u+6]=O,O=O>>8,h[u+5]=O,O=O>>8,h[u+4]=O;let L=Number(f>>BigInt(32)&BigInt(4294967295));return h[u+3]=L,L=L>>8,h[u+2]=L,L=L>>8,h[u+1]=L,L=L>>8,h[u]=L,u+8}a.prototype.writeBigUInt64LE=Xe(function(f,u=0){return ze(this,f,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Xe(function(f,u=0){return kt(this,f,u,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(f,u,y,v){if(f=+f,u=u>>>0,!v){const ve=Math.pow(2,8*y-1);xe(this,f,u,y,ve-1,-ve)}let O=0,L=1,Q=0;for(this[u]=f&255;++O<y&&(L*=256);)f<0&&Q===0&&this[u+O-1]!==0&&(Q=1),this[u+O]=(f/L>>0)-Q&255;return u+y},a.prototype.writeIntBE=function(f,u,y,v){if(f=+f,u=u>>>0,!v){const ve=Math.pow(2,8*y-1);xe(this,f,u,y,ve-1,-ve)}let O=y-1,L=1,Q=0;for(this[u+O]=f&255;--O>=0&&(L*=256);)f<0&&Q===0&&this[u+O+1]!==0&&(Q=1),this[u+O]=(f/L>>0)-Q&255;return u+y},a.prototype.writeInt8=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,1,127,-128),f<0&&(f=255+f+1),this[u]=f&255,u+1},a.prototype.writeInt16LE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,2,32767,-32768),this[u]=f&255,this[u+1]=f>>>8,u+2},a.prototype.writeInt16BE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,2,32767,-32768),this[u]=f>>>8,this[u+1]=f&255,u+2},a.prototype.writeInt32LE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,4,2147483647,-2147483648),this[u]=f&255,this[u+1]=f>>>8,this[u+2]=f>>>16,this[u+3]=f>>>24,u+4},a.prototype.writeInt32BE=function(f,u,y){return f=+f,u=u>>>0,y||xe(this,f,u,4,2147483647,-2147483648),f<0&&(f=4294967295+f+1),this[u]=f>>>24,this[u+1]=f>>>16,this[u+2]=f>>>8,this[u+3]=f&255,u+4},a.prototype.writeBigInt64LE=Xe(function(f,u=0){return ze(this,f,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Xe(function(f,u=0){return kt(this,f,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function bt(h,f,u,y,v,O){if(u+y>h.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function T(h,f,u,y,v){return f=+f,u=u>>>0,v||bt(h,f,u,4),r.write(h,f,u,y,23,4),u+4}a.prototype.writeFloatLE=function(f,u,y){return T(this,f,u,!0,y)},a.prototype.writeFloatBE=function(f,u,y){return T(this,f,u,!1,y)};function P(h,f,u,y,v){return f=+f,u=u>>>0,v||bt(h,f,u,8),r.write(h,f,u,y,52,8),u+8}a.prototype.writeDoubleLE=function(f,u,y){return P(this,f,u,!0,y)},a.prototype.writeDoubleBE=function(f,u,y){return P(this,f,u,!1,y)},a.prototype.copy=function(f,u,y,v){if(!a.isBuffer(f))throw new TypeError("argument should be a Buffer");if(y||(y=0),!v&&v!==0&&(v=this.length),u>=f.length&&(u=f.length),u||(u=0),v>0&&v<y&&(v=y),v===y||f.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(y<0||y>=this.length)throw new RangeError("Index out of range");if(v<0)throw new RangeError("sourceEnd out of bounds");v>this.length&&(v=this.length),f.length-u<v-y&&(v=f.length-u+y);const O=v-y;return this===f&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(u,y,v):Uint8Array.prototype.set.call(f,this.subarray(y,v),u),O},a.prototype.fill=function(f,u,y,v){if(typeof f=="string"){if(typeof u=="string"?(v=u,u=0,y=this.length):typeof y=="string"&&(v=y,y=this.length),v!==void 0&&typeof v!="string")throw new TypeError("encoding must be a string");if(typeof v=="string"&&!a.isEncoding(v))throw new TypeError("Unknown encoding: "+v);if(f.length===1){const L=f.charCodeAt(0);(v==="utf8"&&L<128||v==="latin1")&&(f=L)}}else typeof f=="number"?f=f&255:typeof f=="boolean"&&(f=Number(f));if(u<0||this.length<u||this.length<y)throw new RangeError("Out of range index");if(y<=u)return this;u=u>>>0,y=y===void 0?this.length:y>>>0,f||(f=0);let O;if(typeof f=="number")for(O=u;O<y;++O)this[O]=f;else{const L=a.isBuffer(f)?f:a.from(f,v),Q=L.length;if(Q===0)throw new TypeError('The value "'+f+'" is invalid for argument "value"');for(O=0;O<y-u;++O)this[O+u]=L[O%Q]}return this};const F={};function G(h,f,u){F[h]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:f.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(v){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:v,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}G("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(h,f){return`The "${h}" argument must be of type number. Received type ${typeof f}`},TypeError),G("ERR_OUT_OF_RANGE",function(h,f,u){let y=`The value of "${h}" is out of range.`,v=u;return Number.isInteger(u)&&Math.abs(u)>2**32?v=K(String(u)):typeof u=="bigint"&&(v=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(v=K(v)),v+="n"),y+=` It must be ${f}. Received ${v}`,y},RangeError);function K(h){let f="",u=h.length;const y=h[0]==="-"?1:0;for(;u>=y+4;u-=3)f=`_${h.slice(u-3,u)}${f}`;return`${h.slice(0,u)}${f}`}function w(h,f,u){N(f,"offset"),(h[f]===void 0||h[f+u]===void 0)&&D(f,h.length-(u+1))}function g(h,f,u,y,v,O){if(h>u||h<f){const L=typeof f=="bigint"?"n":"";let Q;throw f===0||f===BigInt(0)?Q=`>= 0${L} and < 2${L} ** ${(O+1)*8}${L}`:Q=`>= -(2${L} ** ${(O+1)*8-1}${L}) and < 2 ** ${(O+1)*8-1}${L}`,new F.ERR_OUT_OF_RANGE("value",Q,h)}w(y,v,O)}function N(h,f){if(typeof h!="number")throw new F.ERR_INVALID_ARG_TYPE(f,"number",h)}function D(h,f,u){throw Math.floor(h)!==h?(N(h,u),new F.ERR_OUT_OF_RANGE("offset","an integer",h)):f<0?new F.ERR_BUFFER_OUT_OF_BOUNDS:new F.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${f}`,h)}const we=/[^+/0-9A-Za-z-_]/g;function Y(h){if(h=h.split("=")[0],h=h.trim().replace(we,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function te(h,f){f=f||1/0;let u;const y=h.length;let v=null;const O=[];for(let L=0;L<y;++L){if(u=h.charCodeAt(L),u>55295&&u<57344){if(!v){if(u>56319){(f-=3)>-1&&O.push(239,191,189);continue}else if(L+1===y){(f-=3)>-1&&O.push(239,191,189);continue}v=u;continue}if(u<56320){(f-=3)>-1&&O.push(239,191,189),v=u;continue}u=(v-55296<<10|u-56320)+65536}else v&&(f-=3)>-1&&O.push(239,191,189);if(v=null,u<128){if((f-=1)<0)break;O.push(u)}else if(u<2048){if((f-=2)<0)break;O.push(u>>6|192,u&63|128)}else if(u<65536){if((f-=3)<0)break;O.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((f-=4)<0)break;O.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return O}function Rt(h){const f=[];for(let u=0;u<h.length;++u)f.push(h.charCodeAt(u)&255);return f}function wr(h,f){let u,y,v;const O=[];for(let L=0;L<h.length&&!((f-=2)<0);++L)u=h.charCodeAt(L),y=u>>8,v=u%256,O.push(v),O.push(y);return O}function Gr(h){return t.toByteArray(Y(h))}function gr(h,f,u,y){let v;for(v=0;v<y&&!(v+u>=f.length||v>=h.length);++v)f[v+u]=h[v];return v}function qe(h,f){return h instanceof f||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===f.name}function Jt(h){return h!==h}const Wr=function(){const h="0123456789abcdef",f=new Array(256);for(let u=0;u<16;++u){const y=u*16;for(let v=0;v<16;++v)f[y+v]=h[u]+h[v]}return f}();function Xe(h){return typeof BigInt>"u"?Qt:h}function Qt(){throw new Error("BigInt not supported")}})(Ot);var yn={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};yn.Null=yn.Nil;for(var oo in yn)yn[oo].toJSON=(function(e){return e}).bind(null,oo);var ks=yn,nr=ks;function va(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function Rs(e){return nr.Nil(e)?"":va(e.constructor)}function Mu(e){return nr.Function(e)?"":nr.String(e)?JSON.stringify(e):e&&nr.Object(e)?"":e}function Us(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Qn(e){return nr.Function(e)?e.toJSON?e.toJSON():va(e):nr.Array(e)?"Array":e&&nr.Object(e)?"Object":e!==void 0?e:""}function Ea(e,t,r){var n=Mu(t);return"Expected "+Qn(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Tt(e,t,r){r=r||Rs(t),this.message=Ea(e,t,r),Us(this,Tt),this.__type=e,this.__value=t,this.__valueTypeName=r}Tt.prototype=Object.create(Error.prototype);Tt.prototype.constructor=Tt;function Hu(e,t,r,n,i){var s='" of type ';return t==="key"&&(s='" with key type '),Ea('property "'+Qn(r)+s+Qn(e),n,i)}function Ar(e,t,r,n,i){e?(i=i||Rs(n),this.message=Hu(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',Us(this,Tt),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Ar.prototype=Object.create(Error.prototype);Ar.prototype.constructor=Tt;function Du(e,t){return new Tt(e,{},t)}function $u(e,t,r){return e instanceof Ar?(t=t+"."+e.__property,e=new Ar(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Tt&&(e=new Ar(e.__type,t,r,e.__value,e.__valueTypeName)),Us(e),e}var xa={TfTypeError:Tt,TfPropertyTypeError:Ar,tfCustomError:Du,tfSubError:$u,tfJSON:Qn,getValueTypeName:Rs},Fi,ao;function ju(){if(ao)return Fi;ao=1;var e=ks,t=xa;function r(x){return Buffer.isBuffer(x)}function n(x){return typeof x=="string"&&/^([0-9a-f]{2})+$/i.test(x)}function i(x,H){var $=x.toJSON();function R(z){if(!x(z))return!1;if(z.length===H)return!0;throw t.tfCustomError($+"(Length: "+H+")",$+"(Length: "+z.length+")")}return R.toJSON=function(){return $},R}var s=i.bind(null,e.Array),o=i.bind(null,r),a=i.bind(null,n),c=i.bind(null,e.String);function l(x,H,$){$=$||e.Number;function R(z,Z){return $(z,Z)&&z>x&&z<H}return R.toJSON=function(){return`${$.toJSON()} between [${x}, ${H}]`},R}var d=Math.pow(2,53)-1;function b(x){return typeof x=="number"&&isFinite(x)}function E(x){return x<<24>>24===x}function p(x){return x<<16>>16===x}function I(x){return(x|0)===x}function B(x){return typeof x=="number"&&x>=-d&&x<=d&&Math.floor(x)===x}function A(x){return(x&255)===x}function k(x){return(x&65535)===x}function U(x){return x>>>0===x}function _(x){return typeof x=="number"&&x>=0&&x<=d&&Math.floor(x)===x}var m={ArrayN:s,Buffer:r,BufferN:o,Finite:b,Hex:n,HexN:a,Int8:E,Int16:p,Int32:I,Int53:B,Range:l,StringN:c,UInt8:A,UInt16:k,UInt32:U,UInt53:_};for(var S in m)m[S].toJSON=(function(x){return x}).bind(null,S);return Fi=m,Fi}var mn=xa,Ae=ks,wt=mn.tfJSON,Sa=mn.TfTypeError,Ba=mn.TfPropertyTypeError,Vr=mn.tfSubError,Gu=mn.getValueTypeName,xt={arrayOf:function(t,r){t=lt(t),r=r||{};function n(i,s){return!Ae.Array(i)||Ae.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(o,a){try{return Ge(t,o,s)}catch(c){throw Vr(c,a)}})}return n.toJSON=function(){var i="["+wt(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=lt(t);function r(n,i){return Ae.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+wt(t)},r},map:function(t,r){t=lt(t),r&&(r=lt(r));function n(i,s){if(!Ae.Object(i)||Ae.Nil(i))return!1;for(var o in i){try{r&&Ge(r,o,s)}catch(c){throw Vr(c,o,"key")}try{var a=i[o];Ge(t,a,s)}catch(c){throw Vr(c,o)}}return!0}return r?n.toJSON=function(){return"{"+wt(r)+": "+wt(t)+"}"}:n.toJSON=function(){return"{"+wt(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=lt(t[n]);function i(s,o){if(!Ae.Object(s)||Ae.Nil(s))return!1;var a;try{for(a in r){var c=r[a],l=s[a];Ge(c,l,o)}}catch(d){throw Vr(d,a)}if(o){for(a in s)if(!r[a])throw new Ba(void 0,a)}return!0}return i.toJSON=function(){return wt(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(lt);function r(n,i){return t.some(function(s){try{return Ge(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(wt).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(lt);function r(n,i){return t.every(function(s){try{return Ge(s,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(wt).join(" & ")},r},quacksLike:function(t){function r(n){return t===Gu(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(lt);function r(n,i){return Ae.Nil(n)||Ae.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(s,o){try{return Ge(s,n[o],i)}catch(a){throw Vr(a,o)}})}return r.toJSON=function(){return"("+t.map(wt).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};xt.oneOf=xt.anyOf;function lt(e){if(Ae.String(e))return e[0]==="?"?xt.maybe(e.slice(1)):Ae[e]||xt.quacksLike(e);if(e&&Ae.Object(e)){if(Ae.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return xt.arrayOf(e[0])}return xt.object(e)}else if(Ae.Function(e))return e;return xt.value(e)}function Ge(e,t,r,n){if(Ae.Function(e)){if(e(t,r))return!0;throw new Sa(n||e,t)}return Ge(lt(e),t,r)}for(var Gt in Ae)Ge[Gt]=Ae[Gt];for(Gt in xt)Ge[Gt]=xt[Gt];var fo=ju();for(Gt in fo)Ge[Gt]=fo[Gt];Ge.compile=lt;Ge.TfTypeError=Sa;Ge.TfPropertyTypeError=Ba;var Pa=Ge;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.oneOf=e.Null=e.BufferN=e.Function=e.UInt32=e.UInt8=e.tuple=e.maybe=e.Hex=e.Buffer=e.String=e.Boolean=e.Array=e.Number=e.Hash256bit=e.Hash160bit=e.Buffer256bit=e.isTaptree=e.isTapleaf=e.TAPLEAF_VERSION_MASK=e.Satoshi=e.isPoint=e.stacksEqual=e.typeforce=void 0;const t=Ot;e.typeforce=Pa;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(d,b){return d.length!==b.length?!1:d.every((E,p)=>E.equals(b[p]))}e.stacksEqual=i;function s(d){if(!t.Buffer.isBuffer(d)||d.length<33)return!1;const b=d[0],E=d.slice(1,33);if(E.compare(r)===0||E.compare(n)>=0)return!1;if((b===2||b===3)&&d.length===33)return!0;const p=d.slice(33);return p.compare(r)===0||p.compare(n)>=0?!1:b===4&&d.length===65}e.isPoint=s;const o=21*1e14;function a(d){return e.typeforce.UInt53(d)&&d<=o}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function c(d){return!d||!("output"in d)||!t.Buffer.isBuffer(d.output)?!1:d.version!==void 0?(d.version&e.TAPLEAF_VERSION_MASK)===d.version:!0}e.isTapleaf=c;function l(d){return(0,e.Array)(d)?d.length!==2?!1:d.every(b=>l(b)):c(d)}e.isTaptree=l,e.Buffer256bit=e.typeforce.BufferN(32),e.Hash160bit=e.typeforce.BufferN(20),e.Hash256bit=e.typeforce.BufferN(32),e.Number=e.typeforce.Number,e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.String=e.typeforce.String,e.Buffer=e.typeforce.Buffer,e.Hex=e.typeforce.Hex,e.maybe=e.typeforce.maybe,e.tuple=e.typeforce.tuple,e.UInt8=e.typeforce.UInt8,e.UInt32=e.typeforce.UInt32,e.Function=e.typeforce.Function,e.BufferN=e.typeforce.BufferN,e.Null=e.typeforce.Null,e.oneOf=e.typeforce.oneOf})(Me);var _n={},Ie={};Object.defineProperty(Ie,"__esModule",{value:!0});Ie.BufferReader=Ie.BufferWriter=Ie.cloneBuffer=Ie.reverseBuffer=Ie.writeUInt64LE=Ie.readUInt64LE=Ie.varuint=void 0;const ir=Me,{typeforce:Ta}=ir,bn=pa;Ie.varuint=bn;function Aa(e,t){if(typeof e!="number")throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function Ia(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Aa(n+r,9007199254740991),n+r}Ie.readUInt64LE=Ia;function Oa(e,t,r){return Aa(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}Ie.writeUInt64LE=Oa;function Wu(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}Ie.reverseBuffer=Wu;function Vu(e){const t=Buffer.allocUnsafe(e.length);return e.copy(t),t}Ie.cloneBuffer=Vu;class Cs{static withCapacity(t){return new Cs(Buffer.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Ta(ir.tuple(ir.Buffer,ir.UInt32),[t,r])}writeUInt8(t){this.offset=this.buffer.writeUInt8(t,this.offset)}writeInt32(t){this.offset=this.buffer.writeInt32LE(t,this.offset)}writeUInt32(t){this.offset=this.buffer.writeUInt32LE(t,this.offset)}writeUInt64(t){this.offset=Oa(this.buffer,t,this.offset)}writeVarInt(t){bn.encode(t,this.buffer,this.offset),this.offset+=bn.encode.bytes}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.offset+=t.copy(this.buffer,this.offset)}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}Ie.BufferWriter=Cs;class zu{constructor(t,r=0){this.buffer=t,this.offset=r,Ta(ir.tuple(ir.Buffer,ir.UInt32),[t,r])}readUInt8(){const t=this.buffer.readUInt8(this.offset);return this.offset++,t}readInt32(){const t=this.buffer.readInt32LE(this.offset);return this.offset+=4,t}readUInt32(){const t=this.buffer.readUInt32LE(this.offset);return this.offset+=4,t}readUInt64(){const t=Ia(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=bn.decode(this.buffer,this.offset);return this.offset+=bn.decode.bytes,t}readSlice(t){if(this.buffer.length<this.offset+t)throw new Error("Cannot read slice out of bounds");const r=this.buffer.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}}Ie.BufferReader=zu;var qt={},Ur={},pt={},nt={};Object.defineProperty(nt,"__esModule",{value:!0});nt.isBytes=Ra;nt.number=Zn;nt.bool=ka;nt.bytes=Ls;nt.hash=Ua;nt.exists=Ca;nt.output=La;function Zn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function ka(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function Ra(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Ls(e,...t){if(!Ra(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ua(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Zn(e.outputLen),Zn(e.blockLen)}function Ca(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function La(e,t){Ls(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const qu={number:Zn,bool:ka,bytes:Ls,hash:Ua,exists:Ca,output:La};nt.default=qu;var vn={},ci={};Object.defineProperty(ci,"__esModule",{value:!0});ci.crypto=void 0;ci.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;(function(e){/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */Object.defineProperty(e,"__esModule",{value:!0}),e.Hash=e.nextTick=e.byteSwapIfBE=e.byteSwap=e.isLE=e.rotl=e.rotr=e.createView=e.u32=e.u8=void 0,e.isBytes=n,e.byteSwap32=d,e.bytesToHex=E,e.hexToBytes=B,e.asyncLoop=k,e.utf8ToBytes=U,e.toBytes=_,e.concatBytes=m,e.checkOpts=H,e.wrapConstructor=$,e.wrapConstructorWithOpts=R,e.wrapXOFConstructorWithOpts=z,e.randomBytes=Z;const t=ci,r=nt;function n(C){return C instanceof Uint8Array||C!=null&&typeof C=="object"&&C.constructor.name==="Uint8Array"}const i=C=>new Uint8Array(C.buffer,C.byteOffset,C.byteLength);e.u8=i;const s=C=>new Uint32Array(C.buffer,C.byteOffset,Math.floor(C.byteLength/4));e.u32=s;const o=C=>new DataView(C.buffer,C.byteOffset,C.byteLength);e.createView=o;const a=(C,M)=>C<<32-M|C>>>M;e.rotr=a;const c=(C,M)=>C<<M|C>>>32-M>>>0;e.rotl=c,e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;const l=C=>C<<24&4278190080|C<<8&16711680|C>>>8&65280|C>>>24&255;e.byteSwap=l,e.byteSwapIfBE=e.isLE?C=>C:C=>(0,e.byteSwap)(C);function d(C){for(let M=0;M<C.length;M++)C[M]=(0,e.byteSwap)(C[M])}const b=Array.from({length:256},(C,M)=>M.toString(16).padStart(2,"0"));function E(C){(0,r.bytes)(C);let M="";for(let W=0;W<C.length;W++)M+=b[C[W]];return M}const p={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function I(C){if(C>=p._0&&C<=p._9)return C-p._0;if(C>=p._A&&C<=p._F)return C-(p._A-10);if(C>=p._a&&C<=p._f)return C-(p._a-10)}function B(C){if(typeof C!="string")throw new Error("hex string expected, got "+typeof C);const M=C.length,W=M/2;if(M%2)throw new Error("padded hex string expected, got unpadded hex of length "+M);const q=new Uint8Array(W);for(let fe=0,ue=0;fe<W;fe++,ue+=2){const tt=I(C.charCodeAt(ue)),Ve=I(C.charCodeAt(ue+1));if(tt===void 0||Ve===void 0){const st=C[ue]+C[ue+1];throw new Error('hex string expected, got non-hex character "'+st+'" at index '+ue)}q[fe]=tt*16+Ve}return q}const A=async()=>{};e.nextTick=A;async function k(C,M,W){let q=Date.now();for(let fe=0;fe<C;fe++){W(fe);const ue=Date.now()-q;ue>=0&&ue<M||(await(0,e.nextTick)(),q+=ue)}}function U(C){if(typeof C!="string")throw new Error(`utf8ToBytes expected string, got ${typeof C}`);return new Uint8Array(new TextEncoder().encode(C))}function _(C){return typeof C=="string"&&(C=U(C)),(0,r.bytes)(C),C}function m(...C){let M=0;for(let q=0;q<C.length;q++){const fe=C[q];(0,r.bytes)(fe),M+=fe.length}const W=new Uint8Array(M);for(let q=0,fe=0;q<C.length;q++){const ue=C[q];W.set(ue,fe),fe+=ue.length}return W}class S{clone(){return this._cloneInto()}}e.Hash=S;const x={}.toString;function H(C,M){if(M!==void 0&&x.call(M)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(C,M)}function $(C){const M=q=>C().update(_(q)).digest(),W=C();return M.outputLen=W.outputLen,M.blockLen=W.blockLen,M.create=()=>C(),M}function R(C){const M=(q,fe)=>C(fe).update(_(q)).digest(),W=C({});return M.outputLen=W.outputLen,M.blockLen=W.blockLen,M.create=q=>C(q),M}function z(C){const M=(q,fe)=>C(fe).update(_(q)).digest(),W=C({});return M.outputLen=W.outputLen,M.blockLen=W.blockLen,M.create=q=>C(q),M}function Z(C=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(C));if(t.crypto&&typeof t.crypto.randomBytes=="function")return t.crypto.randomBytes(C);throw new Error("crypto.getRandomValues must be defined")}})(vn);Object.defineProperty(pt,"__esModule",{value:!0});pt.HashMD=pt.Maj=pt.Chi=void 0;const Mi=nt,zr=vn;function Ku(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,l=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+l,a,n)}const Yu=(e,t,r)=>e&t^~e&r;pt.Chi=Yu;const Xu=(e,t,r)=>e&t^e&r^t&r;pt.Maj=Xu;let Ju=class extends zr.Hash{constructor(t,r,n,i){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,zr.createView)(this.buffer)}update(t){(0,Mi.exists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,zr.toBytes)(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=(0,zr.createView)(t);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Mi.exists)(this),(0,Mi.output)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let b=o;b<i;b++)r[b]=0;Ku(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=(0,zr.createView)(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,d=this.get();if(l>d.length)throw new Error("_sha2: outputLen bigger than state");for(let b=0;b<l;b++)a.setUint32(4*b,d[b],s)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%r&&t.buffer.set(n),t}};pt.HashMD=Ju;Object.defineProperty(Ur,"__esModule",{value:!0});Ur.ripemd160=Ur.RIPEMD160=void 0;const Qu=pt,fn=vn,Zu=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Na=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),ec=Na.map(e=>(9*e+5)%16);let Ns=[Na],Fs=[ec];for(let e=0;e<4;e++)for(let t of[Ns,Fs])t.push(t[e].map(r=>Zu[r]));const Fa=[[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=>new Uint8Array(e)),tc=Ns.map((e,t)=>e.map(r=>Fa[t][r])),rc=Fs.map((e,t)=>e.map(r=>Fa[t][r])),nc=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),ic=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function uo(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const Rn=new Uint32Array(16);let Ma=class extends Qu.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:r,h2:n,h3:i,h4:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=s|0}process(t,r){for(let p=0;p<16;p++,r+=4)Rn[p]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,l=this.h3|0,d=l,b=this.h4|0,E=b;for(let p=0;p<5;p++){const I=4-p,B=nc[p],A=ic[p],k=Ns[p],U=Fs[p],_=tc[p],m=rc[p];for(let S=0;S<16;S++){const x=(0,fn.rotl)(n+uo(p,s,a,l)+Rn[k[S]]+B,_[S])+b|0;n=b,b=l,l=(0,fn.rotl)(a,10)|0,a=s,s=x}for(let S=0;S<16;S++){const x=(0,fn.rotl)(i+uo(I,o,c,d)+Rn[U[S]]+A,m[S])+E|0;i=E,E=d,d=(0,fn.rotl)(c,10)|0,c=o,o=x}}this.set(this.h1+a+d|0,this.h2+l+E|0,this.h3+b+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){Rn.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};Ur.RIPEMD160=Ma;Ur.ripemd160=(0,fn.wrapConstructor)(()=>new Ma);var Cr={};Object.defineProperty(Cr,"__esModule",{value:!0});Cr.sha1=Cr.SHA1=void 0;const Hi=pt,Wn=vn,qr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Ut=new Uint32Array(80);class Ha extends Hi.HashMD{constructor(){super(64,20,8,!1),this.A=qr[0]|0,this.B=qr[1]|0,this.C=qr[2]|0,this.D=qr[3]|0,this.E=qr[4]|0}get(){const{A:t,B:r,C:n,D:i,E:s}=this;return[t,r,n,i,s]}set(t,r,n,i,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0}process(t,r){for(let c=0;c<16;c++,r+=4)Ut[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)Ut[c]=(0,Wn.rotl)(Ut[c-3]^Ut[c-8]^Ut[c-14]^Ut[c-16],1);let{A:n,B:i,C:s,D:o,E:a}=this;for(let c=0;c<80;c++){let l,d;c<20?(l=(0,Hi.Chi)(i,s,o),d=1518500249):c<40?(l=i^s^o,d=1859775393):c<60?(l=(0,Hi.Maj)(i,s,o),d=2400959708):(l=i^s^o,d=3395469782);const b=(0,Wn.rotl)(n,5)+l+a+d+Ut[c]|0;a=o,o=s,s=(0,Wn.rotl)(i,30),i=n,n=b}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,this.set(n,i,s,o,a)}roundClean(){Ut.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}Cr.SHA1=Ha;Cr.sha1=(0,Wn.wrapConstructor)(()=>new Ha);var Bt={};Object.defineProperty(Bt,"__esModule",{value:!0});Bt.sha224=Bt.sha256=Bt.SHA256=void 0;const Di=pt,Qe=vn,sc=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ct=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Lt=new Uint32Array(64);let Ms=class extends Di.HashMD{constructor(){super(64,32,8,!1),this.A=Ct[0]|0,this.B=Ct[1]|0,this.C=Ct[2]|0,this.D=Ct[3]|0,this.E=Ct[4]|0,this.F=Ct[5]|0,this.G=Ct[6]|0,this.H=Ct[7]|0}get(){const{A:t,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[t,r,n,i,s,o,a,c]}set(t,r,n,i,s,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,r){for(let b=0;b<16;b++,r+=4)Lt[b]=t.getUint32(r,!1);for(let b=16;b<64;b++){const E=Lt[b-15],p=Lt[b-2],I=(0,Qe.rotr)(E,7)^(0,Qe.rotr)(E,18)^E>>>3,B=(0,Qe.rotr)(p,17)^(0,Qe.rotr)(p,19)^p>>>10;Lt[b]=B+Lt[b-7]+I+Lt[b-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:l,H:d}=this;for(let b=0;b<64;b++){const E=(0,Qe.rotr)(a,6)^(0,Qe.rotr)(a,11)^(0,Qe.rotr)(a,25),p=d+E+(0,Di.Chi)(a,c,l)+sc[b]+Lt[b]|0,B=((0,Qe.rotr)(n,2)^(0,Qe.rotr)(n,13)^(0,Qe.rotr)(n,22))+(0,Di.Maj)(n,i,s)|0;d=l,l=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+B|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,d=d+this.H|0,this.set(n,i,s,o,a,c,l,d)}roundClean(){Lt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};Bt.SHA256=Ms;class oc extends Ms{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}Bt.sha256=(0,Qe.wrapConstructor)(()=>new Ms);Bt.sha224=(0,Qe.wrapConstructor)(()=>new oc);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.taggedHash=e.TAGGED_HASH_PREFIXES=e.TAGS=e.hash256=e.hash160=e.sha256=e.sha1=e.ripemd160=void 0;const t=Ur,r=Cr,n=Bt;function i(d){return Buffer.from((0,t.ripemd160)(Uint8Array.from(d)))}e.ripemd160=i;function s(d){return Buffer.from((0,r.sha1)(Uint8Array.from(d)))}e.sha1=s;function o(d){return Buffer.from((0,n.sha256)(Uint8Array.from(d)))}e.sha256=o;function a(d){return Buffer.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(d))))}e.hash160=a;function c(d){return Buffer.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(d))))}e.hash256=c,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":Buffer.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Buffer.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Buffer.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Buffer.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Buffer.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Buffer.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Buffer.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Buffer.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Buffer.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function l(d,b){return o(Buffer.concat([e.TAGGED_HASH_PREFIXES[d],b]))}e.taggedHash=l})(qt);var $i={},Pt={};Object.defineProperty(Pt,"__esModule",{value:!0});Pt.encode=Pt.decode=Pt.check=void 0;function ac(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const r=e[5+t];return!(r===0||6+t+r!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||r>1&&e[t+6]===0&&!(e[t+7]&128))}Pt.check=ac;function fc(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const r=e[5+t];if(r===0)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(r>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}Pt.decode=fc;function uc(e,t){const r=e.length,n=t.length;if(r===0)throw new Error("R length is zero");if(n===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(r>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(n>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const i=Buffer.allocUnsafe(6+r+n);return i[0]=48,i[1]=i.length-2,i[2]=2,i[3]=e.length,e.copy(i,4),i[4+r]=2,i[5+r]=t.length,t.copy(i,6+r),i}Pt.encode=uc;var or={};Object.defineProperty(or,"__esModule",{value:!0});or.REVERSE_OPS=or.OPS=void 0;const ps={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,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_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,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_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT: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_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,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,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};or.OPS=ps;const Da={};or.REVERSE_OPS=Da;for(const e of Object.keys(ps)){const t=ps[e];Da[t]=e}var Wt={};Object.defineProperty(Wt,"__esModule",{value:!0});Wt.decode=Wt.encode=Wt.encodingLength=void 0;const jt=or;function $a(e){return e<jt.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}Wt.encodingLength=$a;function cc(e,t,r){const n=$a(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(jt.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(jt.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(jt.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}Wt.encode=cc;function hc(e,t){const r=e.readUInt8(t);let n,i;if(r<jt.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===jt.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===jt.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;n=e.readUInt16LE(t+1),i=3}else{if(t+5>e.length)return null;if(r!==jt.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}Wt.decode=hc;var Lr={};Object.defineProperty(Lr,"__esModule",{value:!0});Lr.encode=Lr.decode=void 0;function lc(e,t,r){t=t||4,r=r===void 0?!0:r;const n=e.length;if(n===0)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(e[n-1]&127)&&(n<=1||!(e[n-2]&128)))throw new Error("Non-minimally encoded script number");if(n===5){const s=e.readUInt32LE(0),o=e.readUInt8(4);return o&128?-((o&-129)*4294967296+s):o*4294967296+s}let i=0;for(let s=0;s<n;++s)i|=e[s]<<8*s;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}Lr.decode=lc;function dc(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function pc(e){let t=Math.abs(e);const r=dc(t),n=Buffer.allocUnsafe(r),i=e<0;for(let s=0;s<r;++s)n.writeUInt8(t&255,s),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}Lr.encode=pc;var er={},co;function yc(){if(co)return er;co=1,Object.defineProperty(er,"__esModule",{value:!0}),er.encode=er.decode=void 0;const e=Pt,t=Ye(),r=Me,{typeforce:n}=r,i=Buffer.alloc(1,0);function s(l){let d=0;for(;l[d]===0;)++d;return d===l.length?i:(l=l.slice(d),l[0]&128?Buffer.concat([i,l],1+l.length):l)}function o(l){l[0]===0&&(l=l.slice(1));const d=Buffer.alloc(32,0),b=Math.max(0,32-l.length);return l.copy(d,b),d}function a(l){const d=l.readUInt8(l.length-1);if(!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const b=e.decode(l.slice(0,-1)),E=o(b.r),p=o(b.s);return{signature:Buffer.concat([E,p],64),hashType:d}}er.decode=a;function c(l,d){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:l,hashType:d}),!(0,t.isDefinedHashType)(d))throw new Error("Invalid hashType "+d);const b=Buffer.allocUnsafe(1);b.writeUInt8(d,0);const E=s(l.slice(0,32)),p=s(l.slice(32,64));return Buffer.concat([e.encode(E,p),b])}return er.encode=c,er}var ho;function Ye(){return ho||(ho=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.signature=e.number=e.isCanonicalScriptSignature=e.isDefinedHashType=e.isCanonicalPubKey=e.toStack=e.fromASM=e.toASM=e.decompile=e.compile=e.countNonPushOnlyOPs=e.isPushOnly=e.OPS=void 0;const t=Pt,r=or;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=Wt,i=Lr,s=yc(),o=Me,{typeforce:a}=o,c=r.OPS.OP_RESERVED;function l(R){return o.Number(R)&&(R===r.OPS.OP_0||R>=r.OPS.OP_1&&R<=r.OPS.OP_16||R===r.OPS.OP_1NEGATE)}function d(R){return o.Buffer(R)||l(R)}function b(R){return o.Array(R)&&R.every(d)}e.isPushOnly=b;function E(R){return R.length-R.filter(d).length}e.countNonPushOnlyOPs=E;function p(R){if(R.length===0)return r.OPS.OP_0;if(R.length===1){if(R[0]>=1&&R[0]<=16)return c+R[0];if(R[0]===129)return r.OPS.OP_1NEGATE}}function I(R){return Buffer.isBuffer(R)}function B(R){return o.Array(R)}function A(R){return Buffer.isBuffer(R)}function k(R){if(I(R))return R;a(o.Array,R);const z=R.reduce((M,W)=>A(W)?W.length===1&&p(W)!==void 0?M+1:M+n.encodingLength(W.length)+W.length:M+1,0),Z=Buffer.allocUnsafe(z);let C=0;if(R.forEach(M=>{if(A(M)){const W=p(M);if(W!==void 0){Z.writeUInt8(W,C),C+=1;return}C+=n.encode(Z,M.length,C),M.copy(Z,C),C+=M.length}else Z.writeUInt8(M,C),C+=1}),C!==Z.length)throw new Error("Could not decode chunks");return Z}e.compile=k;function U(R){if(B(R))return R;a(o.Buffer,R);const z=[];let Z=0;for(;Z<R.length;){const C=R[Z];if(C>r.OPS.OP_0&&C<=r.OPS.OP_PUSHDATA4){const M=n.decode(R,Z);if(M===null||(Z+=M.size,Z+M.number>R.length))return null;const W=R.slice(Z,Z+M.number);Z+=M.number;const q=p(W);q!==void 0?z.push(q):z.push(W)}else z.push(C),Z+=1}return z}e.decompile=U;function _(R){if(I(R)&&(R=U(R)),!R)throw new Error("Could not convert invalid chunks to ASM");return R.map(z=>{if(A(z)){const Z=p(z);if(Z===void 0)return z.toString("hex");z=Z}return r.REVERSE_OPS[z]}).join(" ")}e.toASM=_;function m(R){return a(o.String,R),k(R.split(" ").map(z=>r.OPS[z]!==void 0?r.OPS[z]:(a(o.Hex,z),Buffer.from(z,"hex"))))}e.fromASM=m;function S(R){return R=U(R),a(b,R),R.map(z=>A(z)?z:z===r.OPS.OP_0?Buffer.allocUnsafe(0):i.encode(z-c))}e.toStack=S;function x(R){return o.isPoint(R)}e.isCanonicalPubKey=x;function H(R){const z=R&-129;return z>0&&z<4}e.isDefinedHashType=H;function $(R){return!Buffer.isBuffer(R)||!H(R[R.length-1])?!1:t.check(R.slice(0,-1))}e.isCanonicalScriptSignature=$,e.number=i,e.signature=s}($i)),$i}Object.defineProperty(_n,"__esModule",{value:!0});_n.Transaction=void 0;const Be=Ie,He=qt,lo=Ye(),bc=Ye(),ee=Me,{typeforce:ot}=ee;function ct(e){const t=e.length;return Be.varuint.encodingLength(t)+t}function wc(e){const t=e.length;return Be.varuint.encodingLength(t)+e.reduce((r,n)=>r+ct(n),0)}const $t=Buffer.allocUnsafe(0),po=[],ji=Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),yo=Buffer.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),gc=Buffer.from("ffffffffffffffff","hex"),mc={script:$t,valueBuffer:gc};function _c(e){return e.value!==void 0}class X{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new Be.BufferReader(t),i=new X;i.version=n.readInt32();const s=n.readUInt8(),o=n.readUInt8();let a=!1;s===X.ADVANCED_TRANSACTION_MARKER&&o===X.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const c=n.readVarInt();for(let d=0;d<c;++d)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:po});const l=n.readVarInt();for(let d=0;d<l;++d)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let d=0;d<c;++d)i.ins[d].witness=n.readVector();if(!i.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(i.locktime=n.readUInt32(),r)return i;if(n.offset!==t.length)throw new Error("Transaction has unexpected data");return i}static fromHex(t){return X.fromBuffer(Buffer.from(t,"hex"),!1)}static isCoinbaseHash(t){ot(ee.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&X.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return ot(ee.tuple(ee.Hash256bit,ee.UInt32,ee.maybe(ee.UInt32),ee.maybe(ee.Buffer)),arguments),ee.Null(n)&&(n=X.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||$t,sequence:n,witness:po})-1}addOutput(t,r){return ot(ee.tuple(ee.Buffer,ee.Satoshi),arguments),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),r=this.byteLength(!0);return t*3+r}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const r=t&&this.hasWitnesses();return(r?10:8)+Be.varuint.encodingLength(this.ins.length)+Be.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+ct(i.script),0)+this.outs.reduce((n,i)=>n+8+ct(i.script),0)+(r?this.ins.reduce((n,i)=>n+wc(i.witness),0):0)}clone(){const t=new X;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(ot(ee.tuple(ee.UInt32,ee.Buffer,ee.Number),arguments),t>=this.ins.length)return yo;const i=lo.compile(lo.decompile(r).filter(a=>a!==bc.OPS.OP_CODESEPARATOR)),s=this.clone();if((n&31)===X.SIGHASH_NONE)s.outs=[],s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)});else if((n&31)===X.SIGHASH_SINGLE){if(t>=this.outs.length)return yo;s.outs.length=t+1;for(let a=0;a<t;a++)s.outs[a]=mc;s.ins.forEach((a,c)=>{c!==t&&(a.sequence=0)})}n&X.SIGHASH_ANYONECANPAY?(s.ins=[s.ins[t]],s.ins[0].script=i):(s.ins.forEach(a=>{a.script=$t}),s.ins[t].script=i);const o=Buffer.allocUnsafe(s.byteLength(!1)+4);return o.writeInt32LE(n,o.length-4),s.__toBuffer(o,0,!1),He.hash256(o)}hashForWitnessV1(t,r,n,i,s,o){if(ot(ee.tuple(ee.UInt32,ot.arrayOf(ee.Buffer),ot.arrayOf(ee.Satoshi),ee.UInt32),arguments),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const a=i===X.SIGHASH_DEFAULT?X.SIGHASH_ALL:i&X.SIGHASH_OUTPUT_MASK,l=(i&X.SIGHASH_INPUT_MASK)===X.SIGHASH_ANYONECANPAY,d=a===X.SIGHASH_NONE,b=a===X.SIGHASH_SINGLE;let E=$t,p=$t,I=$t,B=$t,A=$t;if(!l){let m=Be.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(S=>{m.writeSlice(S.hash),m.writeUInt32(S.index)}),E=He.sha256(m.end()),m=Be.BufferWriter.withCapacity(8*this.ins.length),n.forEach(S=>m.writeUInt64(S)),p=He.sha256(m.end()),m=Be.BufferWriter.withCapacity(r.map(ct).reduce((S,x)=>S+x)),r.forEach(S=>m.writeVarSlice(S)),I=He.sha256(m.end()),m=Be.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(S=>m.writeUInt32(S.sequence)),B=He.sha256(m.end())}if(d||b){if(b&&t<this.outs.length){const m=this.outs[t],S=Be.BufferWriter.withCapacity(8+ct(m.script));S.writeUInt64(m.value),S.writeVarSlice(m.script),A=He.sha256(S.end())}}else{const m=this.outs.map(x=>8+ct(x.script)).reduce((x,H)=>x+H),S=Be.BufferWriter.withCapacity(m);this.outs.forEach(x=>{S.writeUInt64(x.value),S.writeVarSlice(x.script)}),A=He.sha256(S.end())}const k=(s?2:0)+(o?1:0),U=174-(l?49:0)-(d?32:0)+(o?32:0)+(s?37:0),_=Be.BufferWriter.withCapacity(U);if(_.writeUInt8(i),_.writeInt32(this.version),_.writeUInt32(this.locktime),_.writeSlice(E),_.writeSlice(p),_.writeSlice(I),_.writeSlice(B),d||b||_.writeSlice(A),_.writeUInt8(k),l){const m=this.ins[t];_.writeSlice(m.hash),_.writeUInt32(m.index),_.writeUInt64(n[t]),_.writeVarSlice(r[t]),_.writeUInt32(m.sequence)}else _.writeUInt32(t);if(o){const m=Be.BufferWriter.withCapacity(ct(o));m.writeVarSlice(o),_.writeSlice(He.sha256(m.end()))}return b&&_.writeSlice(A),s&&(_.writeSlice(s),_.writeUInt8(0),_.writeUInt32(4294967295)),He.taggedHash("TapSighash",Buffer.concat([Buffer.from([0]),_.end()]))}hashForWitnessV0(t,r,n,i){ot(ee.tuple(ee.UInt32,ee.Buffer,ee.Satoshi,ee.UInt32),arguments);let s=Buffer.from([]),o,a=ji,c=ji,l=ji;if(i&X.SIGHASH_ANYONECANPAY||(s=Buffer.allocUnsafe(36*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(b=>{o.writeSlice(b.hash),o.writeUInt32(b.index)}),c=He.hash256(s)),!(i&X.SIGHASH_ANYONECANPAY)&&(i&31)!==X.SIGHASH_SINGLE&&(i&31)!==X.SIGHASH_NONE&&(s=Buffer.allocUnsafe(4*this.ins.length),o=new Be.BufferWriter(s,0),this.ins.forEach(b=>{o.writeUInt32(b.sequence)}),l=He.hash256(s)),(i&31)!==X.SIGHASH_SINGLE&&(i&31)!==X.SIGHASH_NONE){const b=this.outs.reduce((E,p)=>E+8+ct(p.script),0);s=Buffer.allocUnsafe(b),o=new Be.BufferWriter(s,0),this.outs.forEach(E=>{o.writeUInt64(E.value),o.writeVarSlice(E.script)}),a=He.hash256(s)}else if((i&31)===X.SIGHASH_SINGLE&&t<this.outs.length){const b=this.outs[t];s=Buffer.allocUnsafe(8+ct(b.script)),o=new Be.BufferWriter(s,0),o.writeUInt64(b.value),o.writeVarSlice(b.script),a=He.hash256(s)}s=Buffer.allocUnsafe(156+ct(r)),o=new Be.BufferWriter(s,0);const d=this.ins[t];return o.writeInt32(this.version),o.writeSlice(c),o.writeSlice(l),o.writeSlice(d.hash),o.writeUInt32(d.index),o.writeVarSlice(r),o.writeUInt64(n),o.writeUInt32(d.sequence),o.writeSlice(a),o.writeUInt32(this.locktime),o.writeUInt32(i),He.hash256(s)}getHash(t){return t&&this.isCoinbase()?Buffer.alloc(32,0):He.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,Be.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(t,r){ot(ee.tuple(ee.Number,ee.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){ot(ee.tuple(ee.Number,[ee.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=Buffer.allocUnsafe(this.byteLength(n)));const i=new Be.BufferWriter(t,r||0);i.writeInt32(this.version);const s=n&&this.hasWitnesses();return s&&(i.writeUInt8(X.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(X.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(o=>{i.writeSlice(o.hash),i.writeUInt32(o.index),i.writeVarSlice(o.script),i.writeUInt32(o.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(o=>{_c(o)?i.writeUInt64(o.value):i.writeSlice(o.valueBuffer),i.writeVarSlice(o.script)}),s&&this.ins.forEach(o=>{i.writeVector(o.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}_n.Transaction=X;X.DEFAULT_SEQUENCE=4294967295;X.SIGHASH_DEFAULT=0;X.SIGHASH_ALL=1;X.SIGHASH_NONE=2;X.SIGHASH_SINGLE=3;X.SIGHASH_ANYONECANPAY=128;X.SIGHASH_OUTPUT_MASK=3;X.SIGHASH_INPUT_MASK=128;X.ADVANCED_TRANSACTION_MARKER=0;X.ADVANCED_TRANSACTION_FLAG=1;var oe={},En={};Object.defineProperty(En,"__esModule",{value:!0});const vc=9007199254740991;function Hs(e){if(e<0||e>vc||e%1!==0)throw new RangeError("value out of range")}function un(e,t,r){if(Hs(e),t||(t=Buffer.allocUnsafe(ja(e))),!Buffer.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Object.assign(un,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(un,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(un,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(un,{bytes:9})),t}En.encode=un;function cn(e,t){if(!Buffer.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);const r=e.readUInt8(t);if(r<253)return Object.assign(cn,{bytes:1}),r;if(r===253)return Object.assign(cn,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(cn,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(cn,{bytes:9});const n=e.readUInt32LE(t+1),s=e.readUInt32LE(t+5)*4294967296+n;return Hs(s),s}}En.decode=cn;function ja(e){return Hs(e),e<253?1:e<=65535?3:e<=4294967295?5:9}En.encodingLength=ja;var Gi={},hi={},Fe={};Object.defineProperty(Fe,"__esModule",{value:!0});Fe.testnet=Fe.regtest=Fe.bitcoin=void 0;Fe.bitcoin={messagePrefix:`Bitcoin Signed Message:
7
7
  `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Fe.regtest={messagePrefix:`Bitcoin Signed Message:
8
8
  `,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};Fe.testnet={messagePrefix:`Bitcoin Signed Message:
9
- `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Ke={};Object.defineProperty(Ke,"__esModule",{value:!0});Ke.value=Ke.prop=void 0;function Ec(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}Ke.prop=Ec;function xc(e){let t;return()=>(t!==void 0||(t=e()),t)}Ke.value=xc;Object.defineProperty(hi,"__esModule",{value:!0});hi.p2data=void 0;const Sc=Fe,Vn=Ye(),at=Me,bo=Ke,wo=Vn.OPS;function Bc(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,at.typeforce)({network:at.typeforce.maybe(at.typeforce.Object),output:at.typeforce.maybe(at.typeforce.Buffer),data:at.typeforce.maybe(at.typeforce.arrayOf(at.typeforce.Buffer))},e);const n={name:"embed",network:e.network||Sc.bitcoin};if(bo.prop(n,"output",()=>{if(e.data)return Vn.compile([wo.OP_RETURN].concat(e.data))}),bo.prop(n,"data",()=>{if(e.output)return Vn.decompile(e.output).slice(1)}),t.validate&&e.output){const i=Vn.decompile(e.output);if(i[0]!==wo.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(at.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,at.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}hi.p2data=Bc;var li={};Object.defineProperty(li,"__esModule",{value:!0});li.p2ms=void 0;const Pc=Fe,xr=Ye(),Se=Me,Nt=Ke,Sr=xr.OPS,Un=Sr.OP_RESERVED;function Tc(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function r(c){return xr.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===Sr.OP_0)!==void 0}(0,Se.typeforce)({network:Se.typeforce.maybe(Se.typeforce.Object),m:Se.typeforce.maybe(Se.typeforce.Number),n:Se.typeforce.maybe(Se.typeforce.Number),output:Se.typeforce.maybe(Se.typeforce.Buffer),pubkeys:Se.typeforce.maybe(Se.typeforce.arrayOf(Se.isPoint)),signatures:Se.typeforce.maybe(Se.typeforce.arrayOf(r)),input:Se.typeforce.maybe(Se.typeforce.Buffer)},e);const i={network:e.network||Pc.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=xr.decompile(c),i.m=s[0]-Un,i.n=s[s.length-2]-Un,i.pubkeys=s.slice(1,-2))}if(Nt.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return xr.compile([].concat(Un+e.m,e.pubkeys,Un+i.n,Sr.OP_CHECKMULTISIG))}),Nt.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),Nt.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Nt.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),Nt.prop(i,"signatures",()=>{if(e.input)return xr.decompile(e.input).slice(1)}),Nt.prop(i,"input",()=>{if(e.signatures)return xr.compile([Sr.OP_0].concat(e.signatures))}),Nt.prop(i,"witness",()=>{if(i.input)return[]}),Nt.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!Se.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!Se.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==Sr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==s.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(c=>(0,Se.isPoint)(c)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==i.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==i.n)throw new TypeError("n mismatch");if(e.pubkeys&&!(0,Se.stacksEqual)(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==Sr.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,Se.stacksEqual)(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}li.p2ms=Tc;var di={};Object.defineProperty(di,"__esModule",{value:!0});di.p2pk=void 0;const Ac=Fe,Br=Ye(),rt=Me,Er=Ke,go=Br.OPS;function Ic(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,rt.typeforce)({network:rt.typeforce.maybe(rt.typeforce.Object),output:rt.typeforce.maybe(rt.typeforce.Buffer),pubkey:rt.typeforce.maybe(rt.isPoint),signature:rt.typeforce.maybe(Br.isCanonicalScriptSignature),input:rt.typeforce.maybe(rt.typeforce.Buffer)},e);const r=Er.value(()=>Br.decompile(e.input)),i={name:"p2pk",network:e.network||Ac.bitcoin};if(Er.prop(i,"output",()=>{if(e.pubkey)return Br.compile([e.pubkey,go.OP_CHECKSIG])}),Er.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),Er.prop(i,"signature",()=>{if(e.input)return r()[0]}),Er.prop(i,"input",()=>{if(e.signature)return Br.compile([e.signature])}),Er.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==go.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,rt.isPoint)(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(i.input))throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!Br.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}di.p2pk=Ic;var pi={};function Oc(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var I=0,B=0,A=0,k=p.length;A!==k&&p[A]===0;)A++,I++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=p[A],S=0,x=U-1;(m!==0||S<B)&&x!==-1;x--,S++)m+=256*_[x]>>>0,_[x]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");B=S,A++}for(var H=U-B;H!==U&&_[H]===0;)H++;for(var $=a.repeat(I);H<U;++H)$+=e.charAt(_[H]);return $}function b(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;for(var I=0,B=0,A=0;p[I]===a;)B++,I++;for(var k=(p.length-I)*c+1>>>0,U=new Uint8Array(k);p[I];){var _=t[p.charCodeAt(I)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,I++}for(var x=k-A;x!==k&&U[x]===0;)x++;for(var H=new Uint8Array(B+(k-x)),$=B;x!==k;)H[$++]=U[x++];return H}function E(p){var I=b(p);if(I)return I;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:b,decode:E}}var kc=Oc;const Rc=kc,Uc="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var Cc=Rc(Uc),Wi=Cc,Lc=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,l=new Uint8Array(c);return l.set(o,0),l.set(a.subarray(0,4),o.length),Wi.encode(l,c)}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=Wi.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Wi.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:mo}=Bt,Nc=Lc;function Fc(e){return mo(mo(e))}var Ds=Nc(Fc);Object.defineProperty(pi,"__esModule",{value:!0});pi.p2pkh=void 0;const Vi=qt,Mc=Fe,Pr=Ye(),De=Me,gt=Ke,_o=Ds,Ft=Pr.OPS;function Hc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,De.typeforce)({network:De.typeforce.maybe(De.typeforce.Object),address:De.typeforce.maybe(De.typeforce.String),hash:De.typeforce.maybe(De.typeforce.BufferN(20)),output:De.typeforce.maybe(De.typeforce.BufferN(25)),pubkey:De.typeforce.maybe(De.isPoint),signature:De.typeforce.maybe(Pr.isCanonicalScriptSignature),input:De.typeforce.maybe(De.typeforce.Buffer)},e);const r=gt.value(()=>{const o=Buffer.from(_o.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=gt.value(()=>Pr.decompile(e.input)),i=e.network||Mc.bitcoin,s={name:"p2pkh",network:i};if(gt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),_o.encode(o)}),gt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Vi.hash160(e.pubkey||s.pubkey)}),gt.prop(s,"output",()=>{if(s.hash)return Pr.compile([Ft.OP_DUP,Ft.OP_HASH160,s.hash,Ft.OP_EQUALVERIFY,Ft.OP_CHECKSIG])}),gt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),gt.prop(s,"signature",()=>{if(e.input)return n()[0]}),gt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return Pr.compile([e.signature,e.pubkey])}),gt.prop(s,"witness",()=>{if(s.input)return[]}),t.validate){let o=Buffer.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");o=r().hash}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==Ft.OP_DUP||e.output[1]!==Ft.OP_HASH160||e.output[2]!==20||e.output[23]!==Ft.OP_EQUALVERIFY||e.output[24]!==Ft.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.pubkey){const a=Vi.hash160(e.pubkey);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!Pr.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,De.isPoint)(a[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(a[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(a[1]))throw new TypeError("Pubkey mismatch");const c=Vi.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}pi.p2pkh=Hc;var yi={};Object.defineProperty(yi,"__esModule",{value:!0});yi.p2sh=void 0;const vo=qt,Dc=Fe,ht=Ye(),ce=Me,ft=Ke,Eo=Ds,Kr=ht.OPS;function $c(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,ce.typeforce)({network:ce.typeforce.maybe(ce.typeforce.Object),address:ce.typeforce.maybe(ce.typeforce.String),hash:ce.typeforce.maybe(ce.typeforce.BufferN(20)),output:ce.typeforce.maybe(ce.typeforce.BufferN(23)),redeem:ce.typeforce.maybe({network:ce.typeforce.maybe(ce.typeforce.Object),output:ce.typeforce.maybe(ce.typeforce.Buffer),input:ce.typeforce.maybe(ce.typeforce.Buffer),witness:ce.typeforce.maybe(ce.typeforce.arrayOf(ce.typeforce.Buffer))}),input:ce.typeforce.maybe(ce.typeforce.Buffer),witness:ce.typeforce.maybe(ce.typeforce.arrayOf(ce.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Dc.bitcoin);const n={network:r},i=ft.value(()=>{const a=Buffer.from(Eo.decode(e.address)),c=a.readUInt8(0),l=a.slice(1);return{version:c,hash:l}}),s=ft.value(()=>ht.decompile(e.input)),o=ft.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Kr.OP_FALSE?Buffer.from([]):c,input:ht.compile(a.slice(0,-1)),witness:e.witness||[]}});if(ft.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),Eo.encode(a)}),ft.prop(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return vo.hash160(n.redeem.output)}),ft.prop(n,"output",()=>{if(n.hash)return ht.compile([Kr.OP_HASH160,n.hash,Kr.OP_EQUAL])}),ft.prop(n,"redeem",()=>{if(e.input)return o()}),ft.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return ht.compile([].concat(ht.decompile(e.redeem.input),e.redeem.output))}),ft.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),ft.prop(n,"name",()=>{const a=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");a=i().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Kr.OP_HASH160||e.output[1]!==20||e.output[22]!==Kr.OP_EQUAL)throw new TypeError("Output is invalid");const l=e.output.slice(2,22);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}const c=l=>{if(l.output){const d=ht.decompile(l.output);if(!d||d.length<1)throw new TypeError("Redeem.output too short");if(l.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(ht.countNonPushOnlyOPs(d)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const b=vo.hash160(l.output);if(a.length>0&&!a.equals(b))throw new TypeError("Hash mismatch");a=b}if(l.input){const d=l.input.length>0,b=l.witness&&l.witness.length>0;if(!d&&!b)throw new TypeError("Empty input");if(d&&b)throw new TypeError("Input and witness provided");if(d){const E=ht.decompile(l.input);if(!ht.isPushOnly(E))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const l=s();if(!l||l.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(o().output))throw new TypeError("Input is invalid");c(o())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const l=o();if(e.redeem.output&&!e.redeem.output.equals(l.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(l.input))throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,ce.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}yi.p2sh=$c;var bi={},At={};Object.defineProperty(At,"__esModule",{value:!0});At.bech32m=At.bech32=void 0;const ei="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Ga={};for(let e=0;e<ei.length;e++){const t=ei.charAt(e);Ga[t]=e}function Ir(e){const t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function xo(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=Ir(t)^n>>5}t=Ir(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=Ir(t)^n&31}return t}function $s(e,t,r,n){let i=0,s=0;const o=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],s+=t;s>=r;)s-=r,a.push(i>>s&o);if(n)s>0&&a.push(i<<r-s&o);else{if(s>=t)return"Excess padding";if(i<<r-s&o)return"Non-zero padding"}return a}function jc(e){return $s(e,8,5,!0)}function Gc(e){const t=$s(e,5,8,!1);if(Array.isArray(t))return t}function Wc(e){const t=$s(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Wa(e){let t;e==="bech32"?t=1:t=734539939;function r(o,a,c){if(c=c||90,o.length+7+a.length>c)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let l=xo(o);if(typeof l=="string")throw new Error(l);let d=o+"1";for(let b=0;b<a.length;++b){const E=a[b];if(E>>5)throw new Error("Non 5-bit word");l=Ir(l)^E,d+=ei.charAt(E)}for(let b=0;b<6;++b)l=Ir(l);l^=t;for(let b=0;b<6;++b){const E=l>>(5-b)*5&31;d+=ei.charAt(E)}return d}function n(o,a){if(a=a||90,o.length<8)return o+" too short";if(o.length>a)return"Exceeds length limit";const c=o.toLowerCase(),l=o.toUpperCase();if(o!==c&&o!==l)return"Mixed-case string "+o;o=c;const d=o.lastIndexOf("1");if(d===-1)return"No separator character for "+o;if(d===0)return"Missing prefix for "+o;const b=o.slice(0,d),E=o.slice(d+1);if(E.length<6)return"Data too short";let p=xo(b);if(typeof p=="string")return p;const I=[];for(let B=0;B<E.length;++B){const A=E.charAt(B),k=Ga[A];if(k===void 0)return"Unknown character "+A;p=Ir(p)^k,!(B+6>=E.length)&&I.push(k)}return p!==t?"Invalid checksum for "+o:{prefix:b,words:I}}function i(o,a){const c=n(o,a);if(typeof c=="object")return c}function s(o,a){const c=n(o,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:s,encode:r,toWords:jc,fromWordsUnsafe:Gc,fromWords:Wc}}At.bech32=Wa("bech32");At.bech32m=Wa("bech32m");Object.defineProperty(bi,"__esModule",{value:!0});bi.p2wpkh=void 0;const zi=qt,Vc=Fe,zn=Ye(),Pe=Me,Mt=Ke,Cn=At,So=zn.OPS,zc=Buffer.alloc(0);function qc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,Pe.typeforce)({address:Pe.typeforce.maybe(Pe.typeforce.String),hash:Pe.typeforce.maybe(Pe.typeforce.BufferN(20)),input:Pe.typeforce.maybe(Pe.typeforce.BufferN(0)),network:Pe.typeforce.maybe(Pe.typeforce.Object),output:Pe.typeforce.maybe(Pe.typeforce.BufferN(22)),pubkey:Pe.typeforce.maybe(Pe.isPoint),signature:Pe.typeforce.maybe(zn.isCanonicalScriptSignature),witness:Pe.typeforce.maybe(Pe.typeforce.arrayOf(Pe.typeforce.Buffer))},e);const r=Mt.value(()=>{const s=Cn.bech32.decode(e.address),o=s.words.shift(),a=Cn.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||Vc.bitcoin,i={name:"p2wpkh",network:n};if(Mt.prop(i,"address",()=>{if(!i.hash)return;const s=Cn.bech32.toWords(i.hash);return s.unshift(0),Cn.bech32.encode(n.bech32,s)}),Mt.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return zi.hash160(e.pubkey||i.pubkey)}),Mt.prop(i,"output",()=>{if(i.hash)return zn.compile([So.OP_0,i.hash])}),Mt.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Mt.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Mt.prop(i,"input",()=>{if(i.witness)return zc}),Mt.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let s=Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==So.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(s.length>0&&!s.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");s=e.output.slice(2)}if(e.pubkey){const o=zi.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Pe.isPoint)(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!zn.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Pe.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const o=zi.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}bi.p2wpkh=qc;var wi={};Object.defineProperty(wi,"__esModule",{value:!0});wi.p2wsh=void 0;const Bo=qt,Kc=Fe,Et=Ye(),ae=Me,mt=Ke,Ln=At,Po=Et.OPS,qi=Buffer.alloc(0);function Nn(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,ae.isPoint)(e))}function Yc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,ae.typeforce)({network:ae.typeforce.maybe(ae.typeforce.Object),address:ae.typeforce.maybe(ae.typeforce.String),hash:ae.typeforce.maybe(ae.typeforce.BufferN(32)),output:ae.typeforce.maybe(ae.typeforce.BufferN(34)),redeem:ae.typeforce.maybe({input:ae.typeforce.maybe(ae.typeforce.Buffer),network:ae.typeforce.maybe(ae.typeforce.Object),output:ae.typeforce.maybe(ae.typeforce.Buffer),witness:ae.typeforce.maybe(ae.typeforce.arrayOf(ae.typeforce.Buffer))}),input:ae.typeforce.maybe(ae.typeforce.BufferN(0)),witness:ae.typeforce.maybe(ae.typeforce.arrayOf(ae.typeforce.Buffer))},e);const r=mt.value(()=>{const o=Ln.bech32.decode(e.address),a=o.words.shift(),c=Ln.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=mt.value(()=>Et.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Kc.bitcoin);const s={network:i};if(mt.prop(s,"address",()=>{if(!s.hash)return;const o=Ln.bech32.toWords(s.hash);return o.unshift(0),Ln.bech32.encode(i.bech32,o)}),mt.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return Bo.sha256(s.redeem.output)}),mt.prop(s,"output",()=>{if(s.hash)return Et.compile([Po.OP_0,s.hash])}),mt.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:qi,witness:e.witness.slice(0,-1)}}),mt.prop(s,"input",()=>{if(s.witness)return qi}),mt.prop(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=Et.toStack(n());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=qi,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),mt.prop(s,"name",()=>{const o=["p2wsh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&o.push(s.redeem.name),o.join("-")}),t.validate){let o=Buffer.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==Po.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const a=Et.decompile(e.redeem.output);if(!a||a.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(Et.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=Bo.sha256(e.redeem.output);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch");o=c}if(e.redeem.input&&!Et.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,ae.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Nn)||e.redeem.output&&(Et.decompile(e.redeem.output)||[]).some(Nn))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const a=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(a))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(Nn)||(Et.decompile(a)||[]).some(Nn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}wi.p2wsh=Yc;var Yr={},ar={};Object.defineProperty(ar,"__esModule",{value:!0});ar.getEccLib=ar.initEccLib=void 0;const hn={};function Xc(e){e?e!==hn.eccLib&&(Qc(e),hn.eccLib=e):hn.eccLib=e}ar.initEccLib=Xc;function Jc(){if(!hn.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return hn.eccLib}ar.getEccLib=Jc;const _t=e=>Buffer.from(e,"hex");function Qc(e){Je(typeof e.isXOnlyPoint=="function"),Je(e.isXOnlyPoint(_t("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Je(e.isXOnlyPoint(_t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Je(e.isXOnlyPoint(_t("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Je(e.isXOnlyPoint(_t("0000000000000000000000000000000000000000000000000000000000000001"))),Je(!e.isXOnlyPoint(_t("0000000000000000000000000000000000000000000000000000000000000000"))),Je(!e.isXOnlyPoint(_t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Je(typeof e.xOnlyPointAddTweak=="function"),Zc.forEach(t=>{const r=e.xOnlyPointAddTweak(_t(t.pubkey),_t(t.tweak));t.result===null?Je(r===null):(Je(r!==null),Je(r.parity===t.parity),Je(Buffer.from(r.xOnlyPubkey).equals(_t(t.result))))})}function Je(e){if(!e)throw new Error("ecc library invalid")}const Zc=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];var js={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=Ot,r=ar,n=qt,i=Ie,s=Me;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=B=>"left"in B&&"right"in B;function a(B,A){if(B.length<33)throw new TypeError(`The control-block length is too small. Got ${B.length}, expected min 33.`);const k=(B.length-33)/32;let U=A;for(let _=0;_<k;_++){const m=B.slice(33+32*_,65+32*_);U.compare(m)<0?U=p(U,m):U=p(m,U)}return U}e.rootHashFromPath=a;function c(B){if((0,s.isTapleaf)(B))return{hash:d(B)};const A=[c(B[0]),c(B[1])];A.sort((_,m)=>_.hash.compare(m.hash));const[k,U]=A;return{hash:p(k.hash,U.hash),left:k,right:U}}e.toHashTree=c;function l(B,A){if(o(B)){const k=l(B.left,A);if(k!==void 0)return[...k,B.right.hash];const U=l(B.right,A);if(U!==void 0)return[...U,B.left.hash]}else if(B.hash.equals(A))return[]}e.findScriptPath=l;function d(B){const A=B.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([A]),I(B.output)]))}e.tapleafHash=d;function b(B,A){return n.taggedHash("TapTweak",t.Buffer.concat(A?[B,A]:[B]))}e.tapTweakHash=b;function E(B,A){if(!t.Buffer.isBuffer(B)||B.length!==32||A&&A.length!==32)return null;const k=b(B,A),U=(0,r.getEccLib)().xOnlyPointAddTweak(B,k);return!U||U.xOnlyPubkey===null?null:{parity:U.parity,x:t.Buffer.from(U.xOnlyPubkey)}}e.tweakKey=E;function p(B,A){return n.taggedHash("TapBranch",t.Buffer.concat([B,A]))}function I(B){const A=i.varuint.encodingLength(B.length),k=t.Buffer.allocUnsafe(A);return i.varuint.encode(B.length,k),t.Buffer.concat([k,B])}})(js);var $e={},To;function eh(){if(To)return $e;To=1,Object.defineProperty($e,"__esModule",{value:!0}),$e.toOutputScript=$e.fromOutputScript=$e.toBech32=$e.toBase58Check=$e.fromBech32=$e.fromBase58Check=void 0;const e=Fe,t=Gs(),r=Ye(),n=Me,i=At,s=Ds,o=40,a=2,c=16,l=2,d=80,b="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function E(_,m){const S=_.slice(2);if(S.length<a||S.length>o)throw new TypeError("Invalid program length for segwit address");const x=_[0]-d;if(x<l||x>c)throw new TypeError("Invalid version for segwit address");if(_[1]!==S.length)throw new TypeError("Invalid script for segwit address");return console.warn(b),A(S,x,m.bech32)}function p(_){const m=Buffer.from(s.decode(_));if(m.length<21)throw new TypeError(_+" is too short");if(m.length>21)throw new TypeError(_+" is too long");const S=m.readUInt8(0),x=m.slice(1);return{version:S,hash:x}}$e.fromBase58Check=p;function I(_){let m,S;try{m=i.bech32.decode(_)}catch{}if(m){if(S=m.words[0],S!==0)throw new TypeError(_+" uses wrong encoding")}else if(m=i.bech32m.decode(_),S=m.words[0],S===0)throw new TypeError(_+" uses wrong encoding");const x=i.bech32.fromWords(m.words.slice(1));return{version:S,prefix:m.prefix,data:Buffer.from(x)}}$e.fromBech32=I;function B(_,m){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const S=Buffer.allocUnsafe(21);return S.writeUInt8(m,0),_.copy(S,1),s.encode(S)}$e.toBase58Check=B;function A(_,m,S){const x=i.bech32.toWords(_);return x.unshift(m),m===0?i.bech32.encode(S,x):i.bech32m.encode(S,x)}$e.toBech32=A;function k(_,m){m=m||e.bitcoin;try{return t.p2pkh({output:_,network:m}).address}catch{}try{return t.p2sh({output:_,network:m}).address}catch{}try{return t.p2wpkh({output:_,network:m}).address}catch{}try{return t.p2wsh({output:_,network:m}).address}catch{}try{return t.p2tr({output:_,network:m}).address}catch{}try{return E(_,m)}catch{}throw new Error(r.toASM(_)+" has no matching Address")}$e.fromOutputScript=k;function U(_,m){m=m||e.bitcoin;let S,x;try{S=p(_)}catch{}if(S){if(S.version===m.pubKeyHash)return t.p2pkh({hash:S.hash}).output;if(S.version===m.scriptHash)return t.p2sh({hash:S.hash}).output}else{try{x=I(_)}catch{}if(x){if(x.prefix!==m.bech32)throw new Error(_+" has an invalid prefix");if(x.version===0){if(x.data.length===20)return t.p2wpkh({hash:x.data}).output;if(x.data.length===32)return t.p2wsh({hash:x.data}).output}else if(x.version===1){if(x.data.length===32)return t.p2tr({pubkey:x.data}).output}else if(x.version>=l&&x.version<=c&&x.data.length>=a&&x.data.length<=o)return console.warn(b),r.compile([x.version+d,x.data])}}throw new Error(_+" has no matching Script")}return $e.toOutputScript=U,$e}var Ao;function th(){if(Ao)return Yr;Ao=1,Object.defineProperty(Yr,"__esModule",{value:!0}),Yr.p2tr=void 0;const e=Ot,t=Fe,r=Ye(),n=Me,i=ar,s=js,o=Ke,a=At,c=eh(),l=r.OPS,d=1,b=80;function E(p,I){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");I=Object.assign({validate:!0},I||{}),(0,n.typeforce)({address:n.typeforce.maybe(n.typeforce.String),input:n.typeforce.maybe(n.typeforce.BufferN(0)),network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.BufferN(34)),internalPubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),hash:n.typeforce.maybe(n.typeforce.BufferN(32)),pubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),signature:n.typeforce.maybe(n.typeforce.anyOf(n.typeforce.BufferN(64),n.typeforce.BufferN(65))),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer)),scriptTree:n.typeforce.maybe(n.isTaptree),redeem:n.typeforce.maybe({output:n.typeforce.maybe(n.typeforce.Buffer),redeemVersion:n.typeforce.maybe(n.typeforce.Number),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))}),redeemVersion:n.typeforce.maybe(n.typeforce.Number)},p);const B=o.value(()=>(0,c.fromBech32)(p.address)),A=o.value(()=>{if(!(!p.witness||!p.witness.length))return p.witness.length>=2&&p.witness[p.witness.length-1][0]===b?p.witness.slice(0,-1):p.witness.slice()}),k=o.value(()=>{if(p.scriptTree)return(0,s.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),U=p.network||t.bitcoin,_={name:"p2tr",network:U};if(o.prop(_,"address",()=>{if(!_.pubkey)return;const m=a.bech32m.toWords(_.pubkey);return m.unshift(d),a.bech32m.encode(U.bech32,m)}),o.prop(_,"hash",()=>{const m=k();if(m)return m.hash;const S=A();if(S&&S.length>1){const x=S[S.length-1],H=x[0]&n.TAPLEAF_VERSION_MASK,$=S[S.length-2],R=(0,s.tapleafHash)({output:$,version:H});return(0,s.rootHashFromPath)(x,R)}return null}),o.prop(_,"output",()=>{if(_.pubkey)return r.compile([l.OP_1,_.pubkey])}),o.prop(_,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(_,"redeem",()=>{const m=A();if(!(!m||m.length<2))return{output:m[m.length-2],witness:m.slice(0,-2),redeemVersion:m[m.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(_,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return B().data;if(_.internalPubkey){const m=(0,s.tweakKey)(_.internalPubkey,_.hash);if(m)return m.x}}),o.prop(_,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const m=A();if(m&&m.length>1)return m[m.length-1].slice(1,33)}),o.prop(_,"signature",()=>{if(p.signature)return p.signature;const m=A();if(!(!m||m.length!==1))return m[0]}),o.prop(_,"witness",()=>{if(p.witness)return p.witness;const m=k();if(m&&p.redeem&&p.redeem.output&&p.internalPubkey){const S=(0,s.tapleafHash)({output:p.redeem.output,version:_.redeemVersion}),x=(0,s.findScriptPath)(m,S);if(!x)return;const H=(0,s.tweakKey)(p.internalPubkey,m.hash);if(!H)return;const $=e.Buffer.concat([e.Buffer.from([_.redeemVersion|H.parity]),p.internalPubkey].concat(x));return[p.redeem.output,$]}if(p.signature)return[p.signature]}),I.validate){let m=e.Buffer.from([]);if(p.address){if(U&&U.bech32!==B().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(B().version!==d)throw new TypeError("Invalid address version");if(B().data.length!==32)throw new TypeError("Invalid address data");m=B().data}if(p.pubkey){if(m.length>0&&!m.equals(p.pubkey))throw new TypeError("Pubkey mismatch");m=p.pubkey}if(p.output){if(p.output.length!==34||p.output[0]!==l.OP_1||p.output[1]!==32)throw new TypeError("Output is invalid");if(m.length>0&&!m.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");m=p.output.slice(2)}if(p.internalPubkey){const H=(0,s.tweakKey)(p.internalPubkey,_.hash);if(m.length>0&&!m.equals(H.x))throw new TypeError("Pubkey mismatch");m=H.x}if(m&&m.length&&!(0,i.getEccLib)().isXOnlyPoint(m))throw new TypeError("Invalid pubkey for p2tr");const S=k();if(p.hash&&S&&!p.hash.equals(S.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&S){const H=(0,s.tapleafHash)({output:p.redeem.output,version:_.redeemVersion});if(!(0,s.findScriptPath)(S,H))throw new TypeError("Redeem script not in tree")}const x=A();if(p.redeem&&_.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==_.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(p.redeem.output){if(r.decompile(p.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(_.redeem.output&&!p.redeem.output.equals(_.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&_.redeem.witness&&!(0,n.stacksEqual)(p.redeem.witness,_.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(x&&x.length)if(x.length===1){if(p.signature&&!p.signature.equals(x[0]))throw new TypeError("Signature mismatch")}else{const H=x[x.length-1];if(H.length<33)throw new TypeError(`The control-block length is too small. Got ${H.length}, expected min 33.`);if((H.length-33)%32!==0)throw new TypeError(`The control-block length of ${H.length} is incorrect!`);const $=(H.length-33)/32;if($>128)throw new TypeError(`The script path is too long. Got ${$}, expected max 128.`);const R=H.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(R))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(R))throw new TypeError("Invalid internalPubkey for p2tr witness");const z=H[0]&n.TAPLEAF_VERSION_MASK,Z=x[x.length-2],C=(0,s.tapleafHash)({output:Z,version:z}),M=(0,s.rootHashFromPath)(H,C),W=(0,s.tweakKey)(R,M);if(!W)throw new TypeError("Invalid outputKey for p2tr witness");if(m.length&&!m.equals(W.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(W.parity!==(H[0]&1))throw new Error("Incorrect parity")}}return Object.assign(_,p)}return Yr.p2tr=E,Yr}var Io;function Gs(){return Io||(Io=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=hi;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=li;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=di;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=pi;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=yi;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=bi;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=wi;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=th();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Gi)),Gi}Object.defineProperty(oe,"__esModule",{value:!0});oe.signatureBlocksAction=oe.checkInputForSig=oe.pubkeyInScript=oe.pubkeyPositionInScript=oe.witnessStackToScriptWitness=oe.isP2TR=oe.isP2SHScript=oe.isP2WSHScript=oe.isP2WPKH=oe.isP2PKH=oe.isP2PK=oe.isP2MS=void 0;const Oo=En,ln=Ye(),Fn=_n,rh=qt,dr=Gs();function pr(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}oe.isP2MS=pr(dr.p2ms);oe.isP2PK=pr(dr.p2pk);oe.isP2PKH=pr(dr.p2pkh);oe.isP2WPKH=pr(dr.p2wpkh);oe.isP2WSHScript=pr(dr.p2wsh);oe.isP2SHScript=pr(dr.p2sh);oe.isP2TR=pr(dr.p2tr);function nh(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=Oo.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Oo.encode(o,t,a)}function i(o){n(o.length),r(o)}function s(o){n(o.length),o.forEach(i)}return s(e),t}oe.witnessStackToScriptWitness=nh;function Va(e,t){const r=(0,rh.hash160)(e),n=e.slice(1,33),i=ln.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(s=>typeof s=="number"?!1:s.equals(e)||s.equals(r)||s.equals(n))}oe.pubkeyPositionInScript=Va;function ih(e,t){return Va(e,t)!==-1}oe.pubkeyInScript=ih;function sh(e,t){return oh(e).some(n=>za(n,ln.signature.decode,t))}oe.checkInputForSig=sh;function za(e,t,r){const{hashType:n}=t(e),i=[];switch(n&Fn.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case Fn.Transaction.SIGHASH_ALL:break;case Fn.Transaction.SIGHASH_SINGLE:case Fn.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}oe.signatureBlocksAction=za;function oh(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=ah(e)}else t=e.partialSig;return t.map(r=>r.signature)}function ah(e){const t=e.finalScriptSig?ln.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?ln.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&ln.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(_e,"__esModule",{value:!0});_e.checkTaprootInputForSigs=_e.tapTreeFromList=_e.tapTreeToList=_e.tweakInternalPubKey=_e.checkTaprootOutputFields=_e.checkTaprootInputFields=_e.isTaprootOutput=_e.isTaprootInput=qn=_e.serializeTaprootSignature=_e.tapScriptFinalizer=_e.toXOnly=void 0;const Ws=Me,fh=_n,gi=oe,zt=js,uh=Gs(),ch=oe,hh=e=>e.length===32?e:e.slice(1,33);_e.toXOnly=hh;function lh(e,t,r){const n=Oh(t,e,r);try{const s=Ah(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,gi.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}_e.tapScriptFinalizer=lh;function dh(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var qn=_e.serializeTaprootSignature=dh;function Kn(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,gi.isP2TR)(e.witnessUtxo.script))}_e.isTaprootInput=Kn;function Yn(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,gi.isP2TR)(t))}_e.isTaprootOutput=Yn;function ph(e,t,r){Bh(e,t,r),Th(e,t,r)}_e.checkTaprootInputFields=ph;function yh(e,t,r){Ph(e,t,r),bh(e,t)}_e.checkTaprootOutputFields=yh;function bh(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,s=wh(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function wh(e,t){const r=t&&qa(t.leaves),{output:n}=(0,uh.p2tr)({internalPubkey:e,scriptTree:r});return n}function gh(e,t){const r=t.tapInternalKey,n=r&&(0,zt.tweakKey)(r,t.tapMerkleRoot);if(!n)throw new Error(`Cannot tweak tap internal key for input #${e}. Public key: ${r&&r.toString("hex")}`);return n.x}_e.tweakInternalPubKey=gh;function mh(e){if(!(0,Ws.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ys(e)}_e.tapTreeToList=mh;function qa(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:Sh(e)}_e.tapTreeFromList=qa;function _h(e,t){return Eh(e).some(n=>(0,ch.signatureBlocksAction)(n,vh,t))}_e.checkTaprootInputForSigs=_h;function vh(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||fh.Transaction.SIGHASH_DEFAULT}}function Eh(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=xh(e.finalScriptWitness);r&&t.push(r)}return t}function xh(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function ys(e,t=[],r=0){if(r>zt.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,Ws.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||zt.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&ys(e[0],t,r+1),e[1]&&ys(e[1],t,r+1),t):[]}function Sh(e){let t;for(const r of e)if(t=bs(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function bs(e,t,r=0){if(r>zt.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if((0,Ws.isTapleaf)(t))return;const n=bs(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=bs(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function Bh(e,t,r){const n=Kn(e)&&Or(t),i=Or(e)&&Kn(t),s=e===t&&Kn(t)&&Or(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Ph(e,t,r){const n=Yn(e)&&Or(t),i=Or(e)&&Yn(t),s=e===t&&Yn(t)&&Or(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Th(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>Ki(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Ki(s,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>Ki(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Ki(e,t){if(!t)return!0;const r=(0,zt.tapleafHash)({output:e.script,version:e.leafVersion});return(0,zt.rootHashFromPath)(e.controlBlock,r).equals(t)}function Ah(e,t){const r=(0,zt.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>Ih(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function Ih(e,t){return Object.assign({positionInScript:(0,gi.pubkeyPositionInScript)(t.pubkey,e)},t)}function Oh(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((i,s)=>i.controlBlock.length-s.controlBlock.length).find(i=>kh(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function kh(e,t,r){const n=(0,zt.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function Or(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const ke={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},Mn=192;se.initEccLib(sr);class dn{constructor(t,r,n,i,s,o,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=s,this.expiry=o,this.signer=t,this.network=a,this.internalPubkey=Tu(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,_r(n.length===64,ke.secretHashLenMismatch),_r(i.length===64||i.length===66,`initiator ${ke.pubkeyLenMismatch}`),_r(s.length===64||s.length===66,`redeemer ${ke.pubkeyLenMismatch}`),_r(o>0,ke.zeroOrNegativeExpiry);const c=await t.getNetwork();return new dn(t,r,n,ls(s).toString("hex"),ls(i).toString("hex"),o,c,a)}address(){const{address:t}=se.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(ke.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new se.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const l=await s.getTransaction(c);for(let d=0;d<l.vout.length;d++){const b=l.vout[d];b.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:b.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,l)=>c+l.value,0);if(a===0)throw new Error(`${i} ${ke.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);return r??(r=await s.suggestFee(i,a,Rr.Urgency.MEDIUM)),n.addOutput(se.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async _tempBuildRawTx(t,r){const n=new se.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const l=await s.getTransaction(c);for(let d=0;d<l.vout.length;d++){const b=l.vout[d];b.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:b.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,l)=>c+l.value,0);if(a===0)throw new Error(`${i} ${ke.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);if(n.addOutput(se.address.toOutputScript(t,this.network),a),r){const l=(await s.getFeeRates()).hourFee*r,d=a-l;n.outs[0].value=d}return{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return se.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Rr.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateRedeemSACP(t,r,n){const{tx:i,usedUtxos:s}=await this._buildRawTx(r,n),o=this.getOutputScript(),a=se.Transaction.SIGHASH_SINGLE|se.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),l=s.map(b=>b.value),d=Xr(o,s.length);for(let b=0;b<i.ins.length;b++){const E=i.hashForWitnessV1(b,d,l,a,c),p=await this.signer.signSchnorr(E);i.setWitness(b,[qn(p,a),Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return i.toHex()}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),s=this.getOutputScript(),o=se.Transaction.SIGHASH_SINGLE|se.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(d=>d.value),l=Xr(s,i.length);for(let d=0;d<n.ins.length;d++){const b=n.hashForWitnessV1(d,l,c,o,a),E=await this.signer.signSchnorr(b);n.setWitness(d,[qn(E,o),qn(E,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){_r(t.length>0,ke.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const b of i)if(!t.find(E=>E.utxo===b.txid))throw new Error(ke.counterPartySigNotFound(b.txid));const s=this.getOutputScript(),o=se.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(b=>b.value),l=Xr(s,i.length);for(let b=0;b<n.ins.length;b++){const E=n.hashForWitnessV1(b,l,c,o,a);if(!sr.verifySchnorr(E,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[b].sig,"hex")))throw new Error(ke.invalidCounterpartySigForUTXO(t[b].utxo));const p=await this.signer.signSchnorr(E),I=Buffer.from(n.ins[b].hash).reverse().toString("hex"),B=t.find(A=>A.utxo===I);if(!B)throw new Error(ke.counterPartySigNotFound(I));n.setWitness(b,[Buffer.from(B.sig,"hex"),p,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){_r(se.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,ke.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(E=>E.value),c=Xr(this.getOutputScript(),s.length),l=se.Transaction.SIGHASH_DEFAULT;for(let E=0;E<i.ins.length;E++){const p=i.hashForWitnessV1(E,c,a,l,o),I=await this.signer.signSchnorr(p);i.setWitness(E,[I,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:d}=await this._tempBuildRawTx(n,i.virtualSize());for(let E=0;E<d.ins.length;E++){const p=d.hashForWitnessV1(E,c,a,l,o),I=await this.signer.signSchnorr(p);d.setWitness(E,[I,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(d.toHex())}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[s,o]=await this.canRefund(i);if(!s)throw new Error(ke.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(E=>E.value),l=Xr(this.getOutputScript(),i.length),d=se.Transaction.SIGHASH_DEFAULT;for(let E=0;E<n.ins.length;E++){n.ins[E].sequence=this.expiry;const p=n.hashForWitnessV1(E,l,c,d,a),I=await this.signer.signSchnorr(p);n.setWitness(E,[I,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let s=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?s=i.status.block_height+this.expiry-n+1:i.status.confirmed||(s=this.expiry+1),s>0)return[!1,s]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(ke.invalidLeaf)}const n=se.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:Mn}});if(!n.witness)throw new Error(ke.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),se.crypto.taggedHash("TapLeaf",pu(r))}refundLeaf(){return se.script.fromASM(`
9
+ `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Ke={};Object.defineProperty(Ke,"__esModule",{value:!0});Ke.value=Ke.prop=void 0;function Ec(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}Ke.prop=Ec;function xc(e){let t;return()=>(t!==void 0||(t=e()),t)}Ke.value=xc;Object.defineProperty(hi,"__esModule",{value:!0});hi.p2data=void 0;const Sc=Fe,Vn=Ye(),at=Me,bo=Ke,wo=Vn.OPS;function Bc(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,at.typeforce)({network:at.typeforce.maybe(at.typeforce.Object),output:at.typeforce.maybe(at.typeforce.Buffer),data:at.typeforce.maybe(at.typeforce.arrayOf(at.typeforce.Buffer))},e);const n={name:"embed",network:e.network||Sc.bitcoin};if(bo.prop(n,"output",()=>{if(e.data)return Vn.compile([wo.OP_RETURN].concat(e.data))}),bo.prop(n,"data",()=>{if(e.output)return Vn.decompile(e.output).slice(1)}),t.validate&&e.output){const i=Vn.decompile(e.output);if(i[0]!==wo.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(at.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,at.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}hi.p2data=Bc;var li={};Object.defineProperty(li,"__esModule",{value:!0});li.p2ms=void 0;const Pc=Fe,xr=Ye(),Se=Me,Nt=Ke,Sr=xr.OPS,Un=Sr.OP_RESERVED;function Tc(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function r(c){return xr.isCanonicalScriptSignature(c)||(t.allowIncomplete&&c===Sr.OP_0)!==void 0}(0,Se.typeforce)({network:Se.typeforce.maybe(Se.typeforce.Object),m:Se.typeforce.maybe(Se.typeforce.Number),n:Se.typeforce.maybe(Se.typeforce.Number),output:Se.typeforce.maybe(Se.typeforce.Buffer),pubkeys:Se.typeforce.maybe(Se.typeforce.arrayOf(Se.isPoint)),signatures:Se.typeforce.maybe(Se.typeforce.arrayOf(r)),input:Se.typeforce.maybe(Se.typeforce.Buffer)},e);const i={network:e.network||Pc.bitcoin};let s=[],o=!1;function a(c){o||(o=!0,s=xr.decompile(c),i.m=s[0]-Un,i.n=s[s.length-2]-Un,i.pubkeys=s.slice(1,-2))}if(Nt.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return xr.compile([].concat(Un+e.m,e.pubkeys,Un+i.n,Sr.OP_CHECKMULTISIG))}),Nt.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),Nt.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),Nt.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),Nt.prop(i,"signatures",()=>{if(e.input)return xr.decompile(e.input).slice(1)}),Nt.prop(i,"input",()=>{if(e.signatures)return xr.compile([Sr.OP_0].concat(e.signatures))}),Nt.prop(i,"witness",()=>{if(i.input)return[]}),Nt.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!Se.typeforce.Number(s[0]))throw new TypeError("Output is invalid");if(!Se.typeforce.Number(s[s.length-2]))throw new TypeError("Output is invalid");if(s[s.length-1]!==Sr.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==s.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(c=>(0,Se.isPoint)(c)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==i.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==i.n)throw new TypeError("n mismatch");if(e.pubkeys&&!(0,Se.stacksEqual)(e.pubkeys,i.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(i.n=e.pubkeys.length,i.n<i.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<i.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>i.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==Sr.OP_0)throw new TypeError("Input is invalid");if(i.signatures.length===0||!i.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,Se.stacksEqual)(e.signatures,i.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(i,e)}li.p2ms=Tc;var di={};Object.defineProperty(di,"__esModule",{value:!0});di.p2pk=void 0;const Ac=Fe,Br=Ye(),rt=Me,Er=Ke,go=Br.OPS;function Ic(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,rt.typeforce)({network:rt.typeforce.maybe(rt.typeforce.Object),output:rt.typeforce.maybe(rt.typeforce.Buffer),pubkey:rt.typeforce.maybe(rt.isPoint),signature:rt.typeforce.maybe(Br.isCanonicalScriptSignature),input:rt.typeforce.maybe(rt.typeforce.Buffer)},e);const r=Er.value(()=>Br.decompile(e.input)),i={name:"p2pk",network:e.network||Ac.bitcoin};if(Er.prop(i,"output",()=>{if(e.pubkey)return Br.compile([e.pubkey,go.OP_CHECKSIG])}),Er.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),Er.prop(i,"signature",()=>{if(e.input)return r()[0]}),Er.prop(i,"input",()=>{if(e.signature)return Br.compile([e.signature])}),Er.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==go.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,rt.isPoint)(i.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(i.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(i.input))throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!Br.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}di.p2pk=Ic;var pi={};function Oc(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=n}var o=e.length,a=e.charAt(0),c=Math.log(o)/Math.log(256),l=Math.log(256)/Math.log(o);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var I=0,B=0,A=0,k=p.length;A!==k&&p[A]===0;)A++,I++;for(var U=(k-A)*l+1>>>0,_=new Uint8Array(U);A!==k;){for(var m=p[A],S=0,x=U-1;(m!==0||S<B)&&x!==-1;x--,S++)m+=256*_[x]>>>0,_[x]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");B=S,A++}for(var H=U-B;H!==U&&_[H]===0;)H++;for(var $=a.repeat(I);H<U;++H)$+=e.charAt(_[H]);return $}function b(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;for(var I=0,B=0,A=0;p[I]===a;)B++,I++;for(var k=(p.length-I)*c+1>>>0,U=new Uint8Array(k);p[I];){var _=t[p.charCodeAt(I)];if(_===255)return;for(var m=0,S=k-1;(_!==0||m<A)&&S!==-1;S--,m++)_+=o*U[S]>>>0,U[S]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");A=m,I++}for(var x=k-A;x!==k&&U[x]===0;)x++;for(var H=new Uint8Array(B+(k-x)),$=B;x!==k;)H[$++]=U[x++];return H}function E(p){var I=b(p);if(I)return I;throw new Error("Non-base"+o+" character")}return{encode:d,decodeUnsafe:b,decode:E}}var kc=Oc;const Rc=kc,Uc="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var Cc=Rc(Uc),Wi=Cc,Lc=function(e){function t(s){var o=Uint8Array.from(s),a=e(o),c=o.length+4,l=new Uint8Array(c);return l.set(o,0),l.set(a.subarray(0,4),o.length),Wi.encode(l,c)}function r(s){var o=s.slice(0,-4),a=s.slice(-4),c=e(o);if(!(a[0]^c[0]|a[1]^c[1]|a[2]^c[2]|a[3]^c[3]))return o}function n(s){var o=Wi.decodeUnsafe(s);if(o)return r(o)}function i(s){var o=Wi.decode(s),a=r(o);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:mo}=Bt,Nc=Lc;function Fc(e){return mo(mo(e))}var Ds=Nc(Fc);Object.defineProperty(pi,"__esModule",{value:!0});pi.p2pkh=void 0;const Vi=qt,Mc=Fe,Pr=Ye(),De=Me,gt=Ke,_o=Ds,Ft=Pr.OPS;function Hc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,De.typeforce)({network:De.typeforce.maybe(De.typeforce.Object),address:De.typeforce.maybe(De.typeforce.String),hash:De.typeforce.maybe(De.typeforce.BufferN(20)),output:De.typeforce.maybe(De.typeforce.BufferN(25)),pubkey:De.typeforce.maybe(De.isPoint),signature:De.typeforce.maybe(Pr.isCanonicalScriptSignature),input:De.typeforce.maybe(De.typeforce.Buffer)},e);const r=gt.value(()=>{const o=Buffer.from(_o.decode(e.address)),a=o.readUInt8(0),c=o.slice(1);return{version:a,hash:c}}),n=gt.value(()=>Pr.decompile(e.input)),i=e.network||Mc.bitcoin,s={name:"p2pkh",network:i};if(gt.prop(s,"address",()=>{if(!s.hash)return;const o=Buffer.allocUnsafe(21);return o.writeUInt8(i.pubKeyHash,0),s.hash.copy(o,1),_o.encode(o)}),gt.prop(s,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||s.pubkey)return Vi.hash160(e.pubkey||s.pubkey)}),gt.prop(s,"output",()=>{if(s.hash)return Pr.compile([Ft.OP_DUP,Ft.OP_HASH160,s.hash,Ft.OP_EQUALVERIFY,Ft.OP_CHECKSIG])}),gt.prop(s,"pubkey",()=>{if(e.input)return n()[1]}),gt.prop(s,"signature",()=>{if(e.input)return n()[0]}),gt.prop(s,"input",()=>{if(e.pubkey&&e.signature)return Pr.compile([e.signature,e.pubkey])}),gt.prop(s,"witness",()=>{if(s.input)return[]}),t.validate){let o=Buffer.from([]);if(e.address){if(r().version!==i.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");o=r().hash}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==Ft.OP_DUP||e.output[1]!==Ft.OP_HASH160||e.output[2]!==20||e.output[23]!==Ft.OP_EQUALVERIFY||e.output[24]!==Ft.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.pubkey){const a=Vi.hash160(e.pubkey);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!Pr.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,De.isPoint)(a[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(a[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(a[1]))throw new TypeError("Pubkey mismatch");const c=Vi.hash160(a[1]);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch")}}return Object.assign(s,e)}pi.p2pkh=Hc;var yi={};Object.defineProperty(yi,"__esModule",{value:!0});yi.p2sh=void 0;const vo=qt,Dc=Fe,ht=Ye(),ce=Me,ft=Ke,Eo=Ds,Kr=ht.OPS;function $c(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,ce.typeforce)({network:ce.typeforce.maybe(ce.typeforce.Object),address:ce.typeforce.maybe(ce.typeforce.String),hash:ce.typeforce.maybe(ce.typeforce.BufferN(20)),output:ce.typeforce.maybe(ce.typeforce.BufferN(23)),redeem:ce.typeforce.maybe({network:ce.typeforce.maybe(ce.typeforce.Object),output:ce.typeforce.maybe(ce.typeforce.Buffer),input:ce.typeforce.maybe(ce.typeforce.Buffer),witness:ce.typeforce.maybe(ce.typeforce.arrayOf(ce.typeforce.Buffer))}),input:ce.typeforce.maybe(ce.typeforce.Buffer),witness:ce.typeforce.maybe(ce.typeforce.arrayOf(ce.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Dc.bitcoin);const n={network:r},i=ft.value(()=>{const a=Buffer.from(Eo.decode(e.address)),c=a.readUInt8(0),l=a.slice(1);return{version:c,hash:l}}),s=ft.value(()=>ht.decompile(e.input)),o=ft.value(()=>{const a=s(),c=a[a.length-1];return{network:r,output:c===Kr.OP_FALSE?Buffer.from([]):c,input:ht.compile(a.slice(0,-1)),witness:e.witness||[]}});if(ft.prop(n,"address",()=>{if(!n.hash)return;const a=Buffer.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),Eo.encode(a)}),ft.prop(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return i().hash;if(n.redeem&&n.redeem.output)return vo.hash160(n.redeem.output)}),ft.prop(n,"output",()=>{if(n.hash)return ht.compile([Kr.OP_HASH160,n.hash,Kr.OP_EQUAL])}),ft.prop(n,"redeem",()=>{if(e.input)return o()}),ft.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return ht.compile([].concat(ht.decompile(e.redeem.input),e.redeem.output))}),ft.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),ft.prop(n,"name",()=>{const a=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&a.push(n.redeem.name),a.join("-")}),t.validate){let a=Buffer.from([]);if(e.address){if(i().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(i().hash.length!==20)throw new TypeError("Invalid address");a=i().hash}if(e.hash){if(a.length>0&&!a.equals(e.hash))throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Kr.OP_HASH160||e.output[1]!==20||e.output[22]!==Kr.OP_EQUAL)throw new TypeError("Output is invalid");const l=e.output.slice(2,22);if(a.length>0&&!a.equals(l))throw new TypeError("Hash mismatch");a=l}const c=l=>{if(l.output){const d=ht.decompile(l.output);if(!d||d.length<1)throw new TypeError("Redeem.output too short");if(l.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(ht.countNonPushOnlyOPs(d)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const b=vo.hash160(l.output);if(a.length>0&&!a.equals(b))throw new TypeError("Hash mismatch");a=b}if(l.input){const d=l.input.length>0,b=l.witness&&l.witness.length>0;if(!d&&!b)throw new TypeError("Empty input");if(d&&b)throw new TypeError("Input and witness provided");if(d){const E=ht.decompile(l.input);if(!ht.isPushOnly(E))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const l=s();if(!l||l.length<1)throw new TypeError("Input too short");if(!Buffer.isBuffer(o().output))throw new TypeError("Input is invalid");c(o())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const l=o();if(e.redeem.output&&!e.redeem.output.equals(l.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(l.input))throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,ce.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}yi.p2sh=$c;var bi={},At={};Object.defineProperty(At,"__esModule",{value:!0});At.bech32m=At.bech32=void 0;const ei="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Ga={};for(let e=0;e<ei.length;e++){const t=ei.charAt(e);Ga[t]=e}function Ir(e){const t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function xo(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=Ir(t)^n>>5}t=Ir(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=Ir(t)^n&31}return t}function $s(e,t,r,n){let i=0,s=0;const o=(1<<r)-1,a=[];for(let c=0;c<e.length;++c)for(i=i<<t|e[c],s+=t;s>=r;)s-=r,a.push(i>>s&o);if(n)s>0&&a.push(i<<r-s&o);else{if(s>=t)return"Excess padding";if(i<<r-s&o)return"Non-zero padding"}return a}function jc(e){return $s(e,8,5,!0)}function Gc(e){const t=$s(e,5,8,!1);if(Array.isArray(t))return t}function Wc(e){const t=$s(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Wa(e){let t;e==="bech32"?t=1:t=734539939;function r(o,a,c){if(c=c||90,o.length+7+a.length>c)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let l=xo(o);if(typeof l=="string")throw new Error(l);let d=o+"1";for(let b=0;b<a.length;++b){const E=a[b];if(E>>5)throw new Error("Non 5-bit word");l=Ir(l)^E,d+=ei.charAt(E)}for(let b=0;b<6;++b)l=Ir(l);l^=t;for(let b=0;b<6;++b){const E=l>>(5-b)*5&31;d+=ei.charAt(E)}return d}function n(o,a){if(a=a||90,o.length<8)return o+" too short";if(o.length>a)return"Exceeds length limit";const c=o.toLowerCase(),l=o.toUpperCase();if(o!==c&&o!==l)return"Mixed-case string "+o;o=c;const d=o.lastIndexOf("1");if(d===-1)return"No separator character for "+o;if(d===0)return"Missing prefix for "+o;const b=o.slice(0,d),E=o.slice(d+1);if(E.length<6)return"Data too short";let p=xo(b);if(typeof p=="string")return p;const I=[];for(let B=0;B<E.length;++B){const A=E.charAt(B),k=Ga[A];if(k===void 0)return"Unknown character "+A;p=Ir(p)^k,!(B+6>=E.length)&&I.push(k)}return p!==t?"Invalid checksum for "+o:{prefix:b,words:I}}function i(o,a){const c=n(o,a);if(typeof c=="object")return c}function s(o,a){const c=n(o,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:s,encode:r,toWords:jc,fromWordsUnsafe:Gc,fromWords:Wc}}At.bech32=Wa("bech32");At.bech32m=Wa("bech32m");Object.defineProperty(bi,"__esModule",{value:!0});bi.p2wpkh=void 0;const zi=qt,Vc=Fe,zn=Ye(),Pe=Me,Mt=Ke,Cn=At,So=zn.OPS,zc=Buffer.alloc(0);function qc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,Pe.typeforce)({address:Pe.typeforce.maybe(Pe.typeforce.String),hash:Pe.typeforce.maybe(Pe.typeforce.BufferN(20)),input:Pe.typeforce.maybe(Pe.typeforce.BufferN(0)),network:Pe.typeforce.maybe(Pe.typeforce.Object),output:Pe.typeforce.maybe(Pe.typeforce.BufferN(22)),pubkey:Pe.typeforce.maybe(Pe.isPoint),signature:Pe.typeforce.maybe(zn.isCanonicalScriptSignature),witness:Pe.typeforce.maybe(Pe.typeforce.arrayOf(Pe.typeforce.Buffer))},e);const r=Mt.value(()=>{const s=Cn.bech32.decode(e.address),o=s.words.shift(),a=Cn.bech32.fromWords(s.words);return{version:o,prefix:s.prefix,data:Buffer.from(a)}}),n=e.network||Vc.bitcoin,i={name:"p2wpkh",network:n};if(Mt.prop(i,"address",()=>{if(!i.hash)return;const s=Cn.bech32.toWords(i.hash);return s.unshift(0),Cn.bech32.encode(n.bech32,s)}),Mt.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return zi.hash160(e.pubkey||i.pubkey)}),Mt.prop(i,"output",()=>{if(i.hash)return zn.compile([So.OP_0,i.hash])}),Mt.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Mt.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),Mt.prop(i,"input",()=>{if(i.witness)return zc}),Mt.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let s=Buffer.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");s=r().data}if(e.hash){if(s.length>0&&!s.equals(e.hash))throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==So.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(s.length>0&&!s.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");s=e.output.slice(2)}if(e.pubkey){const o=zi.hash160(e.pubkey);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch");if(s=o,!(0,Pe.isPoint)(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!zn.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,Pe.isPoint)(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const o=zi.hash160(e.witness[1]);if(s.length>0&&!s.equals(o))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}bi.p2wpkh=qc;var wi={};Object.defineProperty(wi,"__esModule",{value:!0});wi.p2wsh=void 0;const Bo=qt,Kc=Fe,Et=Ye(),ae=Me,mt=Ke,Ln=At,Po=Et.OPS,qi=Buffer.alloc(0);function Nn(e){return!!(Buffer.isBuffer(e)&&e.length===65&&e[0]===4&&(0,ae.isPoint)(e))}function Yc(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,ae.typeforce)({network:ae.typeforce.maybe(ae.typeforce.Object),address:ae.typeforce.maybe(ae.typeforce.String),hash:ae.typeforce.maybe(ae.typeforce.BufferN(32)),output:ae.typeforce.maybe(ae.typeforce.BufferN(34)),redeem:ae.typeforce.maybe({input:ae.typeforce.maybe(ae.typeforce.Buffer),network:ae.typeforce.maybe(ae.typeforce.Object),output:ae.typeforce.maybe(ae.typeforce.Buffer),witness:ae.typeforce.maybe(ae.typeforce.arrayOf(ae.typeforce.Buffer))}),input:ae.typeforce.maybe(ae.typeforce.BufferN(0)),witness:ae.typeforce.maybe(ae.typeforce.arrayOf(ae.typeforce.Buffer))},e);const r=mt.value(()=>{const o=Ln.bech32.decode(e.address),a=o.words.shift(),c=Ln.bech32.fromWords(o.words);return{version:a,prefix:o.prefix,data:Buffer.from(c)}}),n=mt.value(()=>Et.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Kc.bitcoin);const s={network:i};if(mt.prop(s,"address",()=>{if(!s.hash)return;const o=Ln.bech32.toWords(s.hash);return o.unshift(0),Ln.bech32.encode(i.bech32,o)}),mt.prop(s,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(s.redeem&&s.redeem.output)return Bo.sha256(s.redeem.output)}),mt.prop(s,"output",()=>{if(s.hash)return Et.compile([Po.OP_0,s.hash])}),mt.prop(s,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:qi,witness:e.witness.slice(0,-1)}}),mt.prop(s,"input",()=>{if(s.witness)return qi}),mt.prop(s,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const o=Et.toStack(n());return s.redeem=Object.assign({witness:o},e.redeem),s.redeem.input=qi,[].concat(o,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),mt.prop(s,"name",()=>{const o=["p2wsh"];return s.redeem!==void 0&&s.redeem.name!==void 0&&o.push(s.redeem.name),o.join("-")}),t.validate){let o=Buffer.from([]);if(e.address){if(r().prefix!==i.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");o=r().data}if(e.hash){if(o.length>0&&!o.equals(e.hash))throw new TypeError("Hash mismatch");o=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==Po.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(o.length>0&&!o.equals(a))throw new TypeError("Hash mismatch");o=a}if(e.redeem){if(e.redeem.network&&e.redeem.network!==i)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const a=Et.decompile(e.redeem.output);if(!a||a.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(Et.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=Bo.sha256(e.redeem.output);if(o.length>0&&!o.equals(c))throw new TypeError("Hash mismatch");o=c}if(e.redeem.input&&!Et.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,ae.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Nn)||e.redeem.output&&(Et.decompile(e.redeem.output)||[]).some(Nn))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const a=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(a))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(Nn)||(Et.decompile(a)||[]).some(Nn))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(s,e)}wi.p2wsh=Yc;var Yr={},ar={};Object.defineProperty(ar,"__esModule",{value:!0});ar.getEccLib=ar.initEccLib=void 0;const hn={};function Xc(e){e?e!==hn.eccLib&&(Qc(e),hn.eccLib=e):hn.eccLib=e}ar.initEccLib=Xc;function Jc(){if(!hn.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return hn.eccLib}ar.getEccLib=Jc;const _t=e=>Buffer.from(e,"hex");function Qc(e){Je(typeof e.isXOnlyPoint=="function"),Je(e.isXOnlyPoint(_t("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Je(e.isXOnlyPoint(_t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Je(e.isXOnlyPoint(_t("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Je(e.isXOnlyPoint(_t("0000000000000000000000000000000000000000000000000000000000000001"))),Je(!e.isXOnlyPoint(_t("0000000000000000000000000000000000000000000000000000000000000000"))),Je(!e.isXOnlyPoint(_t("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Je(typeof e.xOnlyPointAddTweak=="function"),Zc.forEach(t=>{const r=e.xOnlyPointAddTweak(_t(t.pubkey),_t(t.tweak));t.result===null?Je(r===null):(Je(r!==null),Je(r.parity===t.parity),Je(Buffer.from(r.xOnlyPubkey).equals(_t(t.result))))})}function Je(e){if(!e)throw new Error("ecc library invalid")}const Zc=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}];var js={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.tweakKey=e.tapTweakHash=e.tapleafHash=e.findScriptPath=e.toHashTree=e.rootHashFromPath=e.MAX_TAPTREE_DEPTH=e.LEAF_VERSION_TAPSCRIPT=void 0;const t=Ot,r=ar,n=qt,i=Ie,s=Me;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const o=B=>"left"in B&&"right"in B;function a(B,A){if(B.length<33)throw new TypeError(`The control-block length is too small. Got ${B.length}, expected min 33.`);const k=(B.length-33)/32;let U=A;for(let _=0;_<k;_++){const m=B.slice(33+32*_,65+32*_);U.compare(m)<0?U=p(U,m):U=p(m,U)}return U}e.rootHashFromPath=a;function c(B){if((0,s.isTapleaf)(B))return{hash:d(B)};const A=[c(B[0]),c(B[1])];A.sort((_,m)=>_.hash.compare(m.hash));const[k,U]=A;return{hash:p(k.hash,U.hash),left:k,right:U}}e.toHashTree=c;function l(B,A){if(o(B)){const k=l(B.left,A);if(k!==void 0)return[...k,B.right.hash];const U=l(B.right,A);if(U!==void 0)return[...U,B.left.hash]}else if(B.hash.equals(A))return[]}e.findScriptPath=l;function d(B){const A=B.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([A]),I(B.output)]))}e.tapleafHash=d;function b(B,A){return n.taggedHash("TapTweak",t.Buffer.concat(A?[B,A]:[B]))}e.tapTweakHash=b;function E(B,A){if(!t.Buffer.isBuffer(B)||B.length!==32||A&&A.length!==32)return null;const k=b(B,A),U=(0,r.getEccLib)().xOnlyPointAddTweak(B,k);return!U||U.xOnlyPubkey===null?null:{parity:U.parity,x:t.Buffer.from(U.xOnlyPubkey)}}e.tweakKey=E;function p(B,A){return n.taggedHash("TapBranch",t.Buffer.concat([B,A]))}function I(B){const A=i.varuint.encodingLength(B.length),k=t.Buffer.allocUnsafe(A);return i.varuint.encode(B.length,k),t.Buffer.concat([k,B])}})(js);var $e={},To;function eh(){if(To)return $e;To=1,Object.defineProperty($e,"__esModule",{value:!0}),$e.toOutputScript=$e.fromOutputScript=$e.toBech32=$e.toBase58Check=$e.fromBech32=$e.fromBase58Check=void 0;const e=Fe,t=Gs(),r=Ye(),n=Me,i=At,s=Ds,o=40,a=2,c=16,l=2,d=80,b="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function E(_,m){const S=_.slice(2);if(S.length<a||S.length>o)throw new TypeError("Invalid program length for segwit address");const x=_[0]-d;if(x<l||x>c)throw new TypeError("Invalid version for segwit address");if(_[1]!==S.length)throw new TypeError("Invalid script for segwit address");return console.warn(b),A(S,x,m.bech32)}function p(_){const m=Buffer.from(s.decode(_));if(m.length<21)throw new TypeError(_+" is too short");if(m.length>21)throw new TypeError(_+" is too long");const S=m.readUInt8(0),x=m.slice(1);return{version:S,hash:x}}$e.fromBase58Check=p;function I(_){let m,S;try{m=i.bech32.decode(_)}catch{}if(m){if(S=m.words[0],S!==0)throw new TypeError(_+" uses wrong encoding")}else if(m=i.bech32m.decode(_),S=m.words[0],S===0)throw new TypeError(_+" uses wrong encoding");const x=i.bech32.fromWords(m.words.slice(1));return{version:S,prefix:m.prefix,data:Buffer.from(x)}}$e.fromBech32=I;function B(_,m){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const S=Buffer.allocUnsafe(21);return S.writeUInt8(m,0),_.copy(S,1),s.encode(S)}$e.toBase58Check=B;function A(_,m,S){const x=i.bech32.toWords(_);return x.unshift(m),m===0?i.bech32.encode(S,x):i.bech32m.encode(S,x)}$e.toBech32=A;function k(_,m){m=m||e.bitcoin;try{return t.p2pkh({output:_,network:m}).address}catch{}try{return t.p2sh({output:_,network:m}).address}catch{}try{return t.p2wpkh({output:_,network:m}).address}catch{}try{return t.p2wsh({output:_,network:m}).address}catch{}try{return t.p2tr({output:_,network:m}).address}catch{}try{return E(_,m)}catch{}throw new Error(r.toASM(_)+" has no matching Address")}$e.fromOutputScript=k;function U(_,m){m=m||e.bitcoin;let S,x;try{S=p(_)}catch{}if(S){if(S.version===m.pubKeyHash)return t.p2pkh({hash:S.hash}).output;if(S.version===m.scriptHash)return t.p2sh({hash:S.hash}).output}else{try{x=I(_)}catch{}if(x){if(x.prefix!==m.bech32)throw new Error(_+" has an invalid prefix");if(x.version===0){if(x.data.length===20)return t.p2wpkh({hash:x.data}).output;if(x.data.length===32)return t.p2wsh({hash:x.data}).output}else if(x.version===1){if(x.data.length===32)return t.p2tr({pubkey:x.data}).output}else if(x.version>=l&&x.version<=c&&x.data.length>=a&&x.data.length<=o)return console.warn(b),r.compile([x.version+d,x.data])}}throw new Error(_+" has no matching Script")}return $e.toOutputScript=U,$e}var Ao;function th(){if(Ao)return Yr;Ao=1,Object.defineProperty(Yr,"__esModule",{value:!0}),Yr.p2tr=void 0;const e=Ot,t=Fe,r=Ye(),n=Me,i=ar,s=js,o=Ke,a=At,c=eh(),l=r.OPS,d=1,b=80;function E(p,I){if(!p.address&&!p.output&&!p.pubkey&&!p.internalPubkey&&!(p.witness&&p.witness.length>1))throw new TypeError("Not enough data");I=Object.assign({validate:!0},I||{}),(0,n.typeforce)({address:n.typeforce.maybe(n.typeforce.String),input:n.typeforce.maybe(n.typeforce.BufferN(0)),network:n.typeforce.maybe(n.typeforce.Object),output:n.typeforce.maybe(n.typeforce.BufferN(34)),internalPubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),hash:n.typeforce.maybe(n.typeforce.BufferN(32)),pubkey:n.typeforce.maybe(n.typeforce.BufferN(32)),signature:n.typeforce.maybe(n.typeforce.anyOf(n.typeforce.BufferN(64),n.typeforce.BufferN(65))),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer)),scriptTree:n.typeforce.maybe(n.isTaptree),redeem:n.typeforce.maybe({output:n.typeforce.maybe(n.typeforce.Buffer),redeemVersion:n.typeforce.maybe(n.typeforce.Number),witness:n.typeforce.maybe(n.typeforce.arrayOf(n.typeforce.Buffer))}),redeemVersion:n.typeforce.maybe(n.typeforce.Number)},p);const B=o.value(()=>(0,c.fromBech32)(p.address)),A=o.value(()=>{if(!(!p.witness||!p.witness.length))return p.witness.length>=2&&p.witness[p.witness.length-1][0]===b?p.witness.slice(0,-1):p.witness.slice()}),k=o.value(()=>{if(p.scriptTree)return(0,s.toHashTree)(p.scriptTree);if(p.hash)return{hash:p.hash}}),U=p.network||t.bitcoin,_={name:"p2tr",network:U};if(o.prop(_,"address",()=>{if(!_.pubkey)return;const m=a.bech32m.toWords(_.pubkey);return m.unshift(d),a.bech32m.encode(U.bech32,m)}),o.prop(_,"hash",()=>{const m=k();if(m)return m.hash;const S=A();if(S&&S.length>1){const x=S[S.length-1],H=x[0]&n.TAPLEAF_VERSION_MASK,$=S[S.length-2],R=(0,s.tapleafHash)({output:$,version:H});return(0,s.rootHashFromPath)(x,R)}return null}),o.prop(_,"output",()=>{if(_.pubkey)return r.compile([l.OP_1,_.pubkey])}),o.prop(_,"redeemVersion",()=>p.redeemVersion?p.redeemVersion:p.redeem&&p.redeem.redeemVersion!==void 0&&p.redeem.redeemVersion!==null?p.redeem.redeemVersion:s.LEAF_VERSION_TAPSCRIPT),o.prop(_,"redeem",()=>{const m=A();if(!(!m||m.length<2))return{output:m[m.length-2],witness:m.slice(0,-2),redeemVersion:m[m.length-1][0]&n.TAPLEAF_VERSION_MASK}}),o.prop(_,"pubkey",()=>{if(p.pubkey)return p.pubkey;if(p.output)return p.output.slice(2);if(p.address)return B().data;if(_.internalPubkey){const m=(0,s.tweakKey)(_.internalPubkey,_.hash);if(m)return m.x}}),o.prop(_,"internalPubkey",()=>{if(p.internalPubkey)return p.internalPubkey;const m=A();if(m&&m.length>1)return m[m.length-1].slice(1,33)}),o.prop(_,"signature",()=>{if(p.signature)return p.signature;const m=A();if(!(!m||m.length!==1))return m[0]}),o.prop(_,"witness",()=>{if(p.witness)return p.witness;const m=k();if(m&&p.redeem&&p.redeem.output&&p.internalPubkey){const S=(0,s.tapleafHash)({output:p.redeem.output,version:_.redeemVersion}),x=(0,s.findScriptPath)(m,S);if(!x)return;const H=(0,s.tweakKey)(p.internalPubkey,m.hash);if(!H)return;const $=e.Buffer.concat([e.Buffer.from([_.redeemVersion|H.parity]),p.internalPubkey].concat(x));return[p.redeem.output,$]}if(p.signature)return[p.signature]}),I.validate){let m=e.Buffer.from([]);if(p.address){if(U&&U.bech32!==B().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(B().version!==d)throw new TypeError("Invalid address version");if(B().data.length!==32)throw new TypeError("Invalid address data");m=B().data}if(p.pubkey){if(m.length>0&&!m.equals(p.pubkey))throw new TypeError("Pubkey mismatch");m=p.pubkey}if(p.output){if(p.output.length!==34||p.output[0]!==l.OP_1||p.output[1]!==32)throw new TypeError("Output is invalid");if(m.length>0&&!m.equals(p.output.slice(2)))throw new TypeError("Pubkey mismatch");m=p.output.slice(2)}if(p.internalPubkey){const H=(0,s.tweakKey)(p.internalPubkey,_.hash);if(m.length>0&&!m.equals(H.x))throw new TypeError("Pubkey mismatch");m=H.x}if(m&&m.length&&!(0,i.getEccLib)().isXOnlyPoint(m))throw new TypeError("Invalid pubkey for p2tr");const S=k();if(p.hash&&S&&!p.hash.equals(S.hash))throw new TypeError("Hash mismatch");if(p.redeem&&p.redeem.output&&S){const H=(0,s.tapleafHash)({output:p.redeem.output,version:_.redeemVersion});if(!(0,s.findScriptPath)(S,H))throw new TypeError("Redeem script not in tree")}const x=A();if(p.redeem&&_.redeem){if(p.redeem.redeemVersion&&p.redeem.redeemVersion!==_.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(p.redeem.output){if(r.decompile(p.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(_.redeem.output&&!p.redeem.output.equals(_.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(p.redeem.witness&&_.redeem.witness&&!(0,n.stacksEqual)(p.redeem.witness,_.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(x&&x.length)if(x.length===1){if(p.signature&&!p.signature.equals(x[0]))throw new TypeError("Signature mismatch")}else{const H=x[x.length-1];if(H.length<33)throw new TypeError(`The control-block length is too small. Got ${H.length}, expected min 33.`);if((H.length-33)%32!==0)throw new TypeError(`The control-block length of ${H.length} is incorrect!`);const $=(H.length-33)/32;if($>128)throw new TypeError(`The script path is too long. Got ${$}, expected max 128.`);const R=H.slice(1,33);if(p.internalPubkey&&!p.internalPubkey.equals(R))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(R))throw new TypeError("Invalid internalPubkey for p2tr witness");const z=H[0]&n.TAPLEAF_VERSION_MASK,Z=x[x.length-2],C=(0,s.tapleafHash)({output:Z,version:z}),M=(0,s.rootHashFromPath)(H,C),W=(0,s.tweakKey)(R,M);if(!W)throw new TypeError("Invalid outputKey for p2tr witness");if(m.length&&!m.equals(W.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(W.parity!==(H[0]&1))throw new Error("Incorrect parity")}}return Object.assign(_,p)}return Yr.p2tr=E,Yr}var Io;function Gs(){return Io||(Io=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.p2tr=e.p2wsh=e.p2wpkh=e.p2sh=e.p2pkh=e.p2pk=e.p2ms=e.embed=void 0;const t=hi;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=li;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=di;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=pi;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const s=yi;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return s.p2sh}});const o=bi;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return o.p2wpkh}});const a=wi;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=th();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})}(Gi)),Gi}Object.defineProperty(oe,"__esModule",{value:!0});oe.signatureBlocksAction=oe.checkInputForSig=oe.pubkeyInScript=oe.pubkeyPositionInScript=oe.witnessStackToScriptWitness=oe.isP2TR=oe.isP2SHScript=oe.isP2WSHScript=oe.isP2WPKH=oe.isP2PKH=oe.isP2PK=oe.isP2MS=void 0;const Oo=En,ln=Ye(),Fn=_n,rh=qt,dr=Gs();function pr(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}oe.isP2MS=pr(dr.p2ms);oe.isP2PK=pr(dr.p2pk);oe.isP2PKH=pr(dr.p2pkh);oe.isP2WPKH=pr(dr.p2wpkh);oe.isP2WSHScript=pr(dr.p2wsh);oe.isP2SHScript=pr(dr.p2sh);oe.isP2TR=pr(dr.p2tr);function nh(e){let t=Buffer.allocUnsafe(0);function r(o){t=Buffer.concat([t,Buffer.from(o)])}function n(o){const a=t.length,c=Oo.encodingLength(o);t=Buffer.concat([t,Buffer.allocUnsafe(c)]),Oo.encode(o,t,a)}function i(o){n(o.length),r(o)}function s(o){n(o.length),o.forEach(i)}return s(e),t}oe.witnessStackToScriptWitness=nh;function Va(e,t){const r=(0,rh.hash160)(e),n=e.slice(1,33),i=ln.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(s=>typeof s=="number"?!1:s.equals(e)||s.equals(r)||s.equals(n))}oe.pubkeyPositionInScript=Va;function ih(e,t){return Va(e,t)!==-1}oe.pubkeyInScript=ih;function sh(e,t){return oh(e).some(n=>za(n,ln.signature.decode,t))}oe.checkInputForSig=sh;function za(e,t,r){const{hashType:n}=t(e),i=[];switch(n&Fn.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case Fn.Transaction.SIGHASH_ALL:break;case Fn.Transaction.SIGHASH_SINGLE:case Fn.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}oe.signatureBlocksAction=za;function oh(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=ah(e)}else t=e.partialSig;return t.map(r=>r.signature)}function ah(e){const t=e.finalScriptSig?ln.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?ln.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>Buffer.isBuffer(n)&&ln.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(_e,"__esModule",{value:!0});_e.checkTaprootInputForSigs=_e.tapTreeFromList=_e.tapTreeToList=_e.tweakInternalPubKey=_e.checkTaprootOutputFields=_e.checkTaprootInputFields=_e.isTaprootOutput=_e.isTaprootInput=qn=_e.serializeTaprootSignature=_e.tapScriptFinalizer=_e.toXOnly=void 0;const Ws=Me,fh=_n,gi=oe,zt=js,uh=Gs(),ch=oe,hh=e=>e.length===32?e:e.slice(1,33);_e.toXOnly=hh;function lh(e,t,r){const n=Oh(t,e,r);try{const s=Ah(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,gi.witnessStackToScriptWitness)(s)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}_e.tapScriptFinalizer=lh;function dh(e,t){const r=t?Buffer.from([t]):Buffer.from([]);return Buffer.concat([e,r])}var qn=_e.serializeTaprootSignature=dh;function Kn(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,gi.isP2TR)(e.witnessUtxo.script))}_e.isTaprootInput=Kn;function Yn(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,gi.isP2TR)(t))}_e.isTaprootOutput=Yn;function ph(e,t,r){Bh(e,t,r),Th(e,t,r)}_e.checkTaprootInputFields=ph;function yh(e,t,r){Ph(e,t,r),bh(e,t)}_e.checkTaprootOutputFields=yh;function bh(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:i}=e,s=wh(r,n);if(i&&!i.equals(s))throw new Error("Error adding output. Script or address missmatch.")}}function wh(e,t){const r=t&&qa(t.leaves),{output:n}=(0,uh.p2tr)({internalPubkey:e,scriptTree:r});return n}function gh(e,t){const r=t.tapInternalKey,n=r&&(0,zt.tweakKey)(r,t.tapMerkleRoot);if(!n)throw new Error(`Cannot tweak tap internal key for input #${e}. Public key: ${r&&r.toString("hex")}`);return n.x}_e.tweakInternalPubKey=gh;function mh(e){if(!(0,Ws.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return ys(e)}_e.tapTreeToList=mh;function qa(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:Sh(e)}_e.tapTreeFromList=qa;function _h(e,t){return Eh(e).some(n=>(0,ch.signatureBlocksAction)(n,vh,t))}_e.checkTaprootInputForSigs=_h;function vh(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||fh.Transaction.SIGHASH_DEFAULT}}function Eh(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=xh(e.finalScriptWitness);r&&t.push(r)}return t}function xh(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function ys(e,t=[],r=0){if(r>zt.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,Ws.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||zt.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&ys(e[0],t,r+1),e[1]&&ys(e[1],t,r+1),t):[]}function Sh(e){let t;for(const r of e)if(t=bs(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function bs(e,t,r=0){if(r>zt.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if((0,Ws.isTapleaf)(t))return;const n=bs(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=bs(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function Bh(e,t,r){const n=Kn(e)&&Or(t),i=Or(e)&&Kn(t),s=e===t&&Kn(t)&&Or(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Ph(e,t,r){const n=Yn(e)&&Or(t),i=Or(e)&&Yn(t),s=e===t&&Yn(t)&&Or(t);if(n||i||s)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Th(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(s=>Ki(s,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(s=>Ki(s,t.tapMerkleRoot));if(!n||!i)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(i=>Ki(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Ki(e,t){if(!t)return!0;const r=(0,zt.tapleafHash)({output:e.script,version:e.leafVersion});return(0,zt.rootHashFromPath)(e.controlBlock,r).equals(t)}function Ah(e,t){const r=(0,zt.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>Ih(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function Ih(e,t){return Object.assign({positionInScript:(0,gi.pubkeyPositionInScript)(t.pubkey,e)},t)}function Oh(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((i,s)=>i.controlBlock.length-s.controlBlock.length).find(i=>kh(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function kh(e,t,r){const n=(0,zt.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(s=>s.leafHash.equals(n))!==void 0}function Or(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const ke={secretMismatch:"invalid secret",secretHashLenMismatch:"secret hash should be 32 bytes",pubkeyLenMismatch:"pubkey should be 32 bytes",zeroOrNegativeExpiry:"expiry should be greater than 0",htlcAddressGenerationFailed:"failed to generate htlc address",notFunded:"address not funded",noCounterpartySigs:"counterparty signatures are required",counterPartySigNotFound:e=>"counterparty signature not found for utxo "+e,invalidCounterpartySigForUTXO:e=>"invalid counterparty signature for utxo "+e,htlcNotExpired:e=>`HTLC not expired, need more ${e} blocks`,controlBlockGenerationFailed:"failed to generate control block",invalidLeaf:"invalid leaf"},Mn=192;se.initEccLib(sr);class dn{constructor(t,r,n,i,s,o,a,c){this.secretHash=n,this.redeemerPubkey=i,this.initiatorPubkey=s,this.expiry=o,this.signer=t,this.network=a,this.internalPubkey=Tu(),this.initiateAmount=r,this.utxoHashes=c}static async from(t,r,n,i,s,o,a){n=n.startsWith("0x")?n.slice(2):n,_r(n.length===64,ke.secretHashLenMismatch),_r(i.length===64||i.length===66,`initiator ${ke.pubkeyLenMismatch}`),_r(s.length===64||s.length===66,`redeemer ${ke.pubkeyLenMismatch}`),_r(o>0,ke.zeroOrNegativeExpiry);const c=await t.getNetwork();return new dn(t,r,n,ls(s).toString("hex"),ls(i).toString("hex"),o,c,a)}address(){const{address:t}=se.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves()});if(!t)throw new Error(ke.htlcAddressGenerationFailed);return t}id(){return this.address()}async _buildRawTx(t,r){const n=new se.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const l=await s.getTransaction(c);for(let d=0;d<l.vout.length;d++){const b=l.vout[d];b.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:b.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,l)=>c+l.value,0);if(a===0)throw new Error(`${i} ${ke.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);return r??(r=await s.suggestFee(i,a,Rr.Urgency.MEDIUM)),n.addOutput(se.address.toOutputScript(t,this.network),a-r),{tx:n,usedUtxos:o}}async _tempBuildRawTx(t,r){const n=new se.Transaction;n.version=2;const i=this.address(),s=await this.signer.getProvider();let o=[];if(this.utxoHashes&&this.utxoHashes.length>0)for(const c of this.utxoHashes){const l=await s.getTransaction(c);for(let d=0;d<l.vout.length;d++){const b=l.vout[d];b.scriptpubkey_address===i&&o.push({txid:l.txid,vout:d,value:b.value,status:{confirmed:!1}})}}else o=await s.getUTXOs(i);const a=o.reduce((c,l)=>c+l.value,0);if(a===0)throw new Error(`${i} ${ke.notFunded}`);for(let c=0;c<o.length;c++)n.addInput(Buffer.from(o[c].txid,"hex").reverse(),o[c].vout);if(n.addOutput(se.address.toOutputScript(t,this.network),a),r){const c=await s.getFeeRates(),l=Math.ceil(c.hourFee*r),d=a-l;n.outs[0].value=d}return{tx:n,usedUtxos:o}}async buildRawTx(t){return await this._buildRawTx(await this.signer.getAddress(),t)}getOutputScript(){return se.address.toOutputScript(this.address(),this.network)}async init(t){return t??(t=await(await this.signer.getProvider()).suggestFee(await this.signer.getAddress(),this.initiateAmount,Rr.Urgency.MEDIUM)),await this.signer.send(this.address(),this.initiateAmount,t)}async generateRedeemSACP(t,r,n){const{tx:i,usedUtxos:s}=await this._buildRawTx(r,n),o=this.getOutputScript(),a=se.Transaction.SIGHASH_SINGLE|se.Transaction.SIGHASH_ANYONECANPAY,c=this.leafHash(1),l=s.map(b=>b.value),d=Xr(o,s.length);for(let b=0;b<i.ins.length;b++){const E=i.hashForWitnessV1(b,d,l,a,c),p=await this.signer.signSchnorr(E);i.setWitness(b,[qn(p,a),Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return i.toHex()}async generateInstantRefundSACP(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t,r),s=this.getOutputScript(),o=se.Transaction.SIGHASH_SINGLE|se.Transaction.SIGHASH_ANYONECANPAY,a=this.leafHash(2),c=i.map(d=>d.value),l=Xr(s,i.length);for(let d=0;d<n.ins.length;d++){const b=n.hashForWitnessV1(d,l,c,o,a),E=await this.signer.signSchnorr(b);n.setWitness(d,[qn(E,o),qn(E,o),this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return n.toHex()}async instantRefund(t,r){_r(t.length>0,ke.noCounterpartySigs);const{tx:n,usedUtxos:i}=await this.buildRawTx(r);for(const b of i)if(!t.find(E=>E.utxo===b.txid))throw new Error(ke.counterPartySigNotFound(b.txid));const s=this.getOutputScript(),o=se.Transaction.SIGHASH_DEFAULT,a=this.leafHash(2),c=i.map(b=>b.value),l=Xr(s,i.length);for(let b=0;b<n.ins.length;b++){const E=n.hashForWitnessV1(b,l,c,o,a);if(!sr.verifySchnorr(E,Buffer.from(this.redeemerPubkey,"hex"),Buffer.from(t[b].sig,"hex")))throw new Error(ke.invalidCounterpartySigForUTXO(t[b].utxo));const p=await this.signer.signSchnorr(E),I=Buffer.from(n.ins[b].hash).reverse().toString("hex"),B=t.find(A=>A.utxo===I);if(!B)throw new Error(ke.counterPartySigNotFound(I));n.setWitness(b,[Buffer.from(B.sig,"hex"),p,this.instantRefundLeaf(),this.generateControlBlockFor(2)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async redeem(t,r){_r(se.crypto.sha256(Buffer.from(t,"hex")).toString("hex")===this.secretHash,ke.secretMismatch);const n=r??await this.signer.getAddress(),{tx:i,usedUtxos:s}=await this._tempBuildRawTx(n),o=this.leafHash(1),a=s.map(E=>E.value),c=Xr(this.getOutputScript(),s.length),l=se.Transaction.SIGHASH_DEFAULT;for(let E=0;E<i.ins.length;E++){const p=i.hashForWitnessV1(E,c,a,l,o),I=await this.signer.signSchnorr(p);i.setWitness(E,[I,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}const{tx:d}=await this._tempBuildRawTx(n,i.virtualSize());for(let E=0;E<d.ins.length;E++){const p=d.hashForWitnessV1(E,c,a,l,o),I=await this.signer.signSchnorr(p);d.setWitness(E,[I,Buffer.from(t,"hex"),this.redeemLeaf(),this.generateControlBlockFor(1)])}return await(await this.signer.getProvider()).broadcast(d.toHex())}async refund(t,r){const{tx:n,usedUtxos:i}=await this._buildRawTx(t??await this.signer.getAddress(),r),[s,o]=await this.canRefund(i);if(!s)throw new Error(ke.htlcNotExpired(o));const a=this.leafHash(0),c=i.map(E=>E.value),l=Xr(this.getOutputScript(),i.length),d=se.Transaction.SIGHASH_DEFAULT;for(let E=0;E<n.ins.length;E++){n.ins[E].sequence=this.expiry;const p=n.hashForWitnessV1(E,l,c,d,a),I=await this.signer.signSchnorr(p);n.setWitness(E,[I,this.refundLeaf(),this.generateControlBlockFor(0)])}return await(await this.signer.getProvider()).broadcast(n.toHex())}async canRefund(t){const n=await(await this.signer.getProvider()).getLatestTip();for(const i of t){let s=0;if(i.status.confirmed&&i.status.block_height+this.expiry>n?s=i.status.block_height+this.expiry-n+1:i.status.confirmed||(s=this.expiry+1),s>0)return[!1,s]}return[!0,0]}generateControlBlockFor(t){let r;switch(t){case 1:r=this.redeemLeaf();break;case 0:r=this.refundLeaf();break;case 2:r=this.instantRefundLeaf();break;default:throw new Error(ke.invalidLeaf)}const n=se.payments.p2tr({internalPubkey:this.internalPubkey,network:this.network,scriptTree:this.leaves(),redeem:{output:r,redeemVersion:Mn}});if(!n.witness)throw new Error(ke.controlBlockGenerationFailed);return n.witness[n.witness.length-1]}leafHash(t){let r=this.redeemLeaf();return t===0&&(r=this.refundLeaf()),t===2&&(r=this.instantRefundLeaf()),se.crypto.taggedHash("TapLeaf",pu(r))}refundLeaf(){return se.script.fromASM(`
10
10
  ${se.script.number.encode(this.expiry).toString("hex")}
11
11
  OP_CHECKSEQUENCEVERIFY
12
12
  OP_DROP
package/dist/index.js CHANGED
@@ -6156,7 +6156,7 @@ class ln {
6156
6156
  se.address.toOutputScript(t, this.network),
6157
6157
  a
6158
6158
  ), r) {
6159
- const l = (await s.getFeeRates()).hourFee * r, d = a - l;
6159
+ const c = await s.getFeeRates(), l = Math.ceil(c.hourFee * r), d = a - l;
6160
6160
  n.outs[0].value = d;
6161
6161
  }
6162
6162
  return { tx: n, usedUtxos: o };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",