Branchwell

Paywell / website / app / wallet.js

1var PWW=(()=>{var kc=Object.create;var qr=Object.defineProperty;var Tc=Object.getOwnPropertyDescriptor;var Ic=Object.getOwnPropertyNames;var Uc=Object.getPrototypeOf,Lc=Object.prototype.hasOwnProperty;var Nc=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Vi=(t,e)=>{for(var r in e)qr(t,r,{get:e[r],enumerable:!0})},zi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ic(e))!Lc.call(t,o)&&o!==r&&qr(t,o,{get:()=>e[o],enumerable:!(n=Tc(e,o))||n.enumerable});return t};var Cc=(t,e,r)=>(r=t!=null?kc(Uc(t)):{},zi(e||!t||!t.__esModule?qr(r,"default",{value:t,enumerable:!0}):r,t)),_c=t=>zi(qr({},"__esModule",{value:!0}),t);var vc=Nc((xc,Ec)=>{var mc=function(){var t=function(m,b){var v=236,x=17,w=m,B=r[b],g=null,d=0,C=null,k=[],T={},D=function(P,_){d=w*4+17,g=function(U){for(var R=new Array(U),H=0;H<U;H+=1){R[H]=new Array(U);for(var O=0;O<U;O+=1)R[H][O]=null}return R}(d),S(0,0),S(d-7,0),S(0,d-7),$(),L(),W(P,_),w>=7&&M(P),C==null&&(C=it(w,B,k)),j(C,_)},S=function(P,_){for(var U=-1;U<=7;U+=1)if(!(P+U<=-1||d<=P+U))for(var R=-1;R<=7;R+=1)_+R<=-1||d<=_+R||(0<=U&&U<=6&&(R==0||R==6)||0<=R&&R<=6&&(U==0||U==6)||2<=U&&U<=4&&2<=R&&R<=4?g[P+U][_+R]=!0:g[P+U][_+R]=!1)},I=function(){for(var P=0,_=0,U=0;U<8;U+=1){D(!0,U);var R=o.getLostPoint(T);(U==0||P>R)&&(P=R,_=U)}return _},L=function(){for(var P=8;P<d-8;P+=1)g[P][6]==null&&(g[P][6]=P%2==0);for(var _=8;_<d-8;_+=1)g[6][_]==null&&(g[6][_]=_%2==0)},$=function(){for(var P=o.getPatternPosition(w),_=0;_<P.length;_+=1)for(var U=0;U<P.length;U+=1){var R=P[_],H=P[U];if(g[R][H]==null)for(var O=-2;O<=2;O+=1)for(var q=-2;q<=2;q+=1)O==-2||O==2||q==-2||q==2||O==0&&q==0?g[R+O][H+q]=!0:g[R+O][H+q]=!1}},M=function(P){for(var _=o.getBCHTypeNumber(w),U=0;U<18;U+=1){var R=!P&&(_>>U&1)==1;g[Math.floor(U/3)][U%3+d-8-3]=R}for(var U=0;U<18;U+=1){var R=!P&&(_>>U&1)==1;g[U%3+d-8-3][Math.floor(U/3)]=R}},W=function(P,_){for(var U=B<<3|_,R=o.getBCHTypeInfo(U),H=0;H<15;H+=1){var O=!P&&(R>>H&1)==1;H<6?g[H][8]=O:H<8?g[H+1][8]=O:g[d-15+H][8]=O}for(var H=0;H<15;H+=1){var O=!P&&(R>>H&1)==1;H<8?g[8][d-H-1]=O:H<9?g[8][15-H-1+1]=O:g[8][15-H-1]=O}g[d-8][8]=!P},j=function(P,_){for(var U=-1,R=d-1,H=7,O=0,q=o.getMaskFunction(_),K=d-1;K>0;K-=2)for(K==6&&(K-=1);;){for(var G=0;G<2;G+=1)if(g[R][K-G]==null){var Z=!1;O<P.length&&(Z=(P[O]>>>H&1)==1);var V=q(R,K-G);V&&(Z=!Z),g[R][K-G]=Z,H-=1,H==-1&&(O+=1,H=7)}if(R+=U,R<0||d<=R){R-=U,U=-U;break}}},Y=function(P,_){for(var U=0,R=0,H=0,O=new Array(_.length),q=new Array(_.length),K=0;K<_.length;K+=1){var G=_[K].dataCount,Z=_[K].totalCount-G;R=Math.max(R,G),H=Math.max(H,Z),O[K]=new Array(G);for(var V=0;V<O[K].length;V+=1)O[K][V]=255&P.getBuffer()[V+U];U+=G;var _t=o.getErrorCorrectPolynomial(Z),Pt=s(O[K],_t.getLength()-1),Ki=Pt.mod(_t);q[K]=new Array(_t.getLength()-1);for(var V=0;V<q[K].length;V+=1){var qi=V+Ki.getLength()-q[K].length;q[K][V]=qi>=0?Ki.getAt(qi):0}}for(var Wi=0,V=0;V<_.length;V+=1)Wi+=_[V].totalCount;for(var Fn=new Array(Wi),Kr=0,V=0;V<R;V+=1)for(var K=0;K<_.length;K+=1)V<O[K].length&&(Fn[Kr]=O[K][V],Kr+=1);for(var V=0;V<H;V+=1)for(var K=0;K<_.length;K+=1)V<q[K].length&&(Fn[Kr]=q[K][V],Kr+=1);return Fn},it=function(P,_,U){for(var R=a.getRSBlocks(P,_),H=c(),O=0;O<U.length;O+=1){var q=U[O];H.put(q.getMode(),4),H.put(q.getLength(),o.getLengthInBits(q.getMode(),P)),q.write(H)}for(var K=0,O=0;O<R.length;O+=1)K+=R[O].dataCount;if(H.getLengthInBits()>K*8)throw"code length overflow. ("+H.getLengthInBits()+">"+K*8+")";for(H.getLengthInBits()+4<=K*8&&H.put(0,4);H.getLengthInBits()%8!=0;)H.putBit(!1);for(;!(H.getLengthInBits()>=K*8||(H.put(v,8),H.getLengthInBits()>=K*8));)H.put(x,8);return Y(H,R)};T.addData=function(P,_){_=_||"Byte";var U=null;switch(_){case"Numeric":U=f(P);break;case"Alphanumeric":U=h(P);break;case"Byte":U=u(P);break;case"Kanji":U=l(P);break;default:throw"mode:"+_}k.push(U),C=null},T.isDark=function(P,_){if(P<0||d<=P||_<0||d<=_)throw P+","+_;return g[P][_]},T.getModuleCount=function(){return d},T.make=function(){if(w<1){for(var P=1;P<40;P++){for(var _=a.getRSBlocks(P,B),U=c(),R=0;R<k.length;R++){var H=k[R];U.put(H.getMode(),4),U.put(H.getLength(),o.getLengthInBits(H.getMode(),P)),H.write(U)}for(var O=0,R=0;R<_.length;R++)O+=_[R].dataCount;if(U.getLengthInBits()<=O*8)break}w=P}D(!1,I())},T.createTableTag=function(P,_){P=P||2,_=typeof _>"u"?P*4:_;var U="";U+='<table style="',U+=" border-width: 0px; border-style: none;",U+=" border-collapse: collapse;",U+=" padding: 0px; margin: "+_+"px;",U+='">',U+="<tbody>";for(var R=0;R<T.getModuleCount();R+=1){U+="<tr>";for(var H=0;H<T.getModuleCount();H+=1)U+='<td style="',U+=" border-width: 0px; border-style: none;",U+=" border-collapse: collapse;",U+=" padding: 0px; margin: 0px;",U+=" width: "+P+"px;",U+=" height: "+P+"px;",U+=" background-color: ",U+=T.isDark(R,H)?"#000000":"#ffffff",U+=";",U+='"/>';U+="</tr>"}return U+="</tbody>",U+="</table>",U},T.createSvgTag=function(P,_,U,R){var H={};typeof arguments[0]=="object"&&(H=arguments[0],P=H.cellSize,_=H.margin,U=H.alt,R=H.title),P=P||2,_=typeof _>"u"?P*4:_,U=typeof U=="string"?{text:U}:U||{},U.text=U.text||null,U.id=U.text?U.id||"qrcode-description":null,R=typeof R=="string"?{text:R}:R||{},R.text=R.text||null,R.id=R.text?R.id||"qrcode-title":null;var O=T.getModuleCount()*P+_*2,q,K,G,Z,V="",_t;for(_t="l"+P+",0 0,"+P+" -"+P+",0 0,-"+P+"z ",V+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',V+=H.scalable?"":' width="'+O+'px" height="'+O+'px"',V+=' viewBox="0 0 '+O+" "+O+'" ',V+=' preserveAspectRatio="xMinYMin meet"',V+=R.text||U.text?' role="img" aria-labelledby="'+X([R.id,U.id].join(" ").trim())+'"':"",V+=">",V+=R.text?'<title id="'+X(R.id)+'">'+X(R.text)+"</title>":"",V+=U.text?'<description id="'+X(U.id)+'">'+X(U.text)+"</description>":"",V+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',V+='<path d="',G=0;G<T.getModuleCount();G+=1)for(Z=G*P+_,q=0;q<T.getModuleCount();q+=1)T.isDark(G,q)&&(K=q*P+_,V+="M"+K+","+Z+_t);return V+='" stroke="transparent" fill="black"/>',V+="</svg>",V},T.createDataURL=function(P,_){P=P||2,_=typeof _>"u"?P*4:_;var U=T.getModuleCount()*P+_*2,R=_,H=U-_;return A(U,U,function(O,q){if(R<=O&&O<H&&R<=q&&q<H){var K=Math.floor((O-R)/P),G=Math.floor((q-R)/P);return T.isDark(G,K)?0:1}else return 1})},T.createImgTag=function(P,_,U){P=P||2,_=typeof _>"u"?P*4:_;var R=T.getModuleCount()*P+_*2,H="";return H+="<img",H+=' src="',H+=T.createDataURL(P,_),H+='"',H+=' width="',H+=R,H+='"',H+=' height="',H+=R,H+='"',U&&(H+=' alt="',H+=X(U),H+='"'),H+="/>",H};var X=function(P){for(var _="",U=0;U<P.length;U+=1){var R=P.charAt(U);switch(R){case"<":_+="&lt;";break;case">":_+="&gt;";break;case"&":_+="&amp;";break;case'"':_+="&quot;";break;default:_+=R;break}}return _},F=function(P){var _=1;P=typeof P>"u"?_*2:P;var U=T.getModuleCount()*_+P*2,R=P,H=U-P,O,q,K,G,Z,V={"\u2588\u2588":"\u2588","\u2588 ":"\u2580"," \u2588":"\u2584"," ":" "},_t={"\u2588\u2588":"\u2580","\u2588 ":"\u2580"," \u2588":" "," ":" "},Pt="";for(O=0;O<U;O+=2){for(K=Math.floor((O-R)/_),G=Math.floor((O+1-R)/_),q=0;q<U;q+=1)Z="\u2588",R<=q&&q<H&&R<=O&&O<H&&T.isDark(K,Math.floor((q-R)/_))&&(Z=" "),R<=q&&q<H&&R<=O+1&&O+1<H&&T.isDark(G,Math.floor((q-R)/_))?Z+=" ":Z+="\u2588",Pt+=P<1&&O+1>=H?_t[Z]:V[Z];Pt+=`
2`}return U%2&&P>0?Pt.substring(0,Pt.length-U-1)+Array(U+1).join("\u2580"):Pt.substring(0,Pt.length-1)};return T.createASCII=function(P,_){if(P=P||1,P<2)return F(_);P-=1,_=typeof _>"u"?P*2:_;var U=T.getModuleCount()*P+_*2,R=_,H=U-_,O,q,K,G,Z=Array(P+1).join("\u2588\u2588"),V=Array(P+1).join(" "),_t="",Pt="";for(O=0;O<U;O+=1){for(K=Math.floor((O-R)/P),Pt="",q=0;q<U;q+=1)G=1,R<=q&&q<H&&R<=O&&O<H&&T.isDark(K,Math.floor((q-R)/P))&&(G=0),Pt+=G?Z:V;for(K=0;K<P;K+=1)_t+=Pt+`
3`}return _t.substring(0,_t.length-1)},T.renderTo2dContext=function(P,_){_=_||2;for(var U=T.getModuleCount(),R=0;R<U;R++)for(var H=0;H<U;H++)P.fillStyle=T.isDark(R,H)?"black":"white",P.fillRect(R*_,H*_,_,_)},T};t.stringToBytesFuncs={default:function(m){for(var b=[],v=0;v<m.length;v+=1){var x=m.charCodeAt(v);b.push(x&255)}return b}},t.stringToBytes=t.stringToBytesFuncs.default,t.createStringToBytes=function(m,b){var v=function(){for(var w=E(m),B=function(){var L=w.read();if(L==-1)throw"eof";return L},g=0,d={};;){var C=w.read();if(C==-1)break;var k=B(),T=B(),D=B(),S=String.fromCharCode(C<<8|k),I=T<<8|D;d[S]=I,g+=1}if(g!=b)throw g+" != "+b;return d}(),x=63;return function(w){for(var B=[],g=0;g<w.length;g+=1){var d=w.charCodeAt(g);if(d<128)B.push(d);else{var C=v[w.charAt(g)];typeof C=="number"?(C&255)==C?B.push(C):(B.push(C>>>8),B.push(C&255)):B.push(x)}}return B}};var e={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},r={L:1,M:0,Q:3,H:2},n={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},o=function(){var m=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],b=1335,v=7973,x=21522,w={},B=function(g){for(var d=0;g!=0;)d+=1,g>>>=1;return d};return w.getBCHTypeInfo=function(g){for(var d=g<<10;B(d)-B(b)>=0;)d^=b<<B(d)-B(b);return(g<<10|d)^x},w.getBCHTypeNumber=function(g){for(var d=g<<12;B(d)-B(v)>=0;)d^=v<<B(d)-B(v);return g<<12|d},w.getPatternPosition=function(g){return m[g-1]},w.getMaskFunction=function(g){switch(g){case n.PATTERN000:return function(d,C){return(d+C)%2==0};case n.PATTERN001:return function(d,C){return d%2==0};case n.PATTERN010:return function(d,C){return C%3==0};case n.PATTERN011:return function(d,C){return(d+C)%3==0};case n.PATTERN100:return function(d,C){return(Math.floor(d/2)+Math.floor(C/3))%2==0};case n.PATTERN101:return function(d,C){return d*C%2+d*C%3==0};case n.PATTERN110:return function(d,C){return(d*C%2+d*C%3)%2==0};case n.PATTERN111:return function(d,C){return(d*C%3+(d+C)%2)%2==0};default:throw"bad maskPattern:"+g}},w.getErrorCorrectPolynomial=function(g){for(var d=s([1],0),C=0;C<g;C+=1)d=d.multiply(s([1,i.gexp(C)],0));return d},w.getLengthInBits=function(g,d){if(1<=d&&d<10)switch(g){case e.MODE_NUMBER:return 10;case e.MODE_ALPHA_NUM:return 9;case e.MODE_8BIT_BYTE:return 8;case e.MODE_KANJI:return 8;default:throw"mode:"+g}else if(d<27)switch(g){case e.MODE_NUMBER:return 12;case e.MODE_ALPHA_NUM:return 11;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 10;default:throw"mode:"+g}else if(d<41)switch(g){case e.MODE_NUMBER:return 14;case e.MODE_ALPHA_NUM:return 13;case e.MODE_8BIT_BYTE:return 16;case e.MODE_KANJI:return 12;default:throw"mode:"+g}else throw"type:"+d},w.getLostPoint=function(g){for(var d=g.getModuleCount(),C=0,k=0;k<d;k+=1)for(var T=0;T<d;T+=1){for(var D=0,S=g.isDark(k,T),I=-1;I<=1;I+=1)if(!(k+I<0||d<=k+I))for(var L=-1;L<=1;L+=1)T+L<0||d<=T+L||I==0&&L==0||S==g.isDark(k+I,T+L)&&(D+=1);D>5&&(C+=3+D-5)}for(var k=0;k<d-1;k+=1)for(var T=0;T<d-1;T+=1){var $=0;g.isDark(k,T)&&($+=1),g.isDark(k+1,T)&&($+=1),g.isDark(k,T+1)&&($+=1),g.isDark(k+1,T+1)&&($+=1),($==0||$==4)&&(C+=3)}for(var k=0;k<d;k+=1)for(var T=0;T<d-6;T+=1)g.isDark(k,T)&&!g.isDark(k,T+1)&&g.isDark(k,T+2)&&g.isDark(k,T+3)&&g.isDark(k,T+4)&&!g.isDark(k,T+5)&&g.isDark(k,T+6)&&(C+=40);for(var T=0;T<d;T+=1)for(var k=0;k<d-6;k+=1)g.isDark(k,T)&&!g.isDark(k+1,T)&&g.isDark(k+2,T)&&g.isDark(k+3,T)&&g.isDark(k+4,T)&&!g.isDark(k+5,T)&&g.isDark(k+6,T)&&(C+=40);for(var M=0,T=0;T<d;T+=1)for(var k=0;k<d;k+=1)g.isDark(k,T)&&(M+=1);var W=Math.abs(100*M/d/d-50)/5;return C+=W*10,C},w}(),i=function(){for(var m=new Array(256),b=new Array(256),v=0;v<8;v+=1)m[v]=1<<v;for(var v=8;v<256;v+=1)m[v]=m[v-4]^m[v-5]^m[v-6]^m[v-8];for(var v=0;v<255;v+=1)b[m[v]]=v;var x={};return x.glog=function(w){if(w<1)throw"glog("+w+")";return b[w]},x.gexp=function(w){for(;w<0;)w+=255;for(;w>=256;)w-=255;return m[w]},x}();function s(m,b){if(typeof m.length>"u")throw m.length+"/"+b;var v=function(){for(var w=0;w<m.length&&m[w]==0;)w+=1;for(var B=new Array(m.length-w+b),g=0;g<m.length-w;g+=1)B[g]=m[g+w];return B}(),x={};return x.getAt=function(w){return v[w]},x.getLength=function(){return v.length},x.multiply=function(w){for(var B=new Array(x.getLength()+w.getLength()-1),g=0;g<x.getLength();g+=1)for(var d=0;d<w.getLength();d+=1)B[g+d]^=i.gexp(i.glog(x.getAt(g))+i.glog(w.getAt(d)));return s(B,0)},x.mod=function(w){if(x.getLength()-w.getLength()<0)return x;for(var B=i.glog(x.getAt(0))-i.glog(w.getAt(0)),g=new Array(x.getLength()),d=0;d<x.getLength();d+=1)g[d]=x.getAt(d);for(var d=0;d<w.getLength();d+=1)g[d]^=i.gexp(i.glog(w.getAt(d))+B);return s(g,0).mod(w)},x}var a=function(){var m=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],b=function(w,B){var g={};return g.totalCount=w,g.dataCount=B,g},v={},x=function(w,B){switch(B){case r.L:return m[(w-1)*4+0];case r.M:return m[(w-1)*4+1];case r.Q:return m[(w-1)*4+2];case r.H:return m[(w-1)*4+3];default:return}};return v.getRSBlocks=function(w,B){var g=x(w,B);if(typeof g>"u")throw"bad rs block @ typeNumber:"+w+"/errorCorrectionLevel:"+B;for(var d=g.length/3,C=[],k=0;k<d;k+=1)for(var T=g[k*3+0],D=g[k*3+1],S=g[k*3+2],I=0;I<T;I+=1)C.push(b(D,S));return C},v}(),c=function(){var m=[],b=0,v={};return v.getBuffer=function(){return m},v.getAt=function(x){var w=Math.floor(x/8);return(m[w]>>>7-x%8&1)==1},v.put=function(x,w){for(var B=0;B<w;B+=1)v.putBit((x>>>w-B-1&1)==1)},v.getLengthInBits=function(){return b},v.putBit=function(x){var w=Math.floor(b/8);m.length<=w&&m.push(0),x&&(m[w]|=128>>>b%8),b+=1},v},f=function(m){var b=e.MODE_NUMBER,v=m,x={};x.getMode=function(){return b},x.getLength=function(g){return v.length},x.write=function(g){for(var d=v,C=0;C+2<d.length;)g.put(w(d.substring(C,C+3)),10),C+=3;C<d.length&&(d.length-C==1?g.put(w(d.substring(C,C+1)),4):d.length-C==2&&g.put(w(d.substring(C,C+2)),7))};var w=function(g){for(var d=0,C=0;C<g.length;C+=1)d=d*10+B(g.charAt(C));return d},B=function(g){if("0"<=g&&g<="9")return g.charCodeAt(0)-48;throw"illegal char :"+g};return x},h=function(m){var b=e.MODE_ALPHA_NUM,v=m,x={};x.getMode=function(){return b},x.getLength=function(B){return v.length},x.write=function(B){for(var g=v,d=0;d+1<g.length;)B.put(w(g.charAt(d))*45+w(g.charAt(d+1)),11),d+=2;d<g.length&&B.put(w(g.charAt(d)),6)};var w=function(B){if("0"<=B&&B<="9")return B.charCodeAt(0)-48;if("A"<=B&&B<="Z")return B.charCodeAt(0)-65+10;switch(B){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+B}};return x},u=function(m){var b=e.MODE_8BIT_BYTE,v=m,x=t.stringToBytes(m),w={};return w.getMode=function(){return b},w.getLength=function(B){return x.length},w.write=function(B){for(var g=0;g<x.length;g+=1)B.put(x[g],8)},w},l=function(m){var b=e.MODE_KANJI,v=m,x=t.stringToBytesFuncs.SJIS;if(!x)throw"sjis not supported.";(function(g,d){var C=x(g);if(C.length!=2||(C[0]<<8|C[1])!=d)throw"sjis not supported."})("\u53CB",38726);var w=x(m),B={};return B.getMode=function(){return b},B.getLength=function(g){return~~(w.length/2)},B.write=function(g){for(var d=w,C=0;C+1<d.length;){var k=(255&d[C])<<8|255&d[C+1];if(33088<=k&&k<=40956)k-=33088;else if(57408<=k&&k<=60351)k-=49472;else throw"illegal char at "+(C+1)+"/"+k;k=(k>>>8&255)*192+(k&255),g.put(k,13),C+=2}if(C<d.length)throw"illegal char at "+(C+1)},B},y=function(){var m=[],b={};return b.writeByte=function(v){m.push(v&255)},b.writeShort=function(v){b.writeByte(v),b.writeByte(v>>>8)},b.writeBytes=function(v,x,w){x=x||0,w=w||v.length;for(var B=0;B<w;B+=1)b.writeByte(v[B+x])},b.writeString=function(v){for(var x=0;x<v.length;x+=1)b.writeByte(v.charCodeAt(x))},b.toByteArray=function(){return m},b.toString=function(){var v="";v+="[";for(var x=0;x<m.length;x+=1)x>0&&(v+=","),v+=m[x];return v+="]",v},b},N=function(){var m=0,b=0,v=0,x="",w={},B=function(d){x+=String.fromCharCode(g(d&63))},g=function(d){if(!(d<0)){if(d<26)return 65+d;if(d<52)return 97+(d-26);if(d<62)return 48+(d-52);if(d==62)return 43;if(d==63)return 47}throw"n:"+d};return w.writeByte=function(d){for(m=m<<8|d&255,b+=8,v+=1;b>=6;)B(m>>>b-6),b-=6},w.flush=function(){if(b>0&&(B(m<<6-b),m=0,b=0),v%3!=0)for(var d=3-v%3,C=0;C<d;C+=1)x+="="},w.toString=function(){return x},w},E=function(m){var b=m,v=0,x=0,w=0,B={};B.read=function(){for(;w<8;){if(v>=b.length){if(w==0)return-1;throw"unexpected end of file./"+w}var d=b.charAt(v);if(v+=1,d=="=")return w=0,-1;if(d.match(/^\s$/))continue;x=x<<6|g(d.charCodeAt(0)),w+=6}var C=x>>>w-8&255;return w-=8,C};var g=function(d){if(65<=d&&d<=90)return d-65;if(97<=d&&d<=122)return d-97+26;if(48<=d&&d<=57)return d-48+52;if(d==43)return 62;if(d==47)return 63;throw"c:"+d};return B},p=function(m,b){var v=m,x=b,w=new Array(m*b),B={};B.setPixel=function(k,T,D){w[T*v+k]=D},B.write=function(k){k.writeString("GIF87a"),k.writeShort(v),k.writeShort(x),k.writeByte(128),k.writeByte(0),k.writeByte(0),k.writeByte(0),k.writeByte(0),k.writeByte(0),k.writeByte(255),k.writeByte(255),k.writeByte(255),k.writeString(","),k.writeShort(0),k.writeShort(0),k.writeShort(v),k.writeShort(x),k.writeByte(0);var T=2,D=d(T);k.writeByte(T);for(var S=0;D.length-S>255;)k.writeByte(255),k.writeBytes(D,S,255),S+=255;k.writeByte(D.length-S),k.writeBytes(D,S,D.length-S),k.writeByte(0),k.writeString(";")};var g=function(k){var T=k,D=0,S=0,I={};return I.write=function(L,$){if(L>>>$)throw"length over";for(;D+$>=8;)T.writeByte(255&(L<<D|S)),$-=8-D,L>>>=8-D,S=0,D=0;S=L<<D|S,D=D+$},I.flush=function(){D>0&&T.writeByte(S)},I},d=function(k){for(var T=1<<k,D=(1<<k)+1,S=k+1,I=C(),L=0;L<T;L+=1)I.add(String.fromCharCode(L));I.add(String.fromCharCode(T)),I.add(String.fromCharCode(D));var $=y(),M=g($);M.write(T,S);var W=0,j=String.fromCharCode(w[W]);for(W+=1;W<w.length;){var Y=String.fromCharCode(w[W]);W+=1,I.contains(j+Y)?j=j+Y:(M.write(I.indexOf(j),S),I.size()<4095&&(I.size()==1<<S&&(S+=1),I.add(j+Y)),j=Y)}return M.write(I.indexOf(j),S),M.write(D,S),M.flush(),$.toByteArray()},C=function(){var k={},T=0,D={};return D.add=function(S){if(D.contains(S))throw"dup key:"+S;k[S]=T,T+=1},D.size=function(){return T},D.indexOf=function(S){return k[S]},D.contains=function(S){return typeof k[S]<"u"},D};return B},A=function(m,b,v){for(var x=p(m,b),w=0;w<b;w+=1)for(var B=0;B<m;B+=1)x.setPixel(B,w,v(B,w));var g=y();x.write(g);for(var d=N(),C=g.toByteArray(),k=0;k<C.length;k+=1)d.writeByte(C[k]);return d.flush(),"data:image/gif;base64,"+d};return t}();(function(){mc.stringToBytesFuncs["UTF-8"]=function(t){function e(r){for(var n=[],o=0;o<r.length;o++){var i=r.charCodeAt(o);i<128?n.push(i):i<2048?n.push(192|i>>6,128|i&63):i<55296||i>=57344?n.push(224|i>>12,128|i>>6&63,128|i&63):(o++,i=65536+((i&1023)<<10|r.charCodeAt(o)&1023),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}return n}return e(t)}})();(function(t){typeof define=="function"&&define.amd?define([],t):typeof xc=="object"&&(Ec.exports=t())})(function(){return mc})});var Ol={};Vi(Ol,{buildPayment:()=>Hl,newWords:()=>Cl,open:()=>Pl,qrSvg:()=>$l,sync:()=>Rl,validAddress:()=>Ac,validWords:()=>_l});function Yi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Pc(t,...e){if(!Yi(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Gi(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Rc(t){if(typeof t!="function")throw new Error("function expected");return!0}function Wr(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Zi(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Xn(t){if(!Array.isArray(t))throw new Error("array expected")}function Fi(t,e){if(!Gi(!0,e))throw new Error(`${t}: array of strings expected`)}function Hc(t,e){if(!Gi(!1,e))throw new Error(`${t}: array of numbers expected`)}function $c(...t){let e=i=>i,r=(i,s)=>a=>i(s(a)),n=t.map(i=>i.encode).reduceRight(r,e),o=t.map(i=>i.decode).reduce(r,e);return{encode:n,decode:o}}function Oc(t){let e=typeof t=="string"?t.split(""):t,r=e.length;Fi("alphabet",e);let n=new Map(e.map((o,i)=>[o,i]));return{encode:o=>(Xn(o),o.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${t}`);return e[i]})),decode:o=>(Xn(o),o.map(i=>{Wr("alphabet.decode",i);let s=n.get(i);if(s===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);return s}))}}function Mc(t=""){return Wr("join",t),{encode:e=>(Fi("join.decode",e),e.join(t)),decode:e=>(Wr("join.decode",e),e.split(t))}}function Dc(t){return Rc(t),{encode:e=>e,decode:e=>t(e)}}var Qi=(t,e)=>e===0?t:Qi(e,t%e),Vr=(t,e)=>t+(e-Qi(t,e)),Qn=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function ji(t,e,r,n){if(Xn(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Vr(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Vr(e,r)}`);let o=0,i=0,s=Qn[e],a=Qn[r]-1,c=[];for(let f of t){if(Zi(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(o=o<<e|f,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=r;i-=r)c.push((o>>i-r&a)>>>0);let h=Qn[i];if(h===void 0)throw new Error("invalid carry");o&=h-1}if(o=o<<r-i&a,!n&&i>=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&c.push(o>>>0),c}function Kc(t,e=!1){if(Zi(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Vr(8,t)>32||Vr(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!Yi(r))throw new Error("radix2.encode input should be Uint8Array");return ji(Array.from(r),8,t,!e)},decode:r=>(Hc("radix2.decode",r),Uint8Array.from(ji(r,t,8,e)))}}var Xi={encode:t=>new TextDecoder().decode(t),decode:t=>new TextEncoder().encode(t)},qc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wc={encode(t){return Pc(t),t.toHex()},decode(t){return Wr("hex",t),Uint8Array.fromHex(t)}},gr=qc?Wc:$c(Kc(4),Oc("0123456789abcdef"),Mc(""),Dc(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var rt=new Uint8Array,ro=new Uint8Array([0]);function Ze(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}function Rt(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Vc(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];if(!Rt(o))throw new Error("Uint8Array expected");e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}var no=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function Fe(t){return Object.prototype.toString.call(t)==="[object Object]"}function Wt(t){return Number.isSafeInteger(t)}var Ji={equalBytes:Ze,isBytes:Rt,isCoder:Ut,checkBounds:es,concatBytes:Vc,createView:no,isPlainObject:Fe},ts=t=>{if(t!==null&&typeof t!="string"&&!Ut(t)&&!Rt(t)&&!Wt(t))throw new Error(`lengthCoder: expected null | number | Uint8Array | CoderType, got ${t} (${typeof t})`);return{encodeStream(e,r){if(t===null)return;if(Ut(t))return t.encodeStream(e,r);let n;if(typeof t=="number"?n=t:typeof t=="string"&&(n=Gt.resolve(e.stack,t)),typeof n=="bigint"&&(n=Number(n)),n===void 0||n!==r)throw e.err(`Wrong length: ${n} len=${t} exp=${r} (${typeof r})`)},decodeStream(e){let r;if(Ut(t)?r=Number(t.decodeStream(e)):typeof t=="number"?r=t:typeof t=="string"&&(r=Gt.resolve(e.stack,t)),typeof r=="bigint"&&(r=Number(r)),typeof r!="number")throw e.err(`Wrong length: ${r}`);return r}}},wt={BITS:32,FULL_MASK:-1>>>0,len:t=>Math.ceil(t/32),create:t=>new Uint32Array(wt.len(t)),clean:t=>t.fill(0),debug:t=>Array.from(t).map(e=>(e>>>0).toString(2).padStart(32,"0")),checkLen:(t,e)=>{if(wt.len(e)!==t.length)throw new Error(`wrong length=${t.length}. Expected: ${wt.len(e)}`)},chunkLen:(t,e,r)=>{if(e<0)throw new Error(`wrong pos=${e}`);if(e+r>t)throw new Error(`wrong range=${e}/${r} of ${t}`)},set:(t,e,r,n=!0)=>!n&&t[e]&r?!1:(t[e]|=r,!0),pos:(t,e)=>({chunk:Math.floor((t+e)/32),mask:1<<32-(t+e)%32-1}),indices:(t,e,r=!1)=>{wt.checkLen(t,e);let{FULL_MASK:n,BITS:o}=wt,i=o-e%o,s=i?n>>>i<<i:n,a=[];for(let c=0;c<t.length;c++){let f=t[c];if(r&&(f=~f),c===t.length-1&&(f&=s),f!==0)for(let h=0;h<o;h++){let u=1<<o-h-1;f&u&&a.push(c*o+h)}}return a},range:t=>{let e=[],r;for(let n of t)r===void 0||n!==r.pos+r.length?e.push(r={pos:n,length:1}):r.length+=1;return e},rangeDebug:(t,e,r=!1)=>`[${wt.range(wt.indices(t,e,r)).map(n=>`(${n.pos}/${n.length})`).join(", ")}]`,setRange:(t,e,r,n,o=!0)=>{wt.chunkLen(e,r,n);let{FULL_MASK:i,BITS:s}=wt,a=r%s?Math.floor(r/s):void 0,c=r+n,f=c%s?Math.floor(c/s):void 0;if(a!==void 0&&a===f)return wt.set(t,a,i>>>s-n<<s-n-r,o);if(a!==void 0&&!wt.set(t,a,i>>>r%s,o))return!1;let h=a!==void 0?a+1:r/s,u=f!==void 0?f:c/s;for(let l=h;l<u;l++)if(!wt.set(t,l,i,o))return!1;return!(f!==void 0&&a!==f&&!wt.set(t,f,i<<s-c%s,o))}},Gt={pushObj:(t,e,r)=>{let n={obj:e};t.push(n),r((o,i)=>{n.field=o,i(),n.field=void 0}),t.pop()},path:t=>{let e=[];for(let r of t)r.field!==void 0&&e.push(r.field);return e.join("/")},err:(t,e,r)=>{let n=new Error(`${t}(${Gt.path(e)}): ${typeof r=="string"?r:r.message}`);return r instanceof Error&&r.stack&&(n.stack=r.stack),n},resolve:(t,e)=>{let r=e.split("/"),n=t.map(s=>s.obj),o=0;for(;o<r.length&&r[o]==="..";o++)n.pop();let i=n.pop();for(;o<r.length;o++){if(!i||i[r[o]]===void 0)return;i=i[r[o]]}return i}},Jn=class t{constructor(e,r={},n=[],o=void 0,i=0){this.pos=0,this.bitBuf=0,this.bitPos=0,this.data=e,this.opts=r,this.stack=n,this.parent=o,this.parentOffset=i,this.view=no(e)}_enablePointers(){if(this.parent)return this.parent._enablePointers();this.bs||(this.bs=wt.create(this.data.length),wt.setRange(this.bs,this.data.length,0,this.pos,this.opts.allowMultipleReads))}markBytesBS(e,r){return this.parent?this.parent.markBytesBS(this.parentOffset+e,r):!r||!this.bs?!0:wt.setRange(this.bs,this.data.length,e,r,!1)}markBytes(e){let r=this.pos;this.pos+=e;let n=this.markBytesBS(r,e);if(!this.opts.allowMultipleReads&&!n)throw this.err(`multiple read pos=${this.pos} len=${e}`);return n}pushObj(e,r){return Gt.pushObj(this.stack,e,r)}readView(e,r){if(!Number.isFinite(e))throw this.err(`readView: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readView: Unexpected end of buffer");let n=r(this.view,this.pos);return this.markBytes(e),n}absBytes(e){if(e>this.data.length)throw new Error("Unexpected end of buffer");return this.data.subarray(e)}finish(){if(!this.opts.allowUnreadBytes){if(this.bitPos)throw this.err(`${this.bitPos} bits left after unpack: ${gr.encode(this.data.slice(this.pos))}`);if(this.bs&&!this.parent){let e=wt.indices(this.bs,this.data.length,!0);if(e.length){let r=wt.range(e).map(({pos:n,length:o})=>`(${n}/${o})[${gr.encode(this.data.subarray(n,n+o))}]`).join(", ");throw this.err(`unread byte ranges: ${r} (total=${this.data.length})`)}else return}if(!this.isEnd())throw this.err(`${this.leftBytes} bytes ${this.bitPos} bits left after unpack: ${gr.encode(this.data.slice(this.pos))}`)}}err(e){return Gt.err("Reader",this.stack,e)}offsetReader(e){if(e>this.data.length)throw this.err("offsetReader: Unexpected end of buffer");return new t(this.absBytes(e),this.opts,this.stack,this,e)}bytes(e,r=!1){if(this.bitPos)throw this.err("readBytes: bitPos not empty");if(!Number.isFinite(e))throw this.err(`readBytes: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let n=this.data.subarray(this.pos,this.pos+e);return r||this.markBytes(e),n}byte(e=!1){if(this.bitPos)throw this.err("readByte: bitPos not empty");if(this.pos+1>this.data.length)throw this.err("readBytes: Unexpected end of buffer");let r=this.data[this.pos];return e||this.markBytes(1),r}get leftBytes(){return this.data.length-this.pos}get totalBytes(){return this.data.length}isEnd(){return this.pos>=this.data.length&&!this.bitPos}bits(e){if(e>32)throw this.err("BitReader: cannot read more than 32 bits in single call");let r=0;for(;e;){this.bitPos||(this.bitBuf=this.byte(),this.bitPos=8);let n=Math.min(e,this.bitPos);this.bitPos-=n,r=r<<n|this.bitBuf>>this.bitPos&2**n-1,this.bitBuf&=2**this.bitPos-1,e-=n}return r>>>0}find(e,r=this.pos){if(!Rt(e))throw this.err(`find: needle is not bytes! ${e}`);if(this.bitPos)throw this.err("findByte: bitPos not empty");if(!e.length)throw this.err("find: needle is empty");for(let n=r;(n=this.data.indexOf(e[0],n))!==-1;n++){if(n===-1||this.data.length-n<e.length)return;if(Ze(e,this.data.subarray(n,n+e.length)))return n}}},to=class{constructor(e=[]){this.pos=0,this.buffers=[],this.ptrs=[],this.bitBuf=0,this.bitPos=0,this.viewBuf=new Uint8Array(8),this.finished=!1,this.stack=e,this.view=no(this.viewBuf)}pushObj(e,r){return Gt.pushObj(this.stack,e,r)}writeView(e,r){if(this.finished)throw this.err("buffer: finished");if(!Wt(e)||e>8)throw new Error(`wrong writeView length=${e}`);r(this.view),this.bytes(this.viewBuf.slice(0,e)),this.viewBuf.fill(0)}err(e){if(this.finished)throw this.err("buffer: finished");return Gt.err("Reader",this.stack,e)}bytes(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeBytes: ends with non-empty bit buffer");this.buffers.push(e),this.pos+=e.length}byte(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeByte: ends with non-empty bit buffer");this.buffers.push(new Uint8Array([e])),this.pos++}finish(e=!0){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("buffer: ends with non-empty bit buffer");let r=this.buffers.concat(this.ptrs.map(i=>i.buffer)),n=r.map(i=>i.length).reduce((i,s)=>i+s,0),o=new Uint8Array(n);for(let i=0,s=0;i<r.length;i++){let a=r[i];o.set(a,s),s+=a.length}for(let i=this.pos,s=0;s<this.ptrs.length;s++){let a=this.ptrs[s];o.set(a.ptr.encode(i),a.pos),i+=a.buffer.length}if(e){this.buffers=[];for(let i of this.ptrs)i.buffer.fill(0);this.ptrs=[],this.finished=!0,this.bitBuf=0}return o}bits(e,r){if(r>32)throw this.err("writeBits: cannot write more than 32 bits in single call");if(e>=2**r)throw this.err(`writeBits: value (${e}) >= 2**bits (${r})`);for(;r;){let n=Math.min(r,8-this.bitPos);this.bitBuf=this.bitBuf<<n|e>>r-n,this.bitPos+=n,r-=n,e&=2**r-1,this.bitPos===8&&(this.bitPos=0,this.buffers.push(new Uint8Array([this.bitBuf])),this.pos++)}}},eo=t=>Uint8Array.from(t).reverse();function es(t,e,r){if(r){let n=2n**(e-1n);if(t<-n||t>=n)throw new Error(`value out of signed bounds. Expected ${-n} <= ${t} < ${n}`)}else if(0n>t||t>=2n**e)throw new Error(`value out of unsigned bounds. Expected 0 <= ${t} < ${2n**e}`)}function rs(t){return{encodeStream:t.encodeStream,decodeStream:t.decodeStream,size:t.size,encode:e=>{let r=new to;return t.encodeStream(r,e),r.finish()},decode:(e,r={})=>{let n=new Jn(e,r),o=t.decodeStream(n);return n.finish(),o}}}function vt(t,e){if(!Ut(t))throw new Error(`validate: invalid inner value ${t}`);if(typeof e!="function")throw new Error("validate: fn should be function");return rs({size:t.size,encodeStream:(r,n)=>{let o;try{o=e(n)}catch(i){throw r.err(i)}t.encodeStream(r,o)},decodeStream:r=>{let n=t.decodeStream(r);try{return e(n)}catch(o){throw r.err(o)}}})}var Bt=t=>{let e=rs(t);return t.validate?vt(e,t.validate):e},zr=t=>Fe(t)&&typeof t.decode=="function"&&typeof t.encode=="function";function Ut(t){return Fe(t)&&zr(t)&&typeof t.encodeStream=="function"&&typeof t.decodeStream=="function"&&(t.size===void 0||Wt(t.size))}function zc(){return{encode:t=>{if(!Array.isArray(t))throw new Error("array expected");let e={};for(let r of t){if(!Array.isArray(r)||r.length!==2)throw new Error("array of two elements expected");let n=r[0],o=r[1];if(e[n]!==void 0)throw new Error(`key(${n}) appears twice in struct`);e[n]=o}return e},decode:t=>{if(!Fe(t))throw new Error(`expected plain object, got ${t}`);return Object.entries(t)}}}var jc={encode:t=>{if(typeof t!="bigint")throw new Error(`expected bigint, got ${typeof t}`);if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error(`element bigger than MAX_SAFE_INTEGER=${t}`);return Number(t)},decode:t=>{if(!Wt(t))throw new Error("element is not a safe integer");return BigInt(t)}};function Yc(t){if(!Fe(t))throw new Error("plain object expected");return{encode:e=>{if(!Wt(e)||!(e in t))throw new Error(`wrong value ${e}`);return t[e]},decode:e=>{if(typeof e!="string")throw new Error(`wrong value ${typeof e}`);return t[e]}}}function Gc(t,e=!1){if(!Wt(t))throw new Error(`decimal/precision: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`decimal/round: expected boolean, got ${typeof e}`);let r=10n**BigInt(t);return{encode:n=>{if(typeof n!="bigint")throw new Error(`expected bigint, got ${typeof n}`);let o=(n<0n?-n:n).toString(10),i=o.length-t;i<0&&(o=o.padStart(o.length-i,"0"),i=0);let s=o.length-1;for(;s>=i&&o[s]==="0";s--);let a=o.slice(0,i),c=o.slice(i,s+1);return a||(a="0"),n<0n&&(a="-"+a),c?`${a}.${c}`:a},decode:n=>{if(typeof n!="string")throw new Error(`expected string, got ${typeof n}`);if(n==="-0")throw new Error("negative zero is not allowed");let o=!1;if(n.startsWith("-")&&(o=!0,n=n.slice(1)),!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))throw new Error(`wrong string value=${n}`);let i=n.indexOf(".");i=i===-1?n.length:i;let s=n.slice(0,i),a=n.slice(i+1).replace(/0+$/,""),c=BigInt(s)*r;if(!e&&a.length>t)throw new Error(`fractional part cannot be represented with this precision (num=${n}, prec=${t})`);let f=Math.min(a.length,t),h=BigInt(a.slice(0,f))*10n**BigInt(t-f),u=c+h;return o?-u:u}}}function Zc(t){if(!Array.isArray(t))throw new Error(`expected array, got ${typeof t}`);for(let e of t)if(!zr(e))throw new Error(`wrong base coder ${e}`);return{encode:e=>{for(let r of t){let n=r.encode(e);if(n!==void 0)return n}throw new Error(`match/encode: cannot find match in ${e}`)},decode:e=>{for(let r of t){let n=r.decode(e);if(n!==void 0)return n}throw new Error(`match/decode: cannot find match in ${e}`)}}}var ns=t=>{if(!zr(t))throw new Error("BaseCoder expected");return{encode:t.decode,decode:t.encode}},ue={dict:zc,numberBigint:jc,tsEnum:Yc,decimal:Gc,match:Zc,reverse:ns};var oo=(t,e=!1,r=!1,n=!0)=>{if(!Wt(t))throw new Error(`bigint/size: wrong value ${t}`);if(typeof e!="boolean")throw new Error(`bigint/le: expected boolean, got ${typeof e}`);if(typeof r!="boolean")throw new Error(`bigint/signed: expected boolean, got ${typeof r}`);if(typeof n!="boolean")throw new Error(`bigint/sized: expected boolean, got ${typeof n}`);let o=BigInt(t),i=2n**(8n*o-1n);return Bt({size:n?t:void 0,encodeStream:(s,a)=>{r&&a<0&&(a=a|i);let c=[];for(let h=0;h<t;h++)c.push(Number(a&255n)),a>>=8n;let f=new Uint8Array(c).reverse();if(!n){let h=0;for(h=0;h<f.length&&f[h]===0;h++);f=f.subarray(h)}s.bytes(e?f.reverse():f)},decodeStream:s=>{let a=s.bytes(n?t:Math.min(t,s.leftBytes)),c=e?a:eo(a),f=0n;for(let h=0;h<c.length;h++)f|=BigInt(c[h])<<8n*BigInt(h);return r&&f&i&&(f=(f^i)-i),f},validate:s=>{if(typeof s!="bigint")throw new Error(`bigint: invalid value: ${s}`);return es(s,8n*o,!!r),s}})};var os=oo(32,!1);var Qe=oo(8,!0);var is=oo(8,!0,!0);var Fc=(t,e)=>Bt({size:t,encodeStream:(r,n)=>r.writeView(t,o=>e.write(o,n)),decodeStream:r=>r.readView(t,e.read),validate:r=>{if(typeof r!="number")throw new Error(`viewCoder: expected number, got ${typeof r}`);return e.validate&&e.validate(r),r}}),wr=(t,e,r)=>{let n=t*8,o=2**(n-1),i=c=>{if(!Wt(c))throw new Error(`sintView: value is not safe integer: ${c}`);if(c<-o||c>=o)throw new Error(`sintView: value out of bounds. Expected ${-o} <= ${c} < ${o}`)},s=2**n,a=c=>{if(!Wt(c))throw new Error(`uintView: value is not safe integer: ${c}`);if(0>c||c>=s)throw new Error(`uintView: value out of bounds. Expected 0 <= ${c} < ${s}`)};return Fc(t,{write:r.write,read:r.read,validate:e?i:a})},Q=wr(4,!1,{read:(t,e)=>t.getUint32(e,!0),write:(t,e)=>t.setUint32(0,e,!0)}),ss=wr(4,!1,{read:(t,e)=>t.getUint32(e,!1),write:(t,e)=>t.setUint32(0,e,!1)}),le=wr(4,!0,{read:(t,e)=>t.getInt32(e,!0),write:(t,e)=>t.setInt32(0,e,!0)});var io=wr(2,!1,{read:(t,e)=>t.getUint16(e,!0),write:(t,e)=>t.setUint16(0,e,!0)});var $t=wr(1,!1,{read:(t,e)=>t.getUint8(e),write:(t,e)=>t.setUint8(0,e)});var et=(t,e=!1)=>{if(typeof e!="boolean")throw new Error(`bytes/le: expected boolean, got ${typeof e}`);let r=ts(t),n=Rt(t);return Bt({size:typeof t=="number"?t:void 0,encodeStream:(o,i)=>{n||r.encodeStream(o,i.length),o.bytes(e?eo(i):i),n&&o.bytes(t)},decodeStream:o=>{let i;if(n){let s=o.find(t);if(!s)throw o.err("bytes: cannot find terminator");i=o.bytes(s-o.pos),o.bytes(t.length)}else i=o.bytes(t===null?o.leftBytes:r.decodeStream(o));return e?eo(i):i},validate:o=>{if(!Rt(o))throw new Error(`bytes: invalid value ${o}`);return o}})};function as(t,e){if(!Ut(e))throw new Error(`prefix: invalid inner value ${e}`);return Vt(et(t),ns(e))}var jr=(t,e=!1)=>vt(Vt(et(t,e),Xi),r=>{if(typeof r!="string")throw new Error(`expected string, got ${typeof r}`);return r});var cs=(t,e={isLE:!1,with0x:!1})=>{let r=Vt(et(t,e.isLE),gr),n=e.with0x;if(typeof n!="boolean")throw new Error(`hex/with0x: expected boolean, got ${typeof n}`);return n&&(r=Vt(r,{encode:o=>`0x${o}`,decode:o=>{if(!o.startsWith("0x"))throw new Error("hex(with0x=true).encode input should start with 0x");return o.slice(2)}})),r};function Vt(t,e){if(!Ut(t))throw new Error(`apply: invalid inner value ${t}`);if(!zr(e))throw new Error(`apply: invalid base value ${t}`);return Bt({size:t.size,encodeStream:(r,n)=>{let o;try{o=e.decode(n)}catch(i){throw r.err(""+i)}return t.encodeStream(r,o)},decodeStream:r=>{let n=t.decodeStream(r);try{return e.encode(n)}catch(o){throw r.err(""+o)}}})}var fs=(t,e=!1)=>{if(!Rt(t))throw new Error(`flag/flagValue: expected Uint8Array, got ${typeof t}`);if(typeof e!="boolean")throw new Error(`flag/xor: expected boolean, got ${typeof e}`);return Bt({size:t.length,encodeStream:(r,n)=>{!!n!==e&&r.bytes(t)},decodeStream:r=>{let n=r.leftBytes>=t.length;return n&&(n=Ze(r.bytes(t.length,!0),t),n&&r.bytes(t.length)),n!==e},validate:r=>{if(r!==void 0&&typeof r!="boolean")throw new Error(`flag: expected boolean value or undefined, got ${typeof r}`);return r}})};function us(t,e,r){if(!Ut(e))throw new Error(`flagged: invalid inner value ${e}`);if(typeof t!="string"&&!Ut(e))throw new Error(`flagged: wrong path=${t}`);return Bt({encodeStream:(n,o)=>{typeof t=="string"?Gt.resolve(n.stack,t)?e.encodeStream(n,o):r&&e.encodeStream(n,r):(t.encodeStream(n,!!o),o?e.encodeStream(n,o):r&&e.encodeStream(n,r))},decodeStream:n=>{let o=!1;if(typeof t=="string"?o=!!Gt.resolve(n.stack,t):o=t.decodeStream(n),o)return e.decodeStream(n);r&&e.decodeStream(n)}})}function Yr(t,e,r=!0){if(!Ut(t))throw new Error(`magic: invalid inner value ${t}`);if(typeof r!="boolean")throw new Error(`magic: expected boolean, got ${typeof r}`);return Bt({size:t.size,encodeStream:(n,o)=>t.encodeStream(n,e),decodeStream:n=>{let o=t.decodeStream(n);if(r&&typeof o!="object"&&o!==e||Rt(e)&&!Ze(e,o))throw n.err(`magic: invalid value: ${o} !== ${e}`)},validate:n=>{if(n!==void 0)throw new Error(`magic: wrong value=${typeof n}`);return n}})}function ls(t){let e=0;for(let r of t){if(r.size===void 0)return;if(!Wt(r.size))throw new Error(`sizeof: wrong element size=${e}`);e+=r.size}return e}function ft(t){if(!Fe(t))throw new Error(`struct: expected plain object, got ${t}`);for(let e in t)if(!Ut(t[e]))throw new Error(`struct: field ${e} is not CoderType`);return Bt({size:ls(Object.values(t)),encodeStream:(e,r)=>{e.pushObj(r,n=>{for(let o in t)n(o,()=>t[o].encodeStream(e,r[o]))})},decodeStream:e=>{let r={};return e.pushObj(r,n=>{for(let o in t)n(o,()=>r[o]=t[o].decodeStream(e))}),r},validate:e=>{if(typeof e!="object"||e===null)throw new Error(`struct: invalid value ${e}`);return e}})}function ds(t){if(!Array.isArray(t))throw new Error(`Packed.Tuple: got ${typeof t} instead of array`);for(let e=0;e<t.length;e++)if(!Ut(t[e]))throw new Error(`tuple: field ${e} is not CoderType`);return Bt({size:ls(t),encodeStream:(e,r)=>{if(!Array.isArray(r))throw e.err(`tuple: invalid value ${r}`);e.pushObj(r,n=>{for(let o=0;o<t.length;o++)n(`${o}`,()=>t[o].encodeStream(e,r[o]))})},decodeStream:e=>{let r=[];return e.pushObj(r,n=>{for(let o=0;o<t.length;o++)n(`${o}`,()=>r.push(t[o].decodeStream(e)))}),r},validate:e=>{if(!Array.isArray(e))throw new Error(`tuple: invalid value ${e}`);if(e.length!==t.length)throw new Error(`tuple: wrong length=${e.length}, expected ${t.length}`);return e}})}function St(t,e){if(!Ut(e))throw new Error(`array: invalid inner value ${e}`);let r=ts(typeof t=="string"?`../${t}`:t);return Bt({size:typeof t=="number"&&e.size?t*e.size:void 0,encodeStream:(n,o)=>{let i=n;i.pushObj(o,s=>{Rt(t)||r.encodeStream(n,o.length);for(let a=0;a<o.length;a++)s(`${a}`,()=>{let c=o[a],f=n.pos;if(e.encodeStream(n,c),Rt(t)){if(t.length>i.pos-f)return;let h=i.finish(!1).subarray(f,i.pos);if(Ze(h.subarray(0,t.length),t))throw i.err(`array: inner element encoding same as separator. elm=${c} data=${h}`)}})}),Rt(t)&&n.bytes(t)},decodeStream:n=>{let o=[];return n.pushObj(o,i=>{if(t===null)for(let s=0;!n.isEnd()&&(i(`${s}`,()=>o.push(e.decodeStream(n))),!(e.size&&n.leftBytes<e.size));s++);else if(Rt(t))for(let s=0;;s++){if(Ze(n.bytes(t.length,!0),t)){n.bytes(t.length);break}i(`${s}`,()=>o.push(e.decodeStream(n)))}else{let s;i("arrayLen",()=>s=r.decodeStream(n));for(let a=0;a<s;a++)i(`${a}`,()=>o.push(e.decodeStream(n)))}}),o},validate:n=>{if(!Array.isArray(n))throw new Error(`array: invalid value ${n}`);return n}})}function Qc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function so(t,...e){if(!Qc(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function ao(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function hs(t,e){so(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var Fr=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Ot=(t,e)=>t<<32-e|t>>>e,yr=(t,e)=>t<<e|t>>>32-e>>>0;function Xc(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function co(t){return typeof t=="string"&&(t=Xc(t)),so(t),t}var Zr=class{clone(){return this._cloneInto()}};function Qr(t){let e=n=>t().update(co(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Jc(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+f,a,n)}var ps=(t,e,r)=>t&e^~t&r,gs=(t,e,r)=>t&e^t&r^e&r,Xe=class extends Zr{constructor(e,r,n,o){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Fr(this.buffer)}update(e){ao(this);let{view:r,buffer:n,blockLen:o}=this;e=co(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Fr(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ao(this),hs(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let u=s;u<o;u++)r[u]=0;Jc(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Fr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,h=this.get();if(f>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,h[u],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%r&&e.buffer.set(n),e}};var tf=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),ys=new Uint8Array(new Array(16).fill(0).map((t,e)=>e)),ef=ys.map(t=>(9*t+5)%16),uo=[ys],lo=[ef];for(let t=0;t<4;t++)for(let e of[uo,lo])e.push(e[t].map(r=>tf[r]));var bs=[[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(t=>new Uint8Array(t)),rf=uo.map((t,e)=>t.map(r=>bs[e][r])),nf=lo.map((t,e)=>t.map(r=>bs[e][r])),of=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),sf=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function ws(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var Xr=new Uint32Array(16),fo=class extends Xe{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:r,h2:n,h3:o,h4:i}=this;return[e,r,n,o,i]}set(e,r,n,o,i){this.h0=e|0,this.h1=r|0,this.h2=n|0,this.h3=o|0,this.h4=i|0}process(e,r){for(let y=0;y<16;y++,r+=4)Xr[y]=e.getUint32(r,!0);let n=this.h0|0,o=n,i=this.h1|0,s=i,a=this.h2|0,c=a,f=this.h3|0,h=f,u=this.h4|0,l=u;for(let y=0;y<5;y++){let N=4-y,E=of[y],p=sf[y],A=uo[y],m=lo[y],b=rf[y],v=nf[y];for(let x=0;x<16;x++){let w=yr(n+ws(y,i,a,f)+Xr[A[x]]+E,b[x])+u|0;n=u,u=f,f=yr(a,10)|0,a=i,i=w}for(let x=0;x<16;x++){let w=yr(o+ws(N,s,c,h)+Xr[m[x]]+p,v[x])+l|0;o=l,l=h,h=yr(c,10)|0,c=s,s=w}}this.set(this.h1+a+h|0,this.h2+f+l|0,this.h3+u+o|0,this.h4+n+s|0,this.h0+i+c|0)}roundClean(){Xr.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}},ms=Qr(()=>new fo);var af=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]),de=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),he=new Uint32Array(64),ho=class extends Xe{constructor(){super(64,32,8,!1),this.A=de[0]|0,this.B=de[1]|0,this.C=de[2]|0,this.D=de[3]|0,this.E=de[4]|0,this.F=de[5]|0,this.G=de[6]|0,this.H=de[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let u=0;u<16;u++,r+=4)he[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let l=he[u-15],y=he[u-2],N=Ot(l,7)^Ot(l,18)^l>>>3,E=Ot(y,17)^Ot(y,19)^y>>>10;he[u]=E+he[u-7]+N+he[u-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let l=Ot(a,6)^Ot(a,11)^Ot(a,25),y=h+l+ps(a,c,f)+af[u]+he[u]|0,E=(Ot(n,2)^Ot(n,13)^Ot(n,22))+gs(n,o,i)|0;h=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+E|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){he.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var kt=Qr(()=>new ho);function xs(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function cf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Je(t,...e){if(!cf(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Es(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");xs(t.outputLen),xs(t.blockLen)}function tr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function vs(t,e){Je(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var Ne=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Jr=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Mt=(t,e)=>t<<32-e|t>>>e;function ff(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function br(t){return typeof t=="string"&&(t=ff(t)),Je(t),t}function Bs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Je(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}var er=class{clone(){return this._cloneInto()}};function Ss(t){let e=n=>t().update(br(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function tn(t=32){if(Ne&&typeof Ne.getRandomValues=="function")return Ne.getRandomValues(new Uint8Array(t));if(Ne&&typeof Ne.randomBytes=="function")return Ne.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function uf(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+f,a,n)}var As=(t,e,r)=>t&e^~t&r,ks=(t,e,r)=>t&e^t&r^e&r,en=class extends er{constructor(e,r,n,o){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Jr(this.buffer)}update(e){tr(this);let{view:r,buffer:n,blockLen:o}=this;e=br(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Jr(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){tr(this),vs(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let u=s;u<o;u++)r[u]=0;uf(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Jr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,h=this.get();if(f>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,h[u],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%r&&e.buffer.set(n),e}};var lf=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]),pe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ge=new Uint32Array(64),po=class extends en{constructor(){super(64,32,8,!1),this.A=pe[0]|0,this.B=pe[1]|0,this.C=pe[2]|0,this.D=pe[3]|0,this.E=pe[4]|0,this.F=pe[5]|0,this.G=pe[6]|0,this.H=pe[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let u=0;u<16;u++,r+=4)ge[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let l=ge[u-15],y=ge[u-2],N=Mt(l,7)^Mt(l,18)^l>>>3,E=Mt(y,17)^Mt(y,19)^y>>>10;ge[u]=E+ge[u-7]+N+ge[u-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let l=Mt(a,6)^Mt(a,11)^Mt(a,25),y=h+l+As(a,c,f)+lf[u]+ge[u]|0,E=(Mt(n,2)^Mt(n,13)^Mt(n,22))+ks(n,o,i)|0;h=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+E|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){ge.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var rn=Ss(()=>new po);var nn=class extends er{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Es(e);let n=br(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return tr(this),this.iHash.update(e),this}digestInto(e){tr(this),Je(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},go=(t,e,r)=>new nn(t,e).update(r).digest();go.create=(t,e)=>new nn(t,e);var Eo={};Vi(Eo,{aInRange:()=>zt,abool:()=>Ce,abytes:()=>rr,bitGet:()=>yf,bitLen:()=>mo,bitMask:()=>mr,bitSet:()=>bf,bytesToHex:()=>_e,bytesToNumberBE:()=>Ht,bytesToNumberLE:()=>an,concatBytes:()=>Ft,createHmacDrbg:()=>xo,ensureBytes:()=>ut,equalBytes:()=>gf,hexToBytes:()=>Re,hexToNumber:()=>bo,inRange:()=>ye,isBytes:()=>we,memoized:()=>fn,notImplemented:()=>xf,numberToBytesBE:()=>Dt,numberToBytesLE:()=>cn,numberToHexUnpadded:()=>Pe,numberToVarBytesBE:()=>pf,utf8ToBytes:()=>wf,validateObject:()=>be});var on=BigInt(0),sn=BigInt(1),df=BigInt(2);function we(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function rr(t){if(!we(t))throw new Error("Uint8Array expected")}function Ce(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}var hf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function _e(t){rr(t);let e="";for(let r=0;r<t.length;r++)e+=hf[t[r]];return e}function Pe(t){let e=t.toString(16);return e.length&1?"0"+e:e}function bo(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?on:BigInt("0x"+t)}var Zt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ts(t){if(t>=Zt._0&&t<=Zt._9)return t-Zt._0;if(t>=Zt.A&&t<=Zt.F)return t-(Zt.A-10);if(t>=Zt.a&&t<=Zt.f)return t-(Zt.a-10)}function Re(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ts(t.charCodeAt(i)),a=Ts(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Ht(t){return bo(_e(t))}function an(t){return rr(t),bo(_e(Uint8Array.from(t).reverse()))}function Dt(t,e){return Re(t.toString(16).padStart(e*2,"0"))}function cn(t,e){return Dt(t,e).reverse()}function pf(t){return Re(Pe(t))}function ut(t,e,r){let n;if(typeof e=="string")try{n=Re(e)}catch(i){throw new Error(t+" must be hex string or Uint8Array, cause: "+i)}else if(we(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(t+" of length "+r+" expected, got "+o);return n}function Ft(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];rr(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function gf(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function wf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}var wo=t=>typeof t=="bigint"&&on<=t;function ye(t,e,r){return wo(t)&&wo(e)&&wo(r)&&e<=t&&t<r}function zt(t,e,r,n){if(!ye(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function mo(t){let e;for(e=0;t>on;t>>=sn,e+=1);return e}function yf(t,e){return t>>BigInt(e)&sn}function bf(t,e,r){return t|(r?sn:on)<<BigInt(e)}var mr=t=>(df<<BigInt(t-1))-sn,yo=t=>new Uint8Array(t),Is=t=>Uint8Array.from(t);function xo(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=yo(t),o=yo(t),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...u)=>r(o,n,...u),c=(u=yo())=>{o=a(Is([0]),u),n=a(),u.length!==0&&(o=a(Is([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,l=[];for(;u<e;){n=a();let y=n.slice();l.push(y),u+=n.length}return Ft(...l)};return(u,l)=>{s(),c(u);let y;for(;!(y=l(f()));)c();return s(),y}}var mf={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||we(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function be(t,e,r={}){let n=(o,i,s)=>{let a=mf[i];if(typeof a!="function")throw new Error("invalid validator function");let c=t[o];if(!(s&&c===void 0)&&!a(c,t))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return t}var xf=()=>{throw new Error("not implemented")};function fn(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let i=t(r,...n);return e.set(r,i),i}}var dt=BigInt(0),nt=BigInt(1),He=BigInt(2),Ef=BigInt(3),vo=BigInt(4),Us=BigInt(5),Ls=BigInt(8),vf=BigInt(9),Bf=BigInt(16);function lt(t,e){let r=t%e;return r>=dt?r:e+r}function Sf(t,e,r){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(r<=dt)throw new Error("invalid modulus");if(r===nt)return dt;let n=nt;for(;e>dt;)e&nt&&(n=n*t%r),t=t*t%r,e>>=nt;return n}function Lt(t,e,r){let n=t;for(;e-- >dt;)n*=n,n%=r;return n}function un(t,e){if(t===dt)throw new Error("invert: expected non-zero number");if(e<=dt)throw new Error("invert: expected positive modulus, got "+e);let r=lt(t,e),n=e,o=dt,i=nt,s=nt,a=dt;for(;r!==dt;){let f=n/r,h=n%r,u=o-s*f,l=i-a*f;n=r,r=h,o=s,i=a,s=u,a=l}if(n!==nt)throw new Error("invert: does not exist");return lt(o,e)}function Af(t){let e=(t-nt)/He,r,n,o;for(r=t-nt,n=0;r%He===dt;r/=He,n++);for(o=He;o<t&&Sf(o,e,t)!==t-nt;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(t+nt)/vo;return function(c,f){let h=c.pow(f,s);if(!c.eql(c.sqr(h),f))throw new Error("Cannot find square root");return h}}let i=(r+nt)/He;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,h=a.pow(a.mul(a.ONE,o),r),u=a.pow(c,i),l=a.pow(c,r);for(;!a.eql(l,a.ONE);){if(a.eql(l,a.ZERO))return a.ZERO;let y=1;for(let E=a.sqr(l);y<f&&!a.eql(E,a.ONE);y++)E=a.sqr(E);let N=a.pow(h,nt<<BigInt(f-y-1));h=a.sqr(N),u=a.mul(u,N),l=a.mul(l,h),f=y}return u}}function kf(t){if(t%vo===Ef){let e=(t+nt)/vo;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(t%Ls===Us){let e=(t-Us)/Ls;return function(n,o){let i=n.mul(o,He),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,He),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return t%Bf,Af(t)}var Tf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Bo(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Tf.reduce((n,o)=>(n[o]="function",n),e);return be(t,r)}function If(t,e,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return t.ONE;if(r===nt)return e;let n=t.ONE,o=e;for(;r>dt;)r&nt&&(n=t.mul(n,o)),o=t.sqr(o),r>>=nt;return n}function Uf(t,e){let r=new Array(e.length),n=e.reduce((i,s,a)=>t.is0(s)?i:(r[a]=i,t.mul(i,s)),t.ONE),o=t.inv(n);return e.reduceRight((i,s,a)=>t.is0(s)?i:(r[a]=t.mul(i,r[a]),t.mul(i,s)),o),r}function So(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ln(t,e,r=!1,n={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:o,nByteLength:i}=So(t,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:t,BITS:o,BYTES:i,MASK:mr(o),ZERO:dt,ONE:nt,create:c=>lt(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return dt<=c&&c<t},is0:c=>c===dt,isOdd:c=>(c&nt)===nt,neg:c=>lt(-c,t),eql:(c,f)=>c===f,sqr:c=>lt(c*c,t),add:(c,f)=>lt(c+f,t),sub:(c,f)=>lt(c-f,t),mul:(c,f)=>lt(c*f,t),pow:(c,f)=>If(a,c,f),div:(c,f)=>lt(c*un(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>un(c,t),sqrt:n.sqrt||(c=>(s||(s=kf(t)),s(a,c))),invertBatch:c=>Uf(a,c),cmov:(c,f,h)=>h?f:c,toBytes:c=>r?cn(c,i):Dt(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?an(c):Ht(c)}});return Object.freeze(a)}function Ns(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ao(t){let e=Ns(t);return e+Math.ceil(e/2)}function Cs(t,e,r=!1){let n=t.length,o=Ns(e),i=Ao(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ht(t):an(t),a=lt(s,e-nt)+nt;return r?cn(a,o):Dt(a,o)}var _s=BigInt(0),dn=BigInt(1);function ko(t,e){let r=e.negate();return t?r:e}function Ps(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function To(t,e){Ps(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1);return{windows:r,windowSize:n}}function Nf(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Cf(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Io=new WeakMap,Rs=new WeakMap;function Uo(t){return Rs.get(t)||1}function Hs(t,e){return{constTimeNegate:ko,hasPrecomputes(r){return Uo(r)!==1},unsafeLadder(r,n,o=t.ZERO){let i=r;for(;n>_s;)n&dn&&(o=o.add(i)),i=i.double(),n>>=dn;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=To(n,e),s=[],a=r,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(r,n,o){let{windows:i,windowSize:s}=To(r,e),a=t.ZERO,c=t.BASE,f=BigInt(2**r-1),h=2**r,u=BigInt(r);for(let l=0;l<i;l++){let y=l*s,N=Number(o&f);o>>=u,N>s&&(N-=h,o+=dn);let E=y,p=y+Math.abs(N)-1,A=l%2!==0,m=N<0;N===0?c=c.add(ko(A,n[E])):a=a.add(ko(m,n[p]))}return{p:a,f:c}},wNAFUnsafe(r,n,o,i=t.ZERO){let{windows:s,windowSize:a}=To(r,e),c=BigInt(2**r-1),f=2**r,h=BigInt(r);for(let u=0;u<s;u++){let l=u*a;if(o===_s)break;let y=Number(o&c);if(o>>=h,y>a&&(y-=f,o+=dn),y===0)continue;let N=n[l+Math.abs(y)-1];y<0&&(N=N.negate()),i=i.add(N)}return i},getPrecomputes(r,n,o){let i=Io.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&Io.set(n,o(i))),i},wNAFCached(r,n,o){let i=Uo(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=Uo(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){Ps(n,e),Rs.set(r,n),Io.delete(r)}}}function $s(t,e,r,n){if(Nf(r,t),Cf(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,i=mo(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=(1<<s)-1,c=new Array(a+1).fill(o),f=Math.floor((e.BITS-1)/s)*s,h=o;for(let u=f;u>=0;u-=s){c.fill(o);for(let y=0;y<n.length;y++){let N=n[y],E=Number(N>>BigInt(u)&BigInt(a));c[E]=c[E].add(r[y])}let l=o;for(let y=c.length-1,N=o;y>0;y--)N=N.add(c[y]),l=l.add(N);if(h=h.add(l),u!==0)for(let y=0;y<s;y++)h=h.double()}return h}function Lo(t){return Bo(t.Fp),be(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...So(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function Os(t){t.lowS!==void 0&&Ce("lowS",t.lowS),t.prehash!==void 0&&Ce("prehash",t.prehash)}function _f(t){let e=Lo(t);be(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:o}=e;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:Pf,hexToBytes:Rf}=Eo,Qt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(t,e)=>{let{Err:r}=Qt;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Pe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Pe(o.length/2|128):"";return Pe(t)+i+o+e},decode(t,e){let{Err:r}=Qt,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of f)s=s<<8|h;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=Qt;if(t<Xt)throw new e("integer: negative integers are not allowed");let r=Pe(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Qt;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Pf(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Qt,o=typeof t=="string"?Rf(t):t;rr(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=Qt,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},Xt=BigInt(0),yt=BigInt(1),Ed=BigInt(2),Ms=BigInt(3),vd=BigInt(4);function Hf(t){let e=_f(t),{Fp:r}=e,n=ln(e.n,e.nBitLength),o=e.toBytes||((E,p,A)=>{let m=p.toAffine();return Ft(Uint8Array.from([4]),r.toBytes(m.x),r.toBytes(m.y))}),i=e.fromBytes||(E=>{let p=E.subarray(1),A=r.fromBytes(p.subarray(0,r.BYTES)),m=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:A,y:m}});function s(E){let{a:p,b:A}=e,m=r.sqr(E),b=r.mul(m,E);return r.add(r.add(b,r.mul(E,p)),A)}if(!r.eql(r.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(E){return ye(E,yt,e.n)}function c(E){let{allowedPrivateKeyLengths:p,nByteLength:A,wrapPrivateKey:m,n:b}=e;if(p&&typeof E!="bigint"){if(we(E)&&(E=_e(E)),typeof E!="string"||!p.includes(E.length))throw new Error("invalid private key");E=E.padStart(A*2,"0")}let v;try{v=typeof E=="bigint"?E:Ht(ut("private key",E,A))}catch{throw new Error("invalid private key, expected hex or "+A+" bytes, got "+typeof E)}return m&&(v=lt(v,b)),zt("private key",v,yt,b),v}function f(E){if(!(E instanceof l))throw new Error("ProjectivePoint expected")}let h=fn((E,p)=>{let{px:A,py:m,pz:b}=E;if(r.eql(b,r.ONE))return{x:A,y:m};let v=E.is0();p==null&&(p=v?r.ONE:r.inv(b));let x=r.mul(A,p),w=r.mul(m,p),B=r.mul(b,p);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(B,r.ONE))throw new Error("invZ was invalid");return{x,y:w}}),u=fn(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.py))return;throw new Error("bad point: ZERO")}let{x:p,y:A}=E.toAffine();if(!r.isValid(p)||!r.isValid(A))throw new Error("bad point: x or y not FE");let m=r.sqr(A),b=s(p);if(!r.eql(m,b))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(p,A,m){if(this.px=p,this.py=A,this.pz=m,p==null||!r.isValid(p))throw new Error("x required");if(A==null||!r.isValid(A))throw new Error("y required");if(m==null||!r.isValid(m))throw new Error("z required");Object.freeze(this)}static fromAffine(p){let{x:A,y:m}=p||{};if(!p||!r.isValid(A)||!r.isValid(m))throw new Error("invalid affine point");if(p instanceof l)throw new Error("projective point not allowed");let b=v=>r.eql(v,r.ZERO);return b(A)&&b(m)?l.ZERO:new l(A,m,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){let A=r.invertBatch(p.map(m=>m.pz));return p.map((m,b)=>m.toAffine(A[b])).map(l.fromAffine)}static fromHex(p){let A=l.fromAffine(i(ut("pointHex",p)));return A.assertValidity(),A}static fromPrivateKey(p){return l.BASE.multiply(c(p))}static msm(p,A){return $s(l,n,p,A)}_setWindowSize(p){N.setWindowSize(this,p)}assertValidity(){u(this)}hasEvenY(){let{y:p}=this.toAffine();if(r.isOdd)return!r.isOdd(p);throw new Error("Field doesn't support isOdd")}equals(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.eql(r.mul(A,w),r.mul(v,b)),g=r.eql(r.mul(m,w),r.mul(x,b));return B&&g}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:p,b:A}=e,m=r.mul(A,Ms),{px:b,py:v,pz:x}=this,w=r.ZERO,B=r.ZERO,g=r.ZERO,d=r.mul(b,b),C=r.mul(v,v),k=r.mul(x,x),T=r.mul(b,v);return T=r.add(T,T),g=r.mul(b,x),g=r.add(g,g),w=r.mul(p,g),B=r.mul(m,k),B=r.add(w,B),w=r.sub(C,B),B=r.add(C,B),B=r.mul(w,B),w=r.mul(T,w),g=r.mul(m,g),k=r.mul(p,k),T=r.sub(d,k),T=r.mul(p,T),T=r.add(T,g),g=r.add(d,d),d=r.add(g,d),d=r.add(d,k),d=r.mul(d,T),B=r.add(B,d),k=r.mul(v,x),k=r.add(k,k),d=r.mul(k,T),w=r.sub(w,d),g=r.mul(k,C),g=r.add(g,g),g=r.add(g,g),new l(w,B,g)}add(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.ZERO,g=r.ZERO,d=r.ZERO,C=e.a,k=r.mul(e.b,Ms),T=r.mul(A,v),D=r.mul(m,x),S=r.mul(b,w),I=r.add(A,m),L=r.add(v,x);I=r.mul(I,L),L=r.add(T,D),I=r.sub(I,L),L=r.add(A,b);let $=r.add(v,w);return L=r.mul(L,$),$=r.add(T,S),L=r.sub(L,$),$=r.add(m,b),B=r.add(x,w),$=r.mul($,B),B=r.add(D,S),$=r.sub($,B),d=r.mul(C,L),B=r.mul(k,S),d=r.add(B,d),B=r.sub(D,d),d=r.add(D,d),g=r.mul(B,d),D=r.add(T,T),D=r.add(D,T),S=r.mul(C,S),L=r.mul(k,L),D=r.add(D,S),S=r.sub(T,S),S=r.mul(C,S),L=r.add(L,S),T=r.mul(D,L),g=r.add(g,T),T=r.mul($,L),B=r.mul(I,B),B=r.sub(B,T),T=r.mul(I,D),d=r.mul($,d),d=r.add(d,T),new l(B,g,d)}subtract(p){return this.add(p.negate())}is0(){return this.equals(l.ZERO)}wNAF(p){return N.wNAFCached(this,p,l.normalizeZ)}multiplyUnsafe(p){let{endo:A,n:m}=e;zt("scalar",p,Xt,m);let b=l.ZERO;if(p===Xt)return b;if(this.is0()||p===yt)return this;if(!A||N.hasPrecomputes(this))return N.wNAFCachedUnsafe(this,p,l.normalizeZ);let{k1neg:v,k1:x,k2neg:w,k2:B}=A.splitScalar(p),g=b,d=b,C=this;for(;x>Xt||B>Xt;)x&yt&&(g=g.add(C)),B&yt&&(d=d.add(C)),C=C.double(),x>>=yt,B>>=yt;return v&&(g=g.negate()),w&&(d=d.negate()),d=new l(r.mul(d.px,A.beta),d.py,d.pz),g.add(d)}multiply(p){let{endo:A,n:m}=e;zt("scalar",p,yt,m);let b,v;if(A){let{k1neg:x,k1:w,k2neg:B,k2:g}=A.splitScalar(p),{p:d,f:C}=this.wNAF(w),{p:k,f:T}=this.wNAF(g);d=N.constTimeNegate(x,d),k=N.constTimeNegate(B,k),k=new l(r.mul(k.px,A.beta),k.py,k.pz),b=d.add(k),v=C.add(T)}else{let{p:x,f:w}=this.wNAF(p);b=x,v=w}return l.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(p,A,m){let b=l.BASE,v=(w,B)=>B===Xt||B===yt||!w.equals(b)?w.multiplyUnsafe(B):w.multiply(B),x=v(this,A).add(v(p,m));return x.is0()?void 0:x}toAffine(p){return h(this,p)}isTorsionFree(){let{h:p,isTorsionFree:A}=e;if(p===yt)return!0;if(A)return A(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:p,clearCofactor:A}=e;return p===yt?this:A?A(l,this):this.multiplyUnsafe(e.h)}toRawBytes(p=!0){return Ce("isCompressed",p),this.assertValidity(),o(l,this,p)}toHex(p=!0){return Ce("isCompressed",p),_e(this.toRawBytes(p))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let y=e.nBitLength,N=Hs(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function $f(t){let e=Lo(t);return be(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Ds(t){let e=$f(t),{Fp:r,n}=e,o=r.BYTES+1,i=2*r.BYTES+1;function s(S){return lt(S,n)}function a(S){return un(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:h,isWithinCurveOrder:u}=Hf({...e,toBytes(S,I,L){let $=I.toAffine(),M=r.toBytes($.x),W=Ft;return Ce("isCompressed",L),L?W(Uint8Array.from([I.hasEvenY()?2:3]),M):W(Uint8Array.from([4]),M,r.toBytes($.y))},fromBytes(S){let I=S.length,L=S[0],$=S.subarray(1);if(I===o&&(L===2||L===3)){let M=Ht($);if(!ye(M,yt,r.ORDER))throw new Error("Point is not on curve");let W=h(M),j;try{j=r.sqrt(W)}catch(X){let F=X instanceof Error?": "+X.message:"";throw new Error("Point is not on curve"+F)}let Y=(j&yt)===yt;return(L&1)===1!==Y&&(j=r.neg(j)),{x:M,y:j}}else if(I===i&&L===4){let M=r.fromBytes($.subarray(0,r.BYTES)),W=r.fromBytes($.subarray(r.BYTES,2*r.BYTES));return{x:M,y:W}}else{let M=o,W=i;throw new Error("invalid Point, expected length of "+M+", or uncompressed "+W+", got "+I)}}}),l=S=>_e(Dt(S,e.nByteLength));function y(S){let I=n>>yt;return S>I}function N(S){return y(S)?s(-S):S}let E=(S,I,L)=>Ht(S.slice(I,L));class p{constructor(I,L,$){this.r=I,this.s=L,this.recovery=$,this.assertValidity()}static fromCompact(I){let L=e.nByteLength;return I=ut("compactSignature",I,L*2),new p(E(I,0,L),E(I,L,2*L))}static fromDER(I){let{r:L,s:$}=Qt.toSig(ut("DER",I));return new p(L,$)}assertValidity(){zt("r",this.r,yt,n),zt("s",this.s,yt,n)}addRecoveryBit(I){return new p(this.r,this.s,I)}recoverPublicKey(I){let{r:L,s:$,recovery:M}=this,W=w(ut("msgHash",I));if(M==null||![0,1,2,3].includes(M))throw new Error("recovery id invalid");let j=M===2||M===3?L+e.n:L;if(j>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let Y=M&1?"03":"02",it=c.fromHex(Y+l(j)),X=a(j),F=s(-W*X),P=s($*X),_=c.BASE.multiplyAndAddUnsafe(it,F,P);if(!_)throw new Error("point at infinify");return _.assertValidity(),_}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Re(this.toDERHex())}toDERHex(){return Qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Re(this.toCompactHex())}toCompactHex(){return l(this.r)+l(this.s)}}let A={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=Ao(e.n);return Cs(e.randomBytes(S),e.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function m(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function b(S){let I=we(S),L=typeof S=="string",$=(I||L)&&S.length;return I?$===o||$===i:L?$===2*o||$===2*i:S instanceof c}function v(S,I,L=!0){if(b(S))throw new Error("first arg must be private key");if(!b(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(f(S)).toRawBytes(L)}let x=e.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=Ht(S),L=S.length*8-e.nBitLength;return L>0?I>>BigInt(L):I},w=e.bits2int_modN||function(S){return s(x(S))},B=mr(e.nBitLength);function g(S){return zt("num < 2^"+e.nBitLength,S,Xt,B),Dt(S,e.nByteLength)}function d(S,I,L=C){if(["recovered","canonical"].some(R=>R in L))throw new Error("sign() legacy options not supported");let{hash:$,randomBytes:M}=e,{lowS:W,prehash:j,extraEntropy:Y}=L;W==null&&(W=!0),S=ut("msgHash",S),Os(L),j&&(S=ut("prehashed msgHash",$(S)));let it=w(S),X=f(I),F=[g(X),g(it)];if(Y!=null&&Y!==!1){let R=Y===!0?M(r.BYTES):Y;F.push(ut("extraEntropy",R))}let P=Ft(...F),_=it;function U(R){let H=x(R);if(!u(H))return;let O=a(H),q=c.BASE.multiply(H).toAffine(),K=s(q.x);if(K===Xt)return;let G=s(O*s(_+K*X));if(G===Xt)return;let Z=(q.x===K?0:2)|Number(q.y&yt),V=G;return W&&y(G)&&(V=N(G),Z^=1),new p(K,V,Z)}return{seed:P,k2sig:U}}let C={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(S,I,L=C){let{seed:$,k2sig:M}=d(S,I,L),W=e;return xo(W.hash.outputLen,W.nByteLength,W.hmac)($,M)}c.BASE._setWindowSize(8);function D(S,I,L,$=k){let M=S;I=ut("msgHash",I),L=ut("publicKey",L);let{lowS:W,prehash:j,format:Y}=$;if(Os($),"strict"in $)throw new Error("options.strict was renamed to lowS");if(Y!==void 0&&Y!=="compact"&&Y!=="der")throw new Error("format must be compact or der");let it=typeof M=="string"||we(M),X=!it&&!Y&&typeof M=="object"&&M!==null&&typeof M.r=="bigint"&&typeof M.s=="bigint";if(!it&&!X)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let F,P;try{if(X&&(F=new p(M.r,M.s)),it){try{Y!=="compact"&&(F=p.fromDER(M))}catch(Z){if(!(Z instanceof Qt.Err))throw Z}!F&&Y!=="der"&&(F=p.fromCompact(M))}P=c.fromHex(L)}catch{return!1}if(!F||W&&F.hasHighS())return!1;j&&(I=e.hash(I));let{r:_,s:U}=F,R=w(I),H=a(U),O=s(R*H),q=s(_*H),K=c.BASE.multiplyAndAddUnsafe(P,O,q)?.toAffine();return K?s(K.x)===_:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:v,sign:T,verify:D,ProjectivePoint:c,Signature:p,utils:A}}function Of(t){return{hash:t,hmac:(e,...r)=>go(t,e,Bs(...r)),randomBytes:tn}}function Ks(t,e){let r=n=>Ds({...t,...Of(n)});return Object.freeze({...r(e),create:r})}var vr=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),hn=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),xr=BigInt(1),pn=BigInt(2),qs=(t,e)=>(t+e/pn)/e;function Vs(t){let e=vr,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,h=f*f*t%e,u=Lt(h,r,e)*h%e,l=Lt(u,r,e)*h%e,y=Lt(l,pn,e)*f%e,N=Lt(y,o,e)*y%e,E=Lt(N,i,e)*N%e,p=Lt(E,a,e)*E%e,A=Lt(p,c,e)*p%e,m=Lt(A,a,e)*E%e,b=Lt(m,r,e)*h%e,v=Lt(b,s,e)*N%e,x=Lt(v,n,e)*f%e,w=Lt(x,pn,e);if(!Co.eql(Co.sqr(w),t))throw new Error("Cannot find square root");return w}var Co=ln(vr,void 0,void 0,{sqrt:Vs}),Jt=Ks({a:BigInt(0),b:BigInt(7),Fp:Co,n:hn,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=hn,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-xr*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=qs(i*t,e),c=qs(-n*t,e),f=lt(t-a*r-c*o,e),h=lt(-a*n-c*i,e),u=f>s,l=h>s;if(u&&(f=e-f),l&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:f,k2neg:l,k2:h}}}},rn),zs=BigInt(0),Ws={};function gn(t,...e){let r=Ws[t];if(r===void 0){let n=rn(Uint8Array.from(t,o=>o.charCodeAt(0)));r=Ft(n,n),Ws[t]=r}return rn(Ft(r,...e))}var Ro=t=>t.toRawBytes(!0).slice(1),_o=t=>Dt(t,32),No=t=>lt(t,vr),Er=t=>lt(t,hn),Ho=Jt.ProjectivePoint,Mf=(t,e,r)=>Ho.BASE.multiplyAndAddUnsafe(t,e,r);function Po(t){let e=Jt.utils.normPrivateKeyToScalar(t),r=Ho.fromPrivateKey(e);return{scalar:r.hasEvenY()?e:Er(-e),bytes:Ro(r)}}function js(t){zt("x",t,xr,vr);let e=No(t*t),r=No(e*t+BigInt(7)),n=Vs(r);n%pn!==zs&&(n=No(-n));let o=new Ho(t,n,xr);return o.assertValidity(),o}var nr=Ht;function Ys(...t){return Er(nr(gn("BIP0340/challenge",...t)))}function Df(t){return Po(t).bytes}function Kf(t,e,r=tn(32)){let n=ut("message",t),{bytes:o,scalar:i}=Po(e),s=ut("auxRand",r,32),a=_o(i^nr(gn("BIP0340/aux",s))),c=gn("BIP0340/nonce",a,o,n),f=Er(nr(c));if(f===zs)throw new Error("sign failed: k is zero");let{bytes:h,scalar:u}=Po(f),l=Ys(h,o,n),y=new Uint8Array(64);if(y.set(h,0),y.set(_o(Er(u+l*i)),32),!Gs(y,n,o))throw new Error("sign: Invalid signature produced");return y}function Gs(t,e,r){let n=ut("signature",t,64),o=ut("message",e),i=ut("publicKey",r,32);try{let s=js(nr(i)),a=nr(n.subarray(0,32));if(!ye(a,xr,vr))return!1;let c=nr(n.subarray(32,64));if(!ye(c,xr,hn))return!1;let f=Ys(_o(a),Ro(s),o),h=Mf(s,c,Er(-f));return!(!h||!h.hasEvenY()||h.toAffine().x!==a)}catch{return!1}}var jt={getPublicKey:Df,sign:Kf,verify:Gs,utils:{randomPrivateKey:Jt.utils.randomPrivateKey,lift_x:js,pointToBytes:Ro,numberToBytesBE:Dt,bytesToNumberBE:Ht,taggedHash:gn,mod:lt}};var yn=Jt.ProjectivePoint,wn=Jt.CURVE.n,{isBytes:J,concatBytes:te,equalBytes:st}=Ji;var Br=t=>ms(kt(t)),ee=(...t)=>kt(kt(te(...t))),Od=jt.utils.randomPrivateKey,bn=jt.getPublicKey,$o=Jt.getPublicKey,Zs=t=>t.r<wn/2n;function Fs(t,e,r=!1){let n=Jt.sign(t,e);if(r&&!Zs(n)){let o=new Uint8Array(32),i=0;for(;!Zs(n);)if(o.set(Q.encode(i++)),n=Jt.sign(t,e,{extraEntropy:o}),i>4294967295)throw new Error("lowR counter overflow: report the error")}return n.toDERRawBytes()}var Oo=jt.sign,mn=jt.utils.taggedHash,xt;(function(t){t[t.ecdsa=0]="ecdsa",t[t.schnorr=1]="schnorr"})(xt||(xt={}));function me(t,e){let r=t.length;if(e===xt.ecdsa){if(r===32)throw new Error("Expected non-Schnorr key");return yn.fromHex(t),t}else if(e===xt.schnorr){if(r!==32)throw new Error("Expected 32-byte Schnorr key");return jt.utils.lift_x(jt.utils.bytesToNumberBE(t)),t}else throw new Error("Unknown key type")}function Qs(t,e){let r=jt.utils,n=r.taggedHash("TapTweak",t,e),o=r.bytesToNumberBE(n);if(o>=wn)throw new Error("tweak higher than curve order");return o}function Xs(t,e=new Uint8Array){let r=jt.utils,n=r.bytesToNumberBE(t),o=yn.fromPrivateKey(n),i=o.hasEvenY()?n:r.mod(-n,wn),s=r.pointToBytes(o),a=Qs(s,e);return r.numberToBytesBE(r.mod(i+a,wn),32)}function Mo(t,e){let r=jt.utils,n=Qs(t,e),i=r.lift_x(r.bytesToNumberBE(t)).add(yn.fromPrivateKey(n)),s=i.hasEvenY()?0:1;return[r.pointToBytes(i),s]}var Do=kt(yn.BASE.toRawBytes(!1)),re={bech32:"bc",pubKeyHash:0,scriptHash:5,wif:128},Ko={bech32:"tb",pubKeyHash:111,scriptHash:196,wif:239};function Sr(t,e){if(!J(t)||!J(e))throw new Error(`cmp: wrong type a=${typeof t} b=${typeof e}`);let r=Math.min(t.length,e.length);for(let n=0;n<r;n++)if(t[n]!=e[n])return Math.sign(t[n]-e[n]);return Math.sign(t.length-e.length)}function kr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function na(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function Vo(t){if(typeof t!="function")throw new Error("function expected");return!0}function or(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function ir(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function En(t){if(!Array.isArray(t))throw new Error("array expected")}function vn(t,e){if(!na(!0,e))throw new Error(`${t}: array of strings expected`)}function zo(t,e){if(!na(!1,e))throw new Error(`${t}: array of numbers expected`)}function Tr(...t){let e=i=>i,r=(i,s)=>a=>i(s(a)),n=t.map(i=>i.encode).reduceRight(r,e),o=t.map(i=>i.decode).reduce(r,e);return{encode:n,decode:o}}function An(t){let e=typeof t=="string"?t.split(""):t,r=e.length;vn("alphabet",e);let n=new Map(e.map((o,i)=>[o,i]));return{encode:o=>(En(o),o.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${t}`);return e[i]})),decode:o=>(En(o),o.map(i=>{or("alphabet.decode",i);let s=n.get(i);if(s===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${t}`);return s}))}}function kn(t=""){return or("join",t),{encode:e=>(vn("join.decode",e),e.join(t)),decode:e=>(or("join.decode",e),e.split(t))}}function qf(t,e="="){return ir(t),or("padding",e),{encode(r){for(vn("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){vn("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function Wf(t){return Vo(t),{encode:e=>e,decode:e=>t(e)}}function qo(t,e,r){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(En(t),!t.length)return[];let n=0,o=[],i=Array.from(t,a=>{if(ir(a),a<0||a>=e)throw new Error(`invalid integer: ${a}`);return a}),s=i.length;for(;;){let a=0,c=!0;for(let f=n;f<s;f++){let h=i[f],u=e*a,l=u+h;if(!Number.isSafeInteger(l)||u/e!==a||l-h!==u)throw new Error("convertRadix: carry overflow");let y=l/r;a=l%r;let N=Math.floor(y);if(i[f]=N,!Number.isSafeInteger(N)||N*r+a!==l)throw new Error("convertRadix: carry overflow");if(c)N?c=!1:n=f;else continue}if(o.push(a),c)break}for(let a=0;a<t.length-1&&t[a]===0;a++)o.push(0);return o.reverse()}var oa=(t,e)=>e===0?t:oa(e,t%e),Bn=(t,e)=>t+(e-oa(t,e)),xn=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Sn(t,e,r,n){if(En(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Bn(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${Bn(e,r)}`);let o=0,i=0,s=xn[e],a=xn[r]-1,c=[];for(let f of t){if(ir(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(o=o<<e|f,i+e>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${e}`);for(i+=e;i>=r;i-=r)c.push((o>>i-r&a)>>>0);let h=xn[i];if(h===void 0)throw new Error("invalid carry");o&=h-1}if(o=o<<r-i&a,!n&&i>=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&c.push(o>>>0),c}function ia(t){ir(t);let e=2**8;return{encode:r=>{if(!kr(r))throw new Error("radix.encode input should be Uint8Array");return qo(Array.from(r),e,t)},decode:r=>(zo("radix.decode",r),Uint8Array.from(qo(r,t,e)))}}function jo(t,e=!1){if(ir(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Bn(8,t)>32||Bn(t,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!kr(r))throw new Error("radix2.encode input should be Uint8Array");return Sn(Array.from(r),8,t,!e)},decode:r=>(zo("radix2.decode",r),Uint8Array.from(Sn(r,t,8,e)))}}function ta(t){return Vo(t),function(...e){try{return t.apply(null,e)}catch{}}}function sa(t,e){return ir(t),Vo(e),{encode(r){if(!kr(r))throw new Error("checksum.encode: input should be Uint8Array");let n=e(r).slice(0,t),o=new Uint8Array(r.length+t);return o.set(r),o.set(n,r.length),o},decode(r){if(!kr(r))throw new Error("checksum.decode: input should be Uint8Array");let n=r.slice(0,-t),o=r.slice(-t),i=e(n).slice(0,t);for(let s=0;s<t;s++)if(i[s]!==o[s])throw new Error("Invalid checksum");return n}}}var Ir={alphabet:An,chain:Tr,checksum:sa,convertRadix:qo,convertRadix2:Sn,radix:ia,radix2:jo,join:kn,padding:qf};var Vf=t=>Tr(ia(58),An(t),kn("")),zf=Vf("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var Tn=t=>Tr(sa(4,e=>t(t(e))),zf);var Wo=Tr(An("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),kn("")),ea=[996825010,642813549,513874426,1027748829,705979059];function Ar(t){let e=t>>25,r=(t&33554431)<<5;for(let n=0;n<ea.length;n++)(e>>n&1)===1&&(r^=ea[n]);return r}function ra(t,e,r=1){let n=t.length,o=1;for(let i=0;i<n;i++){let s=t.charCodeAt(i);if(s<33||s>126)throw new Error(`Invalid prefix (${t})`);o=Ar(o)^s>>5}o=Ar(o);for(let i=0;i<n;i++)o=Ar(o)^t.charCodeAt(i)&31;for(let i of e)o=Ar(o)^i;for(let i=0;i<6;i++)o=Ar(o);return o^=r,Wo.encode(Sn([o%xn[30]],30,5,!1))}function aa(t){let e=t==="bech32"?1:734539939,r=jo(5),n=r.decode,o=r.encode,i=ta(n);function s(u,l,y=90){or("bech32.encode prefix",u),kr(l)&&(l=Array.from(l)),zo("bech32.encode",l);let N=u.length;if(N===0)throw new TypeError(`Invalid prefix length ${N}`);let E=N+7+l.length;if(y!==!1&&E>y)throw new TypeError(`Length ${E} exceeds limit ${y}`);let p=u.toLowerCase(),A=ra(p,l,e);return`${p}1${Wo.encode(l)}${A}`}function a(u,l=90){or("bech32.decode input",u);let y=u.length;if(y<8||l!==!1&&y>l)throw new TypeError(`invalid string length: ${y} (${u}). Expected (8..${l})`);let N=u.toLowerCase();if(u!==N&&u!==u.toUpperCase())throw new Error("String must be lowercase or uppercase");let E=N.lastIndexOf("1");if(E===0||E===-1)throw new Error('Letter "1" must be present between prefix and data only');let p=N.slice(0,E),A=N.slice(E+1);if(A.length<6)throw new Error("Data must be at least 6 characters long");let m=Wo.decode(A).slice(0,-6),b=ra(p,m,e);if(!A.endsWith(b))throw new Error(`Invalid checksum in ${u}: expected "${b}"`);return{prefix:p,words:m}}let c=ta(a);function f(u){let{prefix:l,words:y}=a(u,!1);return{prefix:l,words:y,bytes:n(y)}}function h(u,l){return s(u,o(l))}return{encode:s,decode:a,encodeFromBytes:h,decodeToBytes:f,decodeUnsafe:c,fromWords:n,fromWordsUnsafe:i,toWords:o}}var In=aa("bech32"),Yo=aa("bech32m");var at=Tr(jo(4),An("0123456789abcdef"),kn(""),Wf(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()}));var ht;(function(t){t[t.OP_0=0]="OP_0",t[t.PUSHDATA1=76]="PUSHDATA1",t[t.PUSHDATA2=77]="PUSHDATA2",t[t.PUSHDATA4=78]="PUSHDATA4",t[t["1NEGATE"]=79]="1NEGATE",t[t.RESERVED=80]="RESERVED",t[t.OP_1=81]="OP_1",t[t.OP_2=82]="OP_2",t[t.OP_3=83]="OP_3",t[t.OP_4=84]="OP_4",t[t.OP_5=85]="OP_5",t[t.OP_6=86]="OP_6",t[t.OP_7=87]="OP_7",t[t.OP_8=88]="OP_8",t[t.OP_9=89]="OP_9",t[t.OP_10=90]="OP_10",t[t.OP_11=91]="OP_11",t[t.OP_12=92]="OP_12",t[t.OP_13=93]="OP_13",t[t.OP_14=94]="OP_14",t[t.OP_15=95]="OP_15",t[t.OP_16=96]="OP_16",t[t.NOP=97]="NOP",t[t.VER=98]="VER",t[t.IF=99]="IF",t[t.NOTIF=100]="NOTIF",t[t.VERIF=101]="VERIF",t[t.VERNOTIF=102]="VERNOTIF",t[t.ELSE=103]="ELSE",t[t.ENDIF=104]="ENDIF",t[t.VERIFY=105]="VERIFY",t[t.RETURN=106]="RETURN",t[t.TOALTSTACK=107]="TOALTSTACK",t[t.FROMALTSTACK=108]="FROMALTSTACK",t[t["2DROP"]=109]="2DROP",t[t["2DUP"]=110]="2DUP",t[t["3DUP"]=111]="3DUP",t[t["2OVER"]=112]="2OVER",t[t["2ROT"]=113]="2ROT",t[t["2SWAP"]=114]="2SWAP",t[t.IFDUP=115]="IFDUP",t[t.DEPTH=116]="DEPTH",t[t.DROP=117]="DROP",t[t.DUP=118]="DUP",t[t.NIP=119]="NIP",t[t.OVER=120]="OVER",t[t.PICK=121]="PICK",t[t.ROLL=122]="ROLL",t[t.ROT=123]="ROT",t[t.SWAP=124]="SWAP",t[t.TUCK=125]="TUCK",t[t.CAT=126]="CAT",t[t.SUBSTR=127]="SUBSTR",t[t.LEFT=128]="LEFT",t[t.RIGHT=129]="RIGHT",t[t.SIZE=130]="SIZE",t[t.INVERT=131]="INVERT",t[t.AND=132]="AND",t[t.OR=133]="OR",t[t.XOR=134]="XOR",t[t.EQUAL=135]="EQUAL",t[t.EQUALVERIFY=136]="EQUALVERIFY",t[t.RESERVED1=137]="RESERVED1",t[t.RESERVED2=138]="RESERVED2",t[t["1ADD"]=139]="1ADD",t[t["1SUB"]=140]="1SUB",t[t["2MUL"]=141]="2MUL",t[t["2DIV"]=142]="2DIV",t[t.NEGATE=143]="NEGATE",t[t.ABS=144]="ABS",t[t.NOT=145]="NOT",t[t["0NOTEQUAL"]=146]="0NOTEQUAL",t[t.ADD=147]="ADD",t[t.SUB=148]="SUB",t[t.MUL=149]="MUL",t[t.DIV=150]="DIV",t[t.MOD=151]="MOD",t[t.LSHIFT=152]="LSHIFT",t[t.RSHIFT=153]="RSHIFT",t[t.BOOLAND=154]="BOOLAND",t[t.BOOLOR=155]="BOOLOR",t[t.NUMEQUAL=156]="NUMEQUAL",t[t.NUMEQUALVERIFY=157]="NUMEQUALVERIFY",t[t.NUMNOTEQUAL=158]="NUMNOTEQUAL",t[t.LESSTHAN=159]="LESSTHAN",t[t.GREATERTHAN=160]="GREATERTHAN",t[t.LESSTHANOREQUAL=161]="LESSTHANOREQUAL",t[t.GREATERTHANOREQUAL=162]="GREATERTHANOREQUAL",t[t.MIN=163]="MIN",t[t.MAX=164]="MAX",t[t.WITHIN=165]="WITHIN",t[t.RIPEMD160=166]="RIPEMD160",t[t.SHA1=167]="SHA1",t[t.SHA256=168]="SHA256",t[t.HASH160=169]="HASH160",t[t.HASH256=170]="HASH256",t[t.CODESEPARATOR=171]="CODESEPARATOR",t[t.CHECKSIG=172]="CHECKSIG",t[t.CHECKSIGVERIFY=173]="CHECKSIGVERIFY",t[t.CHECKMULTISIG=174]="CHECKMULTISIG",t[t.CHECKMULTISIGVERIFY=175]="CHECKMULTISIGVERIFY",t[t.NOP1=176]="NOP1",t[t.CHECKLOCKTIMEVERIFY=177]="CHECKLOCKTIMEVERIFY",t[t.CHECKSEQUENCEVERIFY=178]="CHECKSEQUENCEVERIFY",t[t.NOP4=179]="NOP4",t[t.NOP5=180]="NOP5",t[t.NOP6=181]="NOP6",t[t.NOP7=182]="NOP7",t[t.NOP8=183]="NOP8",t[t.NOP9=184]="NOP9",t[t.NOP10=185]="NOP10",t[t.CHECKSIGADD=186]="CHECKSIGADD",t[t.INVALID=255]="INVALID"})(ht||(ht={}));function fa(t=6,e=!1){return Bt({encodeStream:(r,n)=>{if(n===0n)return;let o=n<0,i=BigInt(n),s=[];for(let a=o?-i:i;a;a>>=8n)s.push(Number(a&0xffn));s[s.length-1]>=128?s.push(o?128:0):o&&(s[s.length-1]|=128),r.bytes(new Uint8Array(s))},decodeStream:r=>{let n=r.leftBytes;if(n>t)throw new Error(`ScriptNum: number (${n}) bigger than limit=${t}`);if(n===0)return 0n;if(e){let s=r.bytes(n,!0);if(!(s[s.length-1]&127)&&(n<=1||!(s[s.length-2]&128)))throw new Error("Non-minimally encoded ScriptNum")}let o=0,i=0n;for(let s=0;s<n;++s)o=r.byte(),i|=BigInt(o)<<8n*BigInt(s);return o>=128&&(i&=2n**BigInt(n*8)-1n>>1n,i=-i),i}})}function ua(t,e=4,r=!0){if(typeof t=="number")return t;if(J(t))try{let n=fa(e,r).decode(t);return n>Number.MAX_SAFE_INTEGER?void 0:Number(n)}catch{return}}var ct=Bt({encodeStream:(t,e)=>{for(let r of e){if(typeof r=="string"){if(ht[r]===void 0)throw new Error(`Unknown opcode=${r}`);t.byte(ht[r]);continue}else if(typeof r=="number"){if(r===0){t.byte(0);continue}else if(1<=r&&r<=16){t.byte(ht.OP_1-1+r);continue}}if(typeof r=="number"&&(r=fa().encode(BigInt(r))),!J(r))throw new Error(`Wrong Script OP=${r} (${typeof r})`);let n=r.length;n<ht.PUSHDATA1?t.byte(n):n<=255?(t.byte(ht.PUSHDATA1),t.byte(n)):n<=65535?(t.byte(ht.PUSHDATA2),t.bytes(io.encode(n))):(t.byte(ht.PUSHDATA4),t.bytes(Q.encode(n))),t.bytes(r)}},decodeStream:t=>{let e=[];for(;!t.isEnd();){let r=t.byte();if(ht.OP_0<r&&r<=ht.PUSHDATA4){let n;if(r<ht.PUSHDATA1)n=r;else if(r===ht.PUSHDATA1)n=$t.decodeStream(t);else if(r===ht.PUSHDATA2)n=io.decodeStream(t);else if(r===ht.PUSHDATA4)n=Q.decodeStream(t);else throw new Error("Should be not possible");e.push(t.bytes(n))}else if(r===0)e.push(0);else if(ht.OP_1<=r&&r<=ht.OP_16)e.push(r-(ht.OP_1-1));else{let n=ht[r];if(n===void 0)throw new Error(`Unknown opcode=${r.toString(16)}`);e.push(n)}}return e}}),ca={253:[253,2,253n,65535n],254:[254,4,65536n,4294967295n],255:[255,8,4294967296n,18446744073709551615n]},Ur=Bt({encodeStream:(t,e)=>{if(typeof e=="number"&&(e=BigInt(e)),0n<=e&&e<=252n)return t.byte(Number(e));for(let[r,n,o,i]of Object.values(ca))if(!(o>e||e>i)){t.byte(r);for(let s=0;s<n;s++)t.byte(Number(e>>8n*BigInt(s)&0xffn));return}throw t.err(`VarInt too big: ${e}`)},decodeStream:t=>{let e=t.byte();if(e<=252)return BigInt(e);let[r,n,o]=ca[e],i=0n;for(let s=0;s<n;s++)i|=BigInt(t.byte())<<8n*BigInt(s);if(i<o)throw t.err(`Wrong CompactSize(${8*n})`);return i}}),It=Vt(Ur,ue.numberBigint),Tt=et(Ur),sr=St(It,Tt),Un=t=>St(Ur,t),la=ft({txid:et(32,!0),index:Q,finalScriptSig:Tt,sequence:Q}),ne=ft({amount:Qe,script:Tt}),jf=ft({version:le,segwitFlag:fs(new Uint8Array([0,1])),inputs:Un(la),outputs:Un(ne),witnesses:us("segwitFlag",St("inputs/length",sr)),lockTime:Q});function Yf(t){if(t.segwitFlag&&t.witnesses&&!t.witnesses.length)throw new Error("Segwit flag with empty witnesses array");return t}var oe=vt(jf,Yf),$e=ft({version:le,inputs:Un(la),outputs:Un(ne),lockTime:Q});function Lr(t){if(t.nonWitnessUtxo){if(t.index===void 0)throw new Error("Unknown input index");return t.nonWitnessUtxo.outputs[t.index]}else{if(t.witnessUtxo)return t.witnessUtxo;throw new Error("Cannot find previous output info")}}function Go(t,e,r,n=!1){let{nonWitnessUtxo:o,txid:i}=t;typeof o=="string"&&(o=at.decode(o)),J(o)&&(o=oe.decode(o)),!("nonWitnessUtxo"in t)&&o===void 0&&(o=e?.nonWitnessUtxo),typeof i=="string"&&(i=at.decode(i)),i===void 0&&(i=e?.txid);let s={...e,...t,nonWitnessUtxo:o,txid:i};!("nonWitnessUtxo"in t)&&s.nonWitnessUtxo===void 0&&delete s.nonWitnessUtxo,s.sequence===void 0&&(s.sequence=Fo),s.tapMerkleRoot===null&&delete s.tapMerkleRoot,s=Nr(cr,s,e,r),Ln.encode(s);let a;return s.nonWitnessUtxo&&s.index!==void 0?a=s.nonWitnessUtxo.outputs[s.index]:s.witnessUtxo&&(a=s.witnessUtxo),a&&!n&&Nn(a&&a.script,s.redeemScript,s.witnessScript),s}function Zo(t,e=!1){let r="legacy",n=tt.ALL,o=Lr(t),i=Et.decode(o.script),s=i.type,a=i,c=[i];if(i.type==="tr")return n=tt.DEFAULT,{txType:"taproot",type:"tr",last:i,lastScript:o.script,defaultSighash:n,sighash:t.sighashType||n};{if((i.type==="wpkh"||i.type==="wsh")&&(r="segwit"),i.type==="sh"){if(!t.redeemScript)throw new Error("inputType: sh without redeemScript");let l=Et.decode(t.redeemScript);(l.type==="wpkh"||l.type==="wsh")&&(r="segwit"),c.push(l),a=l,s+=`-${l.type}`}if(a.type==="wsh"){if(!t.witnessScript)throw new Error("inputType: wsh without witnessScript");let l=Et.decode(t.witnessScript);l.type==="wsh"&&(r="segwit"),c.push(l),a=l,s+=`-${l.type}`}let f=c[c.length-1];if(f.type==="sh"||f.type==="wsh")throw new Error("inputType: sh/wsh cannot be terminal type");let h=Et.encode(f),u={type:s,txType:r,last:f,lastScript:h,defaultSighash:n,sighash:t.sighashType||n};if(r==="legacy"&&!e&&!t.nonWitnessUtxo)throw new Error("Transaction/sign: legacy input without nonWitnessUtxo, can result in attack that forces paying higher fees. Pass allowLegacyWitnessUtxo=true, if you sure");return u}}var da=t=>Math.ceil(t/4);var Cn=new Uint8Array(32),Gf={amount:0xffffffffffffffffn,script:rt},Zf=8,Ff=2,Me=0,Fo=4294967295,th=ue.decimal(Zf),_r=(t,e)=>t===void 0?e:t;function _n(t){if(Array.isArray(t))return t.map(e=>_n(e));if(J(t))return Uint8Array.from(t);if(["number","bigint","boolean","string","undefined"].includes(typeof t))return t;if(t===null)return t;if(typeof t=="object")return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,_n(r)]));throw new Error(`cloneDeep: unknown type=${t} (${typeof t})`)}var tt;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.ANYONECANPAY=128]="ANYONECANPAY"})(tt||(tt={}));var Jo;(function(t){t[t.DEFAULT=0]="DEFAULT",t[t.ALL=1]="ALL",t[t.NONE=2]="NONE",t[t.SINGLE=3]="SINGLE",t[t.DEFAULT_ANYONECANPAY=128]="DEFAULT_ANYONECANPAY",t[t.ALL_ANYONECANPAY=129]="ALL_ANYONECANPAY",t[t.NONE_ANYONECANPAY=130]="NONE_ANYONECANPAY",t[t.SINGLE_ANYONECANPAY=131]="SINGLE_ANYONECANPAY"})(Jo||(Jo={}));function Qf(t,e,r,n=rt){return st(r,e)&&(t=Xs(t,n),e=bn(t)),{privKey:t,pubKey:e}}function De(t){if(t.script===void 0||t.amount===void 0)throw new Error("Transaction/output: script and amount required");return{script:t.script,amount:t.amount}}function ar(t){if(t.txid===void 0||t.index===void 0)throw new Error("Transaction/input: txid and index required");return{txid:t.txid,index:t.index,sequence:_r(t.sequence,Fo),finalScriptSig:_r(t.finalScriptSig,rt)}}function Qo(t){for(let e in t){let r=e;ga.includes(r)||delete t[r]}}var Xo=ft({txid:et(32,!0),index:Q});function Xf(t){if(typeof t!="number"||typeof Jo[t]!="string")throw new Error(`Invalid SigHash=${t}`);return t}function pa(t){let e=t&31;return{isAny:!!(t&tt.ANYONECANPAY),isNone:e===tt.NONE,isSingle:e===tt.SINGLE}}function Jf(t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error(`Wrong object type for transaction options: ${t}`);let e={...t,version:_r(t.version,Ff),lockTime:_r(t.lockTime,0),PSBTVersion:_r(t.PSBTVersion,0)};if(typeof e.allowUnknowInput<"u"&&(t.allowUnknownInputs=e.allowUnknowInput),typeof e.allowUnknowOutput<"u"&&(t.allowUnknownOutputs=e.allowUnknowOutput),![-1,0,1,2].includes(e.version))throw new Error(`Unknown version: ${e.version}`);if(typeof e.lockTime!="number")throw new Error("Transaction lock time should be number");if(Q.encode(e.lockTime),e.PSBTVersion!==0&&e.PSBTVersion!==2)throw new Error(`Unknown PSBT version ${e.PSBTVersion}`);for(let r of["allowUnknownOutputs","allowUnknownInputs","disableScriptCheck","bip174jsCompat","allowLegacyWitnessUtxo","lowR"]){let n=e[r];if(n!==void 0&&typeof n!="boolean")throw new Error(`Transation options wrong type: ${r}=${n} (${typeof n})`)}if(e.customScripts!==void 0){let r=e.customScripts;if(!Array.isArray(r))throw new Error(`wrong custom scripts type (expected array): customScripts=${r} (${typeof r})`);for(let n of r){if(typeof n.encode!="function"||typeof n.decode!="function")throw new Error(`wrong script=${n} (${typeof n})`);if(n.finalizeTaproot!==void 0&&typeof n.finalizeTaproot!="function")throw new Error(`wrong script=${n} (${typeof n})`)}}return Object.freeze(e)}var xe=class t{constructor(e={}){this.global={},this.inputs=[],this.outputs=[];let r=this.opts=Jf(e);r.lockTime!==Me&&(this.global.fallbackLocktime=r.lockTime),this.global.txVersion=r.version}static fromRaw(e,r={}){let n=oe.decode(e),o=new t({...r,version:n.version,lockTime:n.lockTime});for(let i of n.outputs)o.addOutput(i);if(o.outputs=n.outputs,o.inputs=n.inputs,n.witnesses)for(let i=0;i<n.witnesses.length;i++)o.inputs[i].finalScriptWitness=n.witnesses[i];return o}static fromPSBT(e,r={}){let n;try{n=ei.decode(e)}catch(u){try{n=ri.decode(e)}catch{throw u}}let o=n.global.version||0;if(o!==0&&o!==2)throw new Error(`Wrong PSBT version=${o}`);let i=n.global.unsignedTx,s=o===0?i?.version:n.global.txVersion,a=o===0?i?.lockTime:n.global.fallbackLocktime,c=new t({...r,version:s,lockTime:a,PSBTVersion:o}),f=o===0?i?.inputs.length:n.global.inputCount;c.inputs=n.inputs.slice(0,f).map((u,l)=>({finalScriptSig:rt,...n.global.unsignedTx?.inputs[l],...u}));let h=o===0?i?.outputs.length:n.global.outputCount;return c.outputs=n.outputs.slice(0,h).map((u,l)=>({...u,...n.global.unsignedTx?.outputs[l]})),c.global={...n.global,txVersion:s},a!==Me&&(c.global.fallbackLocktime=a),c}toPSBT(e=this.opts.PSBTVersion){if(e!==0&&e!==2)throw new Error(`Wrong PSBT version=${e}`);let r=this.inputs.map(i=>ti(e,cr,i));for(let i of r)i.partialSig&&!i.partialSig.length&&delete i.partialSig,i.finalScriptSig&&!i.finalScriptSig.length&&delete i.finalScriptSig,i.finalScriptWitness&&!i.finalScriptWitness.length&&delete i.finalScriptWitness;let n=this.outputs.map(i=>ti(e,Pr,i)),o={...this.global};return e===0?(o.unsignedTx=$e.decode($e.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(ar).map(i=>({...i,finalScriptSig:rt})),outputs:this.outputs.map(De)})),delete o.fallbackLocktime,delete o.txVersion):(o.version=e,o.txVersion=this.version,o.inputCount=this.inputs.length,o.outputCount=this.outputs.length,o.fallbackLocktime&&o.fallbackLocktime===Me&&delete o.fallbackLocktime),this.opts.bip174jsCompat&&(r.length||r.push({}),n.length||n.push({})),(e===0?ei:ri).encode({global:o,inputs:r,outputs:n})}get lockTime(){let e=Me,r=0,n=Me,o=0;for(let i of this.inputs)i.requiredHeightLocktime&&(e=Math.max(e,i.requiredHeightLocktime),r++),i.requiredTimeLocktime&&(n=Math.max(n,i.requiredTimeLocktime),o++);return r&&r>=o?e:n!==Me?n:this.global.fallbackLocktime||Me}get version(){if(this.global.txVersion===void 0)throw new Error("No global.txVersion");return this.global.txVersion}inputStatus(e){this.checkInputIdx(e);let r=this.inputs[e];return r.finalScriptSig&&r.finalScriptSig.length||r.finalScriptWitness&&r.finalScriptWitness.length?"finalized":r.tapKeySig||r.tapScriptSig&&r.tapScriptSig.length||r.partialSig&&r.partialSig.length?"signed":"unsigned"}inputSighash(e){this.checkInputIdx(e);let r=this.inputs[e].sighashType,n=r===void 0?tt.DEFAULT:r,o=n===tt.DEFAULT?tt.ALL:n&3;return{sigInputs:n&tt.ANYONECANPAY,sigOutputs:o}}signStatus(){let e=!0,r=!0,n=[],o=[];for(let i=0;i<this.inputs.length;i++){if(this.inputStatus(i)==="unsigned")continue;let{sigInputs:a,sigOutputs:c}=this.inputSighash(i);if(a===tt.ANYONECANPAY?n.push(i):e=!1,c===tt.ALL)r=!1;else if(c===tt.SINGLE)o.push(i);else if(c!==tt.NONE)throw new Error(`Wrong signature hash output type: ${c}`)}return{addInput:e,addOutput:r,inputs:n,outputs:o}}get isFinal(){for(let e=0;e<this.inputs.length;e++)if(this.inputStatus(e)!=="finalized")return!1;return!0}get hasWitnesses(){let e=!1;for(let r of this.inputs)r.finalScriptWitness&&r.finalScriptWitness.length&&(e=!0);return e}get weight(){if(!this.isFinal)throw new Error("Transaction is not finalized");let e=32,r=this.outputs.map(De);e+=4*It.encode(this.outputs.length).length;for(let n of r)e+=32+4*Tt.encode(n.script).length;this.hasWitnesses&&(e+=2),e+=4*It.encode(this.inputs.length).length;for(let n of this.inputs)e+=160+4*Tt.encode(n.finalScriptSig||rt).length,this.hasWitnesses&&n.finalScriptWitness&&(e+=sr.encode(n.finalScriptWitness).length);return e}get vsize(){return da(this.weight)}toBytes(e=!1,r=!1){return oe.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(ar).map(n=>({...n,finalScriptSig:e&&n.finalScriptSig||rt})),outputs:this.outputs.map(De),witnesses:this.inputs.map(n=>n.finalScriptWitness||[]),segwitFlag:r&&this.hasWitnesses})}get unsignedTx(){return this.toBytes(!1,!1)}get hex(){return at.encode(this.toBytes(!0,this.hasWitnesses))}get hash(){if(!this.isFinal)throw new Error("Transaction is not finalized");return at.encode(ee(this.toBytes(!0)))}get id(){if(!this.isFinal)throw new Error("Transaction is not finalized");return at.encode(ee(this.toBytes(!0)).reverse())}checkInputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.inputs.length)throw new Error(`Wrong input index=${e}`)}getInput(e){return this.checkInputIdx(e),_n(this.inputs[e])}get inputsLength(){return this.inputs.length}addInput(e,r=!1){if(!r&&!this.signStatus().addInput)throw new Error("Tx has signed inputs, cannot add new one");return this.inputs.push(Go(e,void 0,void 0,this.opts.disableScriptCheck)),this.inputs.length-1}updateInput(e,r,n=!1){this.checkInputIdx(e);let o;if(!n){let i=this.signStatus();(!i.addInput||i.inputs.includes(e))&&(o=wa)}this.inputs[e]=Go(r,this.inputs[e],o,this.opts.disableScriptCheck)}checkOutputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.outputs.length)throw new Error(`Wrong output index=${e}`)}getOutput(e){return this.checkOutputIdx(e),_n(this.outputs[e])}getOutputAddress(e,r=re){let n=this.getOutput(e);if(n.script)return Ee(r).encode(Et.decode(n.script))}get outputsLength(){return this.outputs.length}normalizeOutput(e,r,n){let{amount:o,script:i}=e;if(o===void 0&&(o=r?.amount),typeof o!="bigint")throw new Error(`Wrong amount type, should be of type bigint in sats, but got ${o} of type ${typeof o}`);typeof i=="string"&&(i=at.decode(i)),i===void 0&&(i=r?.script);let s={...r,...e,amount:o,script:i};if(s.amount===void 0&&delete s.amount,s=Nr(Pr,s,r,n),Rn.encode(s),s.script&&!this.opts.allowUnknownOutputs&&Et.decode(s.script).type==="unknown")throw new Error("Transaction/output: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure");return this.opts.disableScriptCheck||Nn(s.script,s.redeemScript,s.witnessScript),s}addOutput(e,r=!1){if(!r&&!this.signStatus().addOutput)throw new Error("Tx has signed outputs, cannot add new one");return this.outputs.push(this.normalizeOutput(e)),this.outputs.length-1}updateOutput(e,r,n=!1){this.checkOutputIdx(e);let o;if(!n){let i=this.signStatus();(!i.addOutput||i.outputs.includes(e))&&(o=ya)}this.outputs[e]=this.normalizeOutput(r,this.outputs[e],o)}addOutputAddress(e,r,n=re){return this.addOutput({script:Et.encode(Ee(n).decode(e)),amount:r})}get fee(){let e=0n;for(let n of this.inputs){let o=Lr(n);if(!o)throw new Error("Empty input amount");e+=o.amount}let r=this.outputs.map(De);for(let n of r)e-=n.amount;return e}preimageLegacy(e,r,n){let{isAny:o,isNone:i,isSingle:s}=pa(n);if(e<0||!Number.isSafeInteger(e))throw new Error(`Invalid input idx=${e}`);if(s&&e>=this.outputs.length||e>=this.inputs.length)return os.encode(1n);r=ct.encode(ct.decode(r).filter(h=>h!=="CODESEPARATOR"));let a=this.inputs.map(ar).map((h,u)=>({...h,finalScriptSig:u===e?r:rt}));o?a=[a[e]]:(i||s)&&(a=a.map((h,u)=>({...h,sequence:u===e?h.sequence:0})));let c=this.outputs.map(De);i?c=[]:s&&(c=c.slice(0,e).fill(Gf).concat([c[e]]));let f=oe.encode({lockTime:this.lockTime,version:this.version,segwitFlag:!1,inputs:a,outputs:c});return ee(f,le.encode(n))}preimageWitnessV0(e,r,n,o){let{isAny:i,isNone:s,isSingle:a}=pa(n),c=Cn,f=Cn,h=Cn,u=this.inputs.map(ar),l=this.outputs.map(De);i||(c=ee(...u.map(Xo.encode))),!i&&!a&&!s&&(f=ee(...u.map(N=>Q.encode(N.sequence)))),!a&&!s?h=ee(...l.map(ne.encode)):a&&e<l.length&&(h=ee(ne.encode(l[e])));let y=u[e];return ee(le.encode(this.version),c,f,et(32,!0).encode(y.txid),Q.encode(y.index),Tt.encode(r),Qe.encode(o),Q.encode(y.sequence),h,Q.encode(this.lockTime),Q.encode(n))}preimageWitnessV1(e,r,n,o,i=-1,s,a=192,c){if(!Array.isArray(o)||this.inputs.length!==o.length)throw new Error(`Invalid amounts array=${o}`);if(!Array.isArray(r)||this.inputs.length!==r.length)throw new Error(`Invalid prevOutScript array=${r}`);let f=[$t.encode(0),$t.encode(n),le.encode(this.version),Q.encode(this.lockTime)],h=n===tt.DEFAULT?tt.ALL:n&3,u=n&tt.ANYONECANPAY,l=this.inputs.map(ar),y=this.outputs.map(De);u!==tt.ANYONECANPAY&&f.push(...[l.map(Xo.encode),o.map(Qe.encode),r.map(Tt.encode),l.map(E=>Q.encode(E.sequence))].map(E=>kt(te(...E)))),h===tt.ALL&&f.push(kt(te(...y.map(ne.encode))));let N=(c?1:0)|(s?2:0);if(f.push(new Uint8Array([N])),u===tt.ANYONECANPAY){let E=l[e];f.push(Xo.encode(E),Qe.encode(o[e]),Tt.encode(r[e]),Q.encode(E.sequence))}else f.push(Q.encode(e));return N&1&&f.push(kt(Tt.encode(c||rt))),h===tt.SINGLE&&f.push(e<y.length?kt(ne.encode(y[e])):Cn),s&&f.push(Cr(s,a),$t.encode(0),le.encode(i)),mn("TapSighash",...f)}signIdx(e,r,n,o){this.checkInputIdx(r);let i=this.inputs[r],s=Zo(i,this.opts.allowLegacyWitnessUtxo);if(!J(e)){if(!i.bip32Derivation||!i.bip32Derivation.length)throw new Error("bip32Derivation: empty");let h=i.bip32Derivation.filter(l=>l[1].fingerprint==e.fingerprint).map(([l,{path:y}])=>{let N=e;for(let E of y)N=N.deriveChild(E);if(!st(N.publicKey,l))throw new Error("bip32Derivation: wrong pubKey");if(!N.privateKey)throw new Error("bip32Derivation: no privateKey");return N});if(!h.length)throw new Error(`bip32Derivation: no items with fingerprint=${e.fingerprint}`);let u=!1;for(let l of h)this.signIdx(l.privateKey,r)&&(u=!0);return u}n?n.forEach(Xf):n=[s.defaultSighash];let a=s.sighash;if(!n.includes(a))throw new Error(`Input with not allowed sigHash=${a}. Allowed: ${n.join(", ")}`);let{sigOutputs:c}=this.inputSighash(r);if(c===tt.SINGLE&&r>=this.outputs.length)throw new Error(`Input with sighash SINGLE, but there is no output with corresponding index=${r}`);let f=Lr(i);if(s.txType==="taproot"){let h=this.inputs.map(Lr),u=h.map(p=>p.script),l=h.map(p=>p.amount),y=!1,N=bn(e),E=i.tapMerkleRoot||rt;if(i.tapInternalKey){let{pubKey:p,privKey:A}=Qf(e,N,i.tapInternalKey,E),[m,b]=Mo(i.tapInternalKey,E);if(st(m,p)){let v=this.preimageWitnessV1(r,u,a,l),x=te(Oo(v,A,o),a!==tt.DEFAULT?new Uint8Array([a]):rt);this.updateInput(r,{tapKeySig:x},!0),y=!0}}if(i.tapLeafScript){i.tapScriptSig=i.tapScriptSig||[];for(let[p,A]of i.tapLeafScript){let m=A.subarray(0,-1),b=ct.decode(m),v=A[A.length-1],x=Cr(m,v);if(b.findIndex(d=>J(d)&&st(d,N))===-1)continue;let B=this.preimageWitnessV1(r,u,a,l,void 0,m,v),g=te(Oo(B,e,o),a!==tt.DEFAULT?new Uint8Array([a]):rt);this.updateInput(r,{tapScriptSig:[[{pubKey:N,leafHash:x},g]]},!0),y=!0}}if(!y)throw new Error("No taproot scripts signed");return!0}else{let h=$o(e),u=!1,l=Br(h);for(let E of ct.decode(s.lastScript))J(E)&&(st(E,h)||st(E,l))&&(u=!0);if(!u)throw new Error(`Input script doesn't have pubKey: ${s.lastScript}`);let y;if(s.txType==="legacy")y=this.preimageLegacy(r,s.lastScript,a);else if(s.txType==="segwit"){let E=s.lastScript;s.last.type==="wpkh"&&(E=Et.encode({type:"pkh",hash:s.last.hash})),y=this.preimageWitnessV0(r,E,a,f.amount)}else throw new Error(`Transaction/sign: unknown tx type: ${s.txType}`);let N=Fs(y,e,this.opts.lowR);this.updateInput(r,{partialSig:[[h,te(N,new Uint8Array([a]))]]},!0)}return!0}sign(e,r,n){let o=0;for(let i=0;i<this.inputs.length;i++)try{this.signIdx(e,i,r,n)&&o++}catch{}if(!o)throw new Error("No inputs signed");return o}finalizeIdx(e){if(this.checkInputIdx(e),this.fee<0n)throw new Error("Outputs spends more than inputs amount");let r=this.inputs[e],n=Zo(r,this.opts.allowLegacyWitnessUtxo);if(n.txType==="taproot"){if(r.tapKeySig)r.finalScriptWitness=[r.tapKeySig];else if(r.tapLeafScript&&r.tapScriptSig){let c=r.tapLeafScript.sort((f,h)=>Oe.encode(f[0]).length-Oe.encode(h[0]).length);for(let[f,h]of c){let u=h.slice(0,-1),l=h[h.length-1],y=Et.decode(u),N=Cr(u,l),E=r.tapScriptSig.filter(A=>st(A[0].leafHash,N)),p=[];if(y.type==="tr_ms"){let A=y.m,m=y.pubkeys,b=0;for(let v of m){let x=E.findIndex(w=>st(w[0].pubKey,v));if(b===A||x===-1){p.push(rt);continue}p.push(E[x][1]),b++}if(b!==A)continue}else if(y.type==="tr_ns"){for(let A of y.pubkeys){let m=E.findIndex(b=>st(b[0].pubKey,A));m!==-1&&p.push(E[m][1])}if(p.length!==y.pubkeys.length)continue}else if(y.type==="unknown"&&this.opts.allowUnknownInputs){let A=ct.decode(u);if(p=E.map(([{pubKey:m},b])=>{let v=A.findIndex(x=>J(x)&&st(x,m));if(v===-1)throw new Error("finalize/taproot: cannot find position of pubkey in script");return{signature:b,pos:v}}).sort((m,b)=>m.pos-b.pos).map(m=>m.signature),!p.length)continue}else{let A=this.opts.customScripts;if(A)for(let m of A){if(!m.finalizeTaproot)continue;let b=ct.decode(u),v=m.encode(b);if(v===void 0)continue;let x=m.finalizeTaproot(u,v,E);if(x){r.finalScriptWitness=x.concat(Oe.encode(f)),r.finalScriptSig=rt,Qo(r);return}}throw new Error("Finalize: Unknown tapLeafScript")}r.finalScriptWitness=p.reverse().concat([u,Oe.encode(f)]);break}if(!r.finalScriptWitness)throw new Error("finalize/taproot: empty witness")}else throw new Error("finalize/taproot: unknown input");r.finalScriptSig=rt,Qo(r);return}if(!r.partialSig||!r.partialSig.length)throw new Error("Not enough partial sign");let o=rt,i=[];if(n.last.type==="ms"){let c=n.last.m,f=n.last.pubkeys,h=[];for(let u of f){let l=r.partialSig.find(y=>st(u,y[0]));l&&h.push(l[1])}if(h=h.slice(0,c),h.length!==c)throw new Error(`Multisig: wrong signatures count, m=${c} n=${f.length} signatures=${h.length}`);o=ct.encode([0,...h])}else if(n.last.type==="pk")o=ct.encode([r.partialSig[0][1]]);else if(n.last.type==="pkh")o=ct.encode([r.partialSig[0][1],r.partialSig[0][0]]);else if(n.last.type==="wpkh")o=rt,i=[r.partialSig[0][1],r.partialSig[0][0]];else if(n.last.type==="unknown"&&!this.opts.allowUnknownInputs)throw new Error("Unknown inputs not allowed");let s,a;if(n.type.includes("wsh-")&&(o.length&&n.lastScript.length&&(i=ct.decode(o).map(c=>{if(c===0)return rt;if(J(c))return c;throw new Error(`Wrong witness op=${c}`)})),i=i.concat(n.lastScript)),n.txType==="segwit"&&(a=i),n.type.startsWith("sh-wsh-")?s=ct.encode([ct.encode([0,kt(n.lastScript)])]):n.type.startsWith("sh-")?s=ct.encode([...ct.decode(o),n.lastScript]):n.type.startsWith("wsh-")||n.txType!=="segwit"&&(s=o),!s&&!a)throw new Error("Unknown error finalizing input");s&&(r.finalScriptSig=s),a&&(r.finalScriptWitness=a),Qo(r)}finalize(){for(let e=0;e<this.inputs.length;e++)this.finalizeIdx(e)}extract(){if(!this.isFinal)throw new Error("Transaction has unfinalized inputs");if(!this.outputs.length)throw new Error("Transaction has no outputs");if(this.fee<0n)throw new Error("Outputs spends more than inputs amount");return this.toBytes(!0,!0)}combine(e){for(let o of["PSBTVersion","version","lockTime"])if(this.opts[o]!==e.opts[o])throw new Error(`Transaction/combine: different ${o} this=${this.opts[o]} other=${e.opts[o]}`);for(let o of["inputs","outputs"])if(this[o].length!==e[o].length)throw new Error(`Transaction/combine: different ${o} length this=${this[o].length} other=${e[o].length}`);let r=this.global.unsignedTx?$e.encode(this.global.unsignedTx):rt,n=e.global.unsignedTx?$e.encode(e.global.unsignedTx):rt;if(!st(r,n))throw new Error("Transaction/combine: different unsigned tx");this.global=Nr(Pn,this.global,e.global);for(let o=0;o<this.inputs.length;o++)this.updateInput(o,e.inputs[o],!0);for(let o=0;o<this.outputs.length;o++)this.updateOutput(o,e.outputs[o],!0);return this}clone(){return t.fromPSBT(this.toPSBT(this.opts.PSBTVersion),this.opts)}};var oi=vt(et(null),t=>me(t,xt.ecdsa)),Hn=vt(et(32),t=>me(t,xt.schnorr)),ba=vt(et(null),t=>{if(t.length!==64&&t.length!==65)throw new Error("Schnorr signature should be 64 or 65 bytes long");return t}),$n=ft({fingerprint:ss,path:St(null,Q)}),Ea=ft({hashes:St(It,et(32)),der:$n}),tu=et(78),eu=ft({pubKey:Hn,leafHash:et(32)}),ru=ft({version:$t,internalKey:et(32),merklePath:St(null,et(32))}),Oe=vt(ru,t=>{if(t.merklePath.length>128)throw new Error("TaprootControlBlock: merklePath should be of length 0..128 (inclusive)");return t}),nu=St(null,ft({depth:$t,version:$t,script:Tt})),pt=et(null),ma=et(20),Rr=et(32),Pn={unsignedTx:[0,!1,$e,[0],[0],!1],xpub:[1,tu,$n,[],[0,2],!1],txVersion:[2,!1,Q,[2],[2],!1],fallbackLocktime:[3,!1,Q,[],[2],!1],inputCount:[4,!1,It,[2],[2],!1],outputCount:[5,!1,It,[2],[2],!1],txModifiable:[6,!1,$t,[],[2],!1],version:[251,!1,Q,[],[0,2],!1],proprietary:[252,pt,pt,[],[0,2],!1]},cr={nonWitnessUtxo:[0,!1,oe,[],[0,2],!1],witnessUtxo:[1,!1,ne,[],[0,2],!1],partialSig:[2,oi,pt,[],[0,2],!1],sighashType:[3,!1,Q,[],[0,2],!1],redeemScript:[4,!1,pt,[],[0,2],!1],witnessScript:[5,!1,pt,[],[0,2],!1],bip32Derivation:[6,oi,$n,[],[0,2],!1],finalScriptSig:[7,!1,pt,[],[0,2],!1],finalScriptWitness:[8,!1,sr,[],[0,2],!1],porCommitment:[9,!1,pt,[],[0,2],!1],ripemd160:[10,ma,pt,[],[0,2],!1],sha256:[11,Rr,pt,[],[0,2],!1],hash160:[12,ma,pt,[],[0,2],!1],hash256:[13,Rr,pt,[],[0,2],!1],txid:[14,!1,Rr,[2],[2],!0],index:[15,!1,Q,[2],[2],!0],sequence:[16,!1,Q,[],[2],!0],requiredTimeLocktime:[17,!1,Q,[],[2],!1],requiredHeightLocktime:[18,!1,Q,[],[2],!1],tapKeySig:[19,!1,ba,[],[0,2],!1],tapScriptSig:[20,eu,ba,[],[0,2],!1],tapLeafScript:[21,Oe,pt,[],[0,2],!1],tapBip32Derivation:[22,Rr,Ea,[],[0,2],!1],tapInternalKey:[23,!1,Hn,[],[0,2],!1],tapMerkleRoot:[24,!1,Rr,[],[0,2],!1],proprietary:[252,pt,pt,[],[0,2],!1]},ga=["txid","sequence","index","witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknown"],wa=["partialSig","finalScriptSig","finalScriptWitness","tapKeySig","tapScriptSig"],Pr={redeemScript:[0,!1,pt,[],[0,2],!1],witnessScript:[1,!1,pt,[],[0,2],!1],bip32Derivation:[2,oi,$n,[],[0,2],!1],amount:[3,!1,is,[2],[2],!0],script:[4,!1,pt,[2],[2],!0],tapInternalKey:[5,!1,Hn,[],[0,2],!1],tapTree:[6,!1,nu,[],[0,2],!1],tapBip32Derivation:[7,Hn,Ea,[],[0,2],!1],proprietary:[252,pt,pt,[],[0,2],!1]},ya=[],xa=St(ro,ft({key:as(It,ft({type:It,key:et(null)})),value:et(It)}));function ii(t){let[e,r,n,o,i,s]=t;return{type:e,kc:r,vc:n,reqInc:o,allowInc:i,silentIgnore:s}}var ah=ft({type:It,key:et(null)});function si(t){let e={};for(let r in t){let[n,o,i]=t[r];e[n]=[r,o,i]}return Bt({encodeStream:(r,n)=>{let o=[];for(let i in t){let s=n[i];if(s===void 0)continue;let[a,c,f]=t[i];if(!c)o.push({key:{type:a,key:rt},value:f.encode(s)});else{let h=s.map(([u,l])=>[c.encode(u),f.encode(l)]);h.sort((u,l)=>Sr(u[0],l[0]));for(let[u,l]of h)o.push({key:{key:u,type:a},value:l})}}if(n.unknown){n.unknown.sort((i,s)=>Sr(i[0].key,s[0].key));for(let[i,s]of n.unknown)o.push({key:i,value:s})}xa.encodeStream(r,o)},decodeStream:r=>{let n=xa.decodeStream(r),o={},i={};for(let s of n){let a="unknown",c=s.key.key,f=s.value;if(e[s.key.type]){let[h,u,l]=e[s.key.type];if(a=h,!u&&c.length)throw new Error(`PSBT: Non-empty key for ${a} (key=${at.encode(c)} value=${at.encode(f)}`);if(c=u?u.decode(c):void 0,f=l.decode(f),!u){if(o[a])throw new Error(`PSBT: Same keys: ${a} (key=${c} value=${f})`);o[a]=f,i[a]=!0;continue}}else c={type:s.key.type,key:s.key.key};if(i[a])throw new Error(`PSBT: Key type with empty key and no key=${a} val=${f}`);o[a]||(o[a]=[]),o[a].push([c,f])}return o}})}var Ln=vt(si(cr),t=>{if(t.finalScriptWitness&&!t.finalScriptWitness.length)throw new Error("validateInput: empty finalScriptWitness");if(t.partialSig&&!t.partialSig.length)throw new Error("Empty partialSig");if(t.partialSig)for(let[e]of t.partialSig)me(e,xt.ecdsa);if(t.bip32Derivation)for(let[e]of t.bip32Derivation)me(e,xt.ecdsa);if(t.requiredTimeLocktime!==void 0&&t.requiredTimeLocktime<5e8)throw new Error(`validateInput: wrong timeLocktime=${t.requiredTimeLocktime}`);if(t.requiredHeightLocktime!==void 0&&(t.requiredHeightLocktime<=0||t.requiredHeightLocktime>=5e8))throw new Error(`validateInput: wrong heighLocktime=${t.requiredHeightLocktime}`);if(t.nonWitnessUtxo&&t.index!==void 0){let e=t.nonWitnessUtxo.outputs.length-1;if(t.index>e)throw new Error(`validateInput: index(${t.index}) not in nonWitnessUtxo`);let r=t.nonWitnessUtxo.outputs[t.index];if(t.witnessUtxo&&(!st(t.witnessUtxo.script,r.script)||t.witnessUtxo.amount!==r.amount))throw new Error("validateInput: witnessUtxo different from nonWitnessUtxo")}if(t.tapLeafScript)for(let[e,r]of t.tapLeafScript){if((e.version&254)!==r[r.length-1])throw new Error("validateInput: tapLeafScript version mimatch");if(r[r.length-1]&1)throw new Error("validateInput: tapLeafScript version has parity bit!")}if(t.nonWitnessUtxo&&t.index!==void 0&&t.txid){if(t.nonWitnessUtxo.outputs.length-1<t.index)throw new Error("nonWitnessUtxo: incorect output index");let r=xe.fromRaw(oe.encode(t.nonWitnessUtxo),{allowUnknownOutputs:!0,disableScriptCheck:!0,allowUnknownInputs:!0}),n=at.encode(t.txid);if(r.isFinal&&r.id!==n)throw new Error(`nonWitnessUtxo: wrong txid, exp=${n} got=${r.id}`)}return t}),Rn=vt(si(Pr),t=>{if(t.bip32Derivation)for(let[e]of t.bip32Derivation)me(e,xt.ecdsa);return t}),va=vt(si(Pn),t=>{if((t.version||0)===0){if(!t.unsignedTx)throw new Error("PSBTv0: missing unsignedTx");for(let r of t.unsignedTx.inputs)if(r.finalScriptSig&&r.finalScriptSig.length)throw new Error("PSBTv0: input scriptSig found in unsignedTx")}return t}),ou=ft({magic:Yr(jr(new Uint8Array([255])),"psbt"),global:va,inputs:St("global/unsignedTx/inputs/length",Ln),outputs:St(null,Rn)}),iu=ft({magic:Yr(jr(new Uint8Array([255])),"psbt"),global:va,inputs:St("global/inputCount",Ln),outputs:St("global/outputCount",Rn)}),ch=ft({magic:Yr(jr(new Uint8Array([255])),"psbt"),items:St(null,Vt(St(ro,ds([cs(It),et(Ur)])),ue.dict()))});function ni(t,e,r){for(let n in r){if(n==="unknown"||!e[n])continue;let{allowInc:o}=ii(e[n]);if(!o.includes(t))throw new Error(`PSBTv${t}: field ${n} is not allowed`)}for(let n in e){let{reqInc:o}=ii(e[n]);if(o.includes(t)&&r[n]===void 0)throw new Error(`PSBTv${t}: missing required field ${n}`)}}function ti(t,e,r){let n={};for(let o in r){let i=o;if(i!=="unknown"){if(!e[i])continue;let{allowInc:s,silentIgnore:a}=ii(e[i]);if(!s.includes(t)){if(a)continue;throw new Error(`Failed to serialize in PSBTv${t}: ${i} but versions allows inclusion=${s}`)}}n[i]=r[i]}return n}function Ba(t){let e=t&&t.global&&t.global.version||0;ni(e,Pn,t.global);for(let s of t.inputs)ni(e,cr,s);for(let s of t.outputs)ni(e,Pr,s);let r=e?t.global.inputCount:t.global.unsignedTx.inputs.length;if(t.inputs.length<r)throw new Error("Not enough inputs");let n=t.inputs.slice(r);if(n.length>1||n.length&&Object.keys(n[0]).length)throw new Error(`Unexpected inputs left in tx=${n}`);let o=e?t.global.outputCount:t.global.unsignedTx.outputs.length;if(t.outputs.length<o)throw new Error("Not outputs inputs");let i=t.outputs.slice(o);if(i.length>1||i.length&&Object.keys(i[0]).length)throw new Error(`Unexpected outputs left in tx=${i}`);return t}function Nr(t,e,r,n){let o={...r,...e};for(let i in t){let s=i,[a,c,f]=t[s],h=n&&!n.includes(i);if(e[i]===void 0&&i in e){if(h)throw new Error(`Cannot remove signed field=${i}`);delete o[i]}else if(c){let u=r&&r[i]?r[i]:[],l=e[s];if(l){if(!Array.isArray(l))throw new Error(`keyMap(${i}): KV pairs should be [k, v][]`);l=l.map(E=>{if(E.length!==2)throw new Error(`keyMap(${i}): KV pairs should be [k, v][]`);return[typeof E[0]=="string"?c.decode(at.decode(E[0])):E[0],typeof E[1]=="string"?f.decode(at.decode(E[1])):E[1]]});let y={},N=(E,p,A)=>{if(y[E]===void 0){y[E]=[p,A];return}let m=at.encode(f.encode(y[E][1])),b=at.encode(f.encode(A));if(m!==b)throw new Error(`keyMap(${s}): same key=${E} oldVal=${m} newVal=${b}`)};for(let[E,p]of u){let A=at.encode(c.encode(E));N(A,E,p)}for(let[E,p]of l){let A=at.encode(c.encode(E));if(p===void 0){if(h)throw new Error(`Cannot remove signed field=${s}/${E}`);delete y[A]}else N(A,E,p)}o[s]=Object.values(y)}}else if(typeof o[i]=="string")o[i]=f.decode(at.decode(o[i]));else if(h&&i in e&&r&&r[i]!==void 0&&!st(f.encode(e[i]),f.encode(r[i])))throw new Error(`Cannot change signed field=${i}`)}for(let i in o)t[i]||delete o[i];return o}var ei=vt(ou,Ba),ri=vt(iu,Ba);function fr(t,e){try{return me(t,e),!0}catch{return!1}}var su={encode(t){if(!(t.length!==2||!J(t[0])||!fr(t[0],xt.ecdsa)||t[1]!=="CHECKSIG"))return{type:"pk",pubkey:t[0]}},decode:t=>t.type==="pk"?[t.pubkey,"CHECKSIG"]:void 0},au={encode(t){if(!(t.length!==5||t[0]!=="DUP"||t[1]!=="HASH160"||!J(t[2]))&&!(t[3]!=="EQUALVERIFY"||t[4]!=="CHECKSIG"))return{type:"pkh",hash:t[2]}},decode:t=>t.type==="pkh"?["DUP","HASH160",t.hash,"EQUALVERIFY","CHECKSIG"]:void 0},cu={encode(t){if(!(t.length!==3||t[0]!=="HASH160"||!J(t[1])||t[2]!=="EQUAL"))return{type:"sh",hash:t[1]}},decode:t=>t.type==="sh"?["HASH160",t.hash,"EQUAL"]:void 0},fu={encode(t){if(!(t.length!==2||t[0]!==0||!J(t[1]))&&t[1].length===32)return{type:"wsh",hash:t[1]}},decode:t=>t.type==="wsh"?[0,t.hash]:void 0},uu={encode(t){if(!(t.length!==2||t[0]!==0||!J(t[1]))&&t[1].length===20)return{type:"wpkh",hash:t[1]}},decode:t=>t.type==="wpkh"?[0,t.hash]:void 0},lu={encode(t){let e=t.length-1;if(t[e]!=="CHECKMULTISIG")return;let r=t[0],n=t[e-1];if(typeof r!="number"||typeof n!="number")return;let o=t.slice(1,-2);if(n===o.length){for(let i of o)if(!J(i))return;return{type:"ms",m:r,pubkeys:o}}},decode:t=>t.type==="ms"?[t.m,...t.pubkeys,t.pubkeys.length,"CHECKMULTISIG"]:void 0},du={encode(t){if(!(t.length!==2||t[0]!==1||!J(t[1])))return{type:"tr",pubkey:t[1]}},decode:t=>t.type==="tr"?[1,t.pubkey]:void 0},hu={encode(t){let e=t.length-1;if(t[e]!=="CHECKSIG")return;let r=[];for(let n=0;n<e;n++){let o=t[n];if(n&1){if(o!=="CHECKSIGVERIFY"||n===e-1)return;continue}if(!J(o))return;r.push(o)}return{type:"tr_ns",pubkeys:r}},decode:t=>{if(t.type!=="tr_ns")return;let e=[];for(let r=0;r<t.pubkeys.length-1;r++)e.push(t.pubkeys[r],"CHECKSIGVERIFY");return e.push(t.pubkeys[t.pubkeys.length-1],"CHECKSIG"),e}},pu={encode(t){let e=t.length-1;if(t[e]!=="NUMEQUAL"||t[1]!=="CHECKSIG")return;let r=[],n=ua(t[e-1]);if(typeof n=="number"){for(let o=0;o<e-1;o++){let i=t[o];if(o&1){if(i!==(o===1?"CHECKSIG":"CHECKSIGADD"))throw new Error("OutScript.encode/tr_ms: wrong element");continue}if(!J(i))throw new Error("OutScript.encode/tr_ms: wrong key element");r.push(i)}return{type:"tr_ms",pubkeys:r,m:n}}},decode:t=>{if(t.type!=="tr_ms")return;let e=[t.pubkeys[0],"CHECKSIG"];for(let r=1;r<t.pubkeys.length;r++)e.push(t.pubkeys[r],"CHECKSIGADD");return e.push(t.m,"NUMEQUAL"),e}},gu={encode(t){return{type:"unknown",script:ct.encode(t)}},decode:t=>t.type==="unknown"?ct.decode(t.script):void 0},wu=[su,au,cu,fu,uu,lu,du,hu,pu,gu],yu=Vt(ct,ue.match(wu)),Et=vt(yu,t=>{if(t.type==="pk"&&!fr(t.pubkey,xt.ecdsa))throw new Error("OutScript/pk: wrong key");if((t.type==="pkh"||t.type==="sh"||t.type==="wpkh")&&(!J(t.hash)||t.hash.length!==20))throw new Error(`OutScript/${t.type}: wrong hash`);if(t.type==="wsh"&&(!J(t.hash)||t.hash.length!==32))throw new Error("OutScript/wsh: wrong hash");if(t.type==="tr"&&(!J(t.pubkey)||!fr(t.pubkey,xt.schnorr)))throw new Error("OutScript/tr: wrong taproot public key");if((t.type==="ms"||t.type==="tr_ns"||t.type==="tr_ms")&&!Array.isArray(t.pubkeys))throw new Error("OutScript/multisig: wrong pubkeys array");if(t.type==="ms"){let e=t.pubkeys.length;for(let r of t.pubkeys)if(!fr(r,xt.ecdsa))throw new Error("OutScript/multisig: wrong pubkey");if(t.m<=0||e>16||t.m>e)throw new Error("OutScript/multisig: invalid params")}if(t.type==="tr_ns"||t.type==="tr_ms"){for(let e of t.pubkeys)if(!fr(e,xt.schnorr))throw new Error(`OutScript/${t.type}: wrong pubkey`)}if(t.type==="tr_ms"){let e=t.pubkeys.length;if(t.m<=0||e>999||t.m>e)throw new Error("OutScript/tr_ms: invalid params")}return t});function Sa(t,e){if(!st(t.hash,kt(e)))throw new Error("checkScript: wsh wrong witnessScript hash");let r=Et.decode(e);if(r.type==="tr"||r.type==="tr_ns"||r.type==="tr_ms")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2SH`);if(r.type==="wpkh"||r.type==="sh")throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2WSH`)}function Nn(t,e,r){if(t){let n=Et.decode(t);if(n.type==="tr_ns"||n.type==="tr_ms"||n.type==="ms"||n.type=="pk")throw new Error(`checkScript: non-wrapped ${n.type}`);if(n.type==="sh"&&e){if(!st(n.hash,Br(e)))throw new Error("checkScript: sh wrong redeemScript hash");let o=Et.decode(e);if(o.type==="tr"||o.type==="tr_ns"||o.type==="tr_ms")throw new Error(`checkScript: P2${o.type} cannot be wrapped in P2SH`);if(o.type==="sh")throw new Error("checkScript: P2SH cannot be wrapped in P2SH")}n.type==="wsh"&&r&&Sa(n,r)}if(e){let n=Et.decode(e);n.type==="wsh"&&r&&Sa(n,r)}}var ci=(t,e=re)=>{if(!fr(t,xt.ecdsa))throw new Error("P2WPKH: invalid publicKey");if(t.length===65)throw new Error("P2WPKH: uncompressed public key");let r=Br(t);return{type:"wpkh",script:Et.encode({type:"wpkh",hash:r}),address:Ee(e).encode({type:"wpkh",hash:r})}};var bu=192,Cr=(t,e=bu)=>mn("TapLeaf",new Uint8Array([e]),Tt.encode(t));var ka=Tn(kt);function Ta(t,e){if(e.length<2||e.length>40)throw new Error("Witness: invalid length");if(t>16)throw new Error("Witness: invalid version");if(t===0&&!(e.length===20||e.length===32))throw new Error("Witness: invalid length for version")}function ai(t,e,r=re){Ta(t,e);let n=t===0?In:Yo;return n.encode(r.bech32,[t].concat(n.toWords(e)))}function Aa(t,e){return ka.encode(te(Uint8Array.from(e),t))}function Ee(t=re){return{encode(e){let{type:r}=e;if(r==="wpkh")return ai(0,e.hash,t);if(r==="wsh")return ai(0,e.hash,t);if(r==="tr")return ai(1,e.pubkey,t);if(r==="pkh")return Aa(e.hash,[t.pubKeyHash]);if(r==="sh")return Aa(e.hash,[t.scriptHash]);throw new Error(`Unknown address type=${r}`)},decode(e){if(e.length<14||e.length>74)throw new Error("Invalid address length");if(t.bech32&&e.toLowerCase().startsWith(`${t.bech32}1`)){let n;try{if(n=In.decode(e),n.words[0]!==0)throw new Error(`bech32: wrong version=${n.words[0]}`)}catch{if(n=Yo.decode(e),n.words[0]===0)throw new Error(`bech32m: wrong version=${n.words[0]}`)}if(n.prefix!==t.bech32)throw new Error(`wrong bech32 prefix=${n.prefix}`);let[o,...i]=n.words,s=In.fromWords(i);if(Ta(o,s),o===0&&s.length===32)return{type:"wsh",hash:s};if(o===0&&s.length===20)return{type:"wpkh",hash:s};if(o===1&&s.length===32)return{type:"tr",pubkey:s};throw new Error("Unknown witness program")}let r=ka.decode(e);if(r.length!==21)throw new Error("Invalid base58 address");if(r[0]===t.pubKeyHash)return{type:"pkh",hash:r.slice(1)};if(r[0]===t.scriptHash)return{type:"sh",hash:r.slice(1)};throw new Error(`Invalid address prefix=${r[0]}`)}}}function ve(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function xu(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function At(t,...e){if(!xu(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function On(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ve(t.outputLen),ve(t.blockLen)}function ur(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Ia(t,e){At(t);let r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var Ke=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Yt(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Kt(t,e){return t<<32-e|t>>>e}function Hr(t,e){return t<<e|t>>>32-e>>>0}var La=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Eu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Na(t){if(At(t),La)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Eu[t[r]];return e}var ie={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ua(t){if(t>=ie._0&&t<=ie._9)return t-ie._0;if(t>=ie.A&&t<=ie.F)return t-(ie.A-10);if(t>=ie.a&&t<=ie.f)return t-(ie.a-10)}function Ca(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(La)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ua(t.charCodeAt(i)),a=Ua(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function fi(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function Be(t){return typeof t=="string"&&(t=fi(t)),At(t),t}function qe(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];At(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}var lr=class{clone(){return this._cloneInto()}};function _a(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function dr(t){let e=n=>t().update(Be(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Mn(t=32){if(Ke&&typeof Ke.getRandomValues=="function")return Ke.getRandomValues(new Uint8Array(t));if(Ke&&typeof Ke.randomBytes=="function")return Uint8Array.from(Ke.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}var Dn=class extends lr{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,On(e);let n=Be(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return ur(this),this.iHash.update(e),this}digestInto(e){ur(this),At(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Se=(t,e,r)=>new Dn(t,e).update(r).digest();Se.create=(t,e)=>new Dn(t,e);function vu(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+f,a,n)}function Pa(t,e,r){return t&e^~t&r}function Ra(t,e,r){return t&e^t&r^e&r}var Ae=class extends lr{constructor(e,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Yt(this.buffer)}update(e){ur(this);let{view:r,buffer:n,blockLen:o}=this;e=Be(e);let i=e.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=Yt(e);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ur(this),Ia(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let u=s;u<o;u++)r[u]=0;vu(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Yt(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,h=this.get();if(f>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,h[u],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return e.length=o,e.pos=a,e.finished=i,e.destroyed=s,o%r&&e.buffer.set(n),e}};var Bu=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),$a=new Uint8Array(new Array(16).fill(0).map((t,e)=>e)),Su=$a.map(t=>(9*t+5)%16),li=[$a],di=[Su];for(let t=0;t<4;t++)for(let e of[li,di])e.push(e[t].map(r=>Bu[r]));var Oa=[[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(t=>new Uint8Array(t)),Au=li.map((t,e)=>t.map(r=>Oa[e][r])),ku=di.map((t,e)=>t.map(r=>Oa[e][r])),Tu=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Iu=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function Ha(t,e,r,n){return t===0?e^r^n:t===1?e&r|~e&n:t===2?(e|~r)^n:t===3?e&n|r&~n:e^(r|~n)}var Kn=new Uint32Array(16),ui=class extends Ae{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){let{h0:e,h1:r,h2:n,h3:o,h4:i}=this;return[e,r,n,o,i]}set(e,r,n,o,i){this.h0=e|0,this.h1=r|0,this.h2=n|0,this.h3=o|0,this.h4=i|0}process(e,r){for(let y=0;y<16;y++,r+=4)Kn[y]=e.getUint32(r,!0);let n=this.h0|0,o=n,i=this.h1|0,s=i,a=this.h2|0,c=a,f=this.h3|0,h=f,u=this.h4|0,l=u;for(let y=0;y<5;y++){let N=4-y,E=Tu[y],p=Iu[y],A=li[y],m=di[y],b=Au[y],v=ku[y];for(let x=0;x<16;x++){let w=Hr(n+Ha(y,i,a,f)+Kn[A[x]]+E,b[x])+u|0;n=u,u=f,f=Hr(a,10)|0,a=i,i=w}for(let x=0;x<16;x++){let w=Hr(o+Ha(N,s,c,h)+Kn[m[x]]+p,v[x])+l|0;o=l,l=h,h=Hr(c,10)|0,c=s,s=w}}this.set(this.h1+a+h|0,this.h2+f+l|0,this.h3+u+o|0,this.h4+n+s|0,this.h0+i+c|0)}roundClean(){Kn.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}},Ma=dr(()=>new ui);var Uu=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]),ke=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Te=new Uint32Array(64),hi=class extends Ae{constructor(e=32){super(64,e,8,!1),this.A=ke[0]|0,this.B=ke[1]|0,this.C=ke[2]|0,this.D=ke[3]|0,this.E=ke[4]|0,this.F=ke[5]|0,this.G=ke[6]|0,this.H=ke[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let u=0;u<16;u++,r+=4)Te[u]=e.getUint32(r,!1);for(let u=16;u<64;u++){let l=Te[u-15],y=Te[u-2],N=Kt(l,7)^Kt(l,18)^l>>>3,E=Kt(y,17)^Kt(y,19)^y>>>10;Te[u]=E+Te[u-7]+N+Te[u-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:h}=this;for(let u=0;u<64;u++){let l=Kt(a,6)^Kt(a,11)^Kt(a,25),y=h+l+Pa(a,c,f)+Uu[u]+Te[u]|0,E=(Kt(n,2)^Kt(n,13)^Kt(n,22))+Ra(n,o,i)|0;h=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+E|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,h=h+this.H|0,this.set(n,o,i,s,a,c,f,h)}roundClean(){Te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ie=dr(()=>new hi);var qn=BigInt(4294967295),pi=BigInt(32);function Da(t,e=!1){return e?{h:Number(t&qn),l:Number(t>>pi&qn)}:{h:Number(t>>pi&qn)|0,l:Number(t&qn)|0}}function Lu(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let o=0;o<t.length;o++){let{h:i,l:s}=Da(t[o],e);[r[o],n[o]]=[i,s]}return[r,n]}var Nu=(t,e)=>BigInt(t>>>0)<<pi|BigInt(e>>>0),Cu=(t,e,r)=>t>>>r,_u=(t,e,r)=>t<<32-r|e>>>r,Pu=(t,e,r)=>t>>>r|e<<32-r,Ru=(t,e,r)=>t<<32-r|e>>>r,Hu=(t,e,r)=>t<<64-r|e>>>r-32,$u=(t,e,r)=>t>>>r-32|e<<64-r,Ou=(t,e)=>e,Mu=(t,e)=>t,Du=(t,e,r)=>t<<r|e>>>32-r,Ku=(t,e,r)=>e<<r|t>>>32-r,qu=(t,e,r)=>e<<r-32|t>>>64-r,Wu=(t,e,r)=>t<<r-32|e>>>64-r;function Vu(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var zu=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ju=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Yu=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Gu=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Zu=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Fu=(t,e,r,n,o,i)=>e+r+n+o+i+(t/2**32|0)|0;var Qu={fromBig:Da,split:Lu,toBig:Nu,shrSH:Cu,shrSL:_u,rotrSH:Pu,rotrSL:Ru,rotrBH:Hu,rotrBL:$u,rotr32H:Ou,rotr32L:Mu,rotlSH:Du,rotlSL:Ku,rotlBH:qu,rotlBL:Wu,add:Vu,add3L:zu,add3H:ju,add4L:Yu,add4H:Gu,add5H:Fu,add5L:Zu},z=Qu;var[Xu,Ju]=z.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Ue=new Uint32Array(80),Le=new Uint32Array(80),gi=class extends Ae{constructor(e=64){super(128,e,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:h,Fh:u,Fl:l,Gh:y,Gl:N,Hh:E,Hl:p}=this;return[e,r,n,o,i,s,a,c,f,h,u,l,y,N,E,p]}set(e,r,n,o,i,s,a,c,f,h,u,l,y,N,E,p){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=h|0,this.Fh=u|0,this.Fl=l|0,this.Gh=y|0,this.Gl=N|0,this.Hh=E|0,this.Hl=p|0}process(e,r){for(let b=0;b<16;b++,r+=4)Ue[b]=e.getUint32(r),Le[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let v=Ue[b-15]|0,x=Le[b-15]|0,w=z.rotrSH(v,x,1)^z.rotrSH(v,x,8)^z.shrSH(v,x,7),B=z.rotrSL(v,x,1)^z.rotrSL(v,x,8)^z.shrSL(v,x,7),g=Ue[b-2]|0,d=Le[b-2]|0,C=z.rotrSH(g,d,19)^z.rotrBH(g,d,61)^z.shrSH(g,d,6),k=z.rotrSL(g,d,19)^z.rotrBL(g,d,61)^z.shrSL(g,d,6),T=z.add4L(B,k,Le[b-7],Le[b-16]),D=z.add4H(T,w,C,Ue[b-7],Ue[b-16]);Ue[b]=D|0,Le[b]=T|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:h,Eh:u,El:l,Fh:y,Fl:N,Gh:E,Gl:p,Hh:A,Hl:m}=this;for(let b=0;b<80;b++){let v=z.rotrSH(u,l,14)^z.rotrSH(u,l,18)^z.rotrBH(u,l,41),x=z.rotrSL(u,l,14)^z.rotrSL(u,l,18)^z.rotrBL(u,l,41),w=u&y^~u&E,B=l&N^~l&p,g=z.add5L(m,x,B,Ju[b],Le[b]),d=z.add5H(g,A,v,w,Xu[b],Ue[b]),C=g|0,k=z.rotrSH(n,o,28)^z.rotrBH(n,o,34)^z.rotrBH(n,o,39),T=z.rotrSL(n,o,28)^z.rotrBL(n,o,34)^z.rotrBL(n,o,39),D=n&i^n&a^i&a,S=o&s^o&c^s&c;A=E|0,m=p|0,E=y|0,p=N|0,y=u|0,N=l|0,{h:u,l}=z.add(f|0,h|0,d|0,C|0),f=a|0,h=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let I=z.add3L(C,T,S);n=z.add3H(I,d,k,D),o=I|0}({h:n,l:o}=z.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=z.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=z.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:h}=z.add(this.Dh|0,this.Dl|0,f|0,h|0),{h:u,l}=z.add(this.Eh|0,this.El|0,u|0,l|0),{h:y,l:N}=z.add(this.Fh|0,this.Fl|0,y|0,N|0),{h:E,l:p}=z.add(this.Gh|0,this.Gl|0,E|0,p|0),{h:A,l:m}=z.add(this.Hh|0,this.Hl|0,A|0,m|0),this.set(n,o,i,s,a,c,f,h,u,l,y,N,E,p,A,m)}roundClean(){Ue.fill(0),Le.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var $r=dr(()=>new gi);var mi=BigInt(0),bi=BigInt(1);function We(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function xi(t){if(!We(t))throw new Error("Uint8Array expected")}function hr(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function Or(t){let e=t.toString(16);return e.length&1?"0"+e:e}function Wa(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?mi:BigInt("0x"+t)}var Va=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",tl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function pr(t){if(xi(t),Va)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=tl[t[r]];return e}var se={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ka(t){if(t>=se._0&&t<=se._9)return t-se._0;if(t>=se.A&&t<=se.F)return t-(se.A-10);if(t>=se.a&&t<=se.f)return t-(se.a-10)}function Mr(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Va)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ka(t.charCodeAt(i)),a=Ka(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function ae(t){return Wa(pr(t))}function Ei(t){return xi(t),Wa(pr(Uint8Array.from(t).reverse()))}function Ve(t,e){return Mr(t.toString(16).padStart(e*2,"0"))}function vi(t,e){return Ve(t,e).reverse()}function Nt(t,e,r){let n;if(typeof e=="string")try{n=Mr(e)}catch(i){throw new Error(t+" must be hex string or Uint8Array, cause: "+i)}else if(We(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(t+" of length "+r+" expected, got "+o);return n}function Dr(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];xi(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}var wi=t=>typeof t=="bigint"&&mi<=t;function Wn(t,e,r){return wi(t)&&wi(e)&&wi(r)&&e<=t&&t<r}function ze(t,e,r,n){if(!Wn(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function za(t){let e;for(e=0;t>mi;t>>=bi,e+=1);return e}var je=t=>(bi<<BigInt(t))-bi,yi=t=>new Uint8Array(t),qa=t=>Uint8Array.from(t);function ja(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=yi(t),o=yi(t),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...u)=>r(o,n,...u),c=(u=yi(0))=>{o=a(qa([0]),u),n=a(),u.length!==0&&(o=a(qa([1]),u),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let u=0,l=[];for(;u<e;){n=a();let y=n.slice();l.push(y),u+=n.length}return Dr(...l)};return(u,l)=>{s(),c(u);let y;for(;!(y=l(f()));)c();return s(),y}}var el={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||We(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Ye(t,e,r={}){let n=(o,i,s)=>{let a=el[i];if(typeof a!="function")throw new Error("invalid validator function");let c=t[o];if(!(s&&c===void 0)&&!a(c,t))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(e))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return t}function Bi(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let i=t(r,...n);return e.set(r,i),i}}var gt=BigInt(0),ot=BigInt(1),Ge=BigInt(2),rl=BigInt(3),Si=BigInt(4),Ya=BigInt(5),Ga=BigInt(8),nl=BigInt(9),ol=BigInt(16);function bt(t,e){let r=t%e;return r>=gt?r:e+r}function il(t,e,r){if(e<gt)throw new Error("invalid exponent, negatives unsupported");if(r<=gt)throw new Error("invalid modulus");if(r===ot)return gt;let n=ot;for(;e>gt;)e&ot&&(n=n*t%r),t=t*t%r,e>>=ot;return n}function Ct(t,e,r){let n=t;for(;e-- >gt;)n*=n,n%=r;return n}function Vn(t,e){if(t===gt)throw new Error("invert: expected non-zero number");if(e<=gt)throw new Error("invert: expected positive modulus, got "+e);let r=bt(t,e),n=e,o=gt,i=ot,s=ot,a=gt;for(;r!==gt;){let f=n/r,h=n%r,u=o-s*f,l=i-a*f;n=r,r=h,o=s,i=a,s=u,a=l}if(n!==ot)throw new Error("invert: does not exist");return bt(o,e)}function sl(t){let e=(t-ot)/Ge,r,n,o;for(r=t-ot,n=0;r%Ge===gt;r/=Ge,n++);for(o=Ge;o<t&&il(o,e,t)!==t-ot;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(t+ot)/Si;return function(c,f){let h=c.pow(f,s);if(!c.eql(c.sqr(h),f))throw new Error("Cannot find square root");return h}}let i=(r+ot)/Ge;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,h=a.pow(a.mul(a.ONE,o),r),u=a.pow(c,i),l=a.pow(c,r);for(;!a.eql(l,a.ONE);){if(a.eql(l,a.ZERO))return a.ZERO;let y=1;for(let E=a.sqr(l);y<f&&!a.eql(E,a.ONE);y++)E=a.sqr(E);let N=a.pow(h,ot<<BigInt(f-y-1));h=a.sqr(N),u=a.mul(u,N),l=a.mul(l,h),f=y}return u}}function al(t){if(t%Si===rl){let e=(t+ot)/Si;return function(n,o){let i=n.pow(o,e);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(t%Ga===Ya){let e=(t-Ya)/Ga;return function(n,o){let i=n.mul(o,Ge),s=n.pow(i,e),a=n.mul(o,s),c=n.mul(n.mul(a,Ge),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return t%ol,sl(t)}var cl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ai(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=cl.reduce((n,o)=>(n[o]="function",n),e);return Ye(t,r)}function fl(t,e,r){if(r<gt)throw new Error("invalid exponent, negatives unsupported");if(r===gt)return t.ONE;if(r===ot)return e;let n=t.ONE,o=e;for(;r>gt;)r&ot&&(n=t.mul(n,o)),o=t.sqr(o),r>>=ot;return n}function ul(t,e){let r=new Array(e.length),n=e.reduce((i,s,a)=>t.is0(s)?i:(r[a]=i,t.mul(i,s)),t.ONE),o=t.inv(n);return e.reduceRight((i,s,a)=>t.is0(s)?i:(r[a]=t.mul(i,r[a]),t.mul(i,s)),o),r}function ki(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function zn(t,e,r=!1,n={}){if(t<=gt)throw new Error("invalid field: expected ORDER > 0, got "+t);let{nBitLength:o,nByteLength:i}=ki(t,e);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:t,isLE:r,BITS:o,BYTES:i,MASK:je(o),ZERO:gt,ONE:ot,create:c=>bt(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return gt<=c&&c<t},is0:c=>c===gt,isOdd:c=>(c&ot)===ot,neg:c=>bt(-c,t),eql:(c,f)=>c===f,sqr:c=>bt(c*c,t),add:(c,f)=>bt(c+f,t),sub:(c,f)=>bt(c-f,t),mul:(c,f)=>bt(c*f,t),pow:(c,f)=>fl(a,c,f),div:(c,f)=>bt(c*Vn(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Vn(c,t),sqrt:n.sqrt||(c=>(s||(s=al(t)),s(a,c))),invertBatch:c=>ul(a,c),cmov:(c,f,h)=>h?f:c,toBytes:c=>r?vi(c,i):Ve(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?Ei(c):ae(c)}});return Object.freeze(a)}function Za(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ti(t){let e=Za(t);return e+Math.ceil(e/2)}function Fa(t,e,r=!1){let n=t.length,o=Za(e),i=Ti(e);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ei(t):ae(t),a=bt(s,e-ot)+ot;return r?vi(a,o):Ve(a,o)}var Qa=BigInt(0),Ci=BigInt(1);function Ii(t,e){let r=e.negate();return t?r:e}function Ja(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Ui(t,e){Ja(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,i=je(t),s=BigInt(t);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function Xa(t,e,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(t&o),c=t>>s;a>n&&(a-=i,c+=Ci);let f=e*n,h=f+Math.abs(a)-1,u=a===0,l=a<0,y=e%2!==0;return{nextN:c,offset:h,isZero:u,isNeg:l,isNegF:y,offsetF:f}}function ll(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function dl(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}var Li=new WeakMap,tc=new WeakMap;function Ni(t){return tc.get(t)||1}function ec(t,e){return{constTimeNegate:Ii,hasPrecomputes(r){return Ni(r)!==1},unsafeLadder(r,n,o=t.ZERO){let i=r;for(;n>Qa;)n&Ci&&(o=o.add(i)),i=i.double(),n>>=Ci;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=Ui(n,e),s=[],a=r,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let h=1;h<i;h++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(r,n,o){let i=t.ZERO,s=t.BASE,a=Ui(r,e);for(let c=0;c<a.windows;c++){let{nextN:f,offset:h,isZero:u,isNeg:l,isNegF:y,offsetF:N}=Xa(o,c,a);o=f,u?s=s.add(Ii(y,n[N])):i=i.add(Ii(l,n[h]))}return{p:i,f:s}},wNAFUnsafe(r,n,o,i=t.ZERO){let s=Ui(r,e);for(let a=0;a<s.windows&&o!==Qa;a++){let{nextN:c,offset:f,isZero:h,isNeg:u}=Xa(o,a,s);if(o=c,!h){let l=n[f];i=i.add(u?l.negate():l)}}return i},getPrecomputes(r,n,o){let i=Li.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&Li.set(n,o(i))),i},wNAFCached(r,n,o){let i=Ni(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=Ni(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){Ja(n,e),tc.set(r,n),Li.delete(r)}}}function rc(t,e,r,n){if(ll(r,t),dl(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=t.ZERO,i=za(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=je(s),c=new Array(Number(a)+1).fill(o),f=Math.floor((e.BITS-1)/s)*s,h=o;for(let u=f;u>=0;u-=s){c.fill(o);for(let y=0;y<n.length;y++){let N=n[y],E=Number(N>>BigInt(u)&a);c[E]=c[E].add(r[y])}let l=o;for(let y=c.length-1,N=o;y>0;y--)N=N.add(c[y]),l=l.add(N);if(h=h.add(l),u!==0)for(let y=0;y<s;y++)h=h.double()}return h}function _i(t){return Ai(t.Fp),Ye(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ki(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function nc(t){t.lowS!==void 0&&hr("lowS",t.lowS),t.prehash!==void 0&&hr("prehash",t.prehash)}function hl(t){let e=_i(t);Ye(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:o}=e;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}var Pi=class extends Error{constructor(e=""){super(e)}},ce={Err:Pi,_tlv:{encode:(t,e)=>{let{Err:r}=ce;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Or(o.length/2|128):"";return Or(t)+i+o+e},decode(t,e){let{Err:r}=ce,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let h of f)s=s<<8|h;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=ce;if(t<fe)throw new e("integer: negative integers are not allowed");let r=Or(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ce;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return ae(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ce,o=Nt("signature",t),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:h}=n.decode(2,c);if(h.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=ce,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},fe=BigInt(0),mt=BigInt(1),hp=BigInt(2),oc=BigInt(3),pp=BigInt(4);function pl(t){let e=hl(t),{Fp:r}=e,n=zn(e.n,e.nBitLength),o=e.toBytes||((E,p,A)=>{let m=p.toAffine();return Dr(Uint8Array.from([4]),r.toBytes(m.x),r.toBytes(m.y))}),i=e.fromBytes||(E=>{let p=E.subarray(1),A=r.fromBytes(p.subarray(0,r.BYTES)),m=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:A,y:m}});function s(E){let{a:p,b:A}=e,m=r.sqr(E),b=r.mul(m,E);return r.add(r.add(b,r.mul(E,p)),A)}if(!r.eql(r.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(E){return Wn(E,mt,e.n)}function c(E){let{allowedPrivateKeyLengths:p,nByteLength:A,wrapPrivateKey:m,n:b}=e;if(p&&typeof E!="bigint"){if(We(E)&&(E=pr(E)),typeof E!="string"||!p.includes(E.length))throw new Error("invalid private key");E=E.padStart(A*2,"0")}let v;try{v=typeof E=="bigint"?E:ae(Nt("private key",E,A))}catch{throw new Error("invalid private key, expected hex or "+A+" bytes, got "+typeof E)}return m&&(v=bt(v,b)),ze("private key",v,mt,b),v}function f(E){if(!(E instanceof l))throw new Error("ProjectivePoint expected")}let h=Bi((E,p)=>{let{px:A,py:m,pz:b}=E;if(r.eql(b,r.ONE))return{x:A,y:m};let v=E.is0();p==null&&(p=v?r.ONE:r.inv(b));let x=r.mul(A,p),w=r.mul(m,p),B=r.mul(b,p);if(v)return{x:r.ZERO,y:r.ZERO};if(!r.eql(B,r.ONE))throw new Error("invZ was invalid");return{x,y:w}}),u=Bi(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.py))return;throw new Error("bad point: ZERO")}let{x:p,y:A}=E.toAffine();if(!r.isValid(p)||!r.isValid(A))throw new Error("bad point: x or y not FE");let m=r.sqr(A),b=s(p);if(!r.eql(m,b))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(p,A,m){if(p==null||!r.isValid(p))throw new Error("x required");if(A==null||!r.isValid(A))throw new Error("y required");if(m==null||!r.isValid(m))throw new Error("z required");this.px=p,this.py=A,this.pz=m,Object.freeze(this)}static fromAffine(p){let{x:A,y:m}=p||{};if(!p||!r.isValid(A)||!r.isValid(m))throw new Error("invalid affine point");if(p instanceof l)throw new Error("projective point not allowed");let b=v=>r.eql(v,r.ZERO);return b(A)&&b(m)?l.ZERO:new l(A,m,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){let A=r.invertBatch(p.map(m=>m.pz));return p.map((m,b)=>m.toAffine(A[b])).map(l.fromAffine)}static fromHex(p){let A=l.fromAffine(i(Nt("pointHex",p)));return A.assertValidity(),A}static fromPrivateKey(p){return l.BASE.multiply(c(p))}static msm(p,A){return rc(l,n,p,A)}_setWindowSize(p){N.setWindowSize(this,p)}assertValidity(){u(this)}hasEvenY(){let{y:p}=this.toAffine();if(r.isOdd)return!r.isOdd(p);throw new Error("Field doesn't support isOdd")}equals(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.eql(r.mul(A,w),r.mul(v,b)),g=r.eql(r.mul(m,w),r.mul(x,b));return B&&g}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:p,b:A}=e,m=r.mul(A,oc),{px:b,py:v,pz:x}=this,w=r.ZERO,B=r.ZERO,g=r.ZERO,d=r.mul(b,b),C=r.mul(v,v),k=r.mul(x,x),T=r.mul(b,v);return T=r.add(T,T),g=r.mul(b,x),g=r.add(g,g),w=r.mul(p,g),B=r.mul(m,k),B=r.add(w,B),w=r.sub(C,B),B=r.add(C,B),B=r.mul(w,B),w=r.mul(T,w),g=r.mul(m,g),k=r.mul(p,k),T=r.sub(d,k),T=r.mul(p,T),T=r.add(T,g),g=r.add(d,d),d=r.add(g,d),d=r.add(d,k),d=r.mul(d,T),B=r.add(B,d),k=r.mul(v,x),k=r.add(k,k),d=r.mul(k,T),w=r.sub(w,d),g=r.mul(k,C),g=r.add(g,g),g=r.add(g,g),new l(w,B,g)}add(p){f(p);let{px:A,py:m,pz:b}=this,{px:v,py:x,pz:w}=p,B=r.ZERO,g=r.ZERO,d=r.ZERO,C=e.a,k=r.mul(e.b,oc),T=r.mul(A,v),D=r.mul(m,x),S=r.mul(b,w),I=r.add(A,m),L=r.add(v,x);I=r.mul(I,L),L=r.add(T,D),I=r.sub(I,L),L=r.add(A,b);let $=r.add(v,w);return L=r.mul(L,$),$=r.add(T,S),L=r.sub(L,$),$=r.add(m,b),B=r.add(x,w),$=r.mul($,B),B=r.add(D,S),$=r.sub($,B),d=r.mul(C,L),B=r.mul(k,S),d=r.add(B,d),B=r.sub(D,d),d=r.add(D,d),g=r.mul(B,d),D=r.add(T,T),D=r.add(D,T),S=r.mul(C,S),L=r.mul(k,L),D=r.add(D,S),S=r.sub(T,S),S=r.mul(C,S),L=r.add(L,S),T=r.mul(D,L),g=r.add(g,T),T=r.mul($,L),B=r.mul(I,B),B=r.sub(B,T),T=r.mul(I,D),d=r.mul($,d),d=r.add(d,T),new l(B,g,d)}subtract(p){return this.add(p.negate())}is0(){return this.equals(l.ZERO)}wNAF(p){return N.wNAFCached(this,p,l.normalizeZ)}multiplyUnsafe(p){let{endo:A,n:m}=e;ze("scalar",p,fe,m);let b=l.ZERO;if(p===fe)return b;if(this.is0()||p===mt)return this;if(!A||N.hasPrecomputes(this))return N.wNAFCachedUnsafe(this,p,l.normalizeZ);let{k1neg:v,k1:x,k2neg:w,k2:B}=A.splitScalar(p),g=b,d=b,C=this;for(;x>fe||B>fe;)x&mt&&(g=g.add(C)),B&mt&&(d=d.add(C)),C=C.double(),x>>=mt,B>>=mt;return v&&(g=g.negate()),w&&(d=d.negate()),d=new l(r.mul(d.px,A.beta),d.py,d.pz),g.add(d)}multiply(p){let{endo:A,n:m}=e;ze("scalar",p,mt,m);let b,v;if(A){let{k1neg:x,k1:w,k2neg:B,k2:g}=A.splitScalar(p),{p:d,f:C}=this.wNAF(w),{p:k,f:T}=this.wNAF(g);d=N.constTimeNegate(x,d),k=N.constTimeNegate(B,k),k=new l(r.mul(k.px,A.beta),k.py,k.pz),b=d.add(k),v=C.add(T)}else{let{p:x,f:w}=this.wNAF(p);b=x,v=w}return l.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(p,A,m){let b=l.BASE,v=(w,B)=>B===fe||B===mt||!w.equals(b)?w.multiplyUnsafe(B):w.multiply(B),x=v(this,A).add(v(p,m));return x.is0()?void 0:x}toAffine(p){return h(this,p)}isTorsionFree(){let{h:p,isTorsionFree:A}=e;if(p===mt)return!0;if(A)return A(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:p,clearCofactor:A}=e;return p===mt?this:A?A(l,this):this.multiplyUnsafe(e.h)}toRawBytes(p=!0){return hr("isCompressed",p),this.assertValidity(),o(l,this,p)}toHex(p=!0){return hr("isCompressed",p),pr(this.toRawBytes(p))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let y=e.nBitLength,N=ec(l,e.endo?Math.ceil(y/2):y);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function gl(t){let e=_i(t);return Ye(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function ic(t){let e=gl(t),{Fp:r,n}=e,o=r.BYTES+1,i=2*r.BYTES+1;function s(S){return bt(S,n)}function a(S){return Vn(S,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:h,isWithinCurveOrder:u}=pl({...e,toBytes(S,I,L){let $=I.toAffine(),M=r.toBytes($.x),W=Dr;return hr("isCompressed",L),L?W(Uint8Array.from([I.hasEvenY()?2:3]),M):W(Uint8Array.from([4]),M,r.toBytes($.y))},fromBytes(S){let I=S.length,L=S[0],$=S.subarray(1);if(I===o&&(L===2||L===3)){let M=ae($);if(!Wn(M,mt,r.ORDER))throw new Error("Point is not on curve");let W=h(M),j;try{j=r.sqrt(W)}catch(X){let F=X instanceof Error?": "+X.message:"";throw new Error("Point is not on curve"+F)}let Y=(j&mt)===mt;return(L&1)===1!==Y&&(j=r.neg(j)),{x:M,y:j}}else if(I===i&&L===4){let M=r.fromBytes($.subarray(0,r.BYTES)),W=r.fromBytes($.subarray(r.BYTES,2*r.BYTES));return{x:M,y:W}}else{let M=o,W=i;throw new Error("invalid Point, expected length of "+M+", or uncompressed "+W+", got "+I)}}}),l=S=>pr(Ve(S,e.nByteLength));function y(S){let I=n>>mt;return S>I}function N(S){return y(S)?s(-S):S}let E=(S,I,L)=>ae(S.slice(I,L));class p{constructor(I,L,$){ze("r",I,mt,n),ze("s",L,mt,n),this.r=I,this.s=L,$!=null&&(this.recovery=$),Object.freeze(this)}static fromCompact(I){let L=e.nByteLength;return I=Nt("compactSignature",I,L*2),new p(E(I,0,L),E(I,L,2*L))}static fromDER(I){let{r:L,s:$}=ce.toSig(Nt("DER",I));return new p(L,$)}assertValidity(){}addRecoveryBit(I){return new p(this.r,this.s,I)}recoverPublicKey(I){let{r:L,s:$,recovery:M}=this,W=w(Nt("msgHash",I));if(M==null||![0,1,2,3].includes(M))throw new Error("recovery id invalid");let j=M===2||M===3?L+e.n:L;if(j>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let Y=M&1?"03":"02",it=c.fromHex(Y+l(j)),X=a(j),F=s(-W*X),P=s($*X),_=c.BASE.multiplyAndAddUnsafe(it,F,P);if(!_)throw new Error("point at infinify");return _.assertValidity(),_}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Mr(this.toDERHex())}toDERHex(){return ce.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Mr(this.toCompactHex())}toCompactHex(){return l(this.r)+l(this.s)}}let A={isValidPrivateKey(S){try{return f(S),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let S=Ti(e.n);return Fa(e.randomBytes(S),e.n)},precompute(S=8,I=c.BASE){return I._setWindowSize(S),I.multiply(BigInt(3)),I}};function m(S,I=!0){return c.fromPrivateKey(S).toRawBytes(I)}function b(S){let I=We(S),L=typeof S=="string",$=(I||L)&&S.length;return I?$===o||$===i:L?$===2*o||$===2*i:S instanceof c}function v(S,I,L=!0){if(b(S))throw new Error("first arg must be private key");if(!b(I))throw new Error("second arg must be public key");return c.fromHex(I).multiply(f(S)).toRawBytes(L)}let x=e.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let I=ae(S),L=S.length*8-e.nBitLength;return L>0?I>>BigInt(L):I},w=e.bits2int_modN||function(S){return s(x(S))},B=je(e.nBitLength);function g(S){return ze("num < 2^"+e.nBitLength,S,fe,B),Ve(S,e.nByteLength)}function d(S,I,L=C){if(["recovered","canonical"].some(R=>R in L))throw new Error("sign() legacy options not supported");let{hash:$,randomBytes:M}=e,{lowS:W,prehash:j,extraEntropy:Y}=L;W==null&&(W=!0),S=Nt("msgHash",S),nc(L),j&&(S=Nt("prehashed msgHash",$(S)));let it=w(S),X=f(I),F=[g(X),g(it)];if(Y!=null&&Y!==!1){let R=Y===!0?M(r.BYTES):Y;F.push(Nt("extraEntropy",R))}let P=Dr(...F),_=it;function U(R){let H=x(R);if(!u(H))return;let O=a(H),q=c.BASE.multiply(H).toAffine(),K=s(q.x);if(K===fe)return;let G=s(O*s(_+K*X));if(G===fe)return;let Z=(q.x===K?0:2)|Number(q.y&mt),V=G;return W&&y(G)&&(V=N(G),Z^=1),new p(K,V,Z)}return{seed:P,k2sig:U}}let C={lowS:e.lowS,prehash:!1},k={lowS:e.lowS,prehash:!1};function T(S,I,L=C){let{seed:$,k2sig:M}=d(S,I,L),W=e;return ja(W.hash.outputLen,W.nByteLength,W.hmac)($,M)}c.BASE._setWindowSize(8);function D(S,I,L,$=k){let M=S;I=Nt("msgHash",I),L=Nt("publicKey",L);let{lowS:W,prehash:j,format:Y}=$;if(nc($),"strict"in $)throw new Error("options.strict was renamed to lowS");if(Y!==void 0&&Y!=="compact"&&Y!=="der")throw new Error("format must be compact or der");let it=typeof M=="string"||We(M),X=!it&&!Y&&typeof M=="object"&&M!==null&&typeof M.r=="bigint"&&typeof M.s=="bigint";if(!it&&!X)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let F,P;try{if(X&&(F=new p(M.r,M.s)),it){try{Y!=="compact"&&(F=p.fromDER(M))}catch(Z){if(!(Z instanceof ce.Err))throw Z}!F&&Y!=="der"&&(F=p.fromCompact(M))}P=c.fromHex(L)}catch{return!1}if(!F||W&&F.hasHighS())return!1;j&&(I=e.hash(I));let{r:_,s:U}=F,R=w(I),H=a(U),O=s(R*H),q=s(_*H),K=c.BASE.multiplyAndAddUnsafe(P,O,q)?.toAffine();return K?s(K.x)===_:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:v,sign:T,verify:D,ProjectivePoint:c,Signature:p,utils:A}}function wl(t){return{hash:t,hmac:(e,...r)=>Se(t,e,qe(...r)),randomBytes:Mn}}function sc(t,e){let r=n=>ic({...t,...wl(n)});return{...r(e),create:r}}var fc=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ac=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yl=BigInt(1),Ri=BigInt(2),cc=(t,e)=>(t+e/Ri)/e;function bl(t){let e=fc,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,h=f*f*t%e,u=Ct(h,r,e)*h%e,l=Ct(u,r,e)*h%e,y=Ct(l,Ri,e)*f%e,N=Ct(y,o,e)*y%e,E=Ct(N,i,e)*N%e,p=Ct(E,a,e)*E%e,A=Ct(p,c,e)*p%e,m=Ct(A,a,e)*E%e,b=Ct(m,r,e)*h%e,v=Ct(b,s,e)*N%e,x=Ct(v,n,e)*f%e,w=Ct(x,Ri,e);if(!Hi.eql(Hi.sqr(w),t))throw new Error("Cannot find square root");return w}var Hi=zn(fc,void 0,void 0,{sqrt:bl}),qt=sc({a:BigInt(0),b:BigInt(7),Fp:Hi,n:ac,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=ac,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-yl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=cc(i*t,e),c=cc(-n*t,e),f=bt(t-a*r-c*o,e),h=bt(-a*n-c*i,e),u=f>s,l=h>s;if(u&&(f=e-f),l&&(h=e-h),f>s||h>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:u,k1:f,k2neg:l,k2:h}}}},Ie),Bp=BigInt(0);var Sp=qt.ProjectivePoint;var jn=qt.ProjectivePoint,$i=Tn(Ie);function uc(t){At(t);let e=t.length===0?"0":Na(t);return BigInt("0x"+e)}function ml(t){if(typeof t!="bigint")throw new Error("bigint expected");return Ca(t.toString(16).padStart(64,"0"))}var xl=fi("Bitcoin seed"),Oi={private:76066276,public:76067358},Mi=2147483648,El=t=>Ma(Ie(t)),vl=t=>Yt(t).getUint32(0,!1),Yn=t=>{if(!Number.isSafeInteger(t)||t<0||t>2**32-1)throw new Error("invalid number, should be from 0 to 2**32-1, got "+t);let e=new Uint8Array(4);return Yt(e).setUint32(0,t,!1),e},Gn=class t{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return vl(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){let e=this.privateKey;if(!e)throw new Error("No private key");return $i.encode(this.serialize(this.versions.private,qe(new Uint8Array([0]),e)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return $i.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(e,r=Oi){if(At(e),8*e.length<128||8*e.length>512)throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+e.length);let n=Se($r,xl,e);return new t({versions:r,chainCode:n.slice(32),privateKey:n.slice(0,32)})}static fromExtendedKey(e,r=Oi){let n=$i.decode(e),o=Yt(n),i=o.getUint32(0,!1),s={versions:r,depth:n[4],parentFingerprint:o.getUint32(5,!1),index:o.getUint32(9,!1),chainCode:n.slice(13,45)},a=n.slice(45),c=a[0]===0;if(i!==r[c?"private":"public"])throw new Error("Version mismatch");return c?new t({...s,privateKey:a.slice(1)}):new t({...s,publicKey:a})}static fromJSON(e){return t.fromExtendedKey(e.xpriv)}constructor(e){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!e||typeof e!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=e.versions||Oi,this.depth=e.depth||0,this.chainCode=e.chainCode||null,this.index=e.index||0,this.parentFingerprint=e.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(e.publicKey&&e.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(e.privateKey){if(!qt.utils.isValidPrivateKey(e.privateKey))throw new Error("Invalid private key");this.privKey=typeof e.privateKey=="bigint"?e.privateKey:uc(e.privateKey),this.privKeyBytes=ml(this.privKey),this.pubKey=qt.getPublicKey(e.privateKey,!0)}else if(e.publicKey)this.pubKey=jn.fromHex(e.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=El(this.pubKey)}derive(e){if(!/^[mM]'?/.test(e))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(e))return this;let r=e.replace(/^[mM]'?\//,"").split("/"),n=this;for(let o of r){let i=/^(\d+)('?)$/.exec(o),s=i&&i[1];if(!i||i.length!==3||typeof s!="string")throw new Error("invalid child index: "+o);let a=+s;if(!Number.isSafeInteger(a)||a>=Mi)throw new Error("Invalid index");i[2]==="'"&&(a+=Mi),n=n.deriveChild(a)}return n}deriveChild(e){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let r=Yn(e);if(e>=Mi){let a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");r=qe(new Uint8Array([0]),a,r)}else r=qe(this.pubKey,r);let n=Se($r,this.chainCode,r),o=uc(n.slice(0,32)),i=n.slice(32);if(!qt.utils.isValidPrivateKey(o))throw new Error("Tweak bigger than curve order");let s={versions:this.versions,chainCode:i,depth:this.depth+1,parentFingerprint:this.fingerprint,index:e};try{if(this.privateKey){let a=bt(this.privKey+o,qt.CURVE.n);if(!qt.utils.isValidPrivateKey(a))throw new Error("The tweak was out of range or the resulted private key is invalid");s.privateKey=a}else{let a=jn.fromHex(this.pubKey).add(jn.fromPrivateKey(o));if(a.equals(jn.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");s.publicKey=a.toRawBytes(!0)}return new t(s)}catch{return this.deriveChild(e+1)}}sign(e){if(!this.privateKey)throw new Error("No privateKey set!");return At(e,32),qt.sign(e,this.privKey).toCompactRawBytes()}verify(e,r){if(At(e,32),At(r,64),!this.publicKey)throw new Error("No publicKey set!");let n;try{n=qt.Signature.fromCompact(r)}catch{return!1}return qt.verify(n,e,this.publicKey)}wipePrivateData(){return this.privKey=void 0,this.privKeyBytes&&(this.privKeyBytes.fill(0),this.privKeyBytes=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(e,r){if(!this.chainCode)throw new Error("No chainCode set");return At(r,33),qe(Yn(e),new Uint8Array([this.depth]),Yn(this.parentFingerprint),Yn(this.index),this.chainCode,r)}};function Bl(t,e,r,n){On(t);let o=_a({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:a}=o;if(ve(i),ve(s),ve(a),i<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Be(e),f=Be(r),h=new Uint8Array(s),u=Se.create(t,c),l=u._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:a,DK:h,PRF:u,PRFSalt:l}}function Sl(t,e,r,n,o){return t.destroy(),e.destroy(),n&&n.destroy(),o.fill(0),r}function lc(t,e,r,n){let{c:o,dkLen:i,DK:s,PRF:a,PRFSalt:c}=Bl(t,e,r,n),f,h=new Uint8Array(4),u=Yt(h),l=new Uint8Array(a.outputLen);for(let y=1,N=0;N<i;y++,N+=a.outputLen){let E=s.subarray(N,N+a.outputLen);u.setInt32(0,y,!1),(f=c._cloneInto(f)).update(h).digestInto(l),E.set(l.subarray(0,E.length));for(let p=1;p<o;p++){a._cloneInto(f).update(l).digestInto(l);for(let A=0;A<E.length;A++)E[A]^=l[A]}}return Sl(a,c,s,f,l)}var Al=t=>t[0]==="\u3042\u3044\u3053\u304F\u3057\u3093";function dc(t){if(typeof t!="string")throw new TypeError("invalid mnemonic type: "+typeof t);return t.normalize("NFKD")}function hc(t){let e=dc(t),r=e.split(" ");if(![12,15,18,21,24].includes(r.length))throw new Error("Invalid mnemonic");return{nfkd:e,words:r}}function pc(t){At(t,16,20,24,28,32)}function gc(t,e=128){if(ve(e),e%32!==0||e>256)throw new TypeError("Invalid entropy");return Il(Mn(e/8),t)}var kl=t=>{let e=8-t.length/4;return new Uint8Array([Ie(t)[0]>>e<<e])};function wc(t){if(!Array.isArray(t)||t.length!==2048||typeof t[0]!="string")throw new Error("Wordlist: expected array of 2048 strings");return t.forEach(e=>{if(typeof e!="string")throw new Error("wordlist: non-string element: "+e)}),Ir.chain(Ir.checksum(1,kl),Ir.radix2(11,!0),Ir.alphabet(t))}function Tl(t,e){let{words:r}=hc(t),n=wc(e).decode(r);return pc(n),n}function Il(t,e){return pc(t),wc(e).encode(t).join(Al(e)?"\u3000":" ")}function yc(t,e){try{Tl(t,e)}catch{return!1}return!0}var Ul=t=>dc("mnemonic"+t);function bc(t,e=""){return lc($r,hc(t).nfkd,Ul(e),{c:2048,dkLen:64})}var Di=`abandon
4ability
5able
6about
7above
8absent
9absorb
10abstract
11absurd
12abuse
13access
14accident
15account
16accuse
17achieve
18acid
19acoustic
20acquire
21across
22act
23action
24actor
25actress
26actual
27adapt
28add
29addict
30address
31adjust
32admit
33adult
34advance
35advice
36aerobic
37affair
38afford
39afraid
40again
41age
42agent
43agree
44ahead
45aim
46air
47airport
48aisle
49alarm
50album
51alcohol
52alert
53alien
54all
55alley
56allow
57almost
58alone
59alpha
60already
61also
62alter
63always
64amateur
65amazing
66among
67amount
68amused
69analyst
70anchor
71ancient
72anger
73angle
74angry
75animal
76ankle
77announce
78annual
79another
80answer
81antenna
82antique
83anxiety
84any
85apart
86apology
87appear
88apple
89approve
90april
91arch
92arctic
93area
94arena
95argue
96arm
97armed
98armor
99army
100around
101arrange
102arrest
103arrive
104arrow
105art
106artefact
107artist
108artwork
109ask
110aspect
111assault
112asset
113assist
114assume
115asthma
116athlete
117atom
118attack
119attend
120attitude
121attract
122auction
123audit
124august
125aunt
126author
127auto
128autumn
129average
130avocado
131avoid
132awake
133aware
134away
135awesome
136awful
137awkward
138axis
139baby
140bachelor
141bacon
142badge
143bag
144balance
145balcony
146ball
147bamboo
148banana
149banner
150bar
151barely
152bargain
153barrel
154base
155basic
156basket
157battle
158beach
159bean
160beauty
161because
162become
163beef
164before
165begin
166behave
167behind
168believe
169below
170belt
171bench
172benefit
173best
174betray
175better
176between
177beyond
178bicycle
179bid
180bike
181bind
182biology
183bird
184birth
185bitter
186black
187blade
188blame
189blanket
190blast
191bleak
192bless
193blind
194blood
195blossom
196blouse
197blue
198blur
199blush
200board
201boat
202body
203boil
204bomb
205bone
206bonus
207book
208boost
209border
210boring
211borrow
212boss
213bottom
214bounce
215box
216boy
217bracket
218brain
219brand
220brass
221brave
222bread
223breeze
224brick
225bridge
226brief
227bright
228bring
229brisk
230broccoli
231broken
232bronze
233broom
234brother
235brown
236brush
237bubble
238buddy
239budget
240buffalo
241build
242bulb
243bulk
244bullet
245bundle
246bunker
247burden
248burger
249burst
250bus
251business
252busy
253butter
254buyer
255buzz
256cabbage
257cabin
258cable
259cactus
260cage
261cake
262call
263calm
264camera
265camp
266can
267canal
268cancel
269candy
270cannon
271canoe
272canvas
273canyon
274capable
275capital
276captain
277car
278carbon
279card
280cargo
281carpet
282carry
283cart
284case
285cash
286casino
287castle
288casual
289cat
290catalog
291catch
292category
293cattle
294caught
295cause
296caution
297cave
298ceiling
299celery
300cement
301census
302century
303cereal
304certain
305chair
306chalk
307champion
308change
309chaos
310chapter
311charge
312chase
313chat
314cheap
315check
316cheese
317chef
318cherry
319chest
320chicken
321chief
322child
323chimney
324choice
325choose
326chronic
327chuckle
328chunk
329churn
330cigar
331cinnamon
332circle
333citizen
334city
335civil
336claim
337clap
338clarify
339claw
340clay
341clean
342clerk
343clever
344click
345client
346cliff
347climb
348clinic
349clip
350clock
351clog
352close
353cloth
354cloud
355clown
356club
357clump
358cluster
359clutch
360coach
361coast
362coconut
363code
364coffee
365coil
366coin
367collect
368color
369column
370combine
371come
372comfort
373comic
374common
375company
376concert
377conduct
378confirm
379congress
380connect
381consider
382control
383convince
384cook
385cool
386copper
387copy
388coral
389core
390corn
391correct
392cost
393cotton
394couch
395country
396couple
397course
398cousin
399cover
400coyote
401crack
402cradle
403craft
404cram
405crane
406crash
407crater
408crawl
409crazy
410cream
411credit
412creek
413crew
414cricket
415crime
416crisp
417critic
418crop
419cross
420crouch
421crowd
422crucial
423cruel
424cruise
425crumble
426crunch
427crush
428cry
429crystal
430cube
431culture
432cup
433cupboard
434curious
435current
436curtain
437curve
438cushion
439custom
440cute
441cycle
442dad
443damage
444damp
445dance
446danger
447daring
448dash
449daughter
450dawn
451day
452deal
453debate
454debris
455decade
456december
457decide
458decline
459decorate
460decrease
461deer
462defense
463define
464defy
465degree
466delay
467deliver
468demand
469demise
470denial
471dentist
472deny
473depart
474depend
475deposit
476depth
477deputy
478derive
479describe
480desert
481design
482desk
483despair
484destroy
485detail
486detect
487develop
488device
489devote
490diagram
491dial
492diamond
493diary
494dice
495diesel
496diet
497differ
498digital
499dignity
500dilemma
501dinner
502dinosaur
503direct
504dirt
505disagree
506discover
507disease
508dish
509dismiss
510disorder
511display
512distance
513divert
514divide
515divorce
516dizzy
517doctor
518document
519dog
520doll
521dolphin
522domain
523donate
524donkey
525donor
526door
527dose
528double
529dove
530draft
531dragon
532drama
533drastic
534draw
535dream
536dress
537drift
538drill
539drink
540drip
541drive
542drop
543drum
544dry
545duck
546dumb
547dune
548during
549dust
550dutch
551duty
552dwarf
553dynamic
554eager
555eagle
556early
557earn
558earth
559easily
560east
561easy
562echo
563ecology
564economy
565edge
566edit
567educate
568effort
569egg
570eight
571either
572elbow
573elder
574electric
575elegant
576element
577elephant
578elevator
579elite
580else
581embark
582embody
583embrace
584emerge
585emotion
586employ
587empower
588empty
589enable
590enact
591end
592endless
593endorse
594enemy
595energy
596enforce
597engage
598engine
599enhance
600enjoy
601enlist
602enough
603enrich
604enroll
605ensure
606enter
607entire
608entry
609envelope
610episode
611equal
612equip
613era
614erase
615erode
616erosion
617error
618erupt
619escape
620essay
621essence
622estate
623eternal
624ethics
625evidence
626evil
627evoke
628evolve
629exact
630example
631excess
632exchange
633excite
634exclude
635excuse
636execute
637exercise
638exhaust
639exhibit
640exile
641exist
642exit
643exotic
644expand
645expect
646expire
647explain
648expose
649express
650extend
651extra
652eye
653eyebrow
654fabric
655face
656faculty
657fade
658faint
659faith
660fall
661false
662fame
663family
664famous
665fan
666fancy
667fantasy
668farm
669fashion
670fat
671fatal
672father
673fatigue
674fault
675favorite
676feature
677february
678federal
679fee
680feed
681feel
682female
683fence
684festival
685fetch
686fever
687few
688fiber
689fiction
690field
691figure
692file
693film
694filter
695final
696find
697fine
698finger
699finish
700fire
701firm
702first
703fiscal
704fish
705fit
706fitness
707fix
708flag
709flame
710flash
711flat
712flavor
713flee
714flight
715flip
716float
717flock
718floor
719flower
720fluid
721flush
722fly
723foam
724focus
725fog
726foil
727fold
728follow
729food
730foot
731force
732forest
733forget
734fork
735fortune
736forum
737forward
738fossil
739foster
740found
741fox
742fragile
743frame
744frequent
745fresh
746friend
747fringe
748frog
749front
750frost
751frown
752frozen
753fruit
754fuel
755fun
756funny
757furnace
758fury
759future
760gadget
761gain
762galaxy
763gallery
764game
765gap
766garage
767garbage
768garden
769garlic
770garment
771gas
772gasp
773gate
774gather
775gauge
776gaze
777general
778genius
779genre
780gentle
781genuine
782gesture
783ghost
784giant
785gift
786giggle
787ginger
788giraffe
789girl
790give
791glad
792glance
793glare
794glass
795glide
796glimpse
797globe
798gloom
799glory
800glove
801glow
802glue
803goat
804goddess
805gold
806good
807goose
808gorilla
809gospel
810gossip
811govern
812gown
813grab
814grace
815grain
816grant
817grape
818grass
819gravity
820great
821green
822grid
823grief
824grit
825grocery
826group
827grow
828grunt
829guard
830guess
831guide
832guilt
833guitar
834gun
835gym
836habit
837hair
838half
839hammer
840hamster
841hand
842happy
843harbor
844hard
845harsh
846harvest
847hat
848have
849hawk
850hazard
851head
852health
853heart
854heavy
855hedgehog
856height
857hello
858helmet
859help
860hen
861hero
862hidden
863high
864hill
865hint
866hip
867hire
868history
869hobby
870hockey
871hold
872hole
873holiday
874hollow
875home
876honey
877hood
878hope
879horn
880horror
881horse
882hospital
883host
884hotel
885hour
886hover
887hub
888huge
889human
890humble
891humor
892hundred
893hungry
894hunt
895hurdle
896hurry
897hurt
898husband
899hybrid
900ice
901icon
902idea
903identify
904idle
905ignore
906ill
907illegal
908illness
909image
910imitate
911immense
912immune
913impact
914impose
915improve
916impulse
917inch
918include
919income
920increase
921index
922indicate
923indoor
924industry
925infant
926inflict
927inform
928inhale
929inherit
930initial
931inject
932injury
933inmate
934inner
935innocent
936input
937inquiry
938insane
939insect
940inside
941inspire
942install
943intact
944interest
945into
946invest
947invite
948involve
949iron
950island
951isolate
952issue
953item
954ivory
955jacket
956jaguar
957jar
958jazz
959jealous
960jeans
961jelly
962jewel
963job
964join
965joke
966journey
967joy
968judge
969juice
970jump
971jungle
972junior
973junk
974just
975kangaroo
976keen
977keep
978ketchup
979key
980kick
981kid
982kidney
983kind
984kingdom
985kiss
986kit
987kitchen
988kite
989kitten
990kiwi
991knee
992knife
993knock
994know
995lab
996label
997labor
998ladder
999lady
1000lake
1001lamp
1002language
1003laptop
1004large
1005later
1006latin
1007laugh
1008laundry
1009lava
1010law
1011lawn
1012lawsuit
1013layer
1014lazy
1015leader
1016leaf
1017learn
1018leave
1019lecture
1020left
1021leg
1022legal
1023legend
1024leisure
1025lemon
1026lend
1027length
1028lens
1029leopard
1030lesson
1031letter
1032level
1033liar
1034liberty
1035library
1036license
1037life
1038lift
1039light
1040like
1041limb
1042limit
1043link
1044lion
1045liquid
1046list
1047little
1048live
1049lizard
1050load
1051loan
1052lobster
1053local
1054lock
1055logic
1056lonely
1057long
1058loop
1059lottery
1060loud
1061lounge
1062love
1063loyal
1064lucky
1065luggage
1066lumber
1067lunar
1068lunch
1069luxury
1070lyrics
1071machine
1072mad
1073magic
1074magnet
1075maid
1076mail
1077main
1078major
1079make
1080mammal
1081man
1082manage
1083mandate
1084mango
1085mansion
1086manual
1087maple
1088marble
1089march
1090margin
1091marine
1092market
1093marriage
1094mask
1095mass
1096master
1097match
1098material
1099math
1100matrix
1101matter
1102maximum
1103maze
1104meadow
1105mean
1106measure
1107meat
1108mechanic
1109medal
1110media
1111melody
1112melt
1113member
1114memory
1115mention
1116menu
1117mercy
1118merge
1119merit
1120merry
1121mesh
1122message
1123metal
1124method
1125middle
1126midnight
1127milk
1128million
1129mimic
1130mind
1131minimum
1132minor
1133minute
1134miracle
1135mirror
1136misery
1137miss
1138mistake
1139mix
1140mixed
1141mixture
1142mobile
1143model
1144modify
1145mom
1146moment
1147monitor
1148monkey
1149monster
1150month
1151moon
1152moral
1153more
1154morning
1155mosquito
1156mother
1157motion
1158motor
1159mountain
1160mouse
1161move
1162movie
1163much
1164muffin
1165mule
1166multiply
1167muscle
1168museum
1169mushroom
1170music
1171must
1172mutual
1173myself
1174mystery
1175myth
1176naive
1177name
1178napkin
1179narrow
1180nasty
1181nation
1182nature
1183near
1184neck
1185need
1186negative
1187neglect
1188neither
1189nephew
1190nerve
1191nest
1192net
1193network
1194neutral
1195never
1196news
1197next
1198nice
1199night
1200noble
1201noise
1202nominee
1203noodle
1204normal
1205north
1206nose
1207notable
1208note
1209nothing
1210notice
1211novel
1212now
1213nuclear
1214number
1215nurse
1216nut
1217oak
1218obey
1219object
1220oblige
1221obscure
1222observe
1223obtain
1224obvious
1225occur
1226ocean
1227october
1228odor
1229off
1230offer
1231office
1232often
1233oil
1234okay
1235old
1236olive
1237olympic
1238omit
1239once
1240one
1241onion
1242online
1243only
1244open
1245opera
1246opinion
1247oppose
1248option
1249orange
1250orbit
1251orchard
1252order
1253ordinary
1254organ
1255orient
1256original
1257orphan
1258ostrich
1259other
1260outdoor
1261outer
1262output
1263outside
1264oval
1265oven
1266over
1267own
1268owner
1269oxygen
1270oyster
1271ozone
1272pact
1273paddle
1274page
1275pair
1276palace
1277palm
1278panda
1279panel
1280panic
1281panther
1282paper
1283parade
1284parent
1285park
1286parrot
1287party
1288pass
1289patch
1290path
1291patient
1292patrol
1293pattern
1294pause
1295pave
1296payment
1297peace
1298peanut
1299pear
1300peasant
1301pelican
1302pen
1303penalty
1304pencil
1305people
1306pepper
1307perfect
1308permit
1309person
1310pet
1311phone
1312photo
1313phrase
1314physical
1315piano
1316picnic
1317picture
1318piece
1319pig
1320pigeon
1321pill
1322pilot
1323pink
1324pioneer
1325pipe
1326pistol
1327pitch
1328pizza
1329place
1330planet
1331plastic
1332plate
1333play
1334please
1335pledge
1336pluck
1337plug
1338plunge
1339poem
1340poet
1341point
1342polar
1343pole
1344police
1345pond
1346pony
1347pool
1348popular
1349portion
1350position
1351possible
1352post
1353potato
1354pottery
1355poverty
1356powder
1357power
1358practice
1359praise
1360predict
1361prefer
1362prepare
1363present
1364pretty
1365prevent
1366price
1367pride
1368primary
1369print
1370priority
1371prison
1372private
1373prize
1374problem
1375process
1376produce
1377profit
1378program
1379project
1380promote
1381proof
1382property
1383prosper
1384protect
1385proud
1386provide
1387public
1388pudding
1389pull
1390pulp
1391pulse
1392pumpkin
1393punch
1394pupil
1395puppy
1396purchase
1397purity
1398purpose
1399purse
1400push
1401put
1402puzzle
1403pyramid
1404quality
1405quantum
1406quarter
1407question
1408quick
1409quit
1410quiz
1411quote
1412rabbit
1413raccoon
1414race
1415rack
1416radar
1417radio
1418rail
1419rain
1420raise
1421rally
1422ramp
1423ranch
1424random
1425range
1426rapid
1427rare
1428rate
1429rather
1430raven
1431raw
1432razor
1433ready
1434real
1435reason
1436rebel
1437rebuild
1438recall
1439receive
1440recipe
1441record
1442recycle
1443reduce
1444reflect
1445reform
1446refuse
1447region
1448regret
1449regular
1450reject
1451relax
1452release
1453relief
1454rely
1455remain
1456remember
1457remind
1458remove
1459render
1460renew
1461rent
1462reopen
1463repair
1464repeat
1465replace
1466report
1467require
1468rescue
1469resemble
1470resist
1471resource
1472response
1473result
1474retire
1475retreat
1476return
1477reunion
1478reveal
1479review
1480reward
1481rhythm
1482rib
1483ribbon
1484rice
1485rich
1486ride
1487ridge
1488rifle
1489right
1490rigid
1491ring
1492riot
1493ripple
1494risk
1495ritual
1496rival
1497river
1498road
1499roast
1500robot
1501robust
1502rocket
1503romance
1504roof
1505rookie
1506room
1507rose
1508rotate
1509rough
1510round
1511route
1512royal
1513rubber
1514rude
1515rug
1516rule
1517run
1518runway
1519rural
1520sad
1521saddle
1522sadness
1523safe
1524sail
1525salad
1526salmon
1527salon
1528salt
1529salute
1530same
1531sample
1532sand
1533satisfy
1534satoshi
1535sauce
1536sausage
1537save
1538say
1539scale
1540scan
1541scare
1542scatter
1543scene
1544scheme
1545school
1546science
1547scissors
1548scorpion
1549scout
1550scrap
1551screen
1552script
1553scrub
1554sea
1555search
1556season
1557seat
1558second
1559secret
1560section
1561security
1562seed
1563seek
1564segment
1565select
1566sell
1567seminar
1568senior
1569sense
1570sentence
1571series
1572service
1573session
1574settle
1575setup
1576seven
1577shadow
1578shaft
1579shallow
1580share
1581shed
1582shell
1583sheriff
1584shield
1585shift
1586shine
1587ship
1588shiver
1589shock
1590shoe
1591shoot
1592shop
1593short
1594shoulder
1595shove
1596shrimp
1597shrug
1598shuffle
1599shy
1600sibling
1601sick
1602side
1603siege
1604sight
1605sign
1606silent
1607silk
1608silly
1609silver
1610similar
1611simple
1612since
1613sing
1614siren
1615sister
1616situate
1617six
1618size
1619skate
1620sketch
1621ski
1622skill
1623skin
1624skirt
1625skull
1626slab
1627slam
1628sleep
1629slender
1630slice
1631slide
1632slight
1633slim
1634slogan
1635slot
1636slow
1637slush
1638small
1639smart
1640smile
1641smoke
1642smooth
1643snack
1644snake
1645snap
1646sniff
1647snow
1648soap
1649soccer
1650social
1651sock
1652soda
1653soft
1654solar
1655soldier
1656solid
1657solution
1658solve
1659someone
1660song
1661soon
1662sorry
1663sort
1664soul
1665sound
1666soup
1667source
1668south
1669space
1670spare
1671spatial
1672spawn
1673speak
1674special
1675speed
1676spell
1677spend
1678sphere
1679spice
1680spider
1681spike
1682spin
1683spirit
1684split
1685spoil
1686sponsor
1687spoon
1688sport
1689spot
1690spray
1691spread
1692spring
1693spy
1694square
1695squeeze
1696squirrel
1697stable
1698stadium
1699staff
1700stage
1701stairs
1702stamp
1703stand
1704start
1705state
1706stay
1707steak
1708steel
1709stem
1710step
1711stereo
1712stick
1713still
1714sting
1715stock
1716stomach
1717stone
1718stool
1719story
1720stove
1721strategy
1722street
1723strike
1724strong
1725struggle
1726student
1727stuff
1728stumble
1729style
1730subject
1731submit
1732subway
1733success
1734such
1735sudden
1736suffer
1737sugar
1738suggest
1739suit
1740summer
1741sun
1742sunny
1743sunset
1744super
1745supply
1746supreme
1747sure
1748surface
1749surge
1750surprise
1751surround
1752survey
1753suspect
1754sustain
1755swallow
1756swamp
1757swap
1758swarm
1759swear
1760sweet
1761swift
1762swim
1763swing
1764switch
1765sword
1766symbol
1767symptom
1768syrup
1769system
1770table
1771tackle
1772tag
1773tail
1774talent
1775talk
1776tank
1777tape
1778target
1779task
1780taste
1781tattoo
1782taxi
1783teach
1784team
1785tell
1786ten
1787tenant
1788tennis
1789tent
1790term
1791test
1792text
1793thank
1794that
1795theme
1796then
1797theory
1798there
1799they
1800thing
1801this
1802thought
1803three
1804thrive
1805throw
1806thumb
1807thunder
1808ticket
1809tide
1810tiger
1811tilt
1812timber
1813time
1814tiny
1815tip
1816tired
1817tissue
1818title
1819toast
1820tobacco
1821today
1822toddler
1823toe
1824together
1825toilet
1826token
1827tomato
1828tomorrow
1829tone
1830tongue
1831tonight
1832tool
1833tooth
1834top
1835topic
1836topple
1837torch
1838tornado
1839tortoise
1840toss
1841total
1842tourist
1843toward
1844tower
1845town
1846toy
1847track
1848trade
1849traffic
1850tragic
1851train
1852transfer
1853trap
1854trash
1855travel
1856tray
1857treat
1858tree
1859trend
1860trial
1861tribe
1862trick
1863trigger
1864trim
1865trip
1866trophy
1867trouble
1868truck
1869true
1870truly
1871trumpet
1872trust
1873truth
1874try
1875tube
1876tuition
1877tumble
1878tuna
1879tunnel
1880turkey
1881turn
1882turtle
1883twelve
1884twenty
1885twice
1886twin
1887twist
1888two
1889type
1890typical
1891ugly
1892umbrella
1893unable
1894unaware
1895uncle
1896uncover
1897under
1898undo
1899unfair
1900unfold
1901unhappy
1902uniform
1903unique
1904unit
1905universe
1906unknown
1907unlock
1908until
1909unusual
1910unveil
1911update
1912upgrade
1913uphold
1914upon
1915upper
1916upset
1917urban
1918urge
1919usage
1920use
1921used
1922useful
1923useless
1924usual
1925utility
1926vacant
1927vacuum
1928vague
1929valid
1930valley
1931valve
1932van
1933vanish
1934vapor
1935various
1936vast
1937vault
1938vehicle
1939velvet
1940vendor
1941venture
1942venue
1943verb
1944verify
1945version
1946very
1947vessel
1948veteran
1949viable
1950vibrant
1951vicious
1952victory
1953video
1954view
1955village
1956vintage
1957violin
1958virtual
1959virus
1960visa
1961visit
1962visual
1963vital
1964vivid
1965vocal
1966voice
1967void
1968volcano
1969volume
1970vote
1971voyage
1972wage
1973wagon
1974wait
1975walk
1976wall
1977walnut
1978want
1979warfare
1980warm
1981warrior
1982wash
1983wasp
1984waste
1985water
1986wave
1987way
1988wealth
1989weapon
1990wear
1991weasel
1992weather
1993web
1994wedding
1995weekend
1996weird
1997welcome
1998west
1999wet
2000whale
2001what
2002wheat
2003wheel
2004when
2005where
2006whip
2007whisper
2008wide
2009width
2010wife
2011wild
2012will
2013win
2014window
2015wine
2016wing
2017wink
2018winner
2019winter
2020wire
2021wisdom
2022wise
2023wish
2024witness
2025wolf
2026woman
2027wonder
2028wood
2029wool
2030word
2031work
2032world
2033worry
2034worth
2035wrap
2036wreck
2037wrestle
2038wrist
2039write
2040wrong
2041yard
2042year
2043yellow
2044you
2045young
2046youth
2047zebra
2048zero
2049zone
2050zoo`.split(`
2051`);var Sc=Cc(vc()),Zn=Ko,Ll="m/84'/1'/0'",Nl=10;function Cl(){return gc(Di,128)}function _l(t){return yc(String(t||"").trim().toLowerCase().replace(/\s+/g," "),Di)}function Pl(t){let e=bc(String(t).trim().toLowerCase().replace(/\s+/g," ")),r=Gn.fromMasterSeed(e).derive(Ll),n=(i,s)=>r.deriveChild(i).deriveChild(s),o=(i,s)=>ci(n(i,s).publicKey,Zn);return{address:(i=0,s=0)=>o(s,i).address,key:n,addr:o}}async function Bc(t){let e=await fetch(t);if(!e.ok)throw new Error("Network busy, try again.");return e.json()}async function Rl(t){let e=[],r=new Map,n=0,o=0;for(let c of[0,1]){let f=0;for(let h=0;h<40&&f<(c?4:Nl);h++){let u=t.addr(c,h),[l,y]=await Promise.all([Bc(`/api/chain/address/${u.address}/utxo`),Bc(`/api/chain/address/${u.address}/txs`)]);if(!y.length){f++;continue}f=0,c?o=h+1:n=h+1;for(let N of l)e.push({txid:N.txid,vout:N.vout,value:N.value,confirmed:N.status&&N.status.confirmed,change:c,i:h,script:u.script});for(let N of y)r.set(N.txid,N)}}let i=new Set;for(let c of[0,1])for(let f=0;f<(c?o:n)+1;f++)i.add(t.address(f,c));let s=[...r.values()].map(c=>{let f=0;for(let h of c.vout)i.has(h.scriptpubkey_address)&&(f+=h.value);for(let h of c.vin)h.prevout&&i.has(h.prevout.scriptpubkey_address)&&(f-=h.prevout.value);return{txid:c.txid,delta:f,time:c.status&&c.status.block_time?c.status.block_time*1e3:null,confirmed:!!(c.status&&c.status.confirmed)}}).sort((c,f)=>(f.time||9e15)-(c.time||9e15)),a=e.reduce((c,f)=>c+f.value,0);return{utxos:e,balance:a,history:s,nextReceive:n,nextChange:o}}function Ac(t){try{return Ee(Zn).decode(String(t).trim()),!0}catch{return!1}}function Hl(t,e,r,n,o){if(r=String(r).trim(),!Ac(r))throw new Error("That isn\u2019t a test-network Bitcoin address (they start with tb1).");if(n=Math.floor(n),!(n>=330))throw new Error("That amount is too small to send.");let i=[...e.utxos].sort((u,l)=>l.value-u.value),s=[],a=0,c=0;for(let u of i)if(s.push(u),a+=u.value,c=Math.ceil((11+68*s.length+31*2)*o),a>=n+c)break;if(a<n+c)throw new Error("Not enough in your wallet for this payment and the network fee.");let f=new xe;for(let u of s)f.addInput({txid:u.txid,index:u.vout,witnessUtxo:{script:u.script,amount:BigInt(u.value)}});f.addOutputAddress(r,BigInt(n),Zn);let h=a-n-c;return h>=546?f.addOutputAddress(t.address(e.nextChange,1),BigInt(h),Zn):c+=h,s.forEach((u,l)=>f.signIdx(t.key(u.change,u.i).privateKey,l)),f.finalize(),{hex:f.hex,fee:c,txid:f.id}}function $l(t){let e=(0,Sc.default)(0,"M");return e.addData(t),e.make(),e.createSvgTag({cellSize:6,margin:2,scalable:!0})}return _c(Ol);})();
2052/*! Bundled license information:
2053
2054@scure/base/lib/esm/index.js:
2055 (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2056
2057@noble/hashes/esm/utils.js:
2058 (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2059
2060@noble/hashes/esm/utils.js:
2061 (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2062
2063@noble/curves/esm/abstract/utils.js:
2064 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2065
2066@noble/curves/esm/abstract/modular.js:
2067 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2068
2069@noble/curves/esm/abstract/curve.js:
2070 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2071
2072@noble/curves/esm/abstract/weierstrass.js:
2073 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2074
2075@noble/curves/esm/_shortw_utils.js:
2076 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2077
2078@noble/curves/esm/secp256k1.js:
2079 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2080
2081@scure/base/lib/esm/index.js:
2082 (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2083
2084@scure/btc-signer/esm/index.js:
2085 (*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2086
2087@noble/hashes/esm/utils.js:
2088 (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2089
2090@noble/curves/esm/abstract/utils.js:
2091 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2092
2093@noble/curves/esm/abstract/modular.js:
2094 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2095
2096@noble/curves/esm/abstract/curve.js:
2097 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2098
2099@noble/curves/esm/abstract/weierstrass.js:
2100 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2101
2102@noble/curves/esm/_shortw_utils.js:
2103 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2104
2105@noble/curves/esm/secp256k1.js:
2106 (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2107
2108@scure/bip32/lib/esm/index.js:
2109 (*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
2110
2111@scure/bip39/esm/index.js:
2112 (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
2113*/