"use strict";(()=>{var os=Object.create;var mn=Object.defineProperty;var as=Object.getOwnPropertyDescriptor;var cs=Object.getOwnPropertyNames;var us=Object.getPrototypeOf,fs=Object.prototype.hasOwnProperty;var H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ls=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of cs(t))!fs.call(e,i)&&i!==r&&mn(e,i,{get:()=>t[i],enumerable:!(n=as(t,i))||n.enumerable});return e};var E=(e,t,r)=>(r=e!=null?os(us(e)):{},ls(t||!e||!e.__esModule?mn(r,"default",{value:e,enumerable:!0}):r,e));var Sn=H(ke=>{"use strict";var jc=E(B());ke.byteLength=ds;ke.toByteArray=ps;ke.fromByteArray=_s;var St=[],gt=[],hs=typeof Uint8Array<"u"?Uint8Array:Array,xr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Gt=0,En=xr.length;Gt0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ds(e){var t=Bn(e),r=t[0],n=t[1];return(r+n)*3/4-n}function ws(e,t,r){return(t+r)*3/4-r}function ps(e){var t,r=Bn(e),n=r[0],i=r[1],s=new hs(ws(e,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c>16&255,s[o++]=t>>8&255,s[o++]=t&255;return i===2&&(t=gt[e.charCodeAt(c)]<<2|gt[e.charCodeAt(c+1)]>>4,s[o++]=t&255),i===1&&(t=gt[e.charCodeAt(c)]<<10|gt[e.charCodeAt(c+1)]<<4|gt[e.charCodeAt(c+2)]>>2,s[o++]=t>>8&255,s[o++]=t&255),s}function gs(e){return St[e>>18&63]+St[e>>12&63]+St[e>>6&63]+St[e&63]}function ys(e,t,r){for(var n,i=[],s=t;sa?a:o+s));return n===1?(t=e[r-1],i.push(St[t>>2]+St[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(St[t>>10]+St[t>>4&63]+St[t<<2&63]+"=")),i.join("")}});var Tn=H(mr=>{var Vc=E(B());mr.read=function(e,t,r,n,i){var s,o,a=i*8-n-1,c=(1<>1,l=-7,f=r?i-1:0,p=r?-1:1,w=e[t+f];for(f+=p,s=w&(1<<-l)-1,w>>=-l,l+=a;l>0;s=s*256+e[t+f],f+=p,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=n;l>0;o=o*256+e[t+f],f+=p,l-=8);if(s===0)s=1-u;else{if(s===c)return o?NaN:(w?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-u}return(w?-1:1)*o*Math.pow(2,s-n)};mr.write=function(e,t,r,n,i,s){var o,a,c,u=s*8-i-1,l=(1<>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,w=n?0:s-1,x=n?1:-1,y=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+f>=1?t+=p/c:t+=p*Math.pow(2,1-f),t*c>=2&&(o++,c/=2),o+f>=l?(a=0,o=l):o+f>=1?(a=(t*c-1)*Math.pow(2,i),o=o+f):(a=t*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;e[r+w]=a&255,w+=x,a/=256,i-=8);for(o=o<0;e[r+w]=o&255,w+=x,o/=256,u-=8);e[r+w-x]|=y*128}});var Fn=H(he=>{"use strict";var zc=E(B());var Er=Sn(),fe=Tn(),In=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;he.Buffer=d;he.SlowBuffer=Ss;he.INSPECT_MAX_BYTES=50;var je=2147483647;he.kMaxLength=je;d.TYPED_ARRAY_SUPPORT=bs();!d.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 bs(){try{let e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}});Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function Pt(e){if(e>je)throw new RangeError('The value "'+e+'" is invalid for option "size"');let t=new Uint8Array(e);return Object.setPrototypeOf(t,d.prototype),t}function d(e,t,r){if(typeof e=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Ir(e)}return On(e,t,r)}d.poolSize=8192;function On(e,t,r){if(typeof e=="string")return ms(e,t);if(ArrayBuffer.isView(e))return Es(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(Tt(e,ArrayBuffer)||e&&Tt(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Tt(e,SharedArrayBuffer)||e&&Tt(e.buffer,SharedArrayBuffer)))return Sr(e,t,r);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=e.valueOf&&e.valueOf();if(n!=null&&n!==e)return d.from(n,t,r);let i=Bs(e);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return d.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}d.from=function(e,t,r){return On(e,t,r)};Object.setPrototypeOf(d.prototype,Uint8Array.prototype);Object.setPrototypeOf(d,Uint8Array);function Un(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function xs(e,t,r){return Un(e),e<=0?Pt(e):t!==void 0?typeof r=="string"?Pt(e).fill(t,r):Pt(e).fill(t):Pt(e)}d.alloc=function(e,t,r){return xs(e,t,r)};function Ir(e){return Un(e),Pt(e<0?0:Ar(e)|0)}d.allocUnsafe=function(e){return Ir(e)};d.allocUnsafeSlow=function(e){return Ir(e)};function ms(e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!d.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let r=Rn(e,t)|0,n=Pt(r),i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}function Br(e){let t=e.length<0?0:Ar(e.length)|0,r=Pt(t);for(let n=0;n=je)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+je.toString(16)+" bytes");return e|0}function Ss(e){return+e!=e&&(e=0),d.alloc(+e)}d.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==d.prototype};d.compare=function(t,r){if(Tt(t,Uint8Array)&&(t=d.from(t,t.offset,t.byteLength)),Tt(r,Uint8Array)&&(r=d.from(r,r.offset,r.byteLength)),!d.isBuffer(t)||!d.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;let n=t.length,i=r.length;for(let s=0,o=Math.min(n,i);si.length?(d.isBuffer(o)||(o=d.from(o)),o.copy(i,s)):Uint8Array.prototype.set.call(i,o,s);else if(d.isBuffer(o))o.copy(i,s);else throw new TypeError('"list" argument must be an Array of Buffers');s+=o.length}return i};function Rn(e,t){if(d.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||Tt(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let r=e.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Tr(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return jn(e).length;default:if(i)return n?-1:Tr(e).length;t=(""+t).toLowerCase(),i=!0}}d.byteLength=Rn;function Ts(e,t,r){let n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Hs(this,t,r);case"utf8":case"utf-8":return Cn(this,t,r);case"ascii":return Ns(this,t,r);case"latin1":case"binary":return Cs(this,t,r);case"base64":return Us(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return qs(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}d.prototype._isBuffer=!0;function Yt(e,t,r){let n=e[t];e[t]=e[r],e[r]=n}d.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;rr&&(t+=" ... "),""};In&&(d.prototype[In]=d.prototype.inspect);d.prototype.compare=function(t,r,n,i,s){if(Tt(t,Uint8Array)&&(t=d.from(t,t.offset,t.byteLength)),!d.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),s===void 0&&(s=this.length),r<0||n>t.length||i<0||s>this.length)throw new RangeError("out of range index");if(i>=s&&r>=n)return 0;if(i>=s)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,s>>>=0,this===t)return 0;let o=s-i,a=n-r,c=Math.min(o,a),u=this.slice(i,s),l=t.slice(r,n);for(let f=0;f2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,vr(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof t=="string"&&(t=d.from(t,n)),d.isBuffer(t))return t.length===0?-1:An(e,t,r,n,i);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):An(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function An(e,t,r,n,i){let s=1,o=e.length,a=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(e.length<2||t.length<2)return-1;s=2,o/=2,a/=2,r/=2}function c(l,f){return s===1?l[f]:l.readUInt16BE(f*s)}let u;if(i){let l=-1;for(u=r;uo&&(r=o-a),u=r;u>=0;u--){let l=!0;for(let f=0;fi&&(n=i)):n=i;let s=t.length;n>s/2&&(n=s/2);let o;for(o=0;o>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let s=this.length-r;if((n===void 0||n>s)&&(n=s),t.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let o=!1;for(;;)switch(i){case"hex":return Is(this,t,r,n);case"utf8":case"utf-8":return As(this,t,r,n);case"ascii":case"latin1":case"binary":return Ps(this,t,r,n);case"base64":return vs(this,t,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Os(this,t,r,n);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}};d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Us(e,t,r){return t===0&&r===e.length?Er.fromByteArray(e):Er.fromByteArray(e.slice(t,r))}function Cn(e,t,r){r=Math.min(e.length,r);let n=[],i=t;for(;i239?4:s>223?3:s>191?2:1;if(i+a<=r){let c,u,l,f;switch(a){case 1:s<128&&(o=s);break;case 2:c=e[i+1],(c&192)===128&&(f=(s&31)<<6|c&63,f>127&&(o=f));break;case 3:c=e[i+1],u=e[i+2],(c&192)===128&&(u&192)===128&&(f=(s&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(o=f));break;case 4:c=e[i+1],u=e[i+2],l=e[i+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(f=(s&15)<<18|(c&63)<<12|(u&63)<<6|l&63,f>65535&&f<1114112&&(o=f))}}o===null?(o=65533,a=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),i+=a}return Rs(n)}var Pn=4096;function Rs(e){let t=e.length;if(t<=Pn)return String.fromCharCode.apply(String,e);let r="",n=0;for(;nn)&&(r=n);let i="";for(let s=t;sn&&(t=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),rr)throw new RangeError("Trying to access beyond buffer length")}d.prototype.readUintLE=d.prototype.readUIntLE=function(t,r,n){t=t>>>0,r=r>>>0,n||Q(t,r,this.length);let i=this[t],s=1,o=0;for(;++o>>0,r=r>>>0,n||Q(t,r,this.length);let i=this[t+--r],s=1;for(;r>0&&(s*=256);)i+=this[t+--r]*s;return i};d.prototype.readUint8=d.prototype.readUInt8=function(t,r){return t=t>>>0,r||Q(t,1,this.length),this[t]};d.prototype.readUint16LE=d.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||Q(t,2,this.length),this[t]|this[t+1]<<8};d.prototype.readUint16BE=d.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||Q(t,2,this.length),this[t]<<8|this[t+1]};d.prototype.readUint32LE=d.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||Q(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};d.prototype.readUint32BE=d.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||Q(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};d.prototype.readBigUInt64LE=Mt(function(t){t=t>>>0,le(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Be(t,this.length-8);let i=r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,s=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(i)+(BigInt(s)<>>0,le(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Be(t,this.length-8);let i=r*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],s=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(i)<>>0,r=r>>>0,n||Q(t,r,this.length);let i=this[t],s=1,o=0;for(;++o=s&&(i-=Math.pow(2,8*r)),i};d.prototype.readIntBE=function(t,r,n){t=t>>>0,r=r>>>0,n||Q(t,r,this.length);let i=r,s=1,o=this[t+--i];for(;i>0&&(s*=256);)o+=this[t+--i]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*r)),o};d.prototype.readInt8=function(t,r){return t=t>>>0,r||Q(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};d.prototype.readInt16LE=function(t,r){t=t>>>0,r||Q(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n};d.prototype.readInt16BE=function(t,r){t=t>>>0,r||Q(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n};d.prototype.readInt32LE=function(t,r){return t=t>>>0,r||Q(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};d.prototype.readInt32BE=function(t,r){return t=t>>>0,r||Q(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};d.prototype.readBigInt64LE=Mt(function(t){t=t>>>0,le(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Be(t,this.length-8);let i=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(i)<>>0,le(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Be(t,this.length-8);let i=(r<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(i)<>>0,r||Q(t,4,this.length),fe.read(this,t,!0,23,4)};d.prototype.readFloatBE=function(t,r){return t=t>>>0,r||Q(t,4,this.length),fe.read(this,t,!1,23,4)};d.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||Q(t,8,this.length),fe.read(this,t,!0,52,8)};d.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||Q(t,8,this.length),fe.read(this,t,!1,52,8)};function at(e,t,r,n,i,s){if(!d.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}d.prototype.writeUintLE=d.prototype.writeUIntLE=function(t,r,n,i){if(t=+t,r=r>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;at(this,t,r,n,a,0)}let s=1,o=0;for(this[r]=t&255;++o>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;at(this,t,r,n,a,0)}let s=n-1,o=1;for(this[r+s]=t&255;--s>=0&&(o*=256);)this[r+s]=t/o&255;return r+n};d.prototype.writeUint8=d.prototype.writeUInt8=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,1,255,0),this[r]=t&255,r+1};d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2};d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2};d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4};d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function Hn(e,t,r,n,i){kn(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s=s>>8,e[r++]=s,s=s>>8,e[r++]=s,s=s>>8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o=o>>8,e[r++]=o,o=o>>8,e[r++]=o,o=o>>8,e[r++]=o,r}function qn(e,t,r,n,i){kn(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s=s>>8,e[r+6]=s,s=s>>8,e[r+5]=s,s=s>>8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o=o>>8,e[r+2]=o,o=o>>8,e[r+1]=o,o=o>>8,e[r]=o,r+8}d.prototype.writeBigUInt64LE=Mt(function(t,r=0){return Hn(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeBigUInt64BE=Mt(function(t,r=0){return qn(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeIntLE=function(t,r,n,i){if(t=+t,r=r>>>0,!i){let c=Math.pow(2,8*n-1);at(this,t,r,n,c-1,-c)}let s=0,o=1,a=0;for(this[r]=t&255;++s>0)-a&255;return r+n};d.prototype.writeIntBE=function(t,r,n,i){if(t=+t,r=r>>>0,!i){let c=Math.pow(2,8*n-1);at(this,t,r,n,c-1,-c)}let s=n-1,o=1,a=0;for(this[r+s]=t&255;--s>=0&&(o*=256);)t<0&&a===0&&this[r+s+1]!==0&&(a=1),this[r+s]=(t/o>>0)-a&255;return r+n};d.prototype.writeInt8=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1};d.prototype.writeInt16LE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2};d.prototype.writeInt16BE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2};d.prototype.writeInt32LE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4};d.prototype.writeInt32BE=function(t,r,n){return t=+t,r=r>>>0,n||at(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};d.prototype.writeBigInt64LE=Mt(function(t,r=0){return Hn(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});d.prototype.writeBigInt64BE=Mt(function(t,r=0){return qn(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ln(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Mn(e,t,r,n,i){return t=+t,r=r>>>0,i||Ln(e,t,r,4,34028234663852886e22,-34028234663852886e22),fe.write(e,t,r,n,23,4),r+4}d.prototype.writeFloatLE=function(t,r,n){return Mn(this,t,r,!0,n)};d.prototype.writeFloatBE=function(t,r,n){return Mn(this,t,r,!1,n)};function Dn(e,t,r,n,i){return t=+t,r=r>>>0,i||Ln(e,t,r,8,17976931348623157e292,-17976931348623157e292),fe.write(e,t,r,n,52,8),r+8}d.prototype.writeDoubleLE=function(t,r,n){return Dn(this,t,r,!0,n)};d.prototype.writeDoubleBE=function(t,r,n){return Dn(this,t,r,!1,n)};d.prototype.copy=function(t,r,n,i){if(!d.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=t.length&&(r=t.length),r||(r=0),i>0&&i=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-r>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let s;if(typeof t=="number")for(s=r;s2**32?i=vn(String(r)):typeof r=="bigint"&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=vn(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);function vn(e){let t="",r=e.length,n=e[0]==="-"?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function Ls(e,t,r){le(t,"offset"),(e[t]===void 0||e[t+r]===void 0)&&Be(t,e.length-(r+1))}function kn(e,t,r,n,i,s){if(e>r||e3?t===0||t===BigInt(0)?a=`>= 0${o} and < 2${o} ** ${(s+1)*8}${o}`:a=`>= -(2${o} ** ${(s+1)*8-1}${o}) and < 2 ** ${(s+1)*8-1}${o}`:a=`>= ${t}${o} and <= ${r}${o}`,new ue.ERR_OUT_OF_RANGE("value",a,e)}Ls(n,i,s)}function le(e,t){if(typeof e!="number")throw new ue.ERR_INVALID_ARG_TYPE(t,"number",e)}function Be(e,t,r){throw Math.floor(e)!==e?(le(e,r),new ue.ERR_OUT_OF_RANGE(r||"offset","an integer",e)):t<0?new ue.ERR_BUFFER_OUT_OF_BOUNDS:new ue.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}var Ms=/[^+/0-9A-Za-z-_]/g;function Ds(e){if(e=e.split("=")[0],e=e.trim().replace(Ms,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function Tr(e,t){t=t||1/0;let r,n=e.length,i=null,s=[];for(let o=0;o55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}else if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return s}function ks(e){let t=[];for(let r=0;r>8,i=r%256,s.push(i),s.push(n);return s}function jn(e){return Er.toByteArray(Ds(e))}function Fe(e,t,r,n){let i;for(i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Tt(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function vr(e){return e!==e}var Fs=function(){let e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function Mt(e){return typeof BigInt>"u"?Vs:e}function Vs(){throw new Error("BigInt not supported")}});var B=H(()=>{"use strict";var Vn=E(Fn());globalThis.Buffer=Vn.Buffer});var Kn=H(Ve=>{"use strict";var Yc=E(B());Object.defineProperty(Ve,"__esModule",{value:!0});Ve.crypto=void 0;Ve.crypto=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0});var $e=H(It=>{"use strict";var Xc=E(B());Object.defineProperty(It,"__esModule",{value:!0});It.isBytes=zn;It.number=Ke;It.bool=$n;It.bytes=Or;It.hash=Zn;It.exists=Wn;It.output=Gn;function Ke(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function $n(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function zn(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Or(e,...t){if(!zn(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 Zn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ke(e.outputLen),Ke(e.blockLen)}function Wn(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 Gn(e,t){Or(e);let r=t.outputLen;if(e.length{"use strict";var tu=E(B());Object.defineProperty(R,"__esModule",{value:!0});R.Hash=R.nextTick=R.byteSwapIfBE=R.byteSwap=R.isLE=R.rotl=R.rotr=R.createView=R.u32=R.u8=void 0;R.isBytes=$s;R.byteSwap32=Xs;R.bytesToHex=to;R.hexToBytes=eo;R.asyncLoop=no;R.utf8ToBytes=Qn;R.toBytes=ze;R.concatBytes=io;R.checkOpts=oo;R.wrapConstructor=ao;R.wrapConstructorWithOpts=co;R.wrapXOFConstructorWithOpts=uo;R.randomBytes=fo;var de=Kn(),Rr=$e();function $s(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}var zs=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength);R.u8=zs;var Zs=e=>new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4));R.u32=Zs;var Ws=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);R.createView=Ws;var Gs=(e,t)=>e<<32-t|e>>>t;R.rotr=Gs;var Ys=(e,t)=>e<>>32-t>>>0;R.rotl=Ys;R.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Qs=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;R.byteSwap=Qs;R.byteSwapIfBE=R.isLE?e=>e:e=>(0,R.byteSwap)(e);function Xs(e){for(let t=0;tt.toString(16).padStart(2,"0"));function to(e){(0,Rr.bytes)(e);let t="";for(let r=0;r=vt._0&&e<=vt._9)return e-vt._0;if(e>=vt._A&&e<=vt._F)return e-(vt._A-10);if(e>=vt._a&&e<=vt._f)return e-(vt._a-10)}function eo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length,r=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let i=0,s=0;i{};R.nextTick=ro;async function no(e,t,r){let n=Date.now();for(let i=0;i=0&&se().update(ze(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function co(e){let t=(n,i)=>e(i).update(ze(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}function uo(e){let t=(n,i)=>e(i).update(ze(n)).digest(),r=e({});return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}function fo(e=32){if(de.crypto&&typeof de.crypto.getRandomValues=="function")return de.crypto.getRandomValues(new Uint8Array(e));if(de.crypto&&typeof de.crypto.randomBytes=="function")return de.crypto.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}});var Qt=H(Se=>{"use strict";var ru=E(B());Object.defineProperty(Se,"__esModule",{value:!0});Se.Opcode=void 0;var lo;(function(e){e.OP_0="00",e.OP_FALSE="00",e.OP_PUSHDATA1="4c",e.OP_PUSHDATA2="4d",e.OP_PUSHDATA4="4e",e.OP_1NEGATE="4f",e.OP_RESERVED="50",e.OP_1="51",e.OP_TRUE="51",e.OP_2="52",e.OP_3="53",e.OP_4="54",e.OP_5="55",e.OP_6="56",e.OP_7="57",e.OP_8="58",e.OP_9="59",e.OP_10="5a",e.OP_11="5b",e.OP_12="5c",e.OP_13="5d",e.OP_14="5e",e.OP_15="5f",e.OP_16="60",e.OP_NOP="61",e.OP_VER="62",e.OP_IF="63",e.OP_NOTIF="64",e.OP_VERIF="65",e.OP_VERNOTIF="66",e.OP_ELSE="67",e.OP_ENDIF="68",e.OP_VERIFY="69",e.OP_RETURN="6a",e.OP_TOALTSTACK="6b",e.OP_FROMALTSTACK="6c",e.OP_2DROP="6d",e.OP_2DUP="6e",e.OP_3DUP="6f",e.OP_2OVER="70",e.OP_2ROT="71",e.OP_2SWAP="72",e.OP_IFDUP="73",e.OP_DEPTH="74",e.OP_DROP="75",e.OP_DUP="76",e.OP_NIP="77",e.OP_OVER="78",e.OP_PICK="79",e.OP_ROLL="7a",e.OP_ROT="7b",e.OP_SWAP="7c",e.OP_TUCK="7d",e.OP_CAT="7e",e.OP_SUBSTR="7f",e.OP_LEFT="80",e.OP_RIGHT="81",e.OP_SIZE="82",e.OP_INVERT="83",e.OP_AND="84",e.OP_OR="85",e.OP_XOR="86",e.OP_EQUAL="87",e.OP_EQUALVERIFY="88",e.OP_RESERVED1="89",e.OP_RESERVED2="8a",e.OP_1ADD="8b",e.OP_1SUB="8c",e.OP_2MUL="8d",e.OP_2DIV="8e",e.OP_NEGATE="8f",e.OP_ABS="90",e.OP_NOT="91",e.OP_0NOTEQUAL="92",e.OP_ADD="93",e.OP_SUB="94",e.OP_MUL="95",e.OP_DIV="96",e.OP_MOD="97",e.OP_LSHIFT="98",e.OP_RSHIFT="99",e.OP_BOOLAND="9a",e.OP_BOOLOR="9b",e.OP_NUMEQUAL="9c",e.OP_NUMEQUALVERIFY="9d",e.OP_NUMNOTEQUAL="9e",e.OP_LESSTHAN="9f",e.OP_GREATERTHAN="a0",e.OP_LESSTHANOREQUAL="a1",e.OP_GREATERTHANOREQUAL="a2",e.OP_MIN="a3",e.OP_MAX="a4",e.OP_WITHIN="a5",e.OP_RIPEMD160="a6",e.OP_SHA1="a7",e.OP_SHA256="a8",e.OP_HASH160="a9",e.OP_HASH256="aa",e.OP_CODESEPARATOR="ab",e.OP_CHECKSIG="ac",e.OP_CHECKSIGVERIFY="ad",e.OP_CHECKMULTISIG="ae",e.OP_CHECKMULTISIGVERIFY="af",e.OP_NOP1="b0",e.OP_CHECKLOCKTIMEVERIFY="b1",e.OP_NOP2="b1",e.OP_CHECKSEQUENCEVERIFY="b2",e.OP_NOP3="b2",e.OP_NOP4="b3",e.OP_NOP5="b4",e.OP_NOP6="b5",e.OP_NOP7="b6",e.OP_NOP8="b7",e.OP_NOP9="b8",e.OP_NOP10="b9",e.OP_CHECKSIGADD="ba",e.OP_INVALIDOPCODE="ff"})(lo=Se.Opcode||(Se.Opcode={}))});var Hr=H(Dt=>{"use strict";var iu=E(B());Object.defineProperty(Dt,"__esModule",{value:!0});Dt.HashMD=Dt.Maj=Dt.Chi=void 0;var Nr=$e(),Te=yt();function ho(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,o,n),e.setUint32(t+u,a,n)}var wo=(e,t,r)=>e&t^~e&r;Dt.Chi=wo;var po=(e,t,r)=>e&t^e&r^t&r;Dt.Maj=po;var Cr=class extends Te.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,Te.createView)(this.buffer)}update(t){(0,Nr.exists)(this);let{view:r,buffer:n,blockLen:i}=this;t=(0,Te.toBytes)(t);let s=t.length;for(let o=0;oi-o&&(this.process(n,0),o=0);for(let f=o;fl.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f{"use strict";var ou=E(B());Object.defineProperty(we,"__esModule",{value:!0});we.ripemd160=we.RIPEMD160=void 0;var go=Hr(),Ie=yt(),yo=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Jn=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),_o=Jn.map(e=>(9*e+5)%16),qr=[Jn],Lr=[_o];for(let e=0;e<4;e++)for(let t of[qr,Lr])t.push(t[e].map(r=>yo[r]));var ti=[[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)),bo=qr.map((e,t)=>e.map(r=>ti[t][r])),xo=Lr.map((e,t)=>e.map(r=>ti[t][r])),mo=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Eo=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function Xn(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)}var Ze=new Uint32Array(16),We=class extends go.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{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 w=0;w<16;w++,r+=4)Ze[w]=t.getUint32(r,!0);let n=this.h0|0,i=n,s=this.h1|0,o=s,a=this.h2|0,c=a,u=this.h3|0,l=u,f=this.h4|0,p=f;for(let w=0;w<5;w++){let x=4-w,y=mo[w],h=Eo[w],g=qr[w],_=Lr[w],b=bo[w],m=xo[w];for(let v=0;v<16;v++){let I=(0,Ie.rotl)(n+Xn(w,s,a,u)+Ze[g[v]]+y,b[v])+f|0;n=f,f=u,u=(0,Ie.rotl)(a,10)|0,a=s,s=I}for(let v=0;v<16;v++){let I=(0,Ie.rotl)(i+Xn(x,o,c,l)+Ze[_[v]]+h,m[v])+p|0;i=p,p=l,l=(0,Ie.rotl)(c,10)|0,c=o,o=I}}this.set(this.h1+a+l|0,this.h2+u+p|0,this.h3+f+i|0,this.h4+n+o|0,this.h0+s+c|0)}roundClean(){Ze.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};we.RIPEMD160=We;we.ripemd160=(0,Ie.wrapConstructor)(()=>new We)});var kr=H(Ft=>{"use strict";var cu=E(B());Object.defineProperty(Ft,"__esModule",{value:!0});Ft.sha224=Ft.sha256=Ft.SHA256=void 0;var Mr=Hr(),_t=yt(),Bo=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]),kt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),jt=new Uint32Array(64),Ae=class extends Mr.HashMD{constructor(){super(64,32,8,!1),this.A=kt[0]|0,this.B=kt[1]|0,this.C=kt[2]|0,this.D=kt[3]|0,this.E=kt[4]|0,this.F=kt[5]|0,this.G=kt[6]|0,this.H=kt[7]|0}get(){let{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 f=0;f<16;f++,r+=4)jt[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){let p=jt[f-15],w=jt[f-2],x=(0,_t.rotr)(p,7)^(0,_t.rotr)(p,18)^p>>>3,y=(0,_t.rotr)(w,17)^(0,_t.rotr)(w,19)^w>>>10;jt[f]=y+jt[f-7]+x+jt[f-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let p=(0,_t.rotr)(a,6)^(0,_t.rotr)(a,11)^(0,_t.rotr)(a,25),w=l+p+(0,Mr.Chi)(a,c,u)+Bo[f]+jt[f]|0,y=((0,_t.rotr)(n,2)^(0,_t.rotr)(n,13)^(0,_t.rotr)(n,22))+(0,Mr.Maj)(n,i,s)|0;l=u,u=c,c=a,a=o+w|0,o=s,s=i,i=n,n=w+y|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,u=u+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,u,l)}roundClean(){jt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};Ft.SHA256=Ae;var Dr=class extends Ae{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}};Ft.sha256=(0,_t.wrapConstructor)(()=>new Ae);Ft.sha224=(0,_t.wrapConstructor)(()=>new Dr)});var ni=H(Xt=>{"use strict";var fu=E(B());Object.defineProperty(Xt,"__esModule",{value:!0});Xt.hmac=Xt.HMAC=void 0;var Ge=$e(),ri=yt(),Pe=class extends ri.Hash{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,(0,Ge.hash)(t);let n=(0,ri.toBytes)(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,s=new Uint8Array(i);s.set(n.length>i?t.create().update(n).digest():n);for(let o=0;onew Pe(e,t).update(r).digest();Xt.hmac=So;Xt.hmac.create=(e,t)=>new Pe(e,t)});var Jt=H(q=>{"use strict";var hu=E(B());Object.defineProperty(q,"__esModule",{value:!0});q.notImplemented=q.bitMask=void 0;q.isBytes=Qe;q.abytes=Xe;q.abool=Io;q.bytesToHex=Kr;q.numberToHexUnpadded=oi;q.hexToNumber=$r;q.hexToBytes=Je;q.bytesToNumberBE=Po;q.bytesToNumberLE=vo;q.numberToBytesBE=ai;q.numberToBytesLE=Oo;q.numberToVarBytesBE=Uo;q.ensureBytes=Ro;q.concatBytes=ci;q.equalBytes=No;q.utf8ToBytes=Co;q.inRange=ui;q.aInRange=Ho;q.bitLen=qo;q.bitGet=Lo;q.bitSet=Mo;q.createHmacDrbg=ko;q.validateObject=Fo;q.memoized=Ko;var Vr=BigInt(0),Ye=BigInt(1),To=BigInt(2);function Qe(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function Xe(e){if(!Qe(e))throw new Error("Uint8Array expected")}function Io(e,t){if(typeof t!="boolean")throw new Error(`${e} must be valid boolean, got "${t}".`)}var Ao=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Kr(e){Xe(e);let t="";for(let r=0;r=Ot._0&&e<=Ot._9)return e-Ot._0;if(e>=Ot._A&&e<=Ot._F)return e-(Ot._A-10);if(e>=Ot._a&&e<=Ot._f)return e-(Ot._a-10)}function Je(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);let t=e.length,r=t/2;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let i=0,s=0;itypeof e=="bigint"&&Vr<=e;function ui(e,t,r){return jr(e)&&jr(t)&&jr(r)&&t<=e&&eVr;e>>=Ye,t+=1);return t}function Lo(e,t){return e>>BigInt(t)&Ye}function Mo(e,t,r){return e|(r?Ye:Vr)<(To<new Uint8Array(e),si=e=>Uint8Array.from(e);function ko(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Fr(e),i=Fr(e),s=0,o=()=>{n.fill(1),i.fill(0),s=0},a=(...f)=>r(i,n,...f),c=(f=Fr())=>{i=a(si([0]),f),n=a(),f.length!==0&&(i=a(si([1]),f),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,p=[];for(;f{o(),c(f);let w;for(;!(w=p(u()));)c();return o(),w}}var jo={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Qe(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Fo(e,t,r={}){let n=(i,s,o)=>{let a=jo[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=e[i];if(!(o&&c===void 0)&&!a(c,e))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${s}`)};for(let[i,s]of Object.entries(t))n(i,s,!1);for(let[i,s]of Object.entries(r))n(i,s,!0);return e}var Vo=()=>{throw new Error("not implemented")};q.notImplemented=Vo;function Ko(e){let t=new WeakMap;return(r,...n)=>{let i=t.get(r);if(i!==void 0)return i;let s=e(r,...n);return t.set(r,s),s}}});var ve=H(z=>{"use strict";var wu=E(B());Object.defineProperty(z,"__esModule",{value:!0});z.isNegativeLE=void 0;z.mod=ht;z.pow=hi;z.pow2=Wo;z.invert=tr;z.tonelliShanks=di;z.FpSqrt=wi;z.validateField=Qo;z.FpPow=pi;z.FpInvertBatch=gi;z.FpDiv=Xo;z.FpLegendre=yi;z.FpIsSquare=Jo;z.nLength=Zr;z.Field=ta;z.FpSqrtOdd=ea;z.FpSqrtEven=ra;z.hashToPrivateScalar=na;z.getFieldBytesLength=Wr;z.getMinHashLength=_i;z.mapHashToField=ia;var dt=Jt(),G=BigInt(0),j=BigInt(1),Vt=BigInt(2),$o=BigInt(3),zr=BigInt(4),fi=BigInt(5),li=BigInt(8),zo=BigInt(9),Zo=BigInt(16);function ht(e,t){let r=e%t;return r>=G?r:t+r}function hi(e,t,r){if(r<=G||t 0");if(r===j)return G;let n=j;for(;t>G;)t&j&&(n=n*e%r),e=e*e%r,t>>=j;return n}function Wo(e,t,r){let n=e;for(;t-- >G;)n*=n,n%=r;return n}function tr(e,t){if(e===G||t<=G)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let r=ht(e,t),n=t,i=G,s=j,o=j,a=G;for(;r!==G;){let u=n/r,l=n%r,f=i-o*u,p=s-a*u;n=r,r=l,i=o,s=a,o=f,a=p}if(n!==j)throw new Error("invert: does not exist");return ht(i,t)}function di(e){let t=(e-j)/Vt,r,n,i;for(r=e-j,n=0;r%Vt===G;r/=Vt,n++);for(i=Vt;i(ht(e,t)&j)===j;z.isNegativeLE=Go;var Yo=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Qo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Yo.reduce((n,i)=>(n[i]="function",n),t);return(0,dt.validateObject)(e,r)}function pi(e,t,r){if(r 0");if(r===G)return e.ONE;if(r===j)return t;let n=e.ONE,i=t;for(;r>G;)r&j&&(n=e.mul(n,i)),i=e.sqr(i),r>>=j;return n}function gi(e,t){let r=new Array(t.length),n=t.reduce((s,o,a)=>e.is0(o)?s:(r[a]=s,e.mul(s,o)),e.ONE),i=e.inv(n);return t.reduceRight((s,o,a)=>e.is0(o)?s:(r[a]=e.mul(s,r[a]),e.mul(s,o)),i),r}function Xo(e,t,r){return e.mul(t,typeof r=="bigint"?tr(r,e.ORDER):e.inv(r))}function yi(e){let t=(e-j)/Vt;return(r,n)=>r.pow(n,t)}function Jo(e){let t=yi(e.ORDER);return r=>{let n=t(e,r);return e.eql(n,e.ZERO)||e.eql(n,e.ONE)}}function Zr(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ta(e,t,r=!1,n={}){if(e<=G)throw new Error(`Expected Field ORDER > 0, got ${e}`);let{nBitLength:i,nByteLength:s}=Zr(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=wi(e),a=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:(0,dt.bitMask)(i),ZERO:G,ONE:j,create:c=>ht(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return G<=c&&cc===G,isOdd:c=>(c&j)===j,neg:c=>ht(-c,e),eql:(c,u)=>c===u,sqr:c=>ht(c*c,e),add:(c,u)=>ht(c+u,e),sub:(c,u)=>ht(c-u,e),mul:(c,u)=>ht(c*u,e),pow:(c,u)=>pi(a,c,u),div:(c,u)=>ht(c*tr(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>tr(c,e),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>gi(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>r?(0,dt.numberToBytesLE)(c,s):(0,dt.numberToBytesBE)(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return r?(0,dt.bytesToNumberLE)(c):(0,dt.bytesToNumberBE)(c)}});return Object.freeze(a)}function ea(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");let r=e.sqrt(t);return e.isOdd(r)?r:e.neg(r)}function ra(e,t){if(!e.isOdd)throw new Error("Field doesn't have isOdd");let r=e.sqrt(t);return e.isOdd(r)?e.neg(r):r}function na(e,t,r=!1){e=(0,dt.ensureBytes)("privateHash",e);let n=e.length,i=Zr(t).nByteLength+8;if(i<24||n1024)throw new Error(`hashToPrivateScalar: expected ${i}-1024 bytes of input, got ${n}`);let s=r?(0,dt.bytesToNumberLE)(e):(0,dt.bytesToNumberBE)(e);return ht(s,t-j)+j}function Wr(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function _i(e){let t=Wr(e);return t+Math.ceil(t/2)}function ia(e,t,r=!1){let n=e.length,i=Wr(t),s=_i(t);if(n<16||n1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let o=r?(0,dt.bytesToNumberBE)(e):(0,dt.bytesToNumberLE)(e),a=ht(o,t-j)+j;return r?(0,dt.numberToBytesLE)(a,i):(0,dt.numberToBytesBE)(a,i)}});var Ei=H(Oe=>{"use strict";var gu=E(B());Object.defineProperty(Oe,"__esModule",{value:!0});Oe.wNAF=oa;Oe.pippenger=aa;Oe.validateBasic=ca;var bi=ve(),mi=Jt(),sa=BigInt(0),Gr=BigInt(1),Yr=new WeakMap,xi=new WeakMap;function oa(e,t){let r=(s,o)=>{let a=o.negate();return s?a:o},n=s=>{if(!Number.isSafeInteger(s)||s<=0||s>t)throw new Error(`Wrong window size=${s}, should be [1..${t}]`)},i=s=>{n(s);let o=Math.ceil(t/s)+1,a=2**(s-1);return{windows:o,windowSize:a}};return{constTimeNegate:r,unsafeLadder(s,o){let a=e.ZERO,c=s;for(;o>sa;)o&Gr&&(a=a.add(c)),c=c.double(),o>>=Gr;return a},precomputeWindow(s,o){let{windows:a,windowSize:c}=i(o),u=[],l=s,f=l;for(let p=0;p>=x,g>u&&(g-=w,a+=Gr);let _=h,b=h+Math.abs(g)-1,m=y%2!==0,v=g<0;g===0?f=f.add(r(m,o[_])):l=l.add(r(v,o[b]))}return{p:l,f}},wNAFCached(s,o,a){let c=xi.get(s)||1,u=Yr.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&Yr.set(s,a(u))),this.wNAF(c,u,o)},setWindowSize(s,o){n(o),xi.set(s,o),Yr.delete(s)}}}function aa(e,t,r,n){if(!Array.isArray(r)||!Array.isArray(n)||n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((l,f)=>{if(!t.isValid(l))throw new Error(`wrong scalar at index ${f}`)}),r.forEach((l,f)=>{if(!(l instanceof e))throw new Error(`wrong point at index ${f}`)});let i=(0,mi.bitLen)(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,o=(1<=0;l-=s){a.fill(e.ZERO);for(let p=0;p>BigInt(l)&BigInt(o));a[x]=a[x].add(r[p])}let f=e.ZERO;for(let p=a.length-1,w=e.ZERO;p>0;p--)w=w.add(a[p]),f=f.add(w);if(u=u.add(f),l!==0)for(let p=0;p{"use strict";var bu=E(B());Object.defineProperty(rt,"__esModule",{value:!0});rt.DER=void 0;rt.weierstrassPoints=Ti;rt.weierstrass=da;rt.SWUFpSqrtRatio=Ii;rt.mapToCurveSimpleSWU=wa;var er=Ei(),te=ve(),C=Jt(),et=Jt();function Bi(e){e.lowS!==void 0&&(0,et.abool)("lowS",e.lowS),e.prehash!==void 0&&(0,et.abool)("prehash",e.prehash)}function ua(e){let t=(0,er.validateBasic)(e);C.validateObject(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:i}=t;if(r){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:fa,hexToBytes:la}=C;rt.DER={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(e,t)=>{let{Err:r}=rt.DER;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,i=C.numberToHexUnpadded(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?C.numberToHexUnpadded(i.length/2|128):"";return`${C.numberToHexUnpadded(e)}${s}${i}${t}`},decode(e,t){let{Err:r}=rt.DER,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let i=t[n++],s=!!(i&128),o=0;if(!s)o=i;else{let c=i&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)o=o<<8|l;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=rt.DER;if(e{let _=h.toAffine();return C.concatBytes(Uint8Array.from([4]),r.toBytes(_.x),r.toBytes(_.y))}),s=t.fromBytes||(y=>{let h=y.subarray(1),g=r.fromBytes(h.subarray(0,r.BYTES)),_=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x:g,y:_}});function o(y){let{a:h,b:g}=t,_=r.sqr(y),b=r.mul(_,y);return r.add(r.add(b,r.mul(y,h)),g)}if(!r.eql(r.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return C.inRange(y,D,t.n)}function c(y){let{allowedPrivateKeyLengths:h,nByteLength:g,wrapPrivateKey:_,n:b}=t;if(h&&typeof y!="bigint"){if(C.isBytes(y)&&(y=C.bytesToHex(y)),typeof y!="string"||!h.includes(y.length))throw new Error("Invalid key");y=y.padStart(g*2,"0")}let m;try{m=typeof y=="bigint"?y:C.bytesToNumberBE((0,et.ensureBytes)("private key",y,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof y}`)}return _&&(m=te.mod(m,b)),C.aInRange("private key",m,D,b),m}function u(y){if(!(y instanceof p))throw new Error("ProjectivePoint expected")}let l=(0,et.memoized)((y,h)=>{let{px:g,py:_,pz:b}=y;if(r.eql(b,r.ONE))return{x:g,y:_};let m=y.is0();h==null&&(h=m?r.ONE:r.inv(b));let v=r.mul(g,h),I=r.mul(_,h),T=r.mul(b,h);if(m)return{x:r.ZERO,y:r.ZERO};if(!r.eql(T,r.ONE))throw new Error("invZ was invalid");return{x:v,y:I}}),f=(0,et.memoized)(y=>{if(y.is0()){if(t.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:g}=y.toAffine();if(!r.isValid(h)||!r.isValid(g))throw new Error("bad point: x or y not FE");let _=r.sqr(g),b=o(h);if(!r.eql(_,b))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class p{constructor(h,g,_){if(this.px=h,this.py=g,this.pz=_,h==null||!r.isValid(h))throw new Error("x required");if(g==null||!r.isValid(g))throw new Error("y required");if(_==null||!r.isValid(_))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:g,y:_}=h||{};if(!h||!r.isValid(g)||!r.isValid(_))throw new Error("invalid affine point");if(h instanceof p)throw new Error("projective point not allowed");let b=m=>r.eql(m,r.ZERO);return b(g)&&b(_)?p.ZERO:new p(g,_,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let g=r.invertBatch(h.map(_=>_.pz));return h.map((_,b)=>_.toAffine(g[b])).map(p.fromAffine)}static fromHex(h){let g=p.fromAffine(s((0,et.ensureBytes)("pointHex",h)));return g.assertValidity(),g}static fromPrivateKey(h){return p.BASE.multiply(c(h))}static msm(h,g){return(0,er.pippenger)(p,n,h,g)}_setWindowSize(h){x.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:g,py:_,pz:b}=this,{px:m,py:v,pz:I}=h,T=r.eql(r.mul(g,I),r.mul(m,b)),O=r.eql(r.mul(_,I),r.mul(v,b));return T&&O}negate(){return new p(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b:g}=t,_=r.mul(g,rr),{px:b,py:m,pz:v}=this,I=r.ZERO,T=r.ZERO,O=r.ZERO,U=r.mul(b,b),pt=r.mul(m,m),$=r.mul(v,v),M=r.mul(b,m);return M=r.add(M,M),O=r.mul(b,v),O=r.add(O,O),I=r.mul(h,O),T=r.mul(_,$),T=r.add(I,T),I=r.sub(pt,T),T=r.add(pt,T),T=r.mul(I,T),I=r.mul(M,I),O=r.mul(_,O),$=r.mul(h,$),M=r.sub(U,$),M=r.mul(h,M),M=r.add(M,O),O=r.add(U,U),U=r.add(O,U),U=r.add(U,$),U=r.mul(U,M),T=r.add(T,U),$=r.mul(m,v),$=r.add($,$),U=r.mul($,M),I=r.sub(I,U),O=r.mul($,pt),O=r.add(O,O),O=r.add(O,O),new p(I,T,O)}add(h){u(h);let{px:g,py:_,pz:b}=this,{px:m,py:v,pz:I}=h,T=r.ZERO,O=r.ZERO,U=r.ZERO,pt=t.a,$=r.mul(t.b,rr),M=r.mul(g,m),lt=r.mul(_,v),S=r.mul(b,I),A=r.add(g,_),P=r.add(m,v);A=r.mul(A,P),P=r.add(M,lt),A=r.sub(A,P),P=r.add(g,b);let N=r.add(m,I);return P=r.mul(P,N),N=r.add(M,S),P=r.sub(P,N),N=r.add(_,b),T=r.add(v,I),N=r.mul(N,T),T=r.add(lt,S),N=r.sub(N,T),U=r.mul(pt,P),T=r.mul($,S),U=r.add(T,U),T=r.sub(lt,U),U=r.add(lt,U),O=r.mul(T,U),lt=r.add(M,M),lt=r.add(lt,M),S=r.mul(pt,S),P=r.mul($,P),lt=r.add(lt,S),S=r.sub(M,S),S=r.mul(pt,S),P=r.add(P,S),M=r.mul(lt,P),O=r.add(O,M),M=r.mul(N,P),T=r.mul(A,T),T=r.sub(T,M),M=r.mul(A,lt),U=r.mul(N,U),U=r.add(U,M),new p(T,O,U)}subtract(h){return this.add(h.negate())}is0(){return this.equals(p.ZERO)}wNAF(h){return x.wNAFCached(this,h,p.normalizeZ)}multiplyUnsafe(h){C.aInRange("scalar",h,mt,t.n);let g=p.ZERO;if(h===mt)return g;if(h===D)return this;let{endo:_}=t;if(!_)return x.unsafeLadder(this,h);let{k1neg:b,k1:m,k2neg:v,k2:I}=_.splitScalar(h),T=g,O=g,U=this;for(;m>mt||I>mt;)m&D&&(T=T.add(U)),I&D&&(O=O.add(U)),U=U.double(),m>>=D,I>>=D;return b&&(T=T.negate()),v&&(O=O.negate()),O=new p(r.mul(O.px,_.beta),O.py,O.pz),T.add(O)}multiply(h){let{endo:g,n:_}=t;C.aInRange("scalar",h,D,_);let b,m;if(g){let{k1neg:v,k1:I,k2neg:T,k2:O}=g.splitScalar(h),{p:U,f:pt}=this.wNAF(I),{p:$,f:M}=this.wNAF(O);U=x.constTimeNegate(v,U),$=x.constTimeNegate(T,$),$=new p(r.mul($.px,g.beta),$.py,$.pz),b=U.add($),m=pt.add(M)}else{let{p:v,f:I}=this.wNAF(h);b=v,m=I}return p.normalizeZ([b,m])[0]}multiplyAndAddUnsafe(h,g,_){let b=p.BASE,m=(I,T)=>T===mt||T===D||!I.equals(b)?I.multiplyUnsafe(T):I.multiply(T),v=m(this,g).add(m(h,_));return v.is0()?void 0:v}toAffine(h){return l(this,h)}isTorsionFree(){let{h,isTorsionFree:g}=t;if(h===D)return!0;if(g)return g(p,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:g}=t;return h===D?this:g?g(p,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return(0,et.abool)("isCompressed",h),this.assertValidity(),i(p,this,h)}toHex(h=!0){return(0,et.abool)("isCompressed",h),C.bytesToHex(this.toRawBytes(h))}}p.BASE=new p(t.Gx,t.Gy,r.ONE),p.ZERO=new p(r.ZERO,r.ONE,r.ZERO);let w=t.nBitLength,x=(0,er.wNAF)(p,t.endo?Math.ceil(w/2):w);return{CURVE:t,ProjectivePoint:p,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function ha(e){let t=(0,er.validateBasic)(e);return C.validateObject(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function da(e){let t=ha(e),{Fp:r,n}=t,i=r.BYTES+1,s=2*r.BYTES+1;function o(S){return te.mod(S,n)}function a(S){return te.invert(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:f}=Ti({...t,toBytes(S,A,P){let N=A.toAffine(),k=r.toBytes(N.x),Y=C.concatBytes;return(0,et.abool)("isCompressed",P),P?Y(Uint8Array.from([A.hasEvenY()?2:3]),k):Y(Uint8Array.from([4]),k,r.toBytes(N.y))},fromBytes(S){let A=S.length,P=S[0],N=S.subarray(1);if(A===i&&(P===2||P===3)){let k=C.bytesToNumberBE(N);if(!C.inRange(k,D,r.ORDER))throw new Error("Point is not on curve");let Y=l(k),st;try{st=r.sqrt(Y)}catch(xt){let qt=xt instanceof Error?": "+xt.message:"";throw new Error("Point is not on curve"+qt)}let ot=(st&D)===D;return(P&1)===1!==ot&&(st=r.neg(st)),{x:k,y:st}}else if(A===s&&P===4){let k=r.fromBytes(N.subarray(0,r.BYTES)),Y=r.fromBytes(N.subarray(r.BYTES,2*r.BYTES));return{x:k,y:Y}}else throw new Error(`Point of length ${A} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}}),p=S=>C.bytesToHex(C.numberToBytesBE(S,t.nByteLength));function w(S){let A=n>>D;return S>A}function x(S){return w(S)?o(-S):S}let y=(S,A,P)=>C.bytesToNumberBE(S.slice(A,P));class h{constructor(A,P,N){this.r=A,this.s=P,this.recovery=N,this.assertValidity()}static fromCompact(A){let P=t.nByteLength;return A=(0,et.ensureBytes)("compactSignature",A,P*2),new h(y(A,0,P),y(A,P,2*P))}static fromDER(A){let{r:P,s:N}=rt.DER.toSig((0,et.ensureBytes)("DER",A));return new h(P,N)}assertValidity(){C.aInRange("r",this.r,D,n),C.aInRange("s",this.s,D,n)}addRecoveryBit(A){return new h(this.r,this.s,A)}recoverPublicKey(A){let{r:P,s:N,recovery:k}=this,Y=I((0,et.ensureBytes)("msgHash",A));if(k==null||![0,1,2,3].includes(k))throw new Error("recovery id invalid");let st=k===2||k===3?P+t.n:P;if(st>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let ot=k&1?"03":"02",Ht=c.fromHex(ot+p(st)),xt=a(st),qt=o(-Y*xt),Ee=o(N*xt),Lt=c.BASE.multiplyAndAddUnsafe(Ht,qt,Ee);if(!Lt)throw new Error("point at infinify");return Lt.assertValidity(),Lt}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return C.hexToBytes(this.toDERHex())}toDERHex(){return rt.DER.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return C.hexToBytes(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let g={isValidPrivateKey(S){try{return u(S),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let S=te.getMinHashLength(t.n);return te.mapHashToField(t.randomBytes(S),t.n)},precompute(S=8,A=c.BASE){return A._setWindowSize(S),A.multiply(BigInt(3)),A}};function _(S,A=!0){return c.fromPrivateKey(S).toRawBytes(A)}function b(S){let A=C.isBytes(S),P=typeof S=="string",N=(A||P)&&S.length;return A?N===i||N===s:P?N===2*i||N===2*s:S instanceof c}function m(S,A,P=!0){if(b(S))throw new Error("first arg must be private key");if(!b(A))throw new Error("second arg must be public key");return c.fromHex(A).multiply(u(S)).toRawBytes(P)}let v=t.bits2int||function(S){let A=C.bytesToNumberBE(S),P=S.length*8-t.nBitLength;return P>0?A>>BigInt(P):A},I=t.bits2int_modN||function(S){return o(v(S))},T=C.bitMask(t.nBitLength);function O(S){return C.aInRange(`num < 2^${t.nBitLength}`,S,mt,T),C.numberToBytesBE(S,t.nByteLength)}function U(S,A,P=pt){if(["recovered","canonical"].some(Wt=>Wt in P))throw new Error("sign() legacy options not supported");let{hash:N,randomBytes:k}=t,{lowS:Y,prehash:st,extraEntropy:ot}=P;Y==null&&(Y=!0),S=(0,et.ensureBytes)("msgHash",S),Bi(P),st&&(S=(0,et.ensureBytes)("prehashed msgHash",N(S)));let Ht=I(S),xt=u(A),qt=[O(xt),O(Ht)];if(ot!=null&&ot!==!1){let Wt=ot===!0?k(r.BYTES):ot;qt.push((0,et.ensureBytes)("extraEntropy",Wt))}let Ee=C.concatBytes(...qt),Lt=Ht;function br(Wt){let ae=v(Wt);if(!f(ae))return;let _n=a(ae),Bt=c.BASE.multiply(ae).toAffine(),ce=o(Bt.x);if(ce===mt)return;let De=o(_n*o(Lt+ce*xt));if(De===mt)return;let bn=(Bt.x===ce?0:2)|Number(Bt.y&D),xn=De;return Y&&w(De)&&(xn=x(De),bn^=1),new h(ce,xn,bn)}return{seed:Ee,k2sig:br}}let pt={lowS:t.lowS,prehash:!1},$={lowS:t.lowS,prehash:!1};function M(S,A,P=pt){let{seed:N,k2sig:k}=U(S,A,P),Y=t;return C.createHmacDrbg(Y.hash.outputLen,Y.nByteLength,Y.hmac)(N,k)}c.BASE._setWindowSize(8);function lt(S,A,P,N=$){let k=S;if(A=(0,et.ensureBytes)("msgHash",A),P=(0,et.ensureBytes)("publicKey",P),"strict"in N)throw new Error("options.strict was renamed to lowS");Bi(N);let{lowS:Y,prehash:st}=N,ot,Ht;try{if(typeof k=="string"||C.isBytes(k))try{ot=h.fromDER(k)}catch(Bt){if(!(Bt instanceof rt.DER.Err))throw Bt;ot=h.fromCompact(k)}else if(typeof k=="object"&&typeof k.r=="bigint"&&typeof k.s=="bigint"){let{r:Bt,s:ce}=k;ot=new h(Bt,ce)}else throw new Error("PARSE");Ht=c.fromHex(P)}catch(Bt){if(Bt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(Y&&ot.hasHighS())return!1;st&&(A=t.hash(A));let{r:xt,s:qt}=ot,Ee=I(A),Lt=a(qt),br=o(Ee*Lt),Wt=o(xt*Lt),ae=c.BASE.multiplyAndAddUnsafe(Ht,br,Wt)?.toAffine();return ae?o(ae.x)===xt:!1}return{CURVE:t,getPublicKey:_,getSharedSecret:m,sign:M,verify:lt,ProjectivePoint:c,Signature:h,utils:g}}function Ii(e,t){let r=e.ORDER,n=mt;for(let x=r-D;x%Kt===mt;x/=Kt)n+=D;let i=n,s=Kt<{let h=f,g=e.pow(y,u),_=e.sqr(g);_=e.mul(_,y);let b=e.mul(x,_);b=e.pow(b,c),b=e.mul(b,g),g=e.mul(b,y),_=e.mul(b,x);let m=e.mul(_,g);b=e.pow(m,l);let v=e.eql(b,e.ONE);g=e.mul(_,p),b=e.mul(m,h),_=e.cmov(g,_,v),m=e.cmov(b,m,v);for(let I=i;I>D;I--){let T=I-Kt;T=Kt<{let _=e.sqr(g),b=e.mul(h,g);_=e.mul(_,b);let m=e.pow(_,x);m=e.mul(m,b);let v=e.mul(m,y),I=e.mul(e.sqr(m),g),T=e.eql(I,h),O=e.cmov(v,m,T);return{isValid:T,value:O}}}return w}function wa(e,t){if(te.validateField(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");let r=Ii(e,t.Z);if(!e.isOdd)throw new Error("Fp.isOdd is not implemented!");return n=>{let i,s,o,a,c,u,l,f;i=e.sqr(n),i=e.mul(i,t.Z),s=e.sqr(i),s=e.add(s,i),o=e.add(s,e.ONE),o=e.mul(o,t.B),a=e.cmov(t.Z,e.neg(s),!e.eql(s,e.ZERO)),a=e.mul(a,t.A),s=e.sqr(o),u=e.sqr(a),c=e.mul(u,t.A),s=e.add(s,c),s=e.mul(s,o),u=e.mul(u,a),c=e.mul(u,t.B),s=e.add(s,c),l=e.mul(i,o);let{isValid:p,value:w}=r(s,u);f=e.mul(i,n),f=e.mul(f,w),l=e.cmov(l,o,p),f=e.cmov(f,w,p);let x=e.isOdd(n)===e.isOdd(f);return f=e.cmov(e.neg(f),f,x),l=e.div(l,a),{x:l,y:f}}}});var vi=H(nr=>{"use strict";var mu=E(B());Object.defineProperty(nr,"__esModule",{value:!0});nr.getHash=Pi;nr.createCurve=ya;var pa=ni(),Ai=yt(),ga=Qr();function Pi(e){return{hash:e,hmac:(t,...r)=>(0,pa.hmac)(e,t,(0,Ai.concatBytes)(...r)),randomBytes:Ai.randomBytes}}function ya(e,t){let r=n=>(0,ga.weierstrass)({...e,...Pi(n)});return Object.freeze({...r(t),create:r})}});var Ri=H(ee=>{"use strict";var Bu=E(B());Object.defineProperty(ee,"__esModule",{value:!0});ee.expand_message_xmd=Oi;ee.expand_message_xof=Ui;ee.hash_to_field=Xr;ee.isogenyMap=ma;ee.createHasher=Ea;var _a=ve(),it=Jt(),ba=it.bytesToNumberBE;function $t(e,t){if(Ue(e),Ue(t),e<0||e>=1<<8*t)throw new Error(`bad I2OSP call: value=${e} length=${t}`);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function xa(e,t){let r=new Uint8Array(e.length);for(let n=0;n255&&(t=n((0,it.concatBytes)((0,it.utf8ToBytes)("H2C-OVERSIZE-DST-"),t)));let{outputLen:i,blockLen:s}=n,o=Math.ceil(r/i);if(r>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=(0,it.concatBytes)(t,$t(t.length,1)),c=$t(0,s),u=$t(r,2),l=new Array(o),f=n((0,it.concatBytes)(c,e,u,$t(0,1),a));l[0]=n((0,it.concatBytes)(f,$t(1,1),a));for(let w=1;w<=o;w++){let x=[xa(f,l[w-1]),$t(w+1,1),a];l[w]=n((0,it.concatBytes)(...x))}return(0,it.concatBytes)(...l).slice(0,r)}function Ui(e,t,r,n,i){if((0,it.abytes)(e),(0,it.abytes)(t),Ue(r),t.length>255){let s=Math.ceil(2*n/8);t=i.create({dkLen:s}).update((0,it.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(t).digest()}if(r>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:r}).update(e).update($t(r,2)).update(t).update($t(t.length,1)).digest()}function Xr(e,t,r){(0,it.validateObject)(r,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});let{p:n,k:i,m:s,hash:o,expand:a,DST:c}=r;(0,it.abytes)(e),Ue(t);let u=typeof c=="string"?(0,it.utf8ToBytes)(c):c,l=n.toString(2).length,f=Math.ceil((l+i)/8),p=t*s*f,w;if(a==="xmd")w=Oi(e,u,p,o);else if(a==="xof")w=Ui(e,u,p,i,o);else if(a==="_internal_pass")w=e;else throw new Error('expand must be "xmd" or "xof"');let x=new Array(t);for(let y=0;yArray.from(n).reverse());return(n,i)=>{let[s,o,a,c]=r.map(u=>u.reduce((l,f)=>e.add(e.mul(l,n),f)));return n=e.div(s,o),i=e.mul(i,e.div(a,c)),{x:n,y:i}}}function Ea(e,t,r){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(n,i){let s=Xr(n,2,{...r,DST:r.DST,...i}),o=e.fromAffine(t(s[0])),a=e.fromAffine(t(s[1])),c=o.add(a).clearCofactor();return c.assertValidity(),c},encodeToCurve(n,i){let s=Xr(n,1,{...r,DST:r.encodeDST,...i}),o=e.fromAffine(t(s[0])).clearCofactor();return o.assertValidity(),o},mapToCurve(n){if(!Array.isArray(n))throw new Error("mapToCurve: expected array of bigints");for(let s of n)if(typeof s!="bigint")throw new Error(`mapToCurve: expected array of bigints, got ${s} in array`);let i=e.fromAffine(t(n)).clearCofactor();return i.assertValidity(),i}}}});var cr=H(ut=>{"use strict";var Tu=E(B());Object.defineProperty(ut,"__esModule",{value:!0});ut.encodeToCurve=ut.hashToCurve=ut.schnorr=ut.secp256k1=void 0;var ir=kr(),Ba=yt(),Sa=vi(),Hi=Ri(),X=ve(),ct=Jt(),Ta=Qr(),Ce=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),sr=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Re=BigInt(1),or=BigInt(2),Ni=(e,t)=>(e+t/or)/t;function qi(e){let t=Ce,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=(0,X.pow2)(l,r,t)*l%t,p=(0,X.pow2)(f,r,t)*l%t,w=(0,X.pow2)(p,or,t)*u%t,x=(0,X.pow2)(w,i,t)*w%t,y=(0,X.pow2)(x,s,t)*x%t,h=(0,X.pow2)(y,a,t)*y%t,g=(0,X.pow2)(h,c,t)*h%t,_=(0,X.pow2)(g,a,t)*y%t,b=(0,X.pow2)(_,r,t)*l%t,m=(0,X.pow2)(b,o,t)*x%t,v=(0,X.pow2)(m,n,t)*u%t,I=(0,X.pow2)(v,or,t);if(!zt.eql(zt.sqr(I),e))throw new Error("Cannot find square root");return I}var zt=(0,X.Field)(Ce,void 0,void 0,{sqrt:qi});ut.secp256k1=(0,Sa.createCurve)({a:BigInt(0),b:BigInt(7),Fp:zt,n:sr,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=sr,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Re*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,o=BigInt("0x100000000000000000000000000000000"),a=Ni(s*e,t),c=Ni(-n*e,t),u=(0,X.mod)(e-a*r-c*i,t),l=(0,X.mod)(-a*n-c*s,t),f=u>o,p=l>o;if(f&&(u=t-u),p&&(l=t-l),u>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:p,k2:l}}}},ir.sha256);var Li=BigInt(0),Ci={};function ar(e,...t){let r=Ci[e];if(r===void 0){let n=(0,ir.sha256)(Uint8Array.from(e,i=>i.charCodeAt(0)));r=(0,ct.concatBytes)(n,n),Ci[e]=r}return(0,ir.sha256)((0,ct.concatBytes)(r,...t))}var rn=e=>e.toRawBytes(!0).slice(1),tn=e=>(0,ct.numberToBytesBE)(e,32),Jr=e=>(0,X.mod)(e,Ce),Ne=e=>(0,X.mod)(e,sr),nn=ut.secp256k1.ProjectivePoint,Ia=(e,t,r)=>nn.BASE.multiplyAndAddUnsafe(e,t,r);function en(e){let t=ut.secp256k1.utils.normPrivateKeyToScalar(e),r=nn.fromPrivateKey(t);return{scalar:r.hasEvenY()?t:Ne(-t),bytes:rn(r)}}function Mi(e){(0,ct.aInRange)("x",e,Re,Ce);let t=Jr(e*e),r=Jr(t*e+BigInt(7)),n=qi(r);n%or!==Li&&(n=Jr(-n));let i=new nn(e,n,Re);return i.assertValidity(),i}var pe=ct.bytesToNumberBE;function Di(...e){return Ne(pe(ar("BIP0340/challenge",...e)))}function Aa(e){return en(e).bytes}function Pa(e,t,r=(0,Ba.randomBytes)(32)){let n=(0,ct.ensureBytes)("message",e),{bytes:i,scalar:s}=en(t),o=(0,ct.ensureBytes)("auxRand",r,32),a=tn(s^pe(ar("BIP0340/aux",o))),c=ar("BIP0340/nonce",a,i,n),u=Ne(pe(c));if(u===Li)throw new Error("sign failed: k is zero");let{bytes:l,scalar:f}=en(u),p=Di(l,i,n),w=new Uint8Array(64);if(w.set(l,0),w.set(tn(Ne(f+p*s)),32),!ki(w,n,i))throw new Error("sign: Invalid signature produced");return w}function ki(e,t,r){let n=(0,ct.ensureBytes)("signature",e,64),i=(0,ct.ensureBytes)("message",t),s=(0,ct.ensureBytes)("publicKey",r,32);try{let o=Mi(pe(s)),a=pe(n.subarray(0,32));if(!(0,ct.inRange)(a,Re,Ce))return!1;let c=pe(n.subarray(32,64));if(!(0,ct.inRange)(c,Re,sr))return!1;let u=Di(tn(a),rn(o),i),l=Ia(o,c,Ne(-u));return!(!l||!l.hasEvenY()||l.toAffine().x!==a)}catch{return!1}}ut.schnorr={getPublicKey:Aa,sign:Pa,verify:ki,utils:{randomPrivateKey:ut.secp256k1.utils.randomPrivateKey,lift_x:Mi,pointToBytes:rn,numberToBytesBE:ct.numberToBytesBE,bytesToNumberBE:ct.bytesToNumberBE,taggedHash:ar,mod:X.mod}};var va=(0,Hi.isogenyMap)(zt,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),Oa=(0,Ta.mapToCurveSimpleSWU)(zt,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:zt.create(BigInt("-11"))}),ji=(0,Hi.createHasher)(ut.secp256k1.ProjectivePoint,e=>{let{x:t,y:r}=Oa(zt.create(e[0]));return va(t,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:zt.ORDER,m:1,k:128,expand:"xmd",hash:ir.sha256});ut.hashToCurve=ji.hashToCurve;ut.encodeToCurve=ji.encodeToCurve});var re=H(L=>{"use strict";var Au=E(B());Object.defineProperty(L,"__esModule",{value:!0});L.scriptNum=L.base64ToBytes=L.bytesToBase64=L.utf8ToBytes=L.bytesToHex=L.hexToBytes=L.reverseHex=L.padZeroHexN=void 0;var sn=yt(),Fi=Qt(),Ua=async(e,t)=>e.padStart(t,"0");L.padZeroHexN=Ua;var Ra=async e=>(0,L.bytesToHex)((await(0,L.hexToBytes)(e)).reverse());L.reverseHex=Ra;var Na=async e=>(0,sn.hexToBytes)(e);L.hexToBytes=Na;var Ca=async e=>(0,sn.bytesToHex)(e);L.bytesToHex=Ca;var Ha=async e=>(0,sn.utf8ToBytes)(e);L.utf8ToBytes=Ha;var qa=async e=>btoa(String.fromCharCode(...e));L.bytesToBase64=qa;var La=async e=>Uint8Array.from(atob(e),t=>t.charCodeAt(0));L.base64ToBytes=La;var Ma=async e=>{if(e===0)return Fi.Opcode.OP_0;if(e>=1&&e<=16)return(80+e).toString(16);if(e===-1)return Fi.Opcode.OP_1NEGATE;let t=Math.abs(e);if(t<=127)return e=e>0?e:t+128,await(0,L.reverseHex)(await(0,L.padZeroHexN)(e.toString(16),2));if(t<=32767)return e=e>0?e:t+32768,await(0,L.reverseHex)(await(0,L.padZeroHexN)(e.toString(16),4));if(t<=8388607)return e=e>0?e:t+8388608,await(0,L.reverseHex)(await(0,L.padZeroHexN)(e.toString(16),6));if(t<=2147483647)return e=e>0?e:t+2147483648,await(0,L.reverseHex)(await(0,L.padZeroHexN)(e.toString(16),8));if(t<=549755813887)return e=e>0?e:t+549755813888,await(0,L.reverseHex)(await(0,L.padZeroHexN)(e.toString(16),10));throw new Error("Number can be maximum 5 byte int")};L.scriptNum=Ma});var ne=H(ur=>{"use strict";var vu=E(B());Object.defineProperty(ur,"__esModule",{value:!0});ur.Validator=void 0;var on=class{static validateRedeemScript=async t=>{if(t.length>1040)throw new Error("Redeem script must be equal or less than 520 bytes")};static validateScriptSig=async t=>{if(t.length>3300)throw new Error("Script sig must be less than 1650 bytes")};static validateWitnessItem=async t=>{if(t.length>1040)throw new Error("Each witness stack item must be equal or less than 520 bytes if not taproot")};static validateWitnessScript=async t=>{if(t.length>7200)throw new Error("Witness script must be equal or less than 3,600 bytes if not taproot")};static validateBlockLock=async t=>{if(t>=5e8)throw new Error("Block height must be < 500,000,000")};static validateKeyPair=async(t,r,n="ecdsa")=>{if(t){if(n==="schnorr"){if(t?.length!==64)throw new Error("Schnorr pubkey must be 32 bytes")}else if(t?.length!==66)throw new Error("Pubkey must be compressed 33 bytes")}if(r&&r?.length!==64)throw new Error("Privkey must be 32 bytes")};static validateKeyPairBatch=async(t,r,n)=>{let i=[];for(let s=0;s{if(t.length!==0&&+("0x"+t)<=16)throw new Error("Pushing a 1-byte sequence of byte 0x01 through 0x10 must use OP_n");if(t==="81")throw new Error("Pushing the byte 0x81 must use OP_1NEGATE")};static validateUint64=async t=>{if(t<0||!Number.isInteger(t))throw new Error("Number must be uint64")}};ur.Validator=on});var ge=H(At=>{"use strict";var Uu=E(B());Object.defineProperty(At,"__esModule",{value:!0});At.pushDataToNumber=At.varIntToNumber=At.pushData=At.getVarInt=void 0;var bt=re(),Vi=Qt(),Ki=ne(),Da=async e=>(await Ki.Validator.validateUint64(e),e<=252?await(0,bt.padZeroHexN)(e.toString(16),2):e<=65535?"fd"+await(0,bt.reverseHex)(await(0,bt.padZeroHexN)(e.toString(16),4)):e<=4294967295?"fe"+await(0,bt.reverseHex)(await(0,bt.padZeroHexN)(e.toString(16),8)):"ff"+await(0,bt.reverseHex)(await(0,bt.padZeroHexN)(e.toString(16),16)));At.getVarInt=Da;var ka=async e=>(await Ki.Validator.validateMinimalPush(e),e.length/2<76?await(0,bt.padZeroHexN)((e.length/2).toString(16),2):e.length/2<256?Vi.Opcode.OP_PUSHDATA1+await(0,bt.padZeroHexN)((e.length/2).toString(16),2):Vi.Opcode.OP_PUSHDATA2+await(0,bt.reverseHex)(await(0,bt.padZeroHexN)((e.length/2).toString(16),4)));At.pushData=ka;var ja=async e=>e.length===2?+("0x"+e):+("0x"+await(0,bt.reverseHex)(e.slice(2)));At.varIntToNumber=ja;var Fa=async e=>e.length===2?+("0x"+e):+("0x"+e.slice(2));At.pushDataToNumber=Fa});var zi=H((Ru,$i)=>{"use strict";var Nu=E(B());function Va(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r>>0,b=new Uint8Array(_);h!==g;){for(var m=w[h],v=0,I=_-1;(m!==0||v>>0,b[I]=m%o>>>0,m=m/o>>>0;if(m!==0)throw new Error("Non-zero carry");y=v,h++}for(var T=_-y;T!==_&&b[T]===0;)T++;for(var O=a.repeat(x);T<_;++T)O+=e.charAt(b[T]);return O}function f(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;for(var x=0,y=0,h=0;w[x]===a;)y++,x++;for(var g=(w.length-x)*c+1>>>0,_=new Uint8Array(g);w[x];){var b=t[w.charCodeAt(x)];if(b===255)return;for(var m=0,v=g-1;(b!==0||m>>0,_[v]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");h=m,x++}for(var I=g-h;I!==g&&_[I]===0;)I++;for(var T=new Uint8Array(y+(g-I)),O=y;I!==g;)T[O++]=_[I++];return T}function p(w){var x=f(w);if(x)return x;throw new Error("Non-base"+o+" character")}return{encode:l,decodeUnsafe:f,decode:p}}$i.exports=Va});var an=H((Cu,Zi)=>{var Hu=E(B()),Ka=zi(),$a="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";Zi.exports=Ka($a)});var un=H(_e=>{"use strict";var Lu=E(B());Object.defineProperty(_e,"__esModule",{value:!0});_e.bech32m=_e.bech32=void 0;var fr="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Gi={};for(let e=0;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 Wi(e){let t=1;for(let r=0;r126)return"Invalid prefix ("+e+")";t=ye(t)^n>>5}t=ye(t);for(let r=0;r=r;)s-=r,a.push(i>>s&o);if(n)s>0&&a.push(i<=t)return"Excess padding";if(i<c)throw new TypeError("Exceeds length limit");o=o.toLowerCase();let u=Wi(o);if(typeof u=="string")throw new Error(u);let l=o+"1";for(let f=0;f>5)throw new Error("Non 5-bit word");u=ye(u)^p,l+=fr.charAt(p)}for(let f=0;f<6;++f)u=ye(u);u^=t;for(let f=0;f<6;++f){let p=u>>(5-f)*5&31;l+=fr.charAt(p)}return l}function n(o,a){if(a=a||90,o.length<8)return o+" too short";if(o.length>a)return"Exceeds length limit";let c=o.toLowerCase(),u=o.toUpperCase();if(o!==c&&o!==u)return"Mixed-case string "+o;o=c;let l=o.lastIndexOf("1");if(l===-1)return"No separator character for "+o;if(l===0)return"Missing prefix for "+o;let f=o.slice(0,l),p=o.slice(l+1);if(p.length<6)return"Data too short";let w=Wi(f);if(typeof w=="string")return w;let x=[];for(let y=0;y=p.length)&&x.push(g)}return w!==t?"Invalid checksum for "+o:{prefix:f,words:x}}function i(o,a){let c=n(o,a);if(typeof c=="object")return c}function s(o,a){let c=n(o,a);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:i,decode:s,encode:r,toWords:za,fromWordsUnsafe:Za,fromWords:Wa}}_e.bech32=Yi("bech32");_e.bech32m=Yi("bech32m")});var wr=H(J=>{"use strict";var Du=E(B()),Ga=J&&J.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(J,"__esModule",{value:!0});J.generateDataScript=J.generateHashLockScript=J.generateTimeLockScript=J.generateMultiSigScript=J.generateSingleSigScript=J.generateScriptHash=J.getScriptByAddress=void 0;var Et=yt(),Ya=Ga(an()),lr=un(),Z=Qt(),dr=be(),Ut=ge(),hr=re(),He=ne(),Qa=async e=>{if(e.slice(0,4)==="bc1q"||e.slice(0,4)==="tb1q"){let t=(0,Et.bytesToHex)(new Uint8Array(lr.bech32.fromWords(lr.bech32.decode(e).words.slice(1))));return Z.Opcode.OP_0+await(0,Ut.pushData)(t)+t}else if(e.slice(0,4)==="bc1p"||e.slice(0,4)==="tb1p"){let t=(0,Et.bytesToHex)(new Uint8Array(lr.bech32m.fromWords(lr.bech32m.decode(e).words.slice(1))));return Z.Opcode.OP_1+await(0,Ut.pushData)(t)+t}else{let t=(0,Et.bytesToHex)(Ya.default.decode(e).slice(1,21));return e.slice(0,1)==="3"||e.slice(0,1)==="2"?Z.Opcode.OP_HASH160+await(0,Ut.pushData)(t)+t+Z.Opcode.OP_EQUAL:Z.Opcode.OP_DUP+Z.Opcode.OP_HASH160+await(0,Ut.pushData)(t)+t+Z.Opcode.OP_EQUALVERIFY+Z.Opcode.OP_CHECKSIG}};J.getScriptByAddress=Qa;var Xa=async(e,t="segwit")=>{await He.Validator.validateRedeemScript(e);let r=(0,Et.hexToBytes)(e),n=t==="segwit"?await(0,dr.sha256)(r):await(0,dr.hash160)(r);return(0,Et.bytesToHex)(n)};J.generateScriptHash=Xa;var Ja=async(e,t="segwit")=>{if(t==="taproot")return await He.Validator.validateKeyPair(e,"","schnorr"),await(0,Ut.pushData)(e)+e+Z.Opcode.OP_CHECKSIG;await He.Validator.validateKeyPair(e,"","ecdsa");let r=(0,Et.bytesToHex)(await(0,dr.hash160)((0,Et.hexToBytes)(e)));return Z.Opcode.OP_DUP+Z.Opcode.OP_HASH160+await(0,Ut.pushData)(r)+r+Z.Opcode.OP_EQUALVERIFY+Z.Opcode.OP_CHECKSIG};J.generateSingleSigScript=Ja;var tc=async(e,t,r="segwit")=>{if(e<=0||t.length===0)throw new Error("Both priv key and pub key count must be positive number");let n="";if(r!=="taproot"){if(e>15||t.length>15)throw new Error("Maximum number of keys is 15");let i="21"+t.join("21");if(i.length/t.length!==68)throw new Error("pubkey must be compressed 33 bytes");n+=await(0,hr.scriptNum)(e)+i+await(0,hr.scriptNum)(t.length)+Z.Opcode.OP_CHECKMULTISIG}else{if(e>999||t.length>999)throw new Error("Maximum number of keys is 999");t.forEach((o,a)=>{if(o.length!==64)throw new Error("pubkey must be compressed 32 bytes");n+="20"+o+(a===0?Z.Opcode.OP_CHECKSIG:Z.Opcode.OP_CHECKSIGADD)});let i=await(0,hr.scriptNum)(e),s=e<=16?"":await(0,Ut.pushData)(i);n+=s+i+Z.Opcode.OP_NUMEQUAL}return n};J.generateMultiSigScript=tc;var ec=async e=>{await He.Validator.validateBlockLock(e);let t=await(0,hr.scriptNum)(e),r=e<=16?"":await(0,Ut.pushData)(t),n=Z.Opcode.OP_CHECKLOCKTIMEVERIFY;return r+t+n+Z.Opcode.OP_DROP};J.generateTimeLockScript=ec;var rc=async e=>(e.length%2!==0&&(e+="0"),await He.Validator.validateScriptSig(e),Z.Opcode.OP_HASH256+"20"+(0,Et.bytesToHex)(await(0,dr.hash256)((0,Et.hexToBytes)(e)))+Z.Opcode.OP_EQUALVERIFY);J.generateHashLockScript=rc;var nc=async(e,t="utf-8")=>{let r=t==="hex"?e:(0,Et.bytesToHex)((0,Et.utf8ToBytes)(e));if(r.length>160)throw new Error("Maximum data size is 80 bytes");return Z.Opcode.OP_RETURN+await(0,Ut.pushData)(r)+r};J.generateDataScript=nc});var gr=H(W=>{"use strict";var ju=E(B());Object.defineProperty(W,"__esModule",{value:!0});W.getTapControlBlock=W.getTapSigHash=W.getTapTweakedPrivkey=W.getTapTweakedPubkey=W.getTapTag=W.getTapTweak=W.getTapBranch=W.getTapLeaf=void 0;var qe=be(),ic=ge(),ie=re(),Rt=cr(),pr=ne(),sc=new Uint8Array([84,97,112,76,101,97,102]),oc=new Uint8Array([84,97,112,66,114,97,110,99,104]),ac=new Uint8Array([84,97,112,84,119,101,97,107]),cc=new Uint8Array([84,97,112,83,105,103,104,97,115,104]),uc=async(e,t=192)=>await(0,qe.sha256)(new Uint8Array([...await(0,W.getTapTag)(sc),...await(0,ie.hexToBytes)((t&254).toString(16)+await(0,ic.getVarInt)(e.length/2)+e)]));W.getTapLeaf=uc;var fc=async e=>{if(e.length!==2)throw new Error("TapLeaf pair length must be 2");if(e[0]?.length!==32||e[1]?.length!==32)throw new Error("TapLeaf must be 32 bytes hex");let t=new Uint8Array([...e[0],...e[1]]);for(let r=0;r{if(await pr.Validator.validateKeyPair(e,"","schnorr"),t&&t.length!==32)throw new Error("TapRoot must be 32 bytes");let r=new Uint8Array([...await(0,W.getTapTag)(ac),...await(0,ie.hexToBytes)(e)]);return await(0,qe.sha256)(t?new Uint8Array([...r,...t]):r)};W.getTapTweak=lc;var hc=async e=>{let t=await(0,qe.sha256)(e);return new Uint8Array([...t,...t])};W.getTapTag=hc;var dc=async(e,t)=>{await pr.Validator.validateKeyPair(e,"","schnorr");let n=Rt.schnorr.utils.lift_x(Rt.schnorr.utils.bytesToNumberBE(await(0,ie.hexToBytes)(e))).add(Rt.secp256k1.ProjectivePoint.fromPrivateKey(t));return{parityBit:n.hasEvenY()?"02":"03",tweakedPubKey:await(0,ie.bytesToHex)(new Uint8Array([...Rt.schnorr.utils.pointToBytes(n)]))}};W.getTapTweakedPubkey=dc;var wc=async(e,t)=>{await pr.Validator.validateKeyPair("",e,"schnorr");let r=Rt.secp256k1.utils.normPrivateKeyToScalar,n=Rt.secp256k1.ProjectivePoint.fromPrivateKey(await(0,ie.hexToBytes)(e));return await(0,ie.bytesToHex)(Rt.schnorr.utils.numberToBytesBE(Rt.schnorr.utils.mod((n.hasEvenY()?r(e):-r(e))+r(t),Rt.secp256k1.CURVE.n),32))};W.getTapTweakedPrivkey=wc;var pc=async e=>await(0,qe.sha256)(new Uint8Array([...await(0,W.getTapTag)(cc),...e]));W.getTapSigHash=pc;var gc=async(e,t,r,n=192)=>(await pr.Validator.validateKeyPair(e,"","schnorr"),n+=t==="02"?0:1,n.toString(16)+e+await(0,ie.bytesToHex)(r));W.getTapControlBlock=gc});var be=H(F=>{"use strict";var Vu=E(B());Object.defineProperty(F,"__esModule",{value:!0});F.verifyMessage=F.signMessage=F.verify=F.sign=F.sha256=F.ripemd160=F.hash256=F.hash160=void 0;var yc=ei(),_c=kr(),Nt=cr(),tt=re(),Xi=ne(),Ji=ge(),fn=wr(),se=Qt(),Qi=hn(),ln=gr(),bc=async e=>await(0,F.ripemd160)(await(0,F.sha256)(e));F.hash160=bc;var xc=async e=>await(0,F.sha256)(await(0,F.sha256)(e));F.hash256=xc;var mc=async e=>(0,yc.ripemd160)(e);F.ripemd160=mc;var Ec=async e=>(0,_c.sha256)(e);F.sha256=Ec;var Bc=async(e,t,r="ecdsa",n="01000000")=>(await Xi.Validator.validateKeyPair("",t,r),n==="01000000"&&r==="schnorr"&&(n=""),(r==="ecdsa"?Nt.secp256k1.sign(e,t).toDERHex():await(0,tt.bytesToHex)(Nt.schnorr.sign(e,t)))+n.slice(0,2));F.sign=Bc;var Sc=async(e,t,r,n="ecdsa",i="01000000")=>(await Xi.Validator.validateKeyPair(r,"",n),i==="01000000"&&n==="schnorr"||(e=e.slice(0,-2)),n==="ecdsa"?Nt.secp256k1.verify(e,t,r):Nt.schnorr.verify(e,t,r));F.verify=Sc;var Tc=async(e,t,r)=>{let n=await(0,fn.getScriptByAddress)(r);if(n.slice(0,2)===se.Opcode.OP_DUP){let i=await(0,tt.utf8ToBytes)(`Bitcoin Signed Message: `),s=await(0,tt.utf8ToBytes)(e),o=await(0,Ji.getVarInt)(s.length),a=await(0,F.hash256)(new Uint8Array([...i,...await(0,tt.hexToBytes)(o),...s])),c=Nt.secp256k1.sign(a,t);return(0,tt.bytesToBase64)(new Uint8Array([c.recovery+31,...c.toCompactRawBytes()]))}else{let i=await(0,tt.bytesToHex)(Nt.secp256k1.getPublicKey(t)),s=await ts(e,n);if(n.slice(0,2)===se.Opcode.OP_0)await s.signInput(t,0);else if(n.slice(0,2)===se.Opcode.OP_1){let o=await(0,ln.getTapTweak)(i.slice(2)),a=await(0,ln.getTapTweakedPrivkey)(t,o);await s.signInput(a,0,"taproot","","","01_TRICK_SIGHASH_ALL")}else throw new Error("Only p2pkh, p2wpkh, p2tr address are supported now");return(0,tt.bytesToBase64)(await(0,tt.hexToBytes)(s._witness.get(0)))}};F.signMessage=Tc;var Ic=async(e,t,r)=>{let n=await(0,tt.bytesToHex)(await(0,tt.base64ToBytes)(t)),i=await(0,fn.getScriptByAddress)(r);if(i.slice(0,2)===se.Opcode.OP_DUP){let s=await(0,tt.utf8ToBytes)(`Bitcoin Signed Message: `),o=await(0,tt.utf8ToBytes)(e),a=await(0,Ji.getVarInt)(o.length),c=await(0,F.hash256)(new Uint8Array([...s,...await(0,tt.hexToBytes)(a),...o])),u=i.slice(6,46),l=Nt.secp256k1.Signature.fromCompact(n.slice(2)).addRecoveryBit(parseInt(n.slice(0,2),16)-31).recoverPublicKey(c).toRawBytes();return await(0,tt.bytesToHex)(await(0,F.hash160)(l))===u}else{let s=await ts(e,i);if(i.slice(0,2)===se.Opcode.OP_0){let o=parseInt(n.slice(2,4),16)*2,a=n.slice(4,4+o-2),c=n.slice(6+o),u=await(0,fn.generateSingleSigScript)(c),l=await s.getInputHashToSign(u,0,"segwit");return Nt.secp256k1.verify(a,l,c)}else if(i.slice(0,2)===se.Opcode.OP_1){let o=n.slice(4,132),a=i.slice(4),c=await s.getInputHashToSign("",0,"taproot","01_TRICK_SIGHASH_ALL");return Nt.schnorr.verify(o,c,a)}throw new Error("Only p2pkh, p2wpkh, p2tr address are supported now")}};F.verifyMessage=Ic;var ts=async(e,t)=>{let r=new Qi.Transaction;await r.setVersion(0),await r.addInput({txHash:await(0,tt.padZeroHexN)("",64),index:4294967295,value:0,sequence:"00000000"}),await r.addOutput({script:t,value:0});let n=await(0,tt.bytesToHex)(await(0,F.sha256)(new Uint8Array([...await(0,ln.getTapTag)(await(0,tt.utf8ToBytes)("BIP0322-signed-message")),...await(0,tt.utf8ToBytes)(e)])));await r.signInputByScriptSig(["",n],0,"legacy");let i=new Qi.Transaction;return await i.setVersion(0),await i.addInput({txHash:await r.getId(),index:0,value:0,sequence:"00000000",script:t}),await i.addOutput({script:se.Opcode.OP_RETURN,value:0}),i}});var pn=H(xe=>{"use strict";var $u=E(B());Object.defineProperty(xe,"__esModule",{value:!0});xe.getPublicKey=xe.generateKeyPair=void 0;var dn=cr(),wn=yt(),Ac=async()=>{let e=dn.secp256k1.utils.randomPrivateKey(),t=dn.secp256k1.getPublicKey(e);return{publicKey:(0,wn.bytesToHex)(t),privateKey:(0,wn.bytesToHex)(e)}};xe.generateKeyPair=Ac;var Pc=async e=>(0,wn.bytesToHex)(dn.secp256k1.getPublicKey(e));xe.getPublicKey=Pc});var hn=H(yr=>{"use strict";var Zu=E(B());Object.defineProperty(yr,"__esModule",{value:!0});yr.Transaction=void 0;var nt=yt(),gn=Qt(),wt=be(),ft=re(),K=ge(),Le=wr(),es=gr(),Ct=ne(),vc=pn(),yn=class{_inputs;_outputs;_inputScript;_outputScript;_witness;_version="01000000";_locktime="00000000";_defaultSequence="fdffffff";_unsignedTx="";_segWitMarker="00";_segWitFlag="01";_witnessMsgPrefix;_witnessMsgSuffix;_taprootMsgPrefix;constructor(){this._inputs=[],this._outputs=[],this._witness=new Map,this._inputScript=new Map,this._outputScript=new Map,this._witnessMsgPrefix=new Uint8Array,this._witnessMsgSuffix=new Uint8Array,this._taprootMsgPrefix=new Uint8Array}addInput=async t=>{await this._isSignedCheck("add input"),await this._validateInput(t),this._inputs.push(t)};addOutput=async t=>{await this._isSignedCheck("add output"),await this._validateOutput(t),this._outputs.push(t)};finalize=async(t="segwit")=>{await this._finalize(t)};signAll=async(t,r="segwit",n="",i="",s="01000000")=>{await Ct.Validator.validateKeyPair("",t,r==="taproot"?"schnorr":"ecdsa"),await this._finalize(r);let o=[];for(let a=0;a{await this._validateInputRange(r);let a=await(0,vc.getPublicKey)(t),c=n==="taproot"?a.slice(2):a;await Ct.Validator.validateKeyPair(c,t,n==="taproot"?"schnorr":"ecdsa"),await this._finalize(n),await this._sign([c],[t],this._unsignedTx,r,!1,i,s,n,o)};multiSignInput=async(t,r,n,i="segwit",s="",o="",a="01000000")=>{await this._validateInputRange(n),await Ct.Validator.validateKeyPairBatch(t,r,"ecdsa"),await this._finalize(i),await this._sign(t,r,this._unsignedTx,n,!0,s,o,i,a)};unlockHashInput=async(t,r,n="segwit",i="")=>{await this._validateInputRange(r),await this._finalize(n),t.length%2!==0&&(t+="0");let s=i+await(0,Le.generateHashLockScript)(t),o=n==="segwit",a="01"+gn.Opcode.OP_1+(o?await(0,K.getVarInt)(t.length/2):await(0,K.pushData)(t))+t+(o?await(0,K.getVarInt)(s.length/2):await(0,K.pushData)(s))+s;o?await this._setWitnessScript(r,a,await this._getWitnessItemCount(["count_for_OP_1"],[],!1,i,t)):await this._setInputScriptSig(r,a)};getSignedHex=async()=>{let t=await this.isSegWit(),r="",i=await(0,K.getVarInt)(this._inputs.length);for(let a=0;a{await this._validateInputRange(r),(n==="legacy"||n==="segwit")&&await Ct.Validator.validateRedeemScript(t),await this._finalize(n);let o=n==="segwit"?await(0,K.getVarInt)(t.length/2):await(0,K.pushData)(t),a=n==="tapscript"||n==="taproot"?t:o.length===2||n==="segwit"?o+t:o.slice(2)+t;return await this._getHashToSign(this._unsignedTx,r,a,n,i,s)};signInputByScriptSig=async(t,r,n="segwit")=>{if(await this._validateInputRange(r),await this._finalize(n),n==="segwit"||n==="tapscript"){let i=await(0,K.getVarInt)(t.length),s="";for(let o=0;o(0,nt.bytesToHex)((await(0,wt.hash256)((0,nt.hexToBytes)(await this._getSignedHexLegacy()))).reverse());setLocktime=async t=>{await this._isSignedCheck("set locktime"),await Ct.Validator.validateBlockLock(t),this._locktime=await(0,ft.reverseHex)(await(0,ft.padZeroHexN)(t.toString(16),8))};setVersion=async t=>{await this._isSignedCheck("set version"),this._version=await(0,ft.reverseHex)(await(0,ft.padZeroHexN)(t.toString(16),8))};disableRBF=async()=>{await this._isSignedCheck("disable rbf"),this._defaultSequence="feffffff"};disableLocktime=async()=>{await this._isSignedCheck("disable locktime"),this._defaultSequence="ffffffff"};isSegWit=async()=>this._witness.size!==0;_finalize=async t=>{if(this._unsignedTx.length!==0){if(t==="legacy")return}else{await Promise.all([this._finalizeInputs(),this._finalizeOutputs()]);let n=await(0,K.getVarInt)(this._inputs.length);for(let o=0;o{if(this._inputScript.size===0)for(let t=0;t{if(this._outputScript.size===0)for(let t=0;t{if(this._witnessMsgPrefix.length!==0&&t==="segwit")return;let r=(0,nt.hexToBytes)(this._version),n="",i="";for(let l=0;l{let o="",a="";for(let l=0;l{let l="";if(c!=="taproot"){let x="";if(a.length!==0&&(x=await(0,Le.generateHashLockScript)(a),a.length%2!==0&&(a+="0"),a=(c!=="legacy"?await(0,K.getVarInt)(a.length/2):await(0,K.pushData)(a))+a),s){let y=await(0,Le.generateMultiSigScript)(r.length,t);l=o+x+y}else{let y=await(0,Le.generateSingleSigScript)(t[0]);l=o+x+y}}let f=c!=="legacy"?await(0,K.getVarInt)(l.length/2):await(0,K.pushData)(l);c!=="taproot"&&(l=f.length===2||c!=="legacy"?f+l:f.slice(2)+l);let p=await this._getHashToSign(n,i,l,c,u),w="";if(s){let x=gn.Opcode.OP_0;for(let y=0;y{if(i==="taproot"||i==="tapscript"){let c=i==="taproot"?0:2,u=await(0,nt.hexToBytes)(await(0,ft.padZeroHexN)(r.toString(16),8)).reverse(),l=new Uint8Array([0,s==="01000000"?0:parseInt(s.slice(0,2)),...this._taprootMsgPrefix,c,...u]);return await(0,es.getTapSigHash)(i==="taproot"?l:new Uint8Array([...l,...await(0,es.getTapLeaf)(n),parseInt(o),...await(0,nt.hexToBytes)("ffffffff")]))}else if(i==="segwit"){let a=this._inputScript.get(r),c=(0,nt.hexToBytes)(a.txHash+a.index),u=(0,nt.hexToBytes)(n),l=(0,nt.hexToBytes)(await(0,ft.padZeroHexN)(this._inputs[r].value.toString(16),16)).reverse(),f=this._inputs[r].sequence?this._inputs[r].sequence:this._defaultSequence,p=(0,nt.hexToBytes)(f),w=(0,nt.hexToBytes)(s);return await(0,wt.hash256)(new Uint8Array([...this._witnessMsgPrefix,...c,...u,...l,...p,...this._witnessMsgSuffix,...w]))}else{let a=t+s,c=await this._getScriptCodeIdx(r);return await(0,wt.hash256)((0,nt.hexToBytes)(a.slice(0,c)+n+a.slice(c+2)))}};_getScriptCodeIdx=async t=>8+(await(0,K.getVarInt)(this._inputs.length)).length+82*t+72;_setInputScriptSig=async(t,r)=>{let n=await(0,K.getVarInt)(r.length/2)+r,i=this._inputScript.get(t);i.scriptSig=n,this._inputScript.set(t,i)};_setWitnessScript=async(t,r,n)=>{this._witness.set(t,n+r)};_getWitnessItemCount=async(t,r,n,i="",s="")=>{let o=r.length;return s.length!==0&&(o+=1),n?o+=2:(i.length!==0||s.length!==0)&&(o+=1),n||(o+=t.length),(0,ft.padZeroHexN)(o.toString(16),2)};_isSignedCheck=async t=>{if(this._outputScript.size!==0)throw new Error(`Cannot ${t} after any of input is signed`)};_getSignedHexLegacy=async()=>{let r=await(0,K.getVarInt)(this._inputs.length);for(let s=0;s{if(t.txHash.length!==64||!Number.isInteger(+("0x"+t.txHash)))throw new Error("Input tx hash must be 32 byte hex");if(t.index<0||t.index>4294967295||!Number.isInteger(t.index))throw new Error("Input index must be 4 byte uint");if(t.value<0||!Number.isInteger(t.value))throw new Error("Input value must be 8 byte uint");if(t.sequence&&(t.sequence.length!==8||!Number.isInteger(+("0x"+t.sequence))))throw new Error("Input sequence must be 4 byte hex")};_validateOutput=async t=>{if(!t.address&&!t.script)throw new Error("Either address or script must be given for output");if(t.value<0||!Number.isInteger(t.value))throw new Error("Output value must be 8 byte uint");if(t.script&&t.script.length>2e4)throw new Error("Output script must be equal or less tan 10,000 bytes")};_validateInputRange=async t=>{if(t>this._inputs.length-1)throw new Error(`Out of range, tx contains only ${this._inputs.length} inputs`)}};yr.Transaction=yn});var is=H(Zt=>{"use strict";var Gu=E(B()),Oc=Zt&&Zt.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Zt,"__esModule",{value:!0});Zt.generateScriptAddress=Zt.generateAddress=void 0;var _r=yt(),rs=Oc(an()),Me=be(),me=un(),ns=ne(),Uc=async(e,t="segwit",r="mainnet")=>{if(await ns.Validator.validateKeyPair(e,"",t==="taproot"?"schnorr":"ecdsa"),t==="taproot"){let i=me.bech32m.toWords((0,_r.hexToBytes)(e));return i.unshift(1),me.bech32m.encode(r==="mainnet"?"bc":"tb",i)}let n=await(0,Me.hash160)((0,_r.hexToBytes)(e));if(t==="segwit"){let i=me.bech32.toWords(n);return i.unshift(0),me.bech32.encode(r==="mainnet"?"bc":"tb",i)}else{let i=new Uint8Array([r==="mainnet"?0:111]),s=(await(0,Me.hash256)(new Uint8Array([...i,...n]))).slice(0,4);return rs.default.encode(new Uint8Array([...i,...n,...s]))}};Zt.generateAddress=Uc;var Rc=async(e,t="segwit",r="mainnet")=>{await ns.Validator.validateRedeemScript(e);let n=t==="segwit"?await(0,Me.sha256)((0,_r.hexToBytes)(e)):await(0,Me.hash160)((0,_r.hexToBytes)(e));if(t==="segwit"){let i=me.bech32.toWords(n);return i.unshift(0),me.bech32.encode(r==="mainnet"?"bc":"tb",i)}else{let i=new Uint8Array([r==="mainnet"?5:196]),s=(await(0,Me.hash256)(new Uint8Array([...i,...n]))).slice(0,4);return rs.default.encode(new Uint8Array([...i,...n,...s]))}};Zt.generateScriptAddress=Rc});var ss=H(V=>{"use strict";var Qu=E(B()),Nc=V&&V.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Cc=V&&V.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),oe=V&&V.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&Nc(t,e,r);return Cc(t,e),t};Object.defineProperty(V,"__esModule",{value:!0});V.tapscript=V.data=V.encode=V.crypto=V.Opcode=V.wallet=V.address=V.script=V.Transaction=void 0;var Hc=hn();Object.defineProperty(V,"Transaction",{enumerable:!0,get:function(){return Hc.Transaction}});V.script=oe(wr());V.address=oe(is());V.wallet=oe(pn());var qc=Qt();Object.defineProperty(V,"Opcode",{enumerable:!0,get:function(){return qc.Opcode}});V.crypto=oe(be());V.encode=oe(re());V.data=oe(ge());V.tapscript=oe(gr())});var Mc=H(()=>{var t0=E(B()),{crypto:Lc}=ss();(async()=>{let e={datil:"0x213Db6E1446928E19588269bEF7dFc9187c4829A","datil-test":"0x60C1ddC8b9e38F730F0e7B70A2F84C1A98A69167","datil-dev":"0xf64638F1eb3b064f5443F7c9e2Dc050ed535D891"},t=ethers.utils.keccak256(ethers.utils.toUtf8Bytes("BITCOIN_BIP322_v0")),r=new ethers.utils.Interface(["function isPermittedAuthMethod(uint256 tokenId, uint256 authMethodType, bytes memory id) public view returns (bool)"]);console.log("BITCOIN_BIP322 authSig:",accessToken),console.log("BITCOIN_BIP322 network:",network);try{let n=JSON.parse(accessToken),i=network?e[network]:e["datil-dev"];if(console.log("BITCOIN_BIP322 permissionsContract:",i),!await Lc.verifyMessage(n.signedMessage,n.sig,n.address))return console.log("BITCOIN_BIP322 Invalid Bitcoin BIP322 (P2PKH, P2WPKH, P2TR) signature"),Lit.Actions.setResponse({response:"false",reason:"Invalid Bitcoin BIP322 (P2PKH, P2WPKH, P2TR) signature"});let o=n.signedMessage.split("Expiration Time: ")[1].split(` `)[0];if(!(Date.now()/1e3 *) buffer/index.js: (*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT *) @noble/hashes/utils.js: (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/abstract/utils.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/abstract/modular.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/abstract/curve.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/abstract/weierstrass.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/_shortw_utils.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) @noble/curves/secp256k1.js: (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *) */