-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
140 lines (127 loc) · 189 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>COLDCARD NFC Push TX</title>
<script type="module" crossorigin>var Ws=Object.defineProperty;var js=(e,t,r)=>t in e?Ws(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Zt=(e,t,r)=>js(e,typeof t!="symbol"?t+"":t,r);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const c of i)if(c.type==="childList")for(const s of c.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&n(s)}).observe(document,{childList:!0,subtree:!0});function r(i){const c={};return i.integrity&&(c.integrity=i.integrity),i.referrerPolicy&&(c.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?c.credentials="include":i.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function n(i){if(i.ep)return;i.ep=!0;const c=r(i);fetch(i.href,c)}})();function Vs(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var lo={},se={},Vr={};Vr.byteLength=qs;Vr.toByteArray=Ys;Vr.fromByteArray=Zs;var $e=[],Pe=[],Gs=typeof Uint8Array<"u"?Uint8Array:Array,wn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Lt=0,Xs=wn.length;Lt<Xs;++Lt)$e[Lt]=wn[Lt],Pe[wn.charCodeAt(Lt)]=Lt;Pe[45]=62;Pe[95]=63;function yo(e){var t=e.length;if(t%4>0)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 qs(e){var t=yo(e),r=t[0],n=t[1];return(r+n)*3/4-n}function zs(e,t,r){return(t+r)*3/4-r}function Ys(e){var t,r=yo(e),n=r[0],i=r[1],c=new Gs(zs(e,n,i)),s=0,a=i>0?n-4:n,p;for(p=0;p<a;p+=4)t=Pe[e.charCodeAt(p)]<<18|Pe[e.charCodeAt(p+1)]<<12|Pe[e.charCodeAt(p+2)]<<6|Pe[e.charCodeAt(p+3)],c[s++]=t>>16&255,c[s++]=t>>8&255,c[s++]=t&255;return i===2&&(t=Pe[e.charCodeAt(p)]<<2|Pe[e.charCodeAt(p+1)]>>4,c[s++]=t&255),i===1&&(t=Pe[e.charCodeAt(p)]<<10|Pe[e.charCodeAt(p+1)]<<4|Pe[e.charCodeAt(p+2)]>>2,c[s++]=t>>8&255,c[s++]=t&255),c}function Js(e){return $e[e>>18&63]+$e[e>>12&63]+$e[e>>6&63]+$e[e&63]}function Qs(e,t,r){for(var n,i=[],c=t;c<r;c+=3)n=(e[c]<<16&16711680)+(e[c+1]<<8&65280)+(e[c+2]&255),i.push(Js(n));return i.join("")}function Zs(e){for(var t,r=e.length,n=r%3,i=[],c=16383,s=0,a=r-n;s<a;s+=c)i.push(Qs(e,s,s+c>a?a:s+c));return n===1?(t=e[r-1],i.push($e[t>>2]+$e[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push($e[t>>10]+$e[t>>4&63]+$e[t<<2&63]+"=")),i.join("")}var Vn={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Vn.read=function(e,t,r,n,i){var c,s,a=i*8-n-1,p=(1<<a)-1,w=p>>1,f=-7,d=r?i-1:0,S=r?-1:1,y=e[t+d];for(d+=S,c=y&(1<<-f)-1,y>>=-f,f+=a;f>0;c=c*256+e[t+d],d+=S,f-=8);for(s=c&(1<<-f)-1,c>>=-f,f+=n;f>0;s=s*256+e[t+d],d+=S,f-=8);if(c===0)c=1-w;else{if(c===p)return s?NaN:(y?-1:1)*(1/0);s=s+Math.pow(2,n),c=c-w}return(y?-1:1)*s*Math.pow(2,c-n)};Vn.write=function(e,t,r,n,i,c){var s,a,p,w=c*8-i-1,f=(1<<w)-1,d=f>>1,S=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:c-1,_=n?1:-1,T=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(p=Math.pow(2,-s))<1&&(s--,p*=2),s+d>=1?t+=S/p:t+=S*Math.pow(2,1-d),t*p>=2&&(s++,p/=2),s+d>=f?(a=0,s=f):s+d>=1?(a=(t*p-1)*Math.pow(2,i),s=s+d):(a=t*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;e[r+y]=a&255,y+=_,a/=256,i-=8);for(s=s<<i|a,w+=i;w>0;e[r+y]=s&255,y+=_,s/=256,w-=8);e[r+y-_]|=T*128};/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/(function(e){const t=Vr,r=Vn,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=f,e.SlowBuffer=v,e.INSPECT_MAX_BYTES=50;const i=2147483647;e.kMaxLength=i;const{Uint8Array:c,ArrayBuffer:s,SharedArrayBuffer:a}=globalThis;f.TYPED_ARRAY_SUPPORT=p(),!f.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 p(){try{const h=new c(1),o={foo:function(){return 42}};return Object.setPrototypeOf(o,c.prototype),Object.setPrototypeOf(h,o),h.foo()===42}catch{return!1}}Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}});function w(h){if(h>i)throw new RangeError('The value "'+h+'" is invalid for option "size"');const o=new c(h);return Object.setPrototypeOf(o,f.prototype),o}function f(h,o,u){if(typeof h=="number"){if(typeof o=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return _(h)}return d(h,o,u)}f.poolSize=8192;function d(h,o,u){if(typeof h=="string")return T(h,o);if(s.isView(h))return x(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(Ue(h,s)||h&&Ue(h.buffer,s)||typeof a<"u"&&(Ue(h,a)||h&&Ue(h.buffer,a)))return N(h,o,u);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const l=h.valueOf&&h.valueOf();if(l!=null&&l!==h)return f.from(l,o,u);const g=k(h);if(g)return g;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return f.from(h[Symbol.toPrimitive]("string"),o,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h)}f.from=function(h,o,u){return d(h,o,u)},Object.setPrototypeOf(f.prototype,c.prototype),Object.setPrototypeOf(f,c);function S(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 y(h,o,u){return S(h),h<=0?w(h):o!==void 0?typeof u=="string"?w(h).fill(o,u):w(h).fill(o):w(h)}f.alloc=function(h,o,u){return y(h,o,u)};function _(h){return S(h),w(h<0?0:m(h)|0)}f.allocUnsafe=function(h){return _(h)},f.allocUnsafeSlow=function(h){return _(h)};function T(h,o){if((typeof o!="string"||o==="")&&(o="utf8"),!f.isEncoding(o))throw new TypeError("Unknown encoding: "+o);const u=I(h,o)|0;let l=w(u);const g=l.write(h,o);return g!==u&&(l=l.slice(0,g)),l}function P(h){const o=h.length<0?0:m(h.length)|0,u=w(o);for(let l=0;l<o;l+=1)u[l]=h[l]&255;return u}function x(h){if(Ue(h,c)){const o=new c(h);return N(o.buffer,o.byteOffset,o.byteLength)}return P(h)}function N(h,o,u){if(o<0||h.byteLength<o)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<o+(u||0))throw new RangeError('"length" is outside of buffer bounds');let l;return o===void 0&&u===void 0?l=new c(h):u===void 0?l=new c(h,o):l=new c(h,o,u),Object.setPrototypeOf(l,f.prototype),l}function k(h){if(f.isBuffer(h)){const o=m(h.length)|0,u=w(o);return u.length===0||h.copy(u,0,0,o),u}if(h.length!==void 0)return typeof h.length!="number"||yn(h.length)?w(0):P(h);if(h.type==="Buffer"&&Array.isArray(h.data))return P(h.data)}function m(h){if(h>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return h|0}function v(h){return+h!=h&&(h=0),f.alloc(+h)}f.isBuffer=function(o){return o!=null&&o._isBuffer===!0&&o!==f.prototype},f.compare=function(o,u){if(Ue(o,c)&&(o=f.from(o,o.offset,o.byteLength)),Ue(u,c)&&(u=f.from(u,u.offset,u.byteLength)),!f.isBuffer(o)||!f.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(o===u)return 0;let l=o.length,g=u.length;for(let b=0,A=Math.min(l,g);b<A;++b)if(o[b]!==u[b]){l=o[b],g=u[b];break}return l<g?-1:g<l?1:0},f.isEncoding=function(o){switch(String(o).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}},f.concat=function(o,u){if(!Array.isArray(o))throw new TypeError('"list" argument must be an Array of Buffers');if(o.length===0)return f.alloc(0);let l;if(u===void 0)for(u=0,l=0;l<o.length;++l)u+=o[l].length;const g=f.allocUnsafe(u);let b=0;for(l=0;l<o.length;++l){let A=o[l];if(Ue(A,c))b+A.length>g.length?(f.isBuffer(A)||(A=f.from(A)),A.copy(g,b)):c.prototype.set.call(g,A,b);else if(f.isBuffer(A))A.copy(g,b);else throw new TypeError('"list" argument must be an Array of Buffers');b+=A.length}return g};function I(h,o){if(f.isBuffer(h))return h.length;if(s.isView(h)||Ue(h,s))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,l=arguments.length>2&&arguments[2]===!0;if(!l&&u===0)return 0;let g=!1;for(;;)switch(o){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return dn(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return Ii(h).length;default:if(g)return l?-1:dn(h).length;o=(""+o).toLowerCase(),g=!0}}f.byteLength=I;function C(h,o,u){let l=!1;if((o===void 0||o<0)&&(o=0),o>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,o>>>=0,u<=o))return"";for(h||(h="utf8");;)switch(h){case"hex":return Cs(this,o,u);case"utf8":case"utf-8":return ye(this,o,u);case"ascii":return pn(this,o,u);case"latin1":case"binary":return Ns(this,o,u);case"base64":return ne(this,o,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Hs(this,o,u);default:if(l)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),l=!0}}f.prototype._isBuffer=!0;function M(h,o,u){const l=h[o];h[o]=h[u],h[u]=l}f.prototype.swap16=function(){const o=this.length;if(o%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<o;u+=2)M(this,u,u+1);return this},f.prototype.swap32=function(){const o=this.length;if(o%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<o;u+=4)M(this,u,u+3),M(this,u+1,u+2);return this},f.prototype.swap64=function(){const o=this.length;if(o%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<o;u+=8)M(this,u,u+7),M(this,u+1,u+6),M(this,u+2,u+5),M(this,u+3,u+4);return this},f.prototype.toString=function(){const o=this.length;return o===0?"":arguments.length===0?ye(this,0,o):C.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(o){if(!f.isBuffer(o))throw new TypeError("Argument must be a Buffer");return this===o?!0:f.compare(this,o)===0},f.prototype.inspect=function(){let o="";const u=e.INSPECT_MAX_BYTES;return o=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(o+=" ... "),"<Buffer "+o+">"},n&&(f.prototype[n]=f.prototype.inspect),f.prototype.compare=function(o,u,l,g,b){if(Ue(o,c)&&(o=f.from(o,o.offset,o.byteLength)),!f.isBuffer(o))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof o);if(u===void 0&&(u=0),l===void 0&&(l=o?o.length:0),g===void 0&&(g=0),b===void 0&&(b=this.length),u<0||l>o.length||g<0||b>this.length)throw new RangeError("out of range index");if(g>=b&&u>=l)return 0;if(g>=b)return-1;if(u>=l)return 1;if(u>>>=0,l>>>=0,g>>>=0,b>>>=0,this===o)return 0;let A=b-g,$=l-u;const Q=Math.min(A,$),z=this.slice(g,b),Z=o.slice(u,l);for(let V=0;V<Q;++V)if(z[V]!==Z[V]){A=z[V],$=Z[V];break}return A<$?-1:$<A?1:0};function B(h,o,u,l,g){if(h.length===0)return-1;if(typeof u=="string"?(l=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,yn(u)&&(u=g?0:h.length-1),u<0&&(u=h.length+u),u>=h.length){if(g)return-1;u=h.length-1}else if(u<0)if(g)u=0;else return-1;if(typeof o=="string"&&(o=f.from(o,l)),f.isBuffer(o))return o.length===0?-1:R(h,o,u,l,g);if(typeof o=="number")return o=o&255,typeof c.prototype.indexOf=="function"?g?c.prototype.indexOf.call(h,o,u):c.prototype.lastIndexOf.call(h,o,u):R(h,[o],u,l,g);throw new TypeError("val must be string, number or Buffer")}function R(h,o,u,l,g){let b=1,A=h.length,$=o.length;if(l!==void 0&&(l=String(l).toLowerCase(),l==="ucs2"||l==="ucs-2"||l==="utf16le"||l==="utf-16le")){if(h.length<2||o.length<2)return-1;b=2,A/=2,$/=2,u/=2}function Q(Z,V){return b===1?Z[V]:Z.readUInt16BE(V*b)}let z;if(g){let Z=-1;for(z=u;z<A;z++)if(Q(h,z)===Q(o,Z===-1?0:z-Z)){if(Z===-1&&(Z=z),z-Z+1===$)return Z*b}else Z!==-1&&(z-=z-Z),Z=-1}else for(u+$>A&&(u=A-$),z=u;z>=0;z--){let Z=!0;for(let V=0;V<$;V++)if(Q(h,z+V)!==Q(o,V)){Z=!1;break}if(Z)return z}return-1}f.prototype.includes=function(o,u,l){return this.indexOf(o,u,l)!==-1},f.prototype.indexOf=function(o,u,l){return B(this,o,u,l,!0)},f.prototype.lastIndexOf=function(o,u,l){return B(this,o,u,l,!1)};function j(h,o,u,l){u=Number(u)||0;const g=h.length-u;l?(l=Number(l),l>g&&(l=g)):l=g;const b=o.length;l>b/2&&(l=b/2);let A;for(A=0;A<l;++A){const $=parseInt(o.substr(A*2,2),16);if(yn($))return A;h[u+A]=$}return A}function O(h,o,u,l){return _r(dn(o,h.length-u),h,u,l)}function U(h,o,u,l){return _r($s(o),h,u,l)}function F(h,o,u,l){return _r(Ii(o),h,u,l)}function D(h,o,u,l){return _r(Ms(o,h.length-u),h,u,l)}f.prototype.write=function(o,u,l,g){if(u===void 0)g="utf8",l=this.length,u=0;else if(l===void 0&&typeof u=="string")g=u,l=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(l)?(l=l>>>0,g===void 0&&(g="utf8")):(g=l,l=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const b=this.length-u;if((l===void 0||l>b)&&(l=b),o.length>0&&(l<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");g||(g="utf8");let A=!1;for(;;)switch(g){case"hex":return j(this,o,u,l);case"utf8":case"utf-8":return O(this,o,u,l);case"ascii":case"latin1":case"binary":return U(this,o,u,l);case"base64":return F(this,o,u,l);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,o,u,l);default:if(A)throw new TypeError("Unknown encoding: "+g);g=(""+g).toLowerCase(),A=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ne(h,o,u){return o===0&&u===h.length?t.fromByteArray(h):t.fromByteArray(h.slice(o,u))}function ye(h,o,u){u=Math.min(h.length,u);const l=[];let g=o;for(;g<u;){const b=h[g];let A=null,$=b>239?4:b>223?3:b>191?2:1;if(g+$<=u){let Q,z,Z,V;switch($){case 1:b<128&&(A=b);break;case 2:Q=h[g+1],(Q&192)===128&&(V=(b&31)<<6|Q&63,V>127&&(A=V));break;case 3:Q=h[g+1],z=h[g+2],(Q&192)===128&&(z&192)===128&&(V=(b&15)<<12|(Q&63)<<6|z&63,V>2047&&(V<55296||V>57343)&&(A=V));break;case 4:Q=h[g+1],z=h[g+2],Z=h[g+3],(Q&192)===128&&(z&192)===128&&(Z&192)===128&&(V=(b&15)<<18|(Q&63)<<12|(z&63)<<6|Z&63,V>65535&&V<1114112&&(A=V))}}A===null?(A=65533,$=1):A>65535&&(A-=65536,l.push(A>>>10&1023|55296),A=56320|A&1023),l.push(A),g+=$}return br(l)}const Jt=4096;function br(h){const o=h.length;if(o<=Jt)return String.fromCharCode.apply(String,h);let u="",l=0;for(;l<o;)u+=String.fromCharCode.apply(String,h.slice(l,l+=Jt));return u}function pn(h,o,u){let l="";u=Math.min(h.length,u);for(let g=o;g<u;++g)l+=String.fromCharCode(h[g]&127);return l}function Ns(h,o,u){let l="";u=Math.min(h.length,u);for(let g=o;g<u;++g)l+=String.fromCharCode(h[g]);return l}function Cs(h,o,u){const l=h.length;(!o||o<0)&&(o=0),(!u||u<0||u>l)&&(u=l);let g="";for(let b=o;b<u;++b)g+=Ks[h[b]];return g}function Hs(h,o,u){const l=h.slice(o,u);let g="";for(let b=0;b<l.length-1;b+=2)g+=String.fromCharCode(l[b]+l[b+1]*256);return g}f.prototype.slice=function(o,u){const l=this.length;o=~~o,u=u===void 0?l:~~u,o<0?(o+=l,o<0&&(o=0)):o>l&&(o=l),u<0?(u+=l,u<0&&(u=0)):u>l&&(u=l),u<o&&(u=o);const g=this.subarray(o,u);return Object.setPrototypeOf(g,f.prototype),g};function ce(h,o,u){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+o>u)throw new RangeError("Trying to access beyond buffer length")}f.prototype.readUintLE=f.prototype.readUIntLE=function(o,u,l){o=o>>>0,u=u>>>0,l||ce(o,u,this.length);let g=this[o],b=1,A=0;for(;++A<u&&(b*=256);)g+=this[o+A]*b;return g},f.prototype.readUintBE=f.prototype.readUIntBE=function(o,u,l){o=o>>>0,u=u>>>0,l||ce(o,u,this.length);let g=this[o+--u],b=1;for(;u>0&&(b*=256);)g+=this[o+--u]*b;return g},f.prototype.readUint8=f.prototype.readUInt8=function(o,u){return o=o>>>0,u||ce(o,1,this.length),this[o]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(o,u){return o=o>>>0,u||ce(o,2,this.length),this[o]|this[o+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(o,u){return o=o>>>0,u||ce(o,2,this.length),this[o]<<8|this[o+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(o,u){return o=o>>>0,u||ce(o,4,this.length),(this[o]|this[o+1]<<8|this[o+2]<<16)+this[o+3]*16777216},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(o,u){return o=o>>>0,u||ce(o,4,this.length),this[o]*16777216+(this[o+1]<<16|this[o+2]<<8|this[o+3])},f.prototype.readBigUInt64LE=Ze(function(o){o=o>>>0,Ft(o,"offset");const u=this[o],l=this[o+7];(u===void 0||l===void 0)&&Qt(o,this.length-8);const g=u+this[++o]*2**8+this[++o]*2**16+this[++o]*2**24,b=this[++o]+this[++o]*2**8+this[++o]*2**16+l*2**24;return BigInt(g)+(BigInt(b)<<BigInt(32))}),f.prototype.readBigUInt64BE=Ze(function(o){o=o>>>0,Ft(o,"offset");const u=this[o],l=this[o+7];(u===void 0||l===void 0)&&Qt(o,this.length-8);const g=u*2**24+this[++o]*2**16+this[++o]*2**8+this[++o],b=this[++o]*2**24+this[++o]*2**16+this[++o]*2**8+l;return(BigInt(g)<<BigInt(32))+BigInt(b)}),f.prototype.readIntLE=function(o,u,l){o=o>>>0,u=u>>>0,l||ce(o,u,this.length);let g=this[o],b=1,A=0;for(;++A<u&&(b*=256);)g+=this[o+A]*b;return b*=128,g>=b&&(g-=Math.pow(2,8*u)),g},f.prototype.readIntBE=function(o,u,l){o=o>>>0,u=u>>>0,l||ce(o,u,this.length);let g=u,b=1,A=this[o+--g];for(;g>0&&(b*=256);)A+=this[o+--g]*b;return b*=128,A>=b&&(A-=Math.pow(2,8*u)),A},f.prototype.readInt8=function(o,u){return o=o>>>0,u||ce(o,1,this.length),this[o]&128?(255-this[o]+1)*-1:this[o]},f.prototype.readInt16LE=function(o,u){o=o>>>0,u||ce(o,2,this.length);const l=this[o]|this[o+1]<<8;return l&32768?l|4294901760:l},f.prototype.readInt16BE=function(o,u){o=o>>>0,u||ce(o,2,this.length);const l=this[o+1]|this[o]<<8;return l&32768?l|4294901760:l},f.prototype.readInt32LE=function(o,u){return o=o>>>0,u||ce(o,4,this.length),this[o]|this[o+1]<<8|this[o+2]<<16|this[o+3]<<24},f.prototype.readInt32BE=function(o,u){return o=o>>>0,u||ce(o,4,this.length),this[o]<<24|this[o+1]<<16|this[o+2]<<8|this[o+3]},f.prototype.readBigInt64LE=Ze(function(o){o=o>>>0,Ft(o,"offset");const u=this[o],l=this[o+7];(u===void 0||l===void 0)&&Qt(o,this.length-8);const g=this[o+4]+this[o+5]*2**8+this[o+6]*2**16+(l<<24);return(BigInt(g)<<BigInt(32))+BigInt(u+this[++o]*2**8+this[++o]*2**16+this[++o]*2**24)}),f.prototype.readBigInt64BE=Ze(function(o){o=o>>>0,Ft(o,"offset");const u=this[o],l=this[o+7];(u===void 0||l===void 0)&&Qt(o,this.length-8);const g=(u<<24)+this[++o]*2**16+this[++o]*2**8+this[++o];return(BigInt(g)<<BigInt(32))+BigInt(this[++o]*2**24+this[++o]*2**16+this[++o]*2**8+l)}),f.prototype.readFloatLE=function(o,u){return o=o>>>0,u||ce(o,4,this.length),r.read(this,o,!0,23,4)},f.prototype.readFloatBE=function(o,u){return o=o>>>0,u||ce(o,4,this.length),r.read(this,o,!1,23,4)},f.prototype.readDoubleLE=function(o,u){return o=o>>>0,u||ce(o,8,this.length),r.read(this,o,!0,52,8)},f.prototype.readDoubleBE=function(o,u){return o=o>>>0,u||ce(o,8,this.length),r.read(this,o,!1,52,8)};function Te(h,o,u,l,g,b){if(!f.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(o>g||o<b)throw new RangeError('"value" argument is out of bounds');if(u+l>h.length)throw new RangeError("Index out of range")}f.prototype.writeUintLE=f.prototype.writeUIntLE=function(o,u,l,g){if(o=+o,u=u>>>0,l=l>>>0,!g){const $=Math.pow(2,8*l)-1;Te(this,o,u,l,$,0)}let b=1,A=0;for(this[u]=o&255;++A<l&&(b*=256);)this[u+A]=o/b&255;return u+l},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(o,u,l,g){if(o=+o,u=u>>>0,l=l>>>0,!g){const $=Math.pow(2,8*l)-1;Te(this,o,u,l,$,0)}let b=l-1,A=1;for(this[u+b]=o&255;--b>=0&&(A*=256);)this[u+b]=o/A&255;return u+l},f.prototype.writeUint8=f.prototype.writeUInt8=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,1,255,0),this[u]=o&255,u+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,2,65535,0),this[u]=o&255,this[u+1]=o>>>8,u+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,2,65535,0),this[u]=o>>>8,this[u+1]=o&255,u+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,4,4294967295,0),this[u+3]=o>>>24,this[u+2]=o>>>16,this[u+1]=o>>>8,this[u]=o&255,u+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,4,4294967295,0),this[u]=o>>>24,this[u+1]=o>>>16,this[u+2]=o>>>8,this[u+3]=o&255,u+4};function gi(h,o,u,l,g){Ti(o,l,g,h,u,7);let b=Number(o&BigInt(4294967295));h[u++]=b,b=b>>8,h[u++]=b,b=b>>8,h[u++]=b,b=b>>8,h[u++]=b;let A=Number(o>>BigInt(32)&BigInt(4294967295));return h[u++]=A,A=A>>8,h[u++]=A,A=A>>8,h[u++]=A,A=A>>8,h[u++]=A,u}function Ei(h,o,u,l,g){Ti(o,l,g,h,u,7);let b=Number(o&BigInt(4294967295));h[u+7]=b,b=b>>8,h[u+6]=b,b=b>>8,h[u+5]=b,b=b>>8,h[u+4]=b;let A=Number(o>>BigInt(32)&BigInt(4294967295));return h[u+3]=A,A=A>>8,h[u+2]=A,A=A>>8,h[u+1]=A,A=A>>8,h[u]=A,u+8}f.prototype.writeBigUInt64LE=Ze(function(o,u=0){return gi(this,o,u,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeBigUInt64BE=Ze(function(o,u=0){return Ei(this,o,u,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeIntLE=function(o,u,l,g){if(o=+o,u=u>>>0,!g){const Q=Math.pow(2,8*l-1);Te(this,o,u,l,Q-1,-Q)}let b=0,A=1,$=0;for(this[u]=o&255;++b<l&&(A*=256);)o<0&&$===0&&this[u+b-1]!==0&&($=1),this[u+b]=(o/A>>0)-$&255;return u+l},f.prototype.writeIntBE=function(o,u,l,g){if(o=+o,u=u>>>0,!g){const Q=Math.pow(2,8*l-1);Te(this,o,u,l,Q-1,-Q)}let b=l-1,A=1,$=0;for(this[u+b]=o&255;--b>=0&&(A*=256);)o<0&&$===0&&this[u+b+1]!==0&&($=1),this[u+b]=(o/A>>0)-$&255;return u+l},f.prototype.writeInt8=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,1,127,-128),o<0&&(o=255+o+1),this[u]=o&255,u+1},f.prototype.writeInt16LE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,2,32767,-32768),this[u]=o&255,this[u+1]=o>>>8,u+2},f.prototype.writeInt16BE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,2,32767,-32768),this[u]=o>>>8,this[u+1]=o&255,u+2},f.prototype.writeInt32LE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,4,2147483647,-2147483648),this[u]=o&255,this[u+1]=o>>>8,this[u+2]=o>>>16,this[u+3]=o>>>24,u+4},f.prototype.writeInt32BE=function(o,u,l){return o=+o,u=u>>>0,l||Te(this,o,u,4,2147483647,-2147483648),o<0&&(o=4294967295+o+1),this[u]=o>>>24,this[u+1]=o>>>16,this[u+2]=o>>>8,this[u+3]=o&255,u+4},f.prototype.writeBigInt64LE=Ze(function(o,u=0){return gi(this,o,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeBigInt64BE=Ze(function(o,u=0){return Ei(this,o,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function mi(h,o,u,l,g,b){if(u+l>h.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function Si(h,o,u,l,g){return o=+o,u=u>>>0,g||mi(h,o,u,4),r.write(h,o,u,l,23,4),u+4}f.prototype.writeFloatLE=function(o,u,l){return Si(this,o,u,!0,l)},f.prototype.writeFloatBE=function(o,u,l){return Si(this,o,u,!1,l)};function bi(h,o,u,l,g){return o=+o,u=u>>>0,g||mi(h,o,u,8),r.write(h,o,u,l,52,8),u+8}f.prototype.writeDoubleLE=function(o,u,l){return bi(this,o,u,!0,l)},f.prototype.writeDoubleBE=function(o,u,l){return bi(this,o,u,!1,l)},f.prototype.copy=function(o,u,l,g){if(!f.isBuffer(o))throw new TypeError("argument should be a Buffer");if(l||(l=0),!g&&g!==0&&(g=this.length),u>=o.length&&(u=o.length),u||(u=0),g>0&&g<l&&(g=l),g===l||o.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(l<0||l>=this.length)throw new RangeError("Index out of range");if(g<0)throw new RangeError("sourceEnd out of bounds");g>this.length&&(g=this.length),o.length-u<g-l&&(g=o.length-u+l);const b=g-l;return this===o&&typeof c.prototype.copyWithin=="function"?this.copyWithin(u,l,g):c.prototype.set.call(o,this.subarray(l,g),u),b},f.prototype.fill=function(o,u,l,g){if(typeof o=="string"){if(typeof u=="string"?(g=u,u=0,l=this.length):typeof l=="string"&&(g=l,l=this.length),g!==void 0&&typeof g!="string")throw new TypeError("encoding must be a string");if(typeof g=="string"&&!f.isEncoding(g))throw new TypeError("Unknown encoding: "+g);if(o.length===1){const A=o.charCodeAt(0);(g==="utf8"&&A<128||g==="latin1")&&(o=A)}}else typeof o=="number"?o=o&255:typeof o=="boolean"&&(o=Number(o));if(u<0||this.length<u||this.length<l)throw new RangeError("Out of range index");if(l<=u)return this;u=u>>>0,l=l===void 0?this.length:l>>>0,o||(o=0);let b;if(typeof o=="number")for(b=u;b<l;++b)this[b]=o;else{const A=f.isBuffer(o)?o:f.from(o,g),$=A.length;if($===0)throw new TypeError('The value "'+o+'" is invalid for argument "value"');for(b=0;b<l-u;++b)this[b+u]=A[b%$]}return this};const Rt={};function ln(h,o,u){Rt[h]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:o.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(g){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:g,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}ln("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ln("ERR_INVALID_ARG_TYPE",function(h,o){return`The "${h}" argument must be of type number. Received type ${typeof o}`},TypeError),ln("ERR_OUT_OF_RANGE",function(h,o,u){let l=`The value of "${h}" is out of range.`,g=u;return Number.isInteger(u)&&Math.abs(u)>2**32?g=_i(String(u)):typeof u=="bigint"&&(g=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(g=_i(g)),g+="n"),l+=` It must be ${o}. Received ${g}`,l},RangeError);function _i(h){let o="",u=h.length;const l=h[0]==="-"?1:0;for(;u>=l+4;u-=3)o=`_${h.slice(u-3,u)}${o}`;return`${h.slice(0,u)}${o}`}function Rs(h,o,u){Ft(o,"offset"),(h[o]===void 0||h[o+u]===void 0)&&Qt(o,h.length-(u+1))}function Ti(h,o,u,l,g,b){if(h>u||h<o){const A=typeof o=="bigint"?"n":"";let $;throw o===0||o===BigInt(0)?$=`>= 0${A} and < 2${A} ** ${(b+1)*8}${A}`:$=`>= -(2${A} ** ${(b+1)*8-1}${A}) and < 2 ** ${(b+1)*8-1}${A}`,new Rt.ERR_OUT_OF_RANGE("value",$,h)}Rs(l,g,b)}function Ft(h,o){if(typeof h!="number")throw new Rt.ERR_INVALID_ARG_TYPE(o,"number",h)}function Qt(h,o,u){throw Math.floor(h)!==h?(Ft(h,u),new Rt.ERR_OUT_OF_RANGE("offset","an integer",h)):o<0?new Rt.ERR_BUFFER_OUT_OF_BOUNDS:new Rt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${o}`,h)}const Fs=/[^+/0-9A-Za-z-_]/g;function Ls(h){if(h=h.split("=")[0],h=h.trim().replace(Fs,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function dn(h,o){o=o||1/0;let u;const l=h.length;let g=null;const b=[];for(let A=0;A<l;++A){if(u=h.charCodeAt(A),u>55295&&u<57344){if(!g){if(u>56319){(o-=3)>-1&&b.push(239,191,189);continue}else if(A+1===l){(o-=3)>-1&&b.push(239,191,189);continue}g=u;continue}if(u<56320){(o-=3)>-1&&b.push(239,191,189),g=u;continue}u=(g-55296<<10|u-56320)+65536}else g&&(o-=3)>-1&&b.push(239,191,189);if(g=null,u<128){if((o-=1)<0)break;b.push(u)}else if(u<2048){if((o-=2)<0)break;b.push(u>>6|192,u&63|128)}else if(u<65536){if((o-=3)<0)break;b.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((o-=4)<0)break;b.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return b}function $s(h){const o=[];for(let u=0;u<h.length;++u)o.push(h.charCodeAt(u)&255);return o}function Ms(h,o){let u,l,g;const b=[];for(let A=0;A<h.length&&!((o-=2)<0);++A)u=h.charCodeAt(A),l=u>>8,g=u%256,b.push(g),b.push(l);return b}function Ii(h){return t.toByteArray(Ls(h))}function _r(h,o,u,l){let g;for(g=0;g<l&&!(g+u>=o.length||g>=h.length);++g)o[g+u]=h[g];return g}function Ue(h,o){return h instanceof o||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===o.name}function yn(h){return h!==h}const Ks=function(){const h="0123456789abcdef",o=new Array(256);for(let u=0;u<16;++u){const l=u*16;for(let g=0;g<16;++g)o[l+g]=h[u]+h[g]}return o}();function Ze(h){return typeof BigInt>"u"?Ds:h}function Ds(){throw new Error("BigInt not supported")}})(se);const E=se.Buffer,ec=se.Blob,tc=se.BlobOptions,wo=se.Buffer,rc=se.File,nc=se.FileOptions,ic=se.INSPECT_MAX_BYTES,oc=se.SlowBuffer,sc=se.TranscodeEncoding,cc=se.atob,uc=se.btoa,ac=se.constants,fc=se.isAscii,hc=se.isUtf8,pc=se.kMaxLength,lc=se.kStringMaxLength,dc=se.resolveObjectURL,yc=se.transcode,wc=Object.freeze(Object.defineProperty({__proto__:null,Blob:ec,BlobOptions:tc,Buffer:wo,File:rc,FileOptions:nc,INSPECT_MAX_BYTES:ic,SlowBuffer:oc,TranscodeEncoding:sc,atob:cc,btoa:uc,constants:ac,default:E,isAscii:fc,isUtf8:hc,kMaxLength:pc,kStringMaxLength:lc,resolveObjectURL:dc,transcode:yc},Symbol.toStringTag,{value:"Module"}));var ge={},ae={};Object.defineProperty(ae,"__esModule",{value:!0});ae.testnet=ae.regtest=ae.bitcoin=void 0;ae.bitcoin={messagePrefix:`Bitcoin Signed Message:
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};ae.regtest={messagePrefix:`Bitcoin Signed Message:
`,bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};ae.testnet={messagePrefix:`Bitcoin Signed Message:
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var gn={},Gr={},En={},ze={};Object.defineProperty(ze,"__esModule",{value:!0});ze.encode=ze.decode=ze.check=void 0;function gc(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))}ze.check=gc;function Ec(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)}}ze.decode=Ec;function mc(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=E.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}ze.encode=mc;var ft={};Object.defineProperty(ft,"__esModule",{value:!0});ft.REVERSE_OPS=ft.OPS=void 0;const Fn={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};ft.OPS=Fn;const go={};ft.REVERSE_OPS=go;for(const e of Object.keys(Fn)){const t=Fn[e];go[t]=e}var ut={};Object.defineProperty(ut,"__esModule",{value:!0});ut.decode=ut.encode=ut.encodingLength=void 0;const ct=ft;function Eo(e){return e<ct.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}ut.encodingLength=Eo;function Sc(e,t,r){const n=Eo(t);return n===1?e.writeUInt8(t,r):n===2?(e.writeUInt8(ct.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):n===3?(e.writeUInt8(ct.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(ct.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),n}ut.encode=Sc;function bc(e,t){const r=e.readUInt8(t);let n,i;if(r<ct.OPS.OP_PUSHDATA1)n=r,i=1;else if(r===ct.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;n=e.readUInt8(t+1),i=2}else if(r===ct.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!==ct.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=e.readUInt32LE(t+1),i=5}return{opcode:r,number:n,size:i}}ut.decode=bc;var zt={};Object.defineProperty(zt,"__esModule",{value:!0});zt.encode=zt.decode=void 0;function _c(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 c=e.readUInt32LE(0),s=e.readUInt8(4);return s&128?-((s&-129)*4294967296+c):s*4294967296+c}let i=0;for(let c=0;c<n;++c)i|=e[c]<<8*c;return e[n-1]&128?-(i&~(128<<8*(n-1))):i}zt.decode=_c;function Tc(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function Ic(e){let t=Math.abs(e);const r=Tc(t),n=E.allocUnsafe(r),i=e<0;for(let c=0;c<r;++c)n.writeUInt8(t&255,c),t>>=8;return n[r-1]&128?n.writeUInt8(i?128:0,r-1):i&&(n[r-1]|=128),n}zt.encode=Ic;var dt={},de={};const Xr=Vs(wc);var yr={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}};yr.Null=yr.Nil;for(var ki in yr)yr[ki].toJSON=(function(e){return e}).bind(null,ki);var Gn=yr,gt=Gn;function mo(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function Xn(e){return gt.Nil(e)?"":mo(e.constructor)}function kc(e){return gt.Function(e)?"":gt.String(e)?JSON.stringify(e):e&>.Object(e)?"":e}function qn(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Fr(e){return gt.Function(e)?e.toJSON?e.toJSON():mo(e):gt.Array(e)?"Array":e&>.Object(e)?"Object":e!==void 0?e:""}function So(e,t,r){var n=kc(t);return"Expected "+Fr(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function Je(e,t,r){r=r||Xn(t),this.message=So(e,t,r),qn(this,Je),this.__type=e,this.__value=t,this.__valueTypeName=r}Je.prototype=Object.create(Error.prototype);Je.prototype.constructor=Je;function Ac(e,t,r,n,i){var c='" of type ';return t==="key"&&(c='" with key type '),So('property "'+Fr(r)+c+Fr(e),n,i)}function Gt(e,t,r,n,i){e?(i=i||Xn(n),this.message=Ac(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',qn(this,Je),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}Gt.prototype=Object.create(Error.prototype);Gt.prototype.constructor=Je;function Oc(e,t){return new Je(e,{},t)}function Pc(e,t,r){return e instanceof Gt?(t=t+"."+e.__property,e=new Gt(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof Je&&(e=new Gt(e.__type,t,r,e.__value,e.__valueTypeName)),qn(e),e}var bo={TfTypeError:Je,TfPropertyTypeError:Gt,tfCustomError:Oc,tfSubError:Pc,tfJSON:Fr,getValueTypeName:Xn},mn,Ai;function vc(){if(Ai)return mn;Ai=1;var e=Gn,t=bo;function r(I){return E.isBuffer(I)}function n(I){return typeof I=="string"&&/^([0-9a-f]{2})+$/i.test(I)}function i(I,C){var M=I.toJSON();function B(R){if(!I(R))return!1;if(R.length===C)return!0;throw t.tfCustomError(M+"(Length: "+C+")",M+"(Length: "+R.length+")")}return B.toJSON=function(){return M},B}var c=i.bind(null,e.Array),s=i.bind(null,r),a=i.bind(null,n),p=i.bind(null,e.String);function w(I,C,M){M=M||e.Number;function B(R,j){return M(R,j)&&R>I&&R<C}return B.toJSON=function(){return`${M.toJSON()} between [${I}, ${C}]`},B}var f=Math.pow(2,53)-1;function d(I){return typeof I=="number"&&isFinite(I)}function S(I){return I<<24>>24===I}function y(I){return I<<16>>16===I}function _(I){return(I|0)===I}function T(I){return typeof I=="number"&&I>=-f&&I<=f&&Math.floor(I)===I}function P(I){return(I&255)===I}function x(I){return(I&65535)===I}function N(I){return I>>>0===I}function k(I){return typeof I=="number"&&I>=0&&I<=f&&Math.floor(I)===I}var m={ArrayN:c,Buffer:r,BufferN:s,Finite:d,Hex:n,HexN:a,Int8:S,Int16:y,Int32:_,Int53:T,Range:w,StringN:p,UInt8:P,UInt16:x,UInt32:N,UInt53:k};for(var v in m)m[v].toJSON=(function(I){return I}).bind(null,v);return mn=m,mn}var gr=bo,le=Gn,We=gr.tfJSON,_o=gr.TfTypeError,To=gr.TfPropertyTypeError,er=gr.tfSubError,Bc=gr.getValueTypeName,qe={arrayOf:function(t,r){t=Le(t),r=r||{};function n(i,c){return!le.Array(i)||le.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(s,a){try{return be(t,s,c)}catch(p){throw er(p,a)}})}return n.toJSON=function(){var i="["+We(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=Le(t);function r(n,i){return le.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+We(t)},r},map:function(t,r){t=Le(t),r&&(r=Le(r));function n(i,c){if(!le.Object(i)||le.Nil(i))return!1;for(var s in i){try{r&&be(r,s,c)}catch(p){throw er(p,s,"key")}try{var a=i[s];be(t,a,c)}catch(p){throw er(p,s)}}return!0}return r?n.toJSON=function(){return"{"+We(r)+": "+We(t)+"}"}:n.toJSON=function(){return"{"+We(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Le(t[n]);function i(c,s){if(!le.Object(c)||le.Nil(c))return!1;var a;try{for(a in r){var p=r[a],w=c[a];be(p,w,s)}}catch(f){throw er(f,a)}if(s){for(a in c)if(!r[a])throw new To(void 0,a)}return!0}return i.toJSON=function(){return We(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Le);function r(n,i){return t.some(function(c){try{return be(c,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(We).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Le);function r(n,i){return t.every(function(c){try{return be(c,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(We).join(" & ")},r},quacksLike:function(t){function r(n){return t===Bc(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Le);function r(n,i){return le.Nil(n)||le.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(c,s){try{return be(c,n[s],i)}catch(a){throw er(a,s)}})}return r.toJSON=function(){return"("+t.map(We).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};qe.oneOf=qe.anyOf;function Le(e){if(le.String(e))return e[0]==="?"?qe.maybe(e.slice(1)):le[e]||qe.quacksLike(e);if(e&&le.Object(e)){if(le.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return qe.arrayOf(e[0])}return qe.object(e)}else if(le.Function(e))return e;return qe.value(e)}function be(e,t,r,n){if(le.Function(e)){if(e(t,r))return!0;throw new _o(n||e,t)}return be(Le(e),t,r)}for(var at in le)be[at]=le[at];for(at in qe)be[at]=qe[at];var Oi=vc();for(at in Oi)be[at]=Oi[at];be.compile=Le;be.TfTypeError=_o;be.TfPropertyTypeError=To;var xc=be;(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=Xr;e.typeforce=xc;const r=t.Buffer.alloc(32,0),n=t.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function i(f,d){return f.length!==d.length?!1:f.every((S,y)=>S.equals(d[y]))}e.stacksEqual=i;function c(f){if(!t.Buffer.isBuffer(f)||f.length<33)return!1;const d=f[0],S=f.slice(1,33);if(S.compare(r)===0||S.compare(n)>=0)return!1;if((d===2||d===3)&&f.length===33)return!0;const y=f.slice(33);return y.compare(r)===0||y.compare(n)>=0?!1:d===4&&f.length===65}e.isPoint=c;const s=21*1e14;function a(f){return e.typeforce.UInt53(f)&&f<=s}e.Satoshi=a,e.TAPLEAF_VERSION_MASK=254;function p(f){return!f||!("output"in f)||!t.Buffer.isBuffer(f.output)?!1:f.version!==void 0?(f.version&e.TAPLEAF_VERSION_MASK)===f.version:!0}e.isTapleaf=p;function w(f){return(0,e.Array)(f)?f.length!==2?!1:f.every(d=>w(d)):p(f)}e.isTaptree=w,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})(de);var Pi;function Uc(){if(Pi)return dt;Pi=1,Object.defineProperty(dt,"__esModule",{value:!0}),dt.encode=dt.decode=void 0;const e=ze,t=_e(),r=de,{typeforce:n}=r,i=E.alloc(1,0);function c(w){let f=0;for(;w[f]===0;)++f;return f===w.length?i:(w=w.slice(f),w[0]&128?E.concat([i,w],1+w.length):w)}function s(w){w[0]===0&&(w=w.slice(1));const f=E.alloc(32,0),d=Math.max(0,32-w.length);return w.copy(f,d),f}function a(w){const f=w.readUInt8(w.length-1);if(!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const d=e.decode(w.slice(0,-1)),S=s(d.r),y=s(d.s);return{signature:E.concat([S,y],64),hashType:f}}dt.decode=a;function p(w,f){if(n({signature:r.BufferN(64),hashType:r.UInt8},{signature:w,hashType:f}),!(0,t.isDefinedHashType)(f))throw new Error("Invalid hashType "+f);const d=E.allocUnsafe(1);d.writeUInt8(f,0);const S=c(w.slice(0,32)),y=c(w.slice(32,64));return E.concat([e.encode(S,y),d])}return dt.encode=p,dt}var vi;function _e(){return vi||(vi=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=ze,r=ft;Object.defineProperty(e,"OPS",{enumerable:!0,get:function(){return r.OPS}});const n=ut,i=zt,c=Uc(),s=de,{typeforce:a}=s,p=r.OPS.OP_RESERVED;function w(B){return s.Number(B)&&(B===r.OPS.OP_0||B>=r.OPS.OP_1&&B<=r.OPS.OP_16||B===r.OPS.OP_1NEGATE)}function f(B){return s.Buffer(B)||w(B)}function d(B){return s.Array(B)&&B.every(f)}e.isPushOnly=d;function S(B){return B.length-B.filter(f).length}e.countNonPushOnlyOPs=S;function y(B){if(B.length===0)return r.OPS.OP_0;if(B.length===1){if(B[0]>=1&&B[0]<=16)return p+B[0];if(B[0]===129)return r.OPS.OP_1NEGATE}}function _(B){return E.isBuffer(B)}function T(B){return s.Array(B)}function P(B){return E.isBuffer(B)}function x(B){if(_(B))return B;a(s.Array,B);const R=B.reduce((U,F)=>P(F)?F.length===1&&y(F)!==void 0?U+1:U+n.encodingLength(F.length)+F.length:U+1,0),j=E.allocUnsafe(R);let O=0;if(B.forEach(U=>{if(P(U)){const F=y(U);if(F!==void 0){j.writeUInt8(F,O),O+=1;return}O+=n.encode(j,U.length,O),U.copy(j,O),O+=U.length}else j.writeUInt8(U,O),O+=1}),O!==j.length)throw new Error("Could not decode chunks");return j}e.compile=x;function N(B){if(T(B))return B;a(s.Buffer,B);const R=[];let j=0;for(;j<B.length;){const O=B[j];if(O>r.OPS.OP_0&&O<=r.OPS.OP_PUSHDATA4){const U=n.decode(B,j);if(U===null||(j+=U.size,j+U.number>B.length))return null;const F=B.slice(j,j+U.number);j+=U.number;const D=y(F);D!==void 0?R.push(D):R.push(F)}else R.push(O),j+=1}return R}e.decompile=N;function k(B){if(_(B)&&(B=N(B)),!B)throw new Error("Could not convert invalid chunks to ASM");return B.map(R=>{if(P(R)){const j=y(R);if(j===void 0)return R.toString("hex");R=j}return r.REVERSE_OPS[R]}).join(" ")}e.toASM=k;function m(B){return a(s.String,B),x(B.split(" ").map(R=>r.OPS[R]!==void 0?r.OPS[R]:(a(s.Hex,R),E.from(R,"hex"))))}e.fromASM=m;function v(B){return B=N(B),a(d,B),B.map(R=>P(R)?R:R===r.OPS.OP_0?E.allocUnsafe(0):i.encode(R-p))}e.toStack=v;function I(B){return s.isPoint(B)}e.isCanonicalPubKey=I;function C(B){const R=B&-129;return R>0&&R<4}e.isDefinedHashType=C;function M(B){return!E.isBuffer(B)||!C(B[B.length-1])?!1:t.check(B.slice(0,-1))}e.isCanonicalScriptSignature=M,e.number=i,e.signature=c}(En)),En}var ke={};Object.defineProperty(ke,"__esModule",{value:!0});ke.value=ke.prop=void 0;function Nc(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=Nc;function Cc(e){let t;return()=>(t!==void 0||(t=e()),t)}ke.value=Cc;Object.defineProperty(Gr,"__esModule",{value:!0});Gr.p2data=void 0;const Hc=ae,Ur=_e(),Ne=de,Bi=ke,xi=Ur.OPS;function Rc(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,Ne.typeforce)({network:Ne.typeforce.maybe(Ne.typeforce.Object),output:Ne.typeforce.maybe(Ne.typeforce.Buffer),data:Ne.typeforce.maybe(Ne.typeforce.arrayOf(Ne.typeforce.Buffer))},e);const n={name:"embed",network:e.network||Hc.bitcoin};if(Bi.prop(n,"output",()=>{if(e.data)return Ur.compile([xi.OP_RETURN].concat(e.data))}),Bi.prop(n,"data",()=>{if(e.output)return Ur.decompile(e.output).slice(1)}),t.validate&&e.output){const i=Ur.decompile(e.output);if(i[0]!==xi.OP_RETURN)throw new TypeError("Output is invalid");if(!i.slice(1).every(Ne.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,Ne.stacksEqual)(e.data,n.data))throw new TypeError("Data mismatch")}return Object.assign(n,e)}Gr.p2data=Rc;var qr={};Object.defineProperty(qr,"__esModule",{value:!0});qr.p2ms=void 0;const Fc=ae,Dt=_e(),ee=de,et=ke,Wt=Dt.OPS,Tr=Wt.OP_RESERVED;function Lc(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(p){return Dt.isCanonicalScriptSignature(p)||(t.allowIncomplete&&p===Wt.OP_0)!==void 0}(0,ee.typeforce)({network:ee.typeforce.maybe(ee.typeforce.Object),m:ee.typeforce.maybe(ee.typeforce.Number),n:ee.typeforce.maybe(ee.typeforce.Number),output:ee.typeforce.maybe(ee.typeforce.Buffer),pubkeys:ee.typeforce.maybe(ee.typeforce.arrayOf(ee.isPoint)),signatures:ee.typeforce.maybe(ee.typeforce.arrayOf(r)),input:ee.typeforce.maybe(ee.typeforce.Buffer)},e);const i={network:e.network||Fc.bitcoin};let c=[],s=!1;function a(p){s||(s=!0,c=Dt.decompile(p),i.m=c[0]-Tr,i.n=c[c.length-2]-Tr,i.pubkeys=c.slice(1,-2))}if(et.prop(i,"output",()=>{if(e.m&&i.n&&e.pubkeys)return Dt.compile([].concat(Tr+e.m,e.pubkeys,Tr+i.n,Wt.OP_CHECKMULTISIG))}),et.prop(i,"m",()=>{if(i.output)return a(i.output),i.m}),et.prop(i,"n",()=>{if(i.pubkeys)return i.pubkeys.length}),et.prop(i,"pubkeys",()=>{if(e.output)return a(e.output),i.pubkeys}),et.prop(i,"signatures",()=>{if(e.input)return Dt.decompile(e.input).slice(1)}),et.prop(i,"input",()=>{if(e.signatures)return Dt.compile([Wt.OP_0].concat(e.signatures))}),et.prop(i,"witness",()=>{if(i.input)return[]}),et.prop(i,"name",()=>{if(!(!i.m||!i.n))return`p2ms(${i.m} of ${i.n})`}),t.validate){if(e.output){if(a(e.output),!ee.typeforce.Number(c[0]))throw new TypeError("Output is invalid");if(!ee.typeforce.Number(c[c.length-2]))throw new TypeError("Output is invalid");if(c[c.length-1]!==Wt.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(i.m<=0||i.n>16||i.m>i.n||i.n!==c.length-3)throw new TypeError("Output is invalid");if(!i.pubkeys.every(p=>(0,ee.isPoint)(p)))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,ee.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]!==Wt.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,ee.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)}qr.p2ms=Lc;var zr={};Object.defineProperty(zr,"__esModule",{value:!0});zr.p2pk=void 0;const $c=ae,jt=_e(),Be=de,$t=ke,Ui=jt.OPS;function Mc(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,Be.typeforce)({network:Be.typeforce.maybe(Be.typeforce.Object),output:Be.typeforce.maybe(Be.typeforce.Buffer),pubkey:Be.typeforce.maybe(Be.isPoint),signature:Be.typeforce.maybe(jt.isCanonicalScriptSignature),input:Be.typeforce.maybe(Be.typeforce.Buffer)},e);const r=$t.value(()=>jt.decompile(e.input)),i={name:"p2pk",network:e.network||$c.bitcoin};if($t.prop(i,"output",()=>{if(e.pubkey)return jt.compile([e.pubkey,Ui.OP_CHECKSIG])}),$t.prop(i,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),$t.prop(i,"signature",()=>{if(e.input)return r()[0]}),$t.prop(i,"input",()=>{if(e.signature)return jt.compile([e.signature])}),$t.prop(i,"witness",()=>{if(i.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==Ui.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,Be.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(!jt.isCanonicalScriptSignature(i.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(i,e)}zr.p2pk=Mc;var Yr={},Ke={},Yt={},Me={},ue={};Object.defineProperty(ue,"__esModule",{value:!0});ue.output=ue.exists=ue.hash=ue.bytes=ue.bool=ue.number=ue.isBytes=void 0;function Lr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}ue.number=Lr;function Io(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}ue.bool=Io;function ko(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}ue.isBytes=ko;function zn(e,...t){if(!ko(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}`)}ue.bytes=zn;function Ao(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Lr(e.outputLen),Lr(e.blockLen)}ue.hash=Ao;function Oo(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")}ue.exists=Oo;function Po(e,t){zn(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}ue.output=Po;const Kc={number:Lr,bool:Io,bytes:zn,hash:Ao,exists:Oo,output:Po};ue.default=Kc;var Er={},Jr={};Object.defineProperty(Jr,"__esModule",{value:!0});Jr.crypto=void 0;Jr.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.randomBytes=e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.checkOpts=e.Hash=e.concatBytes=e.toBytes=e.utf8ToBytes=e.asyncLoop=e.nextTick=e.hexToBytes=e.bytesToHex=e.byteSwap32=e.byteSwapIfBE=e.byteSwap=e.isLE=e.rotl=e.rotr=e.createView=e.u32=e.u8=e.isBytes=void 0;const t=Jr,r=ue;function n(O){return O instanceof Uint8Array||O!=null&&typeof O=="object"&&O.constructor.name==="Uint8Array"}e.isBytes=n;const i=O=>new Uint8Array(O.buffer,O.byteOffset,O.byteLength);e.u8=i;const c=O=>new Uint32Array(O.buffer,O.byteOffset,Math.floor(O.byteLength/4));e.u32=c;const s=O=>new DataView(O.buffer,O.byteOffset,O.byteLength);e.createView=s;const a=(O,U)=>O<<32-U|O>>>U;e.rotr=a;const p=(O,U)=>O<<U|O>>>32-U>>>0;e.rotl=p,e.isLE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;const w=O=>O<<24&4278190080|O<<8&16711680|O>>>8&65280|O>>>24&255;e.byteSwap=w,e.byteSwapIfBE=e.isLE?O=>O:O=>(0,e.byteSwap)(O);function f(O){for(let U=0;U<O.length;U++)O[U]=(0,e.byteSwap)(O[U])}e.byteSwap32=f;const d=Array.from({length:256},(O,U)=>U.toString(16).padStart(2,"0"));function S(O){(0,r.bytes)(O);let U="";for(let F=0;F<O.length;F++)U+=d[O[F]];return U}e.bytesToHex=S;const y={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function _(O){if(O>=y._0&&O<=y._9)return O-y._0;if(O>=y._A&&O<=y._F)return O-(y._A-10);if(O>=y._a&&O<=y._f)return O-(y._a-10)}function T(O){if(typeof O!="string")throw new Error("hex string expected, got "+typeof O);const U=O.length,F=U/2;if(U%2)throw new Error("padded hex string expected, got unpadded hex of length "+U);const D=new Uint8Array(F);for(let ne=0,ye=0;ne<F;ne++,ye+=2){const Jt=_(O.charCodeAt(ye)),br=_(O.charCodeAt(ye+1));if(Jt===void 0||br===void 0){const pn=O[ye]+O[ye+1];throw new Error('hex string expected, got non-hex character "'+pn+'" at index '+ye)}D[ne]=Jt*16+br}return D}e.hexToBytes=T;const P=async()=>{};e.nextTick=P;async function x(O,U,F){let D=Date.now();for(let ne=0;ne<O;ne++){F(ne);const ye=Date.now()-D;ye>=0&&ye<U||(await(0,e.nextTick)(),D+=ye)}}e.asyncLoop=x;function N(O){if(typeof O!="string")throw new Error(`utf8ToBytes expected string, got ${typeof O}`);return new Uint8Array(new TextEncoder().encode(O))}e.utf8ToBytes=N;function k(O){return typeof O=="string"&&(O=N(O)),(0,r.bytes)(O),O}e.toBytes=k;function m(...O){let U=0;for(let D=0;D<O.length;D++){const ne=O[D];(0,r.bytes)(ne),U+=ne.length}const F=new Uint8Array(U);for(let D=0,ne=0;D<O.length;D++){const ye=O[D];F.set(ye,ne),ne+=ye.length}return F}e.concatBytes=m;class v{clone(){return this._cloneInto()}}e.Hash=v;const I={}.toString;function C(O,U){if(U!==void 0&&I.call(U)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(O,U)}e.checkOpts=C;function M(O){const U=D=>O().update(k(D)).digest(),F=O();return U.outputLen=F.outputLen,U.blockLen=F.blockLen,U.create=()=>O(),U}e.wrapConstructor=M;function B(O){const U=(D,ne)=>O(ne).update(k(D)).digest(),F=O({});return U.outputLen=F.outputLen,U.blockLen=F.blockLen,U.create=D=>O(D),U}e.wrapConstructorWithOpts=B;function R(O){const U=(D,ne)=>O(ne).update(k(D)).digest(),F=O({});return U.outputLen=F.outputLen,U.blockLen=F.blockLen,U.create=D=>O(D),U}e.wrapXOFConstructorWithOpts=R;function j(O=32){if(t.crypto&&typeof t.crypto.getRandomValues=="function")return t.crypto.getRandomValues(new Uint8Array(O));throw new Error("crypto.getRandomValues must be defined")}e.randomBytes=j})(Er);Object.defineProperty(Me,"__esModule",{value:!0});Me.HashMD=Me.Maj=Me.Chi=void 0;const Sn=ue,tr=Er;function Dc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const i=BigInt(32),c=BigInt(4294967295),s=Number(r>>i&c),a=Number(r&c),p=n?4:0,w=n?0:4;e.setUint32(t+p,s,n),e.setUint32(t+w,a,n)}const Wc=(e,t,r)=>e&t^~e&r;Me.Chi=Wc;const jc=(e,t,r)=>e&t^e&r^t&r;Me.Maj=jc;class Vc extends tr.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,tr.createView)(this.buffer)}update(t){(0,Sn.exists)(this);const{view:r,buffer:n,blockLen:i}=this;t=(0,tr.toBytes)(t);const c=t.length;for(let s=0;s<c;){const a=Math.min(i-this.pos,c-s);if(a===i){const p=(0,tr.createView)(t);for(;i<=c-s;s+=i)this.process(p,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,Sn.exists)(this),(0,Sn.output)(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:c}=this;let{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let d=s;d<i;d++)r[d]=0;Dc(n,i-8,BigInt(this.length*8),c),this.process(n,0);const a=(0,tr.createView)(t),p=this.outputLen;if(p%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const w=p/4,f=this.get();if(w>f.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<w;d++)a.setUint32(4*d,f[d],c)}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:c,destroyed:s,pos:a}=this;return t.length=i,t.pos=a,t.finished=c,t.destroyed=s,i%r&&t.buffer.set(n),t}}Me.HashMD=Vc;Object.defineProperty(Yt,"__esModule",{value:!0});Yt.ripemd160=Yt.RIPEMD160=void 0;const Gc=Me,cr=Er,Xc=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),vo=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),qc=vo.map(e=>(9*e+5)%16);let Yn=[vo],Jn=[qc];for(let e=0;e<4;e++)for(let t of[Yn,Jn])t.push(t[e].map(r=>Xc[r]));const Bo=[[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)),zc=Yn.map((e,t)=>e.map(r=>Bo[t][r])),Yc=Jn.map((e,t)=>e.map(r=>Bo[t][r])),Jc=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Qc=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function Ni(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 Ir=new Uint32Array(16);class xo extends Gc.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:c}=this;return[t,r,n,i,c]}set(t,r,n,i,c){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=i|0,this.h4=c|0}process(t,r){for(let y=0;y<16;y++,r+=4)Ir[y]=t.getUint32(r,!0);let n=this.h0|0,i=n,c=this.h1|0,s=c,a=this.h2|0,p=a,w=this.h3|0,f=w,d=this.h4|0,S=d;for(let y=0;y<5;y++){const _=4-y,T=Jc[y],P=Qc[y],x=Yn[y],N=Jn[y],k=zc[y],m=Yc[y];for(let v=0;v<16;v++){const I=(0,cr.rotl)(n+Ni(y,c,a,w)+Ir[x[v]]+T,k[v])+d|0;n=d,d=w,w=(0,cr.rotl)(a,10)|0,a=c,c=I}for(let v=0;v<16;v++){const I=(0,cr.rotl)(i+Ni(_,s,p,f)+Ir[N[v]]+P,m[v])+S|0;i=S,S=f,f=(0,cr.rotl)(p,10)|0,p=s,s=I}}this.set(this.h1+a+f|0,this.h2+w+S|0,this.h3+d+i|0,this.h4+n+s|0,this.h0+c+p|0)}roundClean(){Ir.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}Yt.RIPEMD160=xo;Yt.ripemd160=(0,cr.wrapConstructor)(()=>new xo);var Qr={};Object.defineProperty(Qr,"__esModule",{value:!0});Qr.sha1=void 0;const bn=Me,Nr=Er,rr=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),tt=new Uint32Array(80);class Zc extends bn.HashMD{constructor(){super(64,20,8,!1),this.A=rr[0]|0,this.B=rr[1]|0,this.C=rr[2]|0,this.D=rr[3]|0,this.E=rr[4]|0}get(){const{A:t,B:r,C:n,D:i,E:c}=this;return[t,r,n,i,c]}set(t,r,n,i,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=c|0}process(t,r){for(let p=0;p<16;p++,r+=4)tt[p]=t.getUint32(r,!1);for(let p=16;p<80;p++)tt[p]=(0,Nr.rotl)(tt[p-3]^tt[p-8]^tt[p-14]^tt[p-16],1);let{A:n,B:i,C:c,D:s,E:a}=this;for(let p=0;p<80;p++){let w,f;p<20?(w=(0,bn.Chi)(i,c,s),f=1518500249):p<40?(w=i^c^s,f=1859775393):p<60?(w=(0,bn.Maj)(i,c,s),f=2400959708):(w=i^c^s,f=3395469782);const d=(0,Nr.rotl)(n,5)+w+a+f+tt[p]|0;a=s,s=c,c=(0,Nr.rotl)(i,30),i=n,n=d}n=n+this.A|0,i=i+this.B|0,c=c+this.C|0,s=s+this.D|0,a=a+this.E|0,this.set(n,i,c,s,a)}roundClean(){tt.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}Qr.sha1=(0,Nr.wrapConstructor)(()=>new Zc);var mt={};Object.defineProperty(mt,"__esModule",{value:!0});mt.sha224=mt.sha256=void 0;const _n=Me,Oe=Er,eu=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]),rt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nt=new Uint32Array(64);class Uo extends _n.HashMD{constructor(){super(64,32,8,!1),this.A=rt[0]|0,this.B=rt[1]|0,this.C=rt[2]|0,this.D=rt[3]|0,this.E=rt[4]|0,this.F=rt[5]|0,this.G=rt[6]|0,this.H=rt[7]|0}get(){const{A:t,B:r,C:n,D:i,E:c,F:s,G:a,H:p}=this;return[t,r,n,i,c,s,a,p]}set(t,r,n,i,c,s,a,p){this.A=t|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=c|0,this.F=s|0,this.G=a|0,this.H=p|0}process(t,r){for(let d=0;d<16;d++,r+=4)nt[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){const S=nt[d-15],y=nt[d-2],_=(0,Oe.rotr)(S,7)^(0,Oe.rotr)(S,18)^S>>>3,T=(0,Oe.rotr)(y,17)^(0,Oe.rotr)(y,19)^y>>>10;nt[d]=T+nt[d-7]+_+nt[d-16]|0}let{A:n,B:i,C:c,D:s,E:a,F:p,G:w,H:f}=this;for(let d=0;d<64;d++){const S=(0,Oe.rotr)(a,6)^(0,Oe.rotr)(a,11)^(0,Oe.rotr)(a,25),y=f+S+(0,_n.Chi)(a,p,w)+eu[d]+nt[d]|0,T=((0,Oe.rotr)(n,2)^(0,Oe.rotr)(n,13)^(0,Oe.rotr)(n,22))+(0,_n.Maj)(n,i,c)|0;f=w,w=p,p=a,a=s+y|0,s=c,c=i,i=n,n=y+T|0}n=n+this.A|0,i=i+this.B|0,c=c+this.C|0,s=s+this.D|0,a=a+this.E|0,p=p+this.F|0,w=w+this.G|0,f=f+this.H|0,this.set(n,i,c,s,a,p,w,f)}roundClean(){nt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class tu extends Uo{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}}mt.sha256=(0,Oe.wrapConstructor)(()=>new Uo);mt.sha224=(0,Oe.wrapConstructor)(()=>new tu);(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=Yt,r=Qr,n=mt;function i(f){return E.from((0,t.ripemd160)(Uint8Array.from(f)))}e.ripemd160=i;function c(f){return E.from((0,r.sha1)(Uint8Array.from(f)))}e.sha1=c;function s(f){return E.from((0,n.sha256)(Uint8Array.from(f)))}e.sha256=s;function a(f){return E.from((0,t.ripemd160)((0,n.sha256)(Uint8Array.from(f))))}e.hash160=a;function p(f){return E.from((0,n.sha256)((0,n.sha256)(Uint8Array.from(f))))}e.hash256=p,e.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],e.TAGGED_HASH_PREFIXES={"BIP0340/challenge":E.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":E.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":E.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:E.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:E.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:E.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:E.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":E.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":E.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 w(f,d){return s(E.concat([e.TAGGED_HASH_PREFIXES[f],d]))}e.taggedHash=w})(Ke);function ru(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),c=i.charCodeAt(0);if(t[c]!==255)throw new TypeError(i+" is ambiguous");t[c]=n}var s=e.length,a=e.charAt(0),p=Math.log(s)/Math.log(256),w=Math.log(256)/Math.log(s);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var _=0,T=0,P=0,x=y.length;P!==x&&y[P]===0;)P++,_++;for(var N=(x-P)*w+1>>>0,k=new Uint8Array(N);P!==x;){for(var m=y[P],v=0,I=N-1;(m!==0||v<T)&&I!==-1;I--,v++)m+=256*k[I]>>>0,k[I]=m%s>>>0,m=m/s>>>0;if(m!==0)throw new Error("Non-zero carry");T=v,P++}for(var C=N-T;C!==N&&k[C]===0;)C++;for(var M=a.repeat(_);C<N;++C)M+=e.charAt(k[C]);return M}function d(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;for(var _=0,T=0,P=0;y[_]===a;)T++,_++;for(var x=(y.length-_)*p+1>>>0,N=new Uint8Array(x);y[_];){var k=t[y.charCodeAt(_)];if(k===255)return;for(var m=0,v=x-1;(k!==0||m<P)&&v!==-1;v--,m++)k+=s*N[v]>>>0,N[v]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");P=m,_++}for(var I=x-P;I!==x&&N[I]===0;)I++;for(var C=new Uint8Array(T+(x-I)),M=T;I!==x;)C[M++]=N[I++];return C}function S(y){var _=d(y);if(_)return _;throw new Error("Non-base"+s+" character")}return{encode:f,decodeUnsafe:d,decode:S}}var nu=ru;const iu=nu,ou="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var su=iu(ou),Tn=su,cu=function(e){function t(c){var s=Uint8Array.from(c),a=e(s),p=s.length+4,w=new Uint8Array(p);return w.set(s,0),w.set(a.subarray(0,4),s.length),Tn.encode(w,p)}function r(c){var s=c.slice(0,-4),a=c.slice(-4),p=e(s);if(!(a[0]^p[0]|a[1]^p[1]|a[2]^p[2]|a[3]^p[3]))return s}function n(c){var s=Tn.decodeUnsafe(c);if(s)return r(s)}function i(c){var s=Tn.decode(c),a=r(s);if(!a)throw new Error("Invalid checksum");return a}return{encode:t,decode:i,decodeUnsafe:n}},{sha256:Ci}=mt,uu=cu;function au(e){return Ci(Ci(e))}var Qn=uu(au);Object.defineProperty(Yr,"__esModule",{value:!0});Yr.p2pkh=void 0;const In=Ke,fu=ae,Vt=_e(),Ee=de,je=ke,Hi=Qn,it=Vt.OPS;function hu(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,Ee.typeforce)({network:Ee.typeforce.maybe(Ee.typeforce.Object),address:Ee.typeforce.maybe(Ee.typeforce.String),hash:Ee.typeforce.maybe(Ee.typeforce.BufferN(20)),output:Ee.typeforce.maybe(Ee.typeforce.BufferN(25)),pubkey:Ee.typeforce.maybe(Ee.isPoint),signature:Ee.typeforce.maybe(Vt.isCanonicalScriptSignature),input:Ee.typeforce.maybe(Ee.typeforce.Buffer)},e);const r=je.value(()=>{const s=E.from(Hi.decode(e.address)),a=s.readUInt8(0),p=s.slice(1);return{version:a,hash:p}}),n=je.value(()=>Vt.decompile(e.input)),i=e.network||fu.bitcoin,c={name:"p2pkh",network:i};if(je.prop(c,"address",()=>{if(!c.hash)return;const s=E.allocUnsafe(21);return s.writeUInt8(i.pubKeyHash,0),c.hash.copy(s,1),Hi.encode(s)}),je.prop(c,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||c.pubkey)return In.hash160(e.pubkey||c.pubkey)}),je.prop(c,"output",()=>{if(c.hash)return Vt.compile([it.OP_DUP,it.OP_HASH160,c.hash,it.OP_EQUALVERIFY,it.OP_CHECKSIG])}),je.prop(c,"pubkey",()=>{if(e.input)return n()[1]}),je.prop(c,"signature",()=>{if(e.input)return n()[0]}),je.prop(c,"input",()=>{if(e.pubkey&&e.signature)return Vt.compile([e.signature,e.pubkey])}),je.prop(c,"witness",()=>{if(c.input)return[]}),t.validate){let s=E.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");s=r().hash}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!==25||e.output[0]!==it.OP_DUP||e.output[1]!==it.OP_HASH160||e.output[2]!==20||e.output[23]!==it.OP_EQUALVERIFY||e.output[24]!==it.OP_CHECKSIG)throw new TypeError("Output is invalid");const a=e.output.slice(3,23);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.pubkey){const a=In.hash160(e.pubkey);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=a}if(e.input){const a=n();if(a.length!==2)throw new TypeError("Input is invalid");if(!Vt.isCanonicalScriptSignature(a[0]))throw new TypeError("Input has invalid signature");if(!(0,Ee.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 p=In.hash160(a[1]);if(s.length>0&&!s.equals(p))throw new TypeError("Hash mismatch")}}return Object.assign(c,e)}Yr.p2pkh=hu;var Zr={};Object.defineProperty(Zr,"__esModule",{value:!0});Zr.p2sh=void 0;const Ri=Ke,pu=ae,Re=_e(),X=de,Ce=ke,Fi=Qn,nr=Re.OPS;function lu(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,X.typeforce)({network:X.typeforce.maybe(X.typeforce.Object),address:X.typeforce.maybe(X.typeforce.String),hash:X.typeforce.maybe(X.typeforce.BufferN(20)),output:X.typeforce.maybe(X.typeforce.BufferN(23)),redeem:X.typeforce.maybe({network:X.typeforce.maybe(X.typeforce.Object),output:X.typeforce.maybe(X.typeforce.Buffer),input:X.typeforce.maybe(X.typeforce.Buffer),witness:X.typeforce.maybe(X.typeforce.arrayOf(X.typeforce.Buffer))}),input:X.typeforce.maybe(X.typeforce.Buffer),witness:X.typeforce.maybe(X.typeforce.arrayOf(X.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||pu.bitcoin);const n={network:r},i=Ce.value(()=>{const a=E.from(Fi.decode(e.address)),p=a.readUInt8(0),w=a.slice(1);return{version:p,hash:w}}),c=Ce.value(()=>Re.decompile(e.input)),s=Ce.value(()=>{const a=c(),p=a[a.length-1];return{network:r,output:p===nr.OP_FALSE?E.from([]):p,input:Re.compile(a.slice(0,-1)),witness:e.witness||[]}});if(Ce.prop(n,"address",()=>{if(!n.hash)return;const a=E.allocUnsafe(21);return a.writeUInt8(n.network.scriptHash,0),n.hash.copy(a,1),Fi.encode(a)}),Ce.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 Ri.hash160(n.redeem.output)}),Ce.prop(n,"output",()=>{if(n.hash)return Re.compile([nr.OP_HASH160,n.hash,nr.OP_EQUAL])}),Ce.prop(n,"redeem",()=>{if(e.input)return s()}),Ce.prop(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return Re.compile([].concat(Re.decompile(e.redeem.input),e.redeem.output))}),Ce.prop(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),Ce.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=E.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]!==nr.OP_HASH160||e.output[1]!==20||e.output[22]!==nr.OP_EQUAL)throw new TypeError("Output is invalid");const w=e.output.slice(2,22);if(a.length>0&&!a.equals(w))throw new TypeError("Hash mismatch");a=w}const p=w=>{if(w.output){const f=Re.decompile(w.output);if(!f||f.length<1)throw new TypeError("Redeem.output too short");if(w.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(Re.countNonPushOnlyOPs(f)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const d=Ri.hash160(w.output);if(a.length>0&&!a.equals(d))throw new TypeError("Hash mismatch");a=d}if(w.input){const f=w.input.length>0,d=w.witness&&w.witness.length>0;if(!f&&!d)throw new TypeError("Empty input");if(f&&d)throw new TypeError("Input and witness provided");if(f){const S=Re.decompile(w.input);if(!Re.isPushOnly(S))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const w=c();if(!w||w.length<1)throw new TypeError("Input too short");if(!E.isBuffer(s().output))throw new TypeError("Input is invalid");p(s())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const w=s();if(e.redeem.output&&!e.redeem.output.equals(w.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(w.input))throw new TypeError("Redeem.input mismatch")}p(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,X.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}Zr.p2sh=lu;var en={},Qe={};Object.defineProperty(Qe,"__esModule",{value:!0});Qe.bech32m=Qe.bech32=void 0;const $r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",No={};for(let e=0;e<$r.length;e++){const t=$r.charAt(e);No[t]=e}function Xt(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 Li(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=Xt(t)^n>>5}t=Xt(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=Xt(t)^n&31}return t}function Zn(e,t,r,n){let i=0,c=0;const s=(1<<r)-1,a=[];for(let p=0;p<e.length;++p)for(i=i<<t|e[p],c+=t;c>=r;)c-=r,a.push(i>>c&s);if(n)c>0&&a.push(i<<r-c&s);else{if(c>=t)return"Excess padding";if(i<<r-c&s)return"Non-zero padding"}return a}function du(e){return Zn(e,8,5,!0)}function yu(e){const t=Zn(e,5,8,!1);if(Array.isArray(t))return t}function wu(e){const t=Zn(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function Co(e){let t;e==="bech32"?t=1:t=734539939;function r(s,a,p){if(p=p||90,s.length+7+a.length>p)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let w=Li(s);if(typeof w=="string")throw new Error(w);let f=s+"1";for(let d=0;d<a.length;++d){const S=a[d];if(S>>5)throw new Error("Non 5-bit word");w=Xt(w)^S,f+=$r.charAt(S)}for(let d=0;d<6;++d)w=Xt(w);w^=t;for(let d=0;d<6;++d){const S=w>>(5-d)*5&31;f+=$r.charAt(S)}return f}function n(s,a){if(a=a||90,s.length<8)return s+" too short";if(s.length>a)return"Exceeds length limit";const p=s.toLowerCase(),w=s.toUpperCase();if(s!==p&&s!==w)return"Mixed-case string "+s;s=p;const f=s.lastIndexOf("1");if(f===-1)return"No separator character for "+s;if(f===0)return"Missing prefix for "+s;const d=s.slice(0,f),S=s.slice(f+1);if(S.length<6)return"Data too short";let y=Li(d);if(typeof y=="string")return y;const _=[];for(let T=0;T<S.length;++T){const P=S.charAt(T),x=No[P];if(x===void 0)return"Unknown character "+P;y=Xt(y)^x,!(T+6>=S.length)&&_.push(x)}return y!==t?"Invalid checksum for "+s:{prefix:d,words:_}}function i(s,a){const p=n(s,a);if(typeof p=="object")return p}function c(s,a){const p=n(s,a);if(typeof p=="object")return p;throw new Error(p)}return{decodeUnsafe:i,decode:c,encode:r,toWords:du,fromWordsUnsafe:yu,fromWords:wu}}Qe.bech32=Co("bech32");Qe.bech32m=Co("bech32m");Object.defineProperty(en,"__esModule",{value:!0});en.p2wpkh=void 0;const kn=Ke,gu=ae,Cr=_e(),ie=de,ot=ke,kr=Qe,$i=Cr.OPS,Eu=E.alloc(0);function mu(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,ie.typeforce)({address:ie.typeforce.maybe(ie.typeforce.String),hash:ie.typeforce.maybe(ie.typeforce.BufferN(20)),input:ie.typeforce.maybe(ie.typeforce.BufferN(0)),network:ie.typeforce.maybe(ie.typeforce.Object),output:ie.typeforce.maybe(ie.typeforce.BufferN(22)),pubkey:ie.typeforce.maybe(ie.isPoint),signature:ie.typeforce.maybe(Cr.isCanonicalScriptSignature),witness:ie.typeforce.maybe(ie.typeforce.arrayOf(ie.typeforce.Buffer))},e);const r=ot.value(()=>{const c=kr.bech32.decode(e.address),s=c.words.shift(),a=kr.bech32.fromWords(c.words);return{version:s,prefix:c.prefix,data:E.from(a)}}),n=e.network||gu.bitcoin,i={name:"p2wpkh",network:n};if(ot.prop(i,"address",()=>{if(!i.hash)return;const c=kr.bech32.toWords(i.hash);return c.unshift(0),kr.bech32.encode(n.bech32,c)}),ot.prop(i,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||i.pubkey)return kn.hash160(e.pubkey||i.pubkey)}),ot.prop(i,"output",()=>{if(i.hash)return Cr.compile([$i.OP_0,i.hash])}),ot.prop(i,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),ot.prop(i,"signature",()=>{if(e.witness)return e.witness[0]}),ot.prop(i,"input",()=>{if(i.witness)return Eu}),ot.prop(i,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let c=E.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");c=r().data}if(e.hash){if(c.length>0&&!c.equals(e.hash))throw new TypeError("Hash mismatch");c=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==$i.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(c.length>0&&!c.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");c=e.output.slice(2)}if(e.pubkey){const s=kn.hash160(e.pubkey);if(c.length>0&&!c.equals(s))throw new TypeError("Hash mismatch");if(c=s,!(0,ie.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(!Cr.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,ie.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 s=kn.hash160(e.witness[1]);if(c.length>0&&!c.equals(s))throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}en.p2wpkh=mu;var tn={};Object.defineProperty(tn,"__esModule",{value:!0});tn.p2wsh=void 0;const Mi=Ke,Su=ae,Xe=_e(),G=de,Ve=ke,Ar=Qe,Ki=Xe.OPS,An=E.alloc(0);function Or(e){return!!(E.isBuffer(e)&&e.length===65&&e[0]===4&&(0,G.isPoint)(e))}function bu(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,G.typeforce)({network:G.typeforce.maybe(G.typeforce.Object),address:G.typeforce.maybe(G.typeforce.String),hash:G.typeforce.maybe(G.typeforce.BufferN(32)),output:G.typeforce.maybe(G.typeforce.BufferN(34)),redeem:G.typeforce.maybe({input:G.typeforce.maybe(G.typeforce.Buffer),network:G.typeforce.maybe(G.typeforce.Object),output:G.typeforce.maybe(G.typeforce.Buffer),witness:G.typeforce.maybe(G.typeforce.arrayOf(G.typeforce.Buffer))}),input:G.typeforce.maybe(G.typeforce.BufferN(0)),witness:G.typeforce.maybe(G.typeforce.arrayOf(G.typeforce.Buffer))},e);const r=Ve.value(()=>{const s=Ar.bech32.decode(e.address),a=s.words.shift(),p=Ar.bech32.fromWords(s.words);return{version:a,prefix:s.prefix,data:E.from(p)}}),n=Ve.value(()=>Xe.decompile(e.redeem.input));let i=e.network;i||(i=e.redeem&&e.redeem.network||Su.bitcoin);const c={network:i};if(Ve.prop(c,"address",()=>{if(!c.hash)return;const s=Ar.bech32.toWords(c.hash);return s.unshift(0),Ar.bech32.encode(i.bech32,s)}),Ve.prop(c,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(c.redeem&&c.redeem.output)return Mi.sha256(c.redeem.output)}),Ve.prop(c,"output",()=>{if(c.hash)return Xe.compile([Ki.OP_0,c.hash])}),Ve.prop(c,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:An,witness:e.witness.slice(0,-1)}}),Ve.prop(c,"input",()=>{if(c.witness)return An}),Ve.prop(c,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const s=Xe.toStack(n());return c.redeem=Object.assign({witness:s},e.redeem),c.redeem.input=An,[].concat(s,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Ve.prop(c,"name",()=>{const s=["p2wsh"];return c.redeem!==void 0&&c.redeem.name!==void 0&&s.push(c.redeem.name),s.join("-")}),t.validate){let s=E.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");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!==34||e.output[0]!==Ki.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const a=e.output.slice(2);if(s.length>0&&!s.equals(a))throw new TypeError("Hash mismatch");s=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=Xe.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(Xe.countNonPushOnlyOPs(a)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const p=Mi.sha256(e.redeem.output);if(s.length>0&&!s.equals(p))throw new TypeError("Hash mismatch");s=p}if(e.redeem.input&&!Xe.isPushOnly(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,G.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Or)||e.redeem.output&&(Xe.decompile(e.redeem.output)||[]).some(Or))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(Or)||(Xe.decompile(a)||[]).some(Or))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(c,e)}tn.p2wsh=bu;var ir={},ht={};Object.defineProperty(ht,"__esModule",{value:!0});ht.getEccLib=ht.initEccLib=void 0;const pr={};function _u(e){e?e!==pr.eccLib&&(Iu(e),pr.eccLib=e):pr.eccLib=e}ht.initEccLib=_u;function Tu(){if(!pr.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return pr.eccLib}ht.getEccLib=Tu;const Ge=e=>E.from(e,"hex");function Iu(e){Ae(typeof e.isXOnlyPoint=="function"),Ae(e.isXOnlyPoint(Ge("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Ae(e.isXOnlyPoint(Ge("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Ae(e.isXOnlyPoint(Ge("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Ae(e.isXOnlyPoint(Ge("0000000000000000000000000000000000000000000000000000000000000001"))),Ae(!e.isXOnlyPoint(Ge("0000000000000000000000000000000000000000000000000000000000000000"))),Ae(!e.isXOnlyPoint(Ge("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Ae(typeof e.xOnlyPointAddTweak=="function"),ku.forEach(t=>{const r=e.xOnlyPointAddTweak(Ge(t.pubkey),Ge(t.tweak));t.result===null?Ae(r===null):(Ae(r!==null),Ae(r.parity===t.parity),Ae(E.from(r.xOnlyPubkey).equals(Ge(t.result))))})}function Ae(e){if(!e)throw new Error("ecc library invalid")}const ku=[{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 rn={},oe={},Ln={exports:{}};/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */(function(e,t){var r=Xr,n=r.Buffer;function i(s,a){for(var p in s)a[p]=s[p]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(i(r,t),t.Buffer=c);function c(s,a,p){return n(s,a,p)}c.prototype=Object.create(n.prototype),i(n,c),c.from=function(s,a,p){if(typeof s=="number")throw new TypeError("Argument must not be a number");return n(s,a,p)},c.alloc=function(s,a,p){if(typeof s!="number")throw new TypeError("Argument must be a number");var w=n(s);return a!==void 0?typeof p=="string"?w.fill(a,p):w.fill(a):w.fill(0),w},c.allocUnsafe=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return n(s)},c.allocUnsafeSlow=function(s){if(typeof s!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(s)}})(Ln,Ln.exports);var Au=Ln.exports,$n=Au.Buffer,Ou=9007199254740991;function ei(e){if(e<0||e>Ou||e%1!==0)throw new RangeError("value out of range")}function ur(e,t,r){if(ei(e),t||(t=$n.allocUnsafe(Ho(e))),!$n.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),ur.bytes=1):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),ur.bytes=3):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),ur.bytes=5):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),ur.bytes=9),t}function ar(e,t){if(!$n.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");t||(t=0);var r=e.readUInt8(t);if(r<253)return ar.bytes=1,r;if(r===253)return ar.bytes=3,e.readUInt16LE(t+1);if(r===254)return ar.bytes=5,e.readUInt32LE(t+1);ar.bytes=9;var n=e.readUInt32LE(t+1),i=e.readUInt32LE(t+5),c=i*4294967296+n;return ei(c),c}function Ho(e){return ei(e),e<253?1:e<=65535?3:e<=4294967295?5:9}var Pu={encode:ur,decode:ar,encodingLength:Ho};Object.defineProperty(oe,"__esModule",{value:!0});oe.BufferReader=oe.BufferWriter=oe.cloneBuffer=oe.reverseBuffer=oe.writeUInt64LE=oe.readUInt64LE=oe.varuint=void 0;const Et=de,{typeforce:Ro}=Et,wr=Pu;oe.varuint=wr;function Fo(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 Lo(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,Fo(n+r,9007199254740991),n+r}oe.readUInt64LE=Lo;function $o(e,t,r){return Fo(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}oe.writeUInt64LE=$o;function vu(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}oe.reverseBuffer=vu;function Bu(e){const t=E.allocUnsafe(e.length);return e.copy(t),t}oe.cloneBuffer=Bu;class ti{static withCapacity(t){return new ti(E.alloc(t))}constructor(t,r=0){this.buffer=t,this.offset=r,Ro(Et.tuple(Et.Buffer,Et.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=$o(this.buffer,t,this.offset)}writeVarInt(t){wr.encode(t,this.buffer,this.offset),this.offset+=wr.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}`)}}oe.BufferWriter=ti;class xu{constructor(t,r=0){this.buffer=t,this.offset=r,Ro(Et.tuple(Et.Buffer,Et.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=Lo(this.buffer,this.offset);return this.offset+=8,t}readVarInt(){const t=wr.decode(this.buffer,this.offset);return this.offset+=wr.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}}oe.BufferReader=xu;(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=Xr,r=ht,n=Ke,i=oe,c=de;e.LEAF_VERSION_TAPSCRIPT=192,e.MAX_TAPTREE_DEPTH=128;const s=T=>"left"in T&&"right"in T;function a(T,P){if(T.length<33)throw new TypeError(`The control-block length is too small. Got ${T.length}, expected min 33.`);const x=(T.length-33)/32;let N=P;for(let k=0;k<x;k++){const m=T.slice(33+32*k,65+32*k);N.compare(m)<0?N=y(N,m):N=y(m,N)}return N}e.rootHashFromPath=a;function p(T){if((0,c.isTapleaf)(T))return{hash:f(T)};const P=[p(T[0]),p(T[1])];P.sort((k,m)=>k.hash.compare(m.hash));const[x,N]=P;return{hash:y(x.hash,N.hash),left:x,right:N}}e.toHashTree=p;function w(T,P){if(s(T)){const x=w(T.left,P);if(x!==void 0)return[...x,T.right.hash];const N=w(T.right,P);if(N!==void 0)return[...N,T.left.hash]}else if(T.hash.equals(P))return[]}e.findScriptPath=w;function f(T){const P=T.version||e.LEAF_VERSION_TAPSCRIPT;return n.taggedHash("TapLeaf",t.Buffer.concat([t.Buffer.from([P]),_(T.output)]))}e.tapleafHash=f;function d(T,P){return n.taggedHash("TapTweak",t.Buffer.concat(P?[T,P]:[T]))}e.tapTweakHash=d;function S(T,P){if(!t.Buffer.isBuffer(T)||T.length!==32||P&&P.length!==32)return null;const x=d(T,P),N=(0,r.getEccLib)().xOnlyPointAddTweak(T,x);return!N||N.xOnlyPubkey===null?null:{parity:N.parity,x:t.Buffer.from(N.xOnlyPubkey)}}e.tweakKey=S;function y(T,P){return n.taggedHash("TapBranch",t.Buffer.concat([T,P]))}function _(T){const P=i.varuint.encodingLength(T.length),x=t.Buffer.allocUnsafe(P);return i.varuint.encode(T.length,x),t.Buffer.concat([x,T])}})(rn);var Di;function Uu(){if(Di)return ir;Di=1,Object.defineProperty(ir,"__esModule",{value:!0}),ir.p2tr=void 0;const e=Xr,t=ae,r=_e(),n=de,i=ht,c=rn,s=ke,a=Qe,p=ri(),w=r.OPS,f=1,d=80;function S(y,_){if(!y.address&&!y.output&&!y.pubkey&&!y.internalPubkey&&!(y.witness&&y.witness.length>1))throw new TypeError("Not enough data");_=Object.assign({validate:!0},_||{}),(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)},y);const T=s.value(()=>(0,p.fromBech32)(y.address)),P=s.value(()=>{if(!(!y.witness||!y.witness.length))return y.witness.length>=2&&y.witness[y.witness.length-1][0]===d?y.witness.slice(0,-1):y.witness.slice()}),x=s.value(()=>{if(y.scriptTree)return(0,c.toHashTree)(y.scriptTree);if(y.hash)return{hash:y.hash}}),N=y.network||t.bitcoin,k={name:"p2tr",network:N};if(s.prop(k,"address",()=>{if(!k.pubkey)return;const m=a.bech32m.toWords(k.pubkey);return m.unshift(f),a.bech32m.encode(N.bech32,m)}),s.prop(k,"hash",()=>{const m=x();if(m)return m.hash;const v=P();if(v&&v.length>1){const I=v[v.length-1],C=I[0]&n.TAPLEAF_VERSION_MASK,M=v[v.length-2],B=(0,c.tapleafHash)({output:M,version:C});return(0,c.rootHashFromPath)(I,B)}return null}),s.prop(k,"output",()=>{if(k.pubkey)return r.compile([w.OP_1,k.pubkey])}),s.prop(k,"redeemVersion",()=>y.redeemVersion?y.redeemVersion:y.redeem&&y.redeem.redeemVersion!==void 0&&y.redeem.redeemVersion!==null?y.redeem.redeemVersion:c.LEAF_VERSION_TAPSCRIPT),s.prop(k,"redeem",()=>{const m=P();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}}),s.prop(k,"pubkey",()=>{if(y.pubkey)return y.pubkey;if(y.output)return y.output.slice(2);if(y.address)return T().data;if(k.internalPubkey){const m=(0,c.tweakKey)(k.internalPubkey,k.hash);if(m)return m.x}}),s.prop(k,"internalPubkey",()=>{if(y.internalPubkey)return y.internalPubkey;const m=P();if(m&&m.length>1)return m[m.length-1].slice(1,33)}),s.prop(k,"signature",()=>{if(y.signature)return y.signature;const m=P();if(!(!m||m.length!==1))return m[0]}),s.prop(k,"witness",()=>{if(y.witness)return y.witness;const m=x();if(m&&y.redeem&&y.redeem.output&&y.internalPubkey){const v=(0,c.tapleafHash)({output:y.redeem.output,version:k.redeemVersion}),I=(0,c.findScriptPath)(m,v);if(!I)return;const C=(0,c.tweakKey)(y.internalPubkey,m.hash);if(!C)return;const M=e.Buffer.concat([e.Buffer.from([k.redeemVersion|C.parity]),y.internalPubkey].concat(I));return[y.redeem.output,M]}if(y.signature)return[y.signature]}),_.validate){let m=e.Buffer.from([]);if(y.address){if(N&&N.bech32!==T().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(T().version!==f)throw new TypeError("Invalid address version");if(T().data.length!==32)throw new TypeError("Invalid address data");m=T().data}if(y.pubkey){if(m.length>0&&!m.equals(y.pubkey))throw new TypeError("Pubkey mismatch");m=y.pubkey}if(y.output){if(y.output.length!==34||y.output[0]!==w.OP_1||y.output[1]!==32)throw new TypeError("Output is invalid");if(m.length>0&&!m.equals(y.output.slice(2)))throw new TypeError("Pubkey mismatch");m=y.output.slice(2)}if(y.internalPubkey){const C=(0,c.tweakKey)(y.internalPubkey,k.hash);if(m.length>0&&!m.equals(C.x))throw new TypeError("Pubkey mismatch");m=C.x}if(m&&m.length&&!(0,i.getEccLib)().isXOnlyPoint(m))throw new TypeError("Invalid pubkey for p2tr");const v=x();if(y.hash&&v&&!y.hash.equals(v.hash))throw new TypeError("Hash mismatch");if(y.redeem&&y.redeem.output&&v){const C=(0,c.tapleafHash)({output:y.redeem.output,version:k.redeemVersion});if(!(0,c.findScriptPath)(v,C))throw new TypeError("Redeem script not in tree")}const I=P();if(y.redeem&&k.redeem){if(y.redeem.redeemVersion&&y.redeem.redeemVersion!==k.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(y.redeem.output){if(r.decompile(y.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(k.redeem.output&&!y.redeem.output.equals(k.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(y.redeem.witness&&k.redeem.witness&&!(0,n.stacksEqual)(y.redeem.witness,k.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(I&&I.length)if(I.length===1){if(y.signature&&!y.signature.equals(I[0]))throw new TypeError("Signature mismatch")}else{const C=I[I.length-1];if(C.length<33)throw new TypeError(`The control-block length is too small. Got ${C.length}, expected min 33.`);if((C.length-33)%32!==0)throw new TypeError(`The control-block length of ${C.length} is incorrect!`);const M=(C.length-33)/32;if(M>128)throw new TypeError(`The script path is too long. Got ${M}, expected max 128.`);const B=C.slice(1,33);if(y.internalPubkey&&!y.internalPubkey.equals(B))throw new TypeError("Internal pubkey mismatch");if(!(0,i.getEccLib)().isXOnlyPoint(B))throw new TypeError("Invalid internalPubkey for p2tr witness");const R=C[0]&n.TAPLEAF_VERSION_MASK,j=I[I.length-2],O=(0,c.tapleafHash)({output:j,version:R}),U=(0,c.rootHashFromPath)(C,O),F=(0,c.tweakKey)(B,U);if(!F)throw new TypeError("Invalid outputKey for p2tr witness");if(m.length&&!m.equals(F.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(F.parity!==(C[0]&1))throw new Error("Incorrect parity")}}return Object.assign(k,y)}return ir.p2tr=S,ir}var Wi;function mr(){return Wi||(Wi=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=Gr;Object.defineProperty(e,"embed",{enumerable:!0,get:function(){return t.p2data}});const r=qr;Object.defineProperty(e,"p2ms",{enumerable:!0,get:function(){return r.p2ms}});const n=zr;Object.defineProperty(e,"p2pk",{enumerable:!0,get:function(){return n.p2pk}});const i=Yr;Object.defineProperty(e,"p2pkh",{enumerable:!0,get:function(){return i.p2pkh}});const c=Zr;Object.defineProperty(e,"p2sh",{enumerable:!0,get:function(){return c.p2sh}});const s=en;Object.defineProperty(e,"p2wpkh",{enumerable:!0,get:function(){return s.p2wpkh}});const a=tn;Object.defineProperty(e,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const p=Uu();Object.defineProperty(e,"p2tr",{enumerable:!0,get:function(){return p.p2tr}})}(gn)),gn}var ji;function ri(){if(ji)return ge;ji=1,Object.defineProperty(ge,"__esModule",{value:!0}),ge.toOutputScript=ge.fromOutputScript=ge.toBech32=ge.toBase58Check=ge.fromBech32=ge.fromBase58Check=void 0;const e=ae,t=mr(),r=_e(),n=de,i=Qe,c=Qn,s=40,a=2,p=16,w=2,f=80,d="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 S(k,m){const v=k.slice(2);if(v.length<a||v.length>s)throw new TypeError("Invalid program length for segwit address");const I=k[0]-f;if(I<w||I>p)throw new TypeError("Invalid version for segwit address");if(k[1]!==v.length)throw new TypeError("Invalid script for segwit address");return console.warn(d),P(v,I,m.bech32)}function y(k){const m=E.from(c.decode(k));if(m.length<21)throw new TypeError(k+" is too short");if(m.length>21)throw new TypeError(k+" is too long");const v=m.readUInt8(0),I=m.slice(1);return{version:v,hash:I}}ge.fromBase58Check=y;function _(k){let m,v;try{m=i.bech32.decode(k)}catch{}if(m){if(v=m.words[0],v!==0)throw new TypeError(k+" uses wrong encoding")}else if(m=i.bech32m.decode(k),v=m.words[0],v===0)throw new TypeError(k+" uses wrong encoding");const I=i.bech32.fromWords(m.words.slice(1));return{version:v,prefix:m.prefix,data:E.from(I)}}ge.fromBech32=_;function T(k,m){(0,n.typeforce)((0,n.tuple)(n.Hash160bit,n.UInt8),arguments);const v=E.allocUnsafe(21);return v.writeUInt8(m,0),k.copy(v,1),c.encode(v)}ge.toBase58Check=T;function P(k,m,v){const I=i.bech32.toWords(k);return I.unshift(m),m===0?i.bech32.encode(v,I):i.bech32m.encode(v,I)}ge.toBech32=P;function x(k,m){m=m||e.bitcoin;try{return t.p2pkh({output:k,network:m}).address}catch{}try{return t.p2sh({output:k,network:m}).address}catch{}try{return t.p2wpkh({output:k,network:m}).address}catch{}try{return t.p2wsh({output:k,network:m}).address}catch{}try{return t.p2tr({output:k,network:m}).address}catch{}try{return S(k,m)}catch{}throw new Error(r.toASM(k)+" has no matching Address")}ge.fromOutputScript=x;function N(k,m){m=m||e.bitcoin;let v,I;try{v=y(k)}catch{}if(v){if(v.version===m.pubKeyHash)return t.p2pkh({hash:v.hash}).output;if(v.version===m.scriptHash)return t.p2sh({hash:v.hash}).output}else{try{I=_(k)}catch{}if(I){if(I.prefix!==m.bech32)throw new Error(k+" has an invalid prefix");if(I.version===0){if(I.data.length===20)return t.p2wpkh({hash:I.data}).output;if(I.data.length===32)return t.p2wsh({hash:I.data}).output}else if(I.version===1){if(I.data.length===32)return t.p2tr({pubkey:I.data}).output}else if(I.version>=w&&I.version<=p&&I.data.length>=a&&I.data.length<=s)return console.warn(d),r.compile([I.version+f,I.data])}}throw new Error(k+" has no matching Script")}return ge.toOutputScript=N,ge}var nn={},on={};Object.defineProperty(on,"__esModule",{value:!0});on.fastMerkleRoot=void 0;function Nu(e,t){if(!Array.isArray(e))throw TypeError("Expected values Array");if(typeof t!="function")throw TypeError("Expected digest Function");let r=e.length;const n=e.concat();for(;r>1;){let i=0;for(let c=0;c<r;c+=2,++i){const s=n[c],a=c+1===r?s:n[c+1],p=E.concat([s,a]);n[i]=t(p)}r=i}return n[0]}on.fastMerkleRoot=Nu;var lt={};Object.defineProperty(lt,"__esModule",{value:!0});lt.Transaction=void 0;const te=oe,me=Ke,Vi=_e(),Cu=_e(),K=de,{typeforce:He}=K;function Fe(e){const t=e.length;return te.varuint.encodingLength(t)+t}function Hu(e){const t=e.length;return te.varuint.encodingLength(t)+e.reduce((r,n)=>r+Fe(n),0)}const st=E.allocUnsafe(0),Gi=[],On=E.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),Xi=E.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),Ru=E.from("ffffffffffffffff","hex"),Fu={script:st,valueBuffer:Ru};function Lu(e){return e.value!==void 0}class L{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(t,r){const n=new te.BufferReader(t),i=new L;i.version=n.readInt32();const c=n.readUInt8(),s=n.readUInt8();let a=!1;c===L.ADVANCED_TRANSACTION_MARKER&&s===L.ADVANCED_TRANSACTION_FLAG?a=!0:n.offset-=2;const p=n.readVarInt();for(let f=0;f<p;++f)i.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:Gi});const w=n.readVarInt();for(let f=0;f<w;++f)i.outs.push({value:n.readUInt64(),script:n.readVarSlice()});if(a){for(let f=0;f<p;++f)i.ins[f].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 L.fromBuffer(E.from(t,"hex"),!1)}static isCoinbaseHash(t){He(K.Hash256bit,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&L.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,i){return He(K.tuple(K.Hash256bit,K.UInt32,K.maybe(K.UInt32),K.maybe(K.Buffer)),arguments),K.Null(n)&&(n=L.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:i||st,sequence:n,witness:Gi})-1}addOutput(t,r){return He(K.tuple(K.Buffer,K.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)+te.varuint.encodingLength(this.ins.length)+te.varuint.encodingLength(this.outs.length)+this.ins.reduce((n,i)=>n+40+Fe(i.script),0)+this.outs.reduce((n,i)=>n+8+Fe(i.script),0)+(r?this.ins.reduce((n,i)=>n+Hu(i.witness),0):0)}clone(){const t=new L;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(He(K.tuple(K.UInt32,K.Buffer,K.Number),arguments),t>=this.ins.length)return Xi;const i=Vi.compile(Vi.decompile(r).filter(a=>a!==Cu.OPS.OP_CODESEPARATOR)),c=this.clone();if((n&31)===L.SIGHASH_NONE)c.outs=[],c.ins.forEach((a,p)=>{p!==t&&(a.sequence=0)});else if((n&31)===L.SIGHASH_SINGLE){if(t>=this.outs.length)return Xi;c.outs.length=t+1;for(let a=0;a<t;a++)c.outs[a]=Fu;c.ins.forEach((a,p)=>{p!==t&&(a.sequence=0)})}n&L.SIGHASH_ANYONECANPAY?(c.ins=[c.ins[t]],c.ins[0].script=i):(c.ins.forEach(a=>{a.script=st}),c.ins[t].script=i);const s=E.allocUnsafe(c.byteLength(!1)+4);return s.writeInt32LE(n,s.length-4),c.__toBuffer(s,0,!1),me.hash256(s)}hashForWitnessV1(t,r,n,i,c,s){if(He(K.tuple(K.UInt32,He.arrayOf(K.Buffer),He.arrayOf(K.Satoshi),K.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===L.SIGHASH_DEFAULT?L.SIGHASH_ALL:i&L.SIGHASH_OUTPUT_MASK,w=(i&L.SIGHASH_INPUT_MASK)===L.SIGHASH_ANYONECANPAY,f=a===L.SIGHASH_NONE,d=a===L.SIGHASH_SINGLE;let S=st,y=st,_=st,T=st,P=st;if(!w){let m=te.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(v=>{m.writeSlice(v.hash),m.writeUInt32(v.index)}),S=me.sha256(m.end()),m=te.BufferWriter.withCapacity(8*this.ins.length),n.forEach(v=>m.writeUInt64(v)),y=me.sha256(m.end()),m=te.BufferWriter.withCapacity(r.map(Fe).reduce((v,I)=>v+I)),r.forEach(v=>m.writeVarSlice(v)),_=me.sha256(m.end()),m=te.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(v=>m.writeUInt32(v.sequence)),T=me.sha256(m.end())}if(f||d){if(d&&t<this.outs.length){const m=this.outs[t],v=te.BufferWriter.withCapacity(8+Fe(m.script));v.writeUInt64(m.value),v.writeVarSlice(m.script),P=me.sha256(v.end())}}else{const m=this.outs.map(I=>8+Fe(I.script)).reduce((I,C)=>I+C),v=te.BufferWriter.withCapacity(m);this.outs.forEach(I=>{v.writeUInt64(I.value),v.writeVarSlice(I.script)}),P=me.sha256(v.end())}const x=(c?2:0)+(s?1:0),N=174-(w?49:0)-(f?32:0)+(s?32:0)+(c?37:0),k=te.BufferWriter.withCapacity(N);if(k.writeUInt8(i),k.writeInt32(this.version),k.writeUInt32(this.locktime),k.writeSlice(S),k.writeSlice(y),k.writeSlice(_),k.writeSlice(T),f||d||k.writeSlice(P),k.writeUInt8(x),w){const m=this.ins[t];k.writeSlice(m.hash),k.writeUInt32(m.index),k.writeUInt64(n[t]),k.writeVarSlice(r[t]),k.writeUInt32(m.sequence)}else k.writeUInt32(t);if(s){const m=te.BufferWriter.withCapacity(Fe(s));m.writeVarSlice(s),k.writeSlice(me.sha256(m.end()))}return d&&k.writeSlice(P),c&&(k.writeSlice(c),k.writeUInt8(0),k.writeUInt32(4294967295)),me.taggedHash("TapSighash",E.concat([E.from([0]),k.end()]))}hashForWitnessV0(t,r,n,i){He(K.tuple(K.UInt32,K.Buffer,K.Satoshi,K.UInt32),arguments);let c=E.from([]),s,a=On,p=On,w=On;if(i&L.SIGHASH_ANYONECANPAY||(c=E.allocUnsafe(36*this.ins.length),s=new te.BufferWriter(c,0),this.ins.forEach(d=>{s.writeSlice(d.hash),s.writeUInt32(d.index)}),p=me.hash256(c)),!(i&L.SIGHASH_ANYONECANPAY)&&(i&31)!==L.SIGHASH_SINGLE&&(i&31)!==L.SIGHASH_NONE&&(c=E.allocUnsafe(4*this.ins.length),s=new te.BufferWriter(c,0),this.ins.forEach(d=>{s.writeUInt32(d.sequence)}),w=me.hash256(c)),(i&31)!==L.SIGHASH_SINGLE&&(i&31)!==L.SIGHASH_NONE){const d=this.outs.reduce((S,y)=>S+8+Fe(y.script),0);c=E.allocUnsafe(d),s=new te.BufferWriter(c,0),this.outs.forEach(S=>{s.writeUInt64(S.value),s.writeVarSlice(S.script)}),a=me.hash256(c)}else if((i&31)===L.SIGHASH_SINGLE&&t<this.outs.length){const d=this.outs[t];c=E.allocUnsafe(8+Fe(d.script)),s=new te.BufferWriter(c,0),s.writeUInt64(d.value),s.writeVarSlice(d.script),a=me.hash256(c)}c=E.allocUnsafe(156+Fe(r)),s=new te.BufferWriter(c,0);const f=this.ins[t];return s.writeInt32(this.version),s.writeSlice(p),s.writeSlice(w),s.writeSlice(f.hash),s.writeUInt32(f.index),s.writeVarSlice(r),s.writeUInt64(n),s.writeUInt32(f.sequence),s.writeSlice(a),s.writeUInt32(this.locktime),s.writeUInt32(i),me.hash256(c)}getHash(t){return t&&this.isCoinbase()?E.alloc(32,0):me.hash256(this.__toBuffer(void 0,void 0,t))}getId(){return(0,te.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){He(K.tuple(K.Number,K.Buffer),arguments),this.ins[t].script=r}setWitness(t,r){He(K.tuple(K.Number,[K.Buffer]),arguments),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=E.allocUnsafe(this.byteLength(n)));const i=new te.BufferWriter(t,r||0);i.writeInt32(this.version);const c=n&&this.hasWitnesses();return c&&(i.writeUInt8(L.ADVANCED_TRANSACTION_MARKER),i.writeUInt8(L.ADVANCED_TRANSACTION_FLAG)),i.writeVarInt(this.ins.length),this.ins.forEach(s=>{i.writeSlice(s.hash),i.writeUInt32(s.index),i.writeVarSlice(s.script),i.writeUInt32(s.sequence)}),i.writeVarInt(this.outs.length),this.outs.forEach(s=>{Lu(s)?i.writeUInt64(s.value):i.writeSlice(s.valueBuffer),i.writeVarSlice(s.script)}),c&&this.ins.forEach(s=>{i.writeVector(s.witness)}),i.writeUInt32(this.locktime),r!==void 0?t.slice(r,i.offset):t}}lt.Transaction=L;L.DEFAULT_SEQUENCE=4294967295;L.SIGHASH_DEFAULT=0;L.SIGHASH_ALL=1;L.SIGHASH_NONE=2;L.SIGHASH_SINGLE=3;L.SIGHASH_ANYONECANPAY=128;L.SIGHASH_OUTPUT_MASK=3;L.SIGHASH_INPUT_MASK=128;L.ADVANCED_TRANSACTION_MARKER=0;L.ADVANCED_TRANSACTION_FLAG=1;Object.defineProperty(nn,"__esModule",{value:!0});nn.Block=void 0;const yt=oe,Pn=Ke,$u=on,Mu=lt,Mo=de,{typeforce:Ku}=Mo,vn=new TypeError("Cannot compute merkle root for zero transactions"),qi=new TypeError("Cannot compute witness commit for non-segwit block");class wt{constructor(){this.version=1,this.prevHash=void 0,this.merkleRoot=void 0,this.timestamp=0,this.witnessCommit=void 0,this.bits=0,this.nonce=0,this.transactions=void 0}static fromBuffer(t){if(t.length<80)throw new Error("Buffer too small (< 80 bytes)");const r=new yt.BufferReader(t),n=new wt;if(n.version=r.readInt32(),n.prevHash=r.readSlice(32),n.merkleRoot=r.readSlice(32),n.timestamp=r.readUInt32(),n.bits=r.readUInt32(),n.nonce=r.readUInt32(),t.length===80)return n;const i=()=>{const a=Mu.Transaction.fromBuffer(r.buffer.slice(r.offset),!0);return r.offset+=a.byteLength(),a},c=r.readVarInt();n.transactions=[];for(let a=0;a<c;++a){const p=i();n.transactions.push(p)}const s=n.getWitnessCommit();return s&&(n.witnessCommit=s),n}static fromHex(t){return wt.fromBuffer(E.from(t,"hex"))}static calculateTarget(t){const r=((t&4278190080)>>24)-3,n=t&8388607,i=E.alloc(32,0);return i.writeUIntBE(n,29-r,3),i}static calculateMerkleRoot(t,r){if(Ku([{getHash:Mo.Function}],t),t.length===0)throw vn;if(r&&!zi(t))throw qi;const n=t.map(c=>c.getHash(r)),i=(0,$u.fastMerkleRoot)(n,Pn.hash256);return r?Pn.hash256(E.concat([i,t[0].ins[0].witness[0]])):i}getWitnessCommit(){if(!zi(this.transactions))return null;const t=this.transactions[0].outs.filter(n=>n.script.slice(0,6).equals(E.from("6a24aa21a9ed","hex"))).map(n=>n.script.slice(6,38));if(t.length===0)return null;const r=t[t.length-1];return r instanceof E&&r.length===32?r:null}hasWitnessCommit(){return this.witnessCommit instanceof E&&this.witnessCommit.length===32||this.getWitnessCommit()!==null}hasWitness(){return Du(this.transactions)}weight(){const t=this.byteLength(!1,!1),r=this.byteLength(!1,!0);return t*3+r}byteLength(t,r=!0){return t||!this.transactions?80:80+yt.varuint.encodingLength(this.transactions.length)+this.transactions.reduce((n,i)=>n+i.byteLength(r),0)}getHash(){return Pn.hash256(this.toBuffer(!0))}getId(){return(0,yt.reverseBuffer)(this.getHash()).toString("hex")}getUTCDate(){const t=new Date(0);return t.setUTCSeconds(this.timestamp),t}toBuffer(t){const r=E.allocUnsafe(this.byteLength(t)),n=new yt.BufferWriter(r);return n.writeInt32(this.version),n.writeSlice(this.prevHash),n.writeSlice(this.merkleRoot),n.writeUInt32(this.timestamp),n.writeUInt32(this.bits),n.writeUInt32(this.nonce),t||!this.transactions||(yt.varuint.encode(this.transactions.length,r,n.offset),n.offset+=yt.varuint.encode.bytes,this.transactions.forEach(i=>{const c=i.byteLength();i.toBuffer(r,n.offset),n.offset+=c})),r}toHex(t){return this.toBuffer(t).toString("hex")}checkTxRoots(){const t=this.hasWitnessCommit();return!t&&this.hasWitness()?!1:this.__checkMerkleRoot()&&(t?this.__checkWitnessCommit():!0)}checkProofOfWork(){const t=(0,yt.reverseBuffer)(this.getHash()),r=wt.calculateTarget(this.bits);return t.compare(r)<=0}__checkMerkleRoot(){if(!this.transactions)throw vn;const t=wt.calculateMerkleRoot(this.transactions);return this.merkleRoot.compare(t)===0}__checkWitnessCommit(){if(!this.transactions)throw vn;if(!this.hasWitnessCommit())throw qi;const t=wt.calculateMerkleRoot(this.transactions,!0);return this.witnessCommit.compare(t)===0}}nn.Block=wt;function zi(e){return e instanceof Array&&e[0]&&e[0].ins&&e[0].ins instanceof Array&&e[0].ins[0]&&e[0].ins[0].witness&&e[0].ins[0].witness instanceof Array&&e[0].ins[0].witness.length>0}function Du(e){return e instanceof Array&&e.some(t=>typeof t=="object"&&t.ins instanceof Array&&t.ins.some(r=>typeof r=="object"&&r.witness instanceof Array&&r.witness.length>0))}var sn={},ni={},ii={},oi={},Sr={},St={},fe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),function(t){t[t.UNSIGNED_TX=0]="UNSIGNED_TX",t[t.GLOBAL_XPUB=1]="GLOBAL_XPUB"}(e.GlobalTypes||(e.GlobalTypes={})),e.GLOBAL_TYPE_NAMES=["unsignedTx","globalXpub"],function(t){t[t.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",t[t.WITNESS_UTXO=1]="WITNESS_UTXO",t[t.PARTIAL_SIG=2]="PARTIAL_SIG",t[t.SIGHASH_TYPE=3]="SIGHASH_TYPE",t[t.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=6]="BIP32_DERIVATION",t[t.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",t[t.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",t[t.POR_COMMITMENT=9]="POR_COMMITMENT",t[t.TAP_KEY_SIG=19]="TAP_KEY_SIG",t[t.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",t[t.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",t[t.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",t[t.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"}(e.InputTypes||(e.InputTypes={})),e.INPUT_TYPE_NAMES=["nonWitnessUtxo","witnessUtxo","partialSig","sighashType","redeemScript","witnessScript","bip32Derivation","finalScriptSig","finalScriptWitness","porCommitment","tapKeySig","tapScriptSig","tapLeafScript","tapBip32Derivation","tapInternalKey","tapMerkleRoot"],function(t){t[t.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",t[t.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",t[t.BIP32_DERIVATION=2]="BIP32_DERIVATION",t[t.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",t[t.TAP_TREE=6]="TAP_TREE",t[t.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"}(e.OutputTypes||(e.OutputTypes={})),e.OUTPUT_TYPE_NAMES=["redeemScript","witnessScript","bip32Derivation","tapInternalKey","tapTree","tapBip32Derivation"]})(fe);var bt={};Object.defineProperty(bt,"__esModule",{value:!0});const Ko=fe,Wu=e=>[...Array(e).keys()];function ju(e){if(e.key[0]!==Ko.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+e.key.toString("hex"));if(e.key.length!==79||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+e.key.toString("hex"));if(e.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),r={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const n of Wu(e.value.length/4-1)){const i=e.value.readUInt32LE(n*4+4),c=!!(i&2147483648),s=i&2147483647;r.path+="/"+s.toString(10)+(c?"'":"")}return r}bt.decode=ju;function Vu(e){const t=E.from([Ko.GlobalTypes.GLOBAL_XPUB]),r=E.concat([t,e.extendedPubkey]),n=e.path.split("/"),i=E.allocUnsafe(n.length*4);e.masterFingerprint.copy(i,0);let c=4;return n.slice(1).forEach(s=>{const a=s.slice(-1)==="'";let p=2147483647&parseInt(a?s.slice(0,-1):s,10);a&&(p+=2147483648),i.writeUInt32LE(p,c),c+=4}),{key:r,value:i}}bt.encode=Vu;bt.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }";function Gu(e){const t=e.extendedPubkey,r=e.masterFingerprint,n=e.path;return E.isBuffer(t)&&t.length===78&&[2,3].indexOf(t[45])>-1&&E.isBuffer(r)&&r.length===4&&typeof n=="string"&&!!n.match(/^m(\/\d+'?)*$/)}bt.check=Gu;function Xu(e,t,r){const n=t.extendedPubkey.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.extendedPubkey.equals(t.extendedPubkey)).length===0)}bt.canAddToArray=Xu;var si={};Object.defineProperty(si,"__esModule",{value:!0});const qu=fe;function zu(e){return{key:E.from([qu.GlobalTypes.UNSIGNED_TX]),value:e.toBuffer()}}si.encode=zu;var _t={};Object.defineProperty(_t,"__esModule",{value:!0});const Do=fe;function Yu(e){if(e.key[0]!==Do.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+e.key.toString("hex"));return e.value}_t.decode=Yu;function Ju(e){return{key:E.from([Do.InputTypes.FINAL_SCRIPTSIG]),value:e}}_t.encode=Ju;_t.expected="Buffer";function Qu(e){return E.isBuffer(e)}_t.check=Qu;function Zu(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}_t.canAdd=Zu;var Tt={};Object.defineProperty(Tt,"__esModule",{value:!0});const Wo=fe;function ea(e){if(e.key[0]!==Wo.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+e.key.toString("hex"));return e.value}Tt.decode=ea;function ta(e){return{key:E.from([Wo.InputTypes.FINAL_SCRIPTWITNESS]),value:e}}Tt.encode=ta;Tt.expected="Buffer";function ra(e){return E.isBuffer(e)}Tt.check=ra;function na(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}Tt.canAdd=na;var It={};Object.defineProperty(It,"__esModule",{value:!0});const jo=fe;function ia(e){if(e.key[0]!==jo.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+e.key.toString("hex"));return e.value}It.decode=ia;function oa(e){return{key:E.from([jo.InputTypes.NON_WITNESS_UTXO]),value:e}}It.encode=oa;It.expected="Buffer";function sa(e){return E.isBuffer(e)}It.check=sa;function ca(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}It.canAdd=ca;var kt={};Object.defineProperty(kt,"__esModule",{value:!0});const Vo=fe;function ua(e){if(e.key[0]!==Vo.InputTypes.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+e.key.toString("hex"));if(!(e.key.length===34||e.key.length===66)||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+e.key.toString("hex"));return{pubkey:e.key.slice(1),signature:e.value}}kt.decode=ua;function aa(e){const t=E.from([Vo.InputTypes.PARTIAL_SIG]);return{key:E.concat([t,e.pubkey]),value:e.signature}}kt.encode=aa;kt.expected="{ pubkey: Buffer; signature: Buffer; }";function fa(e){return E.isBuffer(e.pubkey)&&E.isBuffer(e.signature)&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&ha(e.signature)}kt.check=fa;function ha(e){if(!E.isBuffer(e)||e.length<9||e[0]!==48||e.length!==e[1]+3||e[2]!==2)return!1;const t=e[3];if(t>33||t<1||e[3+t+1]!==2)return!1;const r=e[3+t+2];return!(r>33||r<1||e.length!==3+t+2+r+2)}function pa(e,t,r){const n=t.pubkey.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.pubkey.equals(t.pubkey)).length===0)}kt.canAddToArray=pa;var At={};Object.defineProperty(At,"__esModule",{value:!0});const Go=fe;function la(e){if(e.key[0]!==Go.InputTypes.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+e.key.toString("hex"));return e.value.toString("utf8")}At.decode=la;function da(e){return{key:E.from([Go.InputTypes.POR_COMMITMENT]),value:E.from(e,"utf8")}}At.encode=da;At.expected="string";function ya(e){return typeof e=="string"}At.check=ya;function wa(e,t){return!!e&&!!t&&e.porCommitment===void 0}At.canAdd=wa;var Ot={};Object.defineProperty(Ot,"__esModule",{value:!0});const Xo=fe;function ga(e){if(e.key[0]!==Xo.InputTypes.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+e.key.toString("hex"));return e.value.readUInt32LE(0)}Ot.decode=ga;function Ea(e){const t=E.from([Xo.InputTypes.SIGHASH_TYPE]),r=E.allocUnsafe(4);return r.writeUInt32LE(e,0),{key:t,value:r}}Ot.encode=Ea;Ot.expected="number";function ma(e){return typeof e=="number"}Ot.check=ma;function Sa(e,t){return!!e&&!!t&&e.sighashType===void 0}Ot.canAdd=Sa;var Pt={};Object.defineProperty(Pt,"__esModule",{value:!0});const qo=fe;function ba(e){if(e.key[0]!==qo.InputTypes.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+e.key.toString("hex"));if(!zo(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}Pt.decode=ba;function _a(e){return{key:E.from([qo.InputTypes.TAP_KEY_SIG]),value:e}}Pt.encode=_a;Pt.expected="Buffer";function zo(e){return E.isBuffer(e)&&(e.length===64||e.length===65)}Pt.check=zo;function Ta(e,t){return!!e&&!!t&&e.tapKeySig===void 0}Pt.canAdd=Ta;var vt={};Object.defineProperty(vt,"__esModule",{value:!0});const Yo=fe;function Ia(e){if(e.key[0]!==Yo.InputTypes.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+e.key.toString("hex"));if((e.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+e.key.toString("hex"));const t=e.value[e.value.length-1];if((e.key[1]&254)!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+e.key.toString("hex"));const r=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:r,leafVersion:t}}vt.decode=Ia;function ka(e){const t=E.from([Yo.InputTypes.TAP_LEAF_SCRIPT]),r=E.from([e.leafVersion]);return{key:E.concat([t,e.controlBlock]),value:E.concat([e.script,r])}}vt.encode=ka;vt.expected="{ controlBlock: Buffer; leafVersion: number, script: Buffer; }";function Aa(e){return E.isBuffer(e.controlBlock)&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&E.isBuffer(e.script)}vt.check=Aa;function Oa(e,t,r){const n=t.controlBlock.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.controlBlock.equals(t.controlBlock)).length===0)}vt.canAddToArray=Oa;var Bt={};Object.defineProperty(Bt,"__esModule",{value:!0});const Jo=fe;function Pa(e){if(e.key[0]!==Jo.InputTypes.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+e.key.toString("hex"));if(!Qo(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}Bt.decode=Pa;function va(e){return{key:E.from([Jo.InputTypes.TAP_MERKLE_ROOT]),value:e}}Bt.encode=va;Bt.expected="Buffer";function Qo(e){return E.isBuffer(e)&&e.length===32}Bt.check=Qo;function Ba(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}Bt.canAdd=Ba;var xt={};Object.defineProperty(xt,"__esModule",{value:!0});const Zo=fe;function xa(e){if(e.key[0]!==Zo.InputTypes.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+e.key.toString("hex"));if(e.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+e.key.toString("hex"));if(e.value.length!==64&&e.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+e.key.toString("hex"));const t=e.key.slice(1,33),r=e.key.slice(33);return{pubkey:t,leafHash:r,signature:e.value}}xt.decode=xa;function Ua(e){const t=E.from([Zo.InputTypes.TAP_SCRIPT_SIG]);return{key:E.concat([t,e.pubkey,e.leafHash]),value:e.signature}}xt.encode=Ua;xt.expected="{ pubkey: Buffer; leafHash: Buffer; signature: Buffer; }";function Na(e){return E.isBuffer(e.pubkey)&&E.isBuffer(e.leafHash)&&E.isBuffer(e.signature)&&e.pubkey.length===32&&e.leafHash.length===32&&(e.signature.length===64||e.signature.length===65)}xt.check=Na;function Ca(e,t,r){const n=t.pubkey.toString("hex")+t.leafHash.toString("hex");return r.has(n)?!1:(r.add(n),e.filter(i=>i.pubkey.equals(t.pubkey)&&i.leafHash.equals(t.leafHash)).length===0)}xt.canAddToArray=Ca;var Ut={},De={},xe={};Object.defineProperty(xe,"__esModule",{value:!0});const Ha=9007199254740991;function ci(e){if(e<0||e>Ha||e%1!==0)throw new RangeError("value out of range")}function fr(e,t,r){if(ci(e),t||(t=E.allocUnsafe(es(e))),!E.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");return r||(r=0),e<253?(t.writeUInt8(e,r),Object.assign(fr,{bytes:1})):e<=65535?(t.writeUInt8(253,r),t.writeUInt16LE(e,r+1),Object.assign(fr,{bytes:3})):e<=4294967295?(t.writeUInt8(254,r),t.writeUInt32LE(e,r+1),Object.assign(fr,{bytes:5})):(t.writeUInt8(255,r),t.writeUInt32LE(e>>>0,r+1),t.writeUInt32LE(e/4294967296|0,r+5),Object.assign(fr,{bytes:9})),t}xe.encode=fr;function hr(e,t){if(!E.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(hr,{bytes:1}),r;if(r===253)return Object.assign(hr,{bytes:3}),e.readUInt16LE(t+1);if(r===254)return Object.assign(hr,{bytes:5}),e.readUInt32LE(t+1);{Object.assign(hr,{bytes:9});const n=e.readUInt32LE(t+1),c=e.readUInt32LE(t+5)*4294967296+n;return ci(c),c}}xe.decode=hr;function es(e){return ci(e),e<253?1:e<=65535?3:e<=4294967295?5:9}xe.encodingLength=es;Object.defineProperty(De,"__esModule",{value:!0});const Pr=xe;De.range=e=>[...Array(e).keys()];function Ra(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}De.reverseBuffer=Ra;function Fa(e){const t=e.map(ts);return t.push(E.from([0])),E.concat(t)}De.keyValsToBuffer=Fa;function ts(e){const t=e.key.length,r=e.value.length,n=Pr.encodingLength(t),i=Pr.encodingLength(r),c=E.allocUnsafe(n+t+i+r);return Pr.encode(t,c,0),e.key.copy(c,n),Pr.encode(r,c,n+t),e.value.copy(c,n+t+i),c}De.keyValToBuffer=ts;function rs(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 La(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,rs(n+r,9007199254740991),n+r}De.readUInt64LE=La;function $a(e,t,r){return rs(t,9007199254740991),e.writeInt32LE(t&-1,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}De.writeUInt64LE=$a;Object.defineProperty(Ut,"__esModule",{value:!0});const ns=fe,is=De,Mr=xe;function Ma(e){if(e.key[0]!==ns.InputTypes.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+e.key.toString("hex"));const t=is.readUInt64LE(e.value,0);let r=8;const n=Mr.decode(e.value,r);r+=Mr.encodingLength(n);const i=e.value.slice(r);if(i.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:i,value:t}}Ut.decode=Ma;function Ka(e){const{script:t,value:r}=e,n=Mr.encodingLength(t.length),i=E.allocUnsafe(8+n+t.length);return is.writeUInt64LE(i,r,0),Mr.encode(t.length,i,8),t.copy(i,8+n),{key:E.from([ns.InputTypes.WITNESS_UTXO]),value:i}}Ut.encode=Ka;Ut.expected="{ script: Buffer; value: number; }";function Da(e){return E.isBuffer(e.script)&&typeof e.value=="number"}Ut.check=Da;function Wa(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}Ut.canAdd=Wa;var Nt={};Object.defineProperty(Nt,"__esModule",{value:!0});const os=fe,Mn=xe;function ja(e){if(e.key[0]!==os.OutputTypes.TAP_TREE||e.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+e.key.toString("hex"));let t=0;const r=[];for(;t<e.value.length;){const n=e.value[t++],i=e.value[t++],c=Mn.decode(e.value,t);t+=Mn.encodingLength(c),r.push({depth:n,leafVersion:i,script:e.value.slice(t,t+c)}),t+=c}return{leaves:r}}Nt.decode=ja;function Va(e){const t=E.from([os.OutputTypes.TAP_TREE]),r=[].concat(...e.leaves.map(n=>[E.of(n.depth,n.leafVersion),Mn.encode(n.script.length),n.script]));return{key:t,value:E.concat(r)}}Nt.encode=Va;Nt.expected="{ leaves: [{ depth: number; leafVersion: number, script: Buffer; }] }";function Ga(e){return Array.isArray(e.leaves)&&e.leaves.every(t=>t.depth>=0&&t.depth<=128&&(t.leafVersion&254)===t.leafVersion&&E.isBuffer(t.script))}Nt.check=Ga;function Xa(e,t){return!!e&&!!t&&e.tapTree===void 0}Nt.canAdd=Xa;var cn={};Object.defineProperty(cn,"__esModule",{value:!0});const qa=e=>[...Array(e).keys()],za=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function Ya(e,t=za){function r(a){if(a.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+a.key.toString("hex"));const p=a.key.slice(1);if(!t(p))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+a.key.toString("hex"));if(a.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const w={masterFingerprint:a.value.slice(0,4),pubkey:p,path:"m"};for(const f of qa(a.value.length/4-1)){const d=a.value.readUInt32LE(f*4+4),S=!!(d&2147483648),y=d&2147483647;w.path+="/"+y.toString(10)+(S?"'":"")}return w}function n(a){const p=E.from([e]),w=E.concat([p,a.pubkey]),f=a.path.split("/"),d=E.allocUnsafe(f.length*4);a.masterFingerprint.copy(d,0);let S=4;return f.slice(1).forEach(y=>{const _=y.slice(-1)==="'";let T=2147483647&parseInt(_?y.slice(0,-1):y,10);_&&(T+=2147483648),d.writeUInt32LE(T,S),S+=4}),{key:w,value:d}}const i="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; }";function c(a){return E.isBuffer(a.pubkey)&&E.isBuffer(a.masterFingerprint)&&typeof a.path=="string"&&t(a.pubkey)&&a.masterFingerprint.length===4}function s(a,p,w){const f=p.pubkey.toString("hex");return w.has(f)?!1:(w.add(f),a.filter(d=>d.pubkey.equals(p.pubkey)).length===0)}return{decode:r,encode:n,check:c,expected:i,canAddToArray:s}}cn.makeConverter=Ya;var ui={};Object.defineProperty(ui,"__esModule",{value:!0});function Ja(e){return t;function t(r){let n;if(e.includes(r.key[0])&&(n=r.key.slice(1),!(n.length===33||n.length===65)||![2,3,4].includes(n[0])))throw new Error("Format Error: invalid pubkey in key 0x"+r.key.toString("hex"));return n}}ui.makeChecker=Ja;var ai={};Object.defineProperty(ai,"__esModule",{value:!0});function Qa(e){function t(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+s.key.toString("hex"));return s.value}function r(s){return{key:E.from([e]),value:s}}const n="Buffer";function i(s){return E.isBuffer(s)}function c(s,a){return!!s&&!!a&&s.redeemScript===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:c}}ai.makeConverter=Qa;var fi={};Object.defineProperty(fi,"__esModule",{value:!0});const vr=xe,Za=cn,ef=e=>e.length===32;function tf(e){const t=Za.makeConverter(e,ef);function r(s){const a=vr.decode(s.value),p=vr.encodingLength(a),w=t.decode({key:s.key,value:s.value.slice(p+a*32)}),f=new Array(a);for(let d=0,S=p;d<a;d++,S+=32)f[d]=s.value.slice(S,S+32);return Object.assign({},w,{leafHashes:f})}function n(s){const a=t.encode(s),p=vr.encodingLength(s.leafHashes.length),w=E.allocUnsafe(p);vr.encode(s.leafHashes.length,w);const f=E.concat([w,...s.leafHashes,a.value]);return Object.assign({},a,{value:f})}const i="{ masterFingerprint: Buffer; pubkey: Buffer; path: string; leafHashes: Buffer[]; }";function c(s){return Array.isArray(s.leafHashes)&&s.leafHashes.every(a=>E.isBuffer(a)&&a.length===32)&&t.check(s)}return{decode:r,encode:n,check:c,expected:i,canAddToArray:t.canAddToArray}}fi.makeConverter=tf;var hi={};Object.defineProperty(hi,"__esModule",{value:!0});function rf(e){function t(s){if(s.key[0]!==e||s.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+s.key.toString("hex"));if(s.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return s.value}function r(s){return{key:E.from([e]),value:s}}const n="Buffer";function i(s){return E.isBuffer(s)&&s.length===32}function c(s,a){return!!s&&!!a&&s.tapInternalKey===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:c}}hi.makeConverter=rf;var pi={};Object.defineProperty(pi,"__esModule",{value:!0});function nf(e){function t(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+s.key.toString("hex"));return s.value}function r(s){return{key:E.from([e]),value:s}}const n="Buffer";function i(s){return E.isBuffer(s)}function c(s,a){return!!s&&!!a&&s.witnessScript===void 0}return{decode:t,encode:r,check:i,expected:n,canAdd:c}}pi.makeConverter=nf;Object.defineProperty(St,"__esModule",{value:!0});const Ie=fe,of=bt,sf=si,cf=_t,uf=Tt,af=It,ff=kt,hf=At,pf=Ot,lf=Pt,df=vt,yf=Bt,wf=xt,gf=Ut,Ef=Nt,ss=cn,li=ui,cs=ai,us=fi,as=hi,fs=pi,mf={unsignedTx:sf,globalXpub:of,checkPubkey:li.makeChecker([])};St.globals=mf;const Sf={nonWitnessUtxo:af,partialSig:ff,sighashType:pf,finalScriptSig:cf,finalScriptWitness:uf,porCommitment:hf,witnessUtxo:gf,bip32Derivation:ss.makeConverter(Ie.InputTypes.BIP32_DERIVATION),redeemScript:cs.makeConverter(Ie.InputTypes.REDEEM_SCRIPT),witnessScript:fs.makeConverter(Ie.InputTypes.WITNESS_SCRIPT),checkPubkey:li.makeChecker([Ie.InputTypes.PARTIAL_SIG,Ie.InputTypes.BIP32_DERIVATION]),tapKeySig:lf,tapScriptSig:wf,tapLeafScript:df,tapBip32Derivation:us.makeConverter(Ie.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:as.makeConverter(Ie.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:yf};St.inputs=Sf;const bf={bip32Derivation:ss.makeConverter(Ie.OutputTypes.BIP32_DERIVATION),redeemScript:cs.makeConverter(Ie.OutputTypes.REDEEM_SCRIPT),witnessScript:fs.makeConverter(Ie.OutputTypes.WITNESS_SCRIPT),checkPubkey:li.makeChecker([Ie.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:us.makeConverter(Ie.OutputTypes.TAP_BIP32_DERIVATION),tapTree:Ef,tapInternalKey:as.makeConverter(Ie.OutputTypes.TAP_INTERNAL_KEY)};St.outputs=bf;Object.defineProperty(Sr,"__esModule",{value:!0});const q=St,Kr=De,Yi=xe,H=fe;function _f(e,t){let r=0;function n(){const P=Yi.decode(e,r);r+=Yi.encodingLength(P);const x=e.slice(r,r+P);return r+=P,x}function i(){const P=e.readUInt32BE(r);return r+=4,P}function c(){const P=e.readUInt8(r);return r+=1,P}function s(){const P=n(),x=n();return{key:P,value:x}}function a(){if(r>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const P=e.readUInt8(r)===0;return P&&r++,P}if(i()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(c()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const p=[],w={};for(;!a();){const P=s(),x=P.key.toString("hex");if(w[x])throw new Error("Format Error: Keys must be unique for global keymap: key "+x);w[x]=1,p.push(P)}const f=p.filter(P=>P.key[0]===H.GlobalTypes.UNSIGNED_TX);if(f.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const d=t(f[0].value),{inputCount:S,outputCount:y}=d.getInputOutputCounts(),_=[],T=[];for(const P of Kr.range(S)){const x={},N=[];for(;!a();){const k=s(),m=k.key.toString("hex");if(x[m])throw new Error("Format Error: Keys must be unique for each input: input index "+P+" key "+m);x[m]=1,N.push(k)}_.push(N)}for(const P of Kr.range(y)){const x={},N=[];for(;!a();){const k=s(),m=k.key.toString("hex");if(x[m])throw new Error("Format Error: Keys must be unique for each output: output index "+P+" key "+m);x[m]=1,N.push(k)}T.push(N)}return hs(d,{globalMapKeyVals:p,inputKeyVals:_,outputKeyVals:T})}Sr.psbtFromBuffer=_f;function pe(e,t,r){if(!t.equals(E.from([r])))throw new Error(`Format Error: Invalid ${e} key: ${t.toString("hex")}`)}Sr.checkKeyBuffer=pe;function hs(e,{globalMapKeyVals:t,inputKeyVals:r,outputKeyVals:n}){const i={unsignedTx:e};let c=0;for(const f of t)switch(f.key[0]){case H.GlobalTypes.UNSIGNED_TX:if(pe("global",f.key,H.GlobalTypes.UNSIGNED_TX),c>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");c++;break;case H.GlobalTypes.GLOBAL_XPUB:i.globalXpub===void 0&&(i.globalXpub=[]),i.globalXpub.push(q.globals.globalXpub.decode(f));break;default:i.unknownKeyVals||(i.unknownKeyVals=[]),i.unknownKeyVals.push(f)}const s=r.length,a=n.length,p=[],w=[];for(const f of Kr.range(s)){const d={};for(const S of r[f])switch(q.inputs.checkPubkey(S),S.key[0]){case H.InputTypes.NON_WITNESS_UTXO:if(pe("input",S.key,H.InputTypes.NON_WITNESS_UTXO),d.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");d.nonWitnessUtxo=q.inputs.nonWitnessUtxo.decode(S);break;case H.InputTypes.WITNESS_UTXO:if(pe("input",S.key,H.InputTypes.WITNESS_UTXO),d.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");d.witnessUtxo=q.inputs.witnessUtxo.decode(S);break;case H.InputTypes.PARTIAL_SIG:d.partialSig===void 0&&(d.partialSig=[]),d.partialSig.push(q.inputs.partialSig.decode(S));break;case H.InputTypes.SIGHASH_TYPE:if(pe("input",S.key,H.InputTypes.SIGHASH_TYPE),d.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");d.sighashType=q.inputs.sighashType.decode(S);break;case H.InputTypes.REDEEM_SCRIPT:if(pe("input",S.key,H.InputTypes.REDEEM_SCRIPT),d.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");d.redeemScript=q.inputs.redeemScript.decode(S);break;case H.InputTypes.WITNESS_SCRIPT:if(pe("input",S.key,H.InputTypes.WITNESS_SCRIPT),d.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");d.witnessScript=q.inputs.witnessScript.decode(S);break;case H.InputTypes.BIP32_DERIVATION:d.bip32Derivation===void 0&&(d.bip32Derivation=[]),d.bip32Derivation.push(q.inputs.bip32Derivation.decode(S));break;case H.InputTypes.FINAL_SCRIPTSIG:pe("input",S.key,H.InputTypes.FINAL_SCRIPTSIG),d.finalScriptSig=q.inputs.finalScriptSig.decode(S);break;case H.InputTypes.FINAL_SCRIPTWITNESS:pe("input",S.key,H.InputTypes.FINAL_SCRIPTWITNESS),d.finalScriptWitness=q.inputs.finalScriptWitness.decode(S);break;case H.InputTypes.POR_COMMITMENT:pe("input",S.key,H.InputTypes.POR_COMMITMENT),d.porCommitment=q.inputs.porCommitment.decode(S);break;case H.InputTypes.TAP_KEY_SIG:pe("input",S.key,H.InputTypes.TAP_KEY_SIG),d.tapKeySig=q.inputs.tapKeySig.decode(S);break;case H.InputTypes.TAP_SCRIPT_SIG:d.tapScriptSig===void 0&&(d.tapScriptSig=[]),d.tapScriptSig.push(q.inputs.tapScriptSig.decode(S));break;case H.InputTypes.TAP_LEAF_SCRIPT:d.tapLeafScript===void 0&&(d.tapLeafScript=[]),d.tapLeafScript.push(q.inputs.tapLeafScript.decode(S));break;case H.InputTypes.TAP_BIP32_DERIVATION:d.tapBip32Derivation===void 0&&(d.tapBip32Derivation=[]),d.tapBip32Derivation.push(q.inputs.tapBip32Derivation.decode(S));break;case H.InputTypes.TAP_INTERNAL_KEY:pe("input",S.key,H.InputTypes.TAP_INTERNAL_KEY),d.tapInternalKey=q.inputs.tapInternalKey.decode(S);break;case H.InputTypes.TAP_MERKLE_ROOT:pe("input",S.key,H.InputTypes.TAP_MERKLE_ROOT),d.tapMerkleRoot=q.inputs.tapMerkleRoot.decode(S);break;default:d.unknownKeyVals||(d.unknownKeyVals=[]),d.unknownKeyVals.push(S)}p.push(d)}for(const f of Kr.range(a)){const d={};for(const S of n[f])switch(q.outputs.checkPubkey(S),S.key[0]){case H.OutputTypes.REDEEM_SCRIPT:if(pe("output",S.key,H.OutputTypes.REDEEM_SCRIPT),d.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");d.redeemScript=q.outputs.redeemScript.decode(S);break;case H.OutputTypes.WITNESS_SCRIPT:if(pe("output",S.key,H.OutputTypes.WITNESS_SCRIPT),d.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");d.witnessScript=q.outputs.witnessScript.decode(S);break;case H.OutputTypes.BIP32_DERIVATION:d.bip32Derivation===void 0&&(d.bip32Derivation=[]),d.bip32Derivation.push(q.outputs.bip32Derivation.decode(S));break;case H.OutputTypes.TAP_INTERNAL_KEY:pe("output",S.key,H.OutputTypes.TAP_INTERNAL_KEY),d.tapInternalKey=q.outputs.tapInternalKey.decode(S);break;case H.OutputTypes.TAP_TREE:pe("output",S.key,H.OutputTypes.TAP_TREE),d.tapTree=q.outputs.tapTree.decode(S);break;case H.OutputTypes.TAP_BIP32_DERIVATION:d.tapBip32Derivation===void 0&&(d.tapBip32Derivation=[]),d.tapBip32Derivation.push(q.outputs.tapBip32Derivation.decode(S));break;default:d.unknownKeyVals||(d.unknownKeyVals=[]),d.unknownKeyVals.push(S)}w.push(d)}return{globalMap:i,inputs:p,outputs:w}}Sr.psbtFromKeyVals=hs;var un={};Object.defineProperty(un,"__esModule",{value:!0});const Bn=St,Ji=De;function Tf({globalMap:e,inputs:t,outputs:r}){const{globalKeyVals:n,inputKeyVals:i,outputKeyVals:c}=ps({globalMap:e,inputs:t,outputs:r}),s=Ji.keyValsToBuffer(n),a=d=>d.length===0?[E.from([0])]:d.map(Ji.keyValsToBuffer),p=a(i),w=a(c),f=E.allocUnsafe(5);return f.writeUIntBE(482972169471,0,5),E.concat([f,s].concat(p,w))}un.psbtToBuffer=Tf;const If=(e,t)=>e.key.compare(t.key);function xn(e,t){const r=new Set,n=Object.entries(e).reduce((c,[s,a])=>{if(s==="unknownKeyVals")return c;const p=t[s];if(p===void 0)return c;const w=(Array.isArray(a)?a:[a]).map(p.encode);return w.map(d=>d.key.toString("hex")).forEach(d=>{if(r.has(d))throw new Error("Serialize Error: Duplicate key: "+d);r.add(d)}),c.concat(w)},[]),i=e.unknownKeyVals?e.unknownKeyVals.filter(c=>!r.has(c.key.toString("hex"))):[];return n.concat(i).sort(If)}function ps({globalMap:e,inputs:t,outputs:r}){return{globalKeyVals:xn(e,Bn.globals),inputKeyVals:t.map(n=>xn(n,Bn.inputs)),outputKeyVals:r.map(n=>xn(n,Bn.outputs))}}un.psbtToKeyVals=ps;(function(e){function t(r){for(var n in r)e.hasOwnProperty(n)||(e[n]=r[n])}Object.defineProperty(e,"__esModule",{value:!0}),t(Sr),t(un)})(oi);Object.defineProperty(ii,"__esModule",{value:!0});const Un=oi;function kf(e){const t=e[0],r=Un.psbtToKeyVals(t),n=e.slice(1);if(n.length===0)throw new Error("Combine: Nothing to combine");const i=Qi(t);if(i===void 0)throw new Error("Combine: Self missing transaction");const c=Mt(r.globalKeyVals),s=r.inputKeyVals.map(Mt),a=r.outputKeyVals.map(Mt);for(const p of n){const w=Qi(p);if(w===void 0||!w.toBuffer().equals(i.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const f=Un.psbtToKeyVals(p);Mt(f.globalKeyVals).forEach(Nn(c,r.globalKeyVals,f.globalKeyVals)),f.inputKeyVals.map(Mt).forEach((_,T)=>_.forEach(Nn(s[T],r.inputKeyVals[T],f.inputKeyVals[T]))),f.outputKeyVals.map(Mt).forEach((_,T)=>_.forEach(Nn(a[T],r.outputKeyVals[T],f.outputKeyVals[T])))}return Un.psbtFromKeyVals(i,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}ii.combine=kf;function Nn(e,t,r){return n=>{if(e.has(n))return;const i=r.filter(c=>c.key.toString("hex")===n)[0];t.push(i),e.add(n)}}function Qi(e){return e.globalMap.unsignedTx}function Mt(e){const t=new Set;return e.forEach(r=>{const n=r.key.toString("hex");if(t.has(n))throw new Error("Combine: KeyValue Map keys should be unique");t.add(n)}),t}var di={};(function(e){Object.defineProperty(e,"__esModule",{value:!0});const t=St;function r(y,_){const T=y[_];if(T===void 0)throw new Error(`No input #${_}`);return T}e.checkForInput=r;function n(y,_){const T=y[_];if(T===void 0)throw new Error(`No output #${_}`);return T}e.checkForOutput=n;function i(y,_,T){if(y.key[0]<T)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(_&&_.filter(P=>P.key.equals(y.key)).length!==0)throw new Error(`Duplicate Key: ${y.key.toString("hex")}`)}e.checkHasKey=i;function c(y){let _=0;return Object.keys(y).forEach(T=>{Number(isNaN(Number(T)))&&_++}),_}e.getEnumLength=c;function s(y,_){let T=!1;if(_.nonWitnessUtxo||_.witnessUtxo){const P=!!_.redeemScript,x=!!_.witnessScript,N=!P||!!_.finalScriptSig,k=!x||!!_.finalScriptWitness,m=!!_.finalScriptSig||!!_.finalScriptWitness;T=N&&k&&m}if(T===!1)throw new Error(`Input #${y} has too much or too little data to clean`)}e.inputCheckUncleanFinalized=s;function a(y,_,T,P){throw new Error(`Data for ${y} key ${_} is incorrect: Expected ${T} and got ${JSON.stringify(P)}`)}function p(y){return(_,T)=>{for(const P of Object.keys(_)){const x=_[P],{canAdd:N,canAddToArray:k,check:m,expected:v}=t[y+"s"][P]||{},I=!!k;if(m)if(I){if(!Array.isArray(x)||T[P]&&!Array.isArray(T[P]))throw new Error(`Key type ${P} must be an array`);x.every(m)||a(y,P,v,x);const C=T[P]||[],M=new Set;if(!x.every(B=>k(C,B,M)))throw new Error("Can not add duplicate data to array");T[P]=C.concat(x)}else{if(m(x)||a(y,P,v,x),!N(T,x))throw new Error(`Can not add duplicate data to ${y}`);T[P]=x}}}}e.updateGlobal=p("global"),e.updateInput=p("input"),e.updateOutput=p("output");function w(y,_){const T=y.length-1,P=r(y,T);e.updateInput(_,P)}e.addInputAttributes=w;function f(y,_){const T=y.length-1,P=n(y,T);e.updateOutput(_,P)}e.addOutputAttributes=f;function d(y,_){if(!E.isBuffer(_)||_.length<4)throw new Error("Set Version: Invalid Transaction");return _.writeUInt32LE(y,0),_}e.defaultVersionSetter=d;function S(y,_){if(!E.isBuffer(_)||_.length<4)throw new Error("Set Locktime: Invalid Transaction");return _.writeUInt32LE(y,_.length-4),_}e.defaultLocktimeSetter=S})(di);Object.defineProperty(ni,"__esModule",{value:!0});const Af=ii,Zi=oi,Cn=fe,he=di;let Of=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,r){const n=E.from(t,"base64");return this.fromBuffer(n,r)}static fromHex(t,r){const n=E.from(t,"hex");return this.fromBuffer(n,r)}static fromBuffer(t,r){const n=Zi.psbtFromBuffer(t,r),i=new this(n.globalMap.unsignedTx);return Object.assign(i,n),i}toBase64(){return this.toBuffer().toString("base64")}toHex(){return this.toBuffer().toString("hex")}toBuffer(){return Zi.psbtToBuffer(this)}updateGlobal(t){return he.updateGlobal(t,this.globalMap),this}updateInput(t,r){const n=he.checkForInput(this.inputs,t);return he.updateInput(r,n),this}updateOutput(t,r){const n=he.checkForOutput(this.outputs,t);return he.updateOutput(r,n),this}addUnknownKeyValToGlobal(t){return he.checkHasKey(t,this.globalMap.unknownKeyVals,he.getEnumLength(Cn.GlobalTypes)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,r){const n=he.checkForInput(this.inputs,t);return he.checkHasKey(r,n.unknownKeyVals,he.getEnumLength(Cn.InputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addUnknownKeyValToOutput(t,r){const n=he.checkForOutput(this.outputs,t);return he.checkHasKey(r,n.unknownKeyVals,he.getEnumLength(Cn.OutputTypes)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const r=t.unknownKeyVals||[],n=this.inputs.length-1;if(!Array.isArray(r))throw new Error("unknownKeyVals must be an Array");return r.forEach(i=>this.addUnknownKeyValToInput(n,i)),he.addInputAttributes(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const r=t.unknownKeyVals||[],n=this.outputs.length-1;if(!Array.isArray(r))throw new Error("unknownKeyVals must be an Array");return r.forEach(i=>this.addUnknownKeyValToOutput(n,i)),he.addOutputAttributes(this.outputs,t),this}clearFinalizedInput(t){const r=he.checkForInput(this.inputs,t);he.inputCheckUncleanFinalized(t,r);for(const n of Object.keys(r))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(n)||delete r[n];return this}combine(...t){const r=Af.combine([this].concat(t));return Object.assign(this,r),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};ni.Psbt=Of;var Y={},W={};Object.defineProperty(W,"__esModule",{value:!0});W.signatureBlocksAction=W.checkInputForSig=W.pubkeyInScript=W.pubkeyPositionInScript=W.witnessStackToScriptWitness=W.isP2TR=W.isP2SHScript=W.isP2WSHScript=W.isP2WPKH=W.isP2PKH=W.isP2PK=W.isP2MS=void 0;const eo=xe,lr=_e(),Br=lt,Pf=Ke,Ct=mr();function Ht(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}W.isP2MS=Ht(Ct.p2ms);W.isP2PK=Ht(Ct.p2pk);W.isP2PKH=Ht(Ct.p2pkh);W.isP2WPKH=Ht(Ct.p2wpkh);W.isP2WSHScript=Ht(Ct.p2wsh);W.isP2SHScript=Ht(Ct.p2sh);W.isP2TR=Ht(Ct.p2tr);function vf(e){let t=E.allocUnsafe(0);function r(s){t=E.concat([t,E.from(s)])}function n(s){const a=t.length,p=eo.encodingLength(s);t=E.concat([t,E.allocUnsafe(p)]),eo.encode(s,t,a)}function i(s){n(s.length),r(s)}function c(s){n(s.length),s.forEach(i)}return c(e),t}W.witnessStackToScriptWitness=vf;function ls(e,t){const r=(0,Pf.hash160)(e),n=e.slice(1,33),i=lr.decompile(t);if(i===null)throw new Error("Unknown script error");return i.findIndex(c=>typeof c=="number"?!1:c.equals(e)||c.equals(r)||c.equals(n))}W.pubkeyPositionInScript=ls;function Bf(e,t){return ls(e,t)!==-1}W.pubkeyInScript=Bf;function xf(e,t){return Uf(e).some(n=>ds(n,lr.signature.decode,t))}W.checkInputForSig=xf;function ds(e,t,r){const{hashType:n}=t(e),i=[];switch(n&Br.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),n&31){case Br.Transaction.SIGHASH_ALL:break;case Br.Transaction.SIGHASH_SINGLE:case Br.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence");break}return i.indexOf(r)===-1}W.signatureBlocksAction=ds;function Uf(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=Nf(e)}else t=e.partialSig;return t.map(r=>r.signature)}function Nf(e){const t=e.finalScriptSig?lr.decompile(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?lr.decompile(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>E.isBuffer(n)&&lr.isCanonicalScriptSignature(n)).map(n=>({signature:n}))}Object.defineProperty(Y,"__esModule",{value:!0});Y.checkTaprootInputForSigs=Y.tapTreeFromList=Y.tapTreeToList=Y.tweakInternalPubKey=Y.checkTaprootOutputFields=Y.checkTaprootInputFields=Y.isTaprootOutput=Y.isTaprootInput=Y.serializeTaprootSignature=Y.tapScriptFinalizer=Y.toXOnly=void 0;const yi=de,Cf=lt,an=W,pt=rn,Hf=mr(),Rf=W,Ff=e=>e.length===32?e:e.slice(1,33);Y.toXOnly=Ff;function Lf(e,t,r){const n=rh(t,e,r);try{const c=eh(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:(0,an.witnessStackToScriptWitness)(c)}}catch(i){throw new Error(`Can not finalize taproot input #${e}: ${i}`)}}Y.tapScriptFinalizer=Lf;function $f(e,t){const r=t?E.from([t]):E.from([]);return E.concat([e,r])}Y.serializeTaprootSignature=$f;function Hr(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&(0,an.isP2TR)(e.witnessUtxo.script))}Y.isTaprootInput=Hr;function Rr(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t&&(0,an.isP2TR)(t))}Y.isTaprootOutput=Rr;function Mf(e,t,r){Jf(e,t,r),Zf(e,t,r)}Y.checkTaprootInputFields=Mf;function Kf(e,t,r){Qf(e,t,r),Df(e,t)}Y.checkTaprootOutputFields=Kf;function Df(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,c=Wf(r,n);if(i&&!i.equals(c))throw new Error("Error adding output. Script or address missmatch.")}}function Wf(e,t){const r=t&&ys(t.leaves),{output:n}=(0,Hf.p2tr)({internalPubkey:e,scriptTree:r});return n}function jf(e,t){const r=t.tapInternalKey,n=r&&(0,pt.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}Y.tweakInternalPubKey=jf;function Vf(e){if(!(0,yi.isTaptree)(e))throw new Error("Cannot convert taptree to tapleaf list. Expecting a tapree structure.");return Kn(e)}Y.tapTreeToList=Vf;function ys(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:Yf(e)}Y.tapTreeFromList=ys;function Gf(e,t){return qf(e).some(n=>(0,Rf.signatureBlocksAction)(n,Xf,t))}Y.checkTaprootInputForSigs=Gf;function Xf(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||Cf.Transaction.SIGHASH_DEFAULT}}function qf(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=zf(e.finalScriptWitness);r&&t.push(r)}return t}function zf(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function Kn(e,t=[],r=0){if(r>pt.MAX_TAPTREE_DEPTH)throw new Error("Max taptree depth exceeded.");return e?(0,yi.isTapleaf)(e)?(t.push({depth:r,leafVersion:e.version||pt.LEAF_VERSION_TAPSCRIPT,script:e.output}),t):(e[0]&&Kn(e[0],t,r+1),e[1]&&Kn(e[1],t,r+1),t):[]}function Yf(e){let t;for(const r of e)if(t=Dn(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function Dn(e,t,r=0){if(r>pt.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,yi.isTapleaf)(t))return;const n=Dn(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const i=Dn(e,t&&t[1],r+1);if(i)return[t&&t[0],i]}function Jf(e,t,r){const n=Hr(e)&&qt(t),i=qt(e)&&Hr(t),c=e===t&&Hr(t)&&qt(t);if(n||i||c)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Qf(e,t,r){const n=Rr(e)&&qt(t),i=qt(e)&&Rr(t),c=e===t&&Rr(t)&&qt(t);if(n||i||c)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Zf(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(c=>Hn(c,t.tapMerkleRoot)),i=(e.tapLeafScript||[]).every(c=>Hn(c,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=>Hn(i,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function Hn(e,t){if(!t)return!0;const r=(0,pt.tapleafHash)({output:e.script,version:e.leafVersion});return(0,pt.rootHashFromPath)(e.controlBlock,r).equals(t)}function eh(e,t){const r=(0,pt.tapleafHash)({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>n.leafHash.equals(r)).map(n=>th(t.script,n)).sort((n,i)=>i.positionInScript-n.positionInScript).map(n=>n.signature)}function th(e,t){return Object.assign({positionInScript:(0,an.pubkeyPositionInScript)(t.pubkey,e)},t)}function rh(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,c)=>i.controlBlock.length-c.controlBlock.length).find(i=>nh(i,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function nh(e,t,r){const n=(0,pt.tapleafHash)({output:e.script,version:e.leafVersion});return(!r||r.equals(n))&&t.find(c=>c.leafHash.equals(n))!==void 0}function qt(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}Object.defineProperty(sn,"__esModule",{value:!0});sn.Psbt=void 0;const to=ni,ro=xe,Se=di,no=ri(),Dr=oe,ih=ae,ve=mr(),oh=rn,Ye=_e(),we=lt,J=Y,re=W,sh={network:ih.bitcoin,maximumFeeRate:5e3};class Wr{static fromBase64(t,r={}){const n=E.from(t,"base64");return this.fromBuffer(n,r)}static fromHex(t,r={}){const n=E.from(t,"hex");return this.fromBuffer(n,r)}static fromBuffer(t,r={}){const n=to.Psbt.fromBuffer(t,ch),i=new Wr(r,n);return ph(i.__CACHE.__TX,i.__CACHE),i}constructor(t={},r=new to.Psbt(new ws)){this.data=r,this.opts=Object.assign({},sh,t),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const n=(i,c,s,a)=>Object.defineProperty(i,c,{enumerable:s,writable:a});n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(t){this.setVersion(t)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(t){this.setLocktime(t)}get txInputs(){return this.__CACHE.__TX.ins.map(t=>({hash:(0,Dr.cloneBuffer)(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let r;try{r=(0,no.fromOutputScript)(t.script,this.opts.network)}catch{}return{script:(0,Dr.cloneBuffer)(t.script),value:t.value,address:r}})}combine(...t){return this.data.combine(...t.map(r=>r.data)),this}clone(){const t=Wr.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){xr(t),this.opts.maximumFeeRate=t}setVersion(t){xr(t),or(this.data.inputs,"setVersion");const r=this.__CACHE;return r.__TX.version=t,r.__EXTRACTED_TX=void 0,this}setLocktime(t){xr(t),or(this.data.inputs,"setLocktime");const r=this.__CACHE;return r.__TX.locktime=t,r.__EXTRACTED_TX=void 0,this}setInputSequence(t,r){xr(r),or(this.data.inputs,"setInputSequence");const n=this.__CACHE;if(n.__TX.ins.length<=t)throw new Error("Input index too high");return n.__TX.ins[t].sequence=r,n.__EXTRACTED_TX=void 0,this}addInputs(t){return t.forEach(r=>this.addInput(r)),this}addInput(t){if(arguments.length>1||!t||t.hash===void 0||t.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");(0,J.checkTaprootInputFields)(t,t,"addInput"),or(this.data.inputs,"addInput"),t.witnessScript&&jr(t.witnessScript);const r=this.__CACHE;this.data.addInput(t);const n=r.__TX.ins[r.__TX.ins.length-1];ms(r,n);const i=this.data.inputs.length-1,c=this.data.inputs[i];return c.nonWitnessUtxo&&jn(this.__CACHE,c,i),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}addOutputs(t){return t.forEach(r=>this.addOutput(r)),this}addOutput(t){if(arguments.length>1||!t||t.value===void 0||t.address===void 0&&t.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");or(this.data.inputs,"addOutput");const{address:r}=t;if(typeof r=="string"){const{network:i}=this.opts,c=(0,no.toOutputScript)(r,i);t=Object.assign({},t,{script:c})}(0,J.checkTaprootOutputFields)(t,t,"addOutput");const n=this.__CACHE;return this.data.addOutput(t),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(t){if(!this.data.inputs.every(gs))throw new Error("Not finalized");const r=this.__CACHE;if(t||ah(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return ks(this.data.inputs,n,r,!0),n}getFeeRate(){return uo("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return uo("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return(0,Se.checkForInput)(this.data.inputs,0),sr(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,r){const n=(0,Se.checkForInput)(this.data.inputs,t);return(0,J.isTaprootInput)(n)?this._finalizeTaprootInput(t,n,void 0,r):this._finalizeInput(t,n,r)}finalizeTaprootInput(t,r,n=J.tapScriptFinalizer){const i=(0,Se.checkForInput)(this.data.inputs,t);if((0,J.isTaprootInput)(i))return this._finalizeTaprootInput(t,i,r,n);throw new Error(`Cannot finalize input #${t}. Not Taproot.`)}_finalizeInput(t,r,n=lh){const{script:i,isP2SH:c,isP2WSH:s,isSegwit:a}=gh(t,r,this.__CACHE);if(!i)throw new Error(`No script found for input #${t}`);fh(r);const{finalScriptSig:p,finalScriptWitness:w}=n(t,r,i,a,c,s);if(p&&this.data.updateInput(t,{finalScriptSig:p}),w&&this.data.updateInput(t,{finalScriptWitness:w}),!p&&!w)throw new Error(`Unknown error finalizing input #${t}`);return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,r,n,i=J.tapScriptFinalizer){if(!r.witnessUtxo)throw new Error(`Cannot finalize input #${t}. Missing withness utxo.`);if(r.tapKeySig){const c=ve.p2tr({output:r.witnessUtxo.script,signature:r.tapKeySig}),s=(0,re.witnessStackToScriptWitness)(c.witness);this.data.updateInput(t,{finalScriptWitness:s})}else{const{finalScriptWitness:c}=i(t,r,n);this.data.updateInput(t,{finalScriptWitness:c})}return this.data.clearFinalizedInput(t),this}getInputType(t){const r=(0,Se.checkForInput)(this.data.inputs,t),n=As(t,r,this.__CACHE),i=hn(n,t,"input",r.redeemScript||_h(r.finalScriptSig),r.witnessScript||Th(r.finalScriptWitness)),c=i.type==="raw"?"":i.type+"-",s=Ps(i.meaningfulScript);return c+s}inputHasPubkey(t,r){const n=(0,Se.checkForInput)(this.data.inputs,t);return Sh(r,n,t,this.__CACHE)}inputHasHDKey(t,r){const n=(0,Se.checkForInput)(this.data.inputs,t),i=oo(r);return!!n.bip32Derivation&&n.bip32Derivation.some(i)}outputHasPubkey(t,r){const n=(0,Se.checkForOutput)(this.data.outputs,t);return bh(r,n,t,this.__CACHE)}outputHasHDKey(t,r){const n=(0,Se.checkForOutput)(this.data.outputs,t),i=oo(r);return!!n.bip32Derivation&&n.bip32Derivation.some(i)}validateSignaturesOfAllInputs(t){return(0,Se.checkForInput)(this.data.inputs,0),sr(this.data.inputs.length).map(n=>this.validateSignaturesOfInput(n,t)).reduce((n,i)=>i===!0&&n,!0)}validateSignaturesOfInput(t,r,n){const i=this.data.inputs[t];return(0,J.isTaprootInput)(i)?this.validateSignaturesOfTaprootInput(t,r,n):this._validateSignaturesOfInput(t,r,n)}_validateSignaturesOfInput(t,r,n){const i=this.data.inputs[t],c=(i||{}).partialSig;if(!i||!c||c.length<1)throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");const s=n?c.filter(d=>d.pubkey.equals(n)):c;if(s.length<1)throw new Error("No signatures for this pubkey");const a=[];let p,w,f;for(const d of s){const S=Ye.signature.decode(d.signature),{hash:y,script:_}=f!==S.hashType?bs(t,Object.assign({},i,{sighashType:S.hashType}),this.__CACHE,!0):{hash:p,script:w};f=S.hashType,p=y,w=_,Es(d.pubkey,_,"verify"),a.push(r(d.pubkey,y,S.signature))}return a.every(d=>d===!0)}validateSignaturesOfTaprootInput(t,r,n){const i=this.data.inputs[t],c=(i||{}).tapKeySig,s=(i||{}).tapScriptSig;if(!i&&!c&&!(s&&!s.length))throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");n=n&&(0,J.toXOnly)(n);const a=n?Wn(t,i,this.data.inputs,n,this.__CACHE):yh(t,i,this.data.inputs,this.__CACHE);if(!a.length)throw new Error("No signatures for this pubkey");const p=a.find(f=>!f.leafHash);let w=0;if(c&&p){if(!r(p.pubkey,p.hash,fo(c)))return!1;w++}if(s)for(const f of s){const d=a.find(S=>f.pubkey.equals(S.pubkey));if(d){if(!r(f.pubkey,d.hash,fo(f.signature)))return!1;w++}}return w>0}signAllInputsHD(t,r=[we.Transaction.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");const n=[];for(const i of sr(this.data.inputs.length))try{this.signInputHD(i,t,r),n.push(!0)}catch{n.push(!1)}if(n.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(t,r=[we.Transaction.SIGHASH_ALL]){return new Promise((n,i)=>{if(!t||!t.publicKey||!t.fingerprint)return i(new Error("Need HDSigner to sign input"));const c=[],s=[];for(const a of sr(this.data.inputs.length))s.push(this.signInputHDAsync(a,t,r).then(()=>{c.push(!0)},()=>{c.push(!1)}));return Promise.all(s).then(()=>{if(c.every(a=>a===!1))return i(new Error("No inputs were signed"));n()})})}signInputHD(t,r,n=[we.Transaction.SIGHASH_ALL]){if(!r||!r.publicKey||!r.fingerprint)throw new Error("Need HDSigner to sign input");return ho(t,this.data.inputs,r).forEach(c=>this.signInput(t,c,n)),this}signInputHDAsync(t,r,n=[we.Transaction.SIGHASH_ALL]){return new Promise((i,c)=>{if(!r||!r.publicKey||!r.fingerprint)return c(new Error("Need HDSigner to sign input"));const a=ho(t,this.data.inputs,r).map(p=>this.signInputAsync(t,p,n));return Promise.all(a).then(()=>{i()}).catch(c)})}signAllInputs(t,r){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=[];for(const i of sr(this.data.inputs.length))try{this.signInput(i,t,r),n.push(!0)}catch{n.push(!1)}if(n.every(i=>i===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(t,r){return new Promise((n,i)=>{if(!t||!t.publicKey)return i(new Error("Need Signer to sign input"));const c=[],s=[];for(const[a]of this.data.inputs.entries())s.push(this.signInputAsync(a,t,r).then(()=>{c.push(!0)},()=>{c.push(!1)}));return Promise.all(s).then(()=>{if(c.every(a=>a===!1))return i(new Error("No inputs were signed"));n()})})}signInput(t,r,n){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=(0,Se.checkForInput)(this.data.inputs,t);return(0,J.isTaprootInput)(i)?this._signTaprootInput(t,i,r,void 0,n):this._signInput(t,r,n)}signTaprootInput(t,r,n,i){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const c=(0,Se.checkForInput)(this.data.inputs,t);if((0,J.isTaprootInput)(c))return this._signTaprootInput(t,c,r,n,i);throw new Error(`Input #${t} is not of type Taproot.`)}_signInput(t,r,n=[we.Transaction.SIGHASH_ALL]){const{hash:i,sighashType:c}=ao(this.data.inputs,t,r.publicKey,this.__CACHE,n),s=[{pubkey:r.publicKey,signature:Ye.signature.encode(r.sign(i),c)}];return this.data.updateInput(t,{partialSig:s}),this}_signTaprootInput(t,r,n,i,c=[we.Transaction.SIGHASH_DEFAULT]){const s=this.checkTaprootHashesForSig(t,r,n,i,c),a=s.filter(w=>!w.leafHash).map(w=>(0,J.serializeTaprootSignature)(n.signSchnorr(w.hash),r.sighashType))[0],p=s.filter(w=>!!w.leafHash).map(w=>({pubkey:(0,J.toXOnly)(n.publicKey),signature:(0,J.serializeTaprootSignature)(n.signSchnorr(w.hash),r.sighashType),leafHash:w.leafHash}));return a&&this.data.updateInput(t,{tapKeySig:a}),p.length&&this.data.updateInput(t,{tapScriptSig:p}),this}signInputAsync(t,r,n){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=(0,Se.checkForInput)(this.data.inputs,t);return(0,J.isTaprootInput)(i)?this._signTaprootInputAsync(t,i,r,void 0,n):this._signInputAsync(t,r,n)})}signTaprootInputAsync(t,r,n,i){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const c=(0,Se.checkForInput)(this.data.inputs,t);if((0,J.isTaprootInput)(c))return this._signTaprootInputAsync(t,c,r,n,i);throw new Error(`Input #${t} is not of type Taproot.`)})}_signInputAsync(t,r,n=[we.Transaction.SIGHASH_ALL]){const{hash:i,sighashType:c}=ao(this.data.inputs,t,r.publicKey,this.__CACHE,n);return Promise.resolve(r.sign(i)).then(s=>{const a=[{pubkey:r.publicKey,signature:Ye.signature.encode(s,c)}];this.data.updateInput(t,{partialSig:a})})}async _signTaprootInputAsync(t,r,n,i,c=[we.Transaction.SIGHASH_DEFAULT]){const s=this.checkTaprootHashesForSig(t,r,n,i,c),a=[],p=s.filter(f=>!f.leafHash)[0];if(p){const f=Promise.resolve(n.signSchnorr(p.hash)).then(d=>({tapKeySig:(0,J.serializeTaprootSignature)(d,r.sighashType)}));a.push(f)}const w=s.filter(f=>!!f.leafHash);if(w.length){const f=w.map(d=>Promise.resolve(n.signSchnorr(d.hash)).then(S=>({tapScriptSig:[{pubkey:(0,J.toXOnly)(n.publicKey),signature:(0,J.serializeTaprootSignature)(S,r.sighashType),leafHash:d.leafHash}]})));a.push(...f)}return Promise.all(a).then(f=>{f.forEach(d=>this.data.updateInput(t,d))})}checkTaprootHashesForSig(t,r,n,i,c){if(typeof n.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${t}.`);const s=Wn(t,r,this.data.inputs,n.publicKey,this.__CACHE,i,c);if(!s||!s.length)throw new Error(`Can not sign for input #${t} with the key ${n.publicKey.toString("hex")}`);return s}toBuffer(){return Rn(this.__CACHE),this.data.toBuffer()}toHex(){return Rn(this.__CACHE),this.data.toHex()}toBase64(){return Rn(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,r){return r.witnessScript&&jr(r.witnessScript),(0,J.checkTaprootInputFields)(this.data.inputs[t],r,"updateInput"),this.data.updateInput(t,r),r.nonWitnessUtxo&&jn(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,r){const n=this.data.outputs[t];return(0,J.checkTaprootOutputFields)(n,r,"updateOutput"),this.data.updateOutput(t,r),this}addUnknownKeyValToGlobal(t){return this.data.addUnknownKeyValToGlobal(t),this}addUnknownKeyValToInput(t,r){return this.data.addUnknownKeyValToInput(t,r),this}addUnknownKeyValToOutput(t,r){return this.data.addUnknownKeyValToOutput(t,r),this}clearFinalizedInput(t){return this.data.clearFinalizedInput(t),this}}sn.Psbt=Wr;const ch=e=>new ws(e);class ws{constructor(t=E.from([2,0,0,0,0,0,0,0,0,0])){this.tx=we.Transaction.fromBuffer(t),hh(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(t){if(t.hash===void 0||t.index===void 0||!E.isBuffer(t.hash)&&typeof t.hash!="string"||typeof t.index!="number")throw new Error("Error adding input.");const r=typeof t.hash=="string"?(0,Dr.reverseBuffer)(E.from(t.hash,"hex")):t.hash;this.tx.addInput(r,t.index,t.sequence)}addOutput(t){if(t.script===void 0||t.value===void 0||!E.isBuffer(t.script)||typeof t.value!="number")throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}toBuffer(){return this.tx.toBuffer()}}function uh(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return io(1,e.partialSig);case"multisig":const n=ve.p2ms({output:t});return io(n.m,e.partialSig,n.pubkeys);default:return!1}}function Rn(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function io(e,t,r){if(!t)return!1;let n;if(r?n=r.map(i=>{const c=Ih(i);return t.find(s=>s.pubkey.equals(c))}).filter(i=>!!i):n=t,n.length>e)throw new Error("Too many signatures");return n.length===e}function gs(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function oo(e){return t=>!(!t.masterFingerprint.equals(e.fingerprint)||!e.derivePath(t.path).publicKey.equals(t.pubkey))}function xr(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function ah(e,t,r){const n=t.__FEE_RATE||e.getFeeRate(),i=t.__EXTRACTED_TX.virtualSize(),c=n*i;if(n>=r.maximumFeeRate)throw new Error(`Warning: You are paying around ${(c/1e8).toFixed(8)} in fees, which is ${n} satoshi per byte for a transaction with a VSize of ${i} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function or(e,t){e.forEach(r=>{if((0,J.isTaprootInput)(r)?(0,J.checkTaprootInputForSigs)(r,t):(0,re.checkInputForSig)(r,t))throw new Error("Can not modify transaction, signatures exist.")})}function fh(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(n=>{const{hashType:i}=Ye.signature.decode(n.signature);if(r!==i)throw new Error("Signature sighash does not match input sighash type")})}function Es(e,t,r){if(!(0,re.pubkeyInScript)(e,t))throw new Error(`Can not ${r} for this input with the key ${e.toString("hex")}`)}function hh(e){if(!e.ins.every(r=>r.script&&r.script.length===0&&r.witness&&r.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function ph(e,t){e.ins.forEach(r=>{ms(t,r)})}function ms(e,t){const r=(0,Dr.reverseBuffer)(E.from(t.hash)).toString("hex")+":"+t.index;if(e.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[r]=1}function Ss(e,t){return(r,n,i,c)=>{const s=e({redeem:{output:i}}).output;if(!n.equals(s))throw new Error(`${t} for ${c} #${r} doesn't match the scriptPubKey in the prevout`)}}const so=Ss(ve.p2sh,"Redeem script"),co=Ss(ve.p2wsh,"Witness script");function uo(e,t,r,n){if(!r.every(gs))throw new Error(`PSBT must be finalized to calculate ${t}`);if(e==="__FEE_RATE"&&n.__FEE_RATE)return n.__FEE_RATE;if(e==="__FEE"&&n.__FEE)return n.__FEE;let i,c=!0;if(n.__EXTRACTED_TX?(i=n.__EXTRACTED_TX,c=!1):i=n.__TX.clone(),ks(r,i,n,c),e==="__FEE_RATE")return n.__FEE_RATE;if(e==="__FEE")return n.__FEE}function lh(e,t,r,n,i,c){const s=Ps(r);if(!uh(t,r,s))throw new Error(`Can not finalize input #${e}`);return dh(r,s,t.partialSig,n,i,c)}function dh(e,t,r,n,i,c){let s,a;const p=wh(e,t,r),w=c?ve.p2wsh({redeem:p}):null,f=i?ve.p2sh({redeem:w||p}):null;return n?(w?a=(0,re.witnessStackToScriptWitness)(w.witness):a=(0,re.witnessStackToScriptWitness)(p.witness),f&&(s=f.input)):f?s=f.input:s=p.input,{finalScriptSig:s,finalScriptWitness:a}}function ao(e,t,r,n,i){const c=(0,Se.checkForInput)(e,t),{hash:s,sighashType:a,script:p}=bs(t,c,n,!1,i);return Es(r,p,"sign"),{hash:s,sighashType:a}}function bs(e,t,r,n,i){const c=r.__TX,s=t.sighashType||we.Transaction.SIGHASH_ALL;Ts(s,i);let a,p;if(t.nonWitnessUtxo){const d=fn(r,t,e),S=c.ins[e].hash,y=d.getHash();if(!S.equals(y))throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const _=c.ins[e].index;p=d.outs[_]}else if(t.witnessUtxo)p=t.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:w,type:f}=hn(p.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(f)>=0)a=c.hashForWitnessV0(e,w,p.value,s);else if((0,re.isP2WPKH)(w)){const d=ve.p2pkh({hash:w.slice(2)}).output;a=c.hashForWitnessV0(e,d,p.value,s)}else{if(t.nonWitnessUtxo===void 0&&r.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${w.toString("hex")}`);!n&&r.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
*********************
PROCEED WITH CAUTION!
*********************`),a=c.hashForSignature(e,w,s)}return{script:w,sighashType:s,hash:a}}function yh(e,t,r,n){const i=[];if(t.tapInternalKey){const s=_s(e,t,n);s&&i.push(s)}if(t.tapScriptSig){const s=t.tapScriptSig.map(a=>a.pubkey);i.push(...s)}return i.map(s=>Wn(e,t,r,s,n)).flat()}function _s(e,t,r){const{script:n}=wi(e,t,r);return(0,re.isP2TR)(n)?n.subarray(2,34):null}function fo(e){return e.length===64?e:e.subarray(0,64)}function Wn(e,t,r,n,i,c,s){const a=i.__TX,p=t.sighashType||we.Transaction.SIGHASH_DEFAULT;Ts(p,s);const w=r.map((_,T)=>wi(T,_,i)),f=w.map(_=>_.script),d=w.map(_=>_.value),S=[];if(t.tapInternalKey&&!c){const _=_s(e,t,i)||E.from([]);if((0,J.toXOnly)(n).equals(_)){const T=a.hashForWitnessV1(e,f,d,p);S.push({pubkey:n,hash:T})}}const y=(t.tapLeafScript||[]).filter(_=>(0,re.pubkeyInScript)(n,_.script)).map(_=>{const T=(0,oh.tapleafHash)({output:_.script,version:_.leafVersion});return Object.assign({hash:T},_)}).filter(_=>!c||c.equals(_.hash)).map(_=>{const T=a.hashForWitnessV1(e,f,d,p,_.hash);return{pubkey:n,hash:T,leafHash:_.hash}});return S.concat(y)}function Ts(e,t){if(t&&t.indexOf(e)<0){const r=mh(e);throw new Error(`Sighash type is not allowed. Retry the sign method passing the sighashTypes array of whitelisted types. Sighash type: ${r}`)}}function wh(e,t,r){let n;switch(t){case"multisig":const i=Eh(e,r);n=ve.p2ms({output:e,signatures:i});break;case"pubkey":n=ve.p2pk({output:e,signature:r[0].signature});break;case"pubkeyhash":n=ve.p2pkh({output:e,pubkey:r[0].pubkey,signature:r[0].signature});break;case"witnesspubkeyhash":n=ve.p2wpkh({output:e,pubkey:r[0].pubkey,signature:r[0].signature});break}return n}function gh(e,t,r){const n=r.__TX,i={script:null,isSegwit:!1,isP2SH:!1,isP2WSH:!1};if(i.isP2SH=!!t.redeemScript,i.isP2WSH=!!t.witnessScript,t.witnessScript)i.script=t.witnessScript;else if(t.redeemScript)i.script=t.redeemScript;else if(t.nonWitnessUtxo){const c=fn(r,t,e),s=n.ins[e].index;i.script=c.outs[s].script}else t.witnessUtxo&&(i.script=t.witnessUtxo.script);return(t.witnessScript||(0,re.isP2WPKH)(i.script))&&(i.isSegwit=!0),i}function ho(e,t,r){const n=(0,Se.checkForInput)(t,e);if(!n.bip32Derivation||n.bip32Derivation.length===0)throw new Error("Need bip32Derivation to sign with HD");const i=n.bip32Derivation.map(s=>{if(s.masterFingerprint.equals(r.fingerprint))return s}).filter(s=>!!s);if(i.length===0)throw new Error("Need one bip32Derivation masterFingerprint to match the HDSigner fingerprint");return i.map(s=>{const a=r.derivePath(s.path);if(!s.pubkey.equals(a.publicKey))throw new Error("pubkey did not match bip32Derivation");return a})}function Eh(e,t){return ve.p2ms({output:e}).pubkeys.map(n=>(t.filter(i=>i.pubkey.equals(n))[0]||{}).signature).filter(n=>!!n)}function Is(e){let t=0;function r(s){return t+=s,e.slice(t-s,t)}function n(){const s=ro.decode(e,t);return t+=ro.decode.bytes,s}function i(){return r(n())}function c(){const s=n(),a=[];for(let p=0;p<s;p++)a.push(i());return a}return c()}function mh(e){let t=e&we.Transaction.SIGHASH_ANYONECANPAY?"SIGHASH_ANYONECANPAY | ":"";switch(e&31){case we.Transaction.SIGHASH_ALL:t+="SIGHASH_ALL";break;case we.Transaction.SIGHASH_SINGLE:t+="SIGHASH_SINGLE";break;case we.Transaction.SIGHASH_NONE:t+="SIGHASH_NONE";break}return t}function jn(e,t,r){e.__NON_WITNESS_UTXO_BUF_CACHE[r]=t.nonWitnessUtxo;const n=we.Transaction.fromBuffer(t.nonWitnessUtxo);e.__NON_WITNESS_UTXO_TX_CACHE[r]=n;const i=e,c=r;delete t.nonWitnessUtxo,Object.defineProperty(t,"nonWitnessUtxo",{enumerable:!0,get(){const s=i.__NON_WITNESS_UTXO_BUF_CACHE[c],a=i.__NON_WITNESS_UTXO_TX_CACHE[c];if(s!==void 0)return s;{const p=a.toBuffer();return i.__NON_WITNESS_UTXO_BUF_CACHE[c]=p,p}},set(s){i.__NON_WITNESS_UTXO_BUF_CACHE[c]=s}})}function ks(e,t,r,n){let i=0;e.forEach((p,w)=>{if(n&&p.finalScriptSig&&(t.ins[w].script=p.finalScriptSig),n&&p.finalScriptWitness&&(t.ins[w].witness=Is(p.finalScriptWitness)),p.witnessUtxo)i+=p.witnessUtxo.value;else if(p.nonWitnessUtxo){const f=fn(r,p,w),d=t.ins[w].index,S=f.outs[d];i+=S.value}});const c=t.outs.reduce((p,w)=>p+w.value,0),s=i-c;if(s<0)throw new Error("Outputs are spending more than Inputs");const a=t.virtualSize();r.__FEE=s,r.__EXTRACTED_TX=t,r.__FEE_RATE=Math.floor(s/a)}function fn(e,t,r){const n=e.__NON_WITNESS_UTXO_TX_CACHE;return n[r]||jn(e,t,r),n[r]}function As(e,t,r){const{script:n}=wi(e,t,r);return n}function wi(e,t,r){if(t.witnessUtxo!==void 0)return{script:t.witnessUtxo.script,value:t.witnessUtxo.value};if(t.nonWitnessUtxo!==void 0){const i=fn(r,t,e).outs[r.__TX.ins[e].index];return{script:i.script,value:i.value}}else throw new Error("Can't find pubkey in input without Utxo data")}function Sh(e,t,r,n){const i=As(r,t,n),{meaningfulScript:c}=hn(i,r,"input",t.redeemScript,t.witnessScript);return(0,re.pubkeyInScript)(e,c)}function bh(e,t,r,n){const i=n.__TX.outs[r].script,{meaningfulScript:c}=hn(i,r,"output",t.redeemScript,t.witnessScript);return(0,re.pubkeyInScript)(e,c)}function _h(e){if(!e)return;const t=Ye.decompile(e);if(!t)return;const r=t[t.length-1];if(!(!E.isBuffer(r)||Os(r)||kh(r)||!Ye.decompile(r)))return r}function Th(e){if(!e)return;const t=Is(e),r=t[t.length-1];if(!(Os(r)||!Ye.decompile(r)))return r}function Ih(e){if(e.length===65){const t=e[64]&1,r=e.slice(0,33);return r[0]=2|t,r}return e.slice()}function Os(e){return e.length===33&&Ye.isCanonicalPubKey(e)}function kh(e){return Ye.isCanonicalScriptSignature(e)}function hn(e,t,r,n,i){const c=(0,re.isP2SHScript)(e),s=c&&n&&(0,re.isP2WSHScript)(n),a=(0,re.isP2WSHScript)(e);if(c&&n===void 0)throw new Error("scriptPubkey is P2SH but redeemScript missing");if((a||s)&&i===void 0)throw new Error("scriptPubkey or redeemScript is P2WSH but witnessScript missing");let p;return s?(p=i,so(t,e,n,r),co(t,n,i,r),jr(p)):a?(p=i,co(t,e,i,r),jr(p)):c?(p=n,so(t,e,n,r)):p=e,{meaningfulScript:p,type:s?"p2sh-p2wsh":c?"p2sh":a?"p2wsh":"raw"}}function jr(e){if((0,re.isP2WPKH)(e)||(0,re.isP2SHScript)(e))throw new Error("P2WPKH or P2SH can not be contained within P2WSH")}function Ps(e){return(0,re.isP2WPKH)(e)?"witnesspubkeyhash":(0,re.isP2PKH)(e)?"pubkeyhash":(0,re.isP2MS)(e)?"multisig":(0,re.isP2PK)(e)?"pubkey":"nonstandard"}function sr(e){return[...Array(e).keys()]}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.initEccLib=e.Transaction=e.opcodes=e.Psbt=e.Block=e.script=e.payments=e.networks=e.crypto=e.address=void 0;const t=ri();e.address=t;const r=Ke;e.crypto=r;const n=ae;e.networks=n;const i=mr();e.payments=i;const c=_e();e.script=c;var s=nn;Object.defineProperty(e,"Block",{enumerable:!0,get:function(){return s.Block}});var a=sn;Object.defineProperty(e,"Psbt",{enumerable:!0,get:function(){return a.Psbt}});var p=ft;Object.defineProperty(e,"opcodes",{enumerable:!0,get:function(){return p.OPS}});var w=lt;Object.defineProperty(e,"Transaction",{enumerable:!0,get:function(){return w.Transaction}});var f=ht;Object.defineProperty(e,"initEccLib",{enumerable:!0,get:function(){return f.initEccLib}})})(lo);const vs={BTC:["https://mempool.space/api/tx","https://blockstream.info/api/tx"],XTN:["https://mempool.space/testnet/api/tx","https://blockstream.info/testnet/api/tx"]},Ah={BTC:[["mempool.space","https://mempool.space/tx/"],["blockstream.info","https://blockstream.info/tx/"],["btcscan.org","https://btcscan.org/tx/"],["btc.com","https://explorer.btc.com/btc/transaction/"]],XTN:[["mempool.space","https://mempool.space/testnet/tx/"],["blockstream.info","https://blockstream.info/testnet/tx/"],["blockcypher.com","https://live.blockcypher.com/btc-testnet/tx/"]]},Oh={success:`
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
<path d="m10.97 4.97-.02.022-3.473 4.425-2.093-2.094a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05"/>
</svg>`,error:`
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
<path d="M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0M7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0z"/>
</svg>`,info:`
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/>
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0"/>
</svg>`,progress:`
<svg class="pushtx-spin" width="32" height="32" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>`};async function dr(e){try{return[null,await e]}catch(t){return t instanceof Error?[t,null]:typeof t=="string"?[new Error(t),null]:[new Error,null]}}function po(e){const t=e.replace(/-/g,"+").replace(/_/g,"/").padEnd(e.length+(4-e.length%4)%4,"="),r=atob(t);return new Uint8Array([...r].map(n=>n.charCodeAt(0)))}class Bs extends Error{constructor(r,n,i,c){super();Zt(this,"url");Zt(this,"status");Zt(this,"statusText");Zt(this,"body");this.url=r,this.name="FetchStatusError",this.status=n,this.statusText=i,this.body=c}}const xs=async(e,t)=>{const r=await fetch(e,t);if(!r.ok){const[n,i]=await dr(r.text());throw new Bs(e.toString(),r.status,r.statusText,i)}return r};async function Ph(e,t){if(t!=="BTC"&&t!=="XTN")throw new Error("Unsupported network: "+t);const n=vs[t].map(s=>xs(s,{method:"POST",body:e.toHex()})),[i,c]=await dr(Promise.any(n).then(s=>s.text()));if(c)return c;if(i instanceof AggregateError){const s=i.errors.filter(a=>a instanceof Bs);if(s.length>0){let a=`
<p>The transaction was rejected by all providers:</p>
<ul>
`;throw s.forEach(p=>{a+=`<li>${p.url}: ${p.body}</li>`}),a+="</ul>",new Error(a)}}throw new Error("<p>Could not connect to any push servers. Make sure you are connected to the Internet and try again.</p>")}async function vh(e){e[0]==="#"&&(e=e.slice(1));const t=new URLSearchParams(e),r=t.get("t"),n=t.get("c"),i=t.get("n")||"BTC";if(!r)throw new Error("Invalid URL - missing transaction.");if(!n||n.length!==11)throw new Error("Invalid URL - missing or incomplete checksum. The URL is probably truncated");let c;if(i==="BTC"||i==="XTN")c=i;else throw i==="XRT"?new Error("Regtest transactions are not supported."):new Error(`Invalid URL. The network "${i}" is not recognized.`);let s,a;try{s=po(r),a=po(n)}catch{throw new Error("Invalid URL encoding. The URL is probably corrupted.")}const p=new Uint8Array(await crypto.subtle.digest("SHA-256",s));if(!a.every((f,d)=>f===p[d+24]))throw new Error("Checksum mismatch in URL. Some bytes corrupted in transit. Try again.");return{tx:lo.Transaction.fromBuffer(wo.from(s)),network:c}}async function Bh(e,t){if(t!=="BTC"&&t!=="XTN")throw new Error("Unsupported network: "+t);const n=vs[t].map(i=>xs(i+"/"+e).then(c=>c.json()));return await Promise.any(n)}function xh(e){const t=e.vin.map(n=>`
<tr>
<td>
<span class="address">
<span>${n.prevout.scriptpubkey_address.slice(0,-8)}</span>
<span>${n.prevout.scriptpubkey_address.slice(-8)}</span>
</span>
</td>
<td>
<span class="value">${(n.prevout.value/1e8).toFixed(8)}</span>
</td>
</tr>
`).join(""),r=e.vout.map(n=>`
<tr>
<td>
<span class="address">
<span>${n.scriptpubkey_address.slice(0,-8)}</span>
<span>${n.scriptpubkey_address.slice(-8)}</span>
</span>
</td>
<td>
<span class="value">${(n.value/1e8).toFixed(8)}</span>
</td>
</tr>
`).join("");return`
<div class="pushtx-details">
<div class="inputs">
<table>
<thead>
<tr>
<th>Inputs</th>
<th></th>
</tr>
</thead>
<tbody>
${t}
</tbody>
</table>
</div>
<div class="outputs">
<table>
<thead>
<tr>
<th>Outputs</th>
<th></th>
</tr>
</thead>
<tbody>
${r}
</tbody>
</table>
</div>
<div class="fee">
<strong>Fee:</strong> <span class="value">${(e.fee/1e8).toFixed(8)}</span>
</div>
</div>
`}function Kt(e,t){const r=Oh[e];return`
<div class="pushtx-message pushtx-message--${e}" role="alert">
${r}
<div>${t}</div>
</div>
`}async function Us(){const e=document.querySelector(".pushtx-message-area"),t=document.querySelector(".pushtx-details-area");if(!e||!t)throw new Error("Need message and details areas in HTML.");if(e.innerHTML="",t.innerHTML="",!window.location.hash){const S=`
<p><strong>Did you get here by accident?</strong></p>
<p>
This page is meant to be loaded together with transaction data using the
<strong>COLDCARD NFC Push TX feature</strong>. The complete URL should look something like this (but longer):
</p>
<p><code>${window.location.origin+window.location.pathname}#t=AgAAAAMNCxXtp2GVYVhkRXHLMmdZFs4p3kbFK ⋯ ABf&c=uiSVRda-1tw</code></p>
`;e.innerHTML=Kt("info",S);return}e.innerHTML=Kt("progress","Sending transaction, please wait...");const[r,n]=await dr(vh(window.location.hash));if(r){e.innerHTML=Kt("error",r.message);return}const{tx:i,network:c}=n,s=i.getId(),[a,p]=await dr(Ph(i,c)),[w,f]=await dr(Bh(s,c));if(p||f){const d=f!=null&&f.status.confirmed?"This transaction has already been confirmed.":"The transaction has been sent and is waiting to be confirmed.",S=Ah[c].map(([y,_])=>`<li><a href="${_}${s}" target="_blank" rel="noopener">${y}</a></li>`).join("");e.innerHTML=Kt("success",`<p>${d} Transaction ID:</p>
<p class="txid">${s}</p>
<p>Verify on a block explorer:</p>
<ul>${S}</ul>
`),f&&(t.innerHTML=xh(f));return}if(a&&w)e.innerHTML=Kt("error",a.message);else if(w){e.innerHTML=Kt("error",w.message);return}}Us();window.addEventListener("hashchange",Us);
</script>
<style rel="stylesheet" crossorigin>.pushtx *{margin:0;padding:0;box-sizing:border-box;color:inherit!important}.pushtx ul{list-style-position:inside}.pushtx .monospace{font-family:SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.pushtx-spin{animation:spin 1s linear infinite}.pushtx-message{display:flex;gap:1rem;padding:1rem;border:1px solid transparent;border-radius:.25rem;width:100%}.pushtx-message>:first-child{flex-shrink:0}.pushtx-message>:last-child{overflow:hidden;overflow-wrap:break-word;display:flex;flex-direction:column;gap:.5rem}.pushtx-message--success{color:#155724;background-color:#d4edda;border-color:#c3e6cb}.pushtx-message--info{color:#0c5460;background-color:#d1ecf1;border-color:#bee5eb}.pushtx-message--progress{color:#004085;background-color:#cce5ff;border-color:#b8daff}.pushtx-message--error{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb}.pushtx-message .txid{font-family:SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:.875em;font-weight:700}.pushtx-details{display:flex;flex-direction:column;margin-block:2rem;padding:.5rem;border-radius:.25rem;overflow:hidden;gap:.5rem;border:1px solid #e2e8f0}.pushtx-details table{border-collapse:collapse;width:100%}.pushtx-details th{text-align:left}.pushtx-details :is(th,td){border-width:0px;padding-block:.125rem}.pushtx-details :is(td:first-child,th:first-child){width:75%;max-width:0px}.pushtx-details :is(td:last-child,th:last-child){text-align:right}.pushtx-details :is(.address,.value){font-family:SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.pushtx-details .address{display:flex;padding-right:1em}.pushtx-details .address :first-child{overflow:hidden;text-overflow:ellipsis}.pushtx-details .fee{text-align:right}
</style>
</head>
<body>
<main class="pushtx" style="
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 1024px;
margin: 5vh auto;
">
<h1 style="margin-bottom: 2rem;">COLDCARD NFC Push TX</h1>
<div>
<div class="pushtx-message-area"></div>
<div class="pushtx-details-area"></div>
</div>
</main>
</body>
</html>